diff options
author | Jun Wako <wakojun@gmail.com> | 2015-04-24 16:26:14 +0900 |
---|---|---|
committer | Jun Wako <wakojun@gmail.com> | 2015-04-24 16:26:14 +0900 |
commit | 1fe4406f374291ab2e86e95a97341fd9c475fcb8 (patch) | |
tree | 1be0e16b4b07b5a31ea97ec50a9eb13a288c3d27 /tool/mbed/mbed-sdk/libraries/rpc/Arguments.cpp | |
parent | a20ef7052c6e937d2f7672dd59456e55a5c08296 (diff) |
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
b9e0ea0 Merge commit '7fa9d8bdea3773d1195b04d98fcf27cf48ddd81d' as 'tool/mbed/mbed-sdk'
7fa9d8b Squashed 'tool/mbed/mbed-sdk/' content from commit 7c21ce5
git-subtree-dir: tmk_core
git-subtree-split: b9e0ea08cb940de20b3610ecdda18e9d8cd7c552
Diffstat (limited to 'tool/mbed/mbed-sdk/libraries/rpc/Arguments.cpp')
-rw-r--r-- | tool/mbed/mbed-sdk/libraries/rpc/Arguments.cpp | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/tool/mbed/mbed-sdk/libraries/rpc/Arguments.cpp b/tool/mbed/mbed-sdk/libraries/rpc/Arguments.cpp new file mode 100644 index 0000000000..b14f0b6957 --- /dev/null +++ b/tool/mbed/mbed-sdk/libraries/rpc/Arguments.cpp @@ -0,0 +1,140 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "Arguments.h" +#include "pinmap.h" + +using namespace std; + +namespace mbed { + +Arguments::Arguments(const char* rqs) { + obj_name = NULL; + method_name = NULL; + argc = 0; + + // This copy can be removed if we can assume the request string is + // persistent and writable for the duration of the call + strcpy(request, rqs); + + // Initial '/' + char* p = request; + if (*p != '/') return; + p++; + + // Object Name + p = search_arg(&obj_name, p, '/'); + if (p == NULL) return; + + // Method Name + p = search_arg(&method_name, p, ' '); + if (p == NULL) return; + + // Arguments + while (true) { + argv[argc] = NULL; + p = search_arg(&argv[argc], p, ' '); + if (argv[argc] != NULL) argc++; + if (p == NULL) break; + } + + index = -1; +} + +char* Arguments::search_arg(char **arg, char *p, char next_sep) { + char *s = p; + while (true) { + if ((*p == '/') || (*p == ' ') || (*p == '\n') || (*p == '\0')) break; + p++; + } + if (p == s) return NULL; + *arg = s; + char separator = *p; + *p = '\0'; + p++; + return (separator == next_sep) ? (p) : (NULL); +} + +template<> PinName Arguments::getArg<PinName>(void) { + index++; + return parse_pins(argv[index]); +} + +template<> int Arguments::getArg<int>(void) { + index++; + char *pEnd; + return strtol(argv[index], &pEnd, 10); +} + +template<> const char* Arguments::getArg<const char*>(void) { + index++; + return argv[index]; +} + +template<> char Arguments::getArg<char>(void) { + index++; + return *argv[index]; +} + +template<> double Arguments::getArg<double>(void) { + index++; + return atof(argv[index]); +} + +template<> float Arguments::getArg<float>(void) { + index++; + return atof(argv[index]); +} + +Reply::Reply(char* r) { + first = true; + *r = '\0'; + reply = r; +} + +void Reply::separator(void) { + if (first) { + first = false; + } else { + *reply = ' '; reply++; + } +} + +template<> void Reply::putData<const char*>(const char* s) { + separator(); + reply += sprintf(reply, "%s", s); +} + +template<> void Reply::putData<char*>(char* s) { + separator(); + reply += sprintf(reply, "%s", s); +} + +template<> void Reply::putData<char>(char c) { + separator(); + reply += sprintf(reply, "%c", c); +} + +template<> void Reply::putData<int>(int v) { + separator(); + reply += sprintf(reply, "%d", v); +} + +template<> void Reply::putData<float>(float f) { + separator(); + reply += sprintf(reply, "%.17g", f); +} + +} // namespace mbed |