|
1 /* |
|
2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html." |
|
8 * Initial Contributors: |
|
9 * Nokia Corporation - initial contribution. |
|
10 * Contributors: |
|
11 * |
|
12 * Description: |
|
13 * MSRP Implementation |
|
14 * |
|
15 */ |
|
16 |
|
17 #include "E32cmn.h" |
|
18 |
|
19 #include "MSRPCommon.h" |
|
20 #include "CMSRPServer.h" |
|
21 #include "CMSRPServerSession.h" |
|
22 #include "CMSRPServerSubSession.h" |
|
23 #include <e32math.h> |
|
24 |
|
25 |
|
26 CMSRPServerSession::CMSRPServerSession(CMSRPServer& aServer) |
|
27 : CSession2(), iMSRPServer(aServer), iSubSessionList(_FOFF(CMsrpHandleObj,iLink)) |
|
28 { |
|
29 } |
|
30 |
|
31 |
|
32 CMSRPServerSession::~CMSRPServerSession() |
|
33 { |
|
34 CMsrpHandleObj* pHandleObj; |
|
35 TSglQueIter<CMsrpHandleObj> iter(iSubSessionList); |
|
36 pHandleObj = iter++; |
|
37 while ( pHandleObj ) |
|
38 { |
|
39 iSubSessionList.Remove(*pHandleObj); |
|
40 delete pHandleObj; |
|
41 pHandleObj = iter++; |
|
42 } |
|
43 |
|
44 iMSRPServer.SessionDeleted(); |
|
45 } |
|
46 |
|
47 |
|
48 CMSRPServerSession* CMSRPServerSession::NewLC( CMSRPServer& aServer ) |
|
49 { |
|
50 CMSRPServerSession* self = new(ELeave) CMSRPServerSession(aServer); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 |
|
57 CMSRPServerSession* CMSRPServerSession::NewL( CMSRPServer& aServer ) |
|
58 { |
|
59 CMSRPServerSession* self = CMSRPServerSession::NewLC(aServer); |
|
60 CleanupStack::Pop(self); |
|
61 return self; |
|
62 } |
|
63 |
|
64 |
|
65 void CMSRPServerSession::ConstructL() |
|
66 { |
|
67 MSRPLOG( "CMSRPServerSession::ConstructL" ); |
|
68 iMSRPServer.SessionCreated(); |
|
69 } |
|
70 |
|
71 /* The Client Server Session protocol |
|
72 MSRP sub session creation and deletion |
|
73 1. Client creates a MSRP sub session by sending a code EMSRPCreateSession. |
|
74 No other parameters are required. |
|
75 As a result of this the server returns it a handle to a the created sub-session. |
|
76 The returned handle is used in the client side reflection and is used by the |
|
77 client sub-session to communicate with the server side subsession. |
|
78 2. The Client deletes the MSRP sub session by sending a code EMSRPDeleteSession. |
|
79 The handle of the sub session to be deleted is send as a argument. |
|
80 |
|
81 */ |
|
82 void CMSRPServerSession::ServiceL( const RMessage2& aMessage ) |
|
83 { |
|
84 /* RProcess proc; |
|
85 RThread thread; |
|
86 MSRPLOG2( "CMSRPServerSession::ServiceL... Server Process Priority%d", proc.Priority()); |
|
87 MSRPLOG2( "CMSRPServerSession::ServiceL... Server Thread Priority%d", thread.Priority());*/ |
|
88 // Implements |
|
89 // - Handling of Session requests like Capability Query. |
|
90 // - Handling of Session requests like Application Capability checks. |
|
91 // - Creation/Deletion request for MSRP SubSessions. |
|
92 // - Dispatch of messages to relevant MSRP subsessions. |
|
93 |
|
94 MSRPLOG( "CMSRPServerSession::ServiceL() Entered" ); |
|
95 switch(aMessage.Function()) |
|
96 { |
|
97 case EMSRPCreateSubSession: |
|
98 MSRPLOG( "CMSRPServerSession::ServiceL... EMSRPCreateSubSession" ); |
|
99 CreateSubSessionL(aMessage); |
|
100 break; |
|
101 |
|
102 case EMSRPCloseSubSession: |
|
103 MSRPLOG( "CMSRPServerSession::ServiceL... EMSRPCloseSubSession" ); |
|
104 CloseSubSessionL(aMessage); |
|
105 break; |
|
106 |
|
107 default: |
|
108 MSRPLOG( "CMSRPServerSession::ServiceL... default" ); |
|
109 // Message for the subSession |
|
110 DispatchToSubSessionL(aMessage); |
|
111 break; |
|
112 } |
|
113 |
|
114 MSRPLOG( "CMSRPServerSession::ServiceL() Exit" ); |
|
115 |
|
116 } |
|
117 |
|
118 |
|
119 void CMSRPServerSession::CreateSubSessionL( const RMessage2& aMessage ) |
|
120 { |
|
121 MSRPLOG( "Entered createSubSessionL()" ); |
|
122 |
|
123 /* First notify the Server so that connections can be started */ |
|
124 iMSRPServer.CreatingSubSessionL( aMessage.Int0() ); |
|
125 |
|
126 CMSRPServerSubSession* subSession = CMSRPServerSubSession::NewL( *this, iMSRPServer.StateFactory()); |
|
127 CleanupStack::PushL(subSession); |
|
128 |
|
129 //check handle doesnt preexist or add current time to handle |
|
130 //generate new handle |
|
131 CMsrpHandleObj* handleObj = CMsrpHandleObj::NewL(subSession); |
|
132 |
|
133 CleanupStack::Pop(subSession); //Ownership with handleobj |
|
134 CleanupStack::PushL(handleObj); //dummy push |
|
135 iSubSessionList.AddLast(*handleObj); //ownership of handle with list |
|
136 CleanupStack::Pop(handleObj); //dummy pop |
|
137 |
|
138 WriteResponseL(aMessage, ESubSessionHandle, handleObj->Handle()); |
|
139 |
|
140 |
|
141 MSRPLOG2("CMSRPServerSession::CreateSubSessionL Created subsession with handle %d", handleObj->Handle()) |
|
142 aMessage.Complete(KErrNone); |
|
143 } |
|
144 |
|
145 |
|
146 void CMSRPServerSession::CloseSubSessionL( const RMessage2& aMessage ) |
|
147 { |
|
148 MSRPLOG( "Entered deleteSubSessionL()" ); |
|
149 // Locate the subSession and delete. |
|
150 TInt handle = aMessage.Int3(); |
|
151 CMsrpHandleObj* pHandleObj = FindHandle(handle); |
|
152 |
|
153 if(!pHandleObj) |
|
154 { |
|
155 _LIT(KBadHandle,"Bad Handle"); |
|
156 aMessage.Panic(KBadHandle,EBadSubsessionHandle); |
|
157 } |
|
158 |
|
159 iSubSessionList.Remove(*pHandleObj); |
|
160 delete pHandleObj; |
|
161 aMessage.Complete(KErrNone); |
|
162 } |
|
163 |
|
164 |
|
165 void CMSRPServerSession::DispatchToSubSessionL( const RMessage2& aMessage ) |
|
166 { |
|
167 MSRPLOG( "Entered dispatchToSubSession()" ); |
|
168 // Get the sub session handle |
|
169 TInt handle = aMessage.Int3(); |
|
170 MSRPLOG2( "Received aMessage for subSession ( %d ) ", aMessage.Int3()); |
|
171 CMsrpHandleObj* pHandleObj = FindHandle(handle); |
|
172 if(!pHandleObj) |
|
173 { |
|
174 _LIT(KBadHandle,"Bad Handle"); |
|
175 aMessage.Panic(KBadHandle,EBadSubsessionHandle); |
|
176 } |
|
177 pHandleObj->Subsession()->ServiceL(aMessage); |
|
178 |
|
179 } |
|
180 |
|
181 |
|
182 void CMSRPServerSession::WriteResponseL( const RMessage2& aMessage, |
|
183 TServerClientResponses aResponseItem, |
|
184 TInt aValue ) |
|
185 { |
|
186 MSRPLOG( "CMSRPServerSession::WriteResponseL..." ); |
|
187 //Package the interger value and do a write. |
|
188 TPckg< TInt > valuePackage(aValue); |
|
189 |
|
190 aMessage.WriteL(aResponseItem, valuePackage); |
|
191 } |
|
192 |
|
193 |
|
194 MMSRPConnectionManager& CMSRPServerSession::ConnectionManager() |
|
195 { |
|
196 return iMSRPServer.ConnectionManager(); |
|
197 } |
|
198 |
|
199 CMsrpHandleObj* CMSRPServerSession::FindHandle( TInt aHandle ) |
|
200 { |
|
201 CMsrpHandleObj* pHandleObj = NULL; |
|
202 TSglQueIter<CMsrpHandleObj> iter(iSubSessionList); |
|
203 |
|
204 pHandleObj = iter++; |
|
205 while ( pHandleObj ) |
|
206 { |
|
207 if(pHandleObj->Compare(aHandle)) |
|
208 break; |
|
209 pHandleObj = iter++; |
|
210 } |
|
211 return pHandleObj; |
|
212 } |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 // CHandleObj class function definitions |
|
218 |
|
219 CMsrpHandleObj* CMsrpHandleObj::NewL( CMSRPServerSubSession* aSubSession) |
|
220 { |
|
221 CMsrpHandleObj* self = new(ELeave) CMsrpHandleObj(aSubSession); |
|
222 CleanupStack::PushL(self); |
|
223 self->ConstructL(); |
|
224 CleanupStack::Pop(self); |
|
225 return self; |
|
226 } |
|
227 |
|
228 |
|
229 CMSRPServerSubSession* CMsrpHandleObj::Subsession() const |
|
230 { |
|
231 return iSubSession; |
|
232 } |
|
233 |
|
234 |
|
235 TUint CMsrpHandleObj::Handle() const |
|
236 { |
|
237 return iHandle; |
|
238 } |
|
239 |
|
240 |
|
241 TBool CMsrpHandleObj::Compare( TUint aHandle ) const |
|
242 { |
|
243 if (iHandle == aHandle) |
|
244 return ETrue; |
|
245 |
|
246 return EFalse; |
|
247 } |
|
248 |
|
249 |
|
250 CMsrpHandleObj::~CMsrpHandleObj() |
|
251 { |
|
252 delete iSubSession; |
|
253 } |
|
254 |
|
255 |
|
256 void CMsrpHandleObj::ConstructL() |
|
257 { |
|
258 iHandle = Math::Random(); |
|
259 } |
|
260 |
|
261 |
|
262 CMsrpHandleObj::CMsrpHandleObj( CMSRPServerSubSession* aSubSession) |
|
263 { |
|
264 iSubSession = aSubSession; |
|
265 } |