|
@@ -53,6 +53,32 @@ BasicRoute generate_route(std::string path, std::string method) { /**/
|
|
|
} /**/
|
|
|
|
|
|
MHD_Result BasicServer::requestHandler(void* cls, struct MHD_Connection* connection, const char* url, const char* method, const char* version, const char* upload_data, size_t* upload_data_size, void** req_cls) { /**/
|
|
|
+ // 打印 cls
|
|
|
+// std::cout << "cls: " << cls << std::endl;
|
|
|
+//
|
|
|
+// // 打印 connection(指针地址)
|
|
|
+// std::cout << "connection: " << connection << std::endl;
|
|
|
+//
|
|
|
+// // 打印 URL
|
|
|
+// std::cout << "url: " << (url ? url : "<null>") << std::endl;
|
|
|
+//
|
|
|
+// // 打印 HTTP 方法
|
|
|
+// std::cout << "method: " << (method ? method : "<null>") << std::endl;
|
|
|
+//
|
|
|
+// // 打印 HTTP 版本
|
|
|
+// std::cout << "version: " << (version ? version : "<null>") << std::endl;
|
|
|
+//
|
|
|
+// // 打印 upload_data 和 upload_data_size
|
|
|
+// if (upload_data && *upload_data_size > 0) {
|
|
|
+// std::cout << "upload_data: " << std::string(upload_data, *upload_data_size) << std::endl;
|
|
|
+// } else {
|
|
|
+// std::cout << "upload_data: <empty or null>" << std::endl;
|
|
|
+// }
|
|
|
+// std::cout << "upload_data_size: " << *upload_data_size << std::endl;
|
|
|
+//
|
|
|
+// // 打印 req_cls
|
|
|
+// std::cout << "req_cls: " << *req_cls << std::endl;
|
|
|
+
|
|
|
if (*req_cls == NULL) {
|
|
|
*req_cls = new BasicRequest();
|
|
|
return MHD_YES;
|
|
@@ -85,14 +111,14 @@ MHD_Result BasicServer::requestHandler(void* cls, struct MHD_Connection* connect
|
|
|
std::string url_string(url);
|
|
|
std::cout << "url " << url << std::endl;
|
|
|
|
|
|
- if (url_string.rfind("/api/largeScreenDisplay/", 0) == 0) { // 确保从字符串的开始处匹配
|
|
|
+ if (url_string.rfind("/api/largeScreenDisplay/", 0) == 0) { // 确保从字符串的开始处匹配 http://localhost:8000/api/largeScreenDisplay/devices_info
|
|
|
if (url_string.find("/video") != std::string::npos) {
|
|
|
- std::cout << "largeScreenDisplay video" << std::endl;
|
|
|
+// std::cout << "largeScreenDisplay video" << std::endl;
|
|
|
} else if (url_string.find("/history_data") != std::string::npos) {
|
|
|
std::cout << "largeScreenDisplay history_data" << std::endl;
|
|
|
auto devices_history = createDeviceHistoryData();
|
|
|
Json response_json = deviceHistoryToJson(devices_history);
|
|
|
- std::cout << response_json.dump(4) << std::endl;
|
|
|
+// std::cout << response_json.dump(4) << std::endl;
|
|
|
response = response_json.dump();
|
|
|
} else if (url_string.find("/devices_info") != std::string::npos) {
|
|
|
std::cout << "largeScreenDisplay devices_info" << std::endl;
|
|
@@ -101,7 +127,40 @@ MHD_Result BasicServer::requestHandler(void* cls, struct MHD_Connection* connect
|
|
|
// std::cout << response_json.dump() << std::endl;
|
|
|
response = response_json.dump();
|
|
|
}
|
|
|
- }else {
|
|
|
+ }else if (url_string.find("/control-devices-status") != std::string::npos) {
|
|
|
+ std::cout << "largeScreenDisplay control-devices-status" << std::endl;
|
|
|
+ auto devices = control_devices_status();
|
|
|
+ Json response_json = deviceInfoToJson(devices);
|
|
|
+ std::cout << response_json.dump() << std::endl;
|
|
|
+ response = response_json.dump();
|
|
|
+ }else if (url_string.find("/allow-device") != std::string::npos) {
|
|
|
+ std::cout << "largeScreenDisplay allow-device" << std::endl;
|
|
|
+ auto devices = allowDevice();
|
|
|
+ Json response_json = allowDeviceInfoToJson(devices);
|
|
|
+ std::cout << response_json.dump() << std::endl;
|
|
|
+ response = response_json.dump();
|
|
|
+ }else if (url_string.find("/add-allow-device") != std::string::npos) {
|
|
|
+
|
|
|
+// static std::string post_data; // 存储请求体数据
|
|
|
+// std::cout << post_data << std::endl;
|
|
|
+//
|
|
|
+// if (*upload_data_size != 0) {
|
|
|
+// // 拼接上传的数据块
|
|
|
+// post_data.append(upload_data, *upload_data_size);
|
|
|
+// *upload_data_size = 0; // 告诉 MicroHTTPD 数据已处理
|
|
|
+// return MHD_YES; // 继续接收数据
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (!post_data.empty()) {
|
|
|
+// json request_body = json::parse(post_data);
|
|
|
+// std::string sensorName = request_body["sensorName"];
|
|
|
+// std::cout << "Received sensorName: " << sensorName << std::endl;
|
|
|
+//
|
|
|
+// const char* response = "{\"message\":\"添加成功\"}";
|
|
|
+// post_data.clear();
|
|
|
+// }
|
|
|
+ }
|
|
|
+ else {
|
|
|
BasicRoute route = generate_route(url, method);
|
|
|
route.request = (BasicRequest*)*req_cls;
|
|
|
BasicRouter router;
|