server_thrift.cc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <stdio.h>
  2. #include <signal.h>
  3. #include "workflow/WFFacilities.h"
  4. #include "srpc/rpc_types.h"
  5. #include "config/config.h"
  6. #include "%s.srpc.h"
  7. using namespace srpc;
  8. static WFFacilities::WaitGroup wait_group(1);
  9. static srpc::RPCConfig config;
  10. void sig_handler(int signo)
  11. {
  12. wait_group.done();
  13. }
  14. void init()
  15. {
  16. if (config.load("./server.conf") == false)
  17. {
  18. perror("Load config failed");
  19. exit(1);
  20. }
  21. }
  22. class ServiceImpl : public %s::Service
  23. {
  24. public:
  25. void Echo(EchoResult& _return, const std::string& message) override
  26. {
  27. %s// 4. delete the following codes and fill your logic
  28. fprintf(stderr, "get req. %%s\n", message.c_str());
  29. _return.message = "Hi back.";
  30. }
  31. };
  32. int main()
  33. {
  34. // 1. load config
  35. init();
  36. // 2. start server
  37. %sServer server;
  38. ServiceImpl impl;
  39. server.add_service(&impl);
  40. config.load_filter(server);
  41. if (server.start(config.server_port()) == 0)
  42. {
  43. // 3. success and wait
  44. printf("%s %s server started, port %%u\n", config.server_port());
  45. wait_group.wait();
  46. server.stop();
  47. }
  48. else
  49. perror("server start");
  50. return 0;
  51. }