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
26 #include <command/CommandReceiveInterface.h>
27 #include <dbus/DBusWrapper.h>
28 #include "DBusCommandSender.h"
29 #include "DBusMessageHandler.h"
39 DLT_DECLARE_CONTEXT(DLT_CONTEXT)
42 * factory for plugin loading
44 extern "C" CommandSendInterface* PluginCommandInterfaceDbusFactory()
46 return (new DbusCommandSender());
50 * destroy instance of commandSendInterface
52 extern "C" void destroyRoutingPluginInterfaceDbus(CommandSendInterface* commandSendInterface)
54 delete commandSendInterface;
57 DbusCommandSender::DbusCommandSender() :
58 mDBUSMessageHandler(), //
59 mCommandReceiverShadow(), //
60 mDBusWrapper(NULL), //
61 mCommandReceiveInterface(NULL)
63 DLT_REGISTER_CONTEXT(DLT_CONTEXT, "DBP", "DBus Plugin");
64 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("DbusCommandSender constructed"));
67 DbusCommandSender::~DbusCommandSender()
69 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("DbusCommandSender destructed"));
70 DLT_UNREGISTER_CONTEXT(DLT_CONTEXT);
73 am_Error_e DbusCommandSender::startupInterface(CommandReceiveInterface* commandreceiveinterface)
75 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("startupInterface called"));
77 mCommandReceiveInterface = commandreceiveinterface;
78 mCommandReceiverShadow.setCommandReceiver(mCommandReceiveInterface);
79 mCommandReceiveInterface->getDBusConnectionWrapper(mDBusWrapper);
80 assert(mDBusWrapper!=NULL);
84 am_Error_e DbusCommandSender::stopInterface()
86 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("stopInterface called"));
88 * todo: finish DbusCommandSender::stopInterface(), what needs to be done?
93 am_Error_e DbusCommandSender::cbCommunicationReady()
95 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("cbCommunicationReady called"));
97 * todo: implement DbusCommandSender::cbCommunicationReady()
102 am_Error_e DbusCommandSender::cbCommunicationRundown()
104 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("cbCommunicationRundown called"));
106 * todo: implement DbusCommandSender::cbCommunicationRundown()
111 void DbusCommandSender::cbNumberOfMainConnectionsChanged()
113 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("cbNumberOfMainConnectionsChanged called"));
115 mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("NumberOfMainConnectionsChanged"));
116 mDBUSMessageHandler.sendMessage();
119 void DbusCommandSender::cbNumberOfSinksChanged()
121 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("cbNumberOfSinksChanged called"));
123 std::vector<am_SinkType_s> newListSinks;
124 std::vector<am_SinkType_s> diffList;
125 mCommandReceiveInterface->getListMainSinks(newListSinks);
126 std::sort(newListSinks.begin(), newListSinks.end(), sortBySinkID());
127 std::set_symmetric_difference(newListSinks.begin(), newListSinks.end(), mlistSinks.begin(), mlistSinks.end(), std::back_inserter(diffList), sortBySinkID());
128 assert(diffList.size()==1);
129 if (newListSinks.size() > mlistSinks.size())
131 mDBUSMessageHandler.initSignal(std::string(MY_NODE), "SinkAdded");
132 mDBUSMessageHandler.append(diffList[0]);
134 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("send signal SinkAdded"));
138 mDBUSMessageHandler.initSignal(std::string(MY_NODE), "SinkRemoved");
139 mDBUSMessageHandler.append(diffList.begin()->sinkID);
141 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("send signal SinkRemoved"));
144 mDBUSMessageHandler.sendMessage();
145 mlistSinks = newListSinks;
148 void DbusCommandSender::cbNumberOfSourcesChanged()
150 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("cbNumberOfSourcesChanged called"));
152 std::vector<am_SourceType_s> newlistSources;
153 std::vector<am_SourceType_s> diffList;
154 mCommandReceiveInterface->getListMainSources(newlistSources);
155 std::sort(newlistSources.begin(), newlistSources.end(), sortBySourceID());
156 std::set_symmetric_difference(newlistSources.begin(), newlistSources.end(), mlistSources.begin(), mlistSources.end(), std::back_inserter(diffList), sortBySourceID());
157 assert(diffList.size()==1);
158 if (newlistSources.size() > mlistSources.size())
160 mDBUSMessageHandler.initSignal(std::string(MY_NODE), "SourceAdded");
161 mDBUSMessageHandler.append(diffList[0]);
163 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("send signal SourceAdded"));
167 mDBUSMessageHandler.initSignal(std::string(MY_NODE), "SourceRemoved");
168 mDBUSMessageHandler.append((dbus_uint16_t) diffList.begin()->sourceID);
170 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("send signal SourceRemoved"));
173 mDBUSMessageHandler.sendMessage();
174 mlistSources = newlistSources;
177 void DbusCommandSender::cbNumberOfSinkClassesChanged()
179 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("cbNumberOfSinkClassesChanged called"));
181 mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("NumberOfSinkClassesChanged"));
182 mDBUSMessageHandler.sendMessage();
185 void DbusCommandSender::cbNumberOfSourceClassesChanged()
187 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("cbNumberOfSourceClassesChanged called"));
189 mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("NumberOfSourceClassesChanged"));
190 mDBUSMessageHandler.sendMessage();
193 void DbusCommandSender::cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState)
195 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("cbMainConnectionStateChanged called, connectionID"), DLT_INT16(connectionID), DLT_STRING("connectionState"), DLT_INT16(connectionState));
197 mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("MainConnectionStateChanged"));
198 mDBUSMessageHandler.append((dbus_uint16_t) connectionID);
199 mDBUSMessageHandler.append((dbus_int16_t) connectionState);
200 mDBUSMessageHandler.sendMessage();
203 void DbusCommandSender::cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s SoundProperty)
205 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));
207 mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("MainSinkSoundPropertyChanged"));
208 mDBUSMessageHandler.append((dbus_uint16_t) sinkID);
209 mDBUSMessageHandler.append(SoundProperty);
210 mDBUSMessageHandler.sendMessage();
213 void DbusCommandSender::cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s & SoundProperty)
215 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));
217 mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("MainSourceSoundPropertyChanged"));
218 mDBUSMessageHandler.append((dbus_uint16_t) sourceID);
219 mDBUSMessageHandler.append(SoundProperty);
220 mDBUSMessageHandler.sendMessage();
223 void DbusCommandSender::cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s & availability)
225 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));
227 mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("SinkAvailabilityChanged"));
228 mDBUSMessageHandler.append((dbus_uint16_t) sinkID);
229 mDBUSMessageHandler.append(availability);
230 mDBUSMessageHandler.sendMessage();
233 void DbusCommandSender::cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s & availability)
235 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));
237 mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("SourceAvailabilityChanged"));
238 mDBUSMessageHandler.append((dbus_uint16_t) sourceID);
239 mDBUSMessageHandler.append(availability);
240 mDBUSMessageHandler.sendMessage();
243 void DbusCommandSender::cbVolumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume)
245 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("cbVolumeChanged called, sinkID"), DLT_INT16(sinkID), DLT_STRING("volume"), DLT_INT16(volume));
247 mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("VolumeChanged"));
248 mDBUSMessageHandler.append((dbus_uint16_t) sinkID);
249 mDBUSMessageHandler.append((dbus_int16_t) volume);
250 mDBUSMessageHandler.sendMessage();
253 void DbusCommandSender::cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState)
255 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("cbSinkMuteStateChanged called, sinkID"), DLT_INT16(sinkID), DLT_STRING("muteState"), DLT_INT16(muteState));
257 mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("SinkMuteStateChanged"));
258 mDBUSMessageHandler.append((dbus_uint16_t) sinkID);
259 mDBUSMessageHandler.append((dbus_int16_t) muteState);
260 mDBUSMessageHandler.sendMessage();
263 void DbusCommandSender::cbSystemPropertyChanged(const am_SystemProperty_s & SystemProperty)
265 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));
267 mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("SystemPropertyChanged"));
268 mDBUSMessageHandler.append(SystemProperty);
269 mDBUSMessageHandler.sendMessage();
272 void am::DbusCommandSender::cbTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time)
274 DLT_LOG(DLT_CONTEXT, DLT_LOG_INFO, DLT_STRING("cbTimingInformationChanged called, mainConnectionID"), DLT_INT16(mainConnectionID), DLT_STRING("time"), DLT_INT16(time));
276 mDBUSMessageHandler.initSignal(std::string(MY_NODE), std::string("TimingInformationChanged"));
277 mDBUSMessageHandler.append((dbus_uint16_t) mainConnectionID);
278 mDBUSMessageHandler.append((dbus_int16_t) time);
279 mDBUSMessageHandler.sendMessage();
282 uint16_t DbusCommandSender::getInterfaceVersion() const
284 return (CommandSendVersion);