Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.0 on 2022-01-18 at 14:00 UTC+1 (a few minutes of down time)

Commit aa1c07db authored by vlad_burin's avatar vlad_burin
Browse files

Слияние с DeploymentQt

--HG--
branch : MockCompsTest
......@@ -258,6 +258,11 @@ int Rpc_UnInit(void)
return 0;
}
bool Rpc_IsInit()
{
return (ClientsArray.size()>0);
}
///
int Rpc_Ping(int server_index, int timeout)
......@@ -408,6 +413,11 @@ int Rpc_AddServer(void)
return 0;
}
int Rpc_LastServerId()
{
return (int)ClientsArray.size()-1;
}
int Rpc_DelServer(int server_index)
{
if((int)ClientsArray.size()-1 < server_index)
......@@ -491,6 +501,42 @@ int Rpc_GetChannelName(int server_index, int channel_index, const char* &result,
return 0;
}
int Rpc_GetDeploymentState(int server_index, int &dp_state, int& dp_progress, int& dp_cap, int timeout)
{
RDK::USerStorageXML request,response;
request.Create("Request");
request.WriteInteger("Test", -1);
int res=ProcessSimpleCommand("GetDeploymentState", server_index, -1, timeout, request, response);
if(res)
return res;
static std::string res_string;
res_string=response.ReadString("Data", "").c_str();
//int state=-1;
std::stringstream ss(res_string.c_str());
ss>>dp_state>>dp_progress>>dp_cap;
//dp_state=state;
return res;
}
int Rpc_GetLastError(int server_index, int channel_indes, int timeout, const char* &err_str)
{
RDK::USerStorageXML request,response;
request.Create("Request");
int res=ProcessSimpleCommand("GetLastError", server_index, -1, timeout, request, response);
/*if(res)
return res;*/
static std::string res_string;
res_string=response.ReadString("Data", "").c_str();
err_str = res_string.c_str();
return res;
}
int Rpc_SetChannelName(int server_index, int channel_index, const char* channel_name, int timeout)
{
RDK::USerStorageXML request,response;
......@@ -516,3 +562,24 @@ int Rpc_LoadProject(int server_index, const char* project_path, int timeout)
request.WriteString("FileName", project_path);
return ProcessSimpleCommand("LoadProject", server_index, -1, timeout, request, response);
}
int Rpc_DeployProject(int server_index, int task_index, int &resp, int timeout)
{
RDK::USerStorageXML request,response;
request.Create("Request");
request.WriteInteger("TaskId", task_index);
int res=ProcessSimpleCommand("DeployProject", server_index, 0, timeout, request, response);
static std::string res_string;
res_string=response.ReadString("Data", "").c_str();
resp = atoi(res_string.c_str());
//result=res_string.c_str();
if(res)
return res;
}
......@@ -64,6 +64,8 @@ int Rpc_Init(int num_serverPtz_MoveZoom);
int Rpc_UnInit(void);
bool Rpc_IsInit();
///
int Rpc_Ping(int server_index, int timeout);
......@@ -75,6 +77,8 @@ int Rpc_AddServer(void);
int Rpc_DelServer(int server_index);
int Rpc_LastServerId();
///////////////
int Rpc_StartChannel(int server_index, int channel_index, int timeout);
......@@ -89,10 +93,14 @@ 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_SetChannelName(int server_index, int channel_index, const char* channel_name, int timeout);
int Rpc_SaveProject(int server_index, int timeout);
int Rpc_LoadProject(int server_index, const char* project_path, int timeout);
int Rpc_DeployProject(int server_index, int task_index, int &resp, int timeout=-1);
#endif // RDKQTCPCLIENTLIB_H
This diff is collapsed.
......@@ -2,43 +2,248 @@
#define UProjectDeployerQtH
#include "../../../Deploy/Include/rdk.h"
#include "../UProjectDeployer.h"
#include "../UIVisualController.h"
#include <QtSql>
#include <QThread>
#include <QMutex>
#include <thread>
#include <mutex>
#include <curl/curl.h>
struct FtpFile {
const char *filename;
FILE *stream;
};
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
{
struct FtpFile *out = (struct FtpFile *)stream;
if(!out->stream) {
/* open file for writing */
out->stream = fopen(out->filename, "wb");
if(!out->stream)
{
std::cerr<<"Stream out failure";
return -1; /* failure, can't open file to write */
}
}
size_t res = fwrite(buffer, size, nmemb, out->stream);
std::cerr<<"Res = "<<res<<std::endl;
return res;
}
namespace RDK{
class UApplication;
class RDK_LIB_TYPE UProjectDeployerQt: public UAppController
enum DeploymentState
{
DS_NULL=0,
DS_Unknown=1,
DS_DownloadTemplate=2,
DS_UnpackTemplate=3,
DS_DownloadWeights=4,
DS_UnpackWeights=5,
DS_DownloadScripts=6,
DS_UnpackScripts=7,
DS_DownloadData=8,
DS_UnpackData=9,
DS_Finished=10,
DS_Error=100
};
class RDK_LIB_TYPE UProjectDeployProcessingThread: public QThread
{
Q_OBJECT
public:
UProjectDeployProcessingThread();
~UProjectDeployProcessingThread();
void run() override;
void SetDatabasePath(const QString& path);
void SetDownloadTempPath(const QString& path);
void SetDeploymentTempPath(const QString& path);
void SetFtpRemoteBasePath(const QString& path);
void SetDeploymentState(const DeploymentState& state);
void SetDeploymentProgress(const int &progress);
void SetDeploymentProgressCap(const int &value);
void PrepareProjectDeployment(bool task_template_dr, const QString& task_template_path,
bool task_weights_dr, const QString& task_weights_path,
bool task_script_dr, const QString& task_script_path,
bool task_vsrc_dr, int task_vrc_type, const QString& task_vsrc_path);
void RunProjectDeployment();
///Get
QString GetDatabasePath();
QString GetFtpRemoteBasePath();
QString GetDeploymentTempPath();
QString GetDownloadTempPath(); //
DeploymentState GetDeploymentState();
int GetDeploymentProgress();
int GetDeploymentProgressCap();
std::string GetLastError();
private slots:
void processReadyReadStandardError();
void processReadyReadStandardOutput();
private:
bool DownloadZip(const QString &remote_url, const QString& dst_zip_file);
bool UnpackZipFolder(const QString &local_zip_folder, const QString& local_dst_folder);
bool UnpackZipFile(const QString &local_zip_folder, const QString& local_dst_folder);
void DeployTemplate();
bool VerifyTemplate();
void DeployScript();
bool VerifyScript();
void DeployWeights();
bool VerifyWeights();
void DeployData();
bool VerifyData();
// , , ?
//bool ErrorOccured();
// , ,
//std::string GetLastError();
private:
QMutex deploymentStateMutex;
QMutex deploymentProgressMutex;
QMutex deploymentProgressCapMutex;
QString databasePath;
QString ftpRemoteBasePath;
QString deploymentTempPath;
QString downloadTempPath;
bool template_dr, weights_dr, script_dr, videosource_dr;
int videosource_type;
QString template_path, weights_path, script_path, videosource_path;
DeploymentState deploymentState;
int deploymentProgressCap;
int deploymentProgress;
QProcess zip_process;
std::string lastError;
CURL *curl;
CURLcode res;
};
class RDK_LIB_TYPE UProjectDeployerQt: public UProjectDeployer
{
friend class UApplication;
protected: //
protected: //
///
UEPtr<UApplication> Application;
QSqlDatabase *db;
protected: //
protected: //
//
QString task_name; //
int task_template_id; //
int task_weights_id; //
int task_src_type; // (0-, 1- )
int task_src_id; //
// -
bool task_template_download_required;
// ( ?)
QString task_template_name;
// ()
QString task_template_path;
// ZIP ,
//std::string task_template_zip_url;
//
//
QString task_weights_path;
//
bool task_weights_download_required;
// ( ,
bool task_weights_conf_download_required;
// -
QString task_weights_config_path;
//
//std::string task_weights_zip_url;
//std::string task_weights_conf_zip_url;
//
//
int task_script_id;
// ()
QString task_script_path;
//
bool task_script_download_required;
//
//std::string task_script_zip_url;
//
// ( )
QString task_src_path;
//
bool task_src_download_required;
// ( )
QString task_src_zip_url;
QString deployment_temp_path;
QString download_temp_path;
UProjectDeployProcessingThread *deployProcessingThread;
/*
//?
// (- 1)
std::string project_path;
std::string project_url;
// :
std::string database_address;
std::string database_port;
std::string database_login;
std::string database_password;
//
int project_gt_id;
int project_sln_id;
int project_weigts_id;
int project_script_id;
*/
protected://
//
bool DestroyProcessingThread();
public: //
virtual int StartProjectDeployment(const std::string &project_path, const std::string &project_url);
virtual void SetDatabaseCredentials(const std::string &db_address, const std::string &db_port, const std::string &db_login, const std::string &db_password);
virtual void SetProjectIndices(int gt_id, int sln_id, int weights_id, int script_id);
/// , ( )
virtual int StartProjectDeployment(int task_id);
///
//virtual void SetDatabaseAccess(const std::string &db_address, const std::string &db_name, const std::string &db_login, const std::string &db_password);
//virtual void SetProjectIndices(int gt_id, int sln_id, int weights_id, int script_id);
virtual void AConnectToDatabase();
virtual int GetDeploymentState();
virtual int GetStageCap();
virtual int GetStageProgress();
virtual std::string GetLastError();
public: //
QSqlDatabase *GetDatabase() {return db;};
// --------------------------
//
......
This diff is collapsed.
#ifndef UServerTransportTcpQt_H
#define UServerTransportTcpQt_H
#include "../UServerTransportTcp.h"
#include "../UServerControl.h"
#include <QTcpServer>
#include <QTcpSocket>
#include <QTimer>
class UServerSocketQt: public QObject
{
Q_OBJECT
public:
UServerSocketQt();
UServerSocketQt(QTcpSocket* s);
~UServerSocketQt();
void SetSocket(QTcpSocket *s);
QTcpSocket* GetSocket();
//void WriteData(/*???*/);
//void GetIncomingData(const char* data, int& size);
signals:
//void onConnected(std::string bind);
void onDisconnected(std::string bind);
void onReadyRead(std::string bind);
private slots:
virtual void readyRead();
virtual void disconnected();
private:
QTcpSocket *socket;
};
class UServerTransportTcpQt: public QTcpServer, public RDK::UServerTransportTcp
{
Q_OBJECT
public:
UServerTransportTcpQt();
~UServerTransportTcpQt();
/// ,
///
virtual int ReadIncomingBytes(std::string &bind, std::vector<unsigned char> &bytes);
///
virtual void SendResponseBuffer(std::vector<unsigned char> buffer, std::string &responce_addr);
///
virtual void SetServerBinding(std::string &interface_address, int port);
///
virtual std::string GetServerBindingInterfaceAddress(void);
///
int GetServerBindingPort(void) const;
/// ,
virtual void ServerStop();
///
virtual void ServerStart();
//virtual void ConnectClient(std::string &bind);
//virtual void DisconnectClient(std::string &bind);
virtual int GetSocketState(std::string bind);
bool ServerIsActive();
public slots:
void ServerNewConnection();
void SocketReadyRead(std::string bind);
void SocketDisconnected(std::string bind);
void CommandQueueTimerTimeout();
private:
QTcpServer *server;
std::map<std::string, UServerSocketQt*> serverSockets;
std::string server_address;
int server_port;
QTimer *commandQueueTimer;
};
class RDK_LIB_TYPE UServerControlQt: public RDK::UServerControl
{
public:
// --------------------------
//
// --------------------------
///
virtual int RegisterMetadataReceiver(const std::string &address, int port);
///
virtual int UnRegisterMetadataReceiver(const std::string &address, int port);
// --------------------------
private:
// --------------------------
///
///
/// UApplication
// --------------------------
virtual bool ASetNumChannels(int old_num);
virtual bool AInsertChannel(int index);
virtual bool ADeleteChannel(int index);
// --------------------------
public: // TODO:
// --------------------------
//
// --------------------------
// ,
virtual void AfterReset(void);
// ,
virtual void AfterCalculate(void);
// --------------------------
};
class URpcDecoderCommonQt: public RDK::URpcDecoderCommon
{
///
std::string ControlResponseString;
std::vector<RDK::UParamT> binary_data;
public:
// --------------------------
//
// --------------------------
URpcDecoderCommonQt(void);
virtual ~URpcDecoderCommonQt(void);
// --------------------------
// --------------------------
//
// --------------------------
/// ,
/// , false
virtual bool IsCmdSupported(const RDK::UEPtr<RDK::URpcCommand> &command) const;
///
virtual URpcDecoderCommonQt* New(void);
virtual std::string ARemoteCall(const std::string &cmd, RDK::USerStorageXML &xml, const std::string &component_name, int engine_index, int &return_value);
/*
void SetEngine(QMainWindow* e);
QMainWindow* GetEngine();
*/
// --------------------------
//private:
//QMainWindow *engine;
};
/*
namespace Ui {
class UTcpServerControlWidget;
}
class UTcpServerControlWidget : public UVisualControllerWidget
{
Q_OBJECT
public:
explicit UTcpServerControlWidget(QWidget *parent = 0, RDK::UApplication *app = NULL);
~UTcpServerControlWidget();
///
virtual void ASaveParameters();
///
virtual void ALoadParameters();
///
virtual void AUpdateInterface();
private slots:
void PushButtonResetClicked();
void PushButtonApplyClicked();
void PushButtonServerStartClicked();
void PushButtonServerStopClicked();
void TcpCommandTimerTick();
void TcpServerRestartTimerTick();
private:
Ui::UTcpServerControlWidget *ui;
QTimer *tcpCommandTimer;
QTimer *tcpServerRestartTimer;
};
*/
#endif //UServerTransportTcpQt_H
......@@ -5,11 +5,10 @@
#include "../Utilities/UIniFile.h"
#include "../../Deploy/Include/rdk_application.h"
namespace RDK {
///
template<class ApplicationT, class EngineControlT, class ProjectT, class ServerControlT, class TestManagerT, class DispatcherT, class DecoderT, class DecoderCommonT>
template<class ApplicationT, class EngineControlT, class ProjectT, class ServerControlT, class TestManagerT, class DispatcherT, class DecoderT, class DecoderCommonT, class ServerTransportT, class UProjectDeployerT>
class RDK_LIB_TYPE UAppCore
{
public:
......@@ -21,6 +20,10 @@ public:
///
ServerControlT serverControl;
///
ServerTransportT serverTransport;
DecoderCommonT rpcDecoderCommon;
///
......@@ -35,6 +38,9 @@ public:
///
TestManagerT rdkTestManager;