2 * Copyright (C) 2011, BMW AG
4 * GeniviAudioMananger DbusPlugin
6 * \file CommandSender.cpp
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (christian.ei.mueller@bmw.de)
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
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.
23 * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN
27 #include <command/CommandReceiveInterface.h>
28 #include <dbus/DBusWrapper.h>
29 #include "DBusCommandSender.h"
30 #include "DBusMessageHandler.h"
40 DLT_DECLARE_CONTEXT(DLT_CONTEXT)
43 * factory for plugin loading
45 extern "C" CommandSendInterface* PluginCommandInterfaceDbusFactory()
47 return (new DbusCommandSender());
51 * destroy instance of commandSendInterface
53 extern "C" void destroyRoutingPluginInterfaceDbus(CommandSendInterface* commandSendInterface)
55 delete commandSendInterface;
59 DbusCommandSender::DbusCommandSender()
60 : mDBUSMessageHandler(),
61 mCommandReceiverShadow(),
63 mCommandReceiveInterface(NULL)
65 DLT_REGISTER_CONTEXT(DLT_CONTEXT,"DBP","DBus Plugin");
66 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("DbusCommandSender constructed"));
69 DbusCommandSender::~DbusCommandSender()
71 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("DbusCommandSender destructed"));
72 DLT_UNREGISTER_CONTEXT(DLT_CONTEXT);
75 am_Error_e DbusCommandSender::startupInterface(CommandReceiveInterface* commandreceiveinterface)
77 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("startupInterface called"));
79 mCommandReceiveInterface=commandreceiveinterface;
80 mCommandReceiverShadow.setCommandReceiver(mCommandReceiveInterface);
81 mCommandReceiveInterface->getDBusConnectionWrapper(mDBusWrapper);
82 assert(mDBusWrapper!=NULL);
88 am_Error_e DbusCommandSender::stopInterface()
90 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("stopInterface called"));
92 * todo: finish DbusCommandSender::stopInterface(), what needs to be done?
99 am_Error_e DbusCommandSender::cbCommunicationReady()
101 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbCommunicationReady called"));
103 * todo: implement DbusCommandSender::cbCommunicationReady()
110 am_Error_e DbusCommandSender::cbCommunicationRundown()
112 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbCommunicationRundown called"));
114 * todo: implement DbusCommandSender::cbCommunicationRundown()
121 void DbusCommandSender::cbNumberOfMainConnectionsChanged()
123 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbNumberOfMainConnectionsChanged called"));
125 mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("NumberOfMainConnectionsChanged"));
126 mDBUSMessageHandler.sendMessage();
131 void DbusCommandSender::cbNumberOfSinksChanged()
133 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbNumberOfSinksChanged called"));
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())
143 mDBUSMessageHandler.initSignal(std::string(MY_NODE),"SinkAdded");
144 mDBUSMessageHandler.append(diffList[0]);
146 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("send signal SinkAdded"));
150 mDBUSMessageHandler.initSignal(std::string(MY_NODE),"SinkRemoved");
151 mDBUSMessageHandler.append(diffList.begin()->sinkID);
153 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("send signal SinkRemoved"));
156 mDBUSMessageHandler.sendMessage();
157 mlistSinks=newListSinks;
162 void DbusCommandSender::cbNumberOfSourcesChanged()
164 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbNumberOfSourcesChanged called"));
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())
174 mDBUSMessageHandler.initSignal(std::string(MY_NODE),"SourceAdded");
175 mDBUSMessageHandler.append(diffList[0]);
177 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("send signal SourceAdded"));
181 mDBUSMessageHandler.initSignal(std::string(MY_NODE),"SourceRemoved");
182 mDBUSMessageHandler.append((dbus_uint16_t)diffList.begin()->sourceID);
184 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("send signal SourceRemoved"));
187 mDBUSMessageHandler.sendMessage();
188 mlistSources=newlistSources;
192 void DbusCommandSender::cbNumberOfSinkClassesChanged()
194 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbNumberOfSinkClassesChanged called"));
196 mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("NumberOfSinkClassesChanged"));
197 mDBUSMessageHandler.sendMessage();
202 void DbusCommandSender::cbNumberOfSourceClassesChanged()
204 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbNumberOfSourceClassesChanged called"));
206 mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("NumberOfSourceClassesChanged"));
207 mDBUSMessageHandler.sendMessage();
212 void DbusCommandSender::cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState)
214 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbMainConnectionStateChanged called, connectionID"),DLT_INT16(connectionID),DLT_STRING("connectionState"),DLT_INT16(connectionState));
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();
224 void DbusCommandSender::cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s SoundProperty)
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));
228 mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("MainSinkSoundPropertyChanged"));
229 mDBUSMessageHandler.append((dbus_uint16_t)sinkID);
230 mDBUSMessageHandler.append(SoundProperty);
231 mDBUSMessageHandler.sendMessage();
236 void DbusCommandSender::cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s & SoundProperty)
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));
240 mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("MainSourceSoundPropertyChanged"));
241 mDBUSMessageHandler.append((dbus_uint16_t)sourceID);
242 mDBUSMessageHandler.append(SoundProperty);
243 mDBUSMessageHandler.sendMessage();
248 void DbusCommandSender::cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s & availability)
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));
252 mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("SinkAvailabilityChanged"));
253 mDBUSMessageHandler.append((dbus_uint16_t)sinkID);
254 mDBUSMessageHandler.append(availability);
255 mDBUSMessageHandler.sendMessage();
260 void DbusCommandSender::cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s & availability)
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));
264 mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("SourceAvailabilityChanged"));
265 mDBUSMessageHandler.append((dbus_uint16_t)sourceID);
266 mDBUSMessageHandler.append(availability);
267 mDBUSMessageHandler.sendMessage();
272 void DbusCommandSender::cbVolumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume)
274 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbVolumeChanged called, sinkID"),DLT_INT16(sinkID),DLT_STRING("volume"),DLT_INT16(volume));
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();
284 void DbusCommandSender::cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState)
286 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbSinkMuteStateChanged called, sinkID"),DLT_INT16(sinkID),DLT_STRING("muteState"),DLT_INT16(muteState));
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();
296 void DbusCommandSender::cbSystemPropertyChanged(const am_SystemProperty_s & SystemProperty)
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));
300 mDBUSMessageHandler.initSignal(std::string(MY_NODE),std::string("SystemPropertyChanged"));
301 mDBUSMessageHandler.append(SystemProperty);
302 mDBUSMessageHandler.sendMessage();
307 void DbusCommandSender::cbTimingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time)
309 DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("cbTimingInformationChanged called, mainConnectionID"),DLT_INT16(mainConnection),DLT_STRING("time"),DLT_INT16(time));
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();