|
@@ -10,16 +10,30 @@
|
|
#include <QtSql/QSqlQuery>
|
|
#include <QtSql/QSqlQuery>
|
|
#include <QCryptographicHash>
|
|
#include <QCryptographicHash>
|
|
#include <QHostAddress>
|
|
#include <QHostAddress>
|
|
|
|
+#include <QThread>
|
|
|
|
+#include <QTimer>
|
|
#include "SshClient.h"
|
|
#include "SshClient.h"
|
|
#include "ActiveClient.h"
|
|
#include "ActiveClient.h"
|
|
#include "Settings.h"
|
|
#include "Settings.h"
|
|
|
|
|
|
|
|
+class Sleeper: public QThread
|
|
|
|
+{
|
|
|
|
+public:
|
|
|
|
+ static void msleep(unsigned long msecs)
|
|
|
|
+ {
|
|
|
|
+ QThread::msleep(msecs);
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+
|
|
App::App(int &argc, char **argv) :
|
|
App::App(int &argc, char **argv) :
|
|
QCoreApplication(argc, argv),
|
|
QCoreApplication(argc, argv),
|
|
myServer(new QTcpServer()),
|
|
myServer(new QTcpServer()),
|
|
mySocketConnectedFlag(false),
|
|
mySocketConnectedFlag(false),
|
|
myQWNETSshClient(new SshClient(this))
|
|
myQWNETSshClient(new SshClient(this))
|
|
{
|
|
{
|
|
|
|
+ if(!parseCommandLine())
|
|
|
|
+ return;
|
|
|
|
+
|
|
print("CIMS Bot Service v0.101\n========================================================\n");
|
|
print("CIMS Bot Service v0.101\n========================================================\n");
|
|
|
|
|
|
setApplicationName("CIMSBOT");
|
|
setApplicationName("CIMSBOT");
|
|
@@ -27,10 +41,7 @@ App::App(int &argc, char **argv) :
|
|
setOrganizationName("CIMS");
|
|
setOrganizationName("CIMS");
|
|
setApplicationVersion("0.101");
|
|
setApplicationVersion("0.101");
|
|
|
|
|
|
- // myServer->listen(QHostAddress::Any, 45000);
|
|
|
|
- // connect(myServer, SIGNAL(newConnection()), SLOT(onNewConnection()));
|
|
|
|
-
|
|
|
|
- myClientsFrameTimerID = startTimer(0);
|
|
|
|
|
|
+ myClientsFrameTimerID = startTimer(0);
|
|
|
|
|
|
myQWNETSshClient->connectToHost("stomp", "b4r.org");
|
|
myQWNETSshClient->connectToHost("stomp", "b4r.org");
|
|
|
|
|
|
@@ -46,6 +57,41 @@ App::~App()
|
|
delete myServer;
|
|
delete myServer;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+bool App::parseCommandLine()
|
|
|
|
+{
|
|
|
|
+ if(argc() < 2)
|
|
|
|
+ return true;
|
|
|
|
+
|
|
|
|
+ QStringList args = App::arguments();
|
|
|
|
+ QString arg;
|
|
|
|
+ QStringList::const_iterator itr;
|
|
|
|
+ for(itr = args.constBegin()+1; itr != args.constEnd(); ++itr)
|
|
|
|
+ {
|
|
|
|
+ arg = *itr;
|
|
|
|
+ if(arg == "--help" || arg == "-h")
|
|
|
|
+ {
|
|
|
|
+ printf("Usage: %s [--config/-c config_file] [-h]\n", args.at(0).section("/", -1).toAscii().data());
|
|
|
|
+ QTimer::singleShot(0, this, SLOT(quit()));
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ else if(arg == "--config" || arg == "-c")
|
|
|
|
+ {
|
|
|
|
+ itr++;
|
|
|
|
+ if(itr == args.constEnd())
|
|
|
|
+ {
|
|
|
|
+ printf("--config: Expected config file path.\n");
|
|
|
|
+ QTimer::singleShot(0, this, SLOT(quit()));
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ arg = *itr;
|
|
|
|
+ printf("Using config file [%s]...\n", arg.toAscii().data());
|
|
|
|
+ Settings::globalInstance()->changeConfigFile(*itr);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+}
|
|
|
|
+
|
|
void App::onNewConnection()
|
|
void App::onNewConnection()
|
|
{
|
|
{
|
|
if(mySocketConnectedFlag)
|
|
if(mySocketConnectedFlag)
|
|
@@ -416,8 +462,8 @@ void App::timerEvent(QTimerEvent *e)
|
|
{
|
|
{
|
|
ac->run();
|
|
ac->run();
|
|
}
|
|
}
|
|
- return;
|
|
|
|
}
|
|
}
|
|
|
|
+ Sleeper::msleep(1);
|
|
}
|
|
}
|
|
|
|
|
|
void App::requestBroadcast(const QString &type, const QString &user, const QString &server, const QString &message)
|
|
void App::requestBroadcast(const QString &type, const QString &user, const QString &server, const QString &message)
|