adding feature in the compile script:
[profile/ivi/audiomanager.git] / AudioManagerDaemon / DBusCommandInterface.cpp
1 /**
2  * Copyright (C) 2011, BMW AG
3  *
4  * AudioManangerDeamon
5  *
6  * \file DBusCommandInterface.cpp
7  *
8  * \date 20.05.2011
9  * \author Christian Müller (christian.ei.mueller@bmw.de)
10  *
11  * \section License
12  * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
13  * Copyright (C) 2011, BMW AG – Christian Müller  Christian.ei.mueller@bmw.de
14  *
15  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
16  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
17  * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
18  * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
19  * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
20  * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
21  * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
22  *
23  *
24  */
25
26 #include "DBusCommandInterface.h"
27 #include "DBusCommand.h"
28
29 DBusCommandInterface::DBusCommandInterface(QObject* parent) {
30         (void) parent;
31 REGISTER_METATYPES}
32
33 void DBusCommandInterface::startupInterface() {
34         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Startup of DBUS Command interface"));
35
36         new DBusCommand(this);
37         QDBusConnection connection = QDBusConnection::sessionBus();
38         connection.registerService(QString(SERVICEINTERFACE));
39         if (connection.isConnected()) {
40                 if (connection.registerObject(
41                                 "/Control",
42                                 this,
43                                 (QDBusConnection::ExportAdaptors
44                                                 | QDBusConnection::ExportAllSignals))) {
45                         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Registered DBUS Command interface succsessfully"));
46                 } else {
47                         DLT_LOG(AudioManager,DLT_LOG_ERROR, DLT_STRING("Failed to register DBUS Command interface succsessfully"));
48                 }
49         }
50 }
51
52 int DBusCommandInterface::connect(int Source_ID, int Sink_ID) {
53         if (m_core->UserConnect(Source_ID, Sink_ID) == GEN_OK) {
54                 return 1;
55         }
56         return -1;
57 }
58
59 int DBusCommandInterface::disconnect(int Source_ID, int Sink_ID) {
60         DLT_LOG(AudioManager,DLT_LOG_ERROR, DLT_STRING("Disconnect"));
61         genRoute_t ReturnRoute;
62         if (int value=m_core->returnDatabaseHandler()->returnMainconnectionIDforSinkSourceID(Sink_ID,Source_ID)>0) {
63                 return m_core->UserDisconnect(value);
64         } else {
65                 return -1;
66         }
67 }
68
69 int DBusCommandInterface::interruptRequest(const QString &SourceName,
70                 const QString &SinkName) {
71         source_t sourceID = m_core->returnSourceIDfromName(SourceName);
72         sink_t sinkID = m_core->returnSinkIDfromName(SinkName);
73         genInt_t intID = -1;
74         m_core->interruptRequest(sourceID, sinkID, &intID);
75         return intID;
76 }
77
78 int DBusCommandInterface::interruptResume(int InterruptID) {
79         emit signal_interruptResume(InterruptID);
80         return 1;
81 }
82
83 void DBusCommandInterface::registerAudioManagerCore(AudioManagerCore* core) {
84         m_core = core;
85         QObject::connect((const QObject*) m_core,
86                         SIGNAL(signal_connectionChanged()), (const QObject*) this,
87                         SLOT(slot_connectionChanged()));
88         QObject::connect((const QObject*) m_core,
89                         SIGNAL(signal_numberOfSinksChanged()), (const QObject*) this,
90                         SLOT(slot_numberOfSinksChanged()));
91         QObject::connect((const QObject*) m_core,
92                         SIGNAL(signal_numberOfSourcesChanged()), (const QObject*) this,
93                         SLOT(slot_numberOfSourcesChanged()));
94 }
95
96 void DBusCommandInterface::slot_connectionChanged() {
97         emit signal_connectionChanged();
98 }
99 void DBusCommandInterface::slot_numberOfSinksChanged() {
100         emit signal_numberOfSinksChanged();
101 }
102 void DBusCommandInterface::slot_numberOfSourcesChanged() {
103         emit signal_numberOfSourcesChanged();
104 }
105
106 int DBusCommandInterface::setVolume(int SinkID, int Volume) {
107         if (m_core->UserSetVolume(SinkID, Volume) == GEN_OK) {
108                 return 1;
109         }
110         return -1;
111 }
112
113 QList<SourceType> DBusCommandInterface::getListSources() {
114         return m_core->getListSources();
115 }
116
117 QList<SinkType> DBusCommandInterface::getListSinks() {
118         return m_core->getListSinks();
119 }
120
121 QList<ConnectionType> DBusCommandInterface::getListConnections() {
122         return m_core->getListConnections();
123 }