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