AudioManager  7.5.11
Native Application Runtime Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 namespace am
33 {
34 
36  mDatabaseHandler(iDatabaseHandler), //
37  mControlSender(iControlSender), //
38  mDBusWrapper(NULL), //
39  mSocketHandler(iSocketHandler), //
40  handleCount(0),//
41  mListStartupHandles(), //
42  mListRundownHandles(), //
43  mWaitStartup(false), //
44  mWaitRundown(false),
45  mLastErrorStartup(E_OK), //
46  mLastErrorRundown(E_OK) //
47 
48 {
49  assert(mDatabaseHandler!=NULL);
50  assert(mSocketHandler!=NULL);
51  assert(mControlSender!=NULL);
52 }
53 
54 CAmCommandReceiver::CAmCommandReceiver(IAmDatabaseHandler *iDatabaseHandler, CAmControlSender *iControlSender, CAmSocketHandler *iSocketHandler, CAmDbusWrapper *iDBusWrapper) :
55  mDatabaseHandler(iDatabaseHandler), //
56  mControlSender(iControlSender), //
57  mDBusWrapper(iDBusWrapper), //
58  mSocketHandler(iSocketHandler), //
59  handleCount(0),//
60  mListStartupHandles(), //
61  mListRundownHandles(), //
62  mWaitStartup(false), //
63  mWaitRundown(false), //
64  mLastErrorStartup(E_UNKNOWN), //
65  mLastErrorRundown(E_UNKNOWN)
66 {
67  assert(mDatabaseHandler!=NULL);
68  assert(mSocketHandler!=NULL);
69  assert(mControlSender!=NULL);
70  assert(mDBusWrapper!=NULL);
71 }
72 
74 {
75 }
76 
78 {
79  logInfo("CommandReceiver::connect got called, sourceID=", sourceID, "sinkID=", sinkID);
80  return (mControlSender->hookUserConnectionRequest(sourceID, sinkID, mainConnectionID));
81 }
82 
84 {
85  logInfo("CommandReceiver::disconnect got called, mainConnectionID=", mainConnectionID);
86  return (mControlSender->hookUserDisconnectionRequest(mainConnectionID));
87 }
88 
90 {
91  logInfo("CommandReceiver::setVolume got called, sinkID=", sinkID, "volume=", volume);
92  return (mControlSender->hookUserVolumeChange(sinkID, volume));
93 }
94 
95 am_Error_e CAmCommandReceiver::volumeStep(const am_sinkID_t sinkID, const int16_t volumeStep)
96 {
97  logInfo("CommandReceiver::volumeStep got called, sinkID=", sinkID, "volumeStep=", volumeStep);
98  return (mControlSender->hookUserVolumeStep(sinkID, volumeStep));
99 }
100 
102 {
103  logInfo("CommandReceiver::setSinkMuteState got called, sinkID=", sinkID, "muteState=", muteState);
104  return (mControlSender->hookUserSetSinkMuteState(sinkID, muteState));
105 }
106 
108 {
109  logInfo("CommandReceiver::setMainSinkSoundProperty got called, sinkID=", sinkID, "soundPropertyType=", soundProperty.type, "soundPropertyValue=", soundProperty.value);
110  return (mControlSender->hookUserSetMainSinkSoundProperty(sinkID, soundProperty));
111 }
112 
114 {
115  logInfo("CommandReceiver::setMainSourceSoundProperty got called, sourceID=", sourceID, "soundPropertyType=", soundProperty.type, "soundPropertyValue=", soundProperty.value);
116  return (mControlSender->hookUserSetMainSourceSoundProperty(sourceID, soundProperty));
117 }
118 
120 {
121  logInfo("CommandReceiver::setSystemProperty got called", "type=", property.type, "soundPropertyValue=", property.value);
122  return (mControlSender->hookUserSetSystemProperty(property));
123 }
124 
126 {
127  return (mDatabaseHandler->getSinkMainVolume(sinkID, mainVolume));
128 }
129 
130 am_Error_e CAmCommandReceiver::getListMainConnections(std::vector<am_MainConnectionType_s> & listConnections) const
131 {
132  return (mDatabaseHandler->getListVisibleMainConnections(listConnections));
133 
134 }
135 
136 am_Error_e CAmCommandReceiver::getListMainSinks(std::vector<am_SinkType_s>& listMainSinks) const
137 {
138  return (mDatabaseHandler->getListMainSinks(listMainSinks));
139 }
140 
141 am_Error_e CAmCommandReceiver::getListMainSources(std::vector<am_SourceType_s>& listMainSources) const
142 {
143  return (mDatabaseHandler->getListMainSources(listMainSources));
144 }
145 
146 am_Error_e CAmCommandReceiver::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s> & listSoundProperties) const
147 {
148  return (mDatabaseHandler->getListMainSinkSoundProperties(sinkID, listSoundProperties));
149 }
150 
151 am_Error_e CAmCommandReceiver::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s> & listSourceProperties) const
152 {
153  return (mDatabaseHandler->getListMainSourceSoundProperties(sourceID, listSourceProperties));
154 }
155 
156 am_Error_e CAmCommandReceiver::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
157 {
158  return (mDatabaseHandler->getListSourceClasses(listSourceClasses));
159 }
160 
161 am_Error_e CAmCommandReceiver::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
162 {
163  return (mDatabaseHandler->getListSinkClasses(listSinkClasses));
164 }
165 
166 am_Error_e CAmCommandReceiver::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
167 {
168  return (mDatabaseHandler->getListSystemProperties(listSystemProperties));
169 }
170 
172 {
173  return (mDatabaseHandler->getTimingInformation(mainConnectionID, delay));
174 }
175 
177 {
178 #ifdef WITH_DBUS_WRAPPER
179  dbusConnectionWrapper = mDBusWrapper;
180  return (E_OK);
181 #else
182  dbusConnectionWrapper = NULL;
183  return (E_UNKNOWN);
184 #endif /*WITH_DBUS_WRAPPER*/
185 }
186 
188 {
189  socketHandler = mSocketHandler;
190  return (E_OK);
191 }
192 
193 void CAmCommandReceiver::getInterfaceVersion(std::string & version) const
194 {
195  version = CommandVersion;
196 }
197 
198 void CAmCommandReceiver::confirmCommandReady(const uint16_t handle, const am_Error_e error)
199 {
200  if (error !=E_OK)
201  mLastErrorStartup=error;
202  mListStartupHandles.erase(std::remove(mListStartupHandles.begin(), mListStartupHandles.end(), handle), mListStartupHandles.end());
203  if (mWaitStartup && mListStartupHandles.empty())
204  mControlSender->confirmCommandReady(mLastErrorStartup);
205 }
206 
207 void CAmCommandReceiver::confirmCommandRundown(const uint16_t handle, const am_Error_e error)
208 {
209  if (error !=E_OK)
210  mLastErrorRundown=error;
211  mListRundownHandles.erase(std::remove(mListRundownHandles.begin(), mListRundownHandles.end(), handle), mListRundownHandles.end());
212  if (mWaitRundown && mListRundownHandles.empty())
213  mControlSender->confirmCommandRundown(mLastErrorRundown);
214 }
215 
217 {
218  uint16_t handle = ++handleCount; //todo: handle overflow
219  mListStartupHandles.push_back(handle);
220  return (handle);
221 }
222 
224 {
225  uint16_t handle = ++handleCount; //todo: handle overflow
226  mListRundownHandles.push_back(handle);
227  return (handle);
228 }
229 
231 {
232  mWaitStartup = startup;
233  mLastErrorStartup=E_OK;
234 }
235 
236 am_Error_e CAmCommandReceiver::getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector<am_NotificationConfiguration_s>& listMainNotificationConfigurations) const
237 {
238  return (mDatabaseHandler->getListMainSinkNotificationConfigurations(sinkID,listMainNotificationConfigurations));
239 }
240 
241 am_Error_e CAmCommandReceiver::getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector<am_NotificationConfiguration_s>& listMainNotificationConfigurations) const
242 {
243  return (mDatabaseHandler->getListMainSourceNotificationConfigurations(sourceID,listMainNotificationConfigurations));
244 }
245 
247 {
248  logInfo("CommandReceiver::setMainSinkNotificationConfiguration got called, sinkID=", sinkID, " type=",mainNotificationConfiguration.type, " parameter=", mainNotificationConfiguration.parameter, "status=",mainNotificationConfiguration.status);
249  return (mControlSender->hookUserSetMainSinkNotificationConfiguration(sinkID,mainNotificationConfiguration));
250 }
251 
253 {
254  logInfo("CommandReceiver::setMainSourceNotificationConfiguration got called, sourceID=", sourceID, " type=",mainNotificationConfiguration.type, " parameter=", mainNotificationConfiguration.parameter, "status=",mainNotificationConfiguration.status);
255  return (mControlSender->hookUserSetMainSourceNotificationConfiguration(sourceID,mainNotificationConfiguration));
256 }
257 
259 {
260  mWaitRundown = rundown;
261  mLastErrorStartup=E_OK;
262 }
263 
264 }
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
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.
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.