From 45bd454039d9ac54f492d9c336f333aaddf446d5 Mon Sep 17 00:00:00 2001 From: goldenhawking Date: Wed, 20 Aug 2014 15:41:32 +0800 Subject: [PATCH] Add a auto-join cluster method, as soon as the server node be started, a join-cluster approach will be taken. --- ZoomPipeline_FuncSvr/main.cpp | 22 ++++++-------- ZoomPipeline_FuncSvr/zpmainframe.cpp | 45 +++++++++++++++++++--------- ZoomPipeline_FuncSvr/zpmainframe.h | 2 +- 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/ZoomPipeline_FuncSvr/main.cpp b/ZoomPipeline_FuncSvr/main.cpp index 8c5d458..869f4be 100644 --- a/ZoomPipeline_FuncSvr/main.cpp +++ b/ZoomPipeline_FuncSvr/main.cpp @@ -21,37 +21,33 @@ int main(int argc, char *argv[]) ZPMainFrame w; + w.show(); + //!the main program arg formats: - /*! ZoomPipeline_FuncSvr [[options] [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; } diff --git a/ZoomPipeline_FuncSvr/zpmainframe.cpp b/ZoomPipeline_FuncSvr/zpmainframe.cpp index 850ea43..5c62b72 100644 --- a/ZoomPipeline_FuncSvr/zpmainframe.cpp +++ b/ZoomPipeline_FuncSvr/zpmainframe.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #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); + } + + } } diff --git a/ZoomPipeline_FuncSvr/zpmainframe.h b/ZoomPipeline_FuncSvr/zpmainframe.h index bdb71a5..1066d84 100644 --- a/ZoomPipeline_FuncSvr/zpmainframe.h +++ b/ZoomPipeline_FuncSvr/zpmainframe.h @@ -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 m_set_listenerNames; -- GitLab