From 1fe4406f374291ab2e86e95a97341fd9c475fcb8 Mon Sep 17 00:00:00 2001 From: Jun Wako Date: Fri, 24 Apr 2015 16:26:14 +0900 Subject: 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 --- tool/mbed/mbed-sdk/libraries/rpc/Arguments.cpp | 140 +++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 tool/mbed/mbed-sdk/libraries/rpc/Arguments.cpp (limited to 'tool/mbed/mbed-sdk/libraries/rpc/Arguments.cpp') 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(void) { + index++; + return parse_pins(argv[index]); +} + +template<> int Arguments::getArg(void) { + index++; + char *pEnd; + return strtol(argv[index], &pEnd, 10); +} + +template<> const char* Arguments::getArg(void) { + index++; + return argv[index]; +} + +template<> char Arguments::getArg(void) { + index++; + return *argv[index]; +} + +template<> double Arguments::getArg(void) { + index++; + return atof(argv[index]); +} + +template<> float Arguments::getArg(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* s) { + separator(); + reply += sprintf(reply, "%s", s); +} + +template<> void Reply::putData(char* s) { + separator(); + reply += sprintf(reply, "%s", s); +} + +template<> void Reply::putData(char c) { + separator(); + reply += sprintf(reply, "%c", c); +} + +template<> void Reply::putData(int v) { + separator(); + reply += sprintf(reply, "%d", v); +} + +template<> void Reply::putData(float f) { + separator(); + reply += sprintf(reply, "%.17g", f); +} + +} // namespace mbed -- cgit v1.2.3