javaextensions/midppush/pushregistryplugin/inc/pushdbhandler.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 PUSHDBHANDLER_H
       
    20 #define PUSHDBHANDLER_H
       
    21 
       
    22 #include <memory>
       
    23 #include <string>
       
    24 #include <set>
       
    25 #include <map>
       
    26 #include "javastorage.h"
       
    27 #include "scopedlocks.h"
       
    28 #include "javauid.h"
       
    29 #include "pushconstant.h"
       
    30 
       
    31 namespace java
       
    32 {
       
    33 namespace push
       
    34 {
       
    35 
       
    36 /**
       
    37  * This class contains alarm information read from the Java Storage.
       
    38  */
       
    39 class DbAlarmData
       
    40 {
       
    41 public:
       
    42 
       
    43     /**
       
    44      * @param aUid              UID of the application.
       
    45      * @param aTimeInMilliSecs  Alarm time in milliseconds.
       
    46      * @param aValidateTime     Indicates whether alarm time must be validate. In practice
       
    47      *                          this means check weather alarm has expired.
       
    48      */
       
    49     DbAlarmData(const java::util::Uid& aUid,
       
    50                 const long long& aTimeInMilliSecs,bool aValidateTime);
       
    51 
       
    52     virtual ~DbAlarmData();
       
    53 
       
    54     DbAlarmData(const DbAlarmData&);
       
    55 
       
    56     const java::util::Uid& getUid() const;
       
    57 
       
    58     long long getTime() const;
       
    59 
       
    60     bool validateAlarmTime() const;
       
    61 
       
    62     DbAlarmData &operator=(const DbAlarmData&);
       
    63 
       
    64 private:
       
    65 
       
    66     //Datamembers.
       
    67     java::util::Uid mUid;
       
    68     long long mTimeInMilliSecs;
       
    69     bool mValidateTime;
       
    70 };
       
    71 
       
    72 class MidletSuiteData
       
    73 {
       
    74 public:
       
    75 
       
    76     MidletSuiteData(const java::util::Uid& aMidletUid,const std::wstring& aMidletClassName)
       
    77             : mMidletUid(aMidletUid),mMidletClassName(aMidletClassName),mMediaId(UNDEFINED_MEDIA_ID) {}
       
    78 
       
    79     virtual ~MidletSuiteData() {}
       
    80 
       
    81     MidletSuiteData &operator=(const MidletSuiteData &x)
       
    82     {
       
    83         mMidletUid = x.mMidletUid;
       
    84         mMidletClassName = x.mMidletClassName;
       
    85         mMediaId = x.mMediaId;
       
    86         return *this;
       
    87     }
       
    88 
       
    89     MidletSuiteData(const MidletSuiteData& x)
       
    90     {
       
    91         *this = x;
       
    92     }
       
    93 
       
    94     java::util::Uid mMidletUid;
       
    95     std::wstring mMidletClassName;
       
    96     int mMediaId;
       
    97 };
       
    98 
       
    99 /**
       
   100  * This class manages reading/writing/deleting data from Java Storage.
       
   101  */
       
   102 class PushDBHandler
       
   103 {
       
   104 public:
       
   105 
       
   106     PushDBHandler();
       
   107 
       
   108     virtual ~PushDBHandler();
       
   109 
       
   110     /**
       
   111      * This operation stores dynamic push connnection into database. This operation assumes
       
   112      * that validation of arguments has been done by user.
       
   113      * @param aUid          UID of the MIDlet.
       
   114      * @param aUri          Push connection URI.
       
   115      * @param aMidletName   Class name of the MIdlet.
       
   116      * @param aFilter       Connection URL indicating which senders are allowed to cause
       
   117        *                      the MIDlet to be launched.
       
   118        * @throws              PushException with following error code:
       
   119        *                      DB_ERROR:
       
   120        *                      Inserting dynamic push connection to the database failed.
       
   121      */
       
   122     void storeDynamicPushRegistration(const java::util::Uid& aUid,
       
   123                                       const std::wstring& aUri,
       
   124                                       const std::wstring& aMidletName,
       
   125                                       const std::wstring& aFilter);
       
   126 
       
   127     /**
       
   128      * This operation deletes dynamic push registration from the db.
       
   129      * @param aUid    MIDlet's UID.
       
   130      * @param aUri    Push connection URI.
       
   131      * @throws        PushException with following error code:
       
   132      *                DB_ERROR:
       
   133      *                Deleting push registration failed to the db error.
       
   134      */
       
   135     void unregisterDynamicPushRegistration(const java::util::Uid& aUid,
       
   136                                            const std::wstring& aUri);
       
   137 
       
   138     /**
       
   139      * This operation stores MIDlet's wake-up time to the db.
       
   140      * @param aUid              MIDlet's UID.
       
   141      * @param aAlarmInMilliSecs Wake-up time in milliseconds.
       
   142      * @throws                  PushException with following error code:
       
   143      *                          DB_ERROR:
       
   144        *                          Deleting push registration failed to the db error.
       
   145      */
       
   146     void storeAlarm(const java::util::Uid& aUid, const long long& aAlarmInMilliSecs);
       
   147 
       
   148     /**
       
   149      * Deletes MIDlet's wake-up time from the db.
       
   150      * @param aUid  MIDlet's UID.
       
   151      * @throws      PushException with following error code:
       
   152      *              DB_ERROR:
       
   153        *              Deleting push registration failed to the db error.
       
   154      */
       
   155     void deleteAlarm(const java::util::Uid& aUid);
       
   156 
       
   157     /**
       
   158      * This operation returns push registrations by Uid.
       
   159      * @param aUid        All push registrations are read from the db if value of the uid is empty.
       
   160      *                    Otherwise is returned push registrations by uid.
       
   161      * @param aPushRegs   Output parameter. Contains all push registrations of all MIDlets.
       
   162      *                    Empty list is returned if phone does not have any
       
   163      *                    push registration.
       
   164      * @throws            PushException with following error code:
       
   165      *                    DB_ERROR:
       
   166        *                    Deleting push registration failed to the db error.
       
   167      */
       
   168     void getPushRegs(const java::util::Uid& aUid,
       
   169                      java::storage::JavaStorageApplicationList_t& aPushRegs);
       
   170 
       
   171     /**
       
   172      * This operation returns alarm times by Uid.
       
   173      * @param aUid        All alarms are read from the db if value of the uid is empty.
       
   174      *                    Otherwise is returned alarms by uid.
       
   175      * @param aAlarmList  Output parameter. List contains all MIDlets' alarm time and
       
   176      *                    UID. This operation does not do anything if no alarms has been defined
       
   177      *                    to the phone.
       
   178      */
       
   179     void getAlarms(const java::util::Uid& aUid,std::list<DbAlarmData>& aAlarmList);
       
   180 
       
   181     /**
       
   182      * This operation returns container which contains <MIDlet suite uid,MIDlet uid> value pairs.
       
   183      * @param aSuiteUid MIDlet suite UID of search condition. This can be also empty. All MIDlet suites
       
   184      *        are returned in that case.
       
   185      * @param aMidletSuiteInfo Output parameter. <MIDlet suite uid,MIDlet uid> value pairs.
       
   186      * @throws            PushException with following error code:
       
   187      *                    DB_ERROR:
       
   188        *                    Retrieving MIDlet Suite info failed.
       
   189      */
       
   190     void getMidletSuiteInfo(const java::util::Uid& aSuiteUid,
       
   191                             std::multimap<java::util::Uid,MidletSuiteData>& aMidletSuiteInfo);
       
   192 
       
   193     /**
       
   194      * This operation returns MIDlet Suite info by MIDlet uid.
       
   195      * @param aMidletUid MIDlet UID of search condition.
       
   196      * @param aMidletSuiteInfo Output parameter. <MIDlet suite uid,MIDlet uid> value pairs.
       
   197      * @throws            PushException with following error code:
       
   198      *                    DB_ERROR:
       
   199        *                    Retrieving MIDlet Suite info failed.
       
   200      */
       
   201     void getMidletSuiteInfoByMidletUid(const java::util::Uid& aMidletUid,
       
   202                                        std::multimap<java::util::Uid,MidletSuiteData>& aMidletSuiteInfo);
       
   203 
       
   204 private:
       
   205 
       
   206     //Datamembers.
       
   207     std::auto_ptr<java::storage::JavaStorage> mDbStorage;
       
   208     //java::util::ScopedMutex mMutex;
       
   209 
       
   210     //Internal operations.
       
   211     void getMidletSuiteInfo(const java::util::Uid& aUid,
       
   212                             const std::wstring& aSearchColumn,
       
   213                             std::multimap<java::util::Uid,MidletSuiteData>& aMidletSuiteInfo);
       
   214     void addMediaId(java::storage::JavaStorage& aStorageObj,
       
   215                     std::multimap<java::util::Uid,MidletSuiteData>& aMidletSuiteInfo);
       
   216     void getMediaId(java::storage::JavaStorage& aStorageObj,const java::util::Uid& aSuiteUid,
       
   217                     std::map<java::util::Uid,int>& aMediaIdContainer);
       
   218     void fillMidletId(const java::util::Uid& aSuiteUid,
       
   219                       std::map<java::util::Uid,int>& aMediaIdContainer,
       
   220                       java::storage::JavaStorageApplicationList_t& aFoundEntries);
       
   221     void fillAlarmData(std::list<DbAlarmData>& aAlarmList,
       
   222                        java::storage::JavaStorageApplicationList_t& aFoundEntries);
       
   223     void fillMidletSuiteInfo(std::multimap<java::util::Uid,MidletSuiteData>& aMidletSuiteInfo,
       
   224                              java::storage::JavaStorageApplicationList_t& aFoundEntries);
       
   225     bool getDbValueAsUid(java::storage::JavaStorageApplicationList_t::iterator& aIter,
       
   226                          java::storage::JavaStorageEntry& aFindPattern,java::util::Uid& aOutput);
       
   227     bool getDbValueAsLongLong(java::storage::JavaStorageApplicationList_t::iterator& aIter,
       
   228                               java::storage::JavaStorageEntry& aFindPattern,long long& aOutput);
       
   229     bool getDbValueAsInt(java::storage::JavaStorageApplicationList_t::iterator& aIter,
       
   230                          java::storage::JavaStorageEntry& aFindPattern,int& aOutput);
       
   231     bool getDbValueAsWStr(java::storage::JavaStorageApplicationList_t::iterator& aIter,
       
   232                           java::storage::JavaStorageEntry& aFindPattern,std::wstring& aOutput);
       
   233     void openDbStorage();
       
   234 
       
   235     //Not implemented.
       
   236     PushDBHandler(const PushDBHandler&);
       
   237     PushDBHandler& operator= (const PushDBHandler&);
       
   238 };
       
   239 
       
   240 }//end namespace push
       
   241 }//end namespace java
       
   242 
       
   243 #endif // PUSHDBHANDLER_H