rpc.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "Crown.h"
  2. #include "RPCServer.h"
  3. #include "RPCHandler.h"
  4. using namespace crown;
  5. // void script_callback(TCPClient* client, const char* message)
  6. // {
  7. // Log::i("Executing script.");
  8. // }
  9. // void command_callback(TCPClient* client, const char* message)
  10. // {
  11. // Log::i("Executing command.");
  12. // }
  13. int main()
  14. {
  15. RPCServer rpc;
  16. // rpc.add_callback("script", script_callback);
  17. // rpc.add_callback("command", command_callback);
  18. // const char* json_object = "{\"type\":\"ciao\"}";
  19. // JSONParser parser(json_object);
  20. // JSONElement root = parser.root();
  21. // Log::i("keys: %d", root.size());
  22. // Log::i("type: %s", root.key("type").string_value());
  23. HeapAllocator heap;
  24. ProxyAllocator def_proxy("default-heap", default_allocator());
  25. ProxyAllocator proxy("main-heap", heap);
  26. proxy.allocate(100);
  27. RPCScriptHandler script;
  28. RPCPingHandler ping;
  29. RPCStatsHandler stats;
  30. rpc.add_handler(&script);
  31. rpc.add_handler(&ping);
  32. rpc.add_handler(&stats);
  33. rpc.init(true);
  34. while (1)
  35. {
  36. rpc.update();
  37. rpc.execute_callbacks();
  38. }
  39. rpc.shutdown();
  40. return 0;
  41. }