|
1 // Copyright (c) 2005-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 @file |
|
18 |
|
19 ss_mcprnodeinterfaces.cpp |
|
20 */ |
|
21 |
|
22 #include <comms-infras/ss_mcprnodemessages.h> |
|
23 #include <comms-infras/metatype.h> |
|
24 #include <ss_glob.h> |
|
25 #include <comms-infras/ss_log.h> |
|
26 #include <comms-infras/ss_thread.h> |
|
27 #include <comms-infras/metatypevariablelen.h> |
|
28 #include <comms-infras/ss_mmnode.h> |
|
29 |
|
30 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
31 #include <es_enum_internal.h> |
|
32 #endif |
|
33 |
|
34 #ifdef _DEBUG |
|
35 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module |
|
36 // (if it could happen through user error then you should give it an explicit, documented, category + code) |
|
37 _LIT(KSpecAssert_ESockSSocksmcprn, "ESockSSocksmcprn"); |
|
38 #endif |
|
39 |
|
40 using namespace ESock; |
|
41 using namespace Elements; |
|
42 using namespace Messages; |
|
43 using namespace MeshMachine; |
|
44 |
|
45 const TInt KESockInternalMetaPlaneMessagesImplementationUid = 0x1028300E; |
|
46 |
|
47 enum EMessageTypeId //message signatures only (NOT messages) messages are declared under class TCFMessage |
|
48 { |
|
49 ESafeMessageCarrierBase =0, |
|
50 ESafeMessageCarrierEast =1, |
|
51 ESafeMessageCarrierWest =2 |
|
52 }; |
|
53 |
|
54 |
|
55 // |
|
56 //TConnProviderInfoPref |
|
57 EXPORT_C TConnProviderInfoPref::TConnProviderInfoPref(const TConnProviderInfo& aProviderInfo) |
|
58 : TConnPref(EConnPrefProviderInfo) |
|
59 { |
|
60 TConnProviderInfo* prefPtr = reinterpret_cast<TConnProviderInfo*>(UserPtr()); |
|
61 *prefPtr = aProviderInfo; //Binary copy |
|
62 } |
|
63 |
|
64 EXPORT_C const TConnProviderInfo& TConnProviderInfoPref::Info() const |
|
65 /** |
|
66 @publishedPartner |
|
67 @return stored SNAP value |
|
68 @released since v9.1 |
|
69 */ |
|
70 { |
|
71 return *(reinterpret_cast<TConnProviderInfo*>(UserPtr())); |
|
72 } |
|
73 |
|
74 // |
|
75 //TSelectionPrefs |
|
76 EXPORT_START_ATTRIBUTE_TABLE_AND_FN(TSelectionPrefs, TSelectionPrefs::EUid, TSelectionPrefs::ETypeId) |
|
77 REGISTER_ATTRIBUTE(TSelectionPrefs, iPrefs, TMeta<TConnPref>) |
|
78 REGISTER_ATTRIBUTE(TSelectionPrefs, iU.iSelectionParams, TMetaNumber) |
|
79 REGISTER_ATTRIBUTE(TSelectionPrefs, iSubSessionUniqueId, TMetaNumber) |
|
80 END_ATTRIBUTE_TABLE() |
|
81 |
|
82 EXPORT_C TSelectionPrefs::TSelectionPrefs() |
|
83 { |
|
84 iU.iS.iScope = ENone; |
|
85 iU.iS.iFlags = 0; |
|
86 } |
|
87 |
|
88 EXPORT_C TSelectionPrefs::TSelectionPrefs(TSelectionScope aSelectionScope) |
|
89 { |
|
90 iU.iS.iScope = aSelectionScope; |
|
91 iU.iS.iFlags = 0; |
|
92 } |
|
93 |
|
94 EXPORT_C TSelectionPrefs::TSelectionPrefs(const TConnPref& aPref) |
|
95 { |
|
96 SetPrefs(aPref); |
|
97 } |
|
98 |
|
99 // |
|
100 //TOverridenSelectionPrefsExt |
|
101 EXPORT_START_ATTRIBUTE_TABLE_AND_FN(TOverridenSelectionPrefsExt, TOverridenSelectionPrefsExt::EUid, TOverridenSelectionPrefsExt::ETypeId) |
|
102 //No attributes as this is only for type id |
|
103 END_ATTRIBUTE_TABLE() |
|
104 |
|
105 EXPORT_C TOverridenSelectionPrefsExt::TOverridenSelectionPrefsExt(TUid aTierId, const TSelectionPrefs& aPrefs) |
|
106 : iPrefs(aPrefs), |
|
107 iTierId(aTierId) |
|
108 { |
|
109 } |
|
110 |
|
111 // |
|
112 //TDeferredSelectionPrefsExt |
|
113 EXPORT_START_ATTRIBUTE_TABLE_AND_FN(TDeferredSelectionPrefsExt, TDeferredSelectionPrefsExt::EUid, TDeferredSelectionPrefsExt::ETypeId) |
|
114 //No attributes as this is only for type id |
|
115 END_ATTRIBUTE_TABLE() |
|
116 |
|
117 EXPORT_C TDeferredSelectionPrefsExt::TDeferredSelectionPrefsExt(TUid aTierId, const TConnPref& aPrefs) |
|
118 : iPrefs(aPrefs), |
|
119 iTierId(aTierId) |
|
120 { |
|
121 } |
|
122 |
|
123 // |
|
124 //TPromptingSelectionPrefsExt |
|
125 EXPORT_START_ATTRIBUTE_TABLE_AND_FN(TPromptingSelectionPrefsExt, TPromptingSelectionPrefsExt::EUid, TPromptingSelectionPrefsExt::ETypeId) |
|
126 //No attributes as this is only for type id |
|
127 END_ATTRIBUTE_TABLE() |
|
128 |
|
129 EXPORT_C TPromptingSelectionPrefsExt::TPromptingSelectionPrefsExt(TUid aTierId, const TConnPref& aPrefs) |
|
130 : iPrefs(aPrefs), iTierId(aTierId), iPromptingInProgress(ETrue) |
|
131 { |
|
132 } |
|
133 |
|
134 EXPORT_C Meta::SMetaData* RConnPrefList::TIterBase::AtIndex(const Meta::STypeId& aType, TInt aIndex) |
|
135 { |
|
136 TInt ind = 0; |
|
137 TInt count = 0; |
|
138 while(ind < iConnPrefList.Count()) |
|
139 { |
|
140 if (iConnPrefList[ind]->IsTypeOf(aType)) |
|
141 { |
|
142 if(count == aIndex) |
|
143 { |
|
144 iMasterIndex = ind; |
|
145 return static_cast<Meta::SMetaData*>(iConnPrefList[ind]); |
|
146 } |
|
147 count++; |
|
148 } |
|
149 ind++; |
|
150 } |
|
151 return NULL; |
|
152 } |
|
153 |
|
154 // |
|
155 //RConnPrefList |
|
156 EXPORT_C RConnPrefList::RConnPrefList() |
|
157 { |
|
158 iObject = NULL; |
|
159 } |
|
160 |
|
161 EXPORT_C void RConnPrefList::Open(RConnPrefList& aObject) |
|
162 { |
|
163 iObject = aObject.iObject; |
|
164 } |
|
165 |
|
166 TInt RConnPrefList::Open(TConnPrefList* aObject) |
|
167 { |
|
168 if(aObject == NULL) |
|
169 { |
|
170 return KErrNotFound; |
|
171 } |
|
172 else |
|
173 { |
|
174 iObject = aObject; |
|
175 return KErrNone; |
|
176 } |
|
177 } |
|
178 |
|
179 EXPORT_C void RConnPrefList::Close() |
|
180 { |
|
181 iObject = NULL; |
|
182 } |
|
183 |
|
184 EXPORT_C void RConnPrefList::AppendL(SMetaDataECom* aFamily) |
|
185 { |
|
186 if(iObject == NULL) |
|
187 { |
|
188 User::Leave(KErrNotReady); |
|
189 } |
|
190 else if(aFamily == NULL) |
|
191 { |
|
192 User::Leave(KErrArgument); |
|
193 } |
|
194 iObject->AppendL(aFamily); |
|
195 } |
|
196 |
|
197 EXPORT_C SMetaData* RConnPrefList::operator[](TInt aIndex) |
|
198 { |
|
199 if(iObject == NULL ) |
|
200 { |
|
201 return NULL; |
|
202 } |
|
203 return (*iObject)[aIndex]; |
|
204 } |
|
205 |
|
206 EXPORT_C void RConnPrefList::Remove(TInt aIndex) |
|
207 { |
|
208 if(iObject == NULL) |
|
209 { |
|
210 return; |
|
211 } |
|
212 iObject->Remove(aIndex); |
|
213 } |
|
214 |
|
215 EXPORT_C TInt RConnPrefList::Count() |
|
216 { |
|
217 if(iObject != NULL) |
|
218 { |
|
219 return iObject->Count(); |
|
220 } |
|
221 else |
|
222 { |
|
223 return 0; |
|
224 } |
|
225 } |
|
226 |
|
227 // |
|
228 //TSafeMessageCarrierBase - Safe CF Message carriers |
|
229 |
|
230 //It is not a purposes of these carriers to secure the comunication channel between two non-peer nodes. |
|
231 //Sending of such message does not quarantee the node will be there to receive it |
|
232 //There is a specialisation of the request carrier "locking" the requesting node which makes sure |
|
233 //that the response will always be deliverd. |
|
234 |
|
235 TSafeMessageCarrierBase::TSafeMessageCarrierBase(const Messages::TSignatureBase& aMessage) |
|
236 : Messages::TSignatureBase(aMessage.MessageId()) |
|
237 { |
|
238 __ASSERT_DEBUG(KMaxCarriedMessageSize>=aMessage.Length(), User::Panic(KSpecAssert_ESockSSocksmcprn, 1)); //TODO: Add panic code & description!!! |
|
239 VERIFY(aMessage.Store(iMessageBuf)==KErrNone); //Guaranteed to succeed now - compile assert is quarding it from the template |
|
240 } |
|
241 |
|
242 void TSafeMessageCarrierBase::DispatchCarriedMessageL(const TRuntimeCtxId& aSender, const TNodeId& aNodeId) |
|
243 { |
|
244 TBuf8<__Align8(TSignalBase::KMaxInlineMessageSize + TSignalBase::KMaxUnstoredOverhead)> msgBuf; |
|
245 Meta::CMetaDataVirtualCtorInPlace* vctr = TlsGlobals::Get().VirtualCtor(); |
|
246 TPtrC8 ptr(iMessageBuf); |
|
247 iMessage = static_cast<Messages::TSignatureBase*>(vctr->New(ptr, msgBuf)); |
|
248 User::LeaveIfError(iMessage? KErrNone : KErrNotFound); |
|
249 |
|
250 #ifdef SYMBIAN_TRACE_ENABLE |
|
251 _LIT8(KESockMeshMachine, "cftransport"); |
|
252 NM_LOG_START_BLOCK(KESockMeshMachine, _L8("TransportReceiver::DispatchMessage")); |
|
253 NM_LOG_ADDRESS(KESockMeshMachine, aSender); |
|
254 NM_LOG_ADDRESS(KESockMeshMachine, aNodeId); |
|
255 NM_LOG_MESSAGE(KESockMeshMachine, *iMessage); |
|
256 NM_LOG_END_BLOCK(KESockMeshMachine, _L8("TransportReceiver::DispatchMessage")); |
|
257 #endif |
|
258 |
|
259 iMessage->DispatchL(aSender, aNodeId); |
|
260 } |
|
261 |
|
262 EXPORT_C void TSafeMessageCarrierBase::Error(const TRuntimeCtxId& aSender, const TRuntimeCtxId& aRecipient, TInt aError) |
|
263 { |
|
264 NM_LOG_START_BLOCK(KESockMeshMachine, _L8("TSafeMessageCarrierBase:Error")); |
|
265 NM_LOG((KESockMeshMachine, _L8("[this=0x%08x] [Error=%d] "), this, aError)); |
|
266 NM_LOG_ADDRESS_EXT(KESockMeshMachine, aSender, _L8("Originator: ")); |
|
267 NM_LOG_ADDRESS_EXT(KESockMeshMachine, aRecipient, _L8("Recipient: ")); |
|
268 NM_LOG((KESockMeshMachine, _L8("[MessageId=0x%08x:0x%08x] "), MessageId().Realm(), MessageId().MessageId())); |
|
269 NM_LOG_END_BLOCK(KESockMeshMachine, _L8("TSafeMessageCarrierBase:Error")); |
|
270 |
|
271 if (!aSender.IsNull()) |
|
272 { |
|
273 TEBase::TError errMsg( |
|
274 #if defined(__GCCXML__) |
|
275 static_cast<Messages::TNodeSignal::TMessageId>(MessageId()), |
|
276 #else |
|
277 MessageId(), |
|
278 #endif |
|
279 aError |
|
280 ); |
|
281 |
|
282 TCFSafeMessage::TResponseCarrierWest<TEBase::TError> responseCarrierMsg(errMsg, aSender); |
|
283 |
|
284 RClientInterface::OpenPostMessageClose(aRecipient, aSender, responseCarrierMsg); |
|
285 } |
|
286 |
|
287 } |
|
288 |
|
289 EXPORT_START_ATTRIBUTE_TABLE_AND_FN(TSafeMessageCarrierBase, KESockInternalMetaPlaneMessagesImplementationUid, ESafeMessageCarrierBase) |
|
290 REGISTER_ATTRIBUTE(TSafeMessageCarrierBase, iMessageBuf, TMeta<TBuf8<KMaxCarriedMessageSize> >) //TODO find variable len meta type |
|
291 END_ATTRIBUTE_TABLE_BASE(TSignatureBase, ESignatureBase) |
|
292 |
|
293 /* |
|
294 //Used to lock the requesting node until the response has been received |
|
295 class ARequestingNodeLockingClient : Messages::ASimpleNodeIdBase |
|
296 { |
|
297 public: |
|
298 void LockRequestingNodeL(const MeshMachine::AMMNodeBase& aRequestingNode) |
|
299 { |
|
300 //ARequestingNodeLockingClient can currently only work on MeshMachine::AMMNodeBase nodes!!! |
|
301 MeshMachine::AMMNodeBase* nodeBase = reinterpret_cast<MeshMachine::AMMNodeBase*>(aRequestingNode.FetchNodeInterfaceL(AMMNodeBase::KInterfaceId)); |
|
302 nodeBase.AddClientL((*this)(),RNodeInterface::ECtrl); |
|
303 } |
|
304 |
|
305 static void Cleanup(TAny* aThis) |
|
306 { |
|
307 ARequestingNodeLockingClient* self = static_cast<ARequestingNodeLockingClient*>(aThis); |
|
308 MeshMachine::AMMNodeBase* nodeBase = reinterpret_cast<MeshMachine::AMMNodeBase*>(self->iLockedNode.FetchNodeInterfaceL(AMMNodeBase::KInterfaceId)); |
|
309 nodeBase.RemoveClient((*this)()); |
|
310 delete self; |
|
311 } |
|
312 |
|
313 virtual TInt ReceivedL(Messages::TSignatureBase& aCFMessage) |
|
314 { |
|
315 if (aCFMessage.iSender == iLockedNode()) |
|
316 { |
|
317 return; |
|
318 } |
|
319 |
|
320 //Noone else knows about this node!!!! |
|
321 __ASSERT_DEBUG(aCFMessage.iSender == iRespondingNode, User::Panic(KSpecAssert_ESockSSocksmcprn, 2)); |
|
322 CleanupStack::PushL(TCleanupItem(Cleanup,this)); |
|
323 TInt error = iLockedNode->ReceivedL(aCFMessage); |
|
324 CleanupStack::PopAndDestroy(); |
|
325 return error; |
|
326 } |
|
327 private: |
|
328 TNodeId iRespondingNode; |
|
329 MeshMachine::AMMNodeBase& iLockedNode; |
|
330 }; |
|
331 |
|
332 EXPORT_C void TSafeMessageCarrierEastBase::LockRequestingNodeAndPostL(const MeshMachine::AMMNodeBase& aRequestingNode) |
|
333 { |
|
334 __ASSERT_DEBUG(iMessage, User::Panic(KSpecAssert_ESockSSocksmcprn, 3)); //The local message |
|
335 __ASSERT_DEBUG(KMaxCarriedMessageSize>=aMessage.Length(), User::Panic(KSpecAssert_ESockSSocksmcprn, 4)); //TODO: Add panic code & description!!! |
|
336 iMessageBuf.FillZ(); |
|
337 iMessage-> |
|
338 VERIFY(aMessage.Store(iMessageBuf)==KErrNone); //Guaranteed to succeed now - compile assert is quarding it from the template |
|
339 |
|
340 ARequestingNodeLockingClient* lock = new (ELeave) ARequestingNodeLockingClient; |
|
341 CleanupStack::PushL(lock); |
|
342 lock->LockRequestingNodeL(aRequestingNode); |
|
343 CleanupStack::Pop(lock); |
|
344 } |
|
345 */ |
|
346 |
|
347 EXPORT_C TSafeRequestCarrierEast::TSafeRequestCarrierEast(const Messages::TSignatureBase& aMessage) |
|
348 : TSafeMessageCarrierBase(aMessage) |
|
349 { |
|
350 } |
|
351 |
|
352 EXPORT_C void TSafeRequestCarrierEast::DispatchL(const TRuntimeCtxId& aSender, const TRuntimeCtxId& aRecipient) |
|
353 { |
|
354 const TNodeId& nodeId = address_cast<const TNodeId>(aRecipient); //This message type operates on nodes |
|
355 AMMNodeBase* nodeBase = reinterpret_cast<AMMNodeBase*>(nodeId.Node().FetchNodeInterfaceL(AMMNodeBase::KInterfaceId)); //Will result in Error() when not found |
|
356 if (static_cast<ACFMMNodeIdBase*>(nodeBase)->ControlProvider()==0) |
|
357 { |
|
358 DispatchCarriedMessageL(aSender, nodeId); |
|
359 } |
|
360 else |
|
361 { |
|
362 nodeBase->PostToClients<TDefaultClientMatchPolicy>(aSender, *this, TClientType(TCFClientType::ECtrlProvider), TClientType(0, TClientType::ELeaving)); |
|
363 } |
|
364 } |
|
365 |
|
366 DEFINE_MVIP_CTR(TSafeRequestCarrierEast) |
|
367 |
|
368 EXPORT_START_ATTRIBUTE_TABLE_AND_FN(TSafeRequestCarrierEast, KESockInternalMetaPlaneMessagesImplementationUid, ESafeMessageCarrierEast) |
|
369 END_ATTRIBUTE_TABLE_BASE(TSafeMessageCarrierBase, ESafeMessageCarrierBase) |
|
370 |
|
371 EXPORT_C TSafeResponseCarrierWest::TSafeResponseCarrierWest(const Messages::TSignatureBase& aMessage, const TRuntimeCtxId& aRecipient) |
|
372 : TSafeMessageCarrierBase(aMessage), |
|
373 iRecipient(address_cast<TNodeId>(aRecipient)) //Must be a node! |
|
374 { |
|
375 } |
|
376 |
|
377 EXPORT_C void TSafeResponseCarrierWest::DispatchL(const TRuntimeCtxId& aSender, const TRuntimeCtxId& aRecipient) |
|
378 { |
|
379 const TNodeId& nodeId = address_cast<const TNodeId>(aRecipient); //This message type operates on nodes |
|
380 if (nodeId==iRecipient) |
|
381 { |
|
382 DispatchCarriedMessageL(aSender, nodeId); |
|
383 } |
|
384 else |
|
385 { |
|
386 MeshMachine::AMMNodeBase* nodeBase = NULL; |
|
387 TRAP_IGNORE(nodeBase = reinterpret_cast<MeshMachine::AMMNodeBase*>(nodeId.Node().FetchNodeInterfaceL(AMMNodeBase::KInterfaceId))); |
|
388 if (nodeBase) |
|
389 { |
|
390 //If the interface is not found, ignore |
|
391 nodeBase->PostToClients<TDefaultClientMatchPolicy>(aSender, *this, TClientType(TCFClientType::EData), TClientType(0, TClientType::ELeaving)); |
|
392 } |
|
393 } |
|
394 } |
|
395 |
|
396 DEFINE_MVIP_CTR(TSafeResponseCarrierWest) |
|
397 |
|
398 EXPORT_START_ATTRIBUTE_TABLE_AND_FN(TSafeResponseCarrierWest, KESockInternalMetaPlaneMessagesImplementationUid, ESafeMessageCarrierWest) |
|
399 REGISTER_ATTRIBUTE(TSafeResponseCarrierWest, iRecipient, TMeta<TNodeId>) |
|
400 END_ATTRIBUTE_TABLE_BASE(TSafeMessageCarrierBase, ESafeMessageCarrierBase) |
|
401 |
|
402 const TImplementationProxy SignatureImplementationTable[] = |
|
403 { |
|
404 //NOTE: Entries must be sorted for the binary search to work efficiently! |
|
405 MVIP_CTR_ENTRY(ESafeMessageCarrierEast,TSafeRequestCarrierEast), |
|
406 MVIP_CTR_ENTRY(ESafeMessageCarrierWest,TSafeResponseCarrierWest), |
|
407 }; |
|
408 |
|
409 void TCFSafeMessage::RegisterL() |
|
410 { |
|
411 TlsGlobals::Get().RegisterInterfaceL(TUid::Uid(KESockInternalMetaPlaneMessagesImplementationUid), sizeof(SignatureImplementationTable) / sizeof(SignatureImplementationTable[0]), SignatureImplementationTable); |
|
412 } |
|
413 |
|
414 void TCFSafeMessage::DeRegister() |
|
415 { |
|
416 TlsGlobals::Get().DeregisterInterface(TUid::Uid(KESockInternalMetaPlaneMessagesImplementationUid)); |
|
417 } |
|
418 |