提交 45bd4540 编写于 作者: 丁劲犇's avatar 丁劲犇 😸

Add a auto-join cluster method, as soon as the server node be started, a...

Add a auto-join cluster method, as soon as the server node be started, a join-cluster approach will be taken.
上级 5f07525d
...@@ -21,37 +21,33 @@ int main(int argc, char *argv[]) ...@@ -21,37 +21,33 @@ int main(int argc, char *argv[])
ZPMainFrame w; ZPMainFrame w;
w.show();
//!the main program arg formats: //!the main program arg formats:
/*! ZoomPipeline_FuncSvr [[options] <config file name> [options]] /*! ZoomPipeline_FuncSvr [<--autostart> [config file name] ]
* When start with no commandline arguments, the server will enter a dialog-controlled UI model. * When start with no commandline arguments, the server will enter a dialog-controlled UI model.
* If the commandline args has been specified, this server will enter an aut-config and start model. * If the commandline args has been specified, this server will enter an aut-config and start model.
* Cmdline formats: * Cmdline formats:
* --ui (default) the program will start with an UI * --autostart specify the cluster address to join.
* --noui the program will start without an UI
* config file has a same format with UI-Saved ini file. this file name should be surrounded with "" * config file has a same format with UI-Saved ini file. this file name should be surrounded with ""
* if there are spaces in filename. * if there are spaces in filename.
*/ */
//Command Line Args, support batch auto-config and auto start. //Command Line Args, support batch auto-config and auto start.
if (argc>1) if (argc>1)
{ {
bool bHasUI = false;
QString configfile; QString configfile;
for (int i=1;i < argc;++i) for (int i=1;i < argc;++i)
{ {
QString strArg = argv[i]; QString strArg = argv[i];
if (-1!=strArg.indexOf("--ui")) if (-1!=strArg.indexOf("--autostart"))
bHasUI = true;
else if (-1!=strArg.indexOf("--noui"))
;
else
{ {
configfile = strArg; if (++i < argc)
configfile = argv[i];
w.LoadSettingsAndForkServer(configfile);
break;
} }
} }
w.LoadSettingsAndForkServer(configfile);
} }
w.show();
int pp = app.exec(); int pp = app.exec();
return pp; return pp;
} }
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <QSqlDatabase> #include <QSqlDatabase>
#include <QMap> #include <QMap>
#include <QTcpSocket> #include <QTcpSocket>
#include <QThread>
#include <QSslSocket> #include <QSslSocket>
#include "smartlink/st_clientnode_basetrans.h" #include "smartlink/st_clientnode_basetrans.h"
#include "dialogaddressinput.h" #include "dialogaddressinput.h"
...@@ -25,7 +26,7 @@ ZPMainFrame::ZPMainFrame(QWidget *parent) ...@@ -25,7 +26,7 @@ ZPMainFrame::ZPMainFrame(QWidget *parent)
:QMainWindow(parent) :QMainWindow(parent)
,ui(new Ui::ZPMainFrame) ,ui(new Ui::ZPMainFrame)
{ {
m_currentConffile = QCoreApplication::applicationFilePath()+".ini"; m_currentConfigFile = QCoreApplication::applicationFilePath()+".ini";
ui->setupUi(this); ui->setupUi(this);
//Create net engine //Create net engine
m_netEngine = new zp_net_Engine (8192); m_netEngine = new zp_net_Engine (8192);
...@@ -56,7 +57,7 @@ ZPMainFrame::ZPMainFrame(QWidget *parent) ...@@ -56,7 +57,7 @@ ZPMainFrame::ZPMainFrame(QWidget *parent)
m_nTimerId = startTimer(2000); m_nTimerId = startTimer(2000);
m_nTimerCheck = startTimer(10000); m_nTimerCheck = startTimer(10000);
initUI(); initUI();
LoadSettings(m_currentConffile); LoadSettings(m_currentConfigFile);
} }
ZPMainFrame::~ZPMainFrame() ZPMainFrame::~ZPMainFrame()
...@@ -366,7 +367,7 @@ void ZPMainFrame::on_action_Start_Stop_triggered(bool setordel) ...@@ -366,7 +367,7 @@ void ZPMainFrame::on_action_Start_Stop_triggered(bool setordel)
{ {
if (setordel==true) if (setordel==true)
{ {
forkServer(m_currentConffile); forkServer(m_currentConfigFile);
} }
else else
{ {
...@@ -773,20 +774,20 @@ void ZPMainFrame::on_pushButton_delListener_clicked() ...@@ -773,20 +774,20 @@ void ZPMainFrame::on_pushButton_delListener_clicked()
} }
void ZPMainFrame::on_pushButton_listerner_apply_clicked() void ZPMainFrame::on_pushButton_listerner_apply_clicked()
{ {
SaveSettings(m_currentConffile); SaveSettings(m_currentConfigFile);
} }
void ZPMainFrame::on_pushButton_threadsApply_clicked() void ZPMainFrame::on_pushButton_threadsApply_clicked()
{ {
SaveSettings(m_currentConffile); SaveSettings(m_currentConfigFile);
} }
void ZPMainFrame::on_pushButton_cluster_apply_clicked() void ZPMainFrame::on_pushButton_cluster_apply_clicked()
{ {
SaveSettings(m_currentConffile); SaveSettings(m_currentConfigFile);
} }
void ZPMainFrame::on_pushButton_smartlink_save_clicked() void ZPMainFrame::on_pushButton_smartlink_save_clicked()
{ {
SaveSettings(m_currentConffile); SaveSettings(m_currentConfigFile);
} }
void ZPMainFrame::on_actionReload_config_file_triggered() void ZPMainFrame::on_actionReload_config_file_triggered()
...@@ -796,9 +797,9 @@ void ZPMainFrame::on_actionReload_config_file_triggered() ...@@ -796,9 +797,9 @@ void ZPMainFrame::on_actionReload_config_file_triggered()
if (filename.length()>0) if (filename.length()>0)
{ {
//SaveSettings(m_currentConffile); //SaveSettings(m_currentConffile);
m_currentConffile = filename; m_currentConfigFile = filename;
LoadSettings(m_currentConffile); LoadSettings(m_currentConfigFile);
forkServer(m_currentConffile); forkServer(m_currentConfigFile);
} }
} }
void ZPMainFrame::on_pushButton_db_add_clicked() void ZPMainFrame::on_pushButton_db_add_clicked()
...@@ -847,12 +848,12 @@ void ZPMainFrame::on_pushButton_db_del_clicked() ...@@ -847,12 +848,12 @@ void ZPMainFrame::on_pushButton_db_del_clicked()
void ZPMainFrame::on_pushButton_db_apply_clicked() void ZPMainFrame::on_pushButton_db_apply_clicked()
{ {
SaveSettings(m_currentConffile); SaveSettings(m_currentConfigFile);
} }
void ZPMainFrame::on_pushButton_join_clicked() void ZPMainFrame::on_pushButton_join_clicked()
{ {
QSettings settings(this->m_currentConffile,QSettings::IniFormat); QSettings settings(this->m_currentConfigFile,QSettings::IniFormat);
QString strAddr = settings.value("history/clusterAddr","192.168.1.118").toString(); QString strAddr = settings.value("history/clusterAddr","192.168.1.118").toString();
QString strPort = settings.value("history/clusterPort","25600").toString(); QString strPort = settings.value("history/clusterPort","25600").toString();
DialogAddressInput inputdlg(this); DialogAddressInput inputdlg(this);
...@@ -868,10 +869,26 @@ void ZPMainFrame::on_pushButton_join_clicked() ...@@ -868,10 +869,26 @@ void ZPMainFrame::on_pushButton_join_clicked()
void ZPMainFrame::LoadSettingsAndForkServer(const QString & configfile) void ZPMainFrame::LoadSettingsAndForkServer(const QString & configfile)
{ {
if (configfile.length()>2) if (configfile.length()>2)
this->m_currentConffile = configfile; this->m_currentConfigFile = configfile;
LoadSettings(m_currentConffile); LoadSettings(m_currentConfigFile);
if (ui->action_Start_Stop->isChecked()==true) if (ui->action_Start_Stop->isChecked()==true)
on_action_Start_Stop_triggered(false); on_action_Start_Stop_triggered(false);
on_action_Start_Stop_triggered(true); on_action_Start_Stop_triggered(true);
ui->action_Start_Stop->setChecked(true); ui->action_Start_Stop->setChecked(true);
//Join the cluster immediatly,
//trying for 5 times, 2 seconds each.
QSettings settings(this->m_currentConfigFile,QSettings::IniFormat);
QString strAddr = settings.value("history/clusterAddr","192.168.1.118").toString();
QString strPort = settings.value("history/clusterPort","25600").toString();
for (int i=0;i<5;++i)
{
m_pClusterTerm->JoinCluster(QHostAddress(strAddr),strPort.toInt());
for (int j=0;j<10;++j)
{
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
QThread::currentThread()->msleep(200);
}
}
} }
...@@ -32,7 +32,7 @@ protected: ...@@ -32,7 +32,7 @@ protected:
QStandardItemModel * m_pMsgModelDatabase; QStandardItemModel * m_pMsgModelDatabase;
QStandardItemModel * m_pMsgModelSmartlink; QStandardItemModel * m_pMsgModelSmartlink;
//Config File Name //Config File Name
QString m_currentConffile; QString m_currentConfigFile;
//Listeners settings //Listeners settings
QStandardItemModel * m_pListenerModel; QStandardItemModel * m_pListenerModel;
QSet<QString> m_set_listenerNames; QSet<QString> m_set_listenerNames;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册