2 * RoutingReceiverAsyncShadow.cpp
4 * Created on: Dec 23, 2011
8 #include "RoutingReceiverAsyncShadow.h"
9 #include "DltContext.h"
11 #include <sys/socket.h>
12 #include <sys/ioctl.h>
21 pthread_mutex_t RoutingReceiverAsyncShadow::mMutex = PTHREAD_MUTEX_INITIALIZER;
24 RoutingReceiverAsyncShadow::RoutingReceiverAsyncShadow()
25 :asyncMsgReceive(this, &RoutingReceiverAsyncShadow::asyncMsgReceiver),
26 asyncDispatch(this, &RoutingReceiverAsyncShadow::asyncDispatcher),
27 asyncCheck(this, &RoutingReceiverAsyncShadow::asyncChecker),
29 mRoutingReceiveInterface(),
36 RoutingReceiverAsyncShadow::~RoutingReceiverAsyncShadow()
40 void RoutingReceiverAsyncShadow::ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)
43 //put the data in the queue:
46 temp.connectionID = connectionID;
48 //then we make a message out of it:
50 msg.msgID = MSG_ACKCONNECT;
51 msg.parameters.connect = temp;
52 //here we share data !
53 pthread_mutex_lock(&mMutex);
55 pthread_mutex_unlock(&mMutex);
57 //ok, fire the signal that data needs to be received !
58 if (write(mPipe[1], &msg.msgID, sizeof (msgID_e))==-1)
60 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::ackConnect write failed, error code:"),DLT_STRING(strerror(errno)));
64 void RoutingReceiverAsyncShadow::ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)
67 //put the data in the queue:
70 temp.connectionID = connectionID;
72 //then we make a message out of it:
74 msg.msgID = MSG_ACKDISCONNECT;
75 msg.parameters.connect = temp;
76 //here we share data !
77 pthread_mutex_lock(&mMutex);
79 pthread_mutex_unlock(&mMutex);
81 //ok, fire the signal that data needs to be received !
82 if (write(mPipe[1], &msg.msgID, sizeof (msgID_e))==-1)
84 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::ackDisconnect write failed, error code:"),DLT_STRING(strerror(errno)));
88 void RoutingReceiverAsyncShadow::ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)
91 //put the data in the queue:
96 //then we make a message out of it:
98 msg.msgID = MSG_ACKSETSINKVOLUMECHANGE;
99 msg.parameters.volume = temp;
100 //here we share data !
101 pthread_mutex_lock(&mMutex);
103 pthread_mutex_unlock(&mMutex);
105 //ok, fire the signal that data needs to be received !
106 if (write(mPipe[1], &msg.msgID, sizeof (msgID_e))==-1)
108 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::ackSetSinkVolumeChange write failed, error code:"),DLT_STRING(strerror(errno)));
112 void RoutingReceiverAsyncShadow::ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)
115 //put the data in the queue:
117 temp.handle = handle;
118 temp.volume = volume;
120 //then we make a message out of it:
122 msg.msgID = MSG_ACKSETSOURCEVOLUMECHANGE;
123 msg.parameters.volume = temp;
124 //here we share data !
125 pthread_mutex_lock(&mMutex);
127 pthread_mutex_unlock(&mMutex);
129 //ok, fire the signal that data needs to be received !
130 if (write(mPipe[1], &msg.msgID, sizeof (msgID_e))==-1)
132 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::ackSetSourceVolumeChange write failed, error code:"),DLT_STRING(strerror(errno)));
136 void RoutingReceiverAsyncShadow::ackSetSourceState(const am_Handle_s handle, const am_Error_e error)
139 //put the data in the queue:
141 temp.handle = handle;
143 //then we make a message out of it:
145 msg.msgID = MSG_ACKSETSOURCESTATE;
146 msg.parameters.handle = temp;
147 //here we share data !
148 pthread_mutex_lock(&mMutex);
150 pthread_mutex_unlock(&mMutex);
152 //ok, fire the signal that data needs to be received !
153 if (write(mPipe[1], &msg.msgID, sizeof (msgID_e))==-1)
155 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::ackSetSourceState write failed, error code:"),DLT_STRING(strerror(errno)));
159 void RoutingReceiverAsyncShadow::ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error)
162 //put the data in the queue:
164 temp.handle = handle;
166 //then we make a message out of it:
168 msg.msgID = MSG_ACKSETSINKSOUNDPROPERTY;
169 msg.parameters.handle = temp;
170 //here we share data !
171 pthread_mutex_lock(&mMutex);
173 pthread_mutex_unlock(&mMutex);
175 //ok, fire the signal that data needs to be received !
176 if (write(mPipe[1], &msg.msgID, sizeof (msgID_e))==-1)
178 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::ackSetSinkSoundProperty write failed, error code:"),DLT_STRING(strerror(errno)));
182 void RoutingReceiverAsyncShadow::ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error)
185 //put the data in the queue:
187 temp.handle = handle;
189 //then we make a message out of it:
191 msg.msgID = MSG_ACKSETSOURCESOUNDPROPERTY;
192 msg.parameters.handle = temp;
193 //here we share data !
194 pthread_mutex_lock(&mMutex);
196 pthread_mutex_unlock(&mMutex);
198 //ok, fire the signal that data needs to be received !
199 if (write(mPipe[1], &msg.msgID, sizeof (msgID_e))==-1)
201 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::ackSetSourceSoundProperty write failed, error code:"),DLT_STRING(strerror(errno)));
205 void RoutingReceiverAsyncShadow::ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error)
208 //put the data in the queue:
209 a_crossfading_s temp;
210 temp.handle = handle;
211 temp.hotSink=hotSink;
213 //then we make a message out of it:
215 msg.msgID = MSG_ACKCROSSFADING;
216 msg.parameters.crossfading = temp;
217 //here we share data !
218 pthread_mutex_lock(&mMutex);
220 pthread_mutex_unlock(&mMutex);
222 //ok, fire the signal that data needs to be received !
223 if (write(mPipe[1], &msg.msgID, sizeof (msgID_e))==-1)
225 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::ackCrossFading write failed, error code:"),DLT_STRING(strerror(errno)));
229 void RoutingReceiverAsyncShadow::ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume)
232 //put the data in the queue:
233 a_sourceVolumeTick_s temp;
234 temp.sourceID=sourceID;
235 temp.handle = handle;
236 temp.volume = volume;
237 //then we make a message out of it:
239 msg.msgID = MSG_ACKSOURCEVOLUMETICK;
240 msg.parameters.sourceVolumeTick = temp;
241 //here we share data !
242 pthread_mutex_lock(&mMutex);
244 pthread_mutex_unlock(&mMutex);
246 //ok, fire the signal that data needs to be received !
247 if (write(mPipe[1], &msg.msgID, sizeof (msgID_e))==-1)
249 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::ackSourceVolumeTick write failed, error code:"),DLT_STRING(strerror(errno)));
253 void RoutingReceiverAsyncShadow::ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume)
256 //put the data in the queue:
257 a_sinkVolumeTick_s temp;
259 temp.handle = handle;
260 temp.volume = volume;
261 //then we make a message out of it:
263 msg.msgID = MSG_ACKSINKVOLUMETICK;
264 msg.parameters.sinkVolumeTick = temp;
265 //here we share data !
266 pthread_mutex_lock(&mMutex);
268 pthread_mutex_unlock(&mMutex);
270 //ok, fire the signal that data needs to be received !
271 if (write(mPipe[1], &msg.msgID, sizeof (msgID_e))==-1)
273 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::ackSinkVolumeTick write failed, error code:"),DLT_STRING(strerror(errno)));
277 void RoutingReceiverAsyncShadow::hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)
280 //put the data in the queue:
281 a_interruptStatusChange_s temp;
282 temp.sourceID=sourceID;
283 temp.interruptState = interruptState;
285 //then we make a message out of it:
287 msg.msgID = MSG_HOOKINTERRUPTSTATUSCHANGE;
288 msg.parameters.interruptStatusChange = temp;
289 //here we share data !
290 pthread_mutex_lock(&mMutex);
292 pthread_mutex_unlock(&mMutex);
294 //ok, fire the signal that data needs to be received !
295 if (write(mPipe[1], &msg.msgID, sizeof (msgID_e))==-1)
297 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::hookInterruptStatusChange write failed, error code:"),DLT_STRING(strerror(errno)));
301 void RoutingReceiverAsyncShadow::hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s & availability)
304 //put the data in the queue:
305 a_sinkAvailability_s temp;
307 temp.availability = availability;
309 //then we make a message out of it:
311 msg.msgID = MSG_HOOKSINKAVAILABLITYSTATUSCHANGE;
312 msg.parameters.sinkAvailability = temp;
313 //here we share data !
314 pthread_mutex_lock(&mMutex);
316 pthread_mutex_unlock(&mMutex);
318 //ok, fire the signal that data needs to be received !
319 if (write(mPipe[1], &msg.msgID, sizeof (msgID_e))==-1)
321 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::hookSinkAvailablityStatusChange write failed, error code:"),DLT_STRING(strerror(errno)));
325 void RoutingReceiverAsyncShadow::hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s & availability)
328 //put the data in the queue:
329 a_sourceAvailability_s temp;
330 temp.sourceID=sourceID;
331 temp.availability = availability;
333 //then we make a message out of it:
335 msg.msgID = MSG_HOOKSOURCEAVAILABLITYSTATUSCHANGE;
336 msg.parameters.sourceAvailability = temp;
337 //here we share data !
338 pthread_mutex_lock(&mMutex);
340 pthread_mutex_unlock(&mMutex);
342 //ok, fire the signal that data needs to be received !
343 if (write(mPipe[1], &msg.msgID, sizeof (msgID_e))==-1)
345 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::hookSourceAvailablityStatusChange write failed, error code:"),DLT_STRING(strerror(errno)));
349 void RoutingReceiverAsyncShadow::hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState)
352 //put the data in the queue:
353 a_hookDomainStateChange_s temp;
354 temp.domainID=domainID;
355 temp.state = domainState;
357 //then we make a message out of it:
359 msg.msgID = MSG_HOOKDOMAINSTATECHANGE;
360 msg.parameters.domainStateChange = temp;
361 //here we share data !
362 pthread_mutex_lock(&mMutex);
364 pthread_mutex_unlock(&mMutex);
366 //ok, fire the signal that data needs to be received !
367 if (write(mPipe[1], &msg.msgID, sizeof (msgID_e))==-1)
369 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::hookDomainStateChange write failed, error code:"),DLT_STRING(strerror(errno)));
373 void RoutingReceiverAsyncShadow::hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay)
376 //put the data in the queue:
377 a_timingInfoChanged_s temp;
378 temp.connectionID=connectionID;
381 //then we make a message out of it:
383 msg.msgID = MSG_HOOKTIMINGINFORMATIONCHANGED;
384 msg.parameters.timingInfoChange = temp;
385 //here we share data !
386 pthread_mutex_lock(&mMutex);
388 pthread_mutex_unlock(&mMutex);
390 //ok, fire the signal that data needs to be received !
391 if (write(mPipe[1], &msg.msgID, sizeof (msgID_e))==-1)
393 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::hookTimingInformationChanged write failed, error code:"),DLT_STRING(strerror(errno)));
397 void RoutingReceiverAsyncShadow::asyncMsgReceiver(const pollfd pollfd, const sh_pollHandle_t handle, void *userData)
401 //it is no really important what to read here, we will read the queue later...
403 if(read(pollfd.fd, buffer, 10)==-1)
405 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::asyncMsgReceiver could not read!"));
409 bool RoutingReceiverAsyncShadow::asyncDispatcher(const sh_pollHandle_t handle, void *userData)
415 //ok, let's receive, first lock
416 pthread_mutex_lock(&mMutex);
417 msg = mQueue.front();
419 pthread_mutex_unlock(&mMutex);
421 //check for the message:
424 mRoutingReceiveInterface->ackConnect(msg.parameters.connect.handle, msg.parameters.connect.connectionID, msg.parameters.connect.error);
426 case MSG_ACKDISCONNECT:
427 mRoutingReceiveInterface->ackDisconnect(msg.parameters.connect.handle, msg.parameters.connect.connectionID, msg.parameters.connect.error);
429 case MSG_ACKSETSINKVOLUMECHANGE:
430 mRoutingReceiveInterface->ackSetSinkVolumeChange(msg.parameters.volume.handle, msg.parameters.volume.volume,msg.parameters.volume.error);
432 case MSG_ACKSETSOURCEVOLUMECHANGE:
433 mRoutingReceiveInterface->ackSetSourceVolumeChange(msg.parameters.volume.handle,msg.parameters.volume.volume,msg.parameters.volume.error);
435 case MSG_ACKSETSOURCESTATE:
436 mRoutingReceiveInterface->ackSetSourceState(msg.parameters.handle.handle,msg.parameters.handle.error);
438 case MSG_ACKSETSINKSOUNDPROPERTY:
439 mRoutingReceiveInterface->ackSetSinkSoundProperty(msg.parameters.handle.handle,msg.parameters.handle.error);
441 case MSG_ACKSETSOURCESOUNDPROPERTY:
442 mRoutingReceiveInterface->ackSetSourceSoundProperty(msg.parameters.handle.handle,msg.parameters.handle.error);
444 case MSG_ACKCROSSFADING:
445 mRoutingReceiveInterface->ackCrossFading(msg.parameters.crossfading.handle,msg.parameters.crossfading.hotSink,msg.parameters.crossfading.error);
447 case MSG_ACKSOURCEVOLUMETICK:
448 mRoutingReceiveInterface->ackSourceVolumeTick(msg.parameters.sourceVolumeTick.handle,msg.parameters.sourceVolumeTick.sourceID,msg.parameters.sourceVolumeTick.volume);
450 case MSG_ACKSINKVOLUMETICK:
451 mRoutingReceiveInterface->ackSinkVolumeTick(msg.parameters.sinkVolumeTick.handle,msg.parameters.sinkVolumeTick.sinkID,msg.parameters.sinkVolumeTick.volume);
453 case MSG_HOOKINTERRUPTSTATUSCHANGE:
454 mRoutingReceiveInterface->hookInterruptStatusChange(msg.parameters.interruptStatusChange.sourceID,msg.parameters.interruptStatusChange.interruptState);
456 case MSG_HOOKSINKAVAILABLITYSTATUSCHANGE:
457 mRoutingReceiveInterface->hookSinkAvailablityStatusChange(msg.parameters.sinkAvailability.sinkID,msg.parameters.sinkAvailability.availability);
459 case MSG_HOOKSOURCEAVAILABLITYSTATUSCHANGE:
460 mRoutingReceiveInterface->hookSourceAvailablityStatusChange(msg.parameters.sourceAvailability.sourceID,msg.parameters.sourceAvailability.availability);
462 case MSG_HOOKDOMAINSTATECHANGE:
463 mRoutingReceiveInterface->hookDomainStateChange(msg.parameters.domainStateChange.domainID,msg.parameters.domainStateChange.state);
465 case MSG_HOOKTIMINGINFORMATIONCHANGED:
466 mRoutingReceiveInterface->hookTimingInformationChanged(msg.parameters.timingInfoChange.connectionID,msg.parameters.timingInfoChange.delay);
469 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::asyncDispatcher unknown message was received:"),DLT_INT(msg.msgID));
474 pthread_mutex_lock(&mMutex);
475 if(mQueue.size() > 0) retVal=true;
476 pthread_mutex_unlock(&mMutex);
481 bool RoutingReceiverAsyncShadow::asyncChecker(const sh_pollHandle_t handle, void *userData)
485 bool returnVal=false;
486 pthread_mutex_lock(&mMutex);
487 if(mQueue.size() > 0) returnVal=true;
488 pthread_mutex_unlock(&mMutex);
492 am_Error_e RoutingReceiverAsyncShadow::setRoutingInterface(RoutingReceiveInterface *receiveInterface)
494 assert(receiveInterface!=0);
495 mRoutingReceiveInterface=receiveInterface;
496 mRoutingReceiveInterface->getSocketHandler(mSocketHandler);
499 DLT_LOG(PluginRoutingAsync, DLT_LOG_ERROR, DLT_STRING("RoutingReceiverAsyncShadow::setRoutingInterface could not create pipe!:"));
505 mSocketHandler->addFDPoll(mPipe[0],event,NULL,&asyncMsgReceive,&asyncCheck,&asyncDispatch,NULL,mHandle);