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