58 lines
1.3 KiB
C++
58 lines
1.3 KiB
C++
//
|
|
// Created by lgv on 3/13/26.
|
|
//
|
|
#pragma once
|
|
|
|
#include <atomic>
|
|
#include <condition_variable>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <grpcpp/grpcpp.h>
|
|
#include "rapidxml/xml_parser.h"
|
|
#include "cmvr/config/server_config/server_config.pb.h"
|
|
namespace cmvr::service {
|
|
|
|
|
|
class ServerRunner {
|
|
public:
|
|
ServerRunner();
|
|
ServerRunner(const cmvr::config::ServerConfig& config);
|
|
~ServerRunner();
|
|
|
|
ServerRunner(const ServerRunner&) = delete;
|
|
ServerRunner& operator=(const ServerRunner&) = delete;
|
|
ServerRunner(ServerRunner&&) = delete;
|
|
ServerRunner& operator=(ServerRunner&&) = delete;
|
|
|
|
void start();
|
|
void stop();
|
|
void join();
|
|
|
|
bool isRunning() const;
|
|
std::string address() const;
|
|
|
|
private:
|
|
void threadMain();
|
|
|
|
private:
|
|
mutable std::mutex mtx_;
|
|
std::condition_variable cv_;
|
|
std::thread worker_;
|
|
|
|
cmvr::config::ServerConfig cfg_;
|
|
std::unique_ptr<grpc::Server> server_;
|
|
|
|
std::string address_;
|
|
std::string last_error_;
|
|
|
|
std::atomic<bool> running_{false};
|
|
bool stop_requested_{false};
|
|
bool started_{false};
|
|
bool start_failed_{false};
|
|
};
|
|
|
|
|
|
}
|