|
1 /* |
|
2 * Copyright (c) 2006-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: Message handler for contexts. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_CFMESSAGEHANDLERCONTEXT_H |
|
20 #define C_CFMESSAGEHANDLERCONTEXT_H |
|
21 |
|
22 #include "CFMessageHandlerBase.h" |
|
23 #include "cfcontextobject.h" |
|
24 #include "cfcontextsourceinterface.h" |
|
25 |
|
26 class CCFContextIndicationImpl; |
|
27 class CCFContextSubscription; |
|
28 class CCFContextQuery; |
|
29 class CCFContextObjectImpl; |
|
30 class CCFContextSourceCommand; |
|
31 |
|
32 /** |
|
33 * Context Framework server session message handler base class. |
|
34 */ |
|
35 NONSHARABLE_CLASS( CCFMessageHandlerContext ): |
|
36 public CCFMessageHandlerBase, |
|
37 public MCFContextSubscriptionListener, public MCFContextSource |
|
38 { |
|
39 private: |
|
40 |
|
41 // Subscription error |
|
42 struct TSubscriptionError |
|
43 { |
|
44 TInt iError; |
|
45 CCFContextObjectImpl* iContext; |
|
46 }; |
|
47 |
|
48 public: |
|
49 |
|
50 // Two phased constructors |
|
51 static CCFMessageHandlerContext* NewL( MCFExtendedContextInterface& aCF, |
|
52 MCFActionInterface& aActivatorEngine, |
|
53 MCFScriptInterface& aScriptInterface ); |
|
54 static CCFMessageHandlerContext* NewLC( MCFExtendedContextInterface& aCF, |
|
55 MCFActionInterface& aActivatorEngine, |
|
56 MCFScriptInterface& aScriptInterface ); |
|
57 |
|
58 // Destructor |
|
59 ~CCFMessageHandlerContext(); |
|
60 |
|
61 protected: // From base classes |
|
62 |
|
63 // From CCFMessageHandlerBase |
|
64 TBool HandleMessageL( const RMessage2& aMessage ); |
|
65 |
|
66 // From MCFContextSubscriptionListener |
|
67 void ContextIndicationL( CCFContextIndication* aIndication ); |
|
68 |
|
69 // From MCFContextSubscriptionListener |
|
70 TInt Client( RThread& aThread ) const; |
|
71 |
|
72 // From MCFContextSubscriptionListener |
|
73 void HandleContextSubscriptionError( TInt aError, |
|
74 const TDesC& aSource, |
|
75 const TDesC& aType ); |
|
76 |
|
77 private: // from MCFContextSource |
|
78 |
|
79 // from MCFContextSource |
|
80 void Subscribers( const TDesC& aContextSource, |
|
81 const TDesC& aContextType ); |
|
82 |
|
83 // from MCFContextSource |
|
84 void NoSubscribers( const TDesC& aContextSource, |
|
85 const TDesC& aContextType ); |
|
86 |
|
87 // from MCFContextSource |
|
88 void HandleCommand( const CCFContextSourceCommand& aCommand ); |
|
89 |
|
90 private: // New methods |
|
91 |
|
92 // Publishes a context |
|
93 TInt PublishContext( CCFContextObject& aContext, |
|
94 RThread& aClientThread ); |
|
95 |
|
96 // Adds a new subscription to CF |
|
97 TInt AddSubscription( CCFContextSubscription* aSubscription, |
|
98 RThread& aClientThread ); |
|
99 |
|
100 // Removes subscription |
|
101 void RemoveSubscription(CCFContextSubscription& aSubscription); |
|
102 |
|
103 // Starts receiving context indication |
|
104 void ReceiveContextIndicationMessageL( const RMessage2& aMessage ); |
|
105 |
|
106 // Cancels receive context indication message |
|
107 void CancelReceiveContextIndicationMessage(); |
|
108 |
|
109 // Requests context |
|
110 TInt RequestContext( CCFContextQuery& aContextQuery, |
|
111 RThread& aClientThread ); |
|
112 |
|
113 // Indicate subscription error |
|
114 void IndicateSubscriptionErrorL(); |
|
115 |
|
116 // Get next indication from queue |
|
117 void CompleteNextIndicationFromQueueL( const RMessage2& aMessage ); |
|
118 |
|
119 // Checks context indication queue |
|
120 void CheckContextIndicationQueueL(); |
|
121 |
|
122 // Write context request buffer into stream |
|
123 void CompleteRequestContextL( const RMessage2& aMessage ); |
|
124 |
|
125 // Handles error situations |
|
126 void DoHandleContextSubscriptionErrorL( TInt aError, |
|
127 const TDesC& aSource, |
|
128 const TDesC& aType ); |
|
129 |
|
130 private: // new message system |
|
131 |
|
132 void ReceiveMessageL( const RMessage2& aMessage ); |
|
133 |
|
134 // Cancels receive message |
|
135 void CancelReceiveMessage(); |
|
136 |
|
137 void CompleteNextMessageFromQueueL( const RMessage2& aMessage ); |
|
138 |
|
139 void CheckMessageQueueL(); |
|
140 |
|
141 // Leavable version from subscribers callback |
|
142 void SubscribersL( const TDesC& aContextSource, const TDesC& aContextType ); |
|
143 |
|
144 // Leavable version from no subscribers callback |
|
145 void NoSubscribersL( const TDesC& aContextSource, const TDesC& aContextType ); |
|
146 |
|
147 // Leavable version from handle command callback |
|
148 void HandleCommandL( const CCFContextSourceCommand& aCommand ); |
|
149 |
|
150 private: |
|
151 |
|
152 CCFMessageHandlerContext( MCFExtendedContextInterface& aCFContext, |
|
153 MCFActionInterface& aCFAction, |
|
154 MCFScriptInterface& aScriptInterface ); |
|
155 void ConstructL(); |
|
156 |
|
157 private: // Data |
|
158 |
|
159 // Receive message |
|
160 RMessage2 iReceiveMessage; |
|
161 |
|
162 // Context request buffer |
|
163 RContextObjectArray iContextRequestBuffer; |
|
164 |
|
165 // Context indication queue |
|
166 RPointerArray<CCFContextIndicationImpl> iIndicationQueue; |
|
167 |
|
168 // Own: Subscription errors |
|
169 RArray<TSubscriptionError> iSubscriptionErrors; |
|
170 |
|
171 // Receive message for context source related messages |
|
172 RMessage2 iReceiveContextSourceMsg; |
|
173 |
|
174 // Own: array of messages to client |
|
175 RPointerArray<HBufC8> iMessageQueue; |
|
176 }; |
|
177 |
|
178 #endif |