delete useless code
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
/*
|
||||
* Description: Simple Producer demo
|
||||
*/
|
||||
#include <fstream> // 用于 std::ifstream
|
||||
#include <sstream> // 用于 std::stringstream
|
||||
#include <unistd.h>
|
||||
@@ -12,7 +9,6 @@
|
||||
#include "../include/rocketmq/CProducer.h"
|
||||
#include "../include/rocketmq/CMessage.h"
|
||||
#include "../include/rocketmq/CSendResult.h"
|
||||
|
||||
#include "../include/rocketmq/SimpleProducer.h"
|
||||
|
||||
//测试300数据用lnk20241202
|
||||
@@ -135,13 +131,7 @@ RocketMQConsumer::RocketMQConsumer(const std::string& consumerName, const std::s
|
||||
std::cout << "error setting groupId"<< std::endl;
|
||||
throw std::runtime_error("Failed to set Consumer Group ID.");
|
||||
}
|
||||
/*
|
||||
// 设置消费模式为广播模式
|
||||
if (SetPushConsumerMessageModel(consumer_, BROADCASTING) != 0) {
|
||||
DestroyPushConsumer(consumer_);
|
||||
std::cout << "error setting messagemodel"<< std::endl;
|
||||
}
|
||||
*/
|
||||
|
||||
//调试用
|
||||
std::string consumerlog = "./mqconsumer/" + consumerName +".log";
|
||||
if ( (SetPushConsumerLogPath(consumer_,consumerlog.c_str()) || SetPushConsumerLogFileNumAndSize(consumer_,10,100) || SetPushConsumerLogLevel(consumer_,E_LOG_LEVEL_DEBUG) ) != 0) {//记录消费日志
|
||||
@@ -365,7 +355,6 @@ void rocketmq_consumer_receive(
|
||||
}
|
||||
}
|
||||
|
||||
// 消费逻辑已通过回调处理,无需额外操作
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//封装生产者类
|
||||
@@ -465,19 +454,6 @@ public:
|
||||
RoundRobinSelector, // 队列选择器回调函数
|
||||
&queueNum // 传递给选择器的额外参数(队列数量)
|
||||
);
|
||||
|
||||
//调试用
|
||||
/*int sendResult = SendMessageSync(
|
||||
producer_,
|
||||
msg,
|
||||
&result
|
||||
);
|
||||
int ret = SendMessageSync(producer_, msg, &result);
|
||||
if (ret == 0) {
|
||||
printSendResult(result);
|
||||
} else {
|
||||
std::cerr << "SendMessageSync failed with ret=" << ret << std::endl;
|
||||
}*/
|
||||
|
||||
if (sendResult == 0) { // 假设返回 0 表示成功
|
||||
std::cout << "Message sent successfully.topic:" << topic <<std::endl;
|
||||
@@ -579,56 +555,6 @@ void rocketmq_producer_send(const char* strbody, const char* topic)
|
||||
}
|
||||
#endif
|
||||
|
||||
//lnk20241209队列轮询
|
||||
#if 0
|
||||
// 全局或静态变量,用于维护当前队列索引
|
||||
static int currentQueueId = 0;
|
||||
|
||||
// 队列选择器回调函数:轮询选择队列 ID
|
||||
int RoundRobinSelector(int queueNum, CMessage* msg, void* arg) {
|
||||
if (queueNum == 0) {
|
||||
throw std::runtime_error("No available queues");
|
||||
}
|
||||
// 选择当前队列 ID,并更新索引
|
||||
int queueId = currentQueueId % queueNum;
|
||||
currentQueueId++;
|
||||
// 防止溢出,重置索引
|
||||
if (currentQueueId >= 1024 - queueNum) {
|
||||
currentQueueId = 0;
|
||||
}
|
||||
return queueId;
|
||||
}
|
||||
void StartSendMessage_queue(CProducer* producer, const char* strbody, const char* topic)
|
||||
{
|
||||
CSendResult result;
|
||||
|
||||
// 创建消息并设置一些属性
|
||||
CMessage* msg = CreateMessage(topic);
|
||||
SetMessageTags(msg, G_ROCKETMQ_TAG.c_str());
|
||||
SetMessageKeys(msg, G_ROCKETMQ_KEY.c_str());
|
||||
SetMessageBody(msg, strbody);
|
||||
|
||||
// 动态获取队列数量和 Broker 名称
|
||||
int queueNum = QUEUENUM; // 假设这个是配置的队列数量,比如5
|
||||
|
||||
// 使用 SendMessageOnewayOrderly 发送消息,传递回调函数
|
||||
int sendResult = SendMessageOnewayOrderly(
|
||||
producer,
|
||||
msg,
|
||||
RoundRobinSelector, // 传递符合 QueueSelectorCallback 签名的函数
|
||||
&queueNum // 传递给选择器的额外参数(队列数量)
|
||||
);
|
||||
|
||||
if (sendResult == 0) { // 假设返回 0 表示成功
|
||||
std::cout << "Message sent successfully: " << std::endl;
|
||||
} else {
|
||||
std::cout << "Failed to send message: " << std::endl;
|
||||
}
|
||||
|
||||
// 销毁消息
|
||||
DestroyMessage(msg);
|
||||
}
|
||||
#endif
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// producer_send0测试用
|
||||
void StartSendMessage(CProducer* producer)
|
||||
@@ -716,60 +642,6 @@ void producer_send(const char* strbody)
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#if 0
|
||||
void rocketmq_StartSendMessage(CProducer* producer,const char* strbody,const char* topic)
|
||||
{
|
||||
CSendResult result;
|
||||
|
||||
// create message and set some values for it
|
||||
CMessage* msg = CreateMessage(topic);
|
||||
|
||||
//多前置区分消息tag,一个进程
|
||||
|
||||
SetMessageTags(msg, G_ROCKETMQ_TAG.c_str());
|
||||
SetMessageKeys(msg, G_ROCKETMQ_KEY.c_str());
|
||||
|
||||
SetMessageBody(msg, strbody);
|
||||
// send message
|
||||
SendMessageSync(producer, msg, &result);
|
||||
|
||||
//cout << "rocketmq_result status:" << result.sendStatus << ", msgBody:" << strbody << endl;
|
||||
|
||||
// destroy message
|
||||
DestroyMessage(msg);
|
||||
}
|
||||
|
||||
void rocketmq_producer_send(const char* strbody,const char* topic)
|
||||
{
|
||||
cout << "rocketmq_Producer Initializing....." << endl;
|
||||
|
||||
// create producer and set some values for it
|
||||
CProducer* producer = CreateProducer(G_ROCKETMQ_PRODUCER.c_str());
|
||||
if (producer == NULL) {
|
||||
std::cerr << "Failed to create producer." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// nameserver
|
||||
SetProducerNameServerAddress(producer, G_ROCKETMQ_IPPORT.c_str());
|
||||
|
||||
// start producer
|
||||
StartProducer(producer);
|
||||
|
||||
cout << "rocketmq_Producer start....." << endl;
|
||||
// send message
|
||||
//rocketmq_StartSendMessage(producer,strbody,topic);
|
||||
//根据队列发消息
|
||||
StartSendMessage_queue(producer,strbody,topic);
|
||||
// shutdown producer
|
||||
ShutdownProducer(producer);
|
||||
// destroy producer
|
||||
DestroyProducer(producer);
|
||||
cout << "rocketmq_Producer Shutdown!" << endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
extern "C" {
|
||||
extern std::string G_MQCONSUMER_TOPIC_RT;
|
||||
@@ -862,84 +734,3 @@ void rocketmq_test_log()
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
void rocketmq_test_300(int mpnum,int front_index) {
|
||||
Ckafka_data_t data;
|
||||
data.strTopic = QString::fromStdString(G_ROCKETMQ_TOPIC);
|
||||
data.mp_id = "0";
|
||||
|
||||
// 读取文件内容
|
||||
std::ifstream file("long_string.txt"); // 文件中存储长字符串
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
std::string file_contents = buffer.str(); // 获取文件内容
|
||||
std::string base_strText = file_contents;
|
||||
|
||||
// 获取当前时间作为开始时间
|
||||
std::time_t t = std::time(NULL);//获取当前的系统时间(自 1970 年 1 月 1 日以来的秒数,通常称为 UNIX 时间戳)
|
||||
std::tm* time_info = std::localtime(&t);//将 std::time_t(表示当前的 UNIX 时间戳)转换为本地时间(std::tm 结构)
|
||||
time_info->tm_sec = 0; // 清零秒位
|
||||
//time_info->tm_msec = 0; // 清零毫秒位(如果需要更精确,使用高精度时间)
|
||||
|
||||
// 获取当前的时间戳(秒)
|
||||
std::time_t base_time_t = std::mktime(time_info);//将 std::tm 结构(本地时间)转换回 std::time_t(时间戳)
|
||||
|
||||
// 计算每条消息的时间戳,精确到分钟,毫秒和秒清零
|
||||
long long current_time_ms = static_cast<long long>(base_time_t) * 1000; // 每分钟递增,单位毫秒
|
||||
|
||||
// 设定总的消息数量
|
||||
int total_messages = mpnum;
|
||||
|
||||
// 循环发送 300 条消息
|
||||
for (int i = 0; i < total_messages; ++i) {
|
||||
// 修改 Monitor 值
|
||||
data.monitor_id = front_index *10000 + 1 + i;
|
||||
|
||||
data.mp_id = QString::number(data.monitor_id);
|
||||
|
||||
std::string modified_time = my_to_string(current_time_ms); // 时间转换为整数类型(Unix时间戳)
|
||||
|
||||
// 替换消息中的 Monitor 和 TIME 字段(只匹配字段名,不匹配具体数值)
|
||||
std::string modified_strText = base_strText;
|
||||
|
||||
// 替换 Monitor 字段
|
||||
size_t monitor_pos = modified_strText.find("\"Monitor\"");
|
||||
if (monitor_pos != std::string::npos) {
|
||||
size_t colon_pos = modified_strText.find(":", monitor_pos);
|
||||
size_t quote_pos = modified_strText.find("\"", colon_pos);
|
||||
size_t end_quote_pos = modified_strText.find("\"", quote_pos + 1);
|
||||
if (colon_pos != std::string::npos && quote_pos != std::string::npos && end_quote_pos != std::string::npos) {
|
||||
modified_strText.replace(quote_pos + 1, end_quote_pos - quote_pos - 1, my_to_string(data.monitor_id));
|
||||
}
|
||||
}
|
||||
|
||||
// 替换 TIME 字段
|
||||
size_t time_pos = modified_strText.find("\"TIME\"");
|
||||
if (time_pos != std::string::npos) {
|
||||
size_t colon_pos = modified_strText.find(":", time_pos);
|
||||
size_t quote_pos = colon_pos;
|
||||
size_t end_quote_pos = modified_strText.find(",", quote_pos + 1);
|
||||
if (colon_pos != std::string::npos && quote_pos != std::string::npos && end_quote_pos != std::string::npos) {
|
||||
modified_strText.replace(quote_pos + 1, end_quote_pos - quote_pos - 1, modified_time);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
data.strText = QString::fromStdString(modified_strText);
|
||||
|
||||
// 发送数据
|
||||
my_rocketmq_send(data);
|
||||
|
||||
// 输出调试信息
|
||||
std::cout << "Sent message " << (i + 1) << " with Monitor " << data.monitor_id << " and TIME " << modified_time << std::endl;
|
||||
|
||||
// 等待下一条消息的发送(固定为1分钟)
|
||||
//QThread::sleep(60); // 每次发送间隔1分钟
|
||||
}
|
||||
|
||||
std::cout << "Finished sending " << total_messages << " messages." << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -111,8 +111,6 @@ extern "C" {
|
||||
return encoded_data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <20>ж<EFBFBD><D0B6>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊpower{}<7D><>ʽ
|
||||
/// </summary>
|
||||
@@ -152,38 +150,6 @@ extern "C" {
|
||||
return true; // <20><>ȡ<EFBFBD>ɹ<EFBFBD>
|
||||
}
|
||||
|
||||
//int testbase64(char ** decoded_text) {
|
||||
// unsigned char text[] = "power{SGVsbG8sIFdvcmxkIWV3ZA==}";
|
||||
// size_t encoded_length, decoded_length;
|
||||
|
||||
// char encoded_text[100];
|
||||
|
||||
// if (extract_if_power((char*)text, encoded_text, sizeof(encoded_text), &encoded_length)) {
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// long decodedLen = strlen(encoded_text) * 3 / 4;
|
||||
// * decoded_text = (char*)malloc(decodedLen + 1);
|
||||
// // <20><><EFBFBD><EFBFBD>Base64<36><34><EFBFBD><EFBFBD>
|
||||
// int success = base64_decode(encoded_text, strlen(encoded_text), *decoded_text, &decodedLen);
|
||||
// if (decoded_text) {
|
||||
// printf("Decoded: %s\n", (char*)decoded_text); // ע<>⣺<EFBFBD><E2A3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫȷ<D2AA><C8B7><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>null<6C><6C>ֹ<EFBFBD><D6B9><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
// free(decoded_text); // ע<>⣺<EFBFBD><E2A3BA><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD>ϲ<EFBFBD>Ӧ<EFBFBD><D3A6>ʹ<EFBFBD><CAB9>decoded_text<78><74>Ϊ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>unsigned char*
|
||||
// // <20><>ʵ<EFBFBD><CAB5>Ӧ<EFBFBD><D3A6><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊchar*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>null<6C><6C>ֹ<EFBFBD><D6B9>
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// printf(" no Decoded: %s\n", text); // ע<>⣺<EFBFBD><E2A3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫȷ<D2AA><C8B7><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>null<6C><6C>ֹ<EFBFBD><D6B9><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
// }
|
||||
//
|
||||
|
||||
|
||||
// // ע<>⣺<EFBFBD><E2A3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>decoded_text<78><74>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD>ȷ<D7BC>ģ<EFBFBD><C4A3><EFBFBD>Ϊdecoded_text<78><74>unsigned char*<2A>ҿ<EFBFBD><D2BF>ܲ<EFBFBD><DCB2><EFBFBD>null<6C><6C>ֹ<EFBFBD><D6B9><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
// // <20><>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǽ<EFBFBD>decoded_textת<74><D7AA>Ϊ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
|
||||
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,10 +14,8 @@
|
||||
using namespace std;
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
#include "../mms/db_interface.h"
|
||||
#include "../json/cjson.h"//WW 2023-08-27<32><37><EFBFBD><EFBFBD>json<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#include "../include/curl/curl.h"
|
||||
@@ -29,11 +27,8 @@ extern "C" {
|
||||
|
||||
size_t req_reply_datahub(void* ptr, size_t size, size_t nmemb, void* stream)
|
||||
{
|
||||
//<2F><>ע<EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cookie<69><65><EFBFBD><EFBFBD>Ϣ
|
||||
string* str = (string*)stream;
|
||||
(*str).append((char*)ptr, size * nmemb);
|
||||
//printf(">>>GetDevice in reply %s\n", (char*)ptr);
|
||||
//GetCJson(ptr);
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
@@ -42,6 +37,7 @@ void SendWebAPI_Datahub(const string strUrl,char* topic,char* data)
|
||||
|
||||
// curl<72><6C>ʼ<EFBFBD><CABC>
|
||||
CURL* curl = curl_easy_init();
|
||||
|
||||
// curl<72><6C><EFBFBD><EFBFBD>ֵ
|
||||
CURLcode res;
|
||||
if (curl)
|
||||
@@ -60,18 +56,15 @@ void SendWebAPI_Datahub(const string strUrl,char* topic,char* data)
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>URL<52><4C>ַ
|
||||
curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
|
||||
cJSON* json_root = cJSON_CreateObject();
|
||||
|
||||
//cJSON_AddItemToObject(json_root, "topic", cJSON_CreateString("ems_pq_mmxu_stat"));
|
||||
//cJSON_AddItemToObject(json_root, "data", cJSON_CreateString("{\"DATA_TYPE\": \"04\",\"Monitor\": \"4563\",\"Value\": {\"FLAG\": 1,\"TIME\": 1512097260000,\"VOLTAGE\": {\"MAG\": 56.23,\"DUR\": 23,\"STARTTIME\": 1512097260000,\"ENDTIME\": 1512097283000,\"DISKIND\": \"01\",\"WAVEFILE\": \"PQMonitor_PQM1_000001_20230707_103916_596\",\"PHASIC\": \"unknow\"}}}"));
|
||||
cJSON_AddItemToObject(json_root, "topic", cJSON_CreateString(topic));
|
||||
cJSON_AddItemToObject(json_root, "data", cJSON_CreateString(data));
|
||||
|
||||
char* szjson = cJSON_Print(json_root);
|
||||
//printf(">>>json %s\n", szjson);
|
||||
//string strjson = szjson;
|
||||
//char* pszEncodeSecret = curl_easy_escape(curl, strclientsecret.c_str(), strclientsecret.length());
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, szjson);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>ssl<73><6C>֤
|
||||
@@ -86,7 +79,6 @@ void SendWebAPI_Datahub(const string strUrl,char* topic,char* data)
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>պ<EFBFBD>д<EFBFBD>뺯<EFBFBD><EBBAAF>
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, req_reply_datahub);
|
||||
|
||||
|
||||
string resPost0;
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&resPost0);
|
||||
|
||||
@@ -97,8 +89,10 @@ void SendWebAPI_Datahub(const string strUrl,char* topic,char* data)
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
|
||||
|
||||
printf(">>>Testaliyun datahub Post in curl post\n");
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD>
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
||||
if (res != CURLE_OK) {
|
||||
printf("aliyun datahub failed res code: ");
|
||||
@@ -119,14 +113,11 @@ void SendWebAPI_Datahub(const string strUrl,char* topic,char* data)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
|
||||
void DataHub_Send_Datahub(char* topic,char* data)
|
||||
{
|
||||
SendWebAPI_Datahub("http://127.0.0.1:8091/powerQuality/PQDATAHUB",topic,data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -4,20 +4,9 @@
|
||||
#include <string>
|
||||
#include "../json/cjson.h"
|
||||
|
||||
//#include <mutex>
|
||||
|
||||
//#include <queue>
|
||||
|
||||
//std::mutex data_mutex; // 用来保护 receivedData 变量
|
||||
|
||||
//#include <atomic>
|
||||
//std::atomic<bool> isrunning(false); // 使用原子变量保证 isrunning 的内存可见性
|
||||
|
||||
//std::queue<std::string> receivedData; // 用于存储接收到的数据
|
||||
bool isrunning = true; //用于线程同步
|
||||
std::string receivedData;
|
||||
|
||||
//std::queue<std::string> receivedData2; // 用于存储接收到的数据
|
||||
bool isrunning2 = true; //用于线程同步
|
||||
std::string receivedData2;
|
||||
|
||||
@@ -32,10 +21,6 @@ std::string rtdata_fail = "{\"code\":\"A0002\", \"msg\":\"3s数据执行失败\"
|
||||
|
||||
// 处理补招请求的函数
|
||||
std::string HandleRecall_http(const httplib::Request& req, httplib::Response& res) {
|
||||
// 打印请求的查询参数
|
||||
//std::cout << "Query parameters: " << std::endl;
|
||||
|
||||
//std::lock_guard<std::mutex> lock(data_mutex);
|
||||
|
||||
if(isrunning == true){ //收到前置信号,收到信息可以处理消息
|
||||
if (req.body.empty()) { //消息体为空
|
||||
@@ -180,21 +165,11 @@ std::string Handleupdate_http(const httplib::Request& req, httplib::Response& re
|
||||
//extern "C" std::string getReceivedData() {
|
||||
extern "C" const char* getReceivedData(int fun) {
|
||||
if(1 == fun){
|
||||
/*if (!receivedData.empty()) {
|
||||
std::string msg = receivedData.front(); // 获取队列中的第一条消息
|
||||
receivedData.pop(); // 从队列中移除这条消息
|
||||
return msg.c_str();
|
||||
}
|
||||
return "recall queue empty";*/
|
||||
|
||||
return receivedData.c_str();
|
||||
}
|
||||
if(2 == fun){
|
||||
/*if (!receivedData2.empty()) {
|
||||
std::string msg = receivedData2.front(); // 获取队列中的第一条消息
|
||||
receivedData2.pop(); // 从队列中移除这条消息
|
||||
return msg.c_str();
|
||||
}
|
||||
return "rtdata queue empty";*/
|
||||
|
||||
return receivedData2.c_str();
|
||||
}
|
||||
return "all queue empty";
|
||||
@@ -223,7 +198,6 @@ extern "C" bool threadmsghttp(int fun) {
|
||||
|
||||
// 启动 HTTP 服务器的函数
|
||||
extern "C" void httprun() {
|
||||
//std::cout << "WebhttpThread::run() is called ...... " << std::endl;
|
||||
|
||||
// 创建 HTTP 服务器对象
|
||||
httplib::Server svr;
|
||||
@@ -237,11 +211,8 @@ extern "C" void httprun() {
|
||||
// 监听路径 /powerQuality/update,绑定处理函数
|
||||
svr.Post("/powerQuality/update", Handleupdate_http); // 使用 POST 方法处理请求
|
||||
|
||||
// 监听端口 10004
|
||||
//std::cout << "Server started at http://0.0.0.0:10004" << std::endl;
|
||||
if (!svr.listen(HTTP_IP, HTTP_PORT)) { // 监听所有 IP
|
||||
std::cerr << "Error: Unable to start server on port 10004" << std::endl;
|
||||
}
|
||||
|
||||
//std::cout << "WebhttpThread::run() is end ...... " << std::endl;
|
||||
}
|
||||
1272
cfg_parse/nacos.cpp
1272
cfg_parse/nacos.cpp
File diff suppressed because it is too large
Load Diff
@@ -32,11 +32,8 @@ char BUCKET_NAME_OBS[2048] = { "test-8601" };
|
||||
|
||||
size_t req_reply_device(void* ptr, size_t size, size_t nmemb, void* stream)
|
||||
{
|
||||
//<2F><>ע<EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cookie<69><65><EFBFBD><EFBFBD>Ϣ
|
||||
string* str = (string*)stream;
|
||||
(*str).append((char*)ptr, size * nmemb);
|
||||
//printf(">>>GetDevice in reply %s\n", (char*)ptr);
|
||||
//GetCJson(ptr);
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
@@ -162,8 +159,6 @@ void SendWebAPI(const string strUrl, char* localpath, char* cloudpath,const char
|
||||
|
||||
char* szjson = cJSON_Print(json_root);
|
||||
printf(">>>json %s\n", szjson);
|
||||
//string strjson = szjson;
|
||||
//char* pszEncodeSecret = curl_easy_escape(curl, strclientsecret.c_str(), strclientsecret.length());
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, szjson);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>ssl<73><6C>֤
|
||||
@@ -245,12 +240,10 @@ void SendWebAPI_del(const string strUrl, char* cloudpath, const char* code)
|
||||
//param<61><6D>
|
||||
cJSON_AddItemToObject(json_param, "object_name", cJSON_CreateString(cloudpath));
|
||||
cJSON_AddNullToObject(json_param, "localfile_name");
|
||||
//cJSON_AddItemToObject(json_param, "localfile_name", cJSON_CreateString(localpath));
|
||||
|
||||
char* szjson = cJSON_Print(json_root);
|
||||
printf(">>>json %s\n", szjson);
|
||||
//string strjson = szjson;
|
||||
//char* pszEncodeSecret = curl_easy_escape(curl, strclientsecret.c_str(), strclientsecret.length());
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, szjson);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>ssl<73><6C>֤
|
||||
|
||||
@@ -23,19 +23,14 @@ using namespace std;
|
||||
#include "../mms/db_interface.h"
|
||||
#include <iostream>
|
||||
|
||||
char* OSS_ENDPOINT;
|
||||
char* ACCESS_KEY_ID;
|
||||
char* ACCESS_KEY_SECRET;
|
||||
char* OSS_ENDPOINT;
|
||||
char* ACCESS_KEY_ID;
|
||||
char* ACCESS_KEY_SECRET;
|
||||
char* BUCKET_NAME;
|
||||
|
||||
//const char OSS_ENDPOINT[] = "oss-cn-nanjing.aliyuncs.com";
|
||||
//const char ACCESS_KEY_ID[] = "LTAI5tER4bgJxT6Ptie7t2X7";
|
||||
//const char ACCESS_KEY_SECRET[] = "dSYIC5hD3flhTNoLMAxCoKjSPdWFSz";
|
||||
//const char BUCKET_NAME[] = "cn-pq-test";
|
||||
const char OBJECT_NAME[] = "comtrade/temp.json";
|
||||
|
||||
void init_sample_request_options(oss_request_options_t *options, int is_cname);
|
||||
|
||||
void put_object_from_buffer();
|
||||
void put_object_from_buffer_new(char* File_Name, char* data);
|
||||
void put_object_from_file();
|
||||
@@ -52,27 +47,19 @@ void TestOSS()
|
||||
aos_pool_t *pool = NULL;
|
||||
apr_status_t ret;
|
||||
|
||||
// initialize http io system, call it olny once
|
||||
/* <20>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>aos_http_io_initialize<7A><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>硢<EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>*/
|
||||
printf(">>>TestOSS ini Start");
|
||||
if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
printf(">>>TestOSS put Start");
|
||||
// run samples
|
||||
//put_object_from_buffer();
|
||||
//put_object_from_file();
|
||||
|
||||
put_object_from_buffer();
|
||||
get_object_to_file();
|
||||
//get_object_to_buffer();
|
||||
//get_object_to_file();
|
||||
//delete_object();
|
||||
|
||||
printf(">>>TestOSS put End");
|
||||
|
||||
|
||||
// deinitialize http io system, call it olny once
|
||||
aos_http_io_deinitialize();
|
||||
|
||||
return ;
|
||||
@@ -84,7 +71,6 @@ void PutOSS(char* File_Name,char* data) //zw
|
||||
aos_pool_t* pool = NULL;
|
||||
apr_status_t ret;
|
||||
|
||||
// initialize http io system, call it olny once
|
||||
/* <20>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>aos_http_io_initialize<7A><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>硢<EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>*/
|
||||
printf(">>>PutOSS ini Start");
|
||||
printf(File_Name);
|
||||
@@ -100,8 +86,6 @@ void PutOSS(char* File_Name,char* data) //zw
|
||||
|
||||
printf(">>>PutOSS put End");
|
||||
|
||||
|
||||
// deinitialize http io system, call it olny once
|
||||
aos_http_io_deinitialize();
|
||||
|
||||
return;
|
||||
@@ -113,22 +97,18 @@ void GetOSS(char* File_Name,char* savepath) //zw
|
||||
aos_pool_t* pool = NULL;
|
||||
apr_status_t ret;
|
||||
|
||||
// initialize http io system, call it olny once
|
||||
/* <20>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>aos_http_io_initialize<7A><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>硢<EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>*/
|
||||
printf(">>>GetOSS ini Start");
|
||||
if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
printf(">>>GetOSS put Start");
|
||||
|
||||
get_object_to_file_new(File_Name,savepath);//ʹ<><CAB9>buffer<65><72><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
|
||||
printf(">>>GetOSS put End");
|
||||
|
||||
|
||||
// deinitialize http io system, call it olny once
|
||||
aos_http_io_deinitialize();
|
||||
|
||||
return;
|
||||
@@ -140,32 +120,29 @@ void DelOSS(char* File_Name)
|
||||
aos_pool_t* pool = NULL;
|
||||
apr_status_t ret;
|
||||
|
||||
// initialize http io system, call it olny once
|
||||
/* <20>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>aos_http_io_initialize<7A><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>硢<EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>*/
|
||||
printf(">>>DelOSS ini Start");
|
||||
if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
printf(">>>DelOSS put Start");
|
||||
|
||||
delete_object_new(File_Name);//ʹ<><CAB9>buffer<65><72><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
|
||||
printf(">>>DelOSS put End");
|
||||
|
||||
|
||||
// deinitialize http io system, call it olny once
|
||||
aos_http_io_deinitialize();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void coutTest() {
|
||||
void coutTest()
|
||||
{
|
||||
std:: cout << "OSS_ENDPOINT:" << OSS_ENDPOINT << std::endl;
|
||||
std::cout << "ACCESS_KEY_ID:" << ACCESS_KEY_ID << std::endl;
|
||||
std::cout << "ACCESS_KEY_SECRET:" << ACCESS_KEY_SECRET << std::endl;
|
||||
std::cout << "BUCKET_NAME:" << BUCKET_NAME << std::endl;
|
||||
|
||||
}
|
||||
|
||||
void init_sample_request_options(oss_request_options_t *options, int is_cname)
|
||||
@@ -175,7 +152,6 @@ void init_sample_request_options(oss_request_options_t *options, int is_cname)
|
||||
aos_str_set(&options->config->access_key_id, ACCESS_KEY_ID);
|
||||
aos_str_set(&options->config->access_key_secret, ACCESS_KEY_SECRET);
|
||||
options->config->is_cname = is_cname;
|
||||
|
||||
options->ctl = aos_http_controller_create(options->pool, 0);
|
||||
}
|
||||
|
||||
@@ -231,7 +207,6 @@ void put_object_from_buffer_new(char* File_Name,char* data)//zw
|
||||
aos_buf_t* content = NULL;
|
||||
char* str = data;
|
||||
aos_status_t* s = NULL;
|
||||
|
||||
aos_pool_create(&p, NULL);
|
||||
options = oss_request_options_create(p);
|
||||
init_sample_request_options(options, is_cname);
|
||||
@@ -323,10 +298,8 @@ void put_object_from_file_new(char* File_Name, char* path)
|
||||
printf("put object from file succeeded\n");
|
||||
}
|
||||
else {
|
||||
printf("put object from file failed, code:%d, error_code:%s, error_msg:%s, request_id:%s\n",
|
||||
s->code, s->error_code, s->error_msg, s->req_id);
|
||||
printf("put object from file failed, code:%d, error_code:%s, error_msg:%s, request_id:%s\n",s->code, s->error_code, s->error_msg, s->req_id);
|
||||
}
|
||||
|
||||
|
||||
aos_pool_destroy(p);
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user