• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 
19 #ifndef PV_2WAY_PROXY_ADAPTER_H_INCLUDED
20 #define PV_2WAY_PROXY_ADAPTER_H_INCLUDED
21 
22 #ifndef PV_INTERFACE_PROXY_H_INCLUDED
23 #include "pv_interface_proxy.h"
24 #endif
25 
26 #ifndef PV_2WAY_INTERFACE_H_INCLUDED
27 #include "pv_2way_interface.h"
28 #endif
29 
30 #ifndef PV_2WAY_INTERFACE_CMD_MESSAGES_H_INCLUDED
31 #include "pv_2way_interface_cmd_messages.h"
32 #endif
33 
34 #ifndef PV_2WAY_ENGINE_H_INCLUDED
35 #include "pv_2way_engine.h"
36 #endif
37 
38 #ifndef OSCL_SHARED_PTR_H_INCLUDED
39 #include "oscl_shared_ptr.h"
40 #endif
41 
42 #ifndef OSCL_VECTOR_H_INCLUDED
43 #include "oscl_vector.h"
44 #endif
45 
46 #include "pv_engine_observer.h"
47 #include "pv_engine_observer_message.h"
48 
49 class PVLogger;
50 class PVMFNodeInterface;
51 
52 
53 class PVCmnCmdRespMsg : public CPVCmnInterfaceObserverMessage,
54         public PVCmdResponse
55 {
56     public:
PVCmnCmdRespMsg()57         PVCmnCmdRespMsg() : CPVCmnInterfaceObserverMessage(0),
58                 PVCmdResponse(0, (OsclAny*)NULL, PVMFSuccess, NULL, 0)
59         {};
60 
~PVCmnCmdRespMsg()61         ~PVCmnCmdRespMsg() {};
62 
63         void Set(PVCommandId aId,
64                  void *aContext,
65                  PVMFStatus aStatus,
66                  OsclAny* aEventData = NULL,
67                  int32 aEventDataSize = 0);
68 
SetId(PVCommandId aId)69         void SetId(PVCommandId aId)
70         {
71             iId = aId;
72         }
SetContextData(void * aContext)73         void SetContextData(void *aContext)
74         {
75             iContext = aContext;
76         }
77 };
78 
79 class PVCmnAsyncEventMsg : public CPVCmnInterfaceObserverMessage,
80         public PVAsyncInformationalEvent
81 {
82     public:
PVCmnAsyncEventMsg()83         PVCmnAsyncEventMsg() : CPVCmnInterfaceObserverMessage(1)
84                 , PVAsyncInformationalEvent(PVT_INDICATION_INCOMING_TRACK)
85         {};
86 
~PVCmnAsyncEventMsg()87         ~PVCmnAsyncEventMsg()
88         {
89             if (iEventExtInterface)
90             {
91                 iEventExtInterface->removeRef();
92                 iEventExtInterface = NULL;
93             }
94         };
95 
96         void Set(const PVAsyncInformationalEvent& aEvent, PVEventType aType,
97                  PVExclusivePtr aPtr,
98                  uint8 *aLocalBuffer,
99                  uint32 aLocalBufferSize);
100 };
101 
102 class PVCmnAsyncErrorEvent: public CPVCmnInterfaceObserverMessage,
103         public PVAsyncErrorEvent
104 {
105     public:
PVCmnAsyncErrorEvent()106         PVCmnAsyncErrorEvent() : CPVCmnInterfaceObserverMessage(2)
107                 , PVAsyncErrorEvent(0)
108         {};
109 
~PVCmnAsyncErrorEvent()110         ~PVCmnAsyncErrorEvent() {};
111 
112         void Set(PVEventType aEventType,
113                  PVExclusivePtr aEventData,
114                  uint8* aLocalBuffer,
115                  int32 aLocalBufferSize);
116 
117 };
118 
119 /**
120  * CPV2WayProxyAdapter Class
121  *
122  * CPV2WayProxyAdapter is the interface to the pv2way SDK, which
123  * allows initialization, control, and termination of a two-way terminal.
124  * The application is expected to contain and maintain a pointer to the
125  * CPV2WayInterface instance at all times that a call is active.
126  * The CPV2WayFactory factory class is to be used to create and
127  * delete instances of this class
128  **/
129 class CPV2WayProxyAdapter :
130         public CPV2WayInterface,
131         public PVProxiedEngine,
132         public PVCommandStatusObserver,
133         public PVInformationalEventObserver,
134         public PVErrorEventObserver,
135         public PVProxiedInterfaceClient,
136         public PVProxiedInterfaceServer
137 {
138     public:
139         static CPV2WayProxyAdapter* New(TPVTerminalType aTerminalType,
140                                         PVCommandStatusObserver* aCmdStatusObserver,
141                                         PVInformationalEventObserver *aInfoEventObserver,
142                                         PVErrorEventObserver *aErrorEventObserver);
143         ~CPV2WayProxyAdapter();
144 
145         // CPV2WayInterface virtuals
146         PVCommandId GetSDKInfo(PVSDKInfo &aSDKInfo, OsclAny* aContextData = NULL);
147         PVCommandId GetSDKModuleInfo(PVSDKModuleInfo &aSDKModuleInfo, OsclAny* aContextData = NULL);
148         PVCommandId Init(PV2WayInitInfo& aInitInfo, OsclAny* aContextData = NULL);
149         PVCommandId Reset(OsclAny* aContextData = NULL);
150         PVCommandId AddDataSource(PVTrackId aChannelId, PVMFNodeInterface& aDataSource, OsclAny* aContextData = NULL);
151         PVCommandId RemoveDataSource(PVMFNodeInterface& aDataSource, OsclAny* aContextData = NULL);
152         PVCommandId AddDataSink(PVTrackId aChannelId, PVMFNodeInterface& aDataSink, OsclAny* aContextData = NULL);
153         PVCommandId RemoveDataSink(PVMFNodeInterface& aDataSink, OsclAny* aContextData = NULL);
154         PVCommandId Connect(const PV2WayConnectOptions& aOptions, PVMFNodeInterface* aCommServer = NULL, OsclAny* aContextData = NULL);
155         PVCommandId Disconnect(OsclAny* aContextData = NULL);
156         PVCommandId GetState(PV2WayState& aState, OsclAny* aContextData = NULL);
157         PVCommandId SetLatencyQualityTradeoff(PVMFNodeInterface& aTrack, int32 aTradeoff, OsclAny* aContextData = NULL);
158         PVCommandId Pause(PV2WayDirection aDirection, PVTrackId aTrackId, OsclAny* aContextData = NULL);
159         PVCommandId Resume(PV2WayDirection aDirection, PVTrackId aTrackId, OsclAny* aContextData = NULL);
160         PVCommandId SetLogAppender(const char* aTag, OsclSharedPtr<PVLoggerAppender>& aAppender, OsclAny* aContextData = NULL);
161         PVCommandId RemoveLogAppender(const char* aTag, OsclSharedPtr<PVLoggerAppender>& aAppender, OsclAny* aContextData = NULL);
162         PVCommandId SetLogLevel(const char* aTag, int32 aLevel, bool aSetSubtree = false, OsclAny* aContextData = NULL);
163         PVCommandId GetLogLevel(const char* aTag, int32& aLogInfo, OsclAny* aContextData = NULL);
164         //PVCommandId SendUserInput(CPVUserInput& user_input, OsclAny* aContextData = NULL);
165         //PVCommandId GetCallStatistics(CPVCmn2WayStatistics& aStats, OsclAny* aContextData = NULL);
166         PVCommandId QueryInterface(const PVUuid& aUuid, PVInterface*& aInterfacePtr, OsclAny* aContext = NULL);
167         PVCommandId QueryUUID(const PvmfMimeString& aMimeType, Oscl_Vector<PVUuid, BasicAlloc>& aUuids,
168                               bool aExactUuidsOnly = false, OsclAny* aContextData = NULL);
169         PVCommandId CancelAllCommands(OsclAny* aContextData = NULL);
170 
171 
172         OSCL_IMPORT_REF void CreateAppenders(PVLogger *aLogger = NULL)
173         {
174             OSCL_UNUSED_ARG(aLogger);
175         };
176         OSCL_IMPORT_REF void CreateTerminal(PVLogger *aLogger = NULL);
177         OSCL_IMPORT_REF void DeleteTerminal(PVLogger *aLogger = NULL);
178         OSCL_IMPORT_REF void CleanupMessage(CPVCmnInterfaceCmdMessage *cmdMsg, PVLogger *aLogger = NULL);
179         OSCL_IMPORT_REF void CleanupNotification(CPVCmnInterfaceObserverMessage *obsMsg, PVLogger *aLogger = NULL);
180         OSCL_IMPORT_REF void ProcessNotification(CPVCmnInterfaceObserverMessage *aMsg, PVLogger *aLogger = NULL);
181         OSCL_IMPORT_REF void ProcessMessage(CPVCmnInterfaceCmdMessage *aMsg, PVLogger *aLogger = NULL);
182 
183         //from PVProxiedEngine
184         OSCL_IMPORT_REF void CreateLoggerAppenders();
185         OSCL_IMPORT_REF void PVThreadLogon(PVMainProxy &proxy);
186         OSCL_IMPORT_REF void PVThreadLogoff(PVMainProxy &proxy);
187 
188         //from PVProxiedInterfaceServer
189         OSCL_IMPORT_REF void HandleCommand(TPVProxyMsgId aMsgId, OsclAny* aMsg);
190         OSCL_IMPORT_REF void CleanupNotification(TPVProxyMsgId aId, OsclAny* aMsg);
191 
192         //from PVProxiedInterfaceClient
193         OSCL_IMPORT_REF void HandleNotification(TPVProxyMsgId aId, OsclAny* aMsg);
194         OSCL_IMPORT_REF void CleanupCommand(TPVProxyMsgId aId, OsclAny* aMsg);
195 
196         //from MPVErrorEventObserver
197         void HandleErrorEvent(const PVAsyncErrorEvent& aEvent);
198 
199         //from MPVInformationalEventObserver
200         void HandleInformationalEvent(const PVAsyncInformationalEvent& aEvent) ;
201 
202         //from MPVCommandStatusObserver
203         void CommandCompleted(const PVCmdResponse& aResponse) ;
204 
205     private:
CPV2WayProxyAdapter()206         CPV2WayProxyAdapter(): iCmdStatusObserver(NULL),
207                 iInfoEventObserver(NULL),
208                 iErrorEventObserver(NULL),
209                 iterminalType(PV_TERMINAL_TYPE_NONE),
210                 iterminalEngine(NULL),
211                 iLogger(NULL),
212                 iPVProxy(NULL)
213         {};
214 
215         OsclAny ConstructL(TPVTerminalType aTerminalType,
216                            PVCommandStatusObserver* aCmdStatusObserver,
217                            PVInformationalEventObserver *aInfoEventObserver,
218                            PVErrorEventObserver *aErrorEventObserver);
219 
220         PVCmnCmdRespMsg *GetCmdMsgL();
FreeCmdMsg(PVCmnCmdRespMsg * msg)221         void FreeCmdMsg(PVCmnCmdRespMsg *msg)
222         {
223             iFreeCmdMsg.push_back(msg);
224         }
225 
226         PVCmnAsyncEventMsg *GetEventMsgL();
FreeEventMsg(PVCmnAsyncEventMsg * msg)227         void FreeEventMsg(PVCmnAsyncEventMsg *msg)
228         {
229             iFreeEventMsg.push_back(msg);
230         }
231 
232         PVCmnAsyncErrorEvent *GetErrorMsgL();
FreeErrorMsg(PVCmnAsyncErrorEvent * msg)233         void FreeErrorMsg(PVCmnAsyncErrorEvent *msg)
234         {
235             iFreeErrorMsg.push_back(msg);
236         }
237 
238         static int Construct(CPV2WayProxyAdapter*& aRet,
239                              TPVTerminalType aTerminalType,
240                              PVCommandStatusObserver* aCmdStatusObserver,
241                              PVInformationalEventObserver *aInfoEventObserver,
242                              PVErrorEventObserver *aErrorEventObserver);
243 
244 
245         PVCommandStatusObserver *iCmdStatusObserver;
246         PVInformationalEventObserver *iInfoEventObserver;
247         PVErrorEventObserver *iErrorEventObserver;
248 
249         TPVTerminalType iterminalType;
250         CPV2WayInterface * iterminalEngine;
251 
252         PVLogger *iLogger;
253 
254         int ProcessMessageLTry(CPVCmnInterfaceCmdMessage *aMsg);
255         void ProcessMessageL(CPVCmnInterfaceCmdMessage *aMsg);
256         void ProcessNotificationL(CPVCmnInterfaceObserverMessage *aMsg);
257 
258         friend class CPV2WayInterfaceProxyHandler;
259         friend class CPV2WayInterfaceProxyNotifier;
260 
261         Oscl_Vector<PVCmnCmdRespMsg *, OsclMemAllocator> iFreeCmdMsg;
262         PVCmnCmdRespMsg iCmdMsg[MAX_PENDING_2WAY_COMMANDS];
263 
264         Oscl_Vector<PVCmnAsyncEventMsg *, OsclMemAllocator> iFreeEventMsg;
265         PVCmnAsyncEventMsg iEventMsg[MAX_PENDING_2WAY_EVENTS];
266 
267         Oscl_Vector<PVCmnAsyncErrorEvent *, OsclMemAllocator> iFreeErrorMsg;
268         PVCmnAsyncErrorEvent iErrorMsg[MAX_PENDING_2WAY_ERRORS];
269 
270         CPVInterfaceProxy *iPVProxy;
271         friend class CPV2WayFactory;
272         TPVProxyId iProxyId;
273 };
274 
275 #endif //
276 
277 
278