Commit 534895fc authored by Alexab's avatar Alexab
Browse files

Merge with StandaloneRun

--HG--
branch : MockCompsTest
......@@ -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;
......@@ -459,6 +463,12 @@ int Rpc_StopChannel(int server_index, int channel_index, int timeout)
return ProcessSimpleCommand("StopChannel", server_index, channel_index, timeout, request, response);
}
int Rpc_StartTraining(int server_index, int channel_index, int timeout)
{
RDK::USerStorageXML request, response;
return ProcessSimpleCommand("StartTraining", server_index, channel_index, timeout, request, response);
}
int Rpc_GetNumChannels(int server_index, int &results, int timeout)
{
RDK::USerStorageXML request,response;
......@@ -514,7 +524,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 +535,31 @@ 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();
dp_state = -1;
dp_progress = -1;
dp_cap = -1;
last_error = "Wrong dep state data received";
//int state=-1;
std::stringstream ss(res_string.c_str());
ss>>dp_state>>dp_progress>>dp_cap;
static std::string le_string;
// qDebug()<<"rs_str = "<<rs_str;
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();
qDebug()<<"rs_split[3] = "<<rs_split[3];
qDebug()<<"rs_split[3].toUtf8().constData() = "<<rs_split[3].toUtf8().constData();
le_string = rs_split[3].toUtf8().constData();
last_error = le_string.c_str();
}
}
//dp_state=state;
return res;
}
......@@ -610,10 +639,13 @@ int Rpc_GetPreparationResult(int server_index, const char* &verbose_response, in
res_string=response.ReadString("Data", "").c_str();
static std::string msg="";
QString qs = res_string.c_str();
QStringList spl = qs.split("|");
QStringList spl = qs.split("|-|");
int rs = spl[0].trimmed().toInt();
verbose_response = spl[1].toUtf8().constData();
msg = spl[1].toUtf8().constData();
verbose_response = msg.c_str();
if(res)
return res;
......@@ -641,14 +673,16 @@ int Rpc_GetCalculationState(int server_index,
{
RDK::USerStorageXML request,response;
int res = ProcessSimpleCommand("GetCalculationState", server_index, -1, timeout, request, response);
static std::string s="";
if(res==0)
{
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("|");
QStringList spl = qsl.split("|-|");
if(spl.size()==5)
{
calculation_state = spl[0].toInt();
......@@ -656,11 +690,12 @@ int Rpc_GetCalculationState(int server_index,
capture_frid = spl[2].toInt();
capture_maxfrid = spl[3].toInt();
QString msg = spl[4];
message = msg.toUtf8().constData();
s = msg.toUtf8().constData();
message = s.c_str();
}
else
{
std::string s = "Wrong result: '" + res_string + "'";
s = "Wrong result: '" + res_string + "'";
message = s.c_str();
}
}
......@@ -668,4 +703,101 @@ int Rpc_GetCalculationState(int server_index,
return res;
}
int Rpc_FinishCalculation(int server_index, bool& result, const char* &last_error, int timeout)
{
RDK::USerStorageXML request,response;
int res = ProcessSimpleCommand("FinishCalculation", server_index, -1, timeout, request, response);
std::string res_string;
res_string=response.ReadString("Data", "").c_str();
static std::string le="";
if(res_string!="")
{
QString qs = res_string.c_str();
QStringList spl = qs.split("|-|");
if(spl.size()>=2)
{
result = spl[0].trimmed().toInt();
le = spl[1].toUtf8().constData();
last_error = le.c_str();
}
}
return res;
}
int Rpc_UploadCalculationResults(int server_index, bool& result, const char* &last_error, int timeout)
{
RDK::USerStorageXML request,response;
int res = ProcessSimpleCommand("UploadCalculationResults", server_index, -1, timeout, request, response);
std::string res_string;
res_string=response.ReadString("Data", "").c_str();
if(res_string!="")
{
QString qs = res_string.c_str();
QStringList spl = qs.split("|-|");
if(spl.size()>=2)
{
result = spl[0].trimmed().toInt();
if(!result)
last_error = spl[1].toUtf8().constData();
}
}
return res;
}
int Rpc_GetUploadState(int server_index, int& upload_state, const char* &last_error, int timeout)
{
RDK::USerStorageXML request,response;
int res = ProcessSimpleCommand("GetUploadState", server_index, -1, timeout, request, response);
std::string res_string;
res_string=response.ReadString("Data", "").c_str();
static std::string le_str="";
if(res_string!="")
{
QString qs = res_string.c_str();
QStringList spl = qs.split("|-|");
if(spl.size()>=2)
{
upload_state = spl[0].trimmed().toInt();
le_str = spl[1].toUtf8().constData();
last_error = le_str.c_str();
}
}
if(res)
return res;
}
int Rpc_CloseSolver(int server_index, bool& result, const char* &last_error, int timeout)
{
RDK::USerStorageXML request,response;
int res = ProcessSimpleCommand("CloseSolver", server_index, -1, timeout, request, response);
std::string res_string;
res_string=response.ReadString("Data", "").c_str();
if(res_string!="")
{
QString qs = res_string.c_str();
QStringList spl = qs.split("|-|");
if(spl.size()>=2)
{
result = spl[0].trimmed().toInt();
if(!result)
last_error = spl[1].toUtf8().constData();
}
}
return res;
}
......@@ -85,6 +85,8 @@ int Rpc_StartChannel(int server_index, int channel_index, int timeout);
int Rpc_StopChannel(int server_index, int channel_index, int timeout);
int Rpc_StartTraining(int server_index, int channel_index, int timeout);
int Rpc_ResetChannel(int server_index, int channel_index, int timeout);
int Rpc_GetNumChannels(int server_index, int &results, int timeout);
......@@ -93,7 +95,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);
......@@ -121,4 +123,13 @@ int Rpc_GetLastError(int server_index, const char* &result, int timeout);
const char* &message,
int timeout);
int Rpc_FinishCalculation(int server_index, bool& result, const char* &last_error, int timeout);
int Rpc_UploadCalculationResults(int server_index, bool& result, const char* &last_error, int timeout);
int Rpc_GetUploadState(int server_index, int& upload_state, const char* &last_error, int timeout);
int Rpc_CloseSolver(int server_index, bool& result, const char* &last_error, int timeout);
#endif // RDKQTCPCLIENTLIB_H
......@@ -10,8 +10,12 @@ DEFINES += RDK_QT
CONFIG += c++11
INCLUDEPATH += ../RdkQTcpClientLib
LIBS+= -L../../../Bin/Platform/Linux/RdkQTcpClientLib -lRdkQTcpClientLib
linux {
LIBS+= -L../../../Bin/Platform/Linux/RdkQTcpClientLib -lRdkQTcpClientLib
} else:windows {
LIBS+= -L../../../Bin/Platform/Win/RdkQTcpClientLib -lRdkQTcpClientLib
}
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
......
......@@ -213,3 +213,15 @@ void RdkQTcpClientWidget::onPushButtonPingClick()
std::cerr<<"onPushButtonTestClick sum: "<<sum;
}
*/
void RdkQTcpClientWidget::on_pushButtonStartTraining_clicked()
{
const char* serverAnswer=NULL;
int res=Rpc_StartTraining(0, ui->lineEditChannelIndex->text().toInt(), 60000);
if(WriteLogError(res))
{
serverAnswer=Rpc_GetServerAnswerDebug(0);
if(serverAnswer != NULL && ui->checkBoxWriteServerResponse->isChecked())
ui->plainTextEditLog->appendPlainText(QString(serverAnswer));
}
}
......@@ -40,6 +40,8 @@ private slots:
void onPushButtonLoadConfigClick();
void on_pushButtonStartTraining_clicked();
private:
Ui::RdkQTcpClientWidget *ui;
std::map<int, QString> Errors;
......
......@@ -183,6 +183,13 @@
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="pushButtonStartTraining">
<property name="text">
<string>Start Training</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxWriteServerResponse">
<property name="cursor">
......
This diff is collapsed.
......@@ -27,12 +27,14 @@ struct MLlibDescr
std::string LibWeightFileTagName; //
std::string LibConfigFileTagName; //
std::string LibClassCountTagName; //
std::string LibUseFullPathTagName; //
MLlibDescr(){
LibName="";
LibScriptFileTagName="";
LibWeightFileTagName="";
LibConfigFileTagName="";
LibClassCountTagName="";
LibUseFullPathTagName = "UseFullPath";// ,
}
};
......@@ -99,6 +101,22 @@ enum DeploymentState
DS_Error=100
};
enum DatabaseTaskStatus
{
TS_New=0,
TS_Accepted=1,
TS_Deployment=2,
TS_Calculation=3,
TS_Finished=4,
TS_Error=1000
};
enum TemplateType
{
TT_VideoAnalytics=1,
TT_NeuralInterface=2
};
class RDK_LIB_TYPE UProjectDeployProcessingThread: public QThread
{
Q_OBJECT
......@@ -112,6 +130,7 @@ public:
void SetDatabasePath(const QString& path);
void SetDownloadTempPath(const QString& path);
void SetFtpRemoteBasePath(const QString& path);
void SetStorageMountPath(const QString& path);
void SetDeploymentState(const DeploymentState& state);
void SetDeploymentProgress(const int &progress);
void SetDeploymentProgressCap(const int &value);
......@@ -142,12 +161,19 @@ private:
bool UnpackZipFolder(const QString &local_zip_folder, const QString& local_dst_folder);
bool UnpackZipFile(const QString &local_zip_folder, const QString& local_dst_folder);
bool RecursiveCopyFiles(const QString& src_dir_path, const QString& dst_dir_path);
void DeployTemplate();
void DeployTemplate2();
void DeployDirectory(const QString& file_with_template);
bool VerifyTemplate();
void DeployScript2();
void DeployScript();
bool VerifyScript();
void DeployWeights2();
void DeployWeights();
bool VerifyWeights();
void DeployData2();
void DeployData();
bool VerifyData();
......@@ -159,6 +185,7 @@ private:
QString databasePath;
QString ftpRemoteBasePath;
QString downloadTempPath;
QString storageMountPath;
bool template_dr, weights_dr, script_dr, videosource_dr;
int videosource_type;
......@@ -170,7 +197,7 @@ private:
QProcess zip_process;
std::string lastError;
QString lastError;
CURL *curl;
CURLcode res;
......@@ -181,7 +208,7 @@ class RDK_LIB_TYPE UProjectResultsUploadingThread: public QThread
Q_OBJECT
public:
UProjectResultsUploadingThread();
UProjectResultsUploadingThread(bool standalone = false);
~UProjectResultsUploadingThread();
void run() override;
......@@ -198,25 +225,33 @@ public:
void SetRemoteFtpPath(const QString& ftp_path);
QString GetRemoteFtpPath();
void SetRemoteStoragePath(const QString& strg_path);
QString GetRemoteStoragePath();
QString GetLastError();
DeploymentState GetUploadState();
private:
bool CopyResultsToDestinationDir();
bool ZipResults();
bool UploadResultsViaFtp();
bool RecursiveCopyFiles(const QString& src_dir_path, const QString& dts_dir_path);
bool CopyResultsToDestinationDir();
bool CopyResultsToRemoteStorageDir();
bool RecursiveCopyFiles(const QString& src_dir_path, const QString& dst_dir_path);
private slots:
void processReadyReadStandardError();
void processReadyReadStandardOutput();
private:
bool standalone;
QString projectResultsDir;
QString storageResultsDir;
QString databasePath;
QString remoteFtpPath;
QString remoteStoragePath;
QString lastError;
DeploymentState uploadState;
......@@ -225,6 +260,72 @@ private:
};
// , ,
// ()
// - ,
//
enum ProjectRunState {
PS_Undefined = 0, // ,
PS_Initialization = 100, // - ,
PS_Deployment = 101, // NS_Connected
PS_ProjectPreparation = 102, // ,
PS_ProjectOpening = 103, //
PS_Calculation = 104, //
PS_Finalization = 105, // ,
PS_ResultsUploading = 106, //
PS_Termination = 107, // ,
};
class RDK_LIB_TYPE UProjectRunThread: public QThread
{
Q_OBJECT
public:
UProjectRunThread(UProjectDeployer* deployer);
~UProjectRunThread();
void run() override;
private:
UProjectDeployer* Deployer;
std::string error_string;
unsigned long long last_frame_count;
ProjectRunState projectRunState;
private:
/// :
/// 1.
/// 2. ?
/// 3.
void PrepProject();
///
void OpenProject();
///
void RunProject();
///
void FinishProject();
void UploadResults();
std::string ParseDeploymentState(DeploymentState state);
void ProjectStateInitialization();
void ProjectStateDeployment();
void ProjectStateCalculation();
void ProjectStateFinalization();
void ProjectStateTermination();
};
class RDK_LIB_TYPE UProjectDeployerQt: public UProjectDeployer
{
......@@ -327,12 +428,20 @@ std::map<std::string, CaptureLibDescr> capture_tags;
std::string capture_class_name;
std::string capture_component_name;
std::string predictor_class_name;
std::string predictor_component_name;
//
QDateTime processing_start_datetime;
QDateTime processing_end_datetime;
UProjectResultsUploadingThread *projectResultsUploadingThread;
// standalone ( )
int serverStandaloneTask;
TemplateType template_type;
protected://
//
......@@ -341,7 +450,8 @@ bool DestroyProcessingThread();
public: //
/// , ( )
virtual int StartProjectDeployment(int deploy_task_id);
/// standalone -