Implemented copy, cut and paste frame
[dashstudio.git] / src / dashd / main.cpp
blobc16778c06ed36e2a8c62a9efc36afda0ed2df899
1 /***************************************************************************
2 * Copyright (C) 2006 by David Cuadrado *
3 * krawek@toonka.com *
4 * *
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. *
9 * *
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. *
14 * *
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>
23 #include <QProcess>
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>
41 #ifdef Q_OS_UNIX
42 #include <unistd.h>
43 #include <signal.h>
44 #include <sys/wait.h>
46 static void cleanup(int);
47 #endif
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");
57 // Add the admin user
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);
65 QString xml;
67 QXmlStreamWriter writer(&xml);
68 user.toXml(&writer);
70 dfDebug << xml;
72 XDBMS::Manager::self()->addObject( "users", &user);
75 #ifdef Q_OS_UNIX
76 signal(SIGINT, cleanup);
77 signal(SIGTERM, cleanup);
78 signal( SIGSEGV, cleanup);
79 #endif
81 QString host;
82 qint16 port;
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();
88 config->endGroup();
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());
99 int ret = app.exec();
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());
107 config->endGroup();
110 return ret;
113 #ifdef Q_OS_UNIX
114 void cleanup(int s)
116 dDebug() << "Finishing with signal: " << s;
118 static bool finishing = false;
120 if( finishing )
122 if( s == 11 )
124 qWarning("Crashed! Exiting!...");
125 exit(-256);
127 return;
130 finishing = true;
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());
138 else
139 if( s == 11 )
141 exit(-256);
144 qApp->exit(s);
146 #endif