// cmake_service_test.cpp: 定义应用程序的入口点。
//

//stl
#include <iostream>
//robotics
#include <robotics/message_bus.hpp>
#include <robotics/application.hpp>
#include <robotics/singleton.hpp>
#include <robotics/mvc.hpp>
//local
#include "core/core.hpp"
#include "aop/aop.hpp"
#include "reflect.h"

using namespace robotics;

v3::message_bus g_message_bus;

/// @brief 服务
class service : public v3::application_base {
    using http_server = v3::mvc::http_server<http_before, http_error, http_after>;
public:
    /// @brief 构造
    explicit service() {
        std::string root_directory = std::filesystem::current_path().string() + "/views";
        port_ = v3::config::read<int>("MVC", "PORT", 8002);
        root_directory = v3::config::read<std::string>("MVC", "PATH", root_directory);
        http_server_.set_root_directory(root_directory);
    }
private:
    /**
     * @brief 启用
     */
    virtual void run() override {
        core_.start();
        bool result = http_server_.start("0.0.0.0", port_);
        LOG_INFO << "服务启动完成,状态:" << result << ".";
    }
    /**
     * @brief 停止
     */
    virtual void stop() override {
        http_server_.stop();
        core_.stop();
        LOG_INFO << "服务停止完成.";
    }
private:
    core            core_;
    int             port_ = 80;
    http_server     http_server_;
};
/// @brief 入口函数
/// @param argc 
/// @param argv 
/// @return 
int main(int argc, char* argv[])
{
	SINGLETON("sync_service");
    return v3::application<service>::run(argc, argv);
}

