1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include "Arguments.h"
23 Arguments::Arguments(const char* rqs) {
28 // This copy can be removed if we can assume the request string is
29 // persistent and writable for the duration of the call
34 if (*p != '/') return;
38 p = search_arg(&obj_name, p, '/');
39 if (p == NULL) return;
42 p = search_arg(&method_name, p, ' ');
43 if (p == NULL) return;
48 p = search_arg(&argv[argc], p, ' ');
49 if (argv[argc] != NULL) argc++;
56 char* Arguments::search_arg(char **arg, char *p, char next_sep) {
59 if ((*p == '/') || (*p == ' ') || (*p == '\n') || (*p == '\0')) break;
62 if (p == s) return NULL;
67 return (separator == next_sep) ? (p) : (NULL);
70 template<> PinName Arguments::getArg<PinName>(void) {
72 return parse_pins(argv[index]);
75 template<> int Arguments::getArg<int>(void) {
78 return strtol(argv[index], &pEnd, 10);
81 template<> const char* Arguments::getArg<const char*>(void) {
86 template<> char Arguments::getArg<char>(void) {
91 template<> double Arguments::getArg<double>(void) {
93 return atof(argv[index]);
96 template<> float Arguments::getArg<float>(void) {
98 return atof(argv[index]);
101 Reply::Reply(char* r) {
107 void Reply::separator(void) {
111 *reply = ' '; reply++;
115 template<> void Reply::putData<const char*>(const char* s) {
117 reply += sprintf(reply, "%s", s);
120 template<> void Reply::putData<char*>(char* s) {
122 reply += sprintf(reply, "%s", s);
125 template<> void Reply::putData<char>(char c) {
127 reply += sprintf(reply, "%c", c);
130 template<> void Reply::putData<int>(int v) {
132 reply += sprintf(reply, "%d", v);
135 template<> void Reply::putData<float>(float f) {
137 reply += sprintf(reply, "%.17g", f);