b6024ca4967a69820cbf0a2bc6e44ac21bfce374
[vicar] / src / vicar-telepathy / cpp / main.cpp
1 /*
2 @version: 0.6
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 <QDBusError>
39 #include <QDateTime>
40
41 #include "names.h"
42 #include "connectionmanager.h"
43 #include "basetypes.h"
44 #include "connectionmanagertypes.h"
45 #include "connectiontypes.h"
46 #include "connectioninterfacerequeststypes.h"
47 #include "connectioninterfacecapabilitiestypes.h"
48
49
50 using namespace std;
51
52 /*
53 ofstream logfile;
54
55 void MyOutputHandler(QtMsgType type, const char *msg) {
56     switch (type) {
57         case QtDebugMsg:
58             logfile << QTime::currentTime().toString().toAscii().data() << " Debug: " << msg << "\n";
59             break;
60         case QtCriticalMsg:
61             logfile << QTime::currentTime().toString().toAscii().data() << " Critical: " << msg << "\n";
62             break;
63         case QtWarningMsg:
64             logfile << QTime::currentTime().toString().toAscii().data() << " Warning: " << msg << "\n";
65             break;
66         case QtFatalMsg:
67             logfile << QTime::currentTime().toString().toAscii().data() <<  " Fatal: " << msg << "\n";
68             abort();
69     }
70 }
71
72 */
73
74 int main(int argc, char ** argv)
75 {
76
77 //    logfile.open("/var/log/logfile.txt", ios::app);
78 //    #ifndef QT_NO_DEBUG_OUTPUT
79 //    qInstallMsgHandler(MyOutputHandler);
80 //    #endif
81
82
83     QCoreApplication app(argc, argv);
84
85     // register types:
86     qDBusRegisterMetaType<org::freedesktop::Telepathy::ParameterDefinition>();
87     qDBusRegisterMetaType<org::freedesktop::Telepathy::ParameterDefinitionList>();
88     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelInfo>();
89     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelInfoList>();
90     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelDetails>();
91     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelDetailsList>();
92     qDBusRegisterMetaType<org::freedesktop::Telepathy::ContactCapabilities>();
93     qDBusRegisterMetaType<org::freedesktop::Telepathy::ContactCapabilitiesList>();
94     qDBusRegisterMetaType<org::freedesktop::Telepathy::CapabilityPair>();
95     qDBusRegisterMetaType<org::freedesktop::Telepathy::CapabilityPairList>();
96     qDBusRegisterMetaType<org::freedesktop::Telepathy::CapabilityChange>();
97     qDBusRegisterMetaType<org::freedesktop::Telepathy::CapabilityChangeList>();    
98     qDBusRegisterMetaType<org::freedesktop::Telepathy::RequestableChannelClass>();
99     qDBusRegisterMetaType<org::freedesktop::Telepathy::RequestableChannelClassList>();
100
101     QDBusConnection connection = QDBusConnection::sessionBus();
102
103     if (!connection.interface()->isServiceRegistered(cm_service_name))
104     {
105
106         // register CM on D-BUS:
107         bool success = connection.registerService(cm_service_name);
108         if (success){
109             qDebug(qPrintable(QObject::tr("Vicar-Telepathy: Service %1 registered with session bus.").
110                        arg(cm_service_name)));
111         }
112         else{
113
114             QDBusError error = connection.interface()->lastError();
115
116             qDebug(qPrintable(QObject::tr("Vicar-Telepathy: Unable to register service %1 with session bus due to error %2.").
117                        arg(cm_service_name,error.message())));
118         }
119
120     }
121
122     ConnectionManager connection_mgr(&app);
123     if (!connection.registerObject(cm_object_path,&connection_mgr)){
124         qDebug(qPrintable(QObject::tr("Vicar-Telepathy: Unable to register VICaR connection manager at path %1 with session bus.").
125                    arg(cm_object_path)));
126     }
127
128     qDebug(qPrintable(QObject::tr("Vicar-Telepathy: Enternig main loop.")));
129     return app.exec();
130 }