Commit 6d75f29d authored by Aivan_2008's avatar Aivan_2008
Browse files

Several network protocol fixes

--HG--
branch : DeploymentQt
parent c544daf8d94a
......@@ -7,7 +7,7 @@ RdkQTcpThread::RdkQTcpThread()
}
RdkQTcpThread::RdkQTcpThread(QTcpSocket *socket, RDK::UTransferReader &packetReader, bool CreateSuspended, QObject *parent):
_socket(socket), QThread(parent), PacketReader(&packetReader)
_socket(socket), QThread(parent), PacketReader(&packetReader), Terminated(false)
{
CalcEnable = UCreateEvent(true);
CalcStarted = UCreateEvent(true);
......@@ -46,7 +46,7 @@ void RdkQTcpThread::AfterCalculate(void)
void RdkQTcpThread::run()
{
while(isRunning()) //???
while(!Terminated) //???
{
//if(WaitForSingleObject(CalcStarted,30) == WAIT_TIMEOUT)
// continue;
......@@ -160,6 +160,12 @@ void RdkQTcpThread::run()
}
}
void RdkQTcpThread::MarkForDeletion()
{
//connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
Terminated = true;
}
//=====================================================================================================
......@@ -167,7 +173,9 @@ RdkQTcpClient::RdkQTcpClient()
{
//TODO: , ?
TcpSocket = new QTcpSocket();
Thread = new RdkQTcpThread(TcpSocket, PacketReader,false, this);
Thread = new RdkQTcpThread(TcpSocket, PacketReader,false, NULL);
connect(Thread, SIGNAL(finished()), this, SLOT(deleteLater()));
Thread->PacketReceivedEvent = UCreateEvent(true);
Thread->PacketReaderUnlockEvent = UCreateMutex();
EraseTimer = new QTimer(this);
......@@ -178,13 +186,16 @@ RdkQTcpClient::RdkQTcpClient()
RdkQTcpClient::~RdkQTcpClient()
{
EraseTimer->stop();
if(Thread!=NULL)
{
Thread->terminate();
Thread->CalculationInProgress->wait(-1);
UDestroyEvent(Thread->PacketReceivedEvent);
UDestroyMutex(Thread->PacketReaderUnlockEvent);
Thread->CalculationNotInProgress->reset();
//Thread->MarkForDeletion();
//Thread->exit(0);
delete Thread;
}
if(EraseTimer!=NULL)
......
......@@ -44,6 +44,8 @@ public: //
public://
void run() override;
void MarkForDeletion();
// --------------------------
//
// --------------------------
......
......@@ -430,12 +430,16 @@ int Rpc_DelServer(int server_index)
{
if(ClientsArray[server_index]->SocketIsConnected())
Rpc_Disconnect(server_index);
ClientsArray[server_index]->Thread->MarkForDeletion();
//ClientsArray[server_index]->Thread->exit(0);
//ClientsArray[server_index]->Thread->wait();
}
catch(QException &exception)
{
return RDK_RPC_CONNECTION_ERROR;
}
delete ClientsArray[server_index];
//26.11.2020 - dele
//delete ClientsArray[server_index];
ClientsArray.erase(ClientsArray.begin()+server_index);
return 0;
......@@ -514,7 +518,7 @@ int Rpc_GetLastError(int server_index, const char* &result, int timeout)
return 0;
}
int Rpc_GetDeploymentState(int server_index, int &dp_state, int& dp_progress, int& dp_cap, int timeout)
int Rpc_GetDeploymentState(int server_index, int &dp_state, int& dp_progress, int& dp_cap, const char* &last_error, int timeout)
{
RDK::USerStorageXML request,response;
request.Create("Request");
......@@ -525,12 +529,25 @@ int Rpc_GetDeploymentState(int server_index, int &dp_state, int& dp_progress, i
static std::string res_string;
res_string=response.ReadString("Data", "").c_str();
QString rs_str = res_string.c_str();
//int state=-1;
std::stringstream ss(res_string.c_str());
ss>>dp_state>>dp_progress>>dp_cap;
dp_state = -1;
dp_progress = -1;
dp_cap = -1;
last_error = "Wrong dep state data received";
if(rs_str.size()>0)
{
QStringList rs_split = rs_str.split("|");
if(rs_split.size()>=4)
{
dp_state = rs_split[0].toInt();
dp_progress = rs_split[1].toInt();
dp_cap = rs_split[2].toInt();
last_error = rs_split[3].toUtf8().constData();
}
}
//dp_state=state;
return res;
}
......@@ -646,6 +663,7 @@ int Rpc_GetCalculationState(int server_index,
{
std::string res_string = response.ReadString("Data", "").c_str();
QString qsl = res_string.c_str();
qDebug()<<qsl;
if(qsl.length()>0)
{
QStringList spl = qsl.split("|");
......
......@@ -93,7 +93,7 @@ int Rpc_SetNumChannels(int server_index, int num_channels, int timeout);
int Rpc_GetChannelName(int server_index, int channel_index, const char* &result, int timeout);
int Rpc_GetDeploymentState(int server_index, int &dp_state, int& dp_progress, int& dp_cap, int timeout);
int Rpc_GetDeploymentState(int server_index, int &dp_state, int& dp_progress, int& dp_cap, const char *&last_error, int timeout);
int Rpc_SetChannelName(int server_index, int channel_index, const char* channel_name, int timeout);
......
......@@ -2072,7 +2072,7 @@ bool UProjectDeployerQt::UploadCalculationResults()
QDir results_dir(results_dir_path);
QString results_path="";
if(deploymentState>=DS_DeployFinished)
if(deploymentState>=DS_UploadFinished)
{
lastError = "Upload finished already";
return false;
......
......@@ -413,8 +413,10 @@ const char* URpcDecoderCommon::RemoteCall(const char *request, int &return_value
int stage_max = GetApplication()->GetProjectDeployer()->GetStageCap();
int stage_pos = GetApplication()->GetProjectDeployer()->GetStageProgress();
std::string le = GetApplication()->GetProjectDeployer()->GetLastError();
std::stringstream ss;
ss<<d_state<<" "<<stage_pos<<" "<<stage_max;
ss<<d_state<<"|"<<stage_pos<<"|"<<stage_max<<"|"<<le;
response=ss.str();
return_value=0;//UServerControlForm->SaveProject();
}
......@@ -472,8 +474,8 @@ const char* URpcDecoderCommon::RemoteCall(const char *request, int &return_value
//"<calculation_state>|<capture_state>|<capture_frid>|<capture_maxfrid>|<capture_finished>|<message>"
int calculation_state=-1;
int capture_state=-1;
int capture_frid=-1;
int capture_maxfrid=-1;
unsigned long long capture_frid=0;
unsigned long long capture_maxfrid=0;
std::string message = "test state message";
......@@ -576,6 +578,7 @@ const char* URpcDecoderCommon::RemoteCall(const char *request, int &return_value
std::stringstream ss;
ss<<rs<<"|"<<le;
response = ss.str();
exit(0);
return_value=0;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment