2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
29 #ifndef __creaImageIOSynchron_h_INCLUDED__
30 #define __creaImageIOSynchron_h_INCLUDED__
36 #include "CppSQLite3.h"
41 //================================================================================================================
42 ///Represents the list of currently added files
46 ///Key to be added into the database
48 ///Path of the directory
50 /// Defines if the operation was recursive or not
51 std::string recursive;
52 ///Number of added files
55 AddList(CppSQLite3Query& res):
56 key(res.getStringField(0)),
57 path(res.getStringField(1)),
58 recursive(res.getStringField(2)),
59 nbFiles(res.getStringField(3))
62 //================================================================================================================
64 //================================================================================================================
65 ///Represents the list of currently removed files
69 ///Key to be added into the database
71 ///Path of the remove file
73 ///Defines if the file was removed or not
75 ///Time of the last change of the file
78 RemoveList(CppSQLite3Query& res):
79 key(res.getStringField(1)),
80 path(res.getStringField(2)),
81 remove(res.getStringField(3)),
82 time(res.getStringField(4))
85 //================================================================================================================
87 //================================================================================================================
88 ///In charge of the synchronization of the database and the disk state.
93 Synchronizer(const std::string& path);
95 virtual ~Synchronizer();
96 ///Initializes the database
98 ///Inserts an add operation to the database
99 void InsertAddOp(const std::string& path,
100 const std::string& recursive,
101 const std::string& nChildren,
102 const std::string& refdb);
103 ///Inserts a file to be ignored
104 void InsertIgnoreFile(const std::string& addKey,
105 const std::string& path,
106 const std::string& remove,
107 const std::string& time,
108 const std::string& refdb);
109 ///Removes an entry that matches the given parameter
110 void RemoveEntry(const std::string i_table, const std::string i_key);
111 ///Removes several entries
112 void RemoveEntries(const std::string i_table,
113 const std::string i_attribute,
114 const std::string i_operand,
115 const std::string i_key);
116 ///Gets the list of AddFiles
117 void GetFileList(std::vector<AddList>& files , const std::string& refdb);
118 ///Gets the list of ignored files
119 void GetIgnoredFiles(const std::string& key, std::vector<std::string> &ignoreList);
120 ///Gets the attribute that matches the parameters
121 std::string GetAttribute(const std::string& attribute,
122 const std::string& table,
123 const std::string& searchParam,
124 const std::string& searchValue,
125 const std::string& refdb);
126 ///Sets an attribute to an entry that matches the given parameters
127 void SetAttribute(const std::string& attribute,
128 const std::string& table,
129 const std::string& value,
130 const std::string& searchParam,
131 const std::string& searchValue,
132 const std::string& refdb);
133 // Get the List of indexed files (removed or not)
134 void GetList(const std::string i_db);
135 // Test to not if a file is indexed on db or not
136 bool isIndexed(const std::string filename);
137 // List of all indexed files
138 std::map <std::string, bool> mList;
139 ///The current AddList
140 std::vector<AddList> mAddList;
141 ///The current RemoveList
142 std::vector<RemoveList> mIgnoreList;
147 ///Path of the current database
149 ///Creates a new database
151 ///Updates the AddList
152 void UpdateAddList(const std::string& refdb);
153 ///Cleans the list in case operations are no longer useful (0 added files)
154 void CleanList(const std::string& refdb);
155 ///Cleans the name (changes slashes and backslashes according to the system)
156 void CleanName(std::string& str) const;
157 ///Gets the ignore list
158 std::vector<std::string> GetIgnoreList(const std::string &i_key);
159 const std::string convert(const std::string &i_word);
162 //================================================================================================================