17 #error "Hosted::Client can be used only on the Host architecture!" 23 #include <simpleRPC.h> 24 #include <simpleRPC/parser.h> 40 Client(
Stream& stream,
char methodEndsWith =
':') : stream(stream), methodEndsWith(methodEndsWith)
60 template <
typename... Args>
bool send(
const String& functionName, Args... args)
62 int functionId = getFunctionId(functionName);
63 if(functionId == COMMAND_NOT_FOUND) {
67 rpcPrint(stream,
uint8_t(functionId), args...);
77 template <
typename R> R
wait()
79 size_t neededBytes =
sizeof(R);
81 while(stream.available() <
int(neededBytes)) {
87 stream.readBytes(reinterpret_cast<char*>(&result),
sizeof(result));
107 int id = commands.indexOf(name);
112 return commands[name];
121 host_debug_i(
"Getting remote RPC commands \033[5m...\033[0m");
124 stream.write(&head, 1);
126 ParserSettings settings;
127 settings.startMethods = ParserSettings::SimpleMethod(&Client::startMethods,
this);
128 settings.startMethod = ParserSettings::SimpleMethod(&Client::startMethod,
this);
129 settings.methodSignature = ParserSettings::CharMethod(&Client::methodSignature,
this);
130 settings.methodName = ParserSettings::CharMethod(&Client::methodName,
this);
131 settings.endMethod = ParserSettings::SimpleMethod(&Client::endMethod,
this);
132 settings.endMethods = ParserSettings::SimpleMethod(&Client::endMethods,
this);
133 settings.state = ParserState::ready;
139 size_t length = stream.readBytes(buffer, 512);
144 ParserResult result = parse(settings, buffer, length, methodEndsWith);
145 if(result == ParserResult::finished) {
149 if(result == ParserResult::error) {
157 for(
size_t i = 0; i < commands.count(); i++) {
158 host_debug_i(
"\t%s => %d", commands.keyAt(i).c_str(), commands.valueAt(i));
168 bool fetchCommands{
true};
187 void methodSignature(
char ch)
192 void methodName(
char ch)
199 if(!commands.
contains(name) || signature ==
":") {
200 commands[name] = methodPosition;
202 commands[name +
"(" + signature +
")"] = methodPosition++;
207 fetchCommands =
false;
Client(Stream &stream, char methodEndsWith=':')
Definition: Components/Hosted/include/Hosted/Client.h:40
int getFunctionId(String name)
Fetches a list of commands supported on the RPC server and gives back the id of the desired command...
Definition: Components/Hosted/include/Hosted/Client.h:96
void clear()
Definition: WHashMap.h:382
Definition: Components/Hosted/include/Hosted/Client.h:31
bool getRemoteCommands()
Gets list of remote command names and their ids.
Definition: Components/Hosted/include/Hosted/Client.h:119
The String class.
Definition: WString.h:136
int indexOf(char ch, size_t fromIndex=0) const
String convertFQN(const String &name)
#define host_debug_e(fmt,...)
Definition: hostmsg.h:49
R wait()
This method will block the execution until a message is detected.
Definition: Components/Hosted/include/Hosted/Client.h:77
int host_main_loop()
Executing this function will run once the main emulator loop.
Definition: Components/Hosted/include/Hosted/Client.h:35
bool send(const String &functionName, Args... args)
Method to send commands to the remote server.
Definition: Components/Hosted/include/Hosted/Client.h:60
bool contains(const K &key) const
Definition: WHashMap.h:343
constexpr int COMMAND_NOT_FOUND
Definition: Components/Hosted/include/Hosted/Client.h:33
#define host_debug_i(fmt,...)
Definition: hostmsg.h:51
Base Stream class.
Definition: Wiring/Stream.h:32