|
1 /* |
|
2 * Copyright (c) 2006 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: Server session adapter base class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "ximpsrvsessionadapter.h" |
|
21 #include "ximpsrv.h" |
|
22 #include "ximpsrvsession.h" |
|
23 #include "ximpsrvmessageimp.h" |
|
24 #include "ximppanics.h" |
|
25 #include "ximptrace.h" |
|
26 #include <e32base.h> |
|
27 |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CXIMPSrvSessionAdapter::CXIMPSrvSessionAdapter() |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 EXPORT_C CXIMPSrvSessionAdapter::CXIMPSrvSessionAdapter( MXIMPSrv& aServer ) |
|
34 : iServer( aServer ) |
|
35 { |
|
36 iServer.SessionCreated(); |
|
37 TRACE_1( _L("CXIMPSrvSessionAdapter[%d]::CXIMPSrvSessionAdapter()"), |
|
38 this ); |
|
39 } |
|
40 |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CXIMPSrvSessionAdapter::~CXIMPSrvSessionAdapter() |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 EXPORT_C CXIMPSrvSessionAdapter::~CXIMPSrvSessionAdapter() |
|
47 { |
|
48 delete iMessage; |
|
49 |
|
50 iServer.SessionDied(); |
|
51 delete iSessionImp; |
|
52 |
|
53 TRACE_1( _L("CXIMPSrvSessionAdapter[%d]::~CXIMPSrvSessionAdapter()"), |
|
54 this ); |
|
55 #if _BullseyeCoverage |
|
56 cov_write(); |
|
57 #endif |
|
58 } |
|
59 |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CXIMPSrvSessionAdapter::ServiceL() |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 EXPORT_C void CXIMPSrvSessionAdapter::ServiceL( const RMessage2& aMessage ) |
|
66 { |
|
67 __ASSERT_ALWAYS( !iCurrentMsg, |
|
68 User::Panic( NXIMPPrivPanic::KCategory, |
|
69 NXIMPPrivPanic::ECurrentMsgAlreadyExists ) ); |
|
70 |
|
71 //Non leaving allocation must be used here to prevent OOM leave |
|
72 //to ServiceError() method, without a valid iCurrentMsg |
|
73 //==> CurrentMsg absence triggers an assert in ServiceError() |
|
74 iCurrentMsg = CXIMPSrvMessageImp::NewOrNull( aMessage, |
|
75 ( MXIMPSrvMessage*& )iCurrentMsg, |
|
76 iMessage ); |
|
77 iMessage = NULL; |
|
78 |
|
79 //Handle the message |
|
80 MXIMPSrvSession* sessionImp = DoInstantiateSessionL( *iCurrentMsg ); |
|
81 |
|
82 if( sessionImp ) |
|
83 { |
|
84 CleanupDeletePushL( sessionImp ); |
|
85 |
|
86 __ASSERT_ALWAYS( !iSessionImp, |
|
87 iCurrentMsg->PanicClientAndLeaveL( |
|
88 NXIMPPanic::EOnSrvSessionImpAlreadyExists ) ); |
|
89 |
|
90 iSessionImp = sessionImp; |
|
91 CleanupStack::Pop(); //sessionImp; |
|
92 iCurrentMsg->Complete( KErrNone ); |
|
93 } |
|
94 |
|
95 else |
|
96 { |
|
97 __ASSERT_ALWAYS( iSessionImp, |
|
98 iCurrentMsg->PanicClientAndLeaveL( |
|
99 NXIMPPanic::EOnSrvSessionImpNotFound ) ); |
|
100 |
|
101 |
|
102 iSessionImp->TryHandleMessageL( *iCurrentMsg ); |
|
103 |
|
104 |
|
105 //If current message is still not-completed, inform client |
|
106 //that it tried to do something unknown |
|
107 __ASSERT_ALWAYS( !IsCurrentMessageValid(), |
|
108 iCurrentMsg->PanicClientAndLeaveL( |
|
109 NXIMPPanic::EOnSrvRequestNotUnderstood) ); |
|
110 } |
|
111 |
|
112 iMessage = iCurrentMsg; |
|
113 iCurrentMsg = NULL; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CXIMPSrvSessionAdapter::ServiceError() |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 EXPORT_C void CXIMPSrvSessionAdapter::ServiceError( const RMessage2& /*aMessage*/, |
|
121 TInt aError ) |
|
122 { |
|
123 //If assert below is triggered, it means that current message ownersip |
|
124 //is taken somewhere (to be completed asynchronously), but there has |
|
125 //happened a leave after ownership transfer |
|
126 |
|
127 //The place taking message ownership has to be fixed in this case |
|
128 //not to cause exeptions after ownership transfer |
|
129 __ASSERT_ALWAYS( iCurrentMsg, |
|
130 User::Panic( NXIMPPrivPanic::KCategory, |
|
131 NXIMPPrivPanic::ECurrentMsgNotFoundInServiceError ) ); |
|
132 |
|
133 |
|
134 //If assert below is triggered, it means that current message is already |
|
135 //completed, but there has happened a leave after completion |
|
136 |
|
137 //The place completing message has to be fixed in this case |
|
138 //not to cause exeptions after message completion |
|
139 __ASSERT_ALWAYS( !iCurrentMsg->IsCompleted(), |
|
140 User::Panic( NXIMPPrivPanic::KCategory, |
|
141 NXIMPPrivPanic::ECurrentMsgNotValidInServiceError ) ); |
|
142 |
|
143 |
|
144 TRACE_3( _L("CXIMPSrvSessionAdapter[%d]::ServiceError() in op[%d], code[%d]"), |
|
145 this, iCurrentMsg->Function(), aError ); |
|
146 |
|
147 |
|
148 iCurrentMsg->Complete( aError ); |
|
149 delete iCurrentMsg; |
|
150 iCurrentMsg = NULL; |
|
151 } |
|
152 |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CXIMPSrvSessionAdapter::Server() |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 EXPORT_C MXIMPSrv& CXIMPSrvSessionAdapter::Server() |
|
159 { |
|
160 return iServer; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CXIMPSrvSessionAdapter::IsCurrentMessageValid() |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 TBool CXIMPSrvSessionAdapter::IsCurrentMessageValid() |
|
168 { |
|
169 if( iCurrentMsg && !iCurrentMsg->IsCompleted() ) |
|
170 { |
|
171 return ETrue; |
|
172 } |
|
173 |
|
174 return EFalse; |
|
175 } |
|
176 |
|
177 |
|
178 |
|
179 // End of file |