• 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_INTERFACE_PROXY_H_INCLUDED
24 #define PV_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_PROXIED_INTERFACE_H_INCLUDED
34 #include "pv_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 
46 class CPVInterfaceProxyHandler;
47 class CPVInterfaceProxyNotifier;
48 class OsclExecScheduler;
49 class PVLogger;
50 class Oscl_DefAlloc;
51 
52 
53 /**
54 //list element for the proxy message queues.
55 */
56 class CPVProxyMsg
57 {
58     public:
CPVProxyMsg(TPVProxyId id,TPVProxyMsgId MsgId,OsclAny * msg)59         CPVProxyMsg(TPVProxyId id, TPVProxyMsgId MsgId, OsclAny *msg)
60                 : iProxyId(id), iMsgId(MsgId), iMsg(msg)
61         {}
~CPVProxyMsg()62         ~CPVProxyMsg()
63         {}
64         TPVProxyId iProxyId;
65         TPVProxyMsgId iMsgId;
66         OsclAny *iMsg;
67 };
68 
69 /**
70 //list element for the proxy interface list
71 */
72 class CPVProxyInterface
73 {
74     public:
CPVProxyInterface(TPVProxyId a,PVProxiedInterfaceServer * b,PVProxiedInterfaceClient * c)75         CPVProxyInterface(TPVProxyId a, PVProxiedInterfaceServer* b, PVProxiedInterfaceClient* c): iProxyId(a), iServer(b), iClient(c)
76         {}
~CPVProxyInterface()77         ~CPVProxyInterface()
78         {}
79         TPVProxyId iProxyId;
80         PVProxiedInterfaceServer *iServer;
81         PVProxiedInterfaceClient *iClient;
82 };
83 
84 const int32 PVPROXY_DEFAULT_STACK_SIZE = 0x2000;
85 
86 
87 /**
88 ** Implementation of PVMainProxy
89 */
90 class CPVInterfaceProxy: public PVMainProxy
91 {
92     public:
93         /**
94         ** Create the proxy.
95         ** @param app: the engine to create under the PV thread.
96         ** @param alloc: optional memory allocator.  If null, a default
97         **    allocator will be used.
98         ** @param stacksize: optional stacksize for the PV thread.
99         ** @param nreserveInterfaceList: optional reserve size for
100         **    the interface list-- to prevent dynamic allocation
101         **    in calls to RegisterProxiedInterfaceL.
102         ** @param nreserveMessageLists: optional reserve sizes for
103         **    the command and notification queues-- to prevent
104         **    dynamic allocation by SendCommandL and SendNotificationL
105         ** @param handlerPri: priority of the command handler active
106         **    object (in the PV thread).
107         ** @param notifierPri: priority of the notifier handler active
108         **    object in the app thread-- if there is one.
109         */
110         OSCL_IMPORT_REF static CPVInterfaceProxy * NewL(
111             PVProxiedEngine& app
112             , Oscl_DefAlloc *alloc = NULL
113                                      , int32 stacksize = PVPROXY_DEFAULT_STACK_SIZE
114                                                          , uint32 nreserveInterfaceList = 20
115                                                                                           , uint32 nreserveMessageLists = 20
116                                                                                                                           , int32 handlerPri = OsclActiveObject::EPriorityNominal + 1
117                                                                                                                                                , int32 notifierPri = OsclActiveObject::EPriorityNominal + 1
118         );
119 
120         /**
121         ** Cleanup API.  This call will stop the PV thread if needed
122         ** and then delete the object.  This call differs from the
123         ** destructor only in that it uses the chosen memory allocator
124         ** to delete the memory.
125         */
126         OSCL_IMPORT_REF void Delete();
127 
128         //From PVMainProxy
129         OSCL_IMPORT_REF TPVProxyId RegisterProxiedInterface(
130             PVProxiedInterfaceServer& server_proxy,
131             PVProxiedInterfaceClient& client_proxy) ;
132         OSCL_IMPORT_REF void UnregisterProxiedInterface(TPVProxyId aProxyId) ;
133         OSCL_IMPORT_REF TPVProxyMsgId SendCommand(TPVProxyId aProxyId, OsclAny *aCmd);
134         OSCL_IMPORT_REF void CancelCommand(TPVProxyId aProxyId, TPVProxyMsgId aMsgId);
135         OSCL_IMPORT_REF void CancelAllCommands(TPVProxyId aProxyId);
136         OSCL_IMPORT_REF TPVProxyMsgId SendNotification(TPVProxyId aProxyId, OsclAny *aResp);
137         OSCL_IMPORT_REF void CancelNotification(TPVProxyId aProxyId, TPVProxyMsgId aMsgId);
138         OSCL_IMPORT_REF void CancelAllNotifications(TPVProxyId aProxyId);
139         OSCL_IMPORT_REF void StopPVThread();
140         OSCL_IMPORT_REF bool StartPVThread();
141         OSCL_IMPORT_REF void DeliverNotifications(int32 aCount, int32& aNoticesPending);
142 
143     protected:
144         int32 AppThreadLogon();
145         int32 AppThreadLogoff();
146         int32 AppStartScheduler();
147         int32 CPVIConstructL(uint32&, uint32&, int32&, int32&);
148         OSCL_IMPORT_REF CPVInterfaceProxy(PVProxiedEngine&, Oscl_DefAlloc*, int32);
149         OSCL_IMPORT_REF void ConstructL(uint32, uint32, int32, int32);
150         OSCL_IMPORT_REF virtual ~CPVInterfaceProxy();
151 
152         //PV Thread stuff..
153         PVThreadContext iPVThreadContext;
154         int32 iStacksize;
155         OsclExecScheduler *iPVScheduler;
156         PVLogger *iLogger;
157         void InThread();
158         OsclThread iPVThread;
159 
160         //The handler and notfier AOs.
161         CPVInterfaceProxyHandler *iHandler;
162         CPVInterfaceProxyNotifier *iNotifier;
163 
164         OsclSemaphore iInitSem;
165         bool iStopped;
166         OsclSemaphore iExitedSem;
167 
168         //proxy Id counter
169         int32 iProxyIdCounter;
170 
171         //command Id counter
172         OsclNoYieldMutex iCounterCrit;
173         int32 iCommandIdCounter;
174 
175         //the proxy list
176         OsclNoYieldMutex iProxyListCrit;
177         Oscl_Vector<CPVProxyInterface, OsclMemAllocator> iProxyList;
178         CPVProxyInterface* FindInterface(TPVProxyId aId, bool locked = false);
179         void CleanupInterfaceMessages(CPVProxyInterface *aExt);
180 
181         //Note: The message queues need to be thread safe and therefore
182         //must use a basic allocator that does not use the PV memory management.
183 
184         //The message queues-- handler side
185         OsclNoYieldMutex iHandlerQueueCrit;
186         Oscl_Vector<CPVProxyMsg, OsclMemAllocator> iCommandQueue;
187 
188         //The message queues-- notifier side
189         OsclNoYieldMutex iNotifierQueueCrit;
190         Oscl_Vector<CPVProxyMsg, OsclMemAllocator> iNotificationQueue;
191 
192         void CleanupAppThreadQueues();
193         void CleanupPVThreadQueues();
194         void CleanupNotifications(CPVProxyInterface *aExt, bool aAll, TPVProxyMsgId aMsgId = 0);
195         void CleanupCommands(CPVProxyInterface *aExt, bool aAll, TPVProxyMsgId aMsgId = 0);
196 
197         OsclMemAllocator iDefAlloc;
198         Oscl_DefAlloc *iAlloc;
199 
200         PVProxiedEngine &iPVApp;
201 
202         friend class CPVInterfaceProxyHandler;
203         friend class CPVInterfaceProxyNotifier;
204         friend TOsclThreadFuncRet OSCL_THREAD_DECL pvproxythreadmain(TOsclThreadFuncArg *aPtr);
205 };
206 
207 #endif //
208 
209 
210