javaextensions/midppush/pushregistryplugin/inc/pushalarmhandler.h
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 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 "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 #ifndef PUSHALARMHANDLER_H
       
    20 #define PUSHALARMHANDLER_H
       
    21 
       
    22 #include <map>
       
    23 #include <memory>
       
    24 #include "pushtimercontainer.h"
       
    25 #include "pushalarmutilsinterface.h"
       
    26 
       
    27 namespace java
       
    28 {
       
    29 namespace captain
       
    30 {
       
    31 class CoreInterface;
       
    32 }
       
    33 namespace util
       
    34 {
       
    35 class Uid;
       
    36 }
       
    37 namespace push
       
    38 {
       
    39 
       
    40 class PushDBHandler;
       
    41 class PushAlarmHandler;
       
    42 
       
    43 /**
       
    44  * Alarm for automatic MIDlet launch can be set by this class.
       
    45  * I.e. this class implements functionality of PushRegistry.registerAlarm() java class.
       
    46  */
       
    47 
       
    48 class PushAlarmHandler : public PushTimerListener
       
    49 {
       
    50 public:
       
    51 
       
    52     PushAlarmHandler(java::captain::CoreInterface& aCore,
       
    53                      PushAlarmUtilsInterface& aLaunchInstance,
       
    54                      PushDBHandler& aDbHandler);
       
    55 
       
    56     virtual ~PushAlarmHandler();
       
    57 
       
    58     /**
       
    59      * Reads all alarms from the db and starts timers.
       
    60      * @throws This operation does not throw exceptions.
       
    61      */
       
    62     void readAndStartAlarms();
       
    63 
       
    64     /**
       
    65      * Reads and starts alarm of the application match to the Uid.
       
    66      * @param aUid UID of the application.
       
    67      * @throws This operation does not throw exceptions.
       
    68      */
       
    69     void readAndStartAlarms(const java::util::Uid& aUid);
       
    70 
       
    71     /**
       
    72      * Sets alarm to the application.
       
    73      * @param aUid                    UID of the application.
       
    74      * @param aAlarmTimeInMilliSecs   Time in milliseconds since January 1, 1970, 00:00:00 GMT.
       
    75      * @param aIsUidOfThisMidlet      indicates whether alarm is set to the current MIDlet.
       
    76      *                                i.e. whether alarm is set to the MIDlet where this operation
       
    77      *                                is called.
       
    78      * @return  0 is alarm was set successfully. Value of the alarm time if alarm is pending for a MIDlet.
       
    79      */
       
    80     long long setAlarm(const java::util::Uid& aUid,const long long& aAlarmTimeInMilliSecs,
       
    81                        bool aIsUidOfThisMidlet);
       
    82 
       
    83     /**
       
    84      * Cancels timer of the alarm.
       
    85      * @param aUid UID of the application.
       
    86      */
       
    87     void cancelAlarm(const java::util::Uid& aUid);
       
    88 
       
    89     /**
       
    90      * This method launches MIDlets which was not able to launch when alarm
       
    91      * expired due to missing drive.
       
    92      * This method does not launch MIDlet if expiration time is older
       
    93      * than two week.
       
    94      * @param aMediaId Media id of the added drive.
       
    95      * @throws This operation does not throw exceptions.
       
    96      */
       
    97     void handleDriveWasMissingMidlets(const unsigned int aMediaId);
       
    98 
       
    99     //Method of PushTimerListener interface.
       
   100     virtual void timerExpired(const java::util::Uid& aUid,const long long& aAlarmTime);
       
   101     virtual void deleteAlarm(const java::util::Uid& aUid);
       
   102 
       
   103 private:
       
   104 
       
   105     //Uid is MIdlet's uid.
       
   106     typedef std::map<java::util::Uid,long long> uidAlarmTimeContainer_t;
       
   107     typedef std::map<java::util::Uid,long long>::iterator uidAlarmTimeContainerIter_t;
       
   108 
       
   109     //Datamembers.
       
   110     java::captain::CoreInterface& mCore;
       
   111     PushDBHandler& mPushDbHandler;
       
   112     std::auto_ptr<PushTimerContainer> mPushTimer;
       
   113     PushAlarmUtilsInterface& mUtilsInstance;
       
   114     uidAlarmTimeContainer_t mNotLaunchedExpiredAlarms;
       
   115 
       
   116     //Internal operations.
       
   117     void handleLessOrEqualCurrentTimeOfOtherMidlet
       
   118     (const long long& aCurTimeInMilliSecs,const long long& aAlarmTimeInMilliSecs,
       
   119      const java::util::Uid& aUid);
       
   120     void timerExpired(const java::util::Uid& aUid,const long long& aAlarmTime,
       
   121                       bool aDeleteAlarmFromDb);
       
   122 
       
   123     //Not implemented.
       
   124     PushAlarmHandler(const PushAlarmHandler &x);
       
   125     PushAlarmHandler &operator=(const PushAlarmHandler &x);
       
   126 };
       
   127 
       
   128 } //end namespace push
       
   129 } //end namespace java
       
   130 
       
   131 #endif // PUSHALARMHANDLER_H
       
   132