Improved RPC library with added bounds checking to stop memory corruption, removed memory leaks, Arduino pin names, better object discovery.
Fork of mbed-rpc by
I have added bounds checking in both Argument and Reply classes to stop existing buffer over-runs in both classes.
Added the ability to discover the name and class of an RPC object to allow better discovery of existing objects on a server. Removed a memory leak with externally created RPC objects. Ensured consistency so that externally created objects can't be deleted using the RPC interface and are correctly listed after RPC::clear.
Updated RPCVariable to use references instead of pointers to ensure that the compiler checks that there is always a valid backing variable. Also removed RPC new/delete functionality as this is not valid. Added a specialisation of RPCVariable to allow for strings to be read and written via RPC.
Added Arduino pin names to parse_pins, currently only for FRDM boards but same code should work for others just need to add them to the #ifdef.
RPCFunction.cpp@10:7511acfaa62d, 2015-03-30 (annotated)
- Committer:
- rhourahane
- Date:
- Mon Mar 30 16:43:47 2015 +0000
- Revision:
- 10:7511acfaa62d
- Parent:
- 1:6919289a5946
Updates to improve robustness and remove memory leak. Added RCVariable specialisation for char buffer.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:efe8172b4113 | 1 | /* mbed Microcontroller Library |
emilmont | 1:6919289a5946 | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbed_official | 0:efe8172b4113 | 3 | * |
emilmont | 1:6919289a5946 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
emilmont | 1:6919289a5946 | 5 | * you may not use this file except in compliance with the License. |
emilmont | 1:6919289a5946 | 6 | * You may obtain a copy of the License at |
mbed_official | 0:efe8172b4113 | 7 | * |
emilmont | 1:6919289a5946 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 0:efe8172b4113 | 9 | * |
emilmont | 1:6919289a5946 | 10 | * Unless required by applicable law or agreed to in writing, software |
emilmont | 1:6919289a5946 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
emilmont | 1:6919289a5946 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
emilmont | 1:6919289a5946 | 13 | * See the License for the specific language governing permissions and |
emilmont | 1:6919289a5946 | 14 | * limitations under the License. |
mbed_official | 0:efe8172b4113 | 15 | */ |
mbed_official | 0:efe8172b4113 | 16 | #include "RPCFunction.h" |
mbed_official | 0:efe8172b4113 | 17 | |
mbed_official | 0:efe8172b4113 | 18 | namespace mbed { |
mbed_official | 0:efe8172b4113 | 19 | |
mbed_official | 0:efe8172b4113 | 20 | //Custom rpc method caller for execute so that the string will not be delimited by anything |
mbed_official | 0:efe8172b4113 | 21 | void rpc_method_caller_run(RPC *this_ptr, Arguments *arguments, Reply *result) { |
mbed_official | 0:efe8172b4113 | 22 | ((static_cast<RPCFunction*>(this_ptr))->run)(arguments, result); |
mbed_official | 0:efe8172b4113 | 23 | } |
mbed_official | 0:efe8172b4113 | 24 | |
mbed_official | 0:efe8172b4113 | 25 | RPCFunction::RPCFunction(void (*f)(Arguments*, Reply*), const char* name) : RPC(name) { |
mbed_official | 0:efe8172b4113 | 26 | _ftr = f; |
mbed_official | 0:efe8172b4113 | 27 | } |
mbed_official | 0:efe8172b4113 | 28 | |
emilmont | 1:6919289a5946 | 29 | //Just run the attached function using the string thats in private memory - or just using null values, |
mbed_official | 0:efe8172b4113 | 30 | void RPCFunction::run(Arguments* args, Reply* r) { |
mbed_official | 0:efe8172b4113 | 31 | (*_ftr)(args, r); |
mbed_official | 0:efe8172b4113 | 32 | } |
mbed_official | 0:efe8172b4113 | 33 | |
mbed_official | 0:efe8172b4113 | 34 | const rpc_method *RPCFunction::get_rpc_methods() { |
mbed_official | 0:efe8172b4113 | 35 | static const rpc_method rpc_methods[] = { |
mbed_official | 0:efe8172b4113 | 36 | {"run", rpc_method_caller_run }, //Run using custom caller, all characters accepted in string |
mbed_official | 0:efe8172b4113 | 37 | RPC_METHOD_SUPER(RPC) |
mbed_official | 0:efe8172b4113 | 38 | }; |
mbed_official | 0:efe8172b4113 | 39 | return rpc_methods; |
mbed_official | 0:efe8172b4113 | 40 | } |
mbed_official | 0:efe8172b4113 | 41 | |
mbed_official | 0:efe8172b4113 | 42 | } |