]> Creatis software - creaImageIO.git/blob - src2/creaImageIOTimestampDatabaseHandler.h
Added synchronization
[creaImageIO.git] / src2 / creaImageIOTimestampDatabaseHandler.h
1 #ifndef __creaImageIOTimestampDatabaseHandler_h_INCLUDED__
2 #define __creaImageIOTimestampDatabaseHandler_h_INCLUDED__
3 #include <vector>
4 #include <map>
5 #include <creaImageIOTree.h>
6 class CppSQLite3DB;
7
8 namespace creaImageIO
9 {
10         using namespace std;
11 //=======================================================================
12   /// Concrete TreeHandler which manages a Tree stored in a sqlite database
13   class TimestampDatabaseHandler 
14   {
15   public:
16     //====================================================================
17     /// Ctor with database file name 
18     TimestampDatabaseHandler(const std::string& filename);
19     /// Dtor
20     virtual ~TimestampDatabaseHandler();
21     //====================================================================
22
23     //====================================================================
24     /// Returns the sqlite db file name 
25     const std::string& GetFileName() const { return mFileName; }
26     //====================================================================
27  
28     //====================================================================
29     // INITIALIZATION / FINALIZATION
30     //====================================================================
31
32     //====================================================================
33     /// Opens an existing 'source' 
34      bool Open();
35     /// Closes the 'source'
36     bool Close();
37     /// Creates a new 'source' 
38     bool Create();
39     /// Destroys the 'source'
40     bool Destroy();
41     //====================================================================
42
43         //====================================================================
44     // READ / WRITE
45     //====================================================================
46         //====================================================================
47         ///Returns the id of the path if it's indexed, blank otherwise
48         std::string IsIndexed(const std::string& path);
49     ///Sets the current path's parent
50         bool AddDirectory(const std::string& parent,
51                                    const std::string& path, 
52                                    const time_t lastModif, 
53                                    const time_t lastRead);
54         ///Adds a new file to the database without a parent
55         void AddFile(const std::string& path, const time_t lastModif, const time_t lastRead);
56         ///Adds a new file to the database with a parent
57         void AddFile(const std::string& parentId,const std::string& path, const time_t lastModif, const time_t lastRead);
58         ///Sets the attribute to the value passed as parameter where the searchParameter is searchValue
59         void SetAttribute(const std::string& attName, 
60                                         const std::string& attValue,
61                                         const std::string& searchParam,
62                                         const std::string& searchValue);
63         ///Removes the given node
64         void RemoveNode(const std::string& searchAtt, const tree::Node* node);
65         ///Removes the filename with the given pathname
66         void RemoveFile(const std::string& searchAtt, const std::string& searchVal);
67         ///Cleans the path name
68         void CleanName(std::string& str) const;
69         ///Checks the timestamp in the database and compares it with the given one. 
70         //If there is a difference, it will return false, otherwise it will return true.
71         bool CheckTimestamp(const std::string pathId, const time_t lastModif);
72
73         //====================================================================
74
75
76   protected:
77     //======================================================================
78     /// Open the database
79     bool DBOpen();
80     //======================================================================
81     //======================================================================
82     // Creation
83     /// Creates a new database on disk and the tables
84     bool DBCreate();
85     //======================================================================
86         //======================================================================
87     // Removes a file from the database
88         void DBRemove(const std::string& searchAtt, const std::string& searchVal);
89  
90   private:
91     /// The DB
92     CppSQLite3DB* mDB;
93    /// The physical location associated to the DicomDatabase (directory, db file...)
94     std::string mFileName;
95   
96   };
97   // EO class
98   //=======================================================================
99
100
101 } // EO namespace creaImageIO
102
103 // EOF
104 #endif  
105