108 @return CCacheMemoryClient* pointer to the client that connected, or NULL if parameters are not valid. |
108 @return CCacheMemoryClient* pointer to the client that connected, or NULL if parameters are not valid. |
109 @leave if no memory |
109 @leave if no memory |
110 */ |
110 */ |
111 EXPORT_C CCacheMemoryClient* CCacheMemoryManager::ConnectClientL(const TDesC& aClientName, TUint32 aMinSizeInSegs, TUint32 aMaxSizeInSegs) |
111 EXPORT_C CCacheMemoryClient* CCacheMemoryManager::ConnectClientL(const TDesC& aClientName, TUint32 aMinSizeInSegs, TUint32 aMaxSizeInSegs) |
112 { |
112 { |
113 __PRINT3(_L("CCacheMemoryManager::ConnectClientL: [%S], minSeg=%d, maxSeg=%d"), &aClientName, aMinSizeInSegs, aMaxSizeInSegs); |
113 __PRINT3(_L("CCacheMemoryManager::ConnectClientL([%S], minSeg=%d, maxSeg=%d)"), &aClientName, aMinSizeInSegs, aMaxSizeInSegs); |
|
114 |
|
115 // search for existing clients by name |
114 for (TInt i = 0; i < iRegisteredClients.Count(); i++) |
116 for (TInt i = 0; i < iRegisteredClients.Count(); i++) |
115 { |
117 { |
116 if (aClientName.Compare(iRegisteredClients[i]->Name()) == 0) |
118 if (aClientName.Compare(iRegisteredClients[i]->Name()) == 0) |
117 { |
119 { |
118 ASSERT(iRegisteredClients[i]->iTouchedRegionFlag == 0); |
120 ASSERT(iRegisteredClients[i]->iTouchedRegionFlag == 0); |
119 __PRINT1(_L("CCacheMemoryManager::ConnectClientL: [%S] found!"), &aClientName); |
121 __PRINT1(_L("CCacheMemoryManager::ConnectClientL: [%S] found!"), &aClientName); |
120 return iRegisteredClients[i]; |
122 return iRegisteredClients[i]; |
121 } |
123 } |
122 } |
124 } |
123 |
125 |
|
126 // if it is a new drive/file system who wants to connect, create a new client for it |
124 // parameter validation |
127 // parameter validation |
125 ASSERT(iSizeInBytes > iCurrentOffsetMark + (aMaxSizeInSegs << SegmentSizeInBytesLog2())); |
128 ASSERT(iSizeInBytes > iCurrentOffsetMark + (aMaxSizeInSegs << SegmentSizeInBytesLog2())); |
126 if (iSizeInBytes < iCurrentOffsetMark + (aMaxSizeInSegs << SegmentSizeInBytesLog2())) |
129 if (iSizeInBytes < iCurrentOffsetMark + (aMaxSizeInSegs << SegmentSizeInBytesLog2())) |
127 { |
130 { |
128 ASSERT(0); |
131 ASSERT(0); |
129 return NULL; |
132 User::Leave(KErrArgument); |
130 } |
133 } |
131 |
134 |
132 // if not found in registered clients, creates new |
135 // note: client creation may leave under OOM conditions |
133 // this may leave under OOM condition |
|
134 CCacheMemoryClient* client = CCacheMemoryClient::NewL(*this, aClientName, iCurrentOffsetMark, aMinSizeInSegs, aMaxSizeInSegs); |
136 CCacheMemoryClient* client = CCacheMemoryClient::NewL(*this, aClientName, iCurrentOffsetMark, aMinSizeInSegs, aMaxSizeInSegs); |
135 |
137 |
136 // if error happens during client registration, the client will be deleted |
138 // if error happens during client registration, the client will be deleted |
137 // this may leave under OOM condition |
139 // this may leave under OOM conditions |
138 TInt err = iRegisteredClients.Append(client); |
140 TInt err = iRegisteredClients.Append(client); |
139 if (err != KErrNone) |
141 if (err != KErrNone) |
140 { |
142 { |
141 ASSERT(0); |
143 ASSERT(0); |
142 delete client; |
144 delete client; |
155 @param aSegmentCount the segment number of the contiguous region to be committed. |
157 @param aSegmentCount the segment number of the contiguous region to be committed. |
156 @return TInt KErrNone if succeeded, KErrNoMemory if passed low memory threshold, otherwise a system-wide error code. |
158 @return TInt KErrNone if succeeded, KErrNoMemory if passed low memory threshold, otherwise a system-wide error code. |
157 */ |
159 */ |
158 TInt CCacheMemoryManager::AllocateAndLockSegments(TUint8* aStartRamAddr, TInt aSegmentCount) |
160 TInt CCacheMemoryManager::AllocateAndLockSegments(TUint8* aStartRamAddr, TInt aSegmentCount) |
159 { |
161 { |
160 __PRINT2(_L("CCacheMemoryManager::AllocateAndLockSegments: base=0x%x, seg=%d"), aStartRamAddr, aSegmentCount); |
162 __PRINT2(_L("CCacheMemoryManager::AllocateAndLockSegments(base=0x%x, seg=%d)"), aStartRamAddr, aSegmentCount); |
161 TMemoryInfoV1Buf meminfo; |
163 TMemoryInfoV1Buf meminfo; |
162 TInt r = UserHal::MemoryInfo(meminfo); |
164 TInt r = UserHal::MemoryInfo(meminfo); |
163 __ASSERT_DEBUG(r==KErrNone,Fault(EMemoryInfoFailed)); |
165 __ASSERT_DEBUG(r==KErrNone,Fault(EMemoryInfoFailed)); |
164 if (r != KErrNone) |
166 if (r != KErrNone) |
165 { |
167 { |