contextframework/cfw/inc/cfscriptengine/cfscriptsubscription.h
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2007-2007 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:  CCFScriptSubscription class declaration.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef C_CFSCRIPTSUBSCRIPTION_H
       
    21 #define C_CFSCRIPTSUBSCRIPTION_H
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32base.h>
       
    25 
       
    26 // FORWARD DECLARATIONS
       
    27 class MCFContextInterface;
       
    28 class MCFContextSubscriptionListener;
       
    29 class MCFScriptListener;
       
    30 class CCFContextSubscriptionImpl;
       
    31 class CCFContextObject;
       
    32 
       
    33 // CLASS DECLARATION
       
    34 
       
    35 /**
       
    36 *  Script subscription class provides a centralized context subscription for
       
    37 *  operations on Context Framework Scripts. Script subscription stores all
       
    38 *  operation subscriptions for a context and manages one real context
       
    39 *  subscription on Context Framework.
       
    40 *
       
    41 *  @lib CFScriptEngine
       
    42 *  @since S60 v5.0
       
    43 */
       
    44 NONSHARABLE_CLASS( CCFScriptSubscription ): public CBase
       
    45     {
       
    46 public: // Constructors and destructor
       
    47 
       
    48     /**
       
    49     * Creates a CCFScriptSubscription instance.
       
    50     * @param aCF is a reference to context interface.
       
    51     * @param aCFListener is a reference to context subscription listener.
       
    52     * @param aListener is a pointer to script listener, i.e. context operation.
       
    53     * @return a pointer to the created instance of CCFScriptSubscription.
       
    54     */
       
    55     static CCFScriptSubscription* NewL( MCFContextInterface& aCF,
       
    56             MCFContextSubscriptionListener& aCFListener,
       
    57             MCFScriptListener* aListener );
       
    58 
       
    59     /**
       
    60     * Creates a CCFScriptSubscription instance.
       
    61     * @param aCF is a reference to context interface.
       
    62     * @param aCFListener is a reference to context subscription listener.
       
    63     * @param aListener is a pointer to script listener, i.e. context operation.
       
    64     * @return a pointer to the created instance of CCFScriptSubscription.
       
    65     */
       
    66     static CCFScriptSubscription* NewLC( MCFContextInterface& aCF,
       
    67             MCFContextSubscriptionListener& aCFListener,
       
    68             MCFScriptListener* aListener );
       
    69 
       
    70     /**
       
    71     * Destructor.
       
    72     */
       
    73     virtual ~CCFScriptSubscription();
       
    74 
       
    75 public: // New functions
       
    76 
       
    77     /**
       
    78     * Adds a script listener to this context subscription. Notifies the listener
       
    79     * about the current value of subscribed context.
       
    80     * @param aListener is a pointer to script listener, i.e. context operation.
       
    81     * @return None.
       
    82     */
       
    83     void AddListenerL( MCFScriptListener* aListener );
       
    84 
       
    85     /**
       
    86     * Removes a script listener from this context subscription. Removing the
       
    87     * last listener also removes the context subscription.
       
    88     * @param aListener is a pointer to script listener, i.e. context operation.
       
    89     * @return ETrue if there are no more listeners and the instance could be
       
    90     *   deleted, EFalse otherwise.
       
    91     */
       
    92     TBool RemoveListener( MCFScriptListener* aListener );
       
    93 
       
    94     /**
       
    95     * Checks whether the context subscription is a match with a script listener.
       
    96     * @param aListener is a pointer to script listener, i.e. context operation.
       
    97     * @return ETrue if the subscription is a match with the listener, EFalse
       
    98     *   otherwise.
       
    99     */
       
   100     TBool Match( const MCFScriptListener& aListener ) const;
       
   101 
       
   102     /**
       
   103     * Checks whether the context subscription is a match with a context.
       
   104     * @param aContext is a reference to a context.
       
   105     * @return ETrue if the subscription is a match with the context, EFalse
       
   106     *   otherwise.
       
   107     */
       
   108     TBool Match( const CCFContextObject& aContext ) const;
       
   109 
       
   110     /**
       
   111     * Notifies listeners about a context, i.e. evaluates context operations with
       
   112     * the context.
       
   113     * @param aContext is a reference to the context to be notified.
       
   114     * @param aContextLevelDelay is storage for context level delay requirement
       
   115     *   from the context operation evaluation.
       
   116     * @return ETrue if any listener executed actual evaluation, EFalse
       
   117     *   otherwise.
       
   118     */
       
   119     TBool NotifyListeners( const CCFContextObject& aContext,
       
   120             TInt& aContextLevelDelay ) const;
       
   121 
       
   122 protected:
       
   123 
       
   124     /**
       
   125     * C++ default constructor.
       
   126     */
       
   127     CCFScriptSubscription( MCFContextInterface& aCF,
       
   128             MCFContextSubscriptionListener& aCFListener );
       
   129 
       
   130     /**
       
   131     * By default Symbian 2nd phase constructor is private.
       
   132     */
       
   133     void ConstructL( MCFScriptListener* aListener );
       
   134 
       
   135 private: // New functions
       
   136 
       
   137     /**
       
   138     * Subscribes context requested by a listener and notifies the listener about
       
   139     * the current value of the context.
       
   140     * @param aListener is a pointer to script listener, i.e. context operation.
       
   141     * @return KErrNone if successful, otherwise any system wide error code.
       
   142     */
       
   143     TInt DoSubscribeL( MCFScriptListener* aListener );
       
   144 
       
   145     /**
       
   146     * Notifies a listener about the current value of a context it is interested.
       
   147     * @param aListener is a pointer to script listener, i.e. context operation.
       
   148     * @return None.
       
   149     */
       
   150     void NotifyListenerOfCurrentContextValueL(
       
   151             MCFScriptListener* aListener ) const;
       
   152 
       
   153 private: // Data
       
   154 
       
   155     // Context interface for managing subscriptions.
       
   156     MCFContextInterface& iCF;
       
   157 
       
   158     // Context subscription listener interface for managing subscriptions.
       
   159     MCFContextSubscriptionListener& iCFListener;
       
   160 
       
   161     // Flag telling whether subscription has been made (ownership transferred).
       
   162     TBool iSubscribed;
       
   163 
       
   164     // Context subscription for script listeners; when subscription has been
       
   165     // activated (SubscribeContext() called) the ownership has been transferred.
       
   166     CCFContextSubscriptionImpl* iSubscription;
       
   167 
       
   168     // Script listeners for the context subscription. Not owned.
       
   169     RPointerArray< MCFScriptListener > iListeners;
       
   170     };
       
   171 
       
   172 
       
   173 #endif // C_CFSCRIPTSUBSCRIPTION_H