|
1 /* |
|
2 * Copyright (c) 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 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of server session class. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "posindicatorserversession.h" |
|
19 #include "posindicatorservercore.h" |
|
20 #include "posindicatorserversubsession.h" |
|
21 #include "posindicatorserverconst.h" |
|
22 #include "posindicatorsubsessionregistry.h" |
|
23 #include "posindicatorlogger.h" |
|
24 |
|
25 //--------------------------------------------------------------- |
|
26 // CPosIndicatorServerSession::NewL |
|
27 //--------------------------------------------------------------- |
|
28 CPosIndicatorServerSession* CPosIndicatorServerSession::NewL( |
|
29 const CPosIndicatorServerCore& aServerCore ) |
|
30 { |
|
31 FUNC("CPosIndicatorServerSession::NewL"); |
|
32 CPosIndicatorServerSession* self = new( ELeave ) |
|
33 CPosIndicatorServerSession( aServerCore ); |
|
34 CleanupStack::PushL( self ); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop( self ); |
|
37 return self; |
|
38 } |
|
39 |
|
40 //--------------------------------------------------------------- |
|
41 // CPosIndicatorServerSession::CPosIndicatorServerSession |
|
42 //--------------------------------------------------------------- |
|
43 CPosIndicatorServerSession::CPosIndicatorServerSession( |
|
44 const CPosIndicatorServerCore& aServerCore ): |
|
45 iServerCore( aServerCore ) |
|
46 { |
|
47 FUNC("CPosIndicatorServerSession::CPosIndicatorServerSession"); |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CPosIndicatorServerSession::~CPosIndicatorServerSession |
|
52 // Destructor |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CPosIndicatorServerSession::~CPosIndicatorServerSession() |
|
56 { |
|
57 FUNC("CPosIndicatorServerSession::~CPosIndicatorServerSession"); |
|
58 delete iSubSessionRegistry; |
|
59 iServerCore.HandleSessionClosure(); |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // CPosIndicatorServerSession::ConstructL() |
|
64 // 2nd phase constructor for instantiating member variables |
|
65 // --------------------------------------------------------------------------- |
|
66 void CPosIndicatorServerSession::ConstructL() |
|
67 { |
|
68 FUNC("CPosIndicatorServerSession::ConstructL"); |
|
69 iSubSessionRegistry = CPosIndicatorSubSessionRegistry::NewL(); |
|
70 } |
|
71 |
|
72 //--------------------------------------------------------------- |
|
73 // CPosIndicatorServerSession::SecureId |
|
74 //--------------------------------------------------------------- |
|
75 void CPosIndicatorServerSession::ServiceL( const RMessage2 &aMessage ) |
|
76 { |
|
77 FUNC("CPosIndicatorServerSession::ServiceL"); |
|
78 switch( aMessage.Function() ) |
|
79 { |
|
80 case ESubSessionOpen: |
|
81 { |
|
82 FUNC("ESubSessionOpen"); |
|
83 CreateSubSessionL( aMessage ); |
|
84 break; |
|
85 } |
|
86 case ESubSessionClose: |
|
87 { |
|
88 FUNC("ESubSessionClose"); |
|
89 // Close the sub-session and free the sub-session object |
|
90 TInt retVal = iSubSessionRegistry->CloseSubSession( aMessage.Int3() ); |
|
91 aMessage.Complete( retVal ); |
|
92 break; |
|
93 } |
|
94 default: // Forward other messages to the sub-session |
|
95 { |
|
96 ForwardToSubSessionL( aMessage ); |
|
97 break; |
|
98 } |
|
99 } |
|
100 } |
|
101 |
|
102 //--------------------------------------------------------------- |
|
103 // CPosIndicatorServerSession::SecureId |
|
104 //--------------------------------------------------------------- |
|
105 void CPosIndicatorServerSession::ServiceError( const RMessage2& aMessage, |
|
106 TInt aError ) |
|
107 { |
|
108 FUNC("CPosIndicatorServerSession::ServiceError"); |
|
109 aMessage.Complete( aError ); |
|
110 } |
|
111 |
|
112 //--------------------------------------------------------------- |
|
113 // CPosIndicatorServerSession::Disconnect |
|
114 //--------------------------------------------------------------- |
|
115 void CPosIndicatorServerSession::Disconnect( const RMessage2& aMessage ) |
|
116 { |
|
117 FUNC("CPosIndicatorServerSession::Disconnect"); |
|
118 CSession2::Disconnect( aMessage ); |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CPosIndicatorServerSession::CreateSubSessionL |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 void CPosIndicatorServerSession::CreateSubSessionL( const RMessage2& aMessage ) |
|
126 { |
|
127 FUNC("CPosIndicatorServerSession::CreateSubSessionL"); |
|
128 CPosIndicatorServerSubsession* subSession = |
|
129 CPosIndicatorServerSubsession::NewL( |
|
130 *iServerCore.GetLocationRequestorHandle()); |
|
131 CleanupStack::PushL( subSession ); |
|
132 // If the NewL cannot allocate then it leaves with KErrMemory. In such a |
|
133 // scenario the ServiceError is invoked which responds to the IPC message |
|
134 // with the error code. Hence no special handling is required for |
|
135 // KErrNoMemory here. |
|
136 |
|
137 TInt subSessionHandle = iSubSessionRegistry->AddSubSessionL( subSession ); |
|
138 CleanupStack::Pop(subSession); // subSession ownership taken by registry |
|
139 |
|
140 // Set the client subsession identifier. |
|
141 TPckg<TInt> handlePackage( subSessionHandle ); |
|
142 TInt retVal = aMessage.Write( KParamSubsessionHandle,handlePackage ); |
|
143 |
|
144 // The error code from Write has to be handled as below, |
|
145 // If the retVal is an error code then |
|
146 // close the open subsession first. |
|
147 // If error is KErrBadDescriptor then panic the client |
|
148 // else complete the message with the error code. |
|
149 // else complete the message with KErrNone. |
|
150 if ( retVal != KErrNone ) |
|
151 { |
|
152 // close the open subsession first. |
|
153 iSubSessionRegistry->CloseSubSession( subSessionHandle ); |
|
154 } |
|
155 aMessage.Complete( retVal ); |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CPosIndicatorServerSession::ForwardToSubSessionL |
|
160 // --------------------------------------------------------------------------- |
|
161 void CPosIndicatorServerSession::ForwardToSubSessionL(const RMessage2& aMessage) |
|
162 { |
|
163 FUNC("CPosIndicatorServerSession::ForwardToSubSessionL"); |
|
164 CPosIndicatorServerSubsession* subSession = |
|
165 iSubSessionRegistry->SubSessionFromHandle(aMessage.Int3()); |
|
166 |
|
167 if (!subSession) |
|
168 { |
|
169 // Complete client's request if the sub-session handle is not |
|
170 // present in the registry |
|
171 aMessage.Complete( KErrNotFound ); |
|
172 } |
|
173 else |
|
174 { |
|
175 subSession->ServiceL(aMessage); |
|
176 } |
|
177 } |
|
178 // End of file. |