locationtriggering/ltstrategyengine/inc/lbttriggerview.h
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2006, 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:  Class definition of Trigger View
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_LBTTRIGGERVIEW_H
       
    20 #define C_LBTTRIGGERVIEW_H
       
    21 
       
    22 
       
    23 #include <e32cmn.h>
       
    24 #include <e32base.h>
       
    25 
       
    26 #include "lbttriggerkey.h"
       
    27 #include "lbttriggerviewobserver.h"
       
    28 #include "lbtcontainer.h"
       
    29 #include "lbttriggerfilterbyattribute.h"
       
    30 #include "lbtcontainerextendedtriggerinfo.h"
       
    31 #include "lbttriggerstatusobserver.h"
       
    32 #include "lbtstrategycommon.h"
       
    33 #include "lbtgeoareabase.h"
       
    34 
       
    35 /**
       
    36  * CLbtTriggerView is a container class that stores the list of triggers to be
       
    37  * supervised. An instance of this class is instantiated by CLbtStrategyEngine
       
    38  * The list of triggers is updated based on the location information obtained
       
    39  * by the strategy engine.
       
    40  */
       
    41 NONSHARABLE_CLASS( CLbtTriggerView ) : public CActive
       
    42 	
       
    43     {
       
    44 
       
    45 public:
       
    46 
       
    47     /**
       
    48      * Forward declaration
       
    49      */
       
    50     class TTriggerViewIter;
       
    51 
       
    52     /**
       
    53      * Factory function that instantiates an object of CLbtTriggerView
       
    54      */        
       
    55     static CLbtTriggerView* NewL( MLbtTriggerViewObserver* aObserver );
       
    56 
       
    57     /**
       
    58      * Checks for refresh requests that arrive from container
       
    59      */
       
    60     void CheckRefreshRequests();
       
    61      
       
    62     /**
       
    63      * Updates the list of triggers, to be used by strategy engine for 
       
    64      * supervision, based on the location information 
       
    65      */        
       
    66     void Refresh( TPositionInfo& aPosInfo, 
       
    67                   TLbtTriggerEventMask aEventMask,
       
    68                   RArray<TLbtTriggerId>& aTriggerID );
       
    69                         
       
    70     /**
       
    71      * Retrieves a list of triggers that were modified when a call to Refresh
       
    72      * is made
       
    73      */        
       
    74     void GetModifiedTriggers( RArray< TLbtTriggerId >& aList );
       
    75     
       
    76     /**
       
    77      * Retrieves triggers based on the specified ID
       
    78      */
       
    79     TBool GetTriggerByID( TLbtTriggerId aID, 
       
    80                                     CLbtContainerTriggerEntry*& aTriggerInfo );
       
    81                                     
       
    82     /**
       
    83      * Determines whether the view is empty
       
    84      */
       
    85     TBool IsEmpty();
       
    86     
       
    87     /**
       
    88      * Initializes the observer to monitor changes in container
       
    89      */
       
    90     void SetContainerObserver( MLbtContainerChangeEventObserver* aObserver );
       
    91     
       
    92     /**
       
    93      * Initializes observer to monitor trigger fire events
       
    94      */
       
    95     void SetTriggerStatusObserver( MLbtTriggerStatusObsrvr* aObserver );
       
    96     
       
    97     /**
       
    98      * Updates trigger information in the container
       
    99      */
       
   100     void UpdateTriggerInfo( CLbtGeoAreaBase::TGeoAreaType aAreaType,
       
   101                             TPositionInfo aPosInfo, 
       
   102                             CLbtContainerTriggerEntry* aTrigger, 
       
   103                             TLbtTriggerDataMask aDataMask );
       
   104                             
       
   105     /**
       
   106      * Checks for changes in nearest trigger information provided by strategy
       
   107      * engine. This method is invoked by strategy engine during supervision
       
   108      * to determine any changes in the nearest triggers.
       
   109      */
       
   110     void DetermineNearestTriggerChanges( RArray< TNearestTrigger >* aNearestTriggers );
       
   111     
       
   112     /**
       
   113      * Removes the observer to monitor changes in container
       
   114      */
       
   115     void RemContainerObserver();
       
   116 
       
   117     /**
       
   118      * Sets the internal trigger state to invalid. This method is called only 
       
   119      * when internal errors occur while operating on the Btree or when updates
       
   120      * from the container are erroneous
       
   121      */
       
   122     void InvalidateTrigger( TLbtTriggerId aKey );
       
   123     
       
   124         
       
   125     /**
       
   126      *
       
   127      */
       
   128     inline TInt CellTriggerCount() const;
       
   129     
       
   130     /**
       
   131      *
       
   132      */
       
   133     inline TInt CoordTriggerCount() const;
       
   134       
       
   135     /**
       
   136      * Returns an instance of the iterator used to parse through the trigger
       
   137      * information stored in the tree
       
   138      */
       
   139     TTriggerViewIter BeginL( CLbtGeoAreaBase::TGeoAreaType aPrimaryTriggerArea );
       
   140     
       
   141     
       
   142     /**
       
   143      * Returns an instance of the iterator used to parse through the trigger
       
   144      * information stored in the tree
       
   145      */
       
   146     TTriggerViewIter BeginL(CLbtGeoAreaBase::TGeoAreaType aPrimaryTriggerArea,
       
   147                           CLbtGeoAreaBase::TGeoAreaType aSecondaryTriggerArea);
       
   148     
       
   149     /**
       
   150      * Returns an instance of the iterator used to parse through the trigger
       
   151      * information stored in the tree based on the IDs specified
       
   152      */
       
   153     TTriggerViewIter Begin( RArray< TLbtTriggerId >* aID,
       
   154                             CLbtGeoAreaBase::TGeoAreaType aPrimaryTriggerArea );
       
   155 
       
   156     /**
       
   157      * Destructor
       
   158      */        
       
   159     ~CLbtTriggerView();
       
   160     
       
   161 public:
       
   162 
       
   163     /**
       
   164      * Trigger information that is stored in the BTree
       
   165      */
       
   166     typedef struct TTrigger
       
   167         
       
   168         {
       
   169         
       
   170         TLbtTriggerId                               key;
       
   171         
       
   172         TBool                                       validity;
       
   173         
       
   174         CLbtGeoAreaBase::TGeoAreaType               type;
       
   175         
       
   176         CLbtContainerTriggerEntry*                  info;        
       
   177         
       
   178         };   
       
   179         
       
   180     /**
       
   181      * An iterator class that is used to access trigger information present in 
       
   182      * trigger view. An instance of this class is used by strategy engine when 
       
   183      * accessing triggers successively during supervision
       
   184      */
       
   185     class TTriggerViewIter
       
   186         
       
   187         {
       
   188         
       
   189         public:
       
   190         
       
   191             /**
       
   192              * Default Constructor
       
   193              */
       
   194             TTriggerViewIter();
       
   195             
       
   196             /**
       
   197              * Constructor to initialize the handle to the Btree object
       
   198              */ 
       
   199             TTriggerViewIter( 
       
   200                         TBtreeFix< TTrigger, TLbtTriggerId >* aTriggerList,
       
   201                         CLbtGeoAreaBase::TGeoAreaType aPrimaryTriggerArea );
       
   202             
       
   203             /**
       
   204              * Constructor to initialize the handle to the Btree object
       
   205              */ 
       
   206             TTriggerViewIter( 
       
   207                         TBtreeFix< TTrigger, TLbtTriggerId >* aTriggerList,
       
   208                         CLbtGeoAreaBase::TGeoAreaType aPrimaryTriggerArea,
       
   209                         CLbtGeoAreaBase::TGeoAreaType aSecondaryTriggerArea );
       
   210             
       
   211             /**
       
   212              * Constructor to initialize the handle to the Btree object based 
       
   213              * on the specified IDs
       
   214              */
       
   215             TTriggerViewIter( 
       
   216                     TBtreeFix< TTrigger, TLbtTriggerId >* aTriggerList,
       
   217                                 RArray< TLbtTriggerId >* aTriggerIDs,
       
   218                                 CLbtGeoAreaBase::TGeoAreaType aPrimaryTriggerArea );
       
   219             
       
   220             /**
       
   221              * Constructor to initialize the handle to the Btree object based 
       
   222              * on the specified IDs
       
   223              */
       
   224             TTriggerViewIter( 
       
   225                     TBtreeFix< TTrigger, TLbtTriggerId >* aTriggerList,
       
   226                                 RArray< TLbtTriggerId >* aTriggerIDs,
       
   227                                 CLbtGeoAreaBase::TGeoAreaType aPrimaryTriggerArea,
       
   228                                 CLbtGeoAreaBase::TGeoAreaType aSecondaryTriggerArea );
       
   229 
       
   230             /**
       
   231              * Resets the iterator to point to the trigger element at the 
       
   232              * begining of the tree
       
   233              */
       
   234             TInt Reset();
       
   235             
       
   236             /**
       
   237              * Retrieves trigger information successively from the tree
       
   238              */
       
   239             TBool NextL( CLbtContainerTriggerEntry*& aTriggerInfo );
       
   240             
       
   241             
       
   242         private:
       
   243         
       
   244             /**
       
   245              * Index into the array of trigger IDs
       
   246              */
       
   247             TInt                                    iIndex;
       
   248             
       
   249             /**
       
   250              * TBtree Iterator
       
   251              */
       
   252             TBtreeMark                              iPos;
       
   253             
       
   254             /**
       
   255              * Flag to check if the last element in the Btree is reached
       
   256              */
       
   257             TBool                                   iLast;
       
   258 
       
   259             /**
       
   260              * Handle to the Btree object created by trigger view. Ownership
       
   261              * not acquired
       
   262              */
       
   263             TBtreeFix< TTrigger, TLbtTriggerId >*   iTree;
       
   264             
       
   265             /**
       
   266              * Array of trigger IDs. Ownership not acquired
       
   267              */
       
   268             RArray< TLbtTriggerId >*                iTrgArray;
       
   269             
       
   270             /**
       
   271              * Primary area object that needs to be retrieved
       
   272              */
       
   273             CLbtGeoAreaBase::TGeoAreaType            iPrimaryAreaType;
       
   274             
       
   275             /**
       
   276              * Secondary area object that needs to be retrieved
       
   277              */
       
   278             CLbtGeoAreaBase::TGeoAreaType            iSecondaryAreaType;
       
   279             
       
   280         };  // TTriggerViewIter
       
   281         
       
   282 private:
       
   283 
       
   284     /**
       
   285      * Default constructor
       
   286      */        
       
   287     CLbtTriggerView();
       
   288 
       
   289     /**
       
   290      * 2nd phase constuctor for instantiating member variables
       
   291      */
       
   292     void ConstructL( MLbtTriggerViewObserver* aObserver );
       
   293     
       
   294     /**
       
   295      * Initializes the Btree with the information obtained from container
       
   296      */
       
   297     void InitializeList();
       
   298     
       
   299     /**
       
   300      * Processes trigger modification requests from the list
       
   301      */
       
   302     void ProcessRefreshRequests();
       
   303     
       
   304     /**
       
   305      * Processes update requests from strategy engine
       
   306      */
       
   307      void ProcessUpdateRequests();
       
   308     
       
   309     /**
       
   310      * Makes an entry in the tree for the new trigger created in the system
       
   311      */
       
   312     void HandleTriggerCreationEvent();
       
   313     
       
   314     /**
       
   315      * Changes the entry in the tree in accordance to the modification to the
       
   316      * trigger information in the system
       
   317      */
       
   318     void HandleTriggerModificationEvent();
       
   319     
       
   320     /**
       
   321      * Removes the trigger entry from the tree
       
   322      */
       
   323     void HandleTriggerDeletionEvent( RArray< TLbtTriggerId >* aIDs );
       
   324     
       
   325     /**
       
   326      * Compares two trigger ID values. This method is used for sorting triggers
       
   327      * within an array
       
   328      */
       
   329     static TInt CompareByID(const TLbtTriggerId& src, const TLbtTriggerId& dst );
       
   330 
       
   331     /**
       
   332      * Retrieves triggers based on specific conditions. The method retrieves 
       
   333      * all triggers whose IDs are specified in the array (if provided) 
       
   334      */
       
   335     void GetTriggers( RArray< TLbtTriggerId >* aIDs = NULL );
       
   336     
       
   337     /**
       
   338      * Lists all the enabled and valid triggers present in the system
       
   339      */
       
   340     void ListEnabledAndValidTriggersL();
       
   341     
       
   342     /**
       
   343      * Method used to access the BTree instance to add entries. Also maintains 
       
   344      * the count of specific trigger types being inserted.
       
   345      */    
       
   346     void AddToTreeL( TLbtTriggerId aKey, CLbtContainerTriggerEntry* aEntry );
       
   347 
       
   348     /**
       
   349      * Method used to access the BTree instance to delete entries. Also 
       
   350      * maintains the count of specific trigger types being deleted.
       
   351      */    
       
   352     TBool DeleteFromTreeL( TLbtTriggerId aKey );
       
   353     
       
   354     /**
       
   355      * Find an entry in the tree based on the trigger Id
       
   356      */
       
   357     TBool FindInTreeL( TLbtTriggerId aKey, TTrigger& aEntry );
       
   358     
       
   359     /**
       
   360      * Completes the iRequestStatus with KErrNone 
       
   361      */
       
   362     void SetEvent();
       
   363     
       
   364 private: // from base class CActive
       
   365 
       
   366     /**
       
   367      * Request completion event handler
       
   368      */
       
   369     void RunL();
       
   370     
       
   371     /**
       
   372      * Called to cancel outanding requests
       
   373      */        
       
   374     void DoCancel();
       
   375     
       
   376 private:
       
   377 
       
   378     /**
       
   379      * States of trigger view
       
   380      */
       
   381     typedef enum TState
       
   382     
       
   383         {
       
   384         
       
   385         EInitialize = 1,
       
   386         
       
   387         ERefreshView,
       
   388         
       
   389         EProcessTriggerList,
       
   390         
       
   391         ERefreshContainer,
       
   392         
       
   393         EIdle
       
   394         
       
   395         };
       
   396 
       
   397     /**
       
   398      * Specifies current state of view
       
   399      */
       
   400     TState                                          iState;
       
   401 
       
   402     /**
       
   403      * A handle to the implementation of MTriggerObserver interface to report
       
   404      * a successful refresh operation completion
       
   405      */
       
   406     MLbtTriggerViewObserver*                        iObserver;
       
   407     
       
   408     /**
       
   409      * Handle to the container observer
       
   410      */
       
   411     MLbtContainerChangeEventObserver*               iContainerObserver;
       
   412     
       
   413     /**
       
   414      * Handle to Trigger Status observer
       
   415      */
       
   416     MLbtTriggerStatusObsrvr*                        iTriggerStatusObserver;
       
   417     
       
   418     /**
       
   419      * List of triggers that are to be supervised
       
   420      * This array only consists of pointers to trigger instances stored
       
   421      * in the container.
       
   422      */
       
   423     RPointerArray< CLbtContainerTriggerEntry >      iList;
       
   424     
       
   425     /**
       
   426      * Structure to contain the parameters used for processing requests to 
       
   427      * refresh trigger view
       
   428      */
       
   429     struct TRefRequestParam
       
   430     
       
   431         {
       
   432         
       
   433         TPositionInfo                               posInfo;
       
   434         
       
   435         TLbtTriggerEventMask                        eventMask;
       
   436         
       
   437         RArray< TLbtTriggerId >*                    triggerID;
       
   438         
       
   439         };
       
   440         
       
   441     /**
       
   442      * Structure that defines the parameters used for processing requests to
       
   443      * update container
       
   444      */
       
   445      struct TUpdateRequestParam
       
   446         
       
   447         {
       
   448         CLbtGeoAreaBase::TGeoAreaType               areaType;
       
   449         
       
   450         TPositionInfo                               posInfo;
       
   451         
       
   452         CLbtContainerTriggerEntry*                  trigger;
       
   453         
       
   454         TLbtTriggerDataMask                         dataMask;
       
   455         
       
   456         };
       
   457         
       
   458     /**
       
   459      *
       
   460      */
       
   461      TInt                                           iRequestID;
       
   462     
       
   463     /**
       
   464      *
       
   465      */
       
   466     TUint8                                          iRefReqCounter;
       
   467     
       
   468     /**
       
   469      *
       
   470      */
       
   471     TUint8                                          iUpdateReqCounter;
       
   472     
       
   473     /**
       
   474      *
       
   475      */
       
   476     TInt                                            iCellTriggerCount;
       
   477     
       
   478     /**
       
   479      *
       
   480      */
       
   481     TInt                                            iCoordTriggerCount;
       
   482     
       
   483     /**
       
   484      *
       
   485      */
       
   486     TBool                                           iRequestInitiated;
       
   487     
       
   488     /**
       
   489      *
       
   490      */
       
   491     TBool                                           iDelayedInitialization;
       
   492      
       
   493     /**
       
   494      * List of TRefRequestParam(s) identifying request(s) to refresh trigger 
       
   495      * view
       
   496      */
       
   497     RArray< TRefRequestParam >                      iRefRequestList;
       
   498     
       
   499     /**
       
   500      * List of TUpdateRequestParam(s) identifying request(s) to update container
       
   501      * These trigger updates are provided by strategy engine during supervision
       
   502      */
       
   503     RArray< TUpdateRequestParam >                   iUpdateRequestList;
       
   504 
       
   505     /**
       
   506      * List of modified triggers, if they exist
       
   507      */
       
   508     RArray< TLbtTriggerId >                         iModifiedTrgList;
       
   509         
       
   510     /**
       
   511      * Allocates memory to be used by the BTree to store trigger information
       
   512      */
       
   513     CMemPagePool*                                   iPool;
       
   514     
       
   515     /**
       
   516      * An instance of TBtreeFix to contain the list of enabled and valid 
       
   517      * triggers in the system
       
   518      */
       
   519     TBtreeFix< TTrigger, TLbtTriggerId >*           iTriggerList;
       
   520     
       
   521     /**
       
   522      * Instance of TLbtTriggerKey to manage key values to access trigger 
       
   523      * information stored in the Btree
       
   524      */
       
   525     TLbtTriggerKey                                  iKey;
       
   526     
       
   527     /**
       
   528      * Handle to the trigger container
       
   529      */
       
   530     CLbtContainer*                                  iTrgContainer;
       
   531     
       
   532     };
       
   533 
       
   534 
       
   535 /**
       
   536  *
       
   537  */
       
   538 inline TInt CLbtTriggerView::CellTriggerCount() const
       
   539     {
       
   540     return iCellTriggerCount;
       
   541     }
       
   542 
       
   543 
       
   544 /**
       
   545  *
       
   546  */
       
   547 inline TInt CLbtTriggerView::CoordTriggerCount() const
       
   548     {
       
   549     return iCoordTriggerCount;
       
   550     }
       
   551 
       
   552 
       
   553 #endif	// C_LBTTRIGGERVIEW_H