|
1 /* |
|
2 * Copyright (c) 2002-2008 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: CCFServSession class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CFServSession.h" |
|
20 |
|
21 #include <e32svr.h> |
|
22 |
|
23 #include "CFMessageHandlerBase.h" |
|
24 #include "CFMessageHandlerContext.h" |
|
25 #include "CFMessageHandlerAction.h" |
|
26 #include "CFMessageHandlerScript.h" |
|
27 #include "cfcommon.h" |
|
28 #include "cftrace.h" |
|
29 |
|
30 CCFServSession* CCFServSession::NewL( MCFExtendedContextInterface& aCFContext, |
|
31 MCFActionInterface& aCFAction, |
|
32 MCFScriptInterface& aScriptInterface ) |
|
33 { |
|
34 FUNC_LOG; |
|
35 |
|
36 CCFServSession* self |
|
37 = CCFServSession::NewLC( aCFContext, aCFAction, aScriptInterface ); |
|
38 CleanupStack::Pop(self); |
|
39 |
|
40 return self; |
|
41 } |
|
42 |
|
43 CCFServSession* CCFServSession::NewLC( MCFExtendedContextInterface& aCFContext, |
|
44 MCFActionInterface& aCFAction, |
|
45 MCFScriptInterface& aScriptInterface ) |
|
46 { |
|
47 FUNC_LOG; |
|
48 |
|
49 CCFServSession* self = new ( ELeave ) CCFServSession; |
|
50 CleanupStack::PushL( self ); |
|
51 self->ConstructL( aCFContext, aCFAction, aScriptInterface ); |
|
52 |
|
53 return self; |
|
54 } |
|
55 |
|
56 CCFServSession::~CCFServSession() |
|
57 { |
|
58 FUNC_LOG; |
|
59 |
|
60 iMessageHandlers.ResetAndDestroy(); |
|
61 } |
|
62 |
|
63 void CCFServSession::ConstructL( MCFExtendedContextInterface& aCFContext, |
|
64 MCFActionInterface& aCFAction, |
|
65 MCFScriptInterface& aScriptInterface ) |
|
66 { |
|
67 FUNC_LOG; |
|
68 |
|
69 // Create message handlers |
|
70 iMessageHandlers.InsertL( |
|
71 CCFMessageHandlerContext::NewL( aCFContext, aCFAction, aScriptInterface ), |
|
72 CCFMessageHandlerBase::EContextMessageHandler ); |
|
73 iMessageHandlers.InsertL( |
|
74 CCFMessageHandlerAction::NewL( aCFContext, aCFAction, aScriptInterface ), |
|
75 CCFMessageHandlerBase::EActionMessageHandler ); |
|
76 iMessageHandlers.InsertL( |
|
77 CCFMessageHandlerScript::NewL( aCFContext, aCFAction, aScriptInterface ), |
|
78 CCFMessageHandlerBase::EScriptMessageHandler ); |
|
79 } |
|
80 |
|
81 CCFServSession::CCFServSession() |
|
82 { |
|
83 FUNC_LOG; |
|
84 } |
|
85 |
|
86 // METHODS |
|
87 |
|
88 //----------------------------------------------------------------------------- |
|
89 // CCFServSession::ServiceL |
|
90 //----------------------------------------------------------------------------- |
|
91 // |
|
92 void CCFServSession::ServiceL( const RMessage2& aMessage ) |
|
93 { |
|
94 FUNC_LOG; |
|
95 CLIENT( aMessage ); |
|
96 |
|
97 TRAPD( error, DispatchMessageL( aMessage ) ); |
|
98 if( error ) |
|
99 { |
|
100 ERROR_1( error, "CCFServSession::ServiceL: Dispatch message failed: %d", error ); |
|
101 if( !aMessage.IsNull() ) |
|
102 { |
|
103 aMessage.Complete( error ); |
|
104 } |
|
105 } |
|
106 } |
|
107 |
|
108 //----------------------------------------------------------------------------- |
|
109 // CCFServSession::DispatchMessageL |
|
110 //----------------------------------------------------------------------------- |
|
111 // |
|
112 void CCFServSession::DispatchMessageL( const RMessage2 &aMessage ) |
|
113 { |
|
114 FUNC_LOG; |
|
115 |
|
116 // Forward message to handlers |
|
117 TBool handled = EFalse; |
|
118 TInt count = iMessageHandlers.Count(); |
|
119 for( TInt i = 0; i < count; i++ ) |
|
120 { |
|
121 handled = iMessageHandlers[i]->HandleMessageL( aMessage ); |
|
122 if( handled ) |
|
123 { |
|
124 break; |
|
125 } |
|
126 } |
|
127 |
|
128 // Unrecognized message, panic |
|
129 if( !handled ) |
|
130 { |
|
131 ERROR_GEN( "Unknown message from client!" ); |
|
132 PanicClient( aMessage, EBadRequest ); |
|
133 } |
|
134 } |
|
135 |
|
136 //----------------------------------------------------------------------------- |
|
137 // CCFServSession::PanicClient |
|
138 //----------------------------------------------------------------------------- |
|
139 // |
|
140 void CCFServSession::PanicClient( const RMessage2& aMessage, TInt aPanic ) |
|
141 { |
|
142 FUNC_LOG; |
|
143 |
|
144 _LIT(KTxtServer,"CFWSRVSESSION"); |
|
145 aMessage.Panic(KTxtServer,aPanic); |
|
146 } |
|
147 |
|
148 //----------------------------------------------------------------------------- |
|
149 // CCFServSession::Write |
|
150 //----------------------------------------------------------------------------- |
|
151 // |
|
152 void CCFServSession::Write( const RMessage2& aMessage, TInt aParam, |
|
153 const TDesC8& aDes, |
|
154 TInt anOffset ) |
|
155 { |
|
156 FUNC_LOG; |
|
157 |
|
158 TRAPD( ret,aMessage.WriteL( aParam, aDes, anOffset ) ) |
|
159 if( ret != KErrNone ) |
|
160 { |
|
161 PanicClient( aMessage, EBadDescriptor ); |
|
162 } |
|
163 } |