1 /***************************************************************************
2 * Copyright (C) 2006 by David Cuadrado *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include <QApplication>
22 #include <QAbstractEventDispatcher>
24 #include <QXmlStreamWriter>
26 #include <dgui/application.h>
27 #include <dcore/debug.h>
28 #include "dashserver/server.h"
30 #include <dcore/applicationproperties.h>
31 #include <dcore/config.h>
33 #include "dashserver/logger.h"
34 #include "dashserver/users/user.h"
36 #include <dashserver/registers/regmanager.h>
37 #include <dashserver/com/commanager.h>
38 #include <dashserver/xdbms/manager.h>
46 static void cleanup(int);
49 int main(int argc
, char **argv
)
51 DCore::Debug::setForceDisableGUI();
53 DGui::Application
app(argc
, argv
, false); // Text Item requires X11
54 app
.setApplicationName("dashd");
56 XDBMS::Manager::self()->initialize("database");
59 DashServer::Users::User user
;
60 user
.setLogin( "admin" );
61 user
.setPassword("admin");
62 user
.addPermission(DashServer::Module::Admin
, DashServer::Users::Permission::Read
|DashServer::Users::Permission::Write
);
63 user
.addPermission(DashServer::Module::Users
, DashServer::Users::Permission::Read
|DashServer::Users::Permission::Write
);
67 QXmlStreamWriter
writer(&xml
);
72 XDBMS::Manager::self()->addObject( "users", &user
);
76 signal(SIGINT
, cleanup
);
77 signal(SIGTERM
, cleanup
);
78 signal( SIGSEGV
, cleanup
);
84 DCore::Config
*config
= DCore::Config::self();
85 config
->beginGroup("Connection");
86 host
= config
->value("host", "localhost").toString();
87 port
= config
->value("port", 5123).toInt();
91 DashServer::TcpServer server
;
92 server
.addObserver(new DashServer::Com::Manager
);
93 server
.addObserver(new DashServer::Registers::Manager
);
95 server
.openConnection( host
, port
);
97 dDebug() << QObject::tr("Running server on %1:%2!").arg(server
.serverAddress().toString()).arg(server
.serverPort());
101 if( ret
== 0 || ret
== 2)
103 DCore::Config
*config
= DCore::Config::self();
104 config
->beginGroup("Connection");
105 config
->setValue("host", server
.serverAddress().toString());
106 config
->setValue("port", server
.serverPort());
116 dDebug() << "Finishing with signal: " << s
;
118 static bool finishing
= false;
124 qWarning("Crashed! Exiting!...");
132 DashServer::Logger::self()->info(QObject::tr("Finishing with signal: ")+QString::number(s
));
134 if( s
== 15 ) // Restart to reload the configuration
136 QProcess::startDetached(qApp
->arguments().first());