• 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 /** \file pv_interface_proxy.h
19     \brief Main include file for PV Proxy Implementation.
20 */
21 
22 
23 #ifndef PV_OMX_INTERFACE_PROXY_H_INCLUDED
24 #define PV_OMX_INTERFACE_PROXY_H_INCLUDED
25 
26 
27 #ifndef OSCL_MEM_H_INCLUDED
28 #include "oscl_mem.h"
29 #endif
30 #ifndef OSCL_VECTOR_H_INCLUDED
31 #include "oscl_vector.h"
32 #endif
33 #ifndef PV_OMX_PROXIED_INTERFACE_H_INCLUDED
34 #include "pv_omx_proxied_interface.h"
35 #endif
36 #ifndef OSCL_SCHEDULER_H_INCLUDED
37 #include "oscl_scheduler.h"
38 #endif
39 #ifndef OSCL_MUTEX_H_INCLUDED
40 #include "oscl_mutex.h"
41 #endif
42 #ifndef OSCL_SEMAPHORE_H_INCLUDED
43 #include "oscl_semaphore.h"
44 #endif
45 #ifndef OMX_PROXY_VECTOR_H_INCLUDED
46 #include "omx_proxy_vector.h"
47 #endif
48 
49 #ifndef PV_OMXDEFS_H_INCLUDED
50 #include "pv_omxdefs.h"
51 #endif
52 
53 #if PROXY_INTERFACE
54 
55 class CPVInterfaceProxyHandler_OMX;
56 class CPVInterfaceProxyNotifier_OMX;
57 class OsclExecScheduler;
58 class PVLogger;
59 class Oscl_DefAlloc;
60 /**
61 //list element for the proxy message queues.
62 */
63 
64 class CPVProxyMsg_OMX
65 {
66     public:
CPVProxyMsg_OMX(TPVProxyId id,TPVProxyMsgId MsgId,TPVCommandId cmdid,OsclAny * msg)67         CPVProxyMsg_OMX(TPVProxyId id, TPVProxyMsgId MsgId, TPVCommandId cmdid, OsclAny *msg)
68                 : iProxyId(id), iMsgId(MsgId), iCmdId(cmdid), iMsg(msg)
69         {}
~CPVProxyMsg_OMX()70         ~CPVProxyMsg_OMX()
71         {}
72         TPVProxyId iProxyId;
73         TPVProxyMsgId iMsgId;
74         TPVCommandId  iCmdId;
75         OsclAny *iMsg;
76 };
77 
78 /**
79 //list element for the proxy interface list
80 */
81 class CPVProxyInterface_OMX
82 {
83     public:
CPVProxyInterface_OMX(TPVProxyId a,PVProxiedInterfaceServer_OMX * b,PVProxiedInterfaceClient_OMX * c)84         CPVProxyInterface_OMX(TPVProxyId a, PVProxiedInterfaceServer_OMX* b, PVProxiedInterfaceClient_OMX* c): iProxyId(a), iServer(b), iClient(c)
85         {}
~CPVProxyInterface_OMX()86         ~CPVProxyInterface_OMX()
87         {}
88         TPVProxyId iProxyId;
89         PVProxiedInterfaceServer_OMX *iServer;
90         PVProxiedInterfaceClient_OMX *iClient;
91 };
92 
93 
94 const int32 PVPROXY_DEFAULT_STACK_SIZE = 0x2000;
95 
96 /**
97 ** Implementation of PVMainProxy
98 */
99 class CPVInterfaceProxy_OMX: public PVMainProxy_OMX
100 {
101     public:
102         /**
103         ** Create the proxy.
104         ** @param app: the engine to create under the PV thread.
105         ** @param alloc: optional memory allocator.  If null, a default
106         **    allocator will be used.
107         ** @param stacksize: optional stacksize for the PV thread.
108         ** @param nreserveInterfaceList: optional reserve size for
109         **    the interface list-- to prevent dynamic allocation
110         **    in calls to RegisterProxiedInterfaceL.
111         ** @param nreserveMessageLists: optional reserve sizes for
112         **    the command and notification queues-- to prevent
113         **    dynamic allocation by SendCommandL and SendNotificationL
114         ** @param handlerPri: priority of the command handler active
115         **    object (in the PV thread).
116         ** @param notifierPri: priority of the notifier handler active
117         **    object in the app thread-- if there is one.
118         */
119         OSCL_IMPORT_REF static CPVInterfaceProxy_OMX * NewL(
120             PVProxiedEngine_OMX& app
121             , Oscl_DefAlloc *alloc = NULL
122                                      , int32 stacksize = PVPROXY_DEFAULT_STACK_SIZE
123                                                          , uint32 nreserveInterfaceList = 20
124                                                                                           , uint32 nreserveMessageLists = 20
125                                                                                                                           , int32 handlerPri = OsclActiveObject::EPriorityNominal + 1
126                                                                                                                                                , int32 notifierPri = OsclActiveObject::EPriorityNominal + 1
127         );
128 
129         /**
130         ** Cleanup API.  This call will stop the PV thread if needed
131         ** and then delete the object.  This call differs from the
132         ** destructor only in that it uses the chosen memory allocator
133         ** to delete the memory.
134         */
135         OSCL_IMPORT_REF void Delete();
136 
137         //From PVMainProxy
138         OSCL_IMPORT_REF TPVProxyId RegisterProxiedInterface(
139             PVProxiedInterfaceServer_OMX& server_proxy,
140             PVProxiedInterfaceClient_OMX& client_proxy) ;
141         OSCL_IMPORT_REF void UnregisterProxiedInterface(TPVProxyId aProxyId) ;
142         OSCL_IMPORT_REF TPVProxyMsgId SendCommand(TPVProxyId aProxyId, TPVCommandId cmdid, OsclAny *aCmd);
143         OSCL_IMPORT_REF void CancelCommand(TPVProxyId aProxyId, TPVProxyMsgId aMsgId);
144         OSCL_IMPORT_REF void CancelAllCommands(TPVProxyId aProxyId);
145         OSCL_IMPORT_REF TPVProxyMsgId SendNotification(TPVProxyId aProxyId, OsclAny *aResp);
146         OSCL_IMPORT_REF void CancelNotification(TPVProxyId aProxyId, TPVProxyMsgId aMsgId);
147         OSCL_IMPORT_REF void CancelAllNotifications(TPVProxyId aProxyId);
148         OSCL_IMPORT_REF void StopPVThread();
149         OSCL_IMPORT_REF bool StartPVThread();
150         OSCL_IMPORT_REF void DeliverNotifications(int32 aCount, int32& aNoticesPending);
151 
152     protected:
153         CPVInterfaceProxy_OMX(PVProxiedEngine_OMX&, Oscl_DefAlloc*, int32);
154         //Changed return type to use a different fail mechanism
155         bool ConstructL(uint32, uint32, int32, int32);
156         virtual ~CPVInterfaceProxy_OMX();
157 
158         //PV Thread stuff..
159         PVThreadContext iPVThreadContext;
160         int32 iStacksize;
161         OsclExecScheduler *iPVScheduler;
162         PVLogger *iLogger;
163         OsclSemaphore iThreadCreatedSem;
164         bool iOMXThreadCreated;
165         void InThread();
166         OsclThread iPVThread;
167 
168         //The handler and notfier AOs.
169         CPVInterfaceProxyHandler_OMX *iHandler;
170         CPVInterfaceProxyNotifier_OMX *iNotifier;
171 
172         OsclSemaphore iInitSem;
173         bool iStopped;
174         OsclSemaphore iExitedSem;
175 
176         //proxy Id counter
177         int32 iProxyIdCounter;
178 
179         //command Id counter
180         OsclMutex iCounterCrit;
181         int32 iCommandIdCounter;
182 
183         //the proxy list
184         OsclMutex iProxyListCrit;
185         //Wrote a new vector class & template class
186         Oscl_Vector_New<CPVProxyInterface_OMX, Oscl_Vector_Allocator> iProxyList;
187         CPVProxyInterface_OMX* FindInterface(TPVProxyId aId, bool locked = false);
188         void CleanupInterfaceMessages(CPVProxyInterface_OMX *aExt);
189 
190         //Note: The message queues need to be thread safe and therefore
191         //must use a basic allocator that does not use the PV memory management.
192 
193         //The message queues-- handler side
194         OsclMutex iHandlerQueueCrit;
195 
196         //Wrote a new oscl_vector class & its memory template class
197         Oscl_Vector_New<CPVProxyMsg_OMX, Oscl_Vector_Allocator> iCommandQueue;
198 
199         //The message queues-- notifier side
200         OsclMutex iNotifierQueueCrit;
201         Oscl_Vector<CPVProxyMsg_OMX, OsclMemAllocator> iNotificationQueue;
202 
203         void CleanupAppThreadQueues();
204         void CleanupPVThreadQueues();
205         void CleanupNotifications(CPVProxyInterface_OMX *aExt, bool aAll, TPVProxyMsgId aMsgId = 0);
206         void CleanupCommands(CPVProxyInterface_OMX *aExt, bool aAll, TPVProxyMsgId aMsgId = 0);
207 
208         /* iDefAlloc is static because we need it to still be valid after ~CPVInterfaceProxy_OMX is called */
209         static _OsclBasicAllocator iDefAlloc;
210         Oscl_DefAlloc *iAlloc;
211 
212         PVProxiedEngine_OMX &iPVApp;
213 
214         friend class CPVInterfaceProxyHandler_OMX;
215         friend class CPVInterfaceProxyNotifier_OMX;
216         friend TOsclThreadFuncRet OSCL_THREAD_DECL pvproxythreadmain_omx(TOsclThreadFuncArg *aPtr);
217 };
218 #endif // PROXY_INTERFACE
219 #endif //
220 
221 
222