提交 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[])
ZPMainFrame w;
w.show();
//!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.
* If the commandline args has been specified, this server will enter an aut-config and start model.
* Cmdline formats:
* --ui (default) the program will start with an UI
* --noui the program will start without an UI
* --autostart specify the cluster address to join.
* config file has a same format with UI-Saved ini file. this file name should be surrounded with ""
* if there are spaces in filename.
*/
//Command Line Args, support batch auto-config and auto start.
if (argc>1)
{
bool bHasUI = false;
QString configfile;
for (int i=1;i < argc;++i)
{
QString strArg = argv[i];
if (-1!=strArg.indexOf("--ui"))
bHasUI = true;
else if (-1!=strArg.indexOf("--noui"))
;
else
if (-1!=strArg.indexOf("--autostart"))
{
configfile = strArg;
if (++i < argc)
configfile = argv[i];
w.LoadSettingsAndForkServer(configfile);
break;
}
}
w.LoadSettingsAndForkServer(configfile);
}
w.show();
int pp = app.exec();
return pp;
}
......@@ -8,6 +8,7 @@
#include <QSqlDatabase>
#include <QMap>
#include <QTcpSocket>
#include <QThread>
#include <QSslSocket>
#include "smartlink/st_clientnode_basetrans.h"
#include "dialogaddressinput.h"
......@@ -25,7 +26,7 @@ ZPMainFrame::ZPMainFrame(QWidget *parent)
:QMainWindow(parent)
,ui(new Ui::ZPMainFrame)
{
m_currentConffile = QCoreApplication::applicationFilePath()+".ini";
m_currentConfigFile = QCoreApplication::applicationFilePath()+".ini";
ui->setupUi(this);
//Create net engine
m_netEngine = new zp_net_Engine (8192);
......@@ -56,7 +57,7 @@ ZPMainFrame::ZPMainFrame(QWidget *parent)
m_nTimerId = startTimer(2000);
m_nTimerCheck = startTimer(10000);
initUI();
LoadSettings(m_currentConffile);
LoadSettings(m_currentConfigFile);
}
ZPMainFrame::~ZPMainFrame()
......@@ -366,7 +367,7 @@ void ZPMainFrame::on_action_Start_Stop_triggered(bool setordel)
{
if (setordel==true)
{
forkServer(m_currentConffile);
forkServer(m_currentConfigFile);
}
else
{
......@@ -773,20 +774,20 @@ void ZPMainFrame::on_pushButton_delListener_clicked()
}
void ZPMainFrame::on_pushButton_listerner_apply_clicked()
{
SaveSettings(m_currentConffile);
SaveSettings(m_currentConfigFile);
}
void ZPMainFrame::on_pushButton_threadsApply_clicked()
{
SaveSettings(m_currentConffile);
SaveSettings(m_currentConfigFile);
}
void ZPMainFrame::on_pushButton_cluster_apply_clicked()
{
SaveSettings(m_currentConffile);
SaveSettings(m_currentConfigFile);
}
void ZPMainFrame::on_pushButton_smartlink_save_clicked()
{
SaveSettings(m_currentConffile);
SaveSettings(m_currentConfigFile);
}
void ZPMainFrame::on_actionReload_config_file_triggered()
......@@ -796,9 +797,9 @@ void ZPMainFrame::on_actionReload_config_file_triggered()
if (filename.length()>0)
{
//SaveSettings(m_currentConffile);
m_currentConffile = filename;
LoadSettings(m_currentConffile);
forkServer(m_currentConffile);
m_currentConfigFile = filename;
LoadSettings(m_currentConfigFile);
forkServer(m_currentConfigFile);
}
}
void ZPMainFrame::on_pushButton_db_add_clicked()
......@@ -847,12 +848,12 @@ void ZPMainFrame::on_pushButton_db_del_clicked()
void ZPMainFrame::on_pushButton_db_apply_clicked()
{
SaveSettings(m_currentConffile);
SaveSettings(m_currentConfigFile);
}
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 strPort = settings.value("history/clusterPort","25600").toString();
DialogAddressInput inputdlg(this);
......@@ -868,10 +869,26 @@ void ZPMainFrame::on_pushButton_join_clicked()
void ZPMainFrame::LoadSettingsAndForkServer(const QString & configfile)
{
if (configfile.length()>2)
this->m_currentConffile = configfile;
LoadSettings(m_currentConffile);
this->m_currentConfigFile = configfile;
LoadSettings(m_currentConfigFile);
if (ui->action_Start_Stop->isChecked()==true)
on_action_Start_Stop_triggered(false);
on_action_Start_Stop_triggered(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:
QStandardItemModel * m_pMsgModelDatabase;
QStandardItemModel * m_pMsgModelSmartlink;
//Config File Name
QString m_currentConffile;
QString m_currentConfigFile;
//Listeners settings
QStandardItemModel * m_pListenerModel;
QSet<QString> m_set_listenerNames;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册