Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed
Fork of HTTPServerHelloWorld by
HardwareDrivers/mbed/rpc.h@4:a19825caaf41, 2014-02-01 (annotated)
- Committer:
- wyunreal
- Date:
- Sat Feb 01 17:29:15 2014 +0000
- Revision:
- 4:a19825caaf41
- Parent:
- mbed/rpc.h@3:5dc0023e6284
creating the application model
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| wyunreal | 3:5dc0023e6284 | 1 | /* mbed Microcontroller Library - RPC |
| wyunreal | 3:5dc0023e6284 | 2 | * Copyright (c) 2008-2009 ARM Limited. All rights reserved. |
| wyunreal | 3:5dc0023e6284 | 3 | * sford |
| wyunreal | 3:5dc0023e6284 | 4 | */ |
| wyunreal | 3:5dc0023e6284 | 5 | |
| wyunreal | 3:5dc0023e6284 | 6 | #ifndef MBED_RPC_H |
| wyunreal | 3:5dc0023e6284 | 7 | #define MBED_RPC_H |
| wyunreal | 3:5dc0023e6284 | 8 | |
| wyunreal | 3:5dc0023e6284 | 9 | /* Section rpc |
| wyunreal | 3:5dc0023e6284 | 10 | * Helpers for rpc handling. |
| wyunreal | 3:5dc0023e6284 | 11 | */ |
| wyunreal | 3:5dc0023e6284 | 12 | |
| wyunreal | 3:5dc0023e6284 | 13 | #include <stdlib.h> |
| wyunreal | 3:5dc0023e6284 | 14 | #include <stdio.h> |
| wyunreal | 3:5dc0023e6284 | 15 | #include <string.h> |
| wyunreal | 3:5dc0023e6284 | 16 | #include <ctype.h> |
| wyunreal | 3:5dc0023e6284 | 17 | #include "Base.h" |
| wyunreal | 3:5dc0023e6284 | 18 | |
| wyunreal | 3:5dc0023e6284 | 19 | #include "PinNames.h" |
| wyunreal | 3:5dc0023e6284 | 20 | #include <stdint.h> |
| wyunreal | 3:5dc0023e6284 | 21 | |
| wyunreal | 3:5dc0023e6284 | 22 | namespace mbed { |
| wyunreal | 3:5dc0023e6284 | 23 | |
| wyunreal | 3:5dc0023e6284 | 24 | /* Function parse_arg |
| wyunreal | 3:5dc0023e6284 | 25 | * Parses and returns a value from a string. |
| wyunreal | 3:5dc0023e6284 | 26 | * |
| wyunreal | 3:5dc0023e6284 | 27 | * Variable |
| wyunreal | 3:5dc0023e6284 | 28 | * arg - The string to pase |
| wyunreal | 3:5dc0023e6284 | 29 | * next - If not NULL a pointer to after the last |
| wyunreal | 3:5dc0023e6284 | 30 | * character parsed is written here |
| wyunreal | 3:5dc0023e6284 | 31 | */ |
| wyunreal | 3:5dc0023e6284 | 32 | template<typename T> T parse_arg(const char *arg, const char **next); |
| wyunreal | 3:5dc0023e6284 | 33 | |
| wyunreal | 3:5dc0023e6284 | 34 | inline char parse_char(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 35 | char c = *arg++; |
| wyunreal | 3:5dc0023e6284 | 36 | if(c == '\\') { |
| wyunreal | 3:5dc0023e6284 | 37 | c = *arg++; |
| wyunreal | 3:5dc0023e6284 | 38 | switch(c) { |
| wyunreal | 3:5dc0023e6284 | 39 | case 'a': c = '\a'; break; |
| wyunreal | 3:5dc0023e6284 | 40 | case 'b': c = '\b'; break; |
| wyunreal | 3:5dc0023e6284 | 41 | case 't': c = '\t'; break; |
| wyunreal | 3:5dc0023e6284 | 42 | case 'n': c = '\n'; break; |
| wyunreal | 3:5dc0023e6284 | 43 | case 'v': c = '\v'; break; |
| wyunreal | 3:5dc0023e6284 | 44 | case 'f': c = '\f'; break; |
| wyunreal | 3:5dc0023e6284 | 45 | case 'r': c = '\r'; break; |
| wyunreal | 3:5dc0023e6284 | 46 | case 'x': |
| wyunreal | 3:5dc0023e6284 | 47 | { |
| wyunreal | 3:5dc0023e6284 | 48 | /* two-character hexadecimal */ |
| wyunreal | 3:5dc0023e6284 | 49 | char buf[3]; |
| wyunreal | 3:5dc0023e6284 | 50 | buf[0] = *arg++; |
| wyunreal | 3:5dc0023e6284 | 51 | buf[1] = *arg++; |
| wyunreal | 3:5dc0023e6284 | 52 | buf[2] = 0; |
| wyunreal | 3:5dc0023e6284 | 53 | c = strtol(buf, NULL, 16); |
| wyunreal | 3:5dc0023e6284 | 54 | } |
| wyunreal | 3:5dc0023e6284 | 55 | break; |
| wyunreal | 3:5dc0023e6284 | 56 | default: |
| wyunreal | 3:5dc0023e6284 | 57 | if(isdigit(c)) { |
| wyunreal | 3:5dc0023e6284 | 58 | /* three-character octal */ |
| wyunreal | 3:5dc0023e6284 | 59 | char buf[4]; |
| wyunreal | 3:5dc0023e6284 | 60 | buf[0] = c; |
| wyunreal | 3:5dc0023e6284 | 61 | buf[1] = *arg++; |
| wyunreal | 3:5dc0023e6284 | 62 | buf[2] = *arg++; |
| wyunreal | 3:5dc0023e6284 | 63 | buf[3] = 0; |
| wyunreal | 3:5dc0023e6284 | 64 | c = strtol(buf, NULL, 8); |
| wyunreal | 3:5dc0023e6284 | 65 | } |
| wyunreal | 3:5dc0023e6284 | 66 | break; |
| wyunreal | 3:5dc0023e6284 | 67 | } |
| wyunreal | 3:5dc0023e6284 | 68 | } |
| wyunreal | 3:5dc0023e6284 | 69 | *next = arg; |
| wyunreal | 3:5dc0023e6284 | 70 | return c; |
| wyunreal | 3:5dc0023e6284 | 71 | } |
| wyunreal | 3:5dc0023e6284 | 72 | |
| wyunreal | 3:5dc0023e6284 | 73 | /* signed integer types */ |
| wyunreal | 3:5dc0023e6284 | 74 | |
| wyunreal | 3:5dc0023e6284 | 75 | template<> inline int parse_arg<int>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 76 | if(arg[0] == '\'') { |
| wyunreal | 3:5dc0023e6284 | 77 | char c = parse_char(arg+1, &arg); |
| wyunreal | 3:5dc0023e6284 | 78 | if(next != NULL) *next = arg+1; |
| wyunreal | 3:5dc0023e6284 | 79 | return c; |
| wyunreal | 3:5dc0023e6284 | 80 | } else { |
| wyunreal | 3:5dc0023e6284 | 81 | return strtol(arg, const_cast<char**>(next), 0); |
| wyunreal | 3:5dc0023e6284 | 82 | } |
| wyunreal | 3:5dc0023e6284 | 83 | } |
| wyunreal | 3:5dc0023e6284 | 84 | |
| wyunreal | 3:5dc0023e6284 | 85 | template<> inline char parse_arg<char>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 86 | return parse_arg<int>(arg,next); |
| wyunreal | 3:5dc0023e6284 | 87 | } |
| wyunreal | 3:5dc0023e6284 | 88 | |
| wyunreal | 3:5dc0023e6284 | 89 | template<> inline short int parse_arg<short int>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 90 | return parse_arg<int>(arg,next); |
| wyunreal | 3:5dc0023e6284 | 91 | } |
| wyunreal | 3:5dc0023e6284 | 92 | |
| wyunreal | 3:5dc0023e6284 | 93 | template<> inline long int parse_arg<long int>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 94 | return parse_arg<int>(arg,next); |
| wyunreal | 3:5dc0023e6284 | 95 | } |
| wyunreal | 3:5dc0023e6284 | 96 | |
| wyunreal | 3:5dc0023e6284 | 97 | template<> inline long long parse_arg<long long>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 98 | return strtoll(arg, const_cast<char**>(next), 0); |
| wyunreal | 3:5dc0023e6284 | 99 | } |
| wyunreal | 3:5dc0023e6284 | 100 | |
| wyunreal | 3:5dc0023e6284 | 101 | /* unsigned integer types */ |
| wyunreal | 3:5dc0023e6284 | 102 | |
| wyunreal | 3:5dc0023e6284 | 103 | template<> inline unsigned int parse_arg<unsigned int>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 104 | if(arg[0] == '\'') { |
| wyunreal | 3:5dc0023e6284 | 105 | char c = parse_char(arg+1, &arg); |
| wyunreal | 3:5dc0023e6284 | 106 | if(next != NULL) *next = arg+1; |
| wyunreal | 3:5dc0023e6284 | 107 | return c; |
| wyunreal | 3:5dc0023e6284 | 108 | } else { |
| wyunreal | 3:5dc0023e6284 | 109 | return strtoul(arg, const_cast<char**>(next), 0); |
| wyunreal | 3:5dc0023e6284 | 110 | } |
| wyunreal | 3:5dc0023e6284 | 111 | } |
| wyunreal | 3:5dc0023e6284 | 112 | |
| wyunreal | 3:5dc0023e6284 | 113 | template<> inline unsigned char parse_arg<unsigned char>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 114 | return parse_arg<unsigned int>(arg,next); |
| wyunreal | 3:5dc0023e6284 | 115 | } |
| wyunreal | 3:5dc0023e6284 | 116 | |
| wyunreal | 3:5dc0023e6284 | 117 | template<> inline unsigned short int parse_arg<unsigned short int>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 118 | return parse_arg<unsigned int>(arg,next); |
| wyunreal | 3:5dc0023e6284 | 119 | } |
| wyunreal | 3:5dc0023e6284 | 120 | |
| wyunreal | 3:5dc0023e6284 | 121 | template<> inline unsigned long int parse_arg<unsigned long int>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 122 | return parse_arg<unsigned int>(arg,next); |
| wyunreal | 3:5dc0023e6284 | 123 | } |
| wyunreal | 3:5dc0023e6284 | 124 | |
| wyunreal | 3:5dc0023e6284 | 125 | template<> inline unsigned long long parse_arg<unsigned long long>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 126 | return strtoull(arg, const_cast<char**>(next), 0); |
| wyunreal | 3:5dc0023e6284 | 127 | } |
| wyunreal | 3:5dc0023e6284 | 128 | |
| wyunreal | 3:5dc0023e6284 | 129 | /* floating types */ |
| wyunreal | 3:5dc0023e6284 | 130 | |
| wyunreal | 3:5dc0023e6284 | 131 | template<> inline float parse_arg<float>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 132 | #if !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 410000 |
| wyunreal | 3:5dc0023e6284 | 133 | return strtof(arg,const_cast<char**>(next)); |
| wyunreal | 3:5dc0023e6284 | 134 | #elif __ARMCC_VERSION >= 310000 |
| wyunreal | 3:5dc0023e6284 | 135 | /* bug in header means no using declaration for strtof */ |
| wyunreal | 3:5dc0023e6284 | 136 | return std::strtof(arg,const_cast<char**>(next)); |
| wyunreal | 3:5dc0023e6284 | 137 | #else |
| wyunreal | 3:5dc0023e6284 | 138 | /* strtof not supported */ |
| wyunreal | 3:5dc0023e6284 | 139 | return strtod(arg,const_cast<char**>(next)); |
| wyunreal | 3:5dc0023e6284 | 140 | #endif |
| wyunreal | 3:5dc0023e6284 | 141 | } |
| wyunreal | 3:5dc0023e6284 | 142 | |
| wyunreal | 3:5dc0023e6284 | 143 | template<> inline double parse_arg<double>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 144 | return strtod(arg,const_cast<char**>(next)); |
| wyunreal | 3:5dc0023e6284 | 145 | } |
| wyunreal | 3:5dc0023e6284 | 146 | |
| wyunreal | 3:5dc0023e6284 | 147 | template<> inline long double parse_arg<long double>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 148 | return strtod(arg,const_cast<char**>(next)); |
| wyunreal | 3:5dc0023e6284 | 149 | } |
| wyunreal | 3:5dc0023e6284 | 150 | |
| wyunreal | 3:5dc0023e6284 | 151 | /* string */ |
| wyunreal | 3:5dc0023e6284 | 152 | |
| wyunreal | 3:5dc0023e6284 | 153 | template<> inline char *parse_arg<char*>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 154 | const char *ptr = arg; |
| wyunreal | 3:5dc0023e6284 | 155 | char *res = NULL; |
| wyunreal | 3:5dc0023e6284 | 156 | if(*arg == '"') { |
| wyunreal | 3:5dc0023e6284 | 157 | /* quoted string */ |
| wyunreal | 3:5dc0023e6284 | 158 | ptr = ++arg; |
| wyunreal | 3:5dc0023e6284 | 159 | int len = 0; |
| wyunreal | 3:5dc0023e6284 | 160 | /* find the end (and length) of the quoted string */ |
| wyunreal | 3:5dc0023e6284 | 161 | for(char c = *ptr; c != 0 && c != '"'; c = *++ptr) { |
| wyunreal | 3:5dc0023e6284 | 162 | len++; |
| wyunreal | 3:5dc0023e6284 | 163 | if(c == '\\') { |
| wyunreal | 3:5dc0023e6284 | 164 | ptr++; |
| wyunreal | 3:5dc0023e6284 | 165 | } |
| wyunreal | 3:5dc0023e6284 | 166 | } |
| wyunreal | 3:5dc0023e6284 | 167 | /* copy the quoted string, and unescape characters */ |
| wyunreal | 3:5dc0023e6284 | 168 | if(len != 0) { |
| wyunreal | 3:5dc0023e6284 | 169 | res = new char[len+1]; |
| wyunreal | 3:5dc0023e6284 | 170 | char *resptr = res; |
| wyunreal | 3:5dc0023e6284 | 171 | while(arg != ptr) { |
| wyunreal | 3:5dc0023e6284 | 172 | *resptr++ = parse_char(arg, &arg); |
| wyunreal | 3:5dc0023e6284 | 173 | } |
| wyunreal | 3:5dc0023e6284 | 174 | *resptr = 0; |
| wyunreal | 3:5dc0023e6284 | 175 | } |
| wyunreal | 3:5dc0023e6284 | 176 | } else { |
| wyunreal | 3:5dc0023e6284 | 177 | /* unquoted string */ |
| wyunreal | 3:5dc0023e6284 | 178 | while(isalnum(*ptr) || *ptr=='_') { |
| wyunreal | 3:5dc0023e6284 | 179 | ptr++; |
| wyunreal | 3:5dc0023e6284 | 180 | } |
| wyunreal | 3:5dc0023e6284 | 181 | int len = ptr-arg; |
| wyunreal | 3:5dc0023e6284 | 182 | if(len!=0) { |
| wyunreal | 3:5dc0023e6284 | 183 | res = new char[len+1]; |
| wyunreal | 3:5dc0023e6284 | 184 | memcpy(res, arg, len); |
| wyunreal | 3:5dc0023e6284 | 185 | res[len] = 0; |
| wyunreal | 3:5dc0023e6284 | 186 | } |
| wyunreal | 3:5dc0023e6284 | 187 | } |
| wyunreal | 3:5dc0023e6284 | 188 | |
| wyunreal | 3:5dc0023e6284 | 189 | if(next != NULL) { |
| wyunreal | 3:5dc0023e6284 | 190 | *next = ptr; |
| wyunreal | 3:5dc0023e6284 | 191 | } |
| wyunreal | 3:5dc0023e6284 | 192 | return res; |
| wyunreal | 3:5dc0023e6284 | 193 | } |
| wyunreal | 3:5dc0023e6284 | 194 | |
| wyunreal | 3:5dc0023e6284 | 195 | template<> inline const char *parse_arg<const char*>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 196 | return parse_arg<char*>(arg,next); |
| wyunreal | 3:5dc0023e6284 | 197 | } |
| wyunreal | 3:5dc0023e6284 | 198 | |
| wyunreal | 3:5dc0023e6284 | 199 | /* Pins */ |
| wyunreal | 3:5dc0023e6284 | 200 | |
| wyunreal | 3:5dc0023e6284 | 201 | |
| wyunreal | 3:5dc0023e6284 | 202 | inline PinName parse_pins(const char *str) { |
| wyunreal | 3:5dc0023e6284 | 203 | const PinName pin_names[] = {p5, p6, p7, p8, p9, p10, p11, p12, p13, p14 |
| wyunreal | 3:5dc0023e6284 | 204 | , p15, p16, p17, p18, p19, p20, p21, p22, p23 |
| wyunreal | 3:5dc0023e6284 | 205 | , p24, p25, p26, p27, p28, p29, p30}; |
| wyunreal | 3:5dc0023e6284 | 206 | |
| wyunreal | 3:5dc0023e6284 | 207 | if(str[0] == 'P') { // Pn_n |
| wyunreal | 3:5dc0023e6284 | 208 | uint32_t port = str[1] - '0'; |
| wyunreal | 3:5dc0023e6284 | 209 | uint32_t pin = str[3] - '0'; // Pn_n |
| wyunreal | 3:5dc0023e6284 | 210 | uint32_t pin2 = str[4] - '0'; // Pn_nn |
| wyunreal | 3:5dc0023e6284 | 211 | if(pin2 <= 9) { |
| wyunreal | 3:5dc0023e6284 | 212 | pin = pin * 10 + pin2; |
| wyunreal | 3:5dc0023e6284 | 213 | } |
| wyunreal | 3:5dc0023e6284 | 214 | return (PinName)(LPC_GPIO0_BASE + port * 32 + pin); |
| wyunreal | 3:5dc0023e6284 | 215 | } else if(str[0] == 'p') { // pn |
| wyunreal | 3:5dc0023e6284 | 216 | uint32_t pin = str[1] - '0'; // pn |
| wyunreal | 3:5dc0023e6284 | 217 | uint32_t pin2 = str[2] - '0'; // pnn |
| wyunreal | 3:5dc0023e6284 | 218 | if(pin2 <= 9) { |
| wyunreal | 3:5dc0023e6284 | 219 | pin = pin * 10 + pin2; |
| wyunreal | 3:5dc0023e6284 | 220 | } |
| wyunreal | 3:5dc0023e6284 | 221 | if(pin < 5 || pin > 30) { |
| wyunreal | 3:5dc0023e6284 | 222 | return NC; |
| wyunreal | 3:5dc0023e6284 | 223 | } |
| wyunreal | 3:5dc0023e6284 | 224 | return pin_names[pin - 5]; |
| wyunreal | 3:5dc0023e6284 | 225 | } else if(str[0] == 'L') { // LEDn |
| wyunreal | 3:5dc0023e6284 | 226 | switch(str[3]) { |
| wyunreal | 3:5dc0023e6284 | 227 | case '1' : return LED1; |
| wyunreal | 3:5dc0023e6284 | 228 | case '2' : return LED2; |
| wyunreal | 3:5dc0023e6284 | 229 | case '3' : return LED3; |
| wyunreal | 3:5dc0023e6284 | 230 | case '4' : return LED4; |
| wyunreal | 3:5dc0023e6284 | 231 | } |
| wyunreal | 3:5dc0023e6284 | 232 | } else if(str[0] == 'U') { // USB?X |
| wyunreal | 3:5dc0023e6284 | 233 | switch(str[3]) { |
| wyunreal | 3:5dc0023e6284 | 234 | case 'T' : return USBTX; |
| wyunreal | 3:5dc0023e6284 | 235 | case 'R' : return USBRX; |
| wyunreal | 3:5dc0023e6284 | 236 | } |
| wyunreal | 3:5dc0023e6284 | 237 | } |
| wyunreal | 3:5dc0023e6284 | 238 | return NC; |
| wyunreal | 3:5dc0023e6284 | 239 | } |
| wyunreal | 3:5dc0023e6284 | 240 | |
| wyunreal | 3:5dc0023e6284 | 241 | template<> inline PinName parse_arg<PinName>(const char *arg, const char **next) { |
| wyunreal | 3:5dc0023e6284 | 242 | const char *ptr = arg; |
| wyunreal | 3:5dc0023e6284 | 243 | PinName pinname = NC; |
| wyunreal | 3:5dc0023e6284 | 244 | while(isalnum(*ptr) || *ptr=='_') { |
| wyunreal | 3:5dc0023e6284 | 245 | ptr++; |
| wyunreal | 3:5dc0023e6284 | 246 | } |
| wyunreal | 3:5dc0023e6284 | 247 | int len = ptr-arg; |
| wyunreal | 3:5dc0023e6284 | 248 | if(len!=0) { |
| wyunreal | 3:5dc0023e6284 | 249 | pinname = parse_pins(arg); |
| wyunreal | 3:5dc0023e6284 | 250 | |
| wyunreal | 3:5dc0023e6284 | 251 | } |
| wyunreal | 3:5dc0023e6284 | 252 | if(next != NULL) { |
| wyunreal | 3:5dc0023e6284 | 253 | *next = ptr; |
| wyunreal | 3:5dc0023e6284 | 254 | } |
| wyunreal | 3:5dc0023e6284 | 255 | return pinname; |
| wyunreal | 3:5dc0023e6284 | 256 | } |
| wyunreal | 3:5dc0023e6284 | 257 | |
| wyunreal | 3:5dc0023e6284 | 258 | |
| wyunreal | 3:5dc0023e6284 | 259 | /* Function write_result |
| wyunreal | 3:5dc0023e6284 | 260 | * Writes a value in to a result string in an appropriate manner |
| wyunreal | 3:5dc0023e6284 | 261 | * |
| wyunreal | 3:5dc0023e6284 | 262 | * Variable |
| wyunreal | 3:5dc0023e6284 | 263 | * val - The value to write |
| wyunreal | 3:5dc0023e6284 | 264 | * result - A pointer to the array to write the value into |
| wyunreal | 3:5dc0023e6284 | 265 | */ |
| wyunreal | 3:5dc0023e6284 | 266 | template<typename T> void write_result(T val, char *result); |
| wyunreal | 3:5dc0023e6284 | 267 | |
| wyunreal | 3:5dc0023e6284 | 268 | /* signed integer types */ |
| wyunreal | 3:5dc0023e6284 | 269 | |
| wyunreal | 3:5dc0023e6284 | 270 | template<> inline void write_result<char>(char val, char *result) { |
| wyunreal | 3:5dc0023e6284 | 271 | result[0] = val; |
| wyunreal | 3:5dc0023e6284 | 272 | result[1] = '\0'; |
| wyunreal | 3:5dc0023e6284 | 273 | } |
| wyunreal | 3:5dc0023e6284 | 274 | |
| wyunreal | 3:5dc0023e6284 | 275 | template<> inline void write_result<short int>(short int val, char *result) { |
| wyunreal | 3:5dc0023e6284 | 276 | sprintf(result, "%hi", val); |
| wyunreal | 3:5dc0023e6284 | 277 | } |
| wyunreal | 3:5dc0023e6284 | 278 | |
| wyunreal | 3:5dc0023e6284 | 279 | template<> inline void write_result<int>(int val, char *result) { |
| wyunreal | 3:5dc0023e6284 | 280 | sprintf(result, "%i", val); |
| wyunreal | 3:5dc0023e6284 | 281 | } |
| wyunreal | 3:5dc0023e6284 | 282 | |
| wyunreal | 3:5dc0023e6284 | 283 | template<> inline void write_result<long int>(long int val, char *result) { |
| wyunreal | 3:5dc0023e6284 | 284 | sprintf(result, "%li", val); |
| wyunreal | 3:5dc0023e6284 | 285 | } |
| wyunreal | 3:5dc0023e6284 | 286 | |
| wyunreal | 3:5dc0023e6284 | 287 | template<> inline void write_result<long long int>(long long int val, char *result) { |
| wyunreal | 3:5dc0023e6284 | 288 | sprintf(result, "%lli", val); |
| wyunreal | 3:5dc0023e6284 | 289 | } |
| wyunreal | 3:5dc0023e6284 | 290 | |
| wyunreal | 3:5dc0023e6284 | 291 | /* unsigned integer types */ |
| wyunreal | 3:5dc0023e6284 | 292 | |
| wyunreal | 3:5dc0023e6284 | 293 | template<> inline void write_result<unsigned char>(unsigned char val, char *result) { |
| wyunreal | 3:5dc0023e6284 | 294 | result[0] = val; |
| wyunreal | 3:5dc0023e6284 | 295 | result[1] = '\0'; |
| wyunreal | 3:5dc0023e6284 | 296 | } |
| wyunreal | 3:5dc0023e6284 | 297 | |
| wyunreal | 3:5dc0023e6284 | 298 | template<> inline void write_result<unsigned short int>(unsigned short int val, char *result) { |
| wyunreal | 3:5dc0023e6284 | 299 | sprintf(result, "%hu", val); |
| wyunreal | 3:5dc0023e6284 | 300 | } |
| wyunreal | 3:5dc0023e6284 | 301 | |
| wyunreal | 3:5dc0023e6284 | 302 | template<> inline void write_result<unsigned int>(unsigned int val, char *result) { |
| wyunreal | 3:5dc0023e6284 | 303 | sprintf(result, "%u", val); |
| wyunreal | 3:5dc0023e6284 | 304 | } |
| wyunreal | 3:5dc0023e6284 | 305 | |
| wyunreal | 3:5dc0023e6284 | 306 | template<> inline void write_result<unsigned long int>(unsigned long int val, char *result) { |
| wyunreal | 3:5dc0023e6284 | 307 | sprintf(result, "%lu", val); |
| wyunreal | 3:5dc0023e6284 | 308 | } |
| wyunreal | 3:5dc0023e6284 | 309 | |
| wyunreal | 3:5dc0023e6284 | 310 | template<> inline void write_result<unsigned long long int>(unsigned long long int val, char *result) { |
| wyunreal | 3:5dc0023e6284 | 311 | sprintf(result, "%llu", val); |
| wyunreal | 3:5dc0023e6284 | 312 | } |
| wyunreal | 3:5dc0023e6284 | 313 | |
| wyunreal | 3:5dc0023e6284 | 314 | /* floating types */ |
| wyunreal | 3:5dc0023e6284 | 315 | |
| wyunreal | 3:5dc0023e6284 | 316 | template<> inline void write_result<float>(float val, char *result) { |
| wyunreal | 3:5dc0023e6284 | 317 | sprintf(result, "%.17g", val); |
| wyunreal | 3:5dc0023e6284 | 318 | } |
| wyunreal | 3:5dc0023e6284 | 319 | |
| wyunreal | 3:5dc0023e6284 | 320 | template<> inline void write_result<double>(double val, char *result) { |
| wyunreal | 3:5dc0023e6284 | 321 | sprintf(result, "%.17g", val); |
| wyunreal | 3:5dc0023e6284 | 322 | } |
| wyunreal | 3:5dc0023e6284 | 323 | |
| wyunreal | 3:5dc0023e6284 | 324 | template<> inline void write_result<long double>(long double val, char *result) { |
| wyunreal | 3:5dc0023e6284 | 325 | sprintf(result, "%.17Lg", val); |
| wyunreal | 3:5dc0023e6284 | 326 | } |
| wyunreal | 3:5dc0023e6284 | 327 | |
| wyunreal | 3:5dc0023e6284 | 328 | |
| wyunreal | 3:5dc0023e6284 | 329 | /* string */ |
| wyunreal | 3:5dc0023e6284 | 330 | |
| wyunreal | 3:5dc0023e6284 | 331 | template<> inline void write_result<char*>(char *val, char *result) { |
| wyunreal | 3:5dc0023e6284 | 332 | if(val==NULL) { |
| wyunreal | 3:5dc0023e6284 | 333 | result[0] = 0; |
| wyunreal | 3:5dc0023e6284 | 334 | } else { |
| wyunreal | 3:5dc0023e6284 | 335 | strcpy(result, val); |
| wyunreal | 3:5dc0023e6284 | 336 | } |
| wyunreal | 3:5dc0023e6284 | 337 | } |
| wyunreal | 3:5dc0023e6284 | 338 | |
| wyunreal | 3:5dc0023e6284 | 339 | template<> inline void write_result<const char*>(const char *val, char *result) { |
| wyunreal | 3:5dc0023e6284 | 340 | if(val==NULL) { |
| wyunreal | 3:5dc0023e6284 | 341 | result[0] = 0; |
| wyunreal | 3:5dc0023e6284 | 342 | } else { |
| wyunreal | 3:5dc0023e6284 | 343 | strcpy(result, val); |
| wyunreal | 3:5dc0023e6284 | 344 | } |
| wyunreal | 3:5dc0023e6284 | 345 | } |
| wyunreal | 3:5dc0023e6284 | 346 | |
| wyunreal | 3:5dc0023e6284 | 347 | |
| wyunreal | 3:5dc0023e6284 | 348 | inline const char *next_arg(const char* next) { |
| wyunreal | 3:5dc0023e6284 | 349 | while(*next == ' ') next++; |
| wyunreal | 3:5dc0023e6284 | 350 | if(*next == ',' || *next == '?') next++; |
| wyunreal | 3:5dc0023e6284 | 351 | while(*next == ' ') next++; |
| wyunreal | 3:5dc0023e6284 | 352 | return next; |
| wyunreal | 3:5dc0023e6284 | 353 | } |
| wyunreal | 3:5dc0023e6284 | 354 | |
| wyunreal | 3:5dc0023e6284 | 355 | |
| wyunreal | 3:5dc0023e6284 | 356 | /* Function rpc_method_caller |
| wyunreal | 3:5dc0023e6284 | 357 | */ |
| wyunreal | 3:5dc0023e6284 | 358 | template<class T, void (T::*member)(const char *,char *)> |
| wyunreal | 3:5dc0023e6284 | 359 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
| wyunreal | 3:5dc0023e6284 | 360 | (static_cast<T*>(this_ptr)->*member)(arguments,result); |
| wyunreal | 3:5dc0023e6284 | 361 | } |
| wyunreal | 3:5dc0023e6284 | 362 | |
| wyunreal | 3:5dc0023e6284 | 363 | |
| wyunreal | 3:5dc0023e6284 | 364 | /* Function rpc_method_caller |
| wyunreal | 3:5dc0023e6284 | 365 | */ |
| wyunreal | 3:5dc0023e6284 | 366 | template<class T, void (T::*member)()> |
| wyunreal | 3:5dc0023e6284 | 367 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
| wyunreal | 3:5dc0023e6284 | 368 | (static_cast<T*>(this_ptr)->*member)(); |
| wyunreal | 3:5dc0023e6284 | 369 | if(result != NULL) { |
| wyunreal | 3:5dc0023e6284 | 370 | result[0] = '\0'; |
| wyunreal | 3:5dc0023e6284 | 371 | } |
| wyunreal | 3:5dc0023e6284 | 372 | } |
| wyunreal | 3:5dc0023e6284 | 373 | |
| wyunreal | 3:5dc0023e6284 | 374 | |
| wyunreal | 3:5dc0023e6284 | 375 | /* Function rpc_method_caller |
| wyunreal | 3:5dc0023e6284 | 376 | */ |
| wyunreal | 3:5dc0023e6284 | 377 | template<class T, typename A1, void (T::*member)(A1)> |
| wyunreal | 3:5dc0023e6284 | 378 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
| wyunreal | 3:5dc0023e6284 | 379 | |
| wyunreal | 3:5dc0023e6284 | 380 | const char *next = arguments; |
| wyunreal | 3:5dc0023e6284 | 381 | A1 arg1 = parse_arg<A1>(next_arg(next),NULL); |
| wyunreal | 3:5dc0023e6284 | 382 | |
| wyunreal | 3:5dc0023e6284 | 383 | (static_cast<T*>(this_ptr)->*member)(arg1); |
| wyunreal | 3:5dc0023e6284 | 384 | if(result != NULL) { |
| wyunreal | 3:5dc0023e6284 | 385 | result[0] = '\0'; |
| wyunreal | 3:5dc0023e6284 | 386 | } |
| wyunreal | 3:5dc0023e6284 | 387 | } |
| wyunreal | 3:5dc0023e6284 | 388 | |
| wyunreal | 3:5dc0023e6284 | 389 | |
| wyunreal | 3:5dc0023e6284 | 390 | /* Function rpc_method_caller |
| wyunreal | 3:5dc0023e6284 | 391 | */ |
| wyunreal | 3:5dc0023e6284 | 392 | template<class T, typename A1, typename A2, void (T::*member)(A1,A2)> |
| wyunreal | 3:5dc0023e6284 | 393 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
| wyunreal | 3:5dc0023e6284 | 394 | |
| wyunreal | 3:5dc0023e6284 | 395 | const char *next = arguments; |
| wyunreal | 3:5dc0023e6284 | 396 | A1 arg1 = parse_arg<A1>(next_arg(next),&next); |
| wyunreal | 3:5dc0023e6284 | 397 | A2 arg2 = parse_arg<A2>(next_arg(next),NULL); |
| wyunreal | 3:5dc0023e6284 | 398 | |
| wyunreal | 3:5dc0023e6284 | 399 | (static_cast<T*>(this_ptr)->*member)(arg1,arg2); |
| wyunreal | 3:5dc0023e6284 | 400 | if(result != NULL) { |
| wyunreal | 3:5dc0023e6284 | 401 | result[0] = '\0'; |
| wyunreal | 3:5dc0023e6284 | 402 | } |
| wyunreal | 3:5dc0023e6284 | 403 | } |
| wyunreal | 3:5dc0023e6284 | 404 | |
| wyunreal | 3:5dc0023e6284 | 405 | |
| wyunreal | 3:5dc0023e6284 | 406 | /* Function rpc_method_caller |
| wyunreal | 3:5dc0023e6284 | 407 | */ |
| wyunreal | 3:5dc0023e6284 | 408 | template<class T, typename A1, typename A2, typename A3, void (T::*member)(A1,A2,A3)> |
| wyunreal | 3:5dc0023e6284 | 409 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
| wyunreal | 3:5dc0023e6284 | 410 | |
| wyunreal | 3:5dc0023e6284 | 411 | const char *next = arguments; |
| wyunreal | 3:5dc0023e6284 | 412 | A1 arg1 = parse_arg<A1>(next_arg(next),&next); |
| wyunreal | 3:5dc0023e6284 | 413 | A2 arg2 = parse_arg<A2>(next_arg(next),&next); |
| wyunreal | 3:5dc0023e6284 | 414 | A3 arg3 = parse_arg<A3>(next_arg(next),NULL); |
| wyunreal | 3:5dc0023e6284 | 415 | |
| wyunreal | 3:5dc0023e6284 | 416 | (static_cast<T*>(this_ptr)->*member)(arg1,arg2,arg3); |
| wyunreal | 3:5dc0023e6284 | 417 | if(result != NULL) { |
| wyunreal | 3:5dc0023e6284 | 418 | result[0] = '\0'; |
| wyunreal | 3:5dc0023e6284 | 419 | } |
| wyunreal | 3:5dc0023e6284 | 420 | } |
| wyunreal | 3:5dc0023e6284 | 421 | |
| wyunreal | 3:5dc0023e6284 | 422 | |
| wyunreal | 3:5dc0023e6284 | 423 | /* Function rpc_method_caller |
| wyunreal | 3:5dc0023e6284 | 424 | */ |
| wyunreal | 3:5dc0023e6284 | 425 | template<typename R, class T, R (T::*member)()> |
| wyunreal | 3:5dc0023e6284 | 426 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
| wyunreal | 3:5dc0023e6284 | 427 | R res = (static_cast<T*>(this_ptr)->*member)(); |
| wyunreal | 3:5dc0023e6284 | 428 | if(result != NULL) { |
| wyunreal | 3:5dc0023e6284 | 429 | write_result<R>(res, result); |
| wyunreal | 3:5dc0023e6284 | 430 | } |
| wyunreal | 3:5dc0023e6284 | 431 | } |
| wyunreal | 3:5dc0023e6284 | 432 | |
| wyunreal | 3:5dc0023e6284 | 433 | |
| wyunreal | 3:5dc0023e6284 | 434 | /* Function rpc_method_caller |
| wyunreal | 3:5dc0023e6284 | 435 | */ |
| wyunreal | 3:5dc0023e6284 | 436 | template<typename R, class T, typename A1, R (T::*member)(A1)> |
| wyunreal | 3:5dc0023e6284 | 437 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
| wyunreal | 3:5dc0023e6284 | 438 | |
| wyunreal | 3:5dc0023e6284 | 439 | const char *next = arguments; |
| wyunreal | 3:5dc0023e6284 | 440 | A1 arg1 = parse_arg<A1>(next_arg(next),NULL); |
| wyunreal | 3:5dc0023e6284 | 441 | |
| wyunreal | 3:5dc0023e6284 | 442 | R res = (static_cast<T*>(this_ptr)->*member)(arg1); |
| wyunreal | 3:5dc0023e6284 | 443 | if(result != NULL) { |
| wyunreal | 3:5dc0023e6284 | 444 | write_result<R>(res, result); |
| wyunreal | 3:5dc0023e6284 | 445 | } |
| wyunreal | 3:5dc0023e6284 | 446 | } |
| wyunreal | 3:5dc0023e6284 | 447 | |
| wyunreal | 3:5dc0023e6284 | 448 | |
| wyunreal | 3:5dc0023e6284 | 449 | /* Function rpc_method_caller |
| wyunreal | 3:5dc0023e6284 | 450 | */ |
| wyunreal | 3:5dc0023e6284 | 451 | template<typename R, class T, typename A1, typename A2, R (T::*member)(A1,A2)> |
| wyunreal | 3:5dc0023e6284 | 452 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
| wyunreal | 3:5dc0023e6284 | 453 | |
| wyunreal | 3:5dc0023e6284 | 454 | const char *next = arguments; |
| wyunreal | 3:5dc0023e6284 | 455 | A1 arg1 = parse_arg<A1>(next_arg(next),&next); |
| wyunreal | 3:5dc0023e6284 | 456 | A2 arg2 = parse_arg<A2>(next_arg(next),NULL); |
| wyunreal | 3:5dc0023e6284 | 457 | |
| wyunreal | 3:5dc0023e6284 | 458 | R res = (static_cast<T*>(this_ptr)->*member)(arg1,arg2); |
| wyunreal | 3:5dc0023e6284 | 459 | if(result != NULL) { |
| wyunreal | 3:5dc0023e6284 | 460 | write_result<R>(res, result); |
| wyunreal | 3:5dc0023e6284 | 461 | } |
| wyunreal | 3:5dc0023e6284 | 462 | } |
| wyunreal | 3:5dc0023e6284 | 463 | |
| wyunreal | 3:5dc0023e6284 | 464 | |
| wyunreal | 3:5dc0023e6284 | 465 | /* Function rpc_method_caller |
| wyunreal | 3:5dc0023e6284 | 466 | */ |
| wyunreal | 3:5dc0023e6284 | 467 | template<typename R, class T, typename A1, typename A2, typename A3, R (T::*member)(A1,A2,A3)> |
| wyunreal | 3:5dc0023e6284 | 468 | void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { |
| wyunreal | 3:5dc0023e6284 | 469 | |
| wyunreal | 3:5dc0023e6284 | 470 | const char *next = arguments; |
| wyunreal | 3:5dc0023e6284 | 471 | A1 arg1 = parse_arg<A1>(next_arg(next),&next); |
| wyunreal | 3:5dc0023e6284 | 472 | A2 arg2 = parse_arg<A2>(next_arg(next),&next); |
| wyunreal | 3:5dc0023e6284 | 473 | A3 arg3 = parse_arg<A3>(next_arg(next),NULL); |
| wyunreal | 3:5dc0023e6284 | 474 | |
| wyunreal | 3:5dc0023e6284 | 475 | R res = (static_cast<T*>(this_ptr)->*member)(arg1,arg2,arg3); |
| wyunreal | 3:5dc0023e6284 | 476 | if(result != NULL) { |
| wyunreal | 3:5dc0023e6284 | 477 | write_result<R>(res, result); |
| wyunreal | 3:5dc0023e6284 | 478 | } |
| wyunreal | 3:5dc0023e6284 | 479 | } |
| wyunreal | 3:5dc0023e6284 | 480 | |
| wyunreal | 3:5dc0023e6284 | 481 | |
| wyunreal | 3:5dc0023e6284 | 482 | /* Function rpc_function caller |
| wyunreal | 3:5dc0023e6284 | 483 | */ |
| wyunreal | 3:5dc0023e6284 | 484 | template<typename R, R (*func)()> |
| wyunreal | 3:5dc0023e6284 | 485 | void rpc_function_caller(const char *arguments, char *result) { |
| wyunreal | 3:5dc0023e6284 | 486 | R res = (*func)(); |
| wyunreal | 3:5dc0023e6284 | 487 | if(result != NULL) { |
| wyunreal | 3:5dc0023e6284 | 488 | write_result<R>(res, result); |
| wyunreal | 3:5dc0023e6284 | 489 | } |
| wyunreal | 3:5dc0023e6284 | 490 | } |
| wyunreal | 3:5dc0023e6284 | 491 | |
| wyunreal | 3:5dc0023e6284 | 492 | |
| wyunreal | 3:5dc0023e6284 | 493 | /* Function rpc_function caller |
| wyunreal | 3:5dc0023e6284 | 494 | */ |
| wyunreal | 3:5dc0023e6284 | 495 | template<typename R, typename A1, R (*func)(A1)> |
| wyunreal | 3:5dc0023e6284 | 496 | void rpc_function_caller(const char *arguments, char *result) { |
| wyunreal | 3:5dc0023e6284 | 497 | A1 arg1 = parse_arg<A1>(next_arg(arguments),NULL); |
| wyunreal | 3:5dc0023e6284 | 498 | R res = (*func)(arg1); |
| wyunreal | 3:5dc0023e6284 | 499 | if(result != NULL) { |
| wyunreal | 3:5dc0023e6284 | 500 | write_result<R>(res, result); |
| wyunreal | 3:5dc0023e6284 | 501 | } |
| wyunreal | 3:5dc0023e6284 | 502 | } |
| wyunreal | 3:5dc0023e6284 | 503 | |
| wyunreal | 3:5dc0023e6284 | 504 | |
| wyunreal | 3:5dc0023e6284 | 505 | /* Function rpc_function caller |
| wyunreal | 3:5dc0023e6284 | 506 | */ |
| wyunreal | 3:5dc0023e6284 | 507 | template<typename R, typename A1, typename A2, R (*func)(A1,A2)> |
| wyunreal | 3:5dc0023e6284 | 508 | void rpc_function_caller(const char *arguments, char *result) { |
| wyunreal | 3:5dc0023e6284 | 509 | |
| wyunreal | 3:5dc0023e6284 | 510 | const char *next = arguments; |
| wyunreal | 3:5dc0023e6284 | 511 | A1 arg1 = parse_arg<A1>(next_arg(next),&next); |
| wyunreal | 3:5dc0023e6284 | 512 | A2 arg2 = parse_arg<A2>(next_arg(next),NULL); |
| wyunreal | 3:5dc0023e6284 | 513 | |
| wyunreal | 3:5dc0023e6284 | 514 | R res = (*func)(arg1,arg2); |
| wyunreal | 3:5dc0023e6284 | 515 | if(result != NULL) { |
| wyunreal | 3:5dc0023e6284 | 516 | write_result<R>(res, result); |
| wyunreal | 3:5dc0023e6284 | 517 | } |
| wyunreal | 3:5dc0023e6284 | 518 | } |
| wyunreal | 3:5dc0023e6284 | 519 | |
| wyunreal | 3:5dc0023e6284 | 520 | |
| wyunreal | 3:5dc0023e6284 | 521 | /* Function rpc_function caller |
| wyunreal | 3:5dc0023e6284 | 522 | */ |
| wyunreal | 3:5dc0023e6284 | 523 | template<typename R, typename A1, typename A2, typename A3, R (*func)(A1,A2,A3)> |
| wyunreal | 3:5dc0023e6284 | 524 | void rpc_function_caller(const char *arguments, char *result) { |
| wyunreal | 3:5dc0023e6284 | 525 | |
| wyunreal | 3:5dc0023e6284 | 526 | const char *next = arguments; |
| wyunreal | 3:5dc0023e6284 | 527 | A1 arg1 = parse_arg<A1>(next_arg(next),&next); |
| wyunreal | 3:5dc0023e6284 | 528 | A2 arg2 = parse_arg<A2>(next_arg(next),&next); |
| wyunreal | 3:5dc0023e6284 | 529 | A3 arg3 = parse_arg<A3>(next_arg(next),NULL); |
| wyunreal | 3:5dc0023e6284 | 530 | |
| wyunreal | 3:5dc0023e6284 | 531 | R res = (*func)(arg1,arg2,arg3); |
| wyunreal | 3:5dc0023e6284 | 532 | if(result != NULL) { |
| wyunreal | 3:5dc0023e6284 | 533 | write_result<R>(res, result); |
| wyunreal | 3:5dc0023e6284 | 534 | } |
| wyunreal | 3:5dc0023e6284 | 535 | } |
| wyunreal | 3:5dc0023e6284 | 536 | |
| wyunreal | 3:5dc0023e6284 | 537 | |
| wyunreal | 3:5dc0023e6284 | 538 | /* Function rpc_function caller |
| wyunreal | 3:5dc0023e6284 | 539 | */ |
| wyunreal | 3:5dc0023e6284 | 540 | template<typename R, typename A1, typename A2, typename A3, typename A4, R (*func)(A1,A2,A3,A4)> |
| wyunreal | 3:5dc0023e6284 | 541 | void rpc_function_caller(const char *arguments, char *result) { |
| wyunreal | 3:5dc0023e6284 | 542 | |
| wyunreal | 3:5dc0023e6284 | 543 | const char *next = arguments; |
| wyunreal | 3:5dc0023e6284 | 544 | A1 arg1 = parse_arg<A1>(next_arg(next),&next); |
| wyunreal | 3:5dc0023e6284 | 545 | A2 arg2 = parse_arg<A2>(next_arg(next),&next); |
| wyunreal | 3:5dc0023e6284 | 546 | A3 arg3 = parse_arg<A3>(next_arg(next),&next); |
| wyunreal | 3:5dc0023e6284 | 547 | A4 arg4 = parse_arg<A4>(next_arg(next),NULL); |
| wyunreal | 3:5dc0023e6284 | 548 | |
| wyunreal | 3:5dc0023e6284 | 549 | R res = (*func)(arg1,arg2,arg3,arg4); |
| wyunreal | 3:5dc0023e6284 | 550 | if(result != NULL) { |
| wyunreal | 3:5dc0023e6284 | 551 | write_result<R>(res, result); |
| wyunreal | 3:5dc0023e6284 | 552 | } |
| wyunreal | 3:5dc0023e6284 | 553 | } |
| wyunreal | 3:5dc0023e6284 | 554 | |
| wyunreal | 3:5dc0023e6284 | 555 | |
| wyunreal | 3:5dc0023e6284 | 556 | struct rpc_method { |
| wyunreal | 3:5dc0023e6284 | 557 | const char *name; |
| wyunreal | 3:5dc0023e6284 | 558 | typedef void (*caller_t)(Base*, const char*, char*); |
| wyunreal | 3:5dc0023e6284 | 559 | typedef const struct rpc_method *(*super_t)(Base*); |
| wyunreal | 3:5dc0023e6284 | 560 | union { |
| wyunreal | 3:5dc0023e6284 | 561 | caller_t caller; |
| wyunreal | 3:5dc0023e6284 | 562 | super_t super; |
| wyunreal | 3:5dc0023e6284 | 563 | }; |
| wyunreal | 3:5dc0023e6284 | 564 | }; |
| wyunreal | 3:5dc0023e6284 | 565 | |
| wyunreal | 3:5dc0023e6284 | 566 | template<class C> |
| wyunreal | 3:5dc0023e6284 | 567 | const struct rpc_method *rpc_super(Base *this_ptr) { |
| wyunreal | 3:5dc0023e6284 | 568 | return static_cast<C*>(this_ptr)->C::get_rpc_methods(); |
| wyunreal | 3:5dc0023e6284 | 569 | } |
| wyunreal | 3:5dc0023e6284 | 570 | |
| wyunreal | 3:5dc0023e6284 | 571 | #define RPC_METHOD_END { NULL, NULL } |
| wyunreal | 3:5dc0023e6284 | 572 | #define RPC_METHOD_SUPER(C) { NULL, (rpc_method::caller_t)(rpc_method::super_t)rpc_super<C> } |
| wyunreal | 3:5dc0023e6284 | 573 | |
| wyunreal | 3:5dc0023e6284 | 574 | /* Function rpc |
| wyunreal | 3:5dc0023e6284 | 575 | * Parse a string describing a call and then do it |
| wyunreal | 3:5dc0023e6284 | 576 | * |
| wyunreal | 3:5dc0023e6284 | 577 | * Variables |
| wyunreal | 3:5dc0023e6284 | 578 | * call - A pointer to a string describing the call, which has |
| wyunreal | 3:5dc0023e6284 | 579 | * the form /object/method arg ... argn. Arguments are |
| wyunreal | 3:5dc0023e6284 | 580 | * delimited by space characters, and the string is terminated |
| wyunreal | 3:5dc0023e6284 | 581 | * by a null character. |
| wyunreal | 3:5dc0023e6284 | 582 | * result - A pointer to an array to write the result into. |
| wyunreal | 3:5dc0023e6284 | 583 | */ |
| wyunreal | 3:5dc0023e6284 | 584 | bool rpc(const char *buf, char *result = 0); |
| wyunreal | 3:5dc0023e6284 | 585 | |
| wyunreal | 3:5dc0023e6284 | 586 | |
| wyunreal | 3:5dc0023e6284 | 587 | } // namespace mbed |
| wyunreal | 3:5dc0023e6284 | 588 | |
| wyunreal | 3:5dc0023e6284 | 589 | #endif |
