Einfaches mbed RPC Beispiel

Dependencies:   EthernetInterface HttpServer mbed-rtos mbed

Fork of RPCHTTPServerSimple by th.iotkit2.ch

Remote Procedure Call (RPC - „Aufruf einer fernen Prozedur“) ist eine Technik zur Realisierung von Interprozesskommunikation. Sie ermöglicht den Aufruf von Funktionen in anderen Adressräumen. Im Normalfall werden die aufgerufenen Funktionen auf einem anderen Computer als das aufrufende Programm ausgeführt. Es existieren viele Implementierungen dieser Technik, in der Regel sind sie untereinander nicht kompatibel

Die mbed Plattform beinhaltet eine RPC Library, welche ausgesuchte mbed Objekte (DigitalPin, DigitalOut etc.) mittels Serieller Schnittstelle oder via HTTP Aufrufen, zur Verfügung stellt.

Die mbed RCP Klassen verwenden C++ Templates, siehe Zeilen mit <Argument> und den Namespace RPC, siehe Zeilen mit RPC::.

Client

Committer:
stefan1691
Date:
Wed May 27 12:08:18 2015 +0000
Revision:
13:b7380bc60ad2
Parent:
11:43e28c85fd75
Web-APP ergaenzt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stefan1691 11:43e28c85fd75 1 /* mbed Microcontroller Library
stefan1691 11:43e28c85fd75 2 * Copyright (c) 2006-2013 ARM Limited
stefan1691 11:43e28c85fd75 3 *
stefan1691 11:43e28c85fd75 4 * Licensed under the Apache License, Version 2.0 (the "License");
stefan1691 11:43e28c85fd75 5 * you may not use this file except in compliance with the License.
stefan1691 11:43e28c85fd75 6 * You may obtain a copy of the License at
stefan1691 11:43e28c85fd75 7 *
stefan1691 11:43e28c85fd75 8 * http://www.apache.org/licenses/LICENSE-2.0
stefan1691 11:43e28c85fd75 9 *
stefan1691 11:43e28c85fd75 10 * Unless required by applicable law or agreed to in writing, software
stefan1691 11:43e28c85fd75 11 * distributed under the License is distributed on an "AS IS" BASIS,
stefan1691 11:43e28c85fd75 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
stefan1691 11:43e28c85fd75 13 * See the License for the specific language governing permissions and
stefan1691 11:43e28c85fd75 14 * limitations under the License.
stefan1691 11:43e28c85fd75 15 */
stefan1691 11:43e28c85fd75 16 #include "RPCFunction.h"
stefan1691 11:43e28c85fd75 17
stefan1691 11:43e28c85fd75 18 namespace mbed {
stefan1691 11:43e28c85fd75 19
stefan1691 11:43e28c85fd75 20 //Custom rpc method caller for execute so that the string will not be delimited by anything
stefan1691 11:43e28c85fd75 21 void rpc_method_caller_run(RPC *this_ptr, Arguments *arguments, Reply *result) {
stefan1691 11:43e28c85fd75 22 ((static_cast<RPCFunction*>(this_ptr))->run)(arguments, result);
stefan1691 11:43e28c85fd75 23 }
stefan1691 11:43e28c85fd75 24
stefan1691 11:43e28c85fd75 25 RPCFunction::RPCFunction(void (*f)(Arguments*, Reply*), const char* name) : RPC(name) {
stefan1691 11:43e28c85fd75 26 _ftr = f;
stefan1691 11:43e28c85fd75 27 }
stefan1691 11:43e28c85fd75 28
stefan1691 11:43e28c85fd75 29 //Just run the attached function using the string thats in private memory - or just using null values,
stefan1691 11:43e28c85fd75 30 void RPCFunction::run(Arguments* args, Reply* r) {
stefan1691 11:43e28c85fd75 31 (*_ftr)(args, r);
stefan1691 11:43e28c85fd75 32 }
stefan1691 11:43e28c85fd75 33
stefan1691 11:43e28c85fd75 34 const rpc_method *RPCFunction::get_rpc_methods() {
stefan1691 11:43e28c85fd75 35 static const rpc_method rpc_methods[] = {
stefan1691 11:43e28c85fd75 36 {"run", rpc_method_caller_run }, //Run using custom caller, all characters accepted in string
stefan1691 11:43e28c85fd75 37 RPC_METHOD_SUPER(RPC)
stefan1691 11:43e28c85fd75 38 };
stefan1691 11:43e28c85fd75 39 return rpc_methods;
stefan1691 11:43e28c85fd75 40 }
stefan1691 11:43e28c85fd75 41
stefan1691 11:43e28c85fd75 42 }