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