#include "extapi_service.hpp" #include "configs/project_setting.hpp" #include "iflytop/components/zcanreceiver/zcanreceiverhost.hpp" #include "iflytop/core/components/stringutils.hpp" #include "iflytop/core/core.hpp" #include "version.hpp" using namespace iflytop; using namespace core; using namespace std; using namespace nlohmann; #define BIND namespace iflytop {}; /******************************************************************************* * TOOLS * *******************************************************************************/ static void getJsonValFromJson(json j, int& val) { if (j.is_string()) { string valstr = j; val = atoi(valstr.c_str()); } else if (j.is_number()) { val = j; } else { throw std::runtime_error("getJsonValFromJson(int) error"); } } template static T jsonGet(json j) { T val; getJsonValFromJson(j, val); return val; } void ExtAPIService::dosystem(string order) { logger->info("do:{}", order); system(order.c_str()); } void ExtAPIService::initialize() { GET_TO_SERVICE(m_zconfig); m_restfulServer.reset(new RestfulServer()); m_restfulServer->regAPI("/hello_world", RESTFUL_SERVER_BIND(ExtAPIService::hello_world)); m_restfulServer->start(20000, 20001, "0.0.0.0"); m_iflytopwsService.reset(new IflytopFrontEndService()); m_iflytopwsService->initialize("0.0.0.0"); m_iflytopwsService->startListen(); }; HttpResponsePtr ExtAPIService::hello_world( // HttpRequestPtr request, shared_ptr context, std::shared_ptr) { return std::make_shared(200, "OK", HttpErrorCode::Ok, WebSocketHttpHeaders(), "hello_world"); }