Skip to content

Commit

Permalink
Release v0.1.1 (#45)
Browse files Browse the repository at this point in the history
* Update for Lion protocol
  • Loading branch information
pashinov authored Sep 13, 2020
1 parent b35b1c0 commit 08a7e59
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 222 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ add_subdirectory(proto)
set(SVC_HDR_FILES
src/rest_service/foundation/include/basic_controller.hpp
src/rest_service/foundation/include/controller.hpp
src/rest_service/lion_connector.hpp
src/rest_service/microsvc_controller.hpp
src/system/lion_connector.hpp
src/system/sysinfo.hpp
src/utils/config.hpp
src/utils/config_st.hpp
Expand All @@ -41,8 +41,8 @@ set(SVC_HDR_FILES

set(SVC_SRC_FILES
src/rest_service/foundation/basic_controller.cpp
src/rest_service/lion_connector.cpp
src/rest_service/microsvc_controller.cpp
src/system/lion_connector.cpp
src/system/sysinfo.cpp
src/utils/config.cpp
src/utils/logger.cpp
Expand All @@ -62,4 +62,5 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${ZeroMQ_INCLUDE_DIR})

target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${ZeroMQ_LIBRARY} cpprestsdk::cpprest lion_proto)

install (TARGETS ${PROJECT_NAME} DESTINATION bin)
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(FILES etc/config.json DESTINATION etc/dragon)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Service provides REST API interface for target device.
[travis-link]: https://travis-ci.org/pashinov/dragon
[license-badge]: https://img.shields.io/badge/license-MIT-blue.svg
[license-link]: https://github.com/pashinov/dragon/blob/develop/LICENSE
[release-badge]: https://img.shields.io/badge/release-v0.1.0-blue.svg
[release-badge]: https://img.shields.io/badge/release-v0.1.1-blue.svg
[release-link]: https://github.com/pashinov/dragon/releases
24 changes: 14 additions & 10 deletions proto/lion.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ enum PowerType {
}

enum SysInfoType {
UPTIME = 0;
BOOT_TIME = 1;
TEMPERATURE = 2;
OS_INFO = 3;
CPU_INFO = 4;
DISK_INFO = 5;
ARCH = 0;
OS = 1;
OS_RELEASE = 2;
CPU_NUM = 3;
CPU_SPEED = 4;
STORAGE_TOTAL = 5;
STORAGE_FREE = 6;
UPTIME = 7;
TEMPERATURE = 8;
}

message Power {
Expand All @@ -37,10 +40,11 @@ message ResourceType {

message PayloadType {
oneof payload_val {
int32 ival = 1;
double rval = 2;
bool bval = 3;
string sval = 4;
int32 ival = 1;
uint32 uval = 2;
double rval = 3;
bool bval = 4;
string sval = 5;
}
}

Expand Down
62 changes: 43 additions & 19 deletions src/rest_service/microsvc_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,54 +48,78 @@ namespace rest_service
{
auto response = json::value::object();

auto os_info = sys::sysinfo::get_os_info();
if (!os_info.has_value())
auto arch = sys::sysinfo::get(lion_protocol::SysInfoType::ARCH);
if (!arch.has_value())
{
message.reply(status_codes::InternalError);
return;
}

auto cpu_info = sys::sysinfo::get_cpu_info();
if (!cpu_info.has_value())
auto os = sys::sysinfo::get(lion_protocol::SysInfoType::OS);
if (!os.has_value())
{
message.reply(status_codes::InternalError);
return;
}

auto disk_info = sys::sysinfo::get_disk_info();
if (!disk_info.has_value())
auto os_release = sys::sysinfo::get(lion_protocol::SysInfoType::OS_RELEASE);
if (!os_release.has_value())
{
message.reply(status_codes::InternalError);
return;
}

auto uptime = sys::sysinfo::get_uptime();
if (!uptime.has_value())
auto cpu_num = sys::sysinfo::get(lion_protocol::SysInfoType::CPU_NUM);
if (!cpu_num.has_value())
{
message.reply(status_codes::InternalError);
return;
}

auto cpu_speed = sys::sysinfo::get(lion_protocol::SysInfoType::CPU_SPEED);
if (!cpu_speed.has_value())
{
message.reply(status_codes::InternalError);
return;
}

auto boot_time = sys::sysinfo::get_boot_time();
if (!boot_time.has_value())
auto storage_total = sys::sysinfo::get(lion_protocol::SysInfoType::STORAGE_TOTAL);
if (!storage_total.has_value())
{
message.reply(status_codes::InternalError);
return;
}

/*auto temperature = sys::sysinfo::get_temperature();
auto storage_free = sys::sysinfo::get(lion_protocol::SysInfoType::STORAGE_FREE);
if (!storage_free.has_value())
{
message.reply(status_codes::InternalError);
return;
}

auto uptime = sys::sysinfo::get(lion_protocol::SysInfoType::UPTIME);
if (!uptime.has_value())
{
message.reply(status_codes::InternalError);
return;
}

auto temperature = sys::sysinfo::get(lion_protocol::SysInfoType::TEMPERATURE);
if (!temperature.has_value())
{
message.reply(status_codes::InternalError);
return;
}*/

response["os_info"] = json::value::string(os_info.value());
response["cpu_info"] = json::value::string(cpu_info.value());
response["disk_info"] = json::value::string(disk_info.value());
response["uptime"] = json::value::string(uptime.value());
response["boot_time"] = json::value::string(boot_time.value());
//response["temperature"] = json::value::string(temperature.value());
}

response["arch"] = json::value::string(std::get<std::string>(arch.value()));
response["os"] = json::value::string(std::get<std::string>(os.value()));
response["os_release"] = json::value::string(std::get<std::string>(os_release.value()));
response["cpu_num"] = json::value::number(std::get<std::uint32_t>(cpu_num.value()));
response["cpu_speed"] = json::value::number(std::get<std::uint32_t>(cpu_speed.value()));
response["storage_total"] = json::value::number(std::get<std::uint32_t>(storage_total.value()));
response["storage_free"] = json::value::number(std::get<std::uint32_t>(storage_free.value()));
response["uptime"] = json::value::string(std::get<std::string>(uptime.value()));
response["temperature"] = json::value::number(std::get<double>(temperature.value()));

message.reply(status_codes::OK, response);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// project includes
#include <rest_service//lion_connector.hpp>
#include <system/lion_connector.hpp>

namespace rest_service
namespace lion
{
lion_connector::lion_connector()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// 3rdparty includes
#include <zmq.hpp>

namespace rest_service
namespace lion
{
class lion_connector
{
Expand Down
Loading

0 comments on commit 08a7e59

Please sign in to comment.