Add documentation, code cleanups
[profile/ivi/ofono-qt.git] / lib / ofonomodemmanager.cpp
1 /*
2  * This file is part of ofono-qt
3  *
4  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5  *
6  * Contact: Alexander Kanavin <alexander.kanavin@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #include <QtDBus/QtDBus>
25 #include <QtCore/QObject>
26
27 #include "ofonomodemmanager.h"
28 #include "ofonointerface.h"
29
30 QDBusArgument &operator<<(QDBusArgument &argument, const OfonoModemStruct &modem)
31 {
32     argument.beginStructure();
33     argument << modem.path << modem.properties;
34     argument.endStructure();
35     return argument;
36 }   
37
38 const QDBusArgument &operator>>(const QDBusArgument &argument, OfonoModemStruct &modem)
39 {   
40     argument.beginStructure();
41     argument >> modem.path >> modem.properties; 
42     argument.endStructure();
43     return argument;
44 }
45
46 OfonoModemManager::OfonoModemManager(QObject *parent)
47     : QObject(parent)
48 {
49     QDBusReply<OfonoModemList> reply;
50     OfonoModemList modems;
51
52     QDBusMessage request;
53
54     qDBusRegisterMetaType<OfonoModemStruct>();
55     qDBusRegisterMetaType<OfonoModemList>();
56
57     request = QDBusMessage::createMethodCall("org.ofono",
58                                              "/", "org.ofono.Manager",
59                                              "GetModems");
60     reply = QDBusConnection::systemBus().call(request);
61
62     modems = reply;
63     foreach(OfonoModemStruct modem, modems) {
64         m_modems << modem.path.path();
65     }
66
67     QDBusConnection::systemBus().connect("org.ofono","/","org.ofono.Manager",
68                                          "ModemAdded", this, 
69                                          SLOT(onModemAdded(const QDBusObjectPath&, const QVariantMap&)));
70     QDBusConnection::systemBus().connect("org.ofono","/","org.ofono.Manager",
71                                          "ModemRemoved", this, 
72                                          SLOT(onModemRemoved(const QDBusObjectPath&)));
73
74 }
75
76 OfonoModemManager::~OfonoModemManager()
77 {
78 }
79
80 QStringList OfonoModemManager::modems() const
81 {
82     return m_modems;
83 }
84
85 void OfonoModemManager::onModemAdded(const QDBusObjectPath& path, const QVariantMap& /*map*/)
86 {
87     m_modems << path.path();
88     emit modemAdded(path.path());
89 }
90
91 void OfonoModemManager::onModemRemoved(const QDBusObjectPath& path)
92 {
93     m_modems.removeAll(path.path()); 
94     emit modemRemoved(path.path());
95 }
96
97