|
@ -1,29 +1,77 @@ |
|
|
#include "spdlog/spdlog.h"
|
|
|
|
|
|
#include "configs/config.hpp"
|
|
|
#include "configs/config.hpp"
|
|
|
|
|
|
#include "iflytopcpp/core/spdlogfactory/logger.hpp"
|
|
|
|
|
|
#include "iflytopcpp/core/thread/thread.hpp"
|
|
|
|
|
|
#include "spdlog/spdlog.h"
|
|
|
|
|
|
#include "version.hpp"
|
|
|
|
|
|
#include "zclipp/include/clipp.h"
|
|
|
|
|
|
#include "zservice_container/zservice_container.hpp"
|
|
|
|
|
|
#include "zwebservice/zwebservice.hpp"
|
|
|
|
|
|
//
|
|
|
|
|
|
#include "service/device_io_service.hpp"
|
|
|
|
|
|
#include "service/main_control_service.hpp"
|
|
|
|
|
|
|
|
|
using namespace iflytop; |
|
|
using namespace iflytop; |
|
|
using namespace core; |
|
|
using namespace core; |
|
|
using namespace std; |
|
|
using namespace std; |
|
|
int main() |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
shared_ptr<Config> config; |
|
|
|
|
|
spdlog::info("Welcome to spdlog!"); |
|
|
|
|
|
spdlog::error("Some error message with arg: {}", 1); |
|
|
|
|
|
|
|
|
|
|
|
spdlog::warn("Easy padding in numbers like {:08d}", 12); |
|
|
|
|
|
spdlog::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42); |
|
|
|
|
|
spdlog::info("Support for floats {:03.2f}", 1.23456); |
|
|
|
|
|
spdlog::info("Positional args are {1} {0}..", "too", "supported"); |
|
|
|
|
|
spdlog::info("{:<30}", "left aligned"); |
|
|
|
|
|
|
|
|
|
|
|
spdlog::set_level(spdlog::level::debug); // Set global log level to debug
|
|
|
|
|
|
spdlog::debug("This message should be displayed.."); |
|
|
|
|
|
|
|
|
|
|
|
// change log pattern
|
|
|
|
|
|
spdlog::set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v"); |
|
|
|
|
|
|
|
|
|
|
|
// Compile time log levels
|
|
|
|
|
|
// define SPDLOG_ACTIVE_LEVEL to desired level
|
|
|
|
|
|
SPDLOG_TRACE("Some trace message with param {}", 42); |
|
|
|
|
|
SPDLOG_DEBUG("Some debug message"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
using namespace clipp; |
|
|
|
|
|
|
|
|
|
|
|
class Main { |
|
|
|
|
|
ENABLE_LOGGER(Main); |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
unique_ptr<Thread> thread; |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
void main(int argc, char *argv[]); |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
|
Main(/* args */) {} |
|
|
|
|
|
~Main() {} |
|
|
|
|
|
void run(int argc, char *argv[]) { |
|
|
|
|
|
thread.reset(new Thread("main", [&]() { main(argc, argv); })); |
|
|
|
|
|
while (true) sleep(1000); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
|
|
Main main; |
|
|
|
|
|
main.run(argc, argv); |
|
|
|
|
|
} |
|
|
|
|
|
#define BUILD_AND_REG_SERRVICE(type, ...) \
|
|
|
|
|
|
logger->info("build {}.....", #type); \ |
|
|
|
|
|
shared_ptr<type> type##_val(new type(__VA_ARGS__)); \ |
|
|
|
|
|
ServiceContrainer::get().regService(type##_val); |
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************************************************************
|
|
|
|
|
|
* =======================================================Main======================================================== * |
|
|
|
|
|
***********************************************************************************************************************/ |
|
|
|
|
|
void Main::main(int argc, char *argv[]) { |
|
|
|
|
|
string g_host_server_ip; |
|
|
|
|
|
string g_device_id; |
|
|
|
|
|
auto cli = ( //
|
|
|
|
|
|
(required("-device_id") & value("device_id", g_device_id)).doc("device_id") //
|
|
|
|
|
|
); |
|
|
|
|
|
if (!parse(argc, argv, cli)) { |
|
|
|
|
|
cout << make_man_page(cli, argv[0]); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
logger->info("#"); |
|
|
|
|
|
logger->info("# company:{}", "ifytop"); |
|
|
|
|
|
logger->info("# version:{}", VERSION); |
|
|
|
|
|
logger->info("#"); |
|
|
|
|
|
|
|
|
|
|
|
BUILD_AND_REG_SERRVICE(Config); |
|
|
|
|
|
GET_SERVICE(Config)->initialize(); |
|
|
|
|
|
if (!g_device_id.empty()) GET_SERVICE(Config)->set_deviceId(g_device_id); |
|
|
|
|
|
|
|
|
|
|
|
BUILD_AND_REG_SERRVICE(DeviceIOService); |
|
|
|
|
|
GET_SERVICE(DeviceIOService)->initialize(); |
|
|
|
|
|
|
|
|
|
|
|
BUILD_AND_REG_SERRVICE(ZWebService); |
|
|
|
|
|
GET_SERVICE(ZWebService)->initialize(); |
|
|
|
|
|
|
|
|
|
|
|
BUILD_AND_REG_SERRVICE(MainControlService); |
|
|
|
|
|
GET_SERVICE(MainControlService)->initialize(); |
|
|
|
|
|
|
|
|
|
|
|
logger->info("system setup end."); |
|
|
|
|
|
} |