author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2007-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 the License "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 |
// e32\include\drivers\resourcecontrol.inl |
|
15 |
// |
|
16 |
// WARNING: This file contains some APIs which are internal and are subject |
|
17 |
// to change without noticed. Such APIs should therefore not be used |
|
18 |
// outside the Kernel and Hardware Services package. |
|
19 |
// |
|
20 |
||
21 |
/* The Driver's Version */ |
|
22 |
inline TVersion DResConPddFactory::VersionRequired() |
|
23 |
{ |
|
24 |
const TInt KResConMajorVersionNumber=1; |
|
25 |
const TInt KResConMinorVersionNumber=0; |
|
26 |
const TInt KResConBuildVersionNumber=KE32BuildVersionNumber; |
|
27 |
return TVersion(KResConMajorVersionNumber,KResConMinorVersionNumber,KResConBuildVersionNumber); |
|
28 |
} |
|
29 |
||
30 |
/** Second stage constructor |
|
31 |
Allocates the specified size in kernel heap and creates a virtual link */ |
|
32 |
template <class T> |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
33 |
inline TInt DResourceCon<T>::Initialise(TInt aInitialSize) |
0 | 34 |
{ |
35 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DResourceCon<T>::Initialise")); |
|
36 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("aInitialSize %d", aInitialSize)); |
|
37 |
//Allocate memory for size specified. |
|
38 |
if(aInitialSize != 0) |
|
39 |
{ |
|
40 |
iArray = (T**) new (T*[aInitialSize]); |
|
41 |
if((!iArray)) |
|
42 |
{ |
|
43 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("No Sufficient memory for iArray allocation")); |
|
44 |
return KErrNoMemory; |
|
45 |
} |
|
46 |
//Create a virtual link by storing in each array position the index of next higher free location |
|
47 |
for(TInt c = 0; c < aInitialSize; c++) |
|
48 |
iArray[c] = (T*)(c+1); |
|
49 |
} |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
50 |
iAllocated = (TUint16)aInitialSize; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
51 |
iGrowBy = (TUint16) (aInitialSize < 2 ? aInitialSize : aInitialSize/2); |
0 | 52 |
iCount = 0; |
53 |
iInstanceCount = 0; |
|
54 |
iFreeLoc = 0; |
|
55 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DResourceCon<T>::Initialise")); |
|
56 |
#ifdef PRM_INSTRUMENTATION_MACRO |
|
57 |
if(aInitialSize) |
|
58 |
{ |
|
59 |
TUint size = aInitialSize * 4; |
|
60 |
PRM_MEMORY_USAGE_TRACE |
|
61 |
} |
|
62 |
#endif |
|
63 |
return KErrNone; |
|
64 |
} |
|
65 |
||
66 |
/** Resize the array */ |
|
67 |
template <class T> |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
68 |
inline TInt DResourceCon<T>::ReSize(TInt aGrowBy) |
0 | 69 |
{ |
70 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DResourceCon<T>::ReSize")); |
|
71 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("aGrowBy %d\n", aGrowBy)); |
|
72 |
// Allocate memory for already existing + new required size. |
|
73 |
TInt r = Kern::SafeReAlloc((TAny*&)iArray, iAllocated * sizeof(T*), (iAllocated+aGrowBy)*sizeof(T*)); |
|
74 |
if(r != KErrNone) |
|
75 |
return r; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
76 |
TInt c = iAllocated; |
0 | 77 |
//Virtually link the free ones |
78 |
while(c<(iAllocated+aGrowBy)) |
|
79 |
{ |
|
80 |
iArray[c]=(T*)(c+1); |
|
81 |
c++; |
|
82 |
} |
|
83 |
iAllocated = TUint16(iAllocated + aGrowBy); |
|
84 |
#ifdef PRM_INSTRUMENTATION_MACRO |
|
85 |
TUint size = aGrowBy*4; |
|
86 |
PRM_MEMORY_USAGE_TRACE |
|
87 |
#endif |
|
88 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("< DResourceCon<T>::ReSize, iAllocated = %d", iAllocated)); |
|
89 |
return KErrNone; |
|
90 |
} |
|
91 |
||
92 |
/** Delete the allocated array */ |
|
93 |
template <class T> |
|
94 |
inline void DResourceCon<T>::Delete() |
|
95 |
{ |
|
96 |
delete []iArray; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
iArray = NULL; |
0 | 98 |
} |
99 |
||
100 |
/** Find the object at the specified location */ |
|
101 |
template <class T> |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
102 |
inline T* DResourceCon<T>::operator[](TInt anIndex) |
0 | 103 |
{ |
104 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DResourceCon<T>::operator[], anIndex = %d", anIndex)); |
|
105 |
// Check if passed index is inside allocated range and is not free. |
|
106 |
if(anIndex>=iAllocated || (((TUint)iArray[anIndex])<=iAllocated)) |
|
107 |
return NULL; |
|
108 |
return iArray[anIndex]; |
|
109 |
} |
|
110 |
||
111 |
/** Remove the specified object from the container */ |
|
112 |
template <class T> |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
113 |
inline TInt DResourceCon<T>::Remove(T* /*aObj */, TInt aIndex) |
0 | 114 |
{ |
115 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DResourceCon<T>::Remove")); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
116 |
if(aIndex>=(TInt)iAllocated) |
0 | 117 |
{ |
118 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("Object not found, iAllocated = %d, index = %d", iAllocated, aIndex)); |
|
119 |
DPowerResourceController::Panic(DPowerResourceController::EObjectNotFoundInList); |
|
120 |
} |
|
121 |
// Add the entry to the free location |
|
122 |
iArray[aIndex] = (T*)iFreeLoc; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
iFreeLoc = (TUint16)aIndex; |
0 | 124 |
iCount--; //Decrement valid client count |
125 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DResourceCon<T>::Remove")); |
|
126 |
return KErrNone; |
|
127 |
} |
|
128 |
||
129 |
/** Add the specified object into the container */ |
|
130 |
template <class T> |
|
131 |
inline TInt DResourceCon<T>::Add(T* aObj, TUint &aId) |
|
132 |
{ |
|
133 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DResourceCon<T>::Add")); |
|
134 |
//Check for array full |
|
135 |
if(iFreeLoc == iAllocated) |
|
136 |
return KErrNoMemory; |
|
137 |
//Update in the array in the free location |
|
138 |
aId = ((++iInstanceCount & INSTANCE_COUNT_BIT_MASK) << INSTANCE_COUNT_POS); //Instance count |
|
139 |
aId |= (iFreeLoc & ID_INDEX_BIT_MASK); //Array index |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
140 |
TUint nextFreeLoc = (TUint)iArray[iFreeLoc]; |
0 | 141 |
iArray[iFreeLoc] = aObj; |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
142 |
iFreeLoc = (TUint16)nextFreeLoc; |
0 | 143 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("iFreeLoc %d", iFreeLoc)); |
144 |
iCount++; //Increment the valid client count |
|
145 |
return KErrNone; |
|
146 |
} |
|
147 |
||
148 |
/** Find the entry with specified name and update in anEntry */ |
|
149 |
template <class T> |
|
150 |
inline TInt DResourceCon<T>::Find(T*& anEntry, TDesC8& aName) |
|
151 |
{ |
|
152 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf(">DResourceCon<T>::Find, aName %S", &aName)); |
|
153 |
anEntry = NULL; |
|
154 |
T* pC=anEntry; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
for(TInt count = 0; count < (TInt)iAllocated; count++) |
0 | 156 |
{ |
157 |
/* Check whether the location is free */ |
|
158 |
if(((TUint)iArray[count]) <= iAllocated) |
|
159 |
continue; |
|
160 |
pC=(T*)iArray[count]; |
|
161 |
if(!aName.Compare(*(const TDesC8*)pC->iName)) |
|
162 |
{ |
|
163 |
anEntry=pC; |
|
164 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DResourceCon<T>::Find, Entry Found")); |
|
165 |
return KErrNone; |
|
166 |
} |
|
167 |
} |
|
168 |
||
169 |
__KTRACE_OPT(KRESMANAGER, Kern::Printf("<DResourceCon<T>::Find, Entry Not Found")); |
|
170 |
return KErrNotFound; |
|
171 |
} |