AudioManager  7.6.6
Native Application Runtime Environment
CAmCommandReceiver.cpp
Go to the documentation of this file.
1 
24 #include "CAmCommandReceiver.h"
25 #include <cassert>
26 #include <algorithm>
27 #include "IAmDatabaseHandler.h"
28 #include "CAmControlSender.h"
29 #include "CAmDltWrapper.h"
30 #include "CAmSocketHandler.h"
31 
32 #define __METHOD_NAME__ std::string (std::string("CAmCommandReceiver::") + __func__)
33 
34 namespace am
35 {
36 
38  mDatabaseHandler(iDatabaseHandler), //
39  mControlSender(iControlSender), //
40  mDBusWrapper(NULL), //
41  mSocketHandler(iSocketHandler), //
42  handleCount(0),//
43  mListStartupHandles(), //
44  mListRundownHandles(), //
45  mWaitStartup(false), //
46  mWaitRundown(false),
47  mLastErrorStartup(E_OK), //
48  mLastErrorRundown(E_OK) //
49 
50 {
51  assert(mDatabaseHandler!=NULL);
52  assert(mSocketHandler!=NULL);
53  assert(mControlSender!=NULL);
54 }
55 
56 CAmCommandReceiver::CAmCommandReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler, CAmDbusWrapper *iDBusWrapper) :
57  mDatabaseHandler(iDatabaseHandler), //
58  mControlSender(iControlSender), //
59  mDBusWrapper(iDBusWrapper), //
60  mSocketHandler(iSocketHandler), //
61  handleCount(0),//
62  mListStartupHandles(), //
63  mListRundownHandles(), //
64  mWaitStartup(false), //
65  mWaitRundown(false), //
66  mLastErrorStartup(E_UNKNOWN), //
67  mLastErrorRundown(E_UNKNOWN)
68 {
69  assert(mDatabaseHandler!=NULL);
70  assert(mSocketHandler!=NULL);
71  assert(mControlSender!=NULL);
72  assert(mDBusWrapper!=NULL);
73 }
74 
76 {
77 }
78 
80 {
81  logInfo(__METHOD_NAME__,"sourceID=", sourceID, "sinkID=", sinkID);
82  return (mControlSender->hookUserConnectionRequest(sourceID, sinkID, mainConnectionID));
83 }
84 
86 {
87  logInfo(__METHOD_NAME__,"mainConnectionID=", mainConnectionID);
88  return (mControlSender->hookUserDisconnectionRequest(mainConnectionID));
89 }
90 
92 {
93  logInfo(__METHOD_NAME__,"sinkID=", sinkID, "volume=", volume);
94  return (mControlSender->hookUserVolumeChange(sinkID, volume));
95 }
96 
98 {
99  logInfo(__METHOD_NAME__,"sinkID=", sinkID, "volumeStep=", volumeStep);
100  return (mControlSender->hookUserVolumeStep(sinkID, volumeStep));
101 }
102 
104 {
105  logInfo(__METHOD_NAME__,"sinkID=", sinkID, "muteState=", muteState);
106  return (mControlSender->hookUserSetSinkMuteState(sinkID, muteState));
107 }
108 
110 {
111  logInfo(__METHOD_NAME__,"sinkID=", sinkID, "soundPropertyType=", soundProperty.type, "soundPropertyValue=", soundProperty.value);
112  return (mControlSender->hookUserSetMainSinkSoundProperty(sinkID, soundProperty));
113 }
114 
116 {
117  logInfo(__METHOD_NAME__,"sourceID=", sourceID, "soundPropertyType=", soundProperty.type, "soundPropertyValue=", soundProperty.value);
118  return (mControlSender->hookUserSetMainSourceSoundProperty(sourceID, soundProperty));
119 }
120 
122 {
123  logInfo(__METHOD_NAME__,"type=", property.type, "systemPropertyValue=", property.value);
124  return (mControlSender->hookUserSetSystemProperty(property));
125 }
126 
128 {
129  return (mDatabaseHandler->getSinkMainVolume(sinkID, mainVolume));
130 }
131 
132 am_Error_e CAmCommandReceiver::getListMainConnections(std::vector<am_MainConnectionType_s> & listConnections) const
133 {
134  return (mDatabaseHandler->getListVisibleMainConnections(listConnections));
135 }
136 
137 am_Error_e CAmCommandReceiver::getListMainSinks(std::vector<am_SinkType_s>& listMainSinks) const
138 {
139  return (mDatabaseHandler->getListMainSinks(listMainSinks));
140 }
141 
142 am_Error_e CAmCommandReceiver::getListMainSources(std::vector<am_SourceType_s>& listMainSources) const
143 {
144  return (mDatabaseHandler->getListMainSources(listMainSources));
145 }
146 
147 am_Error_e CAmCommandReceiver::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s> & listSoundProperties) const
148 {
149  return (mDatabaseHandler->getListMainSinkSoundProperties(sinkID, listSoundProperties));
150 }
151 
152 am_Error_e CAmCommandReceiver::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s> & listSourceProperties) const
153 {
154  return (mDatabaseHandler->getListMainSourceSoundProperties(sourceID, listSourceProperties));
155 }
156 
157 am_Error_e CAmCommandReceiver::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
158 {
159  return (mDatabaseHandler->getListSourceClasses(listSourceClasses));
160 }
161 
162 am_Error_e CAmCommandReceiver::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
163 {
164  return (mDatabaseHandler->getListSinkClasses(listSinkClasses));
165 }
166 
167 am_Error_e CAmCommandReceiver::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
168 {
169  return (mDatabaseHandler->getListSystemProperties(listSystemProperties));
170 }
171 
173 {
174  return (mDatabaseHandler->getTimingInformation(mainConnectionID, delay));
175 }
176 
178 {
179 #ifdef WITH_DBUS_WRAPPER
180  dbusConnectionWrapper = mDBusWrapper;
181  return (E_OK);
182 #else
183  dbusConnectionWrapper = NULL;
184  return (E_UNKNOWN);
185 #endif /*WITH_DBUS_WRAPPER*/
186 }
187 
189 {
190  socketHandler = mSocketHandler;
191  return (E_OK);
192 }
193 
194 void CAmCommandReceiver::getInterfaceVersion(std::string & version) const
195 {
196  version = CommandVersion;
197 }
198 
199 void CAmCommandReceiver::confirmCommandReady(const uint16_t handle, const am_Error_e error)
200 {
201  if (error !=E_OK)
202  mLastErrorStartup=error;
203  mListStartupHandles.erase(std::remove(mListStartupHandles.begin(), mListStartupHandles.end(), handle), mListStartupHandles.end());
204  if (mWaitStartup && mListStartupHandles.empty())
205  mControlSender->confirmCommandReady(mLastErrorStartup);
206 }
207 
208 void CAmCommandReceiver::confirmCommandRundown(const uint16_t handle, const am_Error_e error)
209 {
210  if (error !=E_OK)
211  mLastErrorRundown=error;
212  mListRundownHandles.erase(std::remove(mListRundownHandles.begin(), mListRundownHandles.end(), handle), mListRundownHandles.end());
213  if (mWaitRundown && mListRundownHandles.empty())
214  mControlSender->confirmCommandRundown(mLastErrorRundown);
215 }
216 
218 {
219  uint16_t handle = ++handleCount; //todo: handle overflow
220  mListStartupHandles.push_back(handle);
221  return (handle);
222 }
223 
225 {
226  uint16_t handle = ++handleCount; //todo: handle overflow
227  mListRundownHandles.push_back(handle);
228  return (handle);
229 }
230 
232 {
233  mWaitStartup = startup;
234  mLastErrorStartup=E_OK;
235 }
236 
237 am_Error_e CAmCommandReceiver::getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector<am_NotificationConfiguration_s>& listMainNotificationConfigurations) const
238 {
239  return (mDatabaseHandler->getListMainSinkNotificationConfigurations(sinkID,listMainNotificationConfigurations));
240 }
241 
242 am_Error_e CAmCommandReceiver::getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector<am_NotificationConfiguration_s>& listMainNotificationConfigurations) const
243 {
244  return (mDatabaseHandler->getListMainSourceNotificationConfigurations(sourceID,listMainNotificationConfigurations));
245 }
246 
248 {
249  logInfo(__METHOD_NAME__,"sinkID=", sinkID, " type=",mainNotificationConfiguration.type, " parameter=", mainNotificationConfiguration.parameter, "status=",mainNotificationConfiguration.status);
250  return (mControlSender->hookUserSetMainSinkNotificationConfiguration(sinkID,mainNotificationConfiguration));
251 }
252 
254 {
255  logInfo(__METHOD_NAME__,"sourceID=", sourceID, " type=",mainNotificationConfiguration.type, " parameter=", mainNotificationConfiguration.parameter, "status=",mainNotificationConfiguration.status);
256  return (mControlSender->hookUserSetMainSourceNotificationConfiguration(sourceID,mainNotificationConfiguration));
257 }
258 
260 {
261  mWaitRundown = rundown;
262  mLastErrorStartup=E_OK;
263 }
264 
265 }
am_Error_e connect(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t &mainConnectionID)
connects a source to sink
uint16_t getRundownHandle()
returns a rundown handle
am_Error_e hookUserVolumeChange(const am_sinkID_t SinkID, const am_mainVolume_t newVolume)
#define CommandVersion
Definition: IAmCommand.h:37
A Common-API wrapper class, which loads the common-api runtime and instantiates all necessary objects...
am_Error_e setMainSourceNotificationConfiguration(const am_sourceID_t sourceID, const am_NotificationConfiguration_s &mainNotificationConfiguration)
sets a MainNotificationConfiuration.
am_CustomNotificationType_t type
The notification type of the notification.
am_Error_e
the errors of the audiomanager.
am_Error_e hookUserSetMainSinkSoundProperty(const am_sinkID_t sinkID, const am_MainSoundProperty_s &soundProperty)
This struct holds information about the configuration for notifications.
void logInfo(T value, TArgs...args)
logs given values with infolevel with the default context
void getInterfaceVersion(std::string &version) const
This function returns the version of the interface.
am_Error_e hookUserDisconnectionRequest(const am_mainConnectionID_t connectionID)
int16_t value
the actual value
virtual am_Error_e getListSourceClasses(std::vector< am_SourceClass_s > &listSourceClasses) const =0
void confirmCommandRundown(const uint16_t handle, const am_Error_e error)
asynchronous confirmation of setCommandRundown
am_Error_e getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t &delay) const
returns the delay in ms that the audiopath for the given mainConnection has
virtual am_Error_e getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector< am_MainSoundProperty_s > &listSourceProperties) const =0
The am::CAmSocketHandler implements a mainloop for the AudioManager.
am_Error_e hookUserSetSystemProperty(const am_SystemProperty_s &property)
virtual am_Error_e getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector< am_NotificationConfiguration_s > &listMainNotificationConfigurations)=0
void confirmCommandReady(const am_Error_e error)
int16_t am_timeSync_t
offset time that is introduced in milli seconds.
am_Error_e getDBusConnectionWrapper(CAmDbusWrapper *&dbusConnectionWrapper) const
this function is used to retrieve a pointer to the dBusConnectionWrapper
virtual am_Error_e getListMainSinks(std::vector< am_SinkType_s > &listMainSinks) const =0
am_Error_e getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector< am_NotificationConfiguration_s > &listMainNotificationConfigurations) const
Retrieves the list of MainNotifications for a source.
SPDX license identifier: MPL-2.0.
am_Error_e setMainSourceSoundProperty(const am_MainSoundProperty_s &soundProperty, const am_sourceID_t sourceID)
This method is used to set sound properties, e.g.
void confirmCommandReady(const uint16_t handle, const am_Error_e error)
asynchronous confirmation of setCommandReady.
am_Error_e getListMainSinks(std::vector< am_SinkType_s > &listMainSinks) const
returns the actual list of Sinks
struct describing system properties
void waitOnRundown(bool rundown)
tells the ComandReceiver to start waiting for all handles to be confirmed
SPDX license identifier: MPL-2.0.
am_Error_e getListSinkClasses(std::vector< am_SinkClass_s > &listSinkClasses) const
This is used to retrieve SinkClass Information of all sink classes.
am_Error_e setVolume(const am_sinkID_t sinkID, const am_mainVolume_t volume)
sets the volume for a sink
struct describung mainsound property
am_Error_e volumeStep(const am_sinkID_t sinkID, const int16_t volumeStep)
This function is used to increment or decrement the current volume for a sink.
am_Error_e hookUserSetMainSourceNotificationConfiguration(const am_sourceID_t sourceID, const am_NotificationConfiguration_s &notificationConfiguration)
virtual am_Error_e getListMainSources(std::vector< am_SourceType_s > &listMainSources) const =0
am_Error_e hookUserSetMainSinkNotificationConfiguration(const am_sinkID_t sinkID, const am_NotificationConfiguration_s &notificationConfiguration)
SPDX license identifier: MPL-2.0.
am_Error_e getListMainSources(std::vector< am_SourceType_s > &listMainSources) const
returns the actual list of Sources
am_Error_e setMainSinkNotificationConfiguration(const am_sinkID_t sinkID, const am_NotificationConfiguration_s &mainNotificationConfiguration)
sets a MainNotificationConfiuration.
uint16_t am_sourceID_t
a source ID
am_CustomMainSoundPropertyType_t type
the type of the property
am_CustomSystemPropertyType_t type
the type that is set
CAmCommandReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler)
am_Error_e hookUserSetSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState)
sends data to the commandInterface, takes the file of the library that needs to be loaded ...
am_NotificationStatus_e status
The Notification status.
am_Error_e hookUserConnectionRequest(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am_mainConnectionID_t &mainConnectionID)
This class handles and abstracts the database.
virtual am_Error_e getListSinkClasses(std::vector< am_SinkClass_s > &listSinkClasses) const =0
virtual am_Error_e getSinkMainVolume(const am_sinkID_t sinkID, am_mainVolume_t &mainVolume) const =0
am_Error_e hookUserSetMainSourceSoundProperty(const am_sourceID_t sourceID, const am_MainSoundProperty_s &soundProperty)
am_Error_e getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector< am_MainSoundProperty_s > &listSourceProperties) const
This is used to retrieve all source sound properties related to a source.
am_Error_e setSinkMuteState(const am_sinkID_t sinkID, const am_MuteState_e muteState)
sets the mute state of a sink
virtual am_Error_e getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector< am_MainSoundProperty_s > &listSoundProperties) const =0
void confirmCommandRundown(const am_Error_e error)
SPDX license identifier: MPL-2.0.
#define __METHOD_NAME__
virtual am_Error_e getListSystemProperties(std::vector< am_SystemProperty_s > &listSystemProperties) const =0
am_Error_e getListSystemProperties(std::vector< am_SystemProperty_s > &listSystemProperties) const
Retrieves a complete list of all systemProperties.
am_Error_e getSocketHandler(CAmSocketHandler *&socketHandler) const
This function returns the pointer to the socketHandler.
am_Error_e getListSourceClasses(std::vector< am_SourceClass_s > &listSourceClasses) const
This is used to retrieve SourceClass Information of all source classes.
void waitOnStartup(bool startup)
tells the ComandReceiver to start waiting for all handles to be confirmed
virtual am_Error_e getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector< am_NotificationConfiguration_s > &listMainNotificationConfigurations)=0
This wraps dbus and provides everything needed to anyone who wants to use dbus (including plugins)...
virtual am_Error_e getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t &delay) const =0
int16_t am_mainVolume_t
This is the volume presented on the command interface.
no error - positive reply
SPDX license identifier: MPL-2.0.
am_Error_e getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector< am_NotificationConfiguration_s > &listMainNotificationConfigurations) const
Retrieves the list of MainNotifications for a sink.
uint16_t getStartupHandle()
returns a startup handle
am_Error_e getVolume(const am_sinkID_t sinkID, am_mainVolume_t &mainVolume) const
Returns the current volume for the sink directly out of the database.
uint16_t am_sinkID_t
a sink ID
uint16_t am_mainConnectionID_t
a mainConnection ID
am_Error_e getListMainConnections(std::vector< am_MainConnectionType_s > &listConnections) const
returns the actual list of MainConnections
am_Error_e setMainSinkSoundProperty(const am_MainSoundProperty_s &soundProperty, const am_sinkID_t sinkID)
This method is used to set sound properties, e.g.
int16_t parameter
This gives additional information to the notification status.
am_Error_e disconnect(const am_mainConnectionID_t mainConnectionID)
disconnects a mainConnection
am_Error_e setSystemProperty(const am_SystemProperty_s &property)
is used to set a specific system property.
virtual am_Error_e getListVisibleMainConnections(std::vector< am_MainConnectionType_s > &listConnections) const =0
am_Error_e hookUserVolumeStep(const am_sinkID_t SinkID, const int16_t increment)
am_Error_e getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector< am_MainSoundProperty_s > &listSoundProperties) const
This is used to retrieve all source sound properties related to a source.