wvuing/IMPSAlwaysOnlinePlugin/src/CIMPSAlwaysOnlineScheduler.h
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Helper class for always online scheduling
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef __CIMPSALWAYSONLINESCHEDULER_H__
       
    21 #define __CIMPSALWAYSONLINESCHEDULER_H__
       
    22 
       
    23 //  INCLUDES
       
    24 #include "MPEngAOWaitObserver.h"
       
    25 #include "MIMPSSharedDataObserver.h"
       
    26 #include "MIMPSSharedData.h"
       
    27 #include "timpsaokeys.h"
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 class MIMPSScheduleObserver;
       
    31 class CPEngAOPluginTimer;
       
    32 class CIMPSAOKeys;
       
    33 
       
    34 /**
       
    35 *  The implementation for the always online scheduling
       
    36 *
       
    37 *  @lib PEngAOPlugin.lib
       
    38 *  @since 2.6
       
    39 */
       
    40 class CIMPSAlwaysOnlineScheduler : public CBase,
       
    41             public MPEngAOWaitObserver,
       
    42             public MIMPSSharedDataObserver
       
    43     {
       
    44 
       
    45     public:  // Enumerations
       
    46 
       
    47         /**
       
    48          * State of the scheduling
       
    49          */
       
    50         enum TIMPSAOPluginScheduleState
       
    51             {
       
    52             EIMPSAOPluginAlldayConnection = 0,
       
    53             EIMPSAOPluginNormalBeforeConnection = 1,
       
    54             EIMPSAOPluginNormalDuringConnection = 2,
       
    55             EIMPSAOPluginNormalAfterConnection = 3,
       
    56             EIMPSAOPluginOvernightOldConnection = 4,
       
    57             EIMPSAOPluginOvernightNoConnection = 5,
       
    58             EIMPSAOPluginOvernightNewConnection = 6,
       
    59             EIMPSAOPluginInvalidSchedule = 10
       
    60             };
       
    61 
       
    62         /**
       
    63         * The waiting state of the scheduler
       
    64         */
       
    65         enum TIMPSAOSchedulerWaitReason
       
    66             {
       
    67             EIMPSAOSchedulerNotWaiting = 0,
       
    68             EIMPSAOSchedulerWaitingForReconnect = 1,
       
    69             EIMPSAOSchedulerWaitingForDisconnect = 2,
       
    70             EIMPSAOSchedulerWaitingForAllDayConnRefresh = 3
       
    71             };
       
    72 
       
    73     public:  // Constructors and destructor
       
    74 
       
    75         /**
       
    76         * Two-phased constructor.
       
    77         * @param aKeys Shared datakeys and enumeration for retrieve
       
    78         *              right information
       
    79         */
       
    80         static CIMPSAlwaysOnlineScheduler* NewL( TIMPSAOKeys& aKeys );
       
    81 
       
    82         /**
       
    83         * Destructor.
       
    84         */
       
    85         virtual ~CIMPSAlwaysOnlineScheduler();
       
    86 
       
    87     public: // Functions from MIMPSMIMPSSharedDataObserver
       
    88 
       
    89         /**
       
    90         * Handles notify from permanent keys' changes
       
    91         * @see MIMPSMIMPSSharedDataObserver
       
    92         */
       
    93         void HandlePermanentKeyNotifyL( const TUid aUid,
       
    94                                         const TIMPSSharedKeys aKey );
       
    95 
       
    96         /**
       
    97         * Handles notify from temporary keys' changes
       
    98         * @see MIMPSMIMPSSharedDataObserver
       
    99         */
       
   100         void HandleTemporaryKeyNotifyL( const TUid aUid,
       
   101                                         const TIMPSSharedKeys aKey );
       
   102 
       
   103     public: // Functions from MPEngAOWaitObserver
       
   104 
       
   105         /**
       
   106         * @see MPEngAOWaitObserver
       
   107         */
       
   108         void HandleTimeWaited();
       
   109 
       
   110         /**
       
   111         * @see MPEngAOWaitObserver
       
   112         */
       
   113         void HandleTimeWaitedError( TInt aError );
       
   114 
       
   115     public: // New functions
       
   116 
       
   117         /**
       
   118         * Adds observer for this scheduler
       
   119         * @param aSchObserver observer for scheduled login/logouts or schedule changes
       
   120         */
       
   121         void SetObserver( MIMPSScheduleObserver *aSchObserver );
       
   122 
       
   123         /**
       
   124          * Scheduler starts schedule login/logout actions as set in settings and
       
   125          * stars observing settings changes.
       
   126          */
       
   127         void StartSchedulingL();
       
   128 
       
   129         /**
       
   130          * Stops login/logout scheduling and stops observing settings changes.
       
   131          */
       
   132         void StopScheduling();
       
   133 
       
   134         /**
       
   135          * Check if scheduled login is OK.
       
   136          * @return ETrue if scheduled login is OK, else EFalse
       
   137          */
       
   138         TBool IsScheduledLoginOk();
       
   139 
       
   140         /**
       
   141         * Mark the testing class a friend, because this class is not "public" class
       
   142         */
       
   143         friend class T_CIMPSAlwaysOnlineScheduler; // CSI: 36 # Only used for testing
       
   144 
       
   145     private:
       
   146 
       
   147         /**
       
   148         * C++ default constructor.
       
   149         * @param aKeys Shared datakeys and enumeration for retrieve
       
   150         *              right information
       
   151         */
       
   152         CIMPSAlwaysOnlineScheduler( TIMPSAOKeys& aKeys );
       
   153 
       
   154         /**
       
   155         * By default Symbian 2nd phase constructor is private.
       
   156         */
       
   157         void ConstructL();
       
   158 
       
   159         /*
       
   160         * Checks whether it's ok to do the login by the scheduled
       
   161         * setting or not. If not, starts to wait for the event.
       
   162         * If the login is allowed by schedule, starts to wait for
       
   163         * the next logout.
       
   164         */
       
   165         void CheckScheduledLoginSettings();
       
   166 
       
   167         /**
       
   168          * Checks if there is a connection scheduled for the
       
   169          * given day.
       
   170          * @param aToday The day the connection is queried for
       
   171          * @paran aConnectionDays The set connection days in the
       
   172          *		  shared data.
       
   173          * @return TBool ETrue if there's an connection on aToday
       
   174          */
       
   175         TBool ResolveIfConnectionToday( TInt aToday, TInt aConnectionDays );
       
   176 
       
   177         /**
       
   178          * Gets the connection days from the shared data key
       
   179          * @return TInt The bitmask of the user selected connection days
       
   180          */
       
   181         TInt ResolveConnectionDays();
       
   182 
       
   183         /**
       
   184          * Finds the next connection day
       
   185          * @param aToday Today's day's number
       
   186          * @paran aConnectionDays The set connection days in the
       
   187          *		  shared data.
       
   188          * @param aFindConnection ETrue if we are looking for next connection day
       
   189          * @return TInt How many days until next connection
       
   190          */
       
   191         TInt FindNextConnectionChangeDay( TInt aToday,
       
   192                                           TInt aConnectionDays,
       
   193                                           TBool aFindConnectionDay );
       
   194 
       
   195         /**
       
   196         * Resolves the connection hours
       
   197         * @param aTimeNow is the current time
       
   198         * @param aStartTime is the connection start time
       
   199         * @param aEndTime is the connection end time
       
   200         * @return TBool If overnight schedule
       
   201         */
       
   202         TInt FindNextConnectionHours( TTime aTimeNow,
       
   203                                       TTime& aStartTime,
       
   204                                       TTime& aEndTime );
       
   205 
       
   206         /**
       
   207          * Sets scheduled login state
       
   208          * @param aIsScheduledLoginOk ETrue if client should be logged in, else EFalse
       
   209          * @param aReason   Tells what scheduler is waiting according to schedule
       
   210          */
       
   211         void SetScheduledLogin( TBool aIsScheduledLoginOk,
       
   212                                 TIMPSAOSchedulerWaitReason aReason );
       
   213 
       
   214         /**
       
   215         * Starts the waiting timer
       
   216         * @param aTime, time for timer to lauch
       
   217         */
       
   218         void StartTimer( TTime aTime );
       
   219 
       
   220         /**
       
   221          * Parses time from string. Panics if time cannot be parsed.
       
   222          * @param aTime variable where to time is parsed
       
   223          * @param aTimeString to be parsed time in string format
       
   224          */
       
   225         void ParseTime( TTime& aTime, const TDesC& aTimeString );
       
   226 
       
   227         /**
       
   228          * Calculates time difference between two time values
       
   229          * in minutes. Panics if time difference calculation fails.
       
   230          * @param aTime time to where difference is calculated
       
   231          * @param aComparableTime time where aTime difference is calculated
       
   232          * @param aInterval time difference is stored to this variable.
       
   233          */
       
   234         void MinutesInterval( TTime aTime,
       
   235                               TTime aComparableTime,
       
   236                               TTimeIntervalMinutes& aInterval );
       
   237 
       
   238         /**
       
   239         * Returns the hour part of the connection time as integer.
       
   240         * Returns the given default if parsing fails.
       
   241         * @param aTime Time where from hour is parsed
       
   242         * @param aDefault Default value which is return if parsing fails
       
   243         * @return Parsed hour integer
       
   244         * @since 2.6
       
   245         */
       
   246         TInt Hour( const TDesC& aTime, TInt aDefault );
       
   247 
       
   248         /**
       
   249         * Returns the minute part of the connection time as integer
       
   250         * Returns the given default if parsing fails.
       
   251         * @param aTime Time where from minute is parsed
       
   252         * @param aDefault Default value which is return if parsing fails
       
   253         * @return Parsed minute integer
       
   254         * @since 2.6
       
   255         */
       
   256         TInt Minute( const TDesC& aTime, TInt aDefault );
       
   257 
       
   258     private:    // Data
       
   259 
       
   260         /// Shared data client to read common settings, owned
       
   261         MIMPSSharedData* iSharedDataClient;
       
   262 
       
   263         /// Listens settings changes, owned
       
   264         MIMPSSharedData* iSettingChangesNotifier;
       
   265 
       
   266         /// Timer for waiting connect and disconnects according to schedule.
       
   267         /// Owned.
       
   268         CPEngAOPluginTimer* iTimer;
       
   269 
       
   270         /// Tells if the scheduled login is in "should be logged in" state
       
   271         TBool iScheduledLoginOk;
       
   272 
       
   273         /// Defines the current wait reason of the Scheduler
       
   274         TIMPSAOSchedulerWaitReason iWaitReason;
       
   275 
       
   276         /// Observer for schedule changes, not owned
       
   277         MIMPSScheduleObserver* iScheduleObserver;
       
   278 
       
   279         /// shared data keys etc to get wanted information
       
   280         TIMPSAOKeys& iKeys;
       
   281 
       
   282         /// helper variable to track if scheduling is started or not
       
   283         TBool iSchedulingIsStarted;
       
   284 
       
   285         /// variable to track if current schedule check is
       
   286         /// scheduler startup check or timed check
       
   287         TBool iStartupCheckOngoing;
       
   288 
       
   289     };
       
   290 
       
   291 #endif      // __CIMPSALWAYSONLINESCHEDULER_H__
       
   292 
       
   293 // End of File