合并
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
|
||||
#include "cloudfront/code/interface.h"
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
using namespace std;
|
||||
#if 0
|
||||
@@ -32,6 +34,9 @@ typedef struct {
|
||||
} thread_info_t;
|
||||
#endif
|
||||
|
||||
extern int INITFLAG;//̨<>˵ȳ<CBB5>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־
|
||||
extern void cleanup_args(ThreadArgs* args);
|
||||
|
||||
void init_daemon(void)
|
||||
{
|
||||
int pid;
|
||||
@@ -108,6 +113,32 @@ std::vector<DeviceInfo> generate_test_devices(int count) {
|
||||
return devices;
|
||||
}
|
||||
|
||||
void PrintDevices(const std::vector<DeviceInfo>& devices) {
|
||||
std::cout << "==== Devices List (" << devices.size() << ") ====\n";
|
||||
for (const auto& dev : devices) {
|
||||
std::cout << "Device ID : " << dev.device_id << "\n";
|
||||
std::cout << "Name : " << dev.name << "\n";
|
||||
std::cout << "Model : " << dev.model << "\n";
|
||||
std::cout << "MAC : " << dev.mac << "\n";
|
||||
std::cout << "Status : " << dev.status << "\n";
|
||||
std::cout << "Points (" << dev.points.size() << "):\n";
|
||||
for (const auto& pt : dev.points) {
|
||||
std::cout << " Point ID : " << pt.point_id << "\n";
|
||||
std::cout << " Name : " << pt.name << "\n";
|
||||
std::cout << " Device ID : " << pt.device_id << "\n";
|
||||
std::cout << " Cpu No : " << pt.nCpuNo << "\n";
|
||||
std::cout << " PT1 : " << pt.PT1 << "\n";
|
||||
std::cout << " PT2 : " << pt.PT2 << "\n";
|
||||
std::cout << " CT1 : " << pt.CT1 << "\n";
|
||||
std::cout << " CT2 : " << pt.CT2 << "\n";
|
||||
std::cout << " Scale : " << pt.strScale << "\n";
|
||||
std::cout << " PTType : " << pt.nPTType << "\n";
|
||||
std::cout << "----------------------\n";
|
||||
}
|
||||
std::cout << "==========================\n";
|
||||
}
|
||||
}
|
||||
|
||||
/* <20>̹߳<DFB3><CCB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0<><30><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>*/
|
||||
/* <20>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӹ<EFBFBD><D3B9><EFBFBD><EFBFBD>̺߳<DFB3><CCBA><EFBFBD>*/
|
||||
void* client_manager_thread(void* arg) {
|
||||
@@ -207,7 +238,7 @@ void restart_thread(int index) {
|
||||
int* new_index = (int*)malloc(sizeof(int));
|
||||
*new_index = index;
|
||||
|
||||
if (index == 0) {
|
||||
if (index == 1) {
|
||||
// <20>ͻ<EFBFBD><CDBB>˹<EFBFBD><CBB9><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
if (pthread_create(&thread_info[index].tid, NULL, client_manager_thread, new_index) != 0) {
|
||||
pthread_mutex_lock(&global_lock);
|
||||
@@ -217,7 +248,7 @@ void restart_thread(int index) {
|
||||
free(new_index);
|
||||
}
|
||||
}
|
||||
else if (index == 1) {
|
||||
else if (index == 2) {
|
||||
// <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
if (pthread_create(&thread_info[index].tid, NULL, message_processor_thread, new_index) != 0) {
|
||||
pthread_mutex_lock(&global_lock);
|
||||
@@ -227,7 +258,7 @@ void restart_thread(int index) {
|
||||
free(new_index);
|
||||
}
|
||||
}
|
||||
else if (index == 2) {
|
||||
else if (index == 0) {
|
||||
// <20>ӿڣ<D3BF>mq
|
||||
char* argv[] = { (char*)new_index };//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺Ų<CCBA><C5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
ThreadArgs* args = new ThreadArgs{1, argv};
|
||||
@@ -251,6 +282,16 @@ int is_thread_alive(pthread_t tid) {
|
||||
return pthread_tryjoin_np(tid, NULL) == EBUSY; // EBUSY<53><59>ʾ<EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
//lnk<6E><6B><EFBFBD><EFBFBD>
|
||||
ThreadArgs* make_thread_args_from_strs(const std::vector<std::string>& args_vec) {
|
||||
char** argv = new char*[args_vec.size() + 1]; // <20><>һ<EFBFBD><D2BB> nullptr <20><>β
|
||||
for (size_t i = 0; i < args_vec.size(); ++i) {
|
||||
argv[i] = strdup(args_vec[i].c_str()); // strdup <20><> malloc <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
argv[args_vec.size()] = nullptr;
|
||||
return new ThreadArgs{static_cast<int>(args_vec.size()), argv};
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
int main(int argc ,char** argv) {//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD>
|
||||
if(!parse_param(argc,argv)){
|
||||
@@ -267,34 +308,46 @@ int main(int argc ,char** argv) {//
|
||||
pthread_mutex_init(&thread_info[i].lock, NULL); // <20><>ʼ<EFBFBD><CABC>ÿ<EFBFBD><C3BF><EFBFBD>̵߳<DFB3><CCB5><EFBFBD>
|
||||
}
|
||||
|
||||
//<2F>ӿں<D3BF>mq
|
||||
ThreadArgs* args = make_thread_args_from_strs({ "0" });
|
||||
if (pthread_create(&thread_info[0].tid, NULL, cloudfrontthread, args) != 0) {
|
||||
printf("Failed to create message processor thread 0\n");
|
||||
cleanup_args(args);
|
||||
}
|
||||
|
||||
while(!INITFLAG){
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
std::cout << "waiting cloudfront initialize ..." << std::endl;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>߳<EFBFBD><DFB3><EFBFBD>
|
||||
for (int i = 0; i < THREAD_CONNECTIONS; i++) {
|
||||
for (int i = 1; i < THREAD_CONNECTIONS; i++) {
|
||||
int* index = (int*)malloc(sizeof(int));
|
||||
*index = i;
|
||||
|
||||
if (i == 0) {
|
||||
if (i == 1) {
|
||||
// <20>ͻ<EFBFBD><CDBB>˹<EFBFBD><CBB9><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
if (pthread_create(&thread_info[i].tid, NULL, client_manager_thread, index) != 0) {
|
||||
printf("Failed to create client manager thread %d\n", i);
|
||||
free(index);
|
||||
}
|
||||
}
|
||||
else if (i == 1) {
|
||||
else if (i == 2) {
|
||||
// <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
if (pthread_create(&thread_info[i].tid, NULL, message_processor_thread, index) != 0) {
|
||||
printf("Failed to create message processor thread %d\n", i);
|
||||
free(index);
|
||||
}
|
||||
}
|
||||
else if (i == 2){
|
||||
//<2F>ӿں<D3BF>mq
|
||||
else if (i == 3){
|
||||
/*//<2F>ӿں<D3BF>mq
|
||||
char* argv[] = { (char*)index };//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺Ų<CCBA><C5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
ThreadArgs* args = new ThreadArgs{1, argv};
|
||||
if (pthread_create(&thread_info[i].tid, NULL, cloudfrontthread, args) != 0) {
|
||||
printf("Failed to create message processor thread %d\n", i);
|
||||
delete args; // <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6>ͷ<EFBFBD>
|
||||
free(index);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
else {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
|
||||
Reference in New Issue
Block a user