Read about our upcoming Code of Conduct on this issue

This instance was upgraded to Heptapod 0.28.1 today

Commit 0e9f3bbb authored by aivan_2008's avatar aivan_2008
Browse files

Added Qt transport files and Curl test Ftp widget

--HG--
branch : DeploymentQt
parent 8b073262176f
......@@ -501,23 +501,40 @@ int Rpc_GetChannelName(int server_index, int channel_index, const char* &result,
return 0;
}
int Rpc_GetDeploymentState(int server_index, const char* &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, int timeout)
{
RDK::USerStorageXML request,response;
int res=ProcessSimpleCommand("GetChannelName", server_index, -1, timeout, 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();
std::string s;
std::stringstream ss;
ss<<res_string.c_str();
ss>>dp_cap>>dp_progress>>s;
//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();
dp_state=s.c_str();
return 0;
return res;
}
int Rpc_SetChannelName(int server_index, int channel_index, const char* channel_name, int timeout)
......
......@@ -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, const char* &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, int timeout);
int Rpc_SetChannelName(int server_index, int channel_index, const char* channel_name, int timeout);
......
......@@ -134,6 +134,7 @@ DeploymentState UProjectDeployProcessingThread::GetDeploymentState()
return deploymentState;
}
/*
std::string UProjectDeployProcessingThread::GetDeploymentStateString()
{
std::string result;
......@@ -168,6 +169,7 @@ std::string UProjectDeployProcessingThread::GetDeploymentStateString()
}
return result;
}
*/
int UProjectDeployProcessingThread::GetDeploymentProgress()
{
......@@ -181,6 +183,8 @@ int UProjectDeployProcessingThread::GetDeploymentProgressCap()
return deploymentProgressCap;
}
void UProjectDeployProcessingThread::run()
{
DeployTemplate();
......@@ -216,6 +220,14 @@ void UProjectDeployProcessingThread::run()
// -
// ,
}
deploymentState = DS_Finished;
}
std::string UProjectDeployProcessingThread::GetLastError()
{
}
bool UProjectDeployProcessingThread::DownloadZip(const QString &remote_url, const QString& dst_zip_file)
......@@ -792,8 +804,8 @@ bool UProjectDeployerQt::DestroyProcessingThread()
int UProjectDeployerQt::StartProjectDeployment(int task_id)
{
std::string s = GetDeploymentState();
if(s!="DS_NULL")
int ds = GetDeploymentState();
if(ds!=DeploymentState::DS_NULL)
{
return 20;
}
......@@ -1067,28 +1079,42 @@ void UProjectDeployerQt::AConnectToDatabase()
/*
enum DeploymentState
{
DS_DownloadProject,
DS_UnpackProject,
DS_NULL,
DS_Unknown,
DS_DownloadTemplate,
DS_UnpackTemplate,
DS_DownloadWeights,
DS_UnpackWeights,
DS_DownloadScripts,
DS_UnpackScripts,
DS_DownloadData,
DS_UnpackData
DS_UnpackData,
DS_Error
};
*/
std::string UProjectDeployerQt::GetLastError()
{
if(deployProcessingThread==NULL)
{
return "NULL";
}
else
{
return deployProcessingThread->GetLastError();
}
}
std::string UProjectDeployerQt::GetDeploymentState()
int UProjectDeployerQt::GetDeploymentState()
{
if(deployProcessingThread==NULL)
{
return "DS_NULL";
return DeploymentState::DS_NULL;
}
else
{
bool t = deployProcessingThread->isRunning();
return deployProcessingThread->GetDeploymentStateString();
return deployProcessingThread->GetDeploymentState();
}
}
......
......@@ -40,17 +40,18 @@ class UApplication;
enum DeploymentState
{
DS_NULL,
DS_Unknown,
DS_DownloadTemplate,
DS_UnpackTemplate,
DS_DownloadWeights,
DS_UnpackWeights,
DS_DownloadScripts,
DS_UnpackScripts,
DS_DownloadData,
DS_UnpackData,
DS_Error
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
......@@ -85,9 +86,9 @@ public:
QString GetDownloadTempPath(); //
DeploymentState GetDeploymentState();
std::string GetDeploymentStateString();
int GetDeploymentProgress();
int GetDeploymentProgressCap();
std::string GetLastError();
private slots:
void processReadyReadStandardError();
......@@ -107,6 +108,12 @@ private:
void DeployData();
bool VerifyData();
// , , ?
//bool ErrorOccured();
// , ,
//std::string GetLastError();
private:
QMutex deploymentStateMutex;
QMutex deploymentProgressMutex;
......@@ -127,6 +134,8 @@ private:
QProcess zip_process;
std::string lastError;
CURL *curl;
CURLcode res;
};
......@@ -227,9 +236,10 @@ virtual int StartProjectDeployment(int task_id);
virtual void AConnectToDatabase();
virtual std::string GetDeploymentState();
virtual int GetDeploymentState();
virtual int GetStageCap();
virtual int GetStageProgress();
virtual std::string GetLastError();
public: //
......
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
......@@ -49,7 +49,7 @@ void UProjectDeployer::SetDatabaseAccess(const std::string &db_address,
AConnectToDatabase();
}
std::string UProjectDeployer::GetDeploymentState()
int UProjectDeployer::GetDeploymentState()
{
}
......@@ -74,6 +74,11 @@ void UProjectDeployer::SetFtpRemotePath(const std::string &path)
ftp_remote_path = path;
}
std::string UProjectDeployer::GetLastError()
{
return std::string();
}
/*
void UProjectDeployer::SetProjectIndices(int gt_id, int sln_id, int weights_id, int script_id)
{
......
......@@ -60,10 +60,12 @@ virtual void AConnectToDatabase();
///
//virtual void SetProjectIndices(int gt_id, int sln_id, int weights_id, int script_id);
virtual std::string GetDeploymentState();
virtual int GetDeploymentState();
virtual int GetStageCap();
virtual int GetStageProgress();
virtual std::string GetLastError();
virtual void SetFtpRemotePath(const std::string &path);
// --------------------------
......
......@@ -155,6 +155,11 @@ bool URpcDecoderCommon::IsCmdSupported(const UEPtr<URpcCommand> &command) const
{
return true;
}
else
if(cmd == "GetLastError")
{
return true;
}
/*else
if(cmd == "GetDeploymentStageMax")
{
......@@ -369,16 +374,29 @@ const char* URpcDecoderCommon::RemoteCall(const char *request, int &return_value
if(cmd == "GetDeploymentState")
{
//GetApplication()->SaveProject();
std::string stage = GetApplication()->GetProjectDeployer()->GetDeploymentState();
int d_state = GetApplication()->GetProjectDeployer()->GetDeploymentState();
int stage_max = GetApplication()->GetProjectDeployer()->GetStageCap();
int stage_pos = GetApplication()->GetProjectDeployer()->GetStageProgress();
std::stringstream ss;
ss<<stage.c_str()<<" "<<stage_pos<<" "<<stage_max;
\
ss<<d_state<<" "<<stage_pos<<" "<<stage_max;
response=ss.str();
return_value=0;//UServerControlForm->SaveProject();
}
else
if(cmd == "GetLastError")
{
std::string last_error=GetApplication()->GetProjectDeployer()->GetLastError();
//GetApplication()->SaveProject();
int d_state = GetApplication()->GetProjectDeployer()->GetDeploymentState();
int stage_max = GetApplication()->GetProjectDeployer()->GetStageCap();
int stage_pos = GetApplication()->GetProjectDeployer()->GetStageProgress();
std::stringstream ss;
ss<<d_state<<" "<<stage_pos<<" "<<stage_max;
response=ss.str();
return_value=0;
}
/*
else
if(cmd == "GetDeploymentStageMax")
......
#ifndef UCurlFtpClientTestWidget_CPP
#define UCurlFtpClientTestWidget_CPP
#include "UCurlFtpClientTestWidget.h"
#include "ui_UCurlFtpClientTestWidget.h"
#include <QFileDialog>
#include <QDir>
#include <QMessageBox>
#include <sys/types.h>
#include <sys/stat.h>
static
size_t write_response(void *ptr, size_t size, size_t nmemb, void *data)
{
FILE *writehere = (FILE *)data;
char* str = static_cast<char*>(ptr);
//std::string s(str);
qDebug()<<str;
return nmemb;
}
UCurlFtpClientTestWidget::UCurlFtpClientTestWidget(QWidget *parent, RDK::UApplication *app) :
UVisualControllerWidget(parent, app),
ui(new Ui::UCurlFtpClientTestWidget)
{
ui->setupUi(this);
UpdateInterval = 0;
setAccessibleName("UCurlFtpClientTestWidget");
// curl,
curl_global_init(CURL_GLOBAL_DEFAULT);
connect(ui->pushButtonBrowse, SIGNAL(clicked()), this, SLOT(onPushButtonBrowseClick()));
connect(ui->pushButtonSendFile, SIGNAL(clicked()), this, SLOT(onPushButtonSendFileClick()));
connect(ui->pushButtonReceiveFile, SIGNAL(clicked()), this, SLOT(onPushButtonReceiveFileClick()));
connect(ui->pushButtonBrowseReceivePath, SIGNAL(clicked()), this, SLOT(onPushButtonBrowseReceiveFilePathClick()));
connect(ui->pushButtonModelExample, SIGNAL(clicked()), this, SLOT(pushButtonModelExampleClicked()));
}
UCurlFtpClientTestWidget::~UCurlFtpClientTestWidget()
{
curl_global_cleanup();
delete ui;
}
void UCurlFtpClientTestWidget::onPushButtonBrowseClick()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Choose file to upload"), QDir::currentPath());
ui->lineEditSendFilePath->setText(fileName);
}
void UCurlFtpClientTestWidget::onPushButtonBrowseReceiveFilePathClick()
{
QString res_path=QFileDialog::getExistingDirectory(this, tr("Choose directory to download"), QDir::currentPath(), QFileDialog::ShowDirsOnly);
ui->lineEditReceiveFilePath->setText(res_path+"/");
}
void UCurlFtpClientTestWidget::onPushButtonSendFileClick()
{
if(ui->lineEditSendFilePath->text()=="")
{
QMessageBox::information(this, "error", "Send file path is empty");
return;
}
QFileInfo fi(ui->lineEditSendFilePath->text());
if(!fi.exists())
{
QMessageBox::information(this, "error", "Send file not exists, check path and click again");
return;
}
if(ui->lineEditRemotePath->text()=="")
{
QMessageBox::information(this, "error", "Remote file path is empty");
return;
}
FILE *hd_src;
struct stat file_info;
struct curl_slist *headerlist = NULL;
// - .
//static const char* upload_as = ("RNFR "+ui->lineEditRemotePath->text()).toUtf8().constData();
//static const char* rename_to = ("RNTO "+ui->lineEditRemotePath->text()).toUtf8().constData();
curl_off_t fsize;
fsize = fi.size();
/* get a FILE * of the same file */
hd_src = fopen(ui->lineEditSendFilePath->text().toUtf8().constData(), "rb");
curl = curl_easy_init();
if(curl) {
/* build a list of commands to pass to libcurl */
//headerlist = curl_slist_append(headerlist, upload_as);
//headerlist = curl_slist_append(headerlist, rename_to);