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