|
1 // Copyright (c) 2006-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 @internalTechnology |
|
19 */ |
|
20 |
|
21 #include "ss_apiext_messages.h" |
|
22 #include <comms-infras/ss_api_ext.h> |
|
23 #include <comms-infras/ss_thread.h> |
|
24 #include <ss_glob.h> |
|
25 #include <comms-infras/es_api_ext.h> |
|
26 |
|
27 using namespace ESock; |
|
28 using namespace Elements; |
|
29 using namespace Messages; |
|
30 using namespace MeshMachine; |
|
31 |
|
32 // ----- TOpenExtensionInterface ----- |
|
33 |
|
34 void TOpenExtensionInterface::DispatchL(const TRuntimeCtxId& aSender, const TRuntimeCtxId& aRecipient) |
|
35 { |
|
36 const TNodeId& nodeId = address_cast<TNodeId>(aRecipient); |
|
37 TAny* itf = FetchInterfaceOrForwardMsgL(aSender, *this, nodeId.Node(), iInterfaceId); |
|
38 |
|
39 if(itf) |
|
40 { |
|
41 AExtensionInterfaceThickBase& baseItf = *static_cast<AExtensionInterfaceThickBase*>(itf); |
|
42 |
|
43 //This fn will not allow an interface to be reqistered twice |
|
44 SockManGlobals::Get()->iCommsApiExtRegister.RegisterInterfaceL(iInterfaceId, baseItf.MsgImplTid(), iClientId); |
|
45 |
|
46 //When completed with an error code (!=KErrNone), this responder will deregister interface for this client |
|
47 baseItf.OpenExtensionInterface(iClientId, nodeId, CCommsApiExtIpcOpenResponder::NewL(iInterfaceId, iClientId, iMessage)); |
|
48 // coverity [memory_leak] - the ownership of CCommsApiExtIpcOpenResponder::NewL(iInterfaceId, iClientId, iMessage) |
|
49 // is taken by the function, OpenExtensionInterface. No need to setup cleanup stack for memory leak |
|
50 } |
|
51 } |
|
52 |
|
53 void TOpenExtensionInterface::Error(const TRuntimeCtxId& /*aSender*/, const TRuntimeCtxId& /*aRecipient*/, TInt aError) |
|
54 { |
|
55 if (aError==KErrNotFound) |
|
56 { |
|
57 //This IPC call has not been served. |
|
58 aError=KErrNotSupported; |
|
59 } |
|
60 |
|
61 iMessage.Complete(aError); |
|
62 } |
|
63 |
|
64 DEFINE_MVIP_CTR(TOpenExtensionInterface) |
|
65 |
|
66 START_ATTRIBUTE_TABLE(TOpenExtensionInterface, KExtItfMsgImplementationUid, EOpenExtensionInterface) |
|
67 REGISTER_ATTRIBUTE(TOpenExtensionInterface, iClientId, TMeta<TUint>) |
|
68 REGISTER_ATTRIBUTE(TOpenExtensionInterface, iInterfaceId, TMeta<TSupportedCommsApiExt>) |
|
69 END_ATTRIBUTE_TABLE_BASE(TCFSigRMessage2Ext, ESignatureRMessage2) |
|
70 |
|
71 // ----- TCloseExtensionInterface ----- |
|
72 |
|
73 void TCloseExtensionInterface::DispatchL(const TRuntimeCtxId& aSender, const TRuntimeCtxId& aRecipient) |
|
74 { |
|
75 const TNodeId& nodeId = address_cast<TNodeId>(aRecipient); |
|
76 TAny* itf = FetchInterfaceOrForwardMsgL(aSender, *this, nodeId.Node(), iInterfaceId); |
|
77 |
|
78 if(itf) |
|
79 { |
|
80 AExtensionInterfaceThickBase& baseItf = *static_cast<AExtensionInterfaceThickBase*>(itf); |
|
81 baseItf.CloseExtensionInterface(iClientId); |
|
82 SockManGlobals::Get()->iCommsApiExtRegister.DeRegisterInterface(iInterfaceId, iClientId); |
|
83 iMessage.Complete(KErrNone); |
|
84 } |
|
85 } |
|
86 |
|
87 void TCloseExtensionInterface::Error(const TRuntimeCtxId& /*aSender*/, const TRuntimeCtxId& /*aRecipient*/, TInt /*aError*/) |
|
88 { |
|
89 // Anything to do? |
|
90 } |
|
91 |
|
92 DEFINE_MVIP_CTR(TCloseExtensionInterface) |
|
93 |
|
94 START_ATTRIBUTE_TABLE(TCloseExtensionInterface, KExtItfMsgImplementationUid, ECloseExtensionInterface) |
|
95 REGISTER_ATTRIBUTE(TCloseExtensionInterface, iClientId, TMeta<TUint>) |
|
96 REGISTER_ATTRIBUTE(TCloseExtensionInterface, iInterfaceId, TMeta<TSupportedCommsApiExt>) |
|
97 END_ATTRIBUTE_TABLE_BASE(TCFSigRMessage2Ext, ESignatureRMessage2) |
|
98 |
|
99 // ----- TCancelAndCloseAllClientExtItf ----- |
|
100 |
|
101 void TCancelAndCloseAllClientExtItf::DispatchL(const TRuntimeCtxId& aSender, const TRuntimeCtxId& aRecipient) |
|
102 { |
|
103 CancelCloseAllAndForwardMsgL(aSender, *this, address_cast<TNodeId>(aRecipient).Node()); |
|
104 } |
|
105 |
|
106 void TCancelAndCloseAllClientExtItf::Error(const TRuntimeCtxId& /*aSender*/, const TRuntimeCtxId& /*aRecipient*/, TInt /*aError*/) |
|
107 { |
|
108 // Anything to do? |
|
109 } |
|
110 |
|
111 TBool ESock::TCommsClientSideApiExt::IsSupported(TSupportedCommsApiExt aApiExtensionId) |
|
112 { |
|
113 const TInt KEndOfUidListSentinelUid = 0x102864E6; |
|
114 |
|
115 const TSupportedCommsApiExt iList[] = |
|
116 { |
|
117 EMobilityApiExt, |
|
118 ELegacySubConnectionActiveApiExt, |
|
119 EDataMonitoringApiExt, |
|
120 ELegacyEnumerateSubConnectionsApiExt, |
|
121 // End of list |
|
122 (TSupportedCommsApiExt)KEndOfUidListSentinelUid |
|
123 }; |
|
124 |
|
125 for(TInt index = 0; iList[index] != KEndOfUidListSentinelUid; index++) |
|
126 { |
|
127 if(iList[index] == aApiExtensionId) |
|
128 { |
|
129 return ETrue; |
|
130 } |
|
131 } |
|
132 |
|
133 return EFalse; |
|
134 } |
|
135 |
|
136 //MZ: This current hard-coded routing (and closing) behaviour is not ideal. |
|
137 //We should migrate ESockSvr to the solution in Den, |
|
138 //where each session & subsession has its own API ext register |
|
139 //and closes all opened extension when going out of scope. |
|
140 void TCancelAndCloseAllClientExtItf::CancelCloseAllAndForwardMsgL(const TRuntimeCtxId& aSender, TSignalBase& aMessage, Messages::ANode& aNode) |
|
141 { |
|
142 NetInterfaces::TInterfaceControl* ic = aNode.FetchNodeInterfaceControlL(AMMNodeBase::KInterfaceId); |
|
143 NetInterfaces::TInterfaceIter itfIter(*ic); |
|
144 |
|
145 TCommsApiExtRegister& itfRegister = SockManGlobals::Get()->iCommsApiExtRegister; |
|
146 TAny* itf = itfIter[0]; |
|
147 |
|
148 while(itf) |
|
149 { |
|
150 TInt itfId = itfIter.ItfId(); |
|
151 |
|
152 if(TCommsClientSideApiExt::IsSupported((TSupportedCommsApiExt)itfId)) |
|
153 { |
|
154 AExtensionInterfaceThickBase& baseItf = *static_cast<AExtensionInterfaceThickBase*>(itf); |
|
155 if (iClientId!=0) |
|
156 { |
|
157 baseItf.CancelExtensionInterface(iClientId); |
|
158 baseItf.CloseExtensionInterface(iClientId); |
|
159 itfRegister.DeRegisterInterface(itfId, iClientId); |
|
160 } |
|
161 else |
|
162 { |
|
163 //TCommsApiExtRegisterClientIter clientIter(itfId, itfRegister); |
|
164 TUint client = itfRegister.FirstClient(itfId); |
|
165 while (client!=0) |
|
166 { |
|
167 baseItf.CancelExtensionInterface(client); |
|
168 baseItf.CloseExtensionInterface(client); |
|
169 client = itfRegister.DeRegisterInterface(itfId, client); |
|
170 } |
|
171 } |
|
172 } |
|
173 itf = itfIter++; |
|
174 } |
|
175 ForwardMessageL(aSender, aMessage, aNode); |
|
176 } |
|
177 |
|
178 DEFINE_MVIP_CTR(TCancelAndCloseAllClientExtItf) |
|
179 |
|
180 START_ATTRIBUTE_TABLE(TCancelAndCloseAllClientExtItf, KExtItfMsgImplementationUid, ECancelAndCloseAllClientExtItf) |
|
181 REGISTER_ATTRIBUTE(TCancelAndCloseAllClientExtItf, iClientId, TMeta<TUint>) |
|
182 END_ATTRIBUTE_TABLE() |
|
183 |
|
184 // ----- TApiExtMsgDispatcher ----- |
|
185 |
|
186 void TApiExtMsgDispatcher::DispatchL(const TRuntimeCtxId& aSender, const TRuntimeCtxId& aRecipient) |
|
187 { |
|
188 const TNodeId& nodeId = address_cast<const TNodeId>(aRecipient); |
|
189 NetInterfaces::TInterfaceControl* tic = FetchInterfaceControlOrForwardMsgL(aSender, *this, nodeId.Node(), iResponseMsg.InterfaceId()); |
|
190 |
|
191 if (tic) |
|
192 { |
|
193 TBuf8<KMaxExtApiIpcMsgLength> msgDst; |
|
194 TCommsApiExtReqMsg* msg = static_cast<TCommsApiExtReqMsg*>(iResponseMsg.ReadClientReqMsg(msgDst)); |
|
195 User::LeaveIfError(msg? KErrNone : KErrNotSupported); |
|
196 //TODO: ASSERT(msg->IsTypeOf(TCommsApiExtReqMsg::TypeId())); |
|
197 msg->DispatchL(*tic, iClientId, iResponseMsg); |
|
198 } |
|
199 } |
|
200 |
|
201 void TApiExtMsgDispatcher::Error(const TRuntimeCtxId& /*aSender*/, const TRuntimeCtxId& /*aRecipient*/, TInt aError) |
|
202 { |
|
203 if (aError==KErrNotFound) |
|
204 { |
|
205 //This IPC call has not been served. |
|
206 aError=KErrNotSupported; |
|
207 } |
|
208 |
|
209 iResponseMsg.Complete(aError); |
|
210 } |
|
211 |
|
212 DEFINE_MVIP_CTR(TApiExtMsgDispatcher) |
|
213 |
|
214 START_ATTRIBUTE_TABLE(TApiExtMsgDispatcher, KExtItfMsgImplementationUid, EApiExtMsgDispatcher) |
|
215 REGISTER_ATTRIBUTE(TApiExtMsgDispatcher, iClientId, TMeta<TUint>) |
|
216 REGISTER_ATTRIBUTE(TApiExtMsgDispatcher, iResponseMsg, TMeta<Elements::RResponseMsg>) |
|
217 END_ATTRIBUTE_TABLE() |
|
218 |
|
219 const TImplementationProxy ExtItfMsgImplementationTable[] = |
|
220 { |
|
221 MVIP_CTR_ENTRY(EApiExtMsgDispatcher, TApiExtMsgDispatcher), |
|
222 MVIP_CTR_ENTRY(EOpenExtensionInterface, TOpenExtensionInterface), |
|
223 MVIP_CTR_ENTRY(ECloseExtensionInterface, TCloseExtensionInterface), |
|
224 MVIP_CTR_ENTRY(ECancelAndCloseAllClientExtItf, TCancelAndCloseAllClientExtItf) |
|
225 }; |
|
226 |
|
227 void TExtItfMsgTables::RegisterL() |
|
228 { |
|
229 TlsGlobals::Get().RegisterInterfaceL(TUid::Uid(KExtItfMsgImplementationUid), sizeof(ExtItfMsgImplementationTable) / sizeof(ExtItfMsgImplementationTable[0]), ExtItfMsgImplementationTable); |
|
230 } |
|
231 |
|
232 void TExtItfMsgTables::DeRegister() |
|
233 { |
|
234 TlsGlobals::Get().DeregisterInterface(TUid::Uid(KExtItfMsgImplementationUid)); |
|
235 } |
|
236 |
|
237 |
|
238 |
|
239 |