Lab 1 Program C

Dependents:   Lab1C

Fork of mbed by -deleted-

Committer:
rolf.meyer@arm.com
Date:
Fri Aug 28 12:10:11 2009 +0000
Revision:
11:1c1ebd0324fa
Parent:
8:00a04e5cd407
Child:
27:7110ebee3484
A shiny new version

Who changed what in which revision?

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