Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Arguments.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "mbed.h" 00017 #include "Arguments.h" 00018 #include "pinmap.h" 00019 00020 using namespace std; 00021 00022 namespace mbed { 00023 00024 Arguments::Arguments(const char* rqs) { 00025 obj_name = NULL; 00026 method_name = NULL; 00027 argc = 0; 00028 00029 // This copy can be removed if we can assume the request string is 00030 // persistent and writable for the duration of the call 00031 strcpy(request, rqs); 00032 00033 // Initial '/' 00034 char* p = request; 00035 if (*p != '/') return; 00036 p++; 00037 00038 // Object Name 00039 p = search_arg(&obj_name, p, '/'); 00040 if (p == NULL) return; 00041 00042 // Method Name 00043 p = search_arg(&method_name, p, ' '); 00044 if (p == NULL) return; 00045 00046 // Arguments 00047 while (true) { 00048 argv[argc] = NULL; 00049 p = search_arg(&argv[argc], p, ' '); 00050 if (argv[argc] != NULL) argc++; 00051 if (p == NULL) break; 00052 } 00053 00054 index = -1; 00055 } 00056 00057 char* Arguments::search_arg(char **arg, char *p, char next_sep) { 00058 char *s = p; 00059 while (true) { 00060 if ((*p == '/') || (*p == ' ') || (*p == '\n') || (*p == '\0')) break; 00061 p++; 00062 } 00063 if (p == s) return NULL; 00064 *arg = s; 00065 char separator = *p; 00066 *p = '\0'; 00067 p++; 00068 return (separator == next_sep) ? (p) : (NULL); 00069 } 00070 00071 template<> PinName Arguments::getArg<PinName>(void) { 00072 index++; 00073 return parse_pins(argv[index]); 00074 } 00075 00076 template<> int Arguments::getArg<int>(void) { 00077 index++; 00078 char *pEnd; 00079 return strtol(argv[index], &pEnd, 10); 00080 } 00081 00082 template<> const char* Arguments::getArg<const char*>(void) { 00083 index++; 00084 return argv[index]; 00085 } 00086 00087 template<> char Arguments::getArg<char>(void) { 00088 index++; 00089 return *argv[index]; 00090 } 00091 00092 template<> double Arguments::getArg<double>(void) { 00093 index++; 00094 return atof(argv[index]); 00095 } 00096 00097 template<> float Arguments::getArg<float>(void) { 00098 index++; 00099 return atof(argv[index]); 00100 } 00101 00102 Reply::Reply(char* r) { 00103 first = true; 00104 *r = '\0'; 00105 reply = r; 00106 } 00107 00108 void Reply::separator(void) { 00109 if (first) { 00110 first = false; 00111 } else { 00112 *reply = ' '; reply++; 00113 } 00114 } 00115 00116 template<> void Reply::putData<const char*>(const char* s) { 00117 separator(); 00118 reply += sprintf(reply, "%s", s); 00119 } 00120 00121 template<> void Reply::putData<char*>(char* s) { 00122 separator(); 00123 reply += sprintf(reply, "%s", s); 00124 } 00125 00126 template<> void Reply::putData<char>(char c) { 00127 separator(); 00128 reply += sprintf(reply, "%c", c); 00129 } 00130 00131 template<> void Reply::putData<int>(int v) { 00132 separator(); 00133 reply += sprintf(reply, "%d", v); 00134 } 00135 00136 template<> void Reply::putData<float>(float f) { 00137 separator(); 00138 reply += sprintf(reply, "%.17g", f); 00139 } 00140 00141 } // namespace mbed
Generated on Tue Jul 12 2022 14:22:59 by
