|
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 "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 |
|
20 #include "nm_node.h" |
|
21 #include "nm_messages_base.h" |
|
22 |
|
23 |
|
24 #ifdef _DEBUG |
|
25 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module |
|
26 // (if it could happen through user error then you should give it an explicit, documented, category + code) |
|
27 _LIT(KSpecAssert_ElemNodeMessNodC, "ElemNodeMessNodC"); |
|
28 #endif |
|
29 |
|
30 using namespace Messages; |
|
31 |
|
32 |
|
33 EXPORT_C NetInterfaces::TInterfaceControl* ANode::FetchNodeInterfaceControlL(TInt /*aInterfaceId*/) |
|
34 { |
|
35 User::Leave(KErrInterfaceNotSupported); |
|
36 return NULL; |
|
37 } |
|
38 |
|
39 EXPORT_C TAny* ANode::FetchNodeInterfaceL(TInt aInterfaceId) |
|
40 { |
|
41 NetInterfaces::TInterfaceControl* ic = FetchNodeInterfaceControlL(aInterfaceId); |
|
42 return ic->FetchInterfaceL(aInterfaceId); |
|
43 } |
|
44 |
|
45 EXPORT_C const TNodeId& ASimpleNodeIdBase::NodeId() const |
|
46 { |
|
47 return ANodeId::Id(); |
|
48 } |
|
49 |
|
50 EXPORT_C const TNodeId& ANodeIdBase::NodeId() const |
|
51 { |
|
52 return ANodeId::Id(); |
|
53 } |
|
54 |
|
55 EXPORT_C ANodeBase::ANodeBase(const TNodeId& aNodeId) |
|
56 : TIfStaticFetcherNearestInHierarchy(this) |
|
57 { |
|
58 iSelfInterface.Open(aNodeId); |
|
59 } |
|
60 |
|
61 EXPORT_C void ANodeBase::ReturnInterfacePtrL(ANodeBase*& aInterface) |
|
62 { |
|
63 aInterface = this; |
|
64 } |
|
65 |
|
66 EXPORT_C ANodeBase::~ANodeBase() |
|
67 { |
|
68 //There can be no clients left in the array. |
|
69 //No Data Clients |
|
70 //No Control Clients |
|
71 //No Service Providers |
|
72 //No Control Provider |
|
73 |
|
74 TClientIter<TDefaultClientMatchPolicy> iter(GetClientIter<TDefaultClientMatchPolicy>(TClientType(TClientType::EAll))); |
|
75 while(*iter) |
|
76 { |
|
77 NM_LOG((KNodeMessagesSubTag, _L8("ERROR: ~ANodeBase(%08x) - Client %08x Type %04x"), |
|
78 Id().Ptr(), &((*iter)->RecipientId()), (*iter)->Type())); |
|
79 ++iter; |
|
80 } |
|
81 |
|
82 __ASSERT_DEBUG(iClients.Count()==0, User::Panic(KSpecAssert_ElemNodeMessNodC, 1)); //Please fix your node. |
|
83 iClients.ResetAndDestroy(); |
|
84 iSelfInterface.Close(); |
|
85 } |
|
86 |
|
87 EXPORT_C RNodeInterface* ANodeBase::NewClientInterfaceL(const TClientType& /*aClientType*/, TAny* /*aClientInfo*/) |
|
88 { |
|
89 return new(ELeave)RNodeInterface(); |
|
90 } |
|
91 |
|
92 /** |
|
93 * Find specified client identified by id specified |
|
94 * @return A pointer to RNodeInterface, or NULL, if not found |
|
95 */ |
|
96 EXPORT_C RNodeInterface* ANodeBase::FindClient(const TRuntimeCtxId& aId) const |
|
97 { |
|
98 TInt dummy = 0; |
|
99 return DoFindClient(aId, dummy); |
|
100 } |
|
101 |
|
102 //As FindClient but must not return NULL |
|
103 EXPORT_C RNodeInterface* ANodeBase::FindClientL(const TRuntimeCtxId& aId) const |
|
104 { |
|
105 TInt dummy = 0; |
|
106 RNodeInterface* c = DoFindClient(aId, dummy); |
|
107 User::LeaveIfError(c? KErrNone : KErrNotFound); |
|
108 return c; |
|
109 } |
|
110 |
|
111 EXPORT_C RNodeInterface* ANodeBase::DoFindClient(const TRuntimeCtxId& aId, TInt& aFoundAtIndex) const |
|
112 { |
|
113 aFoundAtIndex = KErrNotFound; |
|
114 for (TInt i = iClients.Count() - 1; i>=0; i--) |
|
115 { |
|
116 if (*iClients[i] == aId) |
|
117 { |
|
118 aFoundAtIndex = i; |
|
119 return iClients[i]; |
|
120 } |
|
121 } |
|
122 return NULL; |
|
123 } |
|
124 |
|
125 EXPORT_C TUint ANodeBase::CountClients(TClientIterBase& aClientIterator) const |
|
126 { |
|
127 TUint count = 0; |
|
128 while ((aClientIterator++) != NULL) |
|
129 { |
|
130 count++; |
|
131 } |
|
132 return count; |
|
133 } |
|
134 |
|
135 EXPORT_C TInt ANodeBase::PostToClients(TClientIterBase& aClientIterator, const TRuntimeCtxId& aPostFrom, const TSignalBase& aMessage, TUint32 aFlagsToSet, TUint32 aFlagsToClear) const |
|
136 { |
|
137 TInt count = 0; |
|
138 |
|
139 RNodeInterface* ctl; |
|
140 while ((ctl = aClientIterator++) != NULL) |
|
141 { |
|
142 if (!(ctl->Flags() & TClientType::ELeaving)) |
|
143 { |
|
144 count++; |
|
145 ctl->PostMessage(aPostFrom, aMessage); |
|
146 ctl->ClearFlags(aFlagsToClear); |
|
147 ctl->SetFlags(aFlagsToSet); |
|
148 } |
|
149 } |
|
150 return count; |
|
151 } |
|
152 |
|
153 EXPORT_C RNodeInterface* ANodeBase::AddClientL(const TNodeId& aClientId, const TClientType& aClientType, TAny* aClientInfo) |
|
154 { |
|
155 NM_LOG((KNodeMessagesSubTag, _L8("ANodeBase %08x:\tAddClientL(%08x, flags=%04x, type=%04x)"), Id().Ptr(), aClientId.Ptr(), aClientType.Flags(), aClientType.Type())); |
|
156 RNodeInterface* client = FindClient(aClientId); |
|
157 if (NULL == client) |
|
158 { |
|
159 RNodeInterface* cc = NewClientInterfaceL(aClientType, aClientInfo); |
|
160 CleanupStack::PushL(cc); |
|
161 iClients.AppendL(cc); //don't change it some states may rely on the fact that clients |
|
162 //are appended |
|
163 CleanupStack::Pop(cc); |
|
164 cc->Open(aClientId, aClientType); |
|
165 client = cc; |
|
166 } |
|
167 else |
|
168 { |
|
169 client->SetFlags(aClientType.Flags()); |
|
170 } |
|
171 |
|
172 return client; |
|
173 } |
|
174 |
|
175 EXPORT_C void ANodeBase::RemoveClient(RNodeInterface& aClient) |
|
176 { |
|
177 TInt foundAt = iClients.Find(&aClient); |
|
178 __ASSERT_DEBUG(KErrNotFound!=foundAt, User::Panic(KSpecAssert_ElemNodeMessNodC, 2)); |
|
179 RemoveClient(foundAt); |
|
180 } |
|
181 |
|
182 EXPORT_C void ANodeBase::RemoveClient(TInt aIndex) |
|
183 { |
|
184 __ASSERT_ALWAYS(aIndex >= 0 && aIndex < iClients.Count(), User::Panic(Messages::KMessagesPanic,Messages::EClientNotValidPanic)); |
|
185 RNodeInterface* client = iClients[aIndex]; |
|
186 NM_LOG((KNodeMessagesSubTag, _L8("ANodeBase %08x:\tRemoveClient(%08x, flags=%04x, type=%04x)"), Id().Ptr(), client->RecipientId().Ptr(), client->Flags(), client->Type())); |
|
187 client->Close(); |
|
188 delete client; |
|
189 iClients.Remove(aIndex); |
|
190 } |
|
191 |
|
192 |