|
1 // Copyright (c) 2004-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 SS_FACT.CPP |
|
18 */ |
|
19 |
|
20 #include <ss_std.h> |
|
21 #include <ecom/ecom.h> |
|
22 #include "ss_fact.h" |
|
23 #include <comms-infras/ss_fact_internal.h> |
|
24 |
|
25 |
|
26 #include <ss_glob.h> |
|
27 #include <comms-infras/ss_log.h> |
|
28 #include <comms-infras/netmessages.h> |
|
29 #include <in_sock.h> //KAfInet |
|
30 #include <elements/nm_messages_peer.h> |
|
31 #include <elements/factorynotify.h> |
|
32 #include <comms-infras/ss_nodeinterfaces.h> |
|
33 #include <comms-infras/ss_msgintercept.h> |
|
34 #include <comms-infras/ss_nodemessages_factory.h> |
|
35 #include <comms-infras/ss_tiermanagerutils.h> |
|
36 |
|
37 |
|
38 #ifdef _DEBUG |
|
39 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module |
|
40 // (if it could happen through user error then you should give it an explicit, documented, category + code) |
|
41 _LIT(KSpecAssert_ESockSSocks_fct, "ESockSSocks_fct."); |
|
42 #endif |
|
43 |
|
44 using namespace ESock; |
|
45 using namespace Messages; |
|
46 using namespace Factories; |
|
47 using namespace MeshMachine; |
|
48 |
|
49 |
|
50 CCommsFactoryContainer::CCommsFactoryContainer(TContaineeType aId) |
|
51 : CFactoryContainerNode(), |
|
52 iId(aId) |
|
53 { |
|
54 } |
|
55 |
|
56 void CCommsFactoryContainer::ReceivedL(const TRuntimeCtxId& aSender, const TNodeId& /* aRecipient */, TSignatureBase& aMessage) |
|
57 { |
|
58 if (aMessage.IsMessage<TCFFactory::TFindOrCreatePeer>()) |
|
59 { |
|
60 ACommsFactoryNodeId* factoryObject = CreateFactoryObjectNodeL (aMessage); |
|
61 RClientInterface::OpenPostMessageClose(Id(), aSender, TCFFactory::TPeerFoundOrCreated(factoryObject->Id()).CRef()); |
|
62 aMessage.ClearMessageId(); |
|
63 } |
|
64 else |
|
65 { |
|
66 __ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ESockSSocks_fct, 1)); //For debug configurations |
|
67 User::Leave(KErrNotSupported); //For release configurations |
|
68 } |
|
69 |
|
70 } |
|
71 |
|
72 EXPORT_C CFactoryBase* CCommsFactoryContainer::FindOrCreateFactoryL(TUid aUid) |
|
73 { |
|
74 CFactoryBase* factory = static_cast<CFactoryBase*>(FindFactory(aUid)); |
|
75 if (factory == NULL) |
|
76 { |
|
77 factory = CreateFactoryL(aUid); |
|
78 } |
|
79 return factory; |
|
80 } |
|
81 |
|
82 CFactoryBase* CCommsFactoryContainer::CreateFactoryL(TUid aUid) |
|
83 { |
|
84 return static_cast<CFactoryBase*> (CFactoryBase::NewL(aUid, *this)); |
|
85 } |
|
86 |
|
87 ACommsFactoryNodeId* CCommsFactoryContainer::CreateFactoryObjectNodeL(Messages::TSignatureBase& aMessage) |
|
88 { |
|
89 __ASSERT_DEBUG(aMessage.IsMessage<TCFFactory::TFindOrCreatePeer>(), User::Panic(KSpecAssert_ESockSSocks_fct, 2)); |
|
90 const TCFFactory::TFindOrCreatePeer& msg = message_cast<const TCFFactory::TFindOrCreatePeer>(aMessage); |
|
91 CCommsFactoryBase* factory = static_cast<CCommsFactoryBase*>(FindOrCreateFactoryL(msg.iUid)); |
|
92 return factory->FindOrCreateObjectL(*(msg.iQuery)); |
|
93 } |
|
94 |
|
95 EXPORT_C ACommsFactoryNodeId* CCommsFactoryContainer::Find (Factories::MFactoryQuery& aQuery) |
|
96 { |
|
97 return static_cast<ACommsFactoryNodeId*>(CFactoryContainer::FindObject(aQuery)); |
|
98 } |
|
99 |
|
100 //================================================================== |
|
101 |
|
102 |
|
103 EXPORT_C ACommsFactoryNodeId* CCommsFactoryBase::FindOrCreateObjectL(TFactoryQueryBase& aQuery) |
|
104 { |
|
105 return DoFindOrCreateObjectL(aQuery); |
|
106 } |
|
107 |
|
108 EXPORT_C ACommsFactoryNodeId* CCommsFactoryBase::CreateObjectL(TFactoryQueryBase& aQuery) |
|
109 { |
|
110 ACommsFactoryNodeId* factoryObject = DoCreateObjectL(aQuery); |
|
111 |
|
112 // The object that was created during DoCreateObjectL execution is derived from both CBase |
|
113 // and ACommsFactoryNodeId. |
|
114 // It is not correct to use PushL for factoryObject here, because ACommsFactoryNodeId |
|
115 // is not a CBase child. |
|
116 // So compiler will use CleanupStack::PushL(TAny *) function instead of |
|
117 // CleanupStack::PushL(CBase *). |
|
118 // As a result if something leaves we get following problems: |
|
119 // 1. destructor is not called |
|
120 // 2. User:42 panic when Leave handler will try to free factoryObject's memory |
|
121 TRAPD(err, |
|
122 DoPostCreationL(factoryObject,aQuery); //setting Tiermanager |
|
123 AddManagedObjectL(*factoryObject); |
|
124 ) |
|
125 if (err != KErrNone) |
|
126 { |
|
127 // Use delete for ACommsFactoryNodeId only because it has VIRTUAL destructor in one of it's base classes |
|
128 delete factoryObject; |
|
129 User::Leave(err); |
|
130 } |
|
131 |
|
132 return factoryObject; |
|
133 } |
|
134 |
|
135 EXPORT_C ACommsFactoryNodeId* CCommsFactoryBase::Find(Factories::MFactoryQuery& aQuery) |
|
136 { |
|
137 return static_cast<ACommsFactoryNodeId*>(CFactoryBase::FindObject(aQuery)); |
|
138 } |
|
139 |
|
140 EXPORT_C ACommsFactoryNodeId* CCommsFactoryBase::DoFindOrCreateObjectL(TFactoryQueryBase& aQuery) |
|
141 /** Default implementation to create a factory object. This may be overridden by a derived class |
|
142 */ |
|
143 { |
|
144 ACommsFactoryNodeId* factoryObject = static_cast<ACommsFactoryNodeId*>(FindObject(aQuery)); |
|
145 if (factoryObject == NULL) |
|
146 { |
|
147 factoryObject = CreateObjectL(aQuery); |
|
148 } |
|
149 return factoryObject; |
|
150 } |
|
151 |
|
152 EXPORT_C CCommsFactoryBase::CCommsFactoryBase(TUid aFactoryUid, CCommsFactoryContainer& aParentContainer) |
|
153 : CFactoryBase(aFactoryUid, aParentContainer) |
|
154 { |
|
155 LOG(ESockLog::Printf(KFactoryTag, _L("Factory(Uid : %d) is created."),aFactoryUid) ); |
|
156 } |
|
157 |
|
158 EXPORT_C CCommsFactoryBase::~CCommsFactoryBase() |
|
159 /** CCommsFactoryBase destructor |
|
160 */ |
|
161 { |
|
162 LOG(ESockLog::Printf(KFactoryTag, _L("Factory (Uid : %d) is destroyed"), this->Uid())); |
|
163 } |
|
164 |
|
165 EXPORT_C TInt CCommsFactoryBase::SendMessage( NetMessages::CMessage& aNetMessage ) |
|
166 /** Used to send an arbitrary message to the factory. The implementation is delegated to the |
|
167 derived class, if any |
|
168 @param aNetMessage NetMessages::CMessage reference specifying the message data and type |
|
169 @returns KErrNone on success, else KErrNotSupported */ |
|
170 { |
|
171 return DoReceiveMessage(aNetMessage); |
|
172 } |
|
173 |
|
174 EXPORT_C TInt CCommsFactoryBase::DoReceiveMessage( NetMessages::CMessage& /*aNetMessage*/ ) |
|
175 /** Default implementation for CCommsFactoryBase::SendMessage. This may be overridden by a |
|
176 derived class |
|
177 @see CCommsFactoryBase::SendMessage |
|
178 @released Since 9.1 */ |
|
179 { |
|
180 return KErrNotSupported; |
|
181 } |
|
182 |
|
183 EXPORT_C void CCommsFactoryBase::DoPostCreationL(ACommsFactoryNodeId* /*aObject*/,TFactoryQueryBase& /*aQuery*/) |
|
184 { |
|
185 // Specially left empty, to be overriden in child classes |
|
186 } |
|
187 |
|
188 // ACommsFactoryNodeId |
|
189 //======================================================================= |
|
190 EXPORT_C ACommsFactoryNodeId::~ACommsFactoryNodeId() |
|
191 { |
|
192 |
|
193 } |
|
194 |
|
195 EXPORT_C ACommsFactoryNodeId::ACommsFactoryNodeId(CCommsFactoryBase& aFactory) |
|
196 : AFactoryObject (aFactory) |
|
197 { |
|
198 } |
|
199 |
|
200 |
|
201 // CCFFactoryContainerBroker |
|
202 //-------------------------- |
|
203 |
|
204 void CCFFactoryContainerBroker::ReceivedL(const TRuntimeCtxId& aSender, const TNodeId& /*aRecipient*/, TSignatureBase& aMessage) |
|
205 { |
|
206 ESOCK_DEBUG_MESSAGE_INTERCEPT(aSender, aMessage, Id()); |
|
207 |
|
208 // What have we been sent? |
|
209 if(aMessage.IsMessage<TCFFactory::TFindOrCreatePeer>()) |
|
210 { |
|
211 TCFFactory::TFindOrCreatePeer& msg = message_cast<TCFFactory::TFindOrCreatePeer>(aMessage); |
|
212 |
|
213 // Find the relevant factory container in our client list |
|
214 RNodeInterface* interface = GetFirstClient<TDefaultClientMatchPolicy>(TCFPlayerRole(msg.iFactoryContainerType)); |
|
215 |
|
216 // Forward the 'find or create' message on to it with the originator as the sender |
|
217 if(interface) |
|
218 { |
|
219 interface->PostMessage(aSender, aMessage); |
|
220 } |
|
221 // Respond with an error if we can't find the relevant factory container |
|
222 else |
|
223 { |
|
224 RNodeInterface::OpenPostMessageClose( |
|
225 Id(), |
|
226 aSender, |
|
227 TEBase::TError(KErrNotFound).CRef()); |
|
228 } |
|
229 } |
|
230 else |
|
231 { |
|
232 __ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ESockSSocks_fct, 3)); //For debug configurations |
|
233 User::Leave(KErrNotSupported); //For release configurations |
|
234 } |
|
235 } |
|
236 |
|
237 CCFFactoryContainerBroker* CCFFactoryContainerBroker::NewL() |
|
238 { |
|
239 return new(ELeave) CCFFactoryContainerBroker(); |
|
240 } |
|
241 |
|
242 CCFFactoryContainerBroker::CCFFactoryContainerBroker() |
|
243 { |
|
244 LOG_NODE_CREATE(KESockBaseFactTag, CCFFactoryContainerBroker); |
|
245 } |
|
246 |