smf/smfservermodule/smfserver/datastoremgr/dsm.h
changeset 7 be09cf1f39dd
equal deleted inserted replaced
6:c39a6cfd1fb9 7:be09cf1f39dd
       
     1 /*!	\file 
       
     2 	\brief File containing class description for DataStoreManager class.
       
     3 	
       
     4 	Copyright (c) 2010 Sasken Communication Technologies Ltd.
       
     5 	All rights reserved.
       
     6 	This component and the accompanying materials are made available
       
     7 	under the terms of the "{License}"
       
     8 	which accompanies  this distribution, and is available
       
     9 	at the URL "{LicenseUrl}".
       
    10 
       
    11 	\author Jaspinder Singh, Sasken Communication Technologies Ltd - Initial contribution
       
    12 
       
    13 	\version 0.1
       
    14 
       
    15 */
       
    16 
       
    17 #ifndef DATASTOREMANAGER_H
       
    18 #define DATASTOREMANAGER_H
       
    19 
       
    20 #include <QString>
       
    21 #include <QObject>
       
    22 #include <QtSql>
       
    23 #include "smfSns.h"
       
    24 #include "smfSocialProfile.h"
       
    25 #include "smfUserProfile.h"
       
    26 
       
    27 enum DataStoreManagerState{READY, BUSY, CLOSED, ERROR};
       
    28 
       
    29 //!	\class 	DataStoreManager
       
    30 /*!
       
    31 	\brief 	Data Store Manager
       
    32 	\brief 	Data Store Manager provides the functional interface between the data store and the outside world. 
       
    33 			It manages access to the data store and encapsulates prebuilt queries for relation management and makes sure 
       
    34 			that the data in persistent storage is always in a consistent state.
       
    35 			The DSM implements the Singleton Pattern, which means that only one instance of DSM will be available throughout the system.
       
    36 	
       
    37 	\warning	Not Thread Safe
       
    38 	\warning	Do not subclass
       
    39 */
       
    40 class DataStoreManager : public QObject
       
    41 {
       
    42 	Q_OBJECT
       
    43 	
       
    44 	public:
       
    45         static DataStoreManager* getDataStoreManager();
       
    46         ~DataStoreManager();
       
    47 
       
    48         QList <SMFSocialProfile> getAllRelated(const SMFUserProfile&);
       
    49         SMFSocialProfile getRelatedByService(const SMFUserProfile&, const SMFSocialNetworkingSite&);
       
    50 
       
    51         DataStoreManagerState getState() const;
       
    52         QString getError() const;
       
    53 
       
    54 
       
    55 
       
    56         SMFUserProfile getUserProfile(const QString& name, const QString& contact_id);
       
    57         SMFSocialNetworkingSite getSNSEntry(const QString& name);
       
    58         void saveUserProfile(const SMFUserProfile& user_profile);
       
    59         void saveSocialProfile(const SMFSocialProfile& social_profile);
       
    60         void saveSNSEntry(const SMFSocialNetworkingSite& sns);
       
    61         void modifyRelation(SMFSocialProfile& sns, SMFUserProfile& new_user_profile);
       
    62 
       
    63 
       
    64 	public slots:
       
    65         int addUserProfile( SMFUserProfile&);
       
    66         int deleteUserProfile( SMFUserProfile&);
       
    67         int addSocialProfile( SMFSocialProfile&);
       
    68 		int deleteSocialProfile(SMFSocialProfile&);
       
    69         int addSNSEntry( SMFSocialNetworkingSite&);
       
    70 		int deleteSNSEntry(SMFSocialNetworkingSite&);
       
    71         int createRelation(const SMFUserProfile&, SMFSocialProfile&);
       
    72         int deleteRelation(const SMFUserProfile&, SMFSocialProfile&);
       
    73 
       
    74 	private:
       
    75         static DataStoreManager* m_dsm_instance;		// Unique Instance for DSM (Singleton Implementation)
       
    76         static const QString db_name;
       
    77         int m_dsm_instance_count; 				// Track references to the DSM
       
    78         static DataStoreManagerState state;				// Current state of DSM
       
    79         QString m_last_msg;					// Last message/error generated by the database.
       
    80         QSqlDatabase db;
       
    81 
       
    82         DataStoreManager(const QString& db_name, QObject* parent = 0); 			// Private Constructor.
       
    83         bool InitializeDataBase();				// Initialization code to be called once while lazy construction of the instance
       
    84 };
       
    85 
       
    86 #endif