e58422d16efeeb01721fe06a7fe211b356513291
[profile/ivi/audiomanager.git] / PluginCommandInterfaceDbus / src / DBusCommandSender.cpp
1 /**
2 * Copyright (C) 2011, BMW AG
3 *
4 * GeniviAudioMananger DbusPlugin
5 *
6 * \file CommandSender.cpp
7 *
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (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 Mueller  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 * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN
24 */
25
26
27 #include <command/CommandReceiveInterface.h>
28 #include <dbus/DBusWrapper.h>
29 #include "DBusCommandSender.h"
30 #include "DBusMessageHandler.h"
31 #include <dlt/dlt.h>
32 #include <algorithm>
33 #include <string>
34 #include <vector>
35 #include <assert.h>
36 #include <set>
37
38 using namespace am;
39
40 DLT_DECLARE_CONTEXT(DLT_CONTEXT)
41 //DLT_IMPORT_CONTEXT(DLT_CONTEXT);
42
43 /**
44  * factory for plugin loading
45  */
46 extern "C" CommandSendInterface* PluginCommandInterfaceDbusFactory()
47 {
48         return (new DbusCommandSender());
49 }
50
51 /**
52  * destroy instance of commandSendInterface
53  */
54 extern "C" void destroyRoutingPluginInterfaceDbus(CommandSendInterface* commandSendInterface)
55 {
56     delete commandSendInterface;
57 }
58
59
60 DbusCommandSender::DbusCommandSender()
61 :       mDBUSMessageHandler(),
62         mCommandReceiverShadow(),
63         mDBusWrapper(NULL),
64         mCommandReceiveInterface(NULL)
65 {
66         DLT_REGISTER_CONTEXT(DLT_CONTEXT,"DBP","DBus Plugin");
67         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("DbusCommandSender constructed"));
68 }
69
70 DbusCommandSender::~DbusCommandSender()
71 {
72         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("DbusCommandSender destructed"));
73         DLT_UNREGISTER_CONTEXT(DLT_CONTEXT);
74 }
75
76 am_Error_e DbusCommandSender::startupInterface(CommandReceiveInterface* commandreceiveinterface)
77 {
78         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("startupInterface called"));
79
80         mCommandReceiveInterface=commandreceiveinterface;
81         mCommandReceiverShadow.setCommandReceiver(mCommandReceiveInterface);
82         mCommandReceiveInterface->getDBusConnectionWrapper(mDBusWrapper);
83         assert(mDBusWrapper!=NULL);
84         return (E_OK);
85 }
86
87
88
89 am_Error_e DbusCommandSender::stopInterface()
90 {
91         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("stopInterface called"));
92         /**
93          * todo: finish DbusCommandSender::stopInterface(), what needs to be done?
94          */
95         return(E_OK);
96 }
97
98
99
100 am_Error_e DbusCommandSender::cbCommunicationReady()
101 {
102         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbCommunicationReady called"));
103         /**
104          * todo: implement DbusCommandSender::cbCommunicationReady()
105          */
106         return E_NOT_USED;
107 }
108
109
110
111 am_Error_e DbusCommandSender::cbCommunicationRundown()
112 {
113         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbCommunicationRundown called"));
114         /**
115          * todo: implement DbusCommandSender::cbCommunicationRundown()
116          */
117         return E_NOT_USED;
118 }
119
120
121
122 void DbusCommandSender::cbNumberOfMainConnectionsChanged()
123 {
124         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbNumberOfMainConnectionsChanged called"));
125
126         mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("NumberOfMainConnectionsChanged"));
127         mDBUSMessageHandler.sendMessage();
128 }
129
130
131
132 void DbusCommandSender::cbNumberOfSinksChanged()
133 {
134         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbNumberOfSinksChanged called"));
135
136         std::vector<am_SinkType_s> newListSinks;
137         std::vector<am_SinkType_s> diffList;
138         mCommandReceiveInterface->getListMainSinks(newListSinks);
139         std::sort(newListSinks.begin(),newListSinks.end(),sortBySinkID());
140         std::set_symmetric_difference(newListSinks.begin(),newListSinks.end(),mlistSinks.begin(),mlistSinks.end(),std::back_inserter(diffList), sortBySinkID());
141         assert(diffList.size()==1);
142         if (newListSinks.size()>mlistSinks.size())
143         {
144                 mDBUSMessageHandler.initSignal(std::string(MY_NODE),"SinkAdded");
145                 mDBUSMessageHandler.append(diffList[0]);
146
147                 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("send signal SinkAdded"));
148         }
149         else
150         {
151                 mDBUSMessageHandler.initSignal(std::string(MY_NODE),"SinkRemoved");
152                 mDBUSMessageHandler.append(diffList.begin()->sinkID);
153
154                 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("send signal SinkRemoved"));
155         }
156
157         mDBUSMessageHandler.sendMessage();
158         mlistSinks=newListSinks;
159 }
160
161
162
163 void DbusCommandSender::cbNumberOfSourcesChanged()
164 {
165         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbNumberOfSourcesChanged called"));
166
167         std::vector<am_SourceType_s> newlistSources;
168         std::vector<am_SourceType_s> diffList;
169         mCommandReceiveInterface->getListMainSources(newlistSources);
170         std::sort(newlistSources.begin(),newlistSources.end(),sortBySourceID());
171         std::set_symmetric_difference(newlistSources.begin(),newlistSources.end(),mlistSources.begin(),mlistSources.end(),std::back_inserter(diffList), sortBySourceID());
172         assert(diffList.size()==1);
173         if (newlistSources.size()>mlistSources.size())
174         {
175                 mDBUSMessageHandler.initSignal(std::string(MY_NODE),"SourceAdded");
176                 mDBUSMessageHandler.append(diffList[0]);
177
178                 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("send signal SourceAdded"));
179         }
180         else
181         {
182                 mDBUSMessageHandler.initSignal(std::string(MY_NODE),"SourceRemoved");
183                 mDBUSMessageHandler.append((dbus_uint16_t)diffList.begin()->sourceID);
184
185                 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("send signal SourceRemoved"));
186         }
187
188         mDBUSMessageHandler.sendMessage();
189         mlistSources=newlistSources;
190 }
191
192
193 void DbusCommandSender::cbNumberOfSinkClassesChanged()
194 {
195         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbNumberOfSinkClassesChanged called"));
196
197         mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("NumberOfSinkClassesChanged"));
198         mDBUSMessageHandler.sendMessage();
199 }
200
201
202
203 void DbusCommandSender::cbNumberOfSourceClassesChanged()
204 {
205         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbNumberOfSourceClassesChanged called"));
206
207         mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("NumberOfSourceClassesChanged"));
208         mDBUSMessageHandler.sendMessage();
209 }
210
211
212
213 void DbusCommandSender::cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState)
214 {
215         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbMainConnectionStateChanged called, connectionID"),DLT_INT16(connectionID),DLT_STRING("connectionState"),DLT_INT16(connectionState));
216
217         mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("MainConnectionStateChanged"));
218         mDBUSMessageHandler.append((dbus_uint16_t)connectionID);
219         mDBUSMessageHandler.append((dbus_int16_t)connectionState);
220         mDBUSMessageHandler.sendMessage();
221 }
222
223
224
225 void DbusCommandSender::cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s SoundProperty)
226 {
227         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbMainSinkSoundPropertyChanged called, sinkID"),DLT_INT16(sinkID),DLT_STRING("SoundProperty.type"),DLT_INT16(SoundProperty.type),DLT_STRING("SoundProperty.value"),DLT_INT16(SoundProperty.value));
228
229         mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("MainSinkSoundPropertyChanged"));
230         mDBUSMessageHandler.append((dbus_uint16_t)sinkID);
231         mDBUSMessageHandler.append(SoundProperty);
232         mDBUSMessageHandler.sendMessage();
233 }
234
235
236
237 void DbusCommandSender::cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s & SoundProperty)
238 {
239         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbMainSourceSoundPropertyChanged called, sourceID"),DLT_INT16(sourceID),DLT_STRING("SoundProperty.type"),DLT_INT16(SoundProperty.type),DLT_STRING("SoundProperty.value"),DLT_INT16(SoundProperty.value));
240
241         mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("MainSourceSoundPropertyChanged"));
242         mDBUSMessageHandler.append((dbus_uint16_t)sourceID);
243         mDBUSMessageHandler.append(SoundProperty);
244         mDBUSMessageHandler.sendMessage();
245 }
246
247
248
249 void DbusCommandSender::cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s & availability)
250 {
251         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbSinkAvailabilityChanged called, sinkID"),DLT_INT16(sinkID),DLT_STRING("availability.availability"),DLT_INT16(availability.availability),DLT_STRING("SoundProperty.reason"),DLT_INT16(availability.availabilityReason));
252
253         mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("SinkAvailabilityChanged"));
254         mDBUSMessageHandler.append((dbus_uint16_t)sinkID);
255         mDBUSMessageHandler.append(availability);
256         mDBUSMessageHandler.sendMessage();
257 }
258
259
260
261 void DbusCommandSender::cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s & availability)
262 {
263         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbSourceAvailabilityChanged called, sourceID"),DLT_INT16(sourceID),DLT_STRING("availability.availability"),DLT_INT16(availability.availability),DLT_STRING("SoundProperty.reason"),DLT_INT16(availability.availabilityReason));
264
265         mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("SourceAvailabilityChanged"));
266         mDBUSMessageHandler.append((dbus_uint16_t)sourceID);
267         mDBUSMessageHandler.append(availability);
268         mDBUSMessageHandler.sendMessage();
269 }
270
271
272
273 void DbusCommandSender::cbVolumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume)
274 {
275         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbVolumeChanged called, sinkID"),DLT_INT16(sinkID),DLT_STRING("volume"),DLT_INT16(volume));
276
277         mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("VolumeChanged"));
278         mDBUSMessageHandler.append((dbus_uint16_t)sinkID);
279         mDBUSMessageHandler.append((dbus_int16_t)volume);
280         mDBUSMessageHandler.sendMessage();
281 }
282
283
284
285 void DbusCommandSender::cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState)
286 {
287         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbSinkMuteStateChanged called, sinkID"),DLT_INT16(sinkID),DLT_STRING("muteState"),DLT_INT16(muteState));
288
289         mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("SinkMuteStateChanged"));
290         mDBUSMessageHandler.append((dbus_uint16_t)sinkID);
291         mDBUSMessageHandler.append((dbus_int16_t)muteState);
292         mDBUSMessageHandler.sendMessage();
293 }
294
295
296
297 void DbusCommandSender::cbSystemPropertyChanged(const am_SystemProperty_s & SystemProperty)
298 {
299         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbSystemPropertyChanged called, SystemProperty.type"),DLT_INT16(SystemProperty.type),DLT_STRING("SystemProperty.value"),DLT_INT16(SystemProperty.value));
300
301         mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("SystemPropertyChanged"));
302         mDBUSMessageHandler.append(SystemProperty);
303         mDBUSMessageHandler.sendMessage();
304 }
305
306
307
308 void DbusCommandSender::cbTimingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time)
309 {
310         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbTimingInformationChanged called, mainConnectionID"),DLT_INT16(mainConnection),DLT_STRING("time"),DLT_INT16(time));
311
312         mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("TimingInformationChanged"));
313         mDBUSMessageHandler.append((dbus_uint16_t)mainConnection);
314         mDBUSMessageHandler.append((dbus_int16_t)time);
315         mDBUSMessageHandler.sendMessage();
316 }
317
318
319
320
321
322
323
324
325
326
327
328
329
330