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

1.Minor network exchange changes

2.Potentioal python neteorking fix

--HG--
branch : DeploymentQt
parent 2662a6898dd9
......@@ -619,10 +619,40 @@ int Rpc_GetPreparationResult(int server_index, const char* &verbose_response, in
return res;
}
int Rpc_OpenPreparedProject(int server_index, const char* &verbose_response, int timeout)
{
int Rpc_OpenPreparedProject(int server_index, const char* &verbose_response, int timeout)
{
RDK::USerStorageXML request,response;
return ProcessSimpleCommand("OpenPreparedProject", server_index, -1, timeout, request, response);
}
int Rpc_RunPreparedProject(int server_index, int timeout)
{
RDK::USerStorageXML request,response;
return ProcessSimpleCommand("RunPreparedProject", server_index, -1, timeout, request, response);
}
int Rpc_GetCalculationState(int server_index,
int& calculation_state,
int& capture_state,
int& capture_frid,
int& capture_maxfrid,
const char* &message,
int timeout)
{
RDK::USerStorageXML request,response;
int res = ProcessSimpleCommand("GetCalculationState", server_index, -1, timeout, request, response);
std::string res_string = response.ReadString("Data", "").c_str();
QString qsl = res_string.c_str();
QStringList spl = qsl.split("|");
calculation_state = spl[0].toInt();
capture_state = spl[1].toInt();
capture_frid = spl[2].toInt();
capture_maxfrid = spl[3].toInt();
QString msg = spl[4];
message = msg.toUtf8().constData();
return res;
}
......@@ -111,4 +111,14 @@ int Rpc_GetLastError(int server_index, const char* &result, int timeout);
int Rpc_OpenPreparedProject(int server_index, const char* &verbose_response, int timeout);
int Rpc_RunPreparedProject(int server_index, int timeout);
int Rpc_GetCalculationState(int server_index,
int& calculation_state,
int& capture_state,
int& capture_frid,
int& capture_maxfrid,
const char* &message,
int timeout);
#endif // RDKQTCPCLIENTLIB_H
......@@ -817,6 +817,36 @@ UProjectDeployerQt::UProjectDeployerQt(void):
unet.LibClassCountTagName = "";
file_tags["TPySegmentatorUNet"] = unet;
component_classes.push_back("TPySegmentatorUNet");
MLlibDescr classifier_opencv;
classifier_opencv.LibName = "UOpenCvClassifier";
classifier_opencv.LibConfigFileTagName = "";
classifier_opencv.LibScriptFileTagName = "";
classifier_opencv.LibWeightFileTagName = "ModelPath";
classifier_opencv.LibClassCountTagName = "NumClasses";
file_tags["UOpenCvClassifier"] = classifier_opencv;
component_classes.push_back("UOpenCvClassifier");
MLlibDescr detector_opencv;
detector_opencv.LibName = "UOpenCvDetector";
detector_opencv.LibConfigFileTagName = "ConfigPath";
detector_opencv.LibScriptFileTagName = "";
detector_opencv.LibWeightFileTagName = "ModelPath";
detector_opencv.LibClassCountTagName = "";
file_tags["UOpenCvDetector"] = detector_opencv;
component_classes.push_back("UOpenCvDetector");
CaptureLibDescr opencv_videocapture;
opencv_videocapture.LibName = "TCaptureOpenCV";
opencv_videocapture.LibFrameIdStateName = "FramePosition";
opencv_videocapture.LibCaptureStateTagName = "CaptureState";
capture_tags["TCaptureOpenCV"] = opencv_videocapture;
CaptureLibDescr imseq_capture;
imseq_capture.LibName = "TCaptureImageSequence";
imseq_capture.LibFrameIdStateName = "FramePosition";
imseq_capture.LibCaptureStateTagName = "CaptureState";
capture_tags["TCaptureImageSequence"] = imseq_capture;
}
UProjectDeployerQt::~UProjectDeployerQt(void)
{
......@@ -940,7 +970,9 @@ int UProjectDeployerQt::StartProjectDeployment(int task_id)
QString abs_template_file = task_template_path;
abs_template_file.replace("{Database}", database_path);
QFile t_file(abs_template_file);
QFileInfo t_file(abs_template_file);
task_template_file_name = t_file.fileName();
if(!t_file.exists())
{
......@@ -951,15 +983,6 @@ int UProjectDeployerQt::StartProjectDeployment(int task_id)
task_template_download_required = false;
}
QFileInfo qfi(abs_template_file);
/*
QString task_template_destination_directory = qfi.filePath();
QString ftp_main_path = "";//Application->MainFtpPath().c_str();
QString ftp_template_zip_path = QString(task_template_destination_directory+".zip").replace(database_path, ftp_main_path);*/
q.prepare("SELECT weight_path, weight_confpath, weight_numcls, weight_in_W, weight_in_H, weight_out_format, weight_script FROM vid_an.weights WHERE weight_id="+QString::number(task_weights_id)+";");
q.exec();
q.first();
......@@ -1003,35 +1026,54 @@ int UProjectDeployerQt::StartProjectDeployment(int task_id)
task_weights_download_required = false;
}
q.prepare("SELECT script_path FROM vid_an.scripts WHERE script_id="+QString::number(task_script_id)+";");
q.exec();
q.first();
if(!q.isValid())
{
lastError = "Script query by script id invalid";
return 6;
}
task_script_path = q.value(0).toString();
absolute_script_file = task_script_path;
absolute_script_file.replace("{Database}", database_path);
QFileInfo fi_script_path(absolute_script_file);
q.finish();
q.clear();
if(!fi_script_path.exists())
if(task_script_id==0 || task_script_id==-1)
{
task_script_download_required=true;
//task_script_zip_url = QString(fi_script_path.filePath()+".zip").replace(database_path, ftp_main_path).toUtf8().constData();
task_script_download_required=false;
task_script_path="";
}
else
{
task_script_download_required=false;
}
q.prepare("SELECT script_path,script_name FROM vid_an.scripts WHERE script_id="+QString::number(task_script_id)+";");
q.exec();
q.first();
if(!q.isValid())
{
lastError = "Script query by script id invalid";
QString s = q.lastError().text();
return 6;
}
task_script_path = q.value(0).toString();
QString script_name = q.value(1).toString();
//TODO: Do something if dummy id change
if(task_script_id==2 && script_name=="NoScript")
{
task_script_download_required=false;
task_script_path="";
}
else
{
absolute_script_file = task_script_path;
absolute_script_file.replace("{Database}", database_path);
QFileInfo fi_script_path(absolute_script_file);
q.finish();
q.clear();
if(!fi_script_path.exists())
{
task_script_download_required=true;
//task_script_zip_url = QString(fi_script_path.filePath()+".zip").replace(database_path, ftp_main_path).toUtf8().constData();
}
else
{
task_script_download_required=false;
}
}
}
if(task_src_type==0) //video file
{
q.prepare("SELECT video_relpath FROM vid_an.videos WHERE video_id="+QString::number(task_src_id)+";");
q.prepare("SELECT video_relpath,video_frlen FROM vid_an.videos WHERE video_id="+QString::number(task_src_id)+";");
q.exec();
q.first();
if(!q.isValid())
......@@ -1040,6 +1082,7 @@ int UProjectDeployerQt::StartProjectDeployment(int task_id)
return 7;
}
task_src_path = q.value(0).toString();
task_src_frame_length = q.value(0).toInt();
task_src_fullpath = task_src_path;
task_src_fullpath.replace("{Database}", database_path);
QFileInfo qfi_src_file(task_src_fullpath);
......@@ -1064,7 +1107,7 @@ int UProjectDeployerQt::StartProjectDeployment(int task_id)
return 8;
}
task_src_path = q.value(0).toString();
int frame_length = q.value(1).toInt();
task_src_frame_length = q.value(1).toInt();
task_src_fullpath = task_src_path;
task_src_fullpath.replace("{Database}", database_path);
//QFileInfo qfi_src_file(abs_src_path);
......@@ -1072,7 +1115,7 @@ int UProjectDeployerQt::StartProjectDeployment(int task_id)
if(seq_dir.exists())
{
QStringList ldr = seq_dir.entryList(QDir::Filter::NoDotAndDotDot|QDir::Filter::Files);
if(ldr.size()>=frame_length)
if(ldr.size()>=task_src_frame_length)
{
task_src_download_required = false;
}
......@@ -1396,10 +1439,17 @@ int UProjectDeployerQt::OpenPreparedProject(std::string &response)
//RDK::Sleep(3);
Application->SetStorageBuildMode(1);
QString pdpath = GetTempProjectDeploymentPath().c_str();
QString project_path = pdpath+"/project_full.ini";
QString project_path = pdpath+"/"+task_template_file_name;
if(!Application->OpenProject(project_path.toUtf8().constData()))
{
lastError="UApplication OpenProject normally error";
response = lastError;
return 1;
}
if(AnalyzeLogForErrors(response)>=0)
{
lastError=response;
return 1;
}
////
......@@ -1452,7 +1502,7 @@ int UProjectDeployerQt::OpenProjectMockMode()
//
Application->SetStorageBuildMode(3);
QString pdpath = GetTempProjectDeploymentPath().c_str();
QString project_path = pdpath+"/project_full.ini";
QString project_path = pdpath+"/"+task_template_file_name;
if(!Application->OpenProject(project_path.toUtf8().constData()))
{
lastError="UApplication OpenProject Mock Components error";
......@@ -1487,6 +1537,8 @@ int UProjectDeployerQt::SetupProjectMockParameters()
lastError="Model does not contain video data source, fix project file/task parameters";
return 1;
}
capture_class_name = "TCaptureOpenCV";
capture_component_name = vid_names[0];
video_cont = model->GetComponentL(vid_names[0]);
bool *video_Activity = video_cont->AccessPropertyData<bool>("Activity");
bool *video_EnableCapture = video_cont->AccessPropertyData<bool>("EnableCapture");
......@@ -1534,6 +1586,8 @@ int UProjectDeployerQt::SetupProjectMockParameters()
return 1;
}
capture_class_name = "TCaptureImageSequence";
capture_component_name = imseq_names[0];
imseq_cont = model->GetComponentL(imseq_names[0]);
bool *imseq_Activity = imseq_cont->AccessPropertyData<bool>("Activity");
std::string *imseq_Path = imseq_cont->AccessPropertyData<std::string>("Path");
......@@ -1605,7 +1659,9 @@ int UProjectDeployerQt::SetupProjectMockParameters()
neural_cont = model->GetComponentL(components_names[0]);
bool *nn_Activity = neural_cont->AccessPropertyData<bool>("Activity");
std::string *nn_ScriptFile = neural_cont->AccessPropertyData<std::string>(file_tags[class_name].LibScriptFileTagName.c_str());
std::string *nn_ScriptFile;
if(file_tags[class_name].LibScriptFileTagName!="")
nn_ScriptFile = neural_cont->AccessPropertyData<std::string>(file_tags[class_name].LibScriptFileTagName.c_str());
std::string *nn_WeightsFile = neural_cont->AccessPropertyData<std::string>(file_tags[class_name].LibWeightFileTagName.c_str());
std::string *nn_ConfigFile;
int *nn_ClassCount;
......@@ -1615,7 +1671,8 @@ int UProjectDeployerQt::SetupProjectMockParameters()
if(file_tags[class_name].LibClassCountTagName!="")
nn_ClassCount = neural_cont->AccessPropertyData<int>(file_tags[class_name].LibClassCountTagName.c_str());
*nn_Activity = true;
*nn_ScriptFile = absolute_script_file.toUtf8().constData();
if(file_tags[class_name].LibScriptFileTagName!="")
*nn_ScriptFile = absolute_script_file.toUtf8().constData();
*nn_WeightsFile = absolute_weights_file.toUtf8().constData();
if(file_tags[class_name].LibConfigFileTagName!="")
*nn_ConfigFile = absolute_config_file.toUtf8().constData();
......@@ -1635,6 +1692,102 @@ int UProjectDeployerQt::CloseMockProject()
}
///
int UProjectDeployerQt::RunPreparedProject()
{
// ,
Application->StartChannel(-1);
return 0;
}
/// ( -2/0/1 )
int UProjectDeployerQt::GetCalculationState()
{
std::vector<UEngineStateThread::UCalcState> thread_states = Application->GetEngineControl()->GetEngineStateThread()->ReadCalcThreadStates();
if(thread_states.empty())
{
lastError = "Calculation threads empty!";
return -1;
}
if(thread_states.size()>1)
{
lastError = "More than one calculation threads in solver!";
return -1;
}
UEngineStateThread::UCalcState &state = thread_states[0];
return state;
}
///
/// false
/// @state - ( , 10000 - )
///
/// @frame_id -
bool UProjectDeployerQt::GetCaptureState(int &state, int& frame_id, int& max_frame_id)
{
if(capture_class_name=="")
{
state=-1;
frame_id=-1;
max_frame_id=-1;
lastError = "Capture class name indefined";
return false;
}
if(capture_component_name=="")
{
state=-1;
frame_id=-1;
max_frame_id=-1;
lastError = "Capture component name indefined";
return false;
}
RDK::UELockPtr<RDK::UNet> model = RDK::GetModelLock<RDK::UNet>(0);
if(!model)
{
state=-1;
frame_id=-1;
max_frame_id=-1;
lastError = "RTVModel access error";
return false;
}
RDK::UEPtr<RDK::UContainer> capture_container;
capture_container = model->GetComponentL(capture_component_name);
CaptureLibDescr &lib_descr = capture_tags[capture_class_name];
if(lib_descr.LibName!=capture_class_name)
{
state=-1;
frame_id=-1;
lastError = "Capture class description access error";
return false;
}
int *capture_state = capture_container->AccessPropertyData<int>(lib_descr.LibCaptureStateTagName.c_str());
int *fr_id = capture_container->AccessPropertyData<int>(lib_descr.LibCaptureStateTagName.c_str());
state=*capture_state;
frame_id=*fr_id;
max_frame_id = task_src_frame_length;
return true;
}
///
/// false , true
/// @error -
bool UProjectDeployerQt::ProcessCalculationLog(std::string &error)
{
int error_index = AnalyzeLogForErrors(error);
if(error_index>=0)
{
lastError = error;
return false;
}
error="No log errors";
return true;
}
......
......@@ -36,6 +36,20 @@ struct MLlibDescr
}
};
struct CaptureLibDescr
{
std::string LibName;
std::string LibFrameIdStateName;
std::string LibCaptureStateTagName;
CaptureLibDescr(){
LibName="";
LibFrameIdStateName="";
LibCaptureStateTagName="";
}
};
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
{
struct FtpFile *out = (struct FtpFile *)stream;
......@@ -183,6 +197,9 @@ bool task_template_download_required;
QString task_template_name;
// ()
QString task_template_path;
// (project.ini, project_full.ini ) ,
// ,
QString task_template_file_name;
//
//
......@@ -224,6 +241,9 @@ bool task_src_download_required;
QString task_src_zip_url;
// ( {Database}/Temp )
QString download_temp_path;
// ( ,
// )
int task_src_frame_length;
// FTP
UProjectDeployProcessingThread *deployProcessingThread;
......@@ -243,6 +263,14 @@ DeploymentState deploymentState;
std::map<std::string, MLlibDescr> file_tags;
std::vector<std::string> component_classes;
std::map<std::string, CaptureLibDescr> capture_tags;
//
//std::vector<std::string> capture_classes;
//
std::string capture_class_name;
std::string capture_component_name;
protected://
//
......@@ -262,6 +290,8 @@ virtual int PrepareProject(std::string &response);
virtual int GetPreparationResult(std::string &response);
///
virtual int OpenPreparedProject(std::string &response);
///
virtual int RunPreparedProject();
///
/// , 2
......@@ -279,6 +309,18 @@ virtual std::string GetLastError();
/// (, ?)
virtual std::string GetProjectFileName();
/// ( -2/0/1 )
virtual int GetCalculationState();
///
/// false
/// @state -
/// @frame_id -
virtual bool GetCaptureState(int &state, int& frame_id, int& max_frame_id);
///
/// false , true
/// @error -
virtual bool ProcessCalculationLog(std::string &error);
public: //
///
......
......@@ -7,7 +7,7 @@
#include "../UApplication.h"
#include "UServerTransportTcpQt.h"
#include <QDataStream>
#include <QCoreApplication>
///
//extern RDK::UApplication RdkApplication;
......@@ -82,10 +82,9 @@ UServerTransportTcpQt::UServerTransportTcpQt()
{
server=new QTcpServer();
connect(server, SIGNAL(newConnection()), this, SLOT(ServerNewConnection()));
commandQueueTimer = new QTimer(this);
commandQueueTimer->setInterval(10);
commandQueueTimer->moveToThread(QCoreApplication::instance()->thread());
commandQueueTimer->setSingleShot(false);
commandQueueTimer->start();
connect(commandQueueTimer, SIGNAL(timeout()), this, SLOT(CommandQueueTimerTimeout()));
......@@ -293,7 +292,7 @@ int UServerTransportTcpQt::ReadIncomingBytes(std::string &bind, std::vector<unsi
QDataStream in;
in.setDevice(socket);
in.setVersion(QDataStream::Qt_5_0);
in.startTransaction();
//in.startTransaction();
char *buffer;
uint length=0;
in.readBytes(buffer, length);
......@@ -390,7 +389,7 @@ void UServerTransportTcpQt::SendResponseBuffer(std::vector<unsigned char> buffer
QDataStream out;
out.setDevice(socket);
out.setVersion(QDataStream::Qt_5_0);
out.startTransaction();
//out.startTransaction();
char* buf;
buf = new char[buffer.size()];
......
......@@ -107,6 +107,13 @@ int UProjectDeployer::GetPreparationResult(std::string &response)
return -1;
}
///
int UProjectDeployer::RunPreparedProject()
{
return -1;
}
std::string UProjectDeployer::GetLastError()
{
return std::string();
......@@ -117,6 +124,39 @@ std::string UProjectDeployer::GetProjectFileName()
return std::string();
}
/// ( -2/0/1 )
int UProjectDeployer::GetCalculationState()
{
return -1;
}
///
/// false
/// @state -
/// @frame_id -
bool UProjectDeployer::GetCaptureState(int &state, int& frame_id, int &max_frame_id)
{
state=-1;
frame_id=-1;
max_frame_id=-1;
return false;
}
///
/// false , true
/// @error -
bool UProjectDeployer::ProcessCalculationLog(std::string &error)
{
error="ProcessCalculationLog in base class called!";
return false;
}
/// true /
/// false
/*bool UProjectDeployer::CaptureProcessingFinished(int frame_number)
{
return false;
}*/
/*
void UProjectDeployer::SetProjectIndices(int gt_id, int sln_id, int weights_id, int script_id)
{
......
......@@ -65,6 +65,8 @@ virtual int PrepareProject(std::string &response);
virtual int GetPreparationResult(std::string &response);
///
virtual int OpenPreparedProject(std::string &response);
///
virtual int RunPreparedProject();
/// -
virtual void SetDatabaseAccess(const std::string &db_address, const std::string &db_name, const std::string &db_login, const std::string &db_password);
......@@ -85,6 +87,21 @@ virtual void SetTempProjectDeploymentPath(const std::string &path);
virtual std::string GetTempProjectDeploymentPath();
/// ( -2/0/1 )
virtual int GetCalculationState();
///
/// false
/// @state -
/// @frame_id -
virtual bool GetCaptureState(int &state, int& frame_id, int& max_frame_id);
///
/// false , true
/// @error -
virtual bool ProcessCalculationLog(std::string &error);
/// true /
/// false
//virtual bool CaptureProcessingFinished(int frame_number);
// --------------------------
//
// --------------------------
......
......@@ -175,16 +175,16 @@ bool URpcDecoderCommon::IsCmdSupported(const UEPtr<URpcCommand> &command) const
{
return true;
}
/*else
if(cmd == "GetDeploymentStageMax")
else
if(cmd == "RunPreparedProject")
{
return true;
}
else