CreoPluging9.0/HttpServer.h
2026-01-15 16:23:23 +08:00

50 lines
1.0 KiB
C++

#pragma once
#include <atomic>
#include <condition_variable>
#include <functional>
#include <mutex>
#include <string>
#include <thread>
#include <WinSock2.h>
#include "ShrinkwrapTypes.h"
struct PendingTask {
ShrinkwrapShellRequest request;
ShrinkwrapShellResult result;
std::string error;
bool completed = false;
bool success = false;
};
class HttpServer {
public:
HttpServer();
~HttpServer();
using TriggerCallback = void(*)();
bool Start(int port, std::string* err, TriggerCallback trigger = nullptr);
void Stop();
// Called from Creo main thread via idle notification
void ProcessPendingTask();
bool HasPendingTask() const;
private:
void Run();
void HandleClient(SOCKET client);
std::atomic<bool> stop_{false};
std::thread thread_;
SOCKET listen_ = INVALID_SOCKET;
int port_ = 0;
// Task queue (single task for simplicity)
mutable std::mutex task_mutex_;
std::condition_variable task_cv_;
PendingTask* pending_task_ = nullptr;
TriggerCallback trigger_callback_ = nullptr;
};