|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 /** |
|
19 @internalComponent |
|
20 */ |
|
21 #ifndef __MODULES_H__ |
|
22 #define __MODULES_H__ |
|
23 |
|
24 #include <e32std.h> |
|
25 #include <e32base.h> |
|
26 |
|
27 #include "timeout.h" // ...because inline StartWatchDog needs Start() from CModuleTimeout |
|
28 |
|
29 class CInterface; |
|
30 class CModuleManager; |
|
31 class CProtocolQoS; |
|
32 class CModuleSpec; |
|
33 |
|
34 // module data |
|
35 class CModuleData : public CBase |
|
36 { |
|
37 friend class CModuleManager; |
|
38 private: |
|
39 // CModuleData is "almost reference counted object". When the iRefCount==0, the |
|
40 // object is only present in CModuleManagers iModuleList (and a watchdog timer |
|
41 // is running for it's destruction. Delete can only be issued by self or by |
|
42 // CModuleManager. |
|
43 ~CModuleData(); |
|
44 public: |
|
45 static CModuleData* NewLC(const TDesC& aModuleName, TUint aProtocolId, TUint aTimeoutDelay, TDblQue<CModuleData>& aList); |
|
46 inline void Open(); |
|
47 void Close(); |
|
48 inline CModuleBase* Module(); |
|
49 inline void StartWatchDog(); |
|
50 |
|
51 public: |
|
52 CModuleBase* iModule; |
|
53 CProtocolFamilyBase* iFamily; |
|
54 TUint iProtocolId; |
|
55 TInt iRefCount; |
|
56 TUint iFlags; |
|
57 RLibrary iLib; |
|
58 #ifdef _LOG |
|
59 TProtocolName iName; // Store the module name for easy debugging. |
|
60 #endif |
|
61 |
|
62 protected: |
|
63 CModuleData(TUint aProtocolId, TUint aTimeoutDelay); |
|
64 void ConstructL(const TDesC& aModuleName); |
|
65 |
|
66 private: |
|
67 static TInt WatchDogCallBack(TAny* aProvider); |
|
68 CModuleTimeout *iTimeout; //?? only used for "shutdown watchdog" -- could try to avoid need of this? |
|
69 TUint iTimeoutDelay; |
|
70 TDblQueLink iLink; |
|
71 }; |
|
72 |
|
73 // inline methods |
|
74 inline void CModuleData::Open() |
|
75 { iRefCount++; }; |
|
76 |
|
77 inline CModuleBase* CModuleData::Module() |
|
78 { return iModule; }; |
|
79 |
|
80 inline void CModuleData::StartWatchDog() |
|
81 { iTimeout->Start(iTimeoutDelay); }; |
|
82 |
|
83 |
|
84 class RModule; |
|
85 |
|
86 // library loader |
|
87 class CModuleManager : public CBase |
|
88 { |
|
89 public: |
|
90 static CModuleManager* NewL(CProtocolQoS& aProtocol); |
|
91 ~CModuleManager(); |
|
92 |
|
93 RModule* LoadModuleL(CModuleSpec& aModuleSpec, CProtocolBase* aProtocol); |
|
94 RModule* LoadModuleL(CProtocolBase* aProtocol, const TDesC& aModuleName, TUint aProtocolId, CExtension* aData = NULL); |
|
95 RModule* OpenModuleL(TUint aProtocolId); |
|
96 TBool IsLoaded(TUint aProtocolId); |
|
97 void Unbind(CProtocolBase* aProtocol, TInt aId); |
|
98 |
|
99 protected: |
|
100 CModuleManager(CProtocolQoS& aProtocol); |
|
101 |
|
102 private: |
|
103 CModuleData* Lookup(TUint aProtocolId); |
|
104 inline CProtocolQoS& Protocol(); |
|
105 private: |
|
106 CProtocolQoS& iProtocol; |
|
107 TDblQue<CModuleData> iModuleList; |
|
108 }; |
|
109 |
|
110 // inline methods |
|
111 inline CProtocolQoS& CModuleManager::Protocol() |
|
112 { return iProtocol; } |
|
113 |
|
114 |
|
115 // A handle to CModuleBase. CFlowHook keeps a list of RModules |
|
116 class RModule |
|
117 { |
|
118 public: |
|
119 RModule(CModuleData& aModuleData); |
|
120 RModule(const RModule& aModule); |
|
121 ~RModule(); |
|
122 inline CModuleBase* Module(); |
|
123 inline TUint Flags() const; |
|
124 inline TUint ProtocolId() const; |
|
125 #ifdef _LOG |
|
126 inline const TDesC& Name() const; |
|
127 #endif |
|
128 private: |
|
129 CModuleData& iModuleData; |
|
130 }; |
|
131 |
|
132 // inline methods |
|
133 inline CModuleBase* RModule::Module() |
|
134 { return iModuleData.Module(); }; |
|
135 |
|
136 inline TUint RModule::Flags() const |
|
137 { return iModuleData.iFlags; }; |
|
138 |
|
139 inline TUint RModule::ProtocolId() const |
|
140 { return iModuleData.iProtocolId; }; |
|
141 |
|
142 #ifdef _LOG |
|
143 inline const TDesC& RModule::Name() const |
|
144 { return iModuleData.iName; } |
|
145 #endif |
|
146 |
|
147 #endif |