Fix for publish/subscribe error
[vicar] / src / vicar-telepathy / src / main.cpp
1 /*
2 @version: 0.5
3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
5
6 Based on Telepathy-SNOM with copyright notice below.
7 */
8
9 /*
10  * Telepathy SNOM VoIP phone connection manager
11  * Copyright (C) 2006 by basyskom GmbH
12  *  @author Tobias Hunger <info@basyskom.de>
13  *
14  * This library is free software; you can redisQObject::tribute it and/or
15  * modify it under the terms of the GNU Lesser General Public
16  * License version 2.1 as published by the Free Software Foundation.
17  *
18  * This library is disQObject::tributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License along with this library; if not, write to the
25  * Free Software Foundation, Inc.,
26  * 51 Franklin SQObject::treet, Fifth Floor, Boston, MA  02110-1301  USA
27  */
28
29 #include <iostream>
30 #include <fstream>
31
32 #include <QtCore/QCoreApplication>
33 #include <QtCore/QDebug>
34
35 #include <QtDBus/QDBusConnection>
36 #include <QtDBus/QDBusMetaType>
37 #include <QtDBus/QDBusInterface>
38 #include <QDateTime>
39
40 #include "names.h"
41 #include "connectionmanager.h"
42 #include "basetypes.h"
43 #include "connectionmanagertypes.h"
44 #include "connectiontypes.h"
45 #include "connectioninterfacerequeststypes.h"
46 #include "connectioninterfacecapabilitiestypes.h"
47
48
49 using namespace std;
50
51 ofstream logfile;
52
53 void MyOutputHandler(QtMsgType type, const char *msg) {
54     switch (type) {
55         case QtDebugMsg:
56             logfile << QTime::currentTime().toString().toAscii().data() << " Debug: " << msg << "\n";
57             break;
58         case QtCriticalMsg:
59             logfile << QTime::currentTime().toString().toAscii().data() << " Critical: " << msg << "\n";
60             break;
61         case QtWarningMsg:
62             logfile << QTime::currentTime().toString().toAscii().data() << " Warning: " << msg << "\n";
63             break;
64         case QtFatalMsg:
65             logfile << QTime::currentTime().toString().toAscii().data() <<  " Fatal: " << msg << "\n";
66             abort();
67     }
68 }
69
70 int main(int argc, char ** argv)
71 {
72
73 //    logfile.open("/var/log/logfile.txt", ios::app);
74 //    #ifndef QT_NO_DEBUG_OUTPUT
75 //    qInstallMsgHandler(MyOutputHandler);
76 //    #endif
77
78
79     QCoreApplication app(argc, argv);
80
81     // register types:
82     qDBusRegisterMetaType<org::freedesktop::Telepathy::ParameterDefinition>();
83     qDBusRegisterMetaType<org::freedesktop::Telepathy::ParameterDefinitionList>();
84     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelInfo>();
85     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelInfoList>();
86     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelDetails>();
87     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelDetailsList>();
88     qDBusRegisterMetaType<org::freedesktop::Telepathy::ContactCapabilities>();
89     qDBusRegisterMetaType<org::freedesktop::Telepathy::ContactCapabilitiesList>();
90     qDBusRegisterMetaType<org::freedesktop::Telepathy::CapabilityPair>();
91     qDBusRegisterMetaType<org::freedesktop::Telepathy::CapabilityPairList>();
92     qDBusRegisterMetaType<org::freedesktop::Telepathy::CapabilityChange>();
93     qDBusRegisterMetaType<org::freedesktop::Telepathy::CapabilityChangeList>();    
94     qDBusRegisterMetaType<org::freedesktop::Telepathy::RequestableChannelClass>();
95     qDBusRegisterMetaType<org::freedesktop::Telepathy::RequestableChannelClassList>();
96
97     QDBusConnection connection = QDBusConnection::sessionBus();
98
99     if (!connection.interface()->isServiceRegistered(cm_service_name))
100     {
101
102         // register CM on D-BUS:
103         if (connection.registerService(cm_service_name)){
104             qDebug(qPrintable(QObject::tr("Vicar-Telepathy: Service %1 registered with session bus.").
105                        arg(cm_service_name)));
106         }
107         else{
108             qDebug(qPrintable(QObject::tr("Vicar-Telepathy: Unable to register service %1 with session bus.").
109                        arg(cm_service_name)));
110         }
111
112     }
113
114     ConnectionManager connection_mgr(&app);
115     if (!connection.registerObject(cm_object_path,&connection_mgr)){
116         qDebug(qPrintable(QObject::tr("Vicar-Telepathy: Unable to register VICaR connection manager at path %1 with session bus.").
117                    arg(cm_object_path)));
118     }
119
120     qDebug(qPrintable(QObject::tr("Vicar-Telepathy: Enternig main loop.")));
121 //    logfile.close();
122     return app.exec();
123 }