* assert on empty busname (routinginterface)
[profile/ivi/audiomanager.git] / PluginRoutingInterfaceAsync / include / RoutingReceiverAsyncShadow.h
1 /*
2  * RoutingReceiverAsyncShadow.h
3  *
4  *  Created on: Dec 23, 2011
5  *      Author: christian
6  */
7
8 #ifndef ROUTINGRECEIVERASYNCSHADOW_H_
9 #define ROUTINGRECEIVERASYNCSHADOW_H_
10
11 #include <routing/RoutingReceiveInterface.h>
12 #include <SocketHandler.h>
13 #include <pthread.h>
14 #include <queue>
15
16 namespace am {
17
18 /**
19  * Threadsafe shadow of the RoutingReceiverInterface
20  * Register and deregister Functions are sychronous so they do not show up here...
21  */
22 class RoutingReceiverAsyncShadow
23 {
24 public:
25         RoutingReceiverAsyncShadow();
26         virtual ~RoutingReceiverAsyncShadow();
27         void ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) ;
28         void ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error) ;
29         void ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) ;
30         void ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error) ;
31         void ackSetSourceState(const am_Handle_s handle, const am_Error_e error) ;
32         void ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error) ;
33         void ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error) ;
34         void ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error) ;
35         void ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume) ;
36         void ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) ;
37         void hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState) ;
38         void hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s& availability) ;
39         void hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s& availability) ;
40         void hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState) ;
41         void hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay) ;
42
43         am_Error_e setRoutingInterface(RoutingReceiveInterface *receiveInterface);
44         void asyncMsgReceiver(const pollfd pollfd,const sh_pollHandle_t handle, void* userData);
45         bool asyncDispatcher(const sh_pollHandle_t handle, void* userData);
46         bool asyncChecker(const sh_pollHandle_t handle, void* userData);
47
48         shPollFired_T<RoutingReceiverAsyncShadow> asyncMsgReceive;
49         shPollDispatch_T<RoutingReceiverAsyncShadow> asyncDispatch;
50         shPollCheck_T<RoutingReceiverAsyncShadow> asyncCheck;
51
52 private:
53         enum msgID_e
54         {
55                 MSG_ACKCONNECT,
56                 MSG_ACKDISCONNECT,
57                 MSG_ACKSETSINKVOLUMECHANGE,
58                 MSG_ACKSETSOURCEVOLUMECHANGE,
59                 MSG_ACKSETSOURCESTATE,
60                 MSG_ACKSETSINKSOUNDPROPERTY,
61                 MSG_ACKSETSOURCESOUNDPROPERTY,
62                 MSG_ACKCROSSFADING,
63                 MSG_ACKSOURCEVOLUMETICK,
64                 MSG_ACKSINKVOLUMETICK,
65                 MSG_HOOKINTERRUPTSTATUSCHANGE,
66                 MSG_HOOKSINKAVAILABLITYSTATUSCHANGE,
67                 MSG_HOOKSOURCEAVAILABLITYSTATUSCHANGE,
68                 MSG_HOOKDOMAINSTATECHANGE,
69                 MSG_HOOKTIMINGINFORMATIONCHANGED
70         };
71
72         struct a_connect_s
73         {
74                 am_Handle_s handle;
75                 am_connectionID_t connectionID;
76                 am_Error_e error;
77         };
78
79         struct a_volume_s
80         {
81                 am_Handle_s handle;
82                 am_volume_t volume;
83                 am_Error_e error;
84         };
85
86         struct a_handle_s
87         {
88                 am_Handle_s handle;
89                 am_Error_e error;
90         };
91
92         struct a_crossfading_s
93         {
94                 am_Handle_s handle;
95                 am_HotSink_e hotSink;
96                 am_Error_e error;
97         };
98
99         struct a_sourceVolumeTick_s
100         {
101                 am_sourceID_t sourceID;
102                 am_Handle_s handle;
103                 am_volume_t volume;
104         };
105
106         struct a_sinkVolumeTick_s
107         {
108                 am_sinkID_t sinkID;
109                 am_Handle_s handle;
110                 am_volume_t volume;
111         };
112
113         struct a_interruptStatusChange_s
114         {
115                 am_sourceID_t sourceID;
116                 am_InterruptState_e interruptState;
117         };
118
119         struct a_sinkAvailability_s
120         {
121                 am_sinkID_t sinkID;
122                 am_Availability_s availability;
123         };
124
125         struct a_sourceAvailability_s
126         {
127                 am_sourceID_t sourceID;
128                 am_Availability_s availability;
129         };
130
131         struct a_hookDomainStateChange_s
132         {
133                 am_domainID_t domainID;
134                 am_DomainState_e state;
135         };
136
137         struct a_timingInfoChanged_s
138         {
139                 am_connectionID_t connectionID;
140                 am_timeSync_t delay;
141         };
142
143         union parameter_u
144         {
145                 a_connect_s connect;
146                 a_volume_s volume;
147                 a_handle_s handle;
148                 a_crossfading_s crossfading;
149                 a_sourceVolumeTick_s sourceVolumeTick;
150                 a_sinkVolumeTick_s sinkVolumeTick;
151                 a_interruptStatusChange_s interruptStatusChange;
152                 a_sinkAvailability_s sinkAvailability;
153                 a_sourceAvailability_s sourceAvailability;
154                 a_hookDomainStateChange_s domainStateChange;
155                 a_timingInfoChanged_s timingInfoChange;
156         };
157
158         struct msg_s
159         {
160                 msgID_e msgID;
161                 parameter_u parameters;
162         };
163
164         SocketHandler *mSocketHandler;
165         RoutingReceiveInterface *mRoutingReceiveInterface;
166         std::queue<msg_s> mQueue;
167         static pthread_mutex_t mMutex;
168         sh_pollHandle_t mHandle;
169         int mPipe[2];
170 };
171
172 } /* namespace am */
173 #endif /* ROUTINGRECEIVERASYNCSHADOW_H_ */