|
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 @internalComponent |
|
19 */ |
|
20 |
|
21 #include <mtp/tmtptyperequest.h> |
|
22 |
|
23 #include "cmtpclosesession.h" |
|
24 #include "cmtpconnection.h" |
|
25 #include "cmtpdataprovidercontroller.h" |
|
26 #include "cmtpdataprovider.h" |
|
27 #include "cmtpconnectionmgr.h" |
|
28 #include "mtpdevdppanic.h" |
|
29 #include "rmtpframework.h" |
|
30 |
|
31 /** |
|
32 Two-phase construction method |
|
33 @param aPlugin The data provider plugin |
|
34 @param aFramework The data provider framework |
|
35 @param aConnection The connection from which the request comes |
|
36 @return a pointer to the created request processor object |
|
37 */ |
|
38 MMTPRequestProcessor* CMTPCloseSession::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) |
|
39 { |
|
40 CMTPCloseSession* self = new (ELeave) CMTPCloseSession(aFramework, aConnection); |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(); |
|
43 CleanupStack::Pop(self); |
|
44 return self; |
|
45 } |
|
46 |
|
47 /** |
|
48 Destructor |
|
49 */ |
|
50 CMTPCloseSession::~CMTPCloseSession() |
|
51 { |
|
52 iSingletons.Close(); |
|
53 } |
|
54 |
|
55 /** |
|
56 Standard c++ constructor |
|
57 */ |
|
58 CMTPCloseSession::CMTPCloseSession(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) : |
|
59 CMTPRequestProcessor(aFramework, aConnection, 0, NULL) |
|
60 { |
|
61 |
|
62 } |
|
63 |
|
64 /** |
|
65 Second phase constructor. |
|
66 */ |
|
67 void CMTPCloseSession::ConstructL() |
|
68 { |
|
69 iSingletons.OpenL(); |
|
70 } |
|
71 |
|
72 /** |
|
73 Request checker |
|
74 */ |
|
75 TMTPResponseCode CMTPCloseSession::CheckRequestL() |
|
76 { |
|
77 TMTPResponseCode response = CMTPRequestProcessor::CheckRequestL(); |
|
78 if (response == EMTPRespCodeOK) |
|
79 { |
|
80 TUint32 sessionId = iRequest->Uint32(TMTPTypeRequest::ERequestParameter1); |
|
81 //default session (with id 0) should never be closed |
|
82 if (!iConnection.SessionWithMTPIdExists(sessionId) || sessionId == 0) |
|
83 { |
|
84 response = EMTPRespCodeSessionNotOpen; |
|
85 } |
|
86 } |
|
87 return response; |
|
88 } |
|
89 |
|
90 /** |
|
91 CloseSession request handler |
|
92 */ |
|
93 void CMTPCloseSession::ServiceL() |
|
94 { |
|
95 // Send response first before close the session |
|
96 SendResponseL(EMTPRespCodeOK); |
|
97 |
|
98 // The sessionId for closesession is always 0, the actual session ID to close is |
|
99 // stored in payload parameter 1. |
|
100 RemoveSessionL(iRequest->Uint32(TMTPTypeRequest::ERequestParameter1)); |
|
101 } |
|
102 |
|
103 |
|
104 /** |
|
105 Remove the session from the connection |
|
106 @param aSessionId the sessionId to be removed |
|
107 */ |
|
108 void CMTPCloseSession::RemoveSessionL(TUint32 aSessionId) |
|
109 { |
|
110 TUint connectionId = iConnection.ConnectionId(); |
|
111 CMTPConnectionMgr& connectionMgr = iSingletons.ConnectionMgr(); |
|
112 CMTPConnection& connection = connectionMgr.ConnectionL(connectionId); |
|
113 connection.SessionClosedL(aSessionId); |
|
114 } |
|
115 |
|
116 |
|
117 |
|
118 |