adaptationlayer/tsy/simatktsy_dll/inc/sattimer.h
changeset 0 63b37f68c1ce
equal deleted inserted replaced
-1:000000000000 0:63b37f68c1ce
       
     1 /*
       
     2 * Copyright (c) 2007-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 the License "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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CSATTIMER_H
       
    21 #define CSATTIMER_H
       
    22 
       
    23 
       
    24 //  INCLUDES
       
    25 #include <e32base.h>        // base class cbase
       
    26 
       
    27 
       
    28 // CONSTANTS
       
    29 const TInt KEnvelopeMaxSize             = 0xFF;
       
    30 
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 class CSatMessHandler;
       
    34 class CTsySatMessaging;
       
    35 
       
    36 
       
    37 // CLASS DECLARATION
       
    38 
       
    39 /**
       
    40 *  Sat Timer class.
       
    41 *  This class handles timers in SAT. Class utilizes CPeriodic timer
       
    42 *  to provide desired functionality.
       
    43 *
       
    44 *  @lib SIMATKTSY.LIB
       
    45 *  @since Series 60 Series60_2.6
       
    46 */
       
    47 class CSatTimer : public CBase
       
    48     {
       
    49     public:  // Constructors and destructor
       
    50         
       
    51         /**
       
    52         * Two-phased constructor.
       
    53         * @since NCP 5.0
       
    54         * @param aSatMessHandler pointer to satmessagehandler class
       
    55         * @param aSatMessaging pointer to satmessaging class
       
    56         */
       
    57         static CSatTimer* NewL( CSatMessHandler* aSatMessHandler,
       
    58             CTsySatMessaging* aSatMessaging );
       
    59         
       
    60         /**
       
    61         * Destructor.
       
    62         * @since NCP 5.0
       
    63         */
       
    64         virtual ~CSatTimer();
       
    65         
       
    66         
       
    67     private:    // Constructors
       
    68 
       
    69         /**
       
    70         * C++ default constructor.
       
    71         * @since NCP 5.0
       
    72         * @param aSatMessHandler pointer to satmessagehandler class
       
    73         * @param aSatMessaging pointer to satmessaging class
       
    74         */
       
    75         CSatTimer( CSatMessHandler* aSatMessHandler,
       
    76             CTsySatMessaging* aSatMessaging );
       
    77 
       
    78         /**
       
    79         * By default Symbian 2nd phase constructor is private.
       
    80         * @since NCP 5.0
       
    81         */
       
    82         void ConstructL();        
       
    83     
       
    84 
       
    85     public: // New functions
       
    86 
       
    87         /**
       
    88         * Starts the timer with the provided id and duration.
       
    89         * If there is already timer with same id, older is replaced by the
       
    90         * new one
       
    91         * @since Series 60 Series60_2.6
       
    92         * @param aTimerId ID of timer
       
    93         * @param aTimerValue duration of timer in seconds
       
    94         * @return KErrNone or error code
       
    95         */ 
       
    96         TInt StartTimer( TInt aTimerId, TUint32 aTimerValue );
       
    97 
       
    98 
       
    99         /**
       
   100         * Deletes timer from the table
       
   101         * @since Series 60 Series60_2.6
       
   102         * @param TInt aTimerId: timer identifier
       
   103         * @return TInt: KErrNone or KErrNotFound 
       
   104         */
       
   105         TInt DeleteTimerById( TInt aTimerId );
       
   106 
       
   107         /**
       
   108         * Gets current value of timer by timer id
       
   109         * @since Series 60 Series60_2.6
       
   110         * @param TInt aTimerId: timer identifier
       
   111         * @return TUint32: Current timer value 
       
   112         */
       
   113         TUint32 GetCurrentValueOfTimerById( TInt aTimerId );
       
   114 
       
   115         /**
       
   116         * Sets status for ProactiveCommandOnGoing flag
       
   117         * @since Series 60 Series60_2.6
       
   118         * @param TBool aStatus: status for proactiveCommand
       
   119         * @return None
       
   120         */
       
   121         void SetProactiveCommandOnGoingStatus( TBool aStatus );
       
   122         
       
   123         /**
       
   124         * Clears the timer table. Used when SIM is reset.
       
   125         * @since Series 60 Series60_3.0
       
   126         * @param None
       
   127         * @return None
       
   128         */
       
   129         void ClearTimerTable();
       
   130         
       
   131         /**
       
   132         * Stores the envelope for possible need of resending
       
   133         * @since Series 60 Series60_3.0
       
   134         * @param TUint8 aTId Transaction id of envelope about to be sent
       
   135         * @param TDesC8& aEnvelope Envelope data
       
   136         * @return KErrNone or KErrAlreadyExists if envelope with same 
       
   137         *   transaction id exists.
       
   138         */
       
   139         TInt StoreEnvelope( const TUint8 aTId, const TDesC8& aEnvelope );
       
   140 
       
   141         /**
       
   142         * Activates the resending stored envelope. This will happen if the
       
   143         * sending of envelope failed and error code returned from the SIM
       
   144         * is supported by the CSatTimer.
       
   145         * @since Series 60 Series60_3.0
       
   146         * @param TUint8 aTId Transaction id of envelope to be activated
       
   147         * @param TUint8 aCause Error code returned from SIM (SW1)
       
   148         * @return KErrNone. KErrNotFound if envelope with given id is not 
       
   149         *   found. KErrNotSupported if usupported cause was given.
       
   150         */
       
   151         TInt ActivateEnvelopeResend( const TUint8 aTId, const TUint8 aCause );
       
   152 
       
   153         /**
       
   154         * Removes the requested envelope from the envelope table.
       
   155         * @since Series 60 Series60_3.0
       
   156         * @param TUint8 aTId Transaction id of envelope about to be removed.
       
   157         * @param TBool aRemoveTimer If the envelope typ is a timer expiration, 
       
   158         *   It shall be removed also from internal timer table as a default.
       
   159         * @return KErrNone or KErrNotFound if envelope with given id coun't be
       
   160         *   found.
       
   161         */
       
   162         TInt RemoveEnvelope( const TUint8 aTId, TBool aRemoveTimer = ETrue );
       
   163 
       
   164 
       
   165     private:
       
   166 
       
   167         /**
       
   168         * Callback function that shall be called when timer is active.
       
   169         * @since Series 60 Series60_3.0
       
   170         * @param TAny* aSatTimer Reference to SatTimer
       
   171         * @return None
       
   172         */
       
   173         static TInt Tick( TAny* aSatTimer ); 
       
   174 
       
   175         /**
       
   176         * Starts the timer if it's not already running.
       
   177         * @since Series 60 Series60_3.0
       
   178         * @param None
       
   179         * @return None
       
   180         */
       
   181         void Start();
       
   182 
       
   183         /**
       
   184         * Stops the timer counting if there are no active timers
       
   185         * or delayed envelopes 
       
   186         * @since Series 60 Series60_3.0
       
   187         * @param None
       
   188         * @return None
       
   189         */ 
       
   190         void Stop();    
       
   191 
       
   192         /**
       
   193         * Restarts the deactivated Sat timer.
       
   194         * @since Series 60 Series60_3.0
       
   195         * @param aTimerId Id of timer to be restarted-
       
   196         * @return KErrNone or KErrNotFound if timer with given id wasn't found
       
   197         */ 
       
   198         TInt RestartTimer( TInt aTimerId );            
       
   199 
       
   200         /**
       
   201         * Returns true if the timer exists in the timer table.
       
   202         * @since Series 60 Series60_3.0
       
   203         * @param TInt aTimerId: timer identifier 
       
   204         * @return TBool : ETrue if the timer has an entry in the table
       
   205                          EFalse otherwise.
       
   206         */
       
   207         TBool CheckTimerTable( TInt aTimerId );
       
   208 
       
   209         /**
       
   210         * Locates the position of the requested envelope within envelope table.
       
   211         * @since Series 60 Series60_3.0
       
   212         * @param TUint8 aTId Transaction id of envelope about to be located.
       
   213         * @return KErrNone or KErrNotFound if envelope with given id coun't be
       
   214         *   found.
       
   215         */
       
   216         TInt LocateEnvelope( const TUint8 aTId );
       
   217         
       
   218         
       
   219     private: // Enumerations, data types
       
   220         
       
   221         // Envelope types        
       
   222         enum TEnvelopeType
       
   223             {
       
   224             ETypeUnknown            = 0xD0,
       
   225             ESmsPpDownload          = 0xD1,
       
   226             ECellBroadcast          = 0xD2,
       
   227             EMenuSelection          = 0xD3,
       
   228             ECallControl            = 0xD4,
       
   229             EMoShortMessageControl  = 0xD5,
       
   230             EEventDownload          = 0xD6,
       
   231             ETimerExpiration        = 0xD7
       
   232             };
       
   233             
       
   234         // Supported causes for envelope resending
       
   235         enum TCause
       
   236             {
       
   237             ESimBusy                = 0x93,
       
   238             ERefManagement          = 0x94
       
   239             };        
       
   240 
       
   241         // Envelope struct
       
   242         struct TSatEnvelope
       
   243             {
       
   244             TUint8  iTId;       // Transaction id
       
   245             TUint8  iType;      // Type of envelope
       
   246             TUint8  iDelay;     // Delay in ticks
       
   247             TBool   iActive;    // Is resending active
       
   248             TBuf8<KEnvelopeMaxSize> iEnvelope;
       
   249             };
       
   250             
       
   251     private: // Private nested class 
       
   252            
       
   253         class TTimer
       
   254             {
       
   255             public: // Enumerations
       
   256             
       
   257             enum TState
       
   258                 {
       
   259                 ETicking,       // When timer is ticking
       
   260                 EBeingSent,     // When sending envelope
       
   261                 EWaitingForTr   // When sent during pcmd
       
   262                 };
       
   263             
       
   264             
       
   265             public: // Methods
       
   266                 /**
       
   267                 * Non default Constructor
       
   268                 * @since Series 60 Series60_2.6
       
   269                 * @param TInt iTimerId
       
   270                 * @param TUint32 iStartTime
       
   271                 * @param TUint32 iTimeStamp
       
   272                 */
       
   273                 TTimer( TInt iTimerId,
       
   274                         TUint32 iStartTime,
       
   275                         TUint32 iTimeStamp );
       
   276 
       
   277                 /**
       
   278                 * returns iTimeStamp from a TTimer
       
   279                 * @since Series 60 Series60_3.0
       
   280                 * @return TUint32: value of the iTimeStamp attribute
       
   281                 */
       
   282                 TUint32 TimeStamp();
       
   283 
       
   284                 /**
       
   285                 * returns iTimerId from a TTimer
       
   286                 * @since Series 60 Series60_3.0
       
   287                 * @return TInt: value of the iTimerId attribute
       
   288                 */
       
   289                 TInt Id();
       
   290 
       
   291                 /**
       
   292                 * returns iStartTime from a TTimer
       
   293                 * @since Series 60 Series60_3.0
       
   294                 * @return TUint32: value of the iStartTime attribute
       
   295                 */
       
   296                 TUint32 StartTime();
       
   297                 
       
   298                 /**
       
   299                 * Setter for timer's internal state.
       
   300                 * @param TBool aState Desired state
       
   301                 * @since NCP 5.1
       
   302                 * @return none
       
   303                 */                
       
   304                 void SetState( TState aState );
       
   305                 
       
   306                 /**
       
   307                 * Getter for timer's internal state.
       
   308                 * @since NCP 5.1
       
   309                 * @return State of a timer
       
   310                 */                
       
   311                 TState State();
       
   312                 
       
   313                 /**
       
   314                 * Returns ETrue if two entries are equal
       
   315                 * @since Series 60 Series60_3.0
       
   316                 * @param const TTimer& arg1
       
   317                 * @param const TTimer& arg2
       
   318                 * @return TBool: ETrue if two entries are equal
       
   319                 */
       
   320                 static TBool CompareEntries( const TTimer& arg1,
       
   321                     const TTimer& arg2 );
       
   322 
       
   323                 /**
       
   324                 * Returns order between two entries
       
   325                 * @since Series 60 Series60_3.0
       
   326                 * @param const CTableEntry& arg1
       
   327                 * @param const CTableEntry& arg2
       
   328                 * @return Tint: 0 if arg1 = arg2
       
   329                                 1 if arg1 > arg2
       
   330                                -1 else
       
   331                 */
       
   332                 static TInt OrderEntries( const TTimer& arg1,
       
   333                     const TTimer& arg2 );
       
   334 
       
   335             private: // Data members
       
   336 
       
   337                 // Timer identifier
       
   338                 TInt        iTimerId;
       
   339                 
       
   340                 // Timer start time
       
   341                 TUint32     iStartTime;
       
   342                 
       
   343                 // Time stamp
       
   344                 TUint32     iTimeStamp;
       
   345                 
       
   346                 // Timer state machine
       
   347                 TState      iState;
       
   348                 
       
   349             };        
       
   350 
       
   351     private: // Data members
       
   352 
       
   353         // Pointer to CSatMesshandler instance
       
   354         CSatMessHandler*        iSatMessHandler;
       
   355 
       
   356         // Pointer to CSatMessaging instance
       
   357         CTsySatMessaging*       iSatMessaging;
       
   358         
       
   359         // Counts the number of second passed since the timer was started
       
   360         TUint32                 iSecondsPassed;
       
   361         
       
   362         // Because timer ticks twice in a second, we need to keep track when
       
   363         // to update iSecondsPassed-member
       
   364         TBool                   iHalfSecondTick;    
       
   365 
       
   366         // Flag for proactiveCommandOnGoing status
       
   367         // True if proactive command is ongoing
       
   368         TBool                   iProactiveCommandOnGoing;
       
   369 
       
   370         // Pointer to the CPeriodic type timer. (ETel)
       
   371         CPeriodic*              iTimer; 
       
   372 
       
   373         // Pointer to the timer entry array
       
   374         RArray<TTimer>*         iTimerTable;
       
   375         
       
   376         // Pointer to the envelope entry array
       
   377         RArray<TSatEnvelope>*   iEnvelopeTable;   
       
   378 
       
   379     };
       
   380 
       
   381 #endif //CSATTIMER_H
       
   382 
       
   383 // End of File