2 * Copyright (c) 2003-2005 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Declares an API for the consumer applications to access the
15 * Application Interworking Framework.
23 #ifndef AIW_SERVICE_HANDLER_H
24 #define AIW_SERVICE_HANDLER_H
28 #include <AiwCommon.h>
34 // FUNCTION PROTOTYPES
36 // FORWARD DECLARATIONS
37 class CAiwServiceHandlerImpl;
42 * CAiwServiceHandler is the main class of the Application Interworking
43 * Framework. The Service Handler implements support for dynamically
44 * loadable service providers which offer services to consumer applications.
45 * The Service Handler maps consumers and service providers together via
46 * interests and data agreements and hides the consumers from the providers.
48 * SERVICE is any command or functionality offered by a provider to
49 * consumer. The service includes typically menu item UI elements,
50 * but it can also just an engine type of command which executes specific
51 * functionality and reports status back to the consumer.
53 * CONSUMER application accesses interesting services offered by
54 * service provider(s). The consumer uses only those services in which
55 * it is interested in. The interest is expressed using a set of criteria
58 * INTEREST is a list of criteria items.
60 * CRITERIA consists of set of attributes which guide the AIW Framework to use
61 * only those providers in which the consumer is interested in.
62 * The criteria consists of following attributes:
63 * - Criteria UID (we can allocate pre-defined criteria items).
64 * - Service command UID (we can allocate pre-defined commands).
65 * - Content MIME type (string).
66 * - Additional options (variant data type just in case).
68 * PROVIDER produces those services for a consumer that match the given criteria
69 * specified by the consumer. A provider can offer menu items and their command
70 * handling logic to the consumer applications. A provider can also offer base
71 * services that don't require any UI elements.
73 * DATA AGREEMENT is an agreement between consumer and provider about parameters
74 * needed to be passed in a use case.
76 * @lib ServiceHandler.lib
79 NONSHARABLE_CLASS(CAiwServiceHandler) : public CBase
81 public: // Construction & destruction
84 * Constructs a Service Handler instance.
86 IMPORT_C static CAiwServiceHandler* NewL();
89 * Constructs a Service Handler instance.
91 IMPORT_C static CAiwServiceHandler* NewLC();
96 IMPORT_C virtual ~CAiwServiceHandler();
101 * Resets the Service Handler, discards existing interest and unloads
102 * corresponding service providers.
104 IMPORT_C void Reset();
107 * Returns the amount of providers that fulfil the given criteria.
109 * @param aCriteria Criteria to match.
110 * @return Number of providers matching the criteria.
112 IMPORT_C TInt NbrOfProviders(const CAiwCriteriaItem* aCriteria);
114 public: // Interest handling
117 * Adds the given interest to the Service Handler from a resource and updates
118 * possibly existing old interest. Corresponding service providers are loaded.
119 * If a provider leaves during initialization, it is trapped by the Service Handler.
121 * @param aInterestResourceId ID of the resource containing criteria items.
122 * @leave KErrNotSupported CCoeEnv is not accessible.
125 IMPORT_C void AttachL(TInt aInterestResourceId);
128 * Adds given interest to the Service Handler from an array of criteria items.
129 * If a provider leaves during initialization, it is trapped by the Service Handler.
131 * @param aInterest Array of criteria items. Ownership is not transferred.
133 IMPORT_C void AttachL(const RCriteriaArray& aInterest);
136 * Gets the currently valid interest in use by the Service Handler.
138 * @param aInterest An array of returned criteria items, may be empty.
139 * Ownership is not transferred, i.e. the objects in the
140 * array must not be deleted.
142 IMPORT_C void GetInterest(RCriteriaArray& aInterest);
145 * Removes given interest from the Service Handler. Corresponding service
146 * providers are unloaded.
148 * @param aInterest Array of returned criteria items, may be empty.
150 IMPORT_C void DetachL(const RCriteriaArray& aInterest);
153 * Removes given interest from the Service Handler. Corresponding service
154 * providers are unloaded.
156 * @param aInterestResourceId ID of the resource containing criteria items.
157 * @leave KErrNotSupported CCoeEnv is not accessible.
159 IMPORT_C void DetachL(TInt aInterestResourceId);
162 * Returns criteria by ID.
164 * @param aId Criteria ID.
165 * @return Criteria item pointer matching the ID. Ownership is not transferred.
167 IMPORT_C const CAiwCriteriaItem* GetCriteria(TInt aId);
170 * Returns an empty instance of CAiwGenericParamList class. It can be
171 * used for example as an input parameter list for the Service Handler's
172 * API methods. This is just a convenience method and doesn't have
173 * to be used. If consumer wants to create input list by itself
174 * it is ok. If this method is used, the Service Handler takes care
175 * of deleting returned generic parameter list.
177 * @return An empty instance of CAiwGenericParameter list.
179 IMPORT_C CAiwGenericParamList& InParamListL();
182 * Returns an empty instance of CAiwGenericParamList class. The instance can be
183 * used for example as an output parameter list for Service Handler
184 * API methods. This is just a convenience method and doesn't have
185 * to be used. If consumer wants to create output list by itself
186 * it is ok. If this method is used, Service Handler takes care
187 * of deleting returned generic parameter list.
189 * @return An empty instance of CAiwGenericParameter list.
191 IMPORT_C CAiwGenericParamList& OutParamListL();
193 public: // Menu handling
196 * Initialises menu pane with service commands from a provider.
197 * This method must be called upon DynInitMenuPaneL of consumer
198 * application in order to let the provider to hook its menu items.
200 * @param aMenuPane Handle of the menu pane to initialise.
201 * @param aMenuResourceId The menu to be attached.
202 * @param aBaseMenuCmdId Base ID for the Service Handler to generate
203 * menu IDs for placeholders.
204 * @param aInParamList Input parameter list for provider's parameters checking.
205 * @leave KErrNotSupported CCoeEnv is not accessible.
206 * @leave KErrOverflow Consumer application has too many AIW placeholders in its menu.
207 * Currently, maximum 16 is supported.
209 IMPORT_C void InitializeMenuPaneL(
210 CEikMenuPane& aMenuPane,
211 TInt aMenuResourceId,
213 const CAiwGenericParamList& aInParamList);
216 * Initialises menu pane with service commands from a provider.
217 * This method must be called upon DynInitMenuPaneL of consumer
218 * application in order to let the provider to hook its menu items.
219 * In normal circumstances, the other variant of this method should be used.
222 * @param aMenuPane Handle of the menu pane to initialise.
223 * @param aMenuResourceId The menu to be attached.
224 * @param aBaseMenuCmdId Base ID for the Service Handler to generate
225 * menu IDs for placeholders.
226 * @param aInParamList Input parameter list for provider's parameters checking.
227 * @param aUseSubmenuTextsIfAvailable If the provider has specified alternative submenu
228 * texts for its menu items, those can be taken into use if this
229 * parameter is set to ETrue. This should be used only for manually
230 * created submenus. If using AIW_CASCADE_ID or
231 * AIW_INTELLIGENT_CASCADE_ID, the AIW framework can automatically
232 * decide whether to use the submenu texts or not, and this parameter
234 * @leave KErrNotSupported CCoeEnv is not accessible.
235 * @leave KErrOverflow Consumer application has too many AIW placeholders in its menu.
236 * Currently, maximum 16 is supported.
238 IMPORT_C void InitializeMenuPaneL(
239 CEikMenuPane& aMenuPane,
240 TInt aMenuResourceId,
242 const CAiwGenericParamList& aInParamList,
243 TBool aUseSubmenuTextsIfAvailable);
246 * Initialises menu pane with service commands from a provider.
247 * This method must be called upon DynInitMenuPaneL of consumer
248 * application in order to let the provider to hook its menu items.
249 * In normal circumstances, the other variant of this method should be used.
252 * @param aMenuPane Handle of the menu pane to initialise.
253 * @param aMenuResourceId The menu to be attached.
254 * @param aBaseMenuCmdId Base ID for the Service Handler to generate
255 * menu IDs for placeholders.
256 * @param aInParamList Input parameter list for provider's parameters checking.
257 * @param aUseSubmenuTextsIfAvailable If the provider has specified alternative submenu
258 * texts for its menu items, those can be taken into use if this
259 * parameter is set to ETrue. This should be used only for manually
260 * created submenus. If using AIW_CASCADE_ID or
261 * AIW_INTELLIGENT_CASCADE_ID, the AIW framework can automatically
262 * decide whether to use the submenu texts or not, and this parameter
264 * @param aSetAsItemSpecific Added commands are marked as item specific.
265 * @leave KErrNotSupported CCoeEnv is not accessible.
266 * @leave KErrOverflow Consumer application has too many AIW placeholders in its menu.
267 * Currently, maximum 16 is supported.
269 IMPORT_C void InitializeMenuPaneL(
270 CEikMenuPane& aMenuPane,
271 TInt aMenuResourceId,
273 const CAiwGenericParamList& aInParamList,
274 TBool aUseSubmenuTextsIfAvailable,
275 TBool aSetAsItemSpecific);
278 * Returns the service command ID associated to the menu command. If found, it means
279 * that there is a provider which can handle the menu command. Thus the command
280 * handling needs to be routed to the provider via ExecuteMenuCmdL.
282 * @param aMenuCmdId Menu command ID to be mapped to service cmd.
283 * @return Service command ID, KAiwCmdNone if no ID is found.
284 * @see ExecuteMenuCmdL
286 IMPORT_C TInt ServiceCmdByMenuCmd(TInt aMenuCmdId) const;
289 * Tells the provider to execute a menu command invoked by the consumer.
290 * Not supported if calling outside UI framework. Use ServiceCmdByMenuCmd to
291 * check if there is any provider for the menu command.
293 * @param aMenuCmdId The menu command to be executed.
294 * @param aInParamList Input data parameters, can be an empty list.
295 * @param aOutParamList Output data parameters, can be an empty list.
296 * @param aCmdOptions Options for the command, see TAiwServiceCmdOptions in AiwCommon.hrh.
297 * @param aCallback Callback for asynchronous command handling, parameter checking, etc.
298 * @leave KErrArgument Callback is missing when required.
299 * @leave KErrNotSupported No cmd matches given menu command or CCoeEnv is not accessible.
300 * @see ServiceCmdByMenuCmd
302 IMPORT_C void ExecuteMenuCmdL(
304 const CAiwGenericParamList& aInParamList,
305 CAiwGenericParamList& aOutParamList,
306 TUint aCmdOptions = 0,
307 MAiwNotifyCallback* aCallback= NULL);
310 * Attach menu related criteria items to the given menu.
311 * If a provider leaves during initialization, it is trapped by the Service Handler.
313 * @param aMenuResourceId Menu to be attached.
314 * @param aInterestResourceId Resource id for the interest list.
315 * @leave KErrNotSupported CCoeEnv is not accessible.
317 IMPORT_C void AttachMenuL(TInt aMenuResourceId, TInt aInterestResourceId);
320 * Attach menu related criteria items to the given menu.
321 * If a provider leaves during initialization, it is trapped by the Service Handler.
323 * @param aMenuResourceId Menu to be attached.
324 * @param aReader Resource reader for the interest list.
325 * @leave KErrNotSupported CCoeEnv is not accessible.
327 IMPORT_C void AttachMenuL(TInt aMenuResourceId, TResourceReader& aReader);
330 * Attach menu related criteria items to the given menu.
333 * @param aMenuResourceId Menu to be attached.
334 * @param aInterest Array of criteria items. Ownership is not transferred.
335 * @leave KErrNotSupported CCoeEnv is not accessible.
337 IMPORT_C void AttachMenuL(TInt aMenuResourceId, const RCriteriaArray& aInterest);
340 * Detach menu related criteria items from the given menu.
341 * In following cases this method just returns without doing anything:
342 * 1. If interest resource id is non-zero and CCoeEnv is not accessible.
343 * 2. If interest resource id is non-zero and there occurs an error when reading
344 * the interest (e.g. not enough memory).
346 * @param aMenuResourceId Menu to be detached.
347 * @param aInterestResourceId Resource id for the interest list. If NULL, all
348 * criteria items are detached from the given menu.
350 IMPORT_C void DetachMenu(TInt aMenuResourceId, TInt aInterestResourceId);
353 * Checks if there are menu providers attached to given menu id. Consumer
354 * application can use this information to decide whether a sub menu
355 * containing only AIW items should be hidden or not.
357 * @param aSubMenuId The menu id to be checked.
358 * @return ETrue if there isn't any menu providers attached to this menu.
361 IMPORT_C TBool IsSubMenuEmpty(TInt aSubMenuId);
364 * Returns boolean value indicating whether the given menu contains
365 * currently attached placeholders.
367 * @param aMenuResourceId Resource id of the menu to be queried.
368 * @return ETrue if aMenuResource contains currently attached placeholders.
371 IMPORT_C TBool IsAiwMenu(TInt aMenuResourceId);
374 * Handles AIW submenus. This method should be called from consumer application's
377 * @param aPane Menu pane to be handled.
378 * @return ETrue if aPane was an AIW submenu and it was handled.
379 * Consumer's DynInitMenuPaneL pane may now return.
380 * EFalse if aPane was not an AIW submenu and DynInitMenuPaneL should
383 IMPORT_C TBool HandleSubmenuL(CEikMenuPane& aPane);
386 * CEikMenuPane uses this method to inform AIF framework that a menu is launched.
387 * This method does not need to be called by any other component.
391 IMPORT_C static void ReportMenuLaunch();
393 public: // Generic Service Command handling
396 * Executes a service command for all providers. Otherwise similar to ExecuteMenuCmdL.
398 * @param aCmdId The command to be executed.
399 * @param aInParamList Input data parameters, can be an empty list.
400 * @param aOutParamList Output data parameters, can be an empty list.
401 * @param aCmdOptions Options for the command, see TAiwServiceCmdOptions in AiwCommon.hrh.
402 * @param aCallback Callback for asynchronous command handling, parameter checking, etc.
403 * @leave KErrArgument Callback is missing when required.
404 * @leave KErrNotSupported No provider supports the service.
406 IMPORT_C void ExecuteServiceCmdL(
408 const CAiwGenericParamList& aInParamList,
409 CAiwGenericParamList& aOutParamList,
410 TUint aCmdOptions = 0,
411 MAiwNotifyCallback* aCallback = 0);
415 CAiwServiceHandler();
418 CAiwServiceHandlerImpl* iImpl;
421 #endif // AIW_SERVICE_HANDLER_H