38 lines
827 B
C++
38 lines
827 B
C++
/*
|
|
* VizionStreamer - Unix Socket Server Interface
|
|
* Copyright (c) 2025 Maik Jurischka
|
|
*
|
|
* Licensed under CC BY-NC-SA 4.0
|
|
* https://creativecommons.org/licenses/by-nc-sa/4.0/
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <functional>
|
|
#include <thread>
|
|
#include <atomic>
|
|
#include <memory>
|
|
|
|
class SocketServer {
|
|
public:
|
|
using CommandCallback = std::function<std::string(const std::string&)>;
|
|
|
|
explicit SocketServer(const std::string& socketPath);
|
|
~SocketServer();
|
|
|
|
bool start(CommandCallback callback);
|
|
void stop();
|
|
bool isRunning() const { return running_; }
|
|
|
|
private:
|
|
void serverLoop();
|
|
void handleClient(int clientFd);
|
|
|
|
std::string socketPath_;
|
|
int serverFd_;
|
|
std::atomic<bool> running_;
|
|
std::unique_ptr<std::thread> serverThread_;
|
|
CommandCallback commandCallback_;
|
|
};
|