mbed RPC

Dependents:   WiFlyHTTPServerSample MultiThreadingHTTPServer HTTP-Server EthHTTPServer ... more

Legacy Warning

This is an mbed 2 library. To learn more about mbed OS 5, visit the docs.

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Tue Nov 20 17:23:59 2012 +0000
Child:
1:6919289a5946
Commit message:
mbed RPC

Changed in this revision

Arguments.cpp Show annotated file Show diff for this revision Revisions of this file
Arguments.h Show annotated file Show diff for this revision Revisions of this file
RPCFunction.cpp Show annotated file Show diff for this revision Revisions of this file
RPCFunction.h Show annotated file Show diff for this revision Revisions of this file
RPCVariable.h Show annotated file Show diff for this revision Revisions of this file
RpcClasses.h Show annotated file Show diff for this revision Revisions of this file
mbed_rpc.h Show annotated file Show diff for this revision Revisions of this file
rpc.cpp Show annotated file Show diff for this revision Revisions of this file
rpc.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Arguments.cpp	Tue Nov 20 17:23:59 2012 +0000
@@ -0,0 +1,146 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2012 ARM Limited
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "Arguments.h"
+#include "pinmap.h"
+
+using namespace std;
+
+namespace mbed {
+
+Arguments::Arguments(const char* rqs) {
+    obj_name = NULL;
+    method_name = NULL;
+    argc = 0;
+    
+    // This copy can be removed if we can assume the request string is
+    // persistent and writable for the duration of the call
+    strcpy(request, rqs);
+    
+    // Initial '/'
+    char* p = request;
+    if (*p != '/') return;
+    p++;
+    
+    // Object Name
+    p = search_arg(&obj_name, p, '/');
+    if (p == NULL) return;
+    
+    // Method Name
+    p = search_arg(&method_name, p, ' ');
+    if (p == NULL) return;
+    
+    // Arguments
+    while (true) {
+        argv[argc] = NULL;
+        p = search_arg(&argv[argc], p, ' ');
+        if (argv[argc] != NULL) argc++;
+        if (p == NULL) break;
+    }
+    
+    index = -1;
+}
+
+char* Arguments::search_arg(char **arg, char *p, char next_sep) {
+    char *s = p;
+    while (true) {
+        if ((*p == '/') || (*p == ' ') || (*p == '\n') || (*p == '\0')) break;
+        p++;
+    }
+    if (p == s) return NULL;
+    *arg = s;
+    char separator = *p;
+    *p = '\0';
+    p++;
+    return (separator == next_sep) ? (p) : (NULL);
+}
+
+template<> PinName Arguments::getArg<PinName>(void) {
+    index++;
+    return parse_pins(argv[index]);
+}
+
+template<> int Arguments::getArg<int>(void) {
+    index++;
+    char *pEnd;
+    return strtol(argv[index], &pEnd, 10);
+}
+
+template<> const char* Arguments::getArg<const char*>(void) {
+    index++;
+    return argv[index];
+}
+
+template<> char Arguments::getArg<char>(void) {
+    index++;
+    return *argv[index];
+}
+
+template<> double Arguments::getArg<double>(void) {
+    index++;
+    return atof(argv[index]);
+}
+
+template<> float Arguments::getArg<float>(void) {
+    index++;
+    return atof(argv[index]);
+}
+
+Reply::Reply(char* r) {
+    first = true;
+    *r = '\0';
+    reply = r;
+}
+
+void Reply::separator(void) {
+    if (first) {
+        first = false;
+    } else {
+        *reply = ' '; reply++;
+    }
+}
+
+template<> void Reply::putData<const char*>(const char* s) {
+    separator();
+    reply += sprintf(reply, "%s", s);
+}
+
+template<> void Reply::putData<char*>(char* s) {
+    separator();
+    reply += sprintf(reply, "%s", s);
+}
+
+template<> void Reply::putData<char>(char c) {
+    separator();
+    reply += sprintf(reply, "%c", c);
+}
+
+template<> void Reply::putData<int>(int v) {
+    separator();
+    reply += sprintf(reply, "%d", v);
+}
+
+template<> void Reply::putData<float>(float f) {
+    separator();
+    reply += sprintf(reply, "%.17g", f);
+}
+
+} // namespace mbed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Arguments.h	Tue Nov 20 17:23:59 2012 +0000
@@ -0,0 +1,69 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2012 ARM Limited
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef ARGUMENTS_H
+#define ARGUMENTS_H
+
+#include "platform.h"
+
+namespace mbed {
+
+#define RPC_MAX_STRING  128
+#define RPC_MAX_ARGS     16
+
+class Arguments {
+public:
+    Arguments(const char* rqs);
+    
+    template<typename Arg>
+    Arg   getArg(void);
+    
+    char *obj_name;
+    char *method_name;
+    
+    int   argc;
+    char* argv[RPC_MAX_ARGS];
+
+private:
+    // This copy can be removed if we can assume the request string is
+    // persistent and writable for the duration of the call
+    char  request[RPC_MAX_STRING];
+    int index;
+    char* search_arg(char **arg, char *p, char next_sep);
+};
+
+class Reply {
+public:
+    Reply(char* r);
+    
+    template<typename Data>
+    void putData(Data d);
+
+private:
+    void separator(void);
+    bool first;
+    char* reply;
+};
+
+
+} // Namespace mbed
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RPCFunction.cpp	Tue Nov 20 17:23:59 2012 +0000
@@ -0,0 +1,48 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2012 ARM Limited
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "RPCFunction.h"
+
+namespace mbed {
+
+//Custom rpc method caller for execute so that the string will not be delimited by anything
+void rpc_method_caller_run(RPC *this_ptr, Arguments *arguments, Reply *result) {
+    ((static_cast<RPCFunction*>(this_ptr))->run)(arguments, result);
+}
+
+RPCFunction::RPCFunction(void (*f)(Arguments*, Reply*), const char* name) : RPC(name) {
+    _ftr = f;
+}
+
+//Just run the attached function using the string thats in private memory - or just using null values, 
+void RPCFunction::run(Arguments* args, Reply* r) {
+    (*_ftr)(args, r);
+}
+
+const rpc_method *RPCFunction::get_rpc_methods() {
+    static const rpc_method rpc_methods[] = {
+        {"run", rpc_method_caller_run }, //Run using custom caller, all characters accepted in string
+        RPC_METHOD_SUPER(RPC)
+    };
+    return rpc_methods;
+}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RPCFunction.h	Tue Nov 20 17:23:59 2012 +0000
@@ -0,0 +1,65 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2012 ARM Limited
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef RPCFUNCTION_RPC
+#define RPCFUNCTION_RPC
+
+#include "rpc.h"
+#define STR_LEN 64
+
+namespace mbed {
+
+/**
+ *
+ *Class to call custom functions over RPC
+ *
+ */
+class RPCFunction: public RPC {
+public:
+    /**
+     * Constructor
+     * 
+     *@param f Pointer to the function to call. the function must be of the form void foo(char * input, char * output)
+     *@param name The name of this object
+     */
+    RPCFunction(void (*f)(Arguments*, Reply*), const char* = NULL);
+
+    /** 
+     *run 
+     *
+     *Calls the attached function passing the string in but doesn't return the result.
+     *@param str The string to be passed into the attached function. This string can consist of any ASCII characters apart from escape codes. The usual limtations on argument content for RPC strings has been removed
+     *@return A string output from the function
+     */
+    void run(Arguments* args, Reply* r);
+
+    virtual const struct rpc_method *get_rpc_methods();
+
+private:
+    void (*_ftr)(Arguments*, Reply*);
+
+    char _input[STR_LEN];
+    char _output[STR_LEN];
+};
+
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RPCVariable.h	Tue Nov 20 17:23:59 2012 +0000
@@ -0,0 +1,93 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2012 ARM Limited
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef RPCVARIABLE_H_
+#define RPCVARIABLE_H_
+
+#include "rpc.h"
+
+namespace mbed {
+
+/**
+ *Class to read and set an attached variable using the RPC
+ *
+ */
+template<class T>
+class RPCVariable: public RPC {
+public:
+    /**
+     * Constructor
+     * 
+     *@param ptr Pointer to the variable to make accessible over RPC. Any type of 
+     *variable can be connected
+     *@param name The name of that this object will be over RPC
+     */
+    template<class A>
+    RPCVariable(A * ptr, const char * name) : RPC(name) {
+        _ptr = ptr;
+    }
+    /**
+     *Read the variable over RPC.
+     * 
+     *@return The value of the variable
+     */
+    T read() {
+        return (*_ptr);
+    }
+    /**
+     *Write a value to the variable over RPC
+     * 
+     *@param The value to be written to the attached variable.
+     */
+    void write(T value) {
+        *_ptr = value;
+    }
+    
+    virtual const struct rpc_method *get_rpc_methods();
+    static struct rpc_class *get_rpc_class();
+
+private:
+    T * _ptr;
+};
+
+template<class T>
+const rpc_method *RPCVariable<T>::get_rpc_methods() {
+    static const rpc_method rpc_methods[] = {
+        {"read" , rpc_method_caller<T, RPCVariable, &RPCVariable::read> },
+        {"write", rpc_method_caller<RPCVariable, T, &RPCVariable::write> },
+        RPC_METHOD_SUPER(RPC)
+    };
+    return rpc_methods;
+}
+
+template<class T>
+rpc_class *RPCVariable<T>::get_rpc_class() {
+    static const rpc_function funcs[] = {
+            "new", rpc_function_caller<const char*, T, const char*, &RPC::construct<RPCVariable, T, const char*> > ,
+            RPC_METHOD_END
+    };
+    static rpc_class c = {"RPCVariable", funcs, NULL};
+    return &c;
+}
+
+}
+
+#endif  //RPCVARIABLE_H_
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RpcClasses.h	Tue Nov 20 17:23:59 2012 +0000
@@ -0,0 +1,314 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2012 ARM Limited
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef MBED_CLASSES_H
+#define MBED_CLASSES_H
+
+#include "rpc.h"
+
+namespace mbed {
+
+class RpcDigitalOut : public RPC {
+public:
+    RpcDigitalOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
+    
+    void write(int a0) {o.write(a0);}
+    int read(void) {return o.read();}
+    
+    virtual const struct rpc_method *get_rpc_methods() {
+        static const rpc_method rpc_methods[] = {
+            {"write", rpc_method_caller<RpcDigitalOut, int, &RpcDigitalOut::write>},
+            {"read", rpc_method_caller<int, RpcDigitalOut, &RpcDigitalOut::read>},
+            RPC_METHOD_SUPER(RPC)
+        };
+        return rpc_methods;
+    }
+    static struct rpc_class *get_rpc_class() {
+        static const rpc_function funcs[] = {
+            {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalOut, PinName, const char*> >},
+            RPC_METHOD_END
+        };
+        static rpc_class c = {"DigitalOut", funcs, NULL};
+        return &c;
+    }
+private:
+    DigitalOut o;
+};
+
+class RpcDigitalIn : public RPC {
+public:
+    RpcDigitalIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
+    
+    int read(void) {return o.read();}
+    
+    virtual const struct rpc_method *get_rpc_methods() {
+        static const rpc_method rpc_methods[] = {
+            {"read", rpc_method_caller<int, RpcDigitalIn, &RpcDigitalIn::read>},
+            RPC_METHOD_SUPER(RPC)
+        };
+        return rpc_methods;
+    }
+    static struct rpc_class *get_rpc_class() {
+        static const rpc_function funcs[] = {
+            {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalIn, PinName, const char*> >},
+            RPC_METHOD_END
+        };
+        static rpc_class c = {"DigitalIn", funcs, NULL};
+        return &c;
+    }
+private:
+    DigitalIn o;
+};
+
+class RpcDigitalInOut : public RPC {
+public:
+    RpcDigitalInOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
+    
+    int read(void) {return o.read();}
+    void write(int a0) {o.write(a0);}
+    void input(void) {o.input();}
+    void output(void) {o.output();}
+    
+    virtual const struct rpc_method *get_rpc_methods() {
+        static const rpc_method rpc_methods[] = {
+            {"read", rpc_method_caller<int, RpcDigitalInOut, &RpcDigitalInOut::read>},
+            {"write", rpc_method_caller<RpcDigitalInOut, int, &RpcDigitalInOut::write>},
+            {"input", rpc_method_caller<RpcDigitalInOut, &RpcDigitalInOut::input>},
+            {"output", rpc_method_caller<RpcDigitalInOut, &RpcDigitalInOut::output>},
+            RPC_METHOD_SUPER(RPC)
+        };
+        return rpc_methods;
+    }
+    static struct rpc_class *get_rpc_class() {
+        static const rpc_function funcs[] = {
+            {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalInOut, PinName, const char*> >},
+            RPC_METHOD_END
+        };
+        static rpc_class c = {"DigitalInOut", funcs, NULL};
+        return &c;
+    }
+private:
+    DigitalInOut o;
+};
+
+#if DEVICE_ANALOGIN
+class RpcAnalogIn : public RPC {
+public:
+    RpcAnalogIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
+    
+    float read(void) {return o.read();}
+    unsigned short read_u16(void) {return o.read_u16();}
+    
+    virtual const struct rpc_method *get_rpc_methods() {
+        static const rpc_method rpc_methods[] = {
+            {"read", rpc_method_caller<float, RpcAnalogIn, &RpcAnalogIn::read>},
+            {"read_u16", rpc_method_caller<unsigned short, RpcAnalogIn, &RpcAnalogIn::read_u16>},
+            RPC_METHOD_SUPER(RPC)
+        };
+        return rpc_methods;
+    }
+    static struct rpc_class *get_rpc_class() {
+        static const rpc_function funcs[] = {
+            {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcAnalogIn, PinName, const char*> >},
+            RPC_METHOD_END
+        };
+        static rpc_class c = {"AnalogIn", funcs, NULL};
+        return &c;
+    }
+private:
+    AnalogIn o;
+};
+#endif
+
+#if DEVICE_ANALOGOUT
+class RpcAnalogOut : public RPC {
+public:
+    RpcAnalogOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
+    
+    float read(void) {return o.read();}
+    void write(float a0) {o.write(a0);}
+    void write_u16(unsigned short a0) {o.write_u16(a0);}
+    
+    virtual const struct rpc_method *get_rpc_methods() {
+        static const rpc_method rpc_methods[] = {
+            {"read", rpc_method_caller<float, RpcAnalogOut, &RpcAnalogOut::read>},
+            {"write", rpc_method_caller<RpcAnalogOut, float, &RpcAnalogOut::write>},
+            {"write_u16", rpc_method_caller<RpcAnalogOut, unsigned short, &RpcAnalogOut::write_u16>},
+            RPC_METHOD_SUPER(RPC)
+        };
+        return rpc_methods;
+    }
+    static struct rpc_class *get_rpc_class() {
+        static const rpc_function funcs[] = {
+            {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcAnalogOut, PinName, const char*> >},
+            RPC_METHOD_END
+        };
+        static rpc_class c = {"AnalogOut", funcs, NULL};
+        return &c;
+    }
+private:
+    AnalogOut o;
+};
+#endif
+
+#if DEVICE_PWMOUT
+class RpcPwmOut : public RPC {
+public:
+    RpcPwmOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
+    
+    float read(void) {return o.read();}
+    void write(float a0) {o.write(a0);}
+    void period(float a0) {o.period(a0);}
+    void period_ms(int a0) {o.period_ms(a0);}
+    void pulsewidth(float a0) {o.pulsewidth(a0);}
+    void pulsewidth_ms(int a0) {o.pulsewidth_ms(a0);}
+    
+    virtual const struct rpc_method *get_rpc_methods() {
+        static const rpc_method rpc_methods[] = {
+            {"read", rpc_method_caller<float, RpcPwmOut, &RpcPwmOut::read>},
+            {"write", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::write>},
+            {"period", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::period>},
+            {"period_ms", rpc_method_caller<RpcPwmOut, int, &RpcPwmOut::period_ms>},
+            {"pulsewidth", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::pulsewidth>},
+            {"pulsewidth_ms", rpc_method_caller<RpcPwmOut, int, &RpcPwmOut::pulsewidth_ms>},
+            RPC_METHOD_SUPER(RPC)
+        };
+        return rpc_methods;
+    }
+    static struct rpc_class *get_rpc_class() {
+        static const rpc_function funcs[] = {
+            {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcPwmOut, PinName, const char*> >},
+            RPC_METHOD_END
+        };
+        static rpc_class c = {"PwmOut", funcs, NULL};
+        return &c;
+    }
+private:
+    PwmOut o;
+};
+#endif
+
+#if DEVICE_SPI
+class RpcSPI : public RPC {
+public:
+    RpcSPI(PinName a0, PinName a1, PinName a2, const char *name=NULL) : RPC(name), o(a0, a1, a2) {}
+    
+    void format(int a0, int a1) {o.format(a0, a1);}
+    void frequency(int a0) {o.frequency(a0);}
+    int write(int a0) {return o.write(a0);}
+    
+    virtual const struct rpc_method *get_rpc_methods() {
+        static const rpc_method rpc_methods[] = {
+            {"format", rpc_method_caller<RpcSPI, int, int, &RpcSPI::format>},
+            {"frequency", rpc_method_caller<RpcSPI, int, &RpcSPI::frequency>},
+            {"write", rpc_method_caller<int, RpcSPI, int, &RpcSPI::write>},
+            RPC_METHOD_SUPER(RPC)
+        };
+        return rpc_methods;
+    }
+    static struct rpc_class *get_rpc_class() {
+        static const rpc_function funcs[] = {
+            {"new", rpc_function_caller<const char*, PinName, PinName, PinName, const char*, &RPC::construct<RpcSPI, PinName, PinName, PinName, const char*> >},
+            RPC_METHOD_END
+        };
+        static rpc_class c = {"SPI", funcs, NULL};
+        return &c;
+    }
+private:
+    SPI o;
+};
+#endif
+
+#if DEVICE_SERIAL
+class RpcSerial : public RPC {
+public:
+    RpcSerial(PinName a0, PinName a1, const char *name=NULL) : RPC(name), o(a0, a1) {}
+    
+    void baud(int a0) {o.baud(a0);}
+    int readable(void) {return o.readable();}
+    int writeable(void) {return o.writeable();}
+    int putc(int a0) {return o.putc(a0);}
+    int getc(void) {return o.getc();}
+    int puts(const char * a0) {return o.puts(a0);}
+    
+    virtual const struct rpc_method *get_rpc_methods() {
+        static const rpc_method rpc_methods[] = {
+            {"baud", rpc_method_caller<RpcSerial, int, &RpcSerial::baud>},
+            {"readable", rpc_method_caller<int, RpcSerial, &RpcSerial::readable>},
+            {"writeable", rpc_method_caller<int, RpcSerial, &RpcSerial::writeable>},
+            {"putc", rpc_method_caller<int, RpcSerial, int, &RpcSerial::putc>},
+            {"getc", rpc_method_caller<int, RpcSerial, &RpcSerial::getc>},
+            {"puts", rpc_method_caller<int, RpcSerial, const char *, &RpcSerial::puts>},
+            RPC_METHOD_SUPER(RPC)
+        };
+        return rpc_methods;
+    }
+    static struct rpc_class *get_rpc_class() {
+        static const rpc_function funcs[] = {
+            {"new", rpc_function_caller<const char*, PinName, PinName, const char*, &RPC::construct<RpcSerial, PinName, PinName, const char*> >},
+            RPC_METHOD_END
+        };
+        static rpc_class c = {"Serial", funcs, NULL};
+        return &c;
+    }
+private:
+    Serial o;
+};
+#endif
+
+class RpcTimer : public RPC {
+public:
+    RpcTimer(const char *name=NULL) : RPC(name), o() {}
+    
+    void start(void) {o.start();}
+    void stop(void) {o.stop();}
+    void reset(void) {o.reset();}
+    float read(void) {return o.read();}
+    int read_ms(void) {return o.read_ms();}
+    int read_us(void) {return o.read_us();}
+    
+    virtual const struct rpc_method *get_rpc_methods() {
+        static const rpc_method rpc_methods[] = {
+            {"start", rpc_method_caller<RpcTimer, &RpcTimer::start>},
+            {"stop", rpc_method_caller<RpcTimer, &RpcTimer::stop>},
+            {"reset", rpc_method_caller<RpcTimer, &RpcTimer::reset>},
+            {"read", rpc_method_caller<float, RpcTimer, &RpcTimer::read>},
+            {"read_ms", rpc_method_caller<int, RpcTimer, &RpcTimer::read_ms>},
+            {"read_us", rpc_method_caller<int, RpcTimer, &RpcTimer::read_us>},
+            RPC_METHOD_SUPER(RPC)
+        };
+        return rpc_methods;
+    }
+    static struct rpc_class *get_rpc_class() {
+        static const rpc_function funcs[] = {
+            {"new", rpc_function_caller<const char*, const char*, &RPC::construct<RpcTimer, const char*> >},
+            RPC_METHOD_END
+        };
+        static rpc_class c = {"Timer", funcs, NULL};
+        return &c;
+    }
+private:
+    Timer o;
+};
+
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_rpc.h	Tue Nov 20 17:23:59 2012 +0000
@@ -0,0 +1,31 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2012 ARM Limited
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef MBED_RPC_H
+#define MBED_RPC_H
+
+#include "rpc.h"
+#include "RPCVariable.h"
+#include "RPCFunction.h"
+#include "RpcClasses.h"
+#include "Arguments.h"
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rpc.cpp	Tue Nov 20 17:23:59 2012 +0000
@@ -0,0 +1,197 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2012 ARM Limited
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "rpc.h"
+
+using namespace std;
+
+namespace mbed {
+
+RPC::RPC(const char *name) {
+    _from_construct = false;
+    if (name != NULL) {
+        _name = new char[strlen(name) + 1];
+        strcpy(_name, name);
+    } else {
+        _name = new char[12];
+        sprintf(_name, "obj%p", this);
+    }
+    // put this object at head of the list
+    _next = _head;
+    _head = this;
+}
+
+RPC::~RPC() {
+    // remove this object from the list
+    if (_head == this) { // first in the list, so just drop me
+        _head = _next;
+    } else {            // find the object before me, then drop me
+        RPC* p = _head;
+        while (p->_next != this) {
+            p = p->_next;
+        }
+        p->_next = _next;
+    }
+}
+
+const rpc_method *RPC::get_rpc_methods() {
+    static const rpc_method methods[] = {
+        {"delete", rpc_method_caller<RPC, &RPC::delete_self> },
+        RPC_METHOD_END
+    };
+    return methods;
+}
+
+RPC *RPC::lookup(const char *name) {
+    size_t len = strlen(name);
+    for (RPC *p = _head; p != NULL; p = p->_next) {
+        /* Check that p->_name matches name and is the correct length */
+        if (strncmp(p->_name, name, len) == 0 && (strlen(p->_name) == len)) {
+            return p;
+        }
+    }
+    return NULL;
+}
+
+void RPC::delete_self() {
+    delete[] _name;
+    if (_from_construct) {
+        delete this;
+    }
+}
+
+void RPC::list_objs(Arguments *args, Reply *result) {
+    for (RPC *ptr = RPC::_head; ptr != NULL; ptr = ptr->_next) {
+        if (ptr->_from_construct) {
+            result->putData<const char*>(ptr->_name);
+        }
+    }
+}
+
+void RPC::clear(Arguments*, Reply*) {
+    RPC *ptr = RPC::_head;
+    while (ptr != NULL) {
+        RPC *tmp = ptr;
+        ptr = ptr->_next;
+        delete[] tmp->_name;
+        if (tmp->_from_construct) {
+            delete tmp;
+        }
+    }
+}
+
+const rpc_function RPC::_RPC_funcs[] = {
+    {"clear", &RPC::clear },
+    { "objects", &RPC::list_objs },
+    RPC_METHOD_END
+};
+
+rpc_class RPC::_RPC_class = { "RPC", _RPC_funcs, NULL };
+
+RPC *RPC::_head = NULL;
+
+rpc_class *RPC::_classes = &_RPC_class;
+
+bool RPC::call(const char *request, char *reply) {
+    if (request == NULL) return false;
+    
+    Arguments args(request);
+    Reply r(reply);
+    
+    /* If there's no name print object and class names to result */
+    if (args.obj_name == NULL) {
+        for (RPC *p = RPC::_head; p != NULL; p = p->_next) {
+            r.putData<const char*>(p->_name);
+        }
+        for (rpc_class *c = RPC::_classes; c != NULL; c = c->next) {
+            r.putData<const char*>(c->name);
+        }
+        return true;
+    }
+    
+    /* First try matching an instance */
+    RPC *p = lookup(args.obj_name);
+    if (p != NULL) {
+        /* Get the list of methods we support */
+        const rpc_method *cur_method = p->get_rpc_methods();
+        
+        /* When there's no method print method names to result */
+        if (args.method_name == NULL) {
+            while (true) {
+                for (; cur_method->name != NULL; cur_method++) {
+                    r.putData<const char*>(cur_method->name);
+                }
+                
+                /* write_name_arr's args are references, so result and cur_method will have changed */
+                if (cur_method->super != 0) {
+                    cur_method = cur_method->super(p);
+                } else {
+                    return true;
+                }
+            }
+        }
+        
+        /* Look through the methods for the one whose name matches */
+        while (true) {
+            for (; cur_method->name != NULL; cur_method++) {
+                if (strcmp(cur_method->name, args.method_name) == 0) {
+                    (cur_method->method_caller)(p, &args, &r);
+                    return true;
+                }
+            }
+            
+            if (cur_method->super != 0) {
+                cur_method = cur_method->super(p);
+            } else {
+                /* end of methods and no match */
+                return false;
+            }
+            
+        }
+    }
+    
+    /* Then try a class */
+    for (const rpc_class *q = _classes; q != NULL; q = q->next) {
+        if (strcmp(q->name, args.obj_name) == 0) {
+            /* Matched the class name, so get its functions */
+            const rpc_function *cur_func = q->static_functions;
+            if (args.method_name == NULL) {
+                for (; cur_func->name != NULL; cur_func++) {
+                    r.putData<const char*>(cur_func->name);
+                }
+                return true;
+            } else {
+                /* Otherwise call the appropriate function */
+                for (; cur_func->name != NULL; cur_func++) {
+                    if (strcmp(cur_func->name, args.method_name) == 0) {
+                        (cur_func->function_caller)(&args, &r);
+                        return true;
+                    }
+                }
+                return false;
+            }
+        }
+    }
+    
+    return false;
+}
+
+} // namespace mbed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rpc.h	Tue Nov 20 17:23:59 2012 +0000
@@ -0,0 +1,319 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2012 ARM Limited
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef RPC_H
+#define RPC_H
+
+#include "mbed.h"
+#include "Arguments.h"
+
+namespace mbed {
+
+#define RPC_MAX_STRING      128
+
+struct rpc_function {
+    const char *name;
+    void (*function_caller)(Arguments*, Reply*);
+};
+
+struct rpc_class {
+    const char *name;
+    const rpc_function *static_functions;
+    struct rpc_class *next;
+};
+
+/* Class RPC
+ *  The RPC class for most things
+ */
+class RPC {
+    
+public:
+    
+    RPC(const char *name = NULL);
+
+    virtual ~RPC();
+
+    /* Function get_rpc_methods
+     *  Returns a pointer to an array describing the rpc methods
+     *  supported by this object, terminated by either
+     *  RPC_METHOD_END or RPC_METHOD_SUPER(Superclass).
+     *
+     * Example
+     * > class Example : public RPC {
+     * >   int foo(int a, int b) { return a + b; }
+     * >   virtual const struct rpc_method *get_rpc_methods() {
+     * >     static const rpc_method rpc_methods[] = {
+     * >       { "foo", generic_caller<int, Example, int, int, &Example::foo> },
+     * >       RPC_METHOD_SUPER(RPC)
+     * >     };
+     * >     return rpc_methods;
+     * >   }
+     * > };
+     */
+    virtual const struct rpc_method *get_rpc_methods();
+    
+    static bool call(const char *buf, char *result);
+
+    /* Function lookup
+     *  Lookup and return the object that has the given name.
+     *
+     * Variables
+     *  name - the name to lookup.
+     */
+    static RPC *lookup(const char *name);
+
+protected:
+    static RPC *_head;
+    RPC *_next;
+    char *_name;
+    bool _from_construct;
+
+private:
+    static rpc_class *_classes;
+
+    static const rpc_function _RPC_funcs[];
+    static rpc_class _RPC_class;
+
+    void delete_self();
+    static void list_objs(Arguments *args, Reply *result);
+    static void clear(Arguments *args, Reply *result);
+
+public:
+    /* Function add_rpc_class
+     *  Add the class to the list of classes which can have static
+     *  methods called via rpc (the static methods which can be called
+     *  are defined by that class' get_rpc_class() static method).
+     */
+    template<class C>
+    static void add_rpc_class() {
+        rpc_class *c = C::get_rpc_class();
+        c->next = _classes;
+        _classes = c;
+    }
+    
+    template<class C>
+    static const char *construct() {
+        RPC *p = new C();
+        p->_from_construct = true;
+        return p->_name;
+    }
+    
+    template<class C, typename A1>
+    static const char *construct(A1 arg1) {
+        RPC *p = new C(arg1);
+        p->_from_construct = true;
+        return p->_name;
+    }
+    
+    template<class C, typename A1, typename A2>
+    static const char *construct(A1 arg1, A2 arg2) {
+        RPC *p = new C(arg1, arg2);
+        p->_from_construct = true;
+        return p->_name;
+    }
+    
+    template<class C, typename A1, typename A2, typename A3>
+    static const char *construct(A1 arg1, A2 arg2, A3 arg3) {
+        RPC *p = new C(arg1, arg2, arg3);
+        p->_from_construct = true;
+        return p->_name;
+    }
+    
+    template<class C, typename A1, typename A2, typename A3, typename A4>
+    static const char *construct(A1 arg1, A2 arg2, A3 arg3, A4 arg4) {
+        RPC *p = new C(arg1, arg2, arg3, arg4);
+        p->_from_construct = true;
+        return p->_name;
+    }
+};
+
+/* Macro MBED_OBJECT_NAME_MAX
+ *  The maximum size of object name (including terminating null byte)
+ *  that will be recognised when using fopen to open a FileLike
+ *  object, or when using the rpc function.
+ */
+#define MBED_OBJECT_NAME_MAX 32
+
+/* Macro MBED_METHOD_NAME_MAX
+ *  The maximum size of rpc method name (including terminating null
+ *  byte) that will be recognised by the rpc function (in rpc.h).
+ */
+#define MBED_METHOD_NAME_MAX 32
+
+/* Function rpc_method_caller
+ */
+template<class T, void(T::*member)(const char *, char *)>
+void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) {
+    (static_cast<T*>(this_ptr)->*member)(arguments, result);
+}
+
+/* Function rpc_method_caller
+ */
+template<class T, void(T::*member)()>
+void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) {
+    (static_cast<T*>(this_ptr)->*member)();
+}
+
+/* Function rpc_method_caller
+ */
+template<class T, typename A1, void(T::*member)(A1)>
+void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) {
+    A1 arg1 = arguments->getArg<A1>();
+    
+    (static_cast<T*>(this_ptr)->*member)(arg1);
+}
+
+/* Function rpc_method_caller
+ */
+template<class T, typename A1, typename A2, void(T::*member)(A1, A2)>
+void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) {
+    A1 arg1 = arguments->getArg<A1>();
+    A2 arg2 = arguments->getArg<A2>();
+    
+    (static_cast<T*>(this_ptr)->*member)(arg1, arg2);
+}
+
+/* Function rpc_method_caller
+ */
+template<class T, typename A1, typename A2, typename A3, void(T::*member)(A1, A2, A3)>
+void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) {
+    A1 arg1 = arguments->getArg<A1>();
+    A2 arg2 = arguments->getArg<A2>();
+    A3 arg3 = arguments->getArg<A3>();
+    
+    (static_cast<T*>(this_ptr)->*member)(arg1, arg2, arg3);
+}
+
+/* Function rpc_method_caller
+ */
+template<typename R, class T, R(T::*member)()>
+void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) {
+    R res = (static_cast<T*>(this_ptr)->*member)();
+    result->putData<R>(res);
+}
+
+/* Function rpc_method_caller
+ */
+template<typename R, class T, typename A1, R(T::*member)(A1)>
+void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) {
+    A1 arg1 = arguments->getArg<A1>();
+    
+    R res = (static_cast<T*>(this_ptr)->*member)(arg1);
+    result->putData<R>(res);
+}
+
+/* Function rpc_method_caller
+ */
+template<typename R, class T, typename A1, typename A2, R(T::*member)(A1, A2)>
+void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) {
+    A1 arg1 = arguments->getArg<A1>();
+    A2 arg2 = arguments->getArg<A2>();
+    
+    R res = (static_cast<T*>(this_ptr)->*member)(arg1, arg2);
+    result->putData<R>(res);
+}
+
+/* Function rpc_method_caller
+ */
+template<typename R, class T, typename A1, typename A2, typename A3, R(T::*member)(A1, A2, A3)>
+void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) {
+    A1 arg1 = arguments->getArg<A1>();
+    A2 arg2 = arguments->getArg<A2>();
+    A3 arg3 = arguments->getArg<A3>();
+    
+    R res = (static_cast<T*>(this_ptr)->*member)(arg1, arg2, arg3);
+    result->putData<R>(res);
+}
+
+/* Function rpc_function caller
+ */
+template<typename R, R(*func)()>
+void rpc_function_caller(Arguments *arguments, Reply *result) {
+    R res = (*func)();
+    result->putData<R>(res);
+}
+
+/* Function rpc_function caller
+ */
+template<typename R, typename A1, R(*func)(A1)>
+void rpc_function_caller(Arguments *arguments, Reply *result) {
+    A1 arg1 = arguments->getArg<A1>();
+    R res = (*func)(arg1);
+    result->putData<R>(res);
+}
+
+/* Function rpc_function caller
+ */
+template<typename R, typename A1, typename A2, R(*func)(A1, A2)>
+void rpc_function_caller(Arguments *arguments, Reply *result) {
+    A1 arg1 = arguments->getArg<A1>();
+    A2 arg2 = arguments->getArg<A2>();
+    
+    R res = (*func)(arg1, arg2);
+    result->putData<R>(res);
+}
+
+/* Function rpc_function caller
+ */
+template<typename R, typename A1, typename A2, typename A3, R(*func)(A1, A2, A3)>
+void rpc_function_caller(Arguments *arguments, Reply *result) {
+    A1 arg1 = arguments->getArg<A1>();
+    A2 arg2 = arguments->getArg<A2>();
+    A3 arg3 = arguments->getArg<A3>();
+    
+    R res = (*func)(arg1, arg2, arg3);
+    result->putData<R>(res);
+}
+
+/* Function rpc_function caller
+ */
+template<typename R, typename A1, typename A2, typename A3, typename A4, R(*func)(A1, A2, A3, A4)>
+void rpc_function_caller(Arguments *arguments, Reply *result) {
+    A1 arg1 = arguments->getArg<A1>();
+    A2 arg2 = arguments->getArg<A2>();
+    A3 arg3 = arguments->getArg<A3>();
+    A4 arg4 = arguments->getArg<A4>();
+    
+    R res = (*func)(arg1, arg2, arg3, arg4);
+    result->putData<R>(res);
+}
+
+struct rpc_method {
+    const char *name;
+    typedef void (*method_caller_t)(RPC*, Arguments*, Reply*);
+    typedef const struct rpc_method *(*super_t)(RPC*);
+    union {
+        method_caller_t method_caller;
+        super_t super;
+    };
+};
+
+template<class C>
+const struct rpc_method *rpc_super(RPC *this_ptr) {
+    return static_cast<C*>(this_ptr)->C::get_rpc_methods();
+}
+
+#define RPC_METHOD_END      { NULL, NULL }
+#define RPC_METHOD_SUPER(C) { NULL, (rpc_method::method_caller_t)rpc_super<C> }
+
+} // namespace mbed
+
+#endif