void SECCAuthorizationSetup::process_message(void* message)
{
char buffer[1024];
int clientfd = getClientFd();
std::cout << "SECCAuthorizationSetup " << clientfd << std::endl;
ResponseCode responseCode;
std::vector<AuthEnum> AuthorizationServices;
PnCAuthSetupResParams PnC_ASResAuthorizationMode;
EIMAuthSetupResParams EIM_ASResAuthorizationMode;
//received_req.Header.SessionID
AuthorizationSetupRes auth_setup_res("SessionID",20 ,responseCode.OK,AuthorizationServices,true,PnC_ASResAuthorizationMode,EIM_ASResAuthorizationMode);
nlohmann::json k ;
k["SessionID"] = auth_setup_res.Header.SessionID;
k["Timestamp"] = auth_setup_res.Header.Timestamp;
k["ResponseCode"] = responseCode.OK;
k["PnCAuthSetupResParams"] = true;
k["EIMAuthSetupResParams"] = true;
std::string serialized_data = k.dump();
EVCCAuthorizationSetup evccAuthorizationSetup(nullptr,3,clientfd);
std::cout << "while1" << std::endl;
evccAuthorizationSetup.process_message(nullptr);
std::thread sendThread([&]{
while(true)
{
int bytes_sent = send_data_server(clientfd, serialized_data.c_str());
if(bytes_sent == -1)
{
std::cerr << "Send error: " << strerror(errno) << std::endl;
}else{
std::cout << "Sent bytes: " << bytes_sent << " to clientfd: " << clientfd << std::endl;
}
std::this_thread::sleep_for(std::chrono::milliseconds(500)); //// 可以根據需要調整發送頻率
}
}
);
if(sendThread.joinable())
{
std::cout << "Thread created successfully" << std::endl;
}else{
std::cerr << "Failed to create thread!" << std::endl;
}
sendThread.detach();
std::cout << "while2" << std::endl;
// while(true)
// {
// int received_bytes = receive_data_server(clientfd, buffer, sizeof(buffer));
// int sock_fd;
// std::cout << "11111111112" << endl;
// if(received_bytes > 0)
// {
// buffer[received_bytes] = '\0';
// nlohmann::json j = nlohmann::json::parse(buffer);
// AuthorizationSetupReq received_req(j["SessionID"].get<std::string>(), j["Timestamp"].get<int>());
// received_req.Header.SessionID = j["SessionID"];
// received_req.Header.Timestamp = j["Timestamp"];
// sock_fd = j["Sockfd"];
// std::cout << "Received from client: " << received_req.Header.SessionID << std::endl;
// std::cout << "Received from client: " << received_req.Header.Timestamp << std::endl;
// std::cout << "Received from client: sock_fd " << sock_fd << std::endl;
// //--------
// break;
// }else{
// std::cerr << "Error receiving data" << std::endl;
// break;
// }
// std::cout << "while0" << std::endl;
// }
};