update on dbus
[profile/ivi/genivi/genivi-audio-manager.git] / PluginRoutingInterfaceDbus / DbusInterface.cpp
1 /**
2  *
3  * Copyright (C) 2011, BMW AG
4  *
5  * PluginDBus
6  *
7  * \file RoutingSend.cpp
8  *
9  * \date 20.05.2011
10  * \author Christian Müller (christian.ei.mueller@bmw.de)
11  *
12  * \section License
13  * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
14  * Copyright (C) 2011, BMW AG – Christian Müller  Christian.ei.mueller@bmw.de
15  *
16  * 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.
17  * 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.
18  * 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>.
19  * 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.
20  * 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.
21  * 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.
22  * 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.
23  */
24
25
26 #include "headers.h"
27 #include "routinginterface.h"
28 #include <stdbool.h>
29 #include <unistd.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <string>
34 #include <sstream>
35
36 DLT_DECLARE_CONTEXT(DBusPlugin)
37
38 DbusInterface::DbusInterface(): m_busname(DBUS_BUSNAME), m_path(DBUS_PATH) {
39
40         DLT_REGISTER_APP("DBusPlugin", "DBusPlugin");
41         DLT_REGISTER_CONTEXT(DBusPlugin, "DPlugin", "Dbus Plugin");
42         DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("The DBus Plugin is started"));
43 }
44
45 DbusInterface::~DbusInterface() {
46         delete m_DbusInterface;
47 }
48
49 void DbusInterface::startup_interface(RoutingReceiveInterface* audioman,dbusRoothandler* dbushandler) {
50         m_audioman = audioman;
51         m_rootHandler = dbushandler;
52         m_DbusInterface = new AudioManagerInterface(audioman,dbushandler);
53         m_DbusInterface->startup_interface();
54         m_rootHandler->registerNode(MY_NODE);
55         DBusError err;
56     dbus_error_init(&err);
57
58     m_conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
59         if (dbus_error_is_set(&err)) {
60                 DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("Could not connect to DBUS for sending, Error: "), DLT_STRING(err.message));
61             dbus_error_free(&err);
62         }
63
64         DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("DBus Interface started "));
65 }
66
67 void DbusInterface::return_BusName(char* BusName) {
68         strcpy(BusName, BUS_NAME);
69 }
70
71 genError_t DbusInterface::connect(source_t source, sink_t sink, connection_t connID) {
72         int reply;
73         DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path, "connect");
74         send.appendInteger(source);
75         send.appendInteger(sink);
76         send.appendInteger(connID);
77         send.sendReply(&reply);
78         return GEN_OK;
79         /**
80          * \todo always OK...
81          */
82 }
83
84 void DbusInterface::system_ready() {
85         DLT_LOG(DBusPlugin, DLT_LOG_INFO, DLT_STRING("DBus Plugin got ready"));
86         m_DbusInterface->emit_systemReady();
87 }
88
89 genError_t DbusInterface::disconnect(connection_t connectionID) {
90         bool reply;
91         DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path,"disconnect");
92         send.appendInteger(connectionID);
93         send.sendReply(&reply);
94         return GEN_OK;
95         /**
96          * \todo always OK...
97          */
98 }
99
100 genError_t DbusInterface::setSinkVolume(volume_t volume, sink_t sink) {
101         int reply;
102         DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path,"setSinkVolume");
103         send.appendInteger(volume);
104         send.appendInteger(sink);
105         send.sendReply(&reply);
106         return GEN_OK;
107         /**
108          * \todo always OK...
109          */
110 }
111
112 genError_t DbusInterface::setSourceVolume(volume_t volume, source_t source) {
113         int reply;
114         DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path,"setSourceVolume");
115         send.appendInteger(volume);
116         send.appendInteger(source);
117         send.sendReply(&reply);
118         return GEN_OK;
119         /**
120          * \todo always OK...
121          */
122 }
123
124 genError_t DbusInterface::muteSource(source_t sourceID) {
125         bool reply;
126         DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path,"muteSource");
127         send.appendInteger(sourceID);
128         send.sendReply(&reply);
129         return GEN_OK;
130         /**
131          * \todo always OK...
132          */
133 }
134
135 genError_t DbusInterface::muteSink(sink_t sinkID) {
136         bool reply;
137         DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path,"muteSink");
138         send.appendInteger(sinkID);
139         send.sendReply(&reply);
140         return GEN_OK;
141         /**
142          * \todo always OK...
143          */
144 }
145
146 genError_t DbusInterface::unmuteSource(source_t sourceID) {
147         bool reply;
148         DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path,"unmuteSource");
149         send.appendInteger(sourceID);
150         send.sendReply(&reply);
151         return GEN_OK;
152         /**
153          * \todo always OK...
154          */
155 }
156
157 genError_t DbusInterface::unmuteSink(sink_t sinkID) {
158         bool reply;
159         DbusSend send = DbusSend(m_conn,"PULSE",(const char*)m_busname,(const char*)m_path,"unmuteSink");
160         send.appendInteger(sinkID);
161         send.sendReply(&reply);
162         return GEN_OK;
163         /**
164          * \todo always OK...
165          */
166 }
167
168 //genError_t DbusInterface::asyncConnect(source_t source, sink_t sink, connection_t con_ID) {
169 //      /**
170 //       * \todo implement
171 //       */
172 //      return GEN_OK;
173 //}
174 //
175 //genError_t DbusInterface::asyncDisconnect(connection_t connection_ID){
176 //      /**
177 //       * \todo implement
178 //       */
179 //      return GEN_OK;
180 //}
181
182 //That is the actual implementation of the Factory Class returning the real sendInterface
183
184 extern "C" RoutingSendInterface* PluginRoutingInterfaceDbusFactory() {
185     return new DbusInterface();
186 }
187
188 extern "C" void destroyRoutingPluginInterfaceDbus(RoutingSendInterface* iface) {
189     delete iface;
190 }
191
192