harvester/contentinfodb/inc/contentinfodb.h
changeset 23 d4d56f5e7c55
equal deleted inserted replaced
20:556534771396 23:d4d56f5e7c55
       
     1 /*
       
     2  * Copyright (c) 2009 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:  contentinfodb .
       
    15  *
       
    16  */
       
    17 #ifndef CONTENTINFODB_H
       
    18 #define CONTENTINFODB_H
       
    19 #include <qobject.h>
       
    20 #include <QSqlDatabase>
       
    21 #include <qmutex.h>
       
    22 #include "contentinfodbcommon.h"
       
    23 CONTENTINFODB_CLASS(ContentinfodbTest)
       
    24 
       
    25 class ContentInfoDb : public QObject
       
    26     {
       
    27 Q_OBJECT
       
    28 public:
       
    29     /**
       
    30      * Singleton construtor
       
    31      * @since S60 ?S60_version.
       
    32      */
       
    33     static ContentInfoDb* instance()
       
    34         {
       
    35         static QMutex mutex;
       
    36         if (!m_instance)
       
    37             {
       
    38             mutex.lock();
       
    39             m_instanceCounter++;
       
    40             if (!m_instance)
       
    41                 {
       
    42                 m_instance = new ContentInfoDb;
       
    43                 }
       
    44             mutex.unlock();
       
    45             }
       
    46 
       
    47         return m_instance;
       
    48         }
       
    49 
       
    50     /**
       
    51      * Singleton destructor
       
    52      * @since S60 ?S60_version.
       
    53      */
       
    54     static void deleteinstance()
       
    55         {
       
    56         m_instanceCounter--;
       
    57         if ((m_instanceCounter <= 0) && (m_instance))
       
    58             {
       
    59             delete m_instance;
       
    60             m_instance = 0;
       
    61             }
       
    62         }
       
    63 private:
       
    64     /**
       
    65      * Constructor.
       
    66      * @since S60 ?S60_version.
       
    67      */
       
    68     ContentInfoDb();
       
    69 
       
    70     /**
       
    71      * Destructor.
       
    72      * @since S60 ?S60_version.
       
    73      */
       
    74     ~ContentInfoDb();
       
    75 public:
       
    76 
       
    77     /**
       
    78      * returns success/failure status.
       
    79      * @since S60 ?S60_version.
       
    80      * @param query
       
    81      */
       
    82     bool writeData(QString query);
       
    83 
       
    84     /**
       
    85      * returns success/failure status.
       
    86      * @since S60 ?S60_version.
       
    87      * @param query input
       
    88      */
       
    89     QStringList readData(QString query);
       
    90 
       
    91     /**
       
    92      * returns value at mentioned position
       
    93      * @param query input     
       
    94      */
       
    95     QString readStringData(QString query);
       
    96 
       
    97     /**
       
    98      * creates the table with the mentioned tablename.
       
    99      * @param tablename 
       
   100      * @param sql query
       
   101      */
       
   102     void createTable(QString tablename, QString query);
       
   103 
       
   104     /**
       
   105      * returns success/failure status.
       
   106      * @since S60 ?S60_version.
       
   107      */
       
   108     bool Open();
       
   109 
       
   110     /**     
       
   111      * close the database connection
       
   112      * @since S60 ?S60_version.     
       
   113      */
       
   114     void Close();
       
   115 
       
   116 signals:
       
   117 
       
   118     /**     
       
   119      * signal to notify when updation happens in the contentinfodb
       
   120      */
       
   121     void dbUpdated();
       
   122 
       
   123 private:
       
   124 
       
   125     /**
       
   126      * static instance to make single instance
       
   127      * Own.
       
   128      */
       
   129     static ContentInfoDb *m_instance;
       
   130 
       
   131     /**
       
   132      * counter for number for instance
       
   133      * Own.
       
   134      */
       
   135     static int m_instanceCounter;
       
   136 
       
   137     /**
       
   138      * database handle
       
   139      * Own.
       
   140      */
       
   141     QSqlDatabase m_db;
       
   142 
       
   143 private:
       
   144     CONTENTINFODB_FRIEND_CLASS(ContentinfodbTest)
       
   145     };
       
   146 #endif //CONTENTINFODB_H