diff --git a/CMakeLists.txt b/CMakeLists.txt index d00ec40..cefe8a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,8 @@ add_executable (rpc commands.cpp activation.h activation.cpp + heartbeat.h + heartbeat.cpp lms.h lms.cpp main.cpp diff --git a/activation.h b/activation.h index 71c1f3f..714fcf8 100644 --- a/activation.h +++ b/activation.h @@ -8,7 +8,7 @@ #include -#define PROTOCOL_VERSION "3.0.0" +#define PROTOCOL_VERSION "4.0.0" #ifdef _WIN32 #define convertstring to_utf16string diff --git a/heartbeat.cpp b/heartbeat.cpp new file mode 100644 index 0000000..12ef8b6 --- /dev/null +++ b/heartbeat.cpp @@ -0,0 +1,48 @@ +/********************************************************************* +* Copyright (c) Intel Corporation 2019 - 2020 +* SPDX-License-Identifier: Apache-2.0 +**********************************************************************/ + +#include "heartbeat.h" +#include +#include +#include +#include +#include +#include "activation.h" +#include "version.h" +#include "commands.h" +#include "network.h" +#include "utils.h" + +bool heartbeat_create_response(std::string& response) +{ + web::json::value msg; + + utility::string_t tmp = utility::conversions::convertstring("heartbeat_response"); + msg[U("method")] = web::json::value::string(tmp); + + tmp = utility::conversions::convertstring(""); + msg[U("apiKey")] = web::json::value::string(tmp); + + tmp = utility::conversions::convertstring(PROJECT_VER); + msg[U("appVersion")] = web::json::value::string(tmp); + + tmp = utility::conversions::convertstring(PROTOCOL_VERSION); + msg[U("protocolVersion")] = web::json::value::string(tmp); + + tmp = utility::conversions::convertstring("success"); + msg[U("status")] = web::json::value::string(tmp); + + tmp = utility::conversions::convertstring(""); + msg[U("message")] = web::json::value::string(tmp); + + // set empty payload + tmp = utility::conversions::convertstring(""); + msg[U("payload")] = web::json::value::string(tmp); + + // serialize the entire message + response = utility::conversions::to_utf8string(msg.serialize()); + + return true; +} \ No newline at end of file diff --git a/heartbeat.h b/heartbeat.h new file mode 100644 index 0000000..1b2d8a1 --- /dev/null +++ b/heartbeat.h @@ -0,0 +1,13 @@ +/********************************************************************* +* Copyright (c) Intel Corporation 2019 - 2020 +* SPDX-License-Identifier: Apache-2.0 +**********************************************************************/ + +#ifndef __HEARTBEAT_H__ +#define __HEARTBEAT_H__ + +#include + +bool heartbeat_create_response(std::string& response); + +#endif \ No newline at end of file diff --git a/main.cpp b/main.cpp index d2e227d..3c5497a 100644 --- a/main.cpp +++ b/main.cpp @@ -11,6 +11,7 @@ #include "lms.h" #include "commands.h" #include "activation.h" +#include "heartbeat.h" #include "utils.h" #include "usage.h" #include "args.h" @@ -246,6 +247,21 @@ int main(int argc, char* argv[]) return; } + if (msgMethod.compare("heartbeat_request") == 0) + { + // create the response + std::string response; + if (!heartbeat_create_response(response)) return; + + // send it + web::websockets::client::websocket_outgoing_message send_websocket_msg; + std::string send_websocket_buffer(response); + send_websocket_msg.set_utf8_message(send_websocket_buffer); + client.send(send_websocket_msg).wait(); + + return; + } + // process any messages we can // - if success, done // - if error, get out