33#ifndef BRIDGE_IMOLA_H
44#define BRIDGE_IMOLA_H
55
6+ #define RESET_METHOD " $/reset"
7+ #define BIND_METHOD " $/register"
8+
69#include < Arduino_RPClite.h>
710
811
@@ -19,22 +22,34 @@ class Bridge {
1922 }
2023
2124 // Initialize the bridge
22- void begin () {
25+ bool begin () {
2326 client = new RPCClient (*transport);
2427 server = new RPCServer (*transport);
28+ bool res;
29+ return call (RESET_METHOD, res);
2530 }
2631
2732 template <typename F>
2833 bool provide (const MsgPack::str_t & name, F&& func) {
34+ bool res;
35+ if (!call (BIND_METHOD, res, name)) {
36+ return false ;
37+ }
2938 return server->bind (name, func);
3039 }
3140
3241 void update () {
42+ // Protect the following calls with a mutex if necessary
43+ // server->read_request(); // <- inbound
44+ // server->serve(); // -> outbound
3345 server->run ();
3446 }
3547
3648 template <typename RType, typename ... Args>
3749 bool call (const MsgPack::str_t method, RType& result, Args&&... args) {
50+ // Protect the following calls with a mutex if necessary
51+ // client->send_call(); // -> outbound
52+ // client->read_response(); // <- inbound
3853 return client->call (method, result, std::forward<Args>(args)...);
3954 }
4055
@@ -44,7 +59,7 @@ class Bridge {
4459 }
4560
4661 String get_error_message () const {
47- return client->lastError .traceback ;
62+ return (String) client->lastError .traceback ;
4863 }
4964
5065 uint8_t get_error_code () const {
0 commit comments