- 添加模块化HTTP服务器架构,支持路由注册和请求处理 - 实现Creo状态检测API,提供连接状态和模型状态实时监控 - 完成STEP格式模型导出功能,支持装配体和零件导出 - 实现装配体层级结构分析,支持无限深度遍历和组件信息提取 - 添加层级组件安全删除功能,使用抑制策略保持装配体完整性 - 集成WebSocket服务器框架,为实时通信和长操作做准备 - 完善JSON处理、日志记录和认证管理基础设施 - 修复OTK API兼容性问题和内存管理优化 - 解决DeleteFeatures崩溃问题,采用SuppressFeatures替代方案 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
58 lines
1.5 KiB
C++
58 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <winsock2.h>
|
|
#include <ws2tcpip.h>
|
|
#include <string>
|
|
#include <map>
|
|
#include <functional>
|
|
#include "Config.h"
|
|
|
|
// HTTP请求结构
|
|
struct HttpRequest {
|
|
std::string method;
|
|
std::string path;
|
|
std::string query;
|
|
std::map<std::string, std::string> headers;
|
|
std::string body;
|
|
};
|
|
|
|
// HTTP响应结构
|
|
struct HttpResponse {
|
|
int status_code = 200;
|
|
std::map<std::string, std::string> headers;
|
|
std::string body;
|
|
|
|
HttpResponse() {
|
|
headers["Content-Type"] = "application/json; charset=utf-8";
|
|
headers["Access-Control-Allow-Origin"] = "*";
|
|
headers["Access-Control-Allow-Methods"] = "GET, POST, OPTIONS";
|
|
headers["Access-Control-Allow-Headers"] = "Content-Type";
|
|
}
|
|
};
|
|
|
|
// HTTP服务器类
|
|
class HttpServer {
|
|
public:
|
|
HttpServer();
|
|
~HttpServer();
|
|
|
|
bool Start();
|
|
void Stop();
|
|
bool IsRunning() const { return running_; }
|
|
|
|
// 设置路由处理器
|
|
void SetRouteHandler(const std::string& path,
|
|
std::function<HttpResponse(const HttpRequest&)> handler);
|
|
|
|
private:
|
|
static DWORD WINAPI ServerThread(LPVOID lpParam);
|
|
void HandleClient(SOCKET client_socket);
|
|
HttpRequest ParseRequest(const std::string& raw_request);
|
|
void SendResponse(SOCKET client_socket, const HttpResponse& response);
|
|
|
|
SOCKET server_socket_;
|
|
volatile bool running_;
|
|
HANDLE thread_handle_;
|
|
std::map<std::string, std::function<HttpResponse(const HttpRequest&)>> route_handlers_;
|
|
};
|