All Classes Namespaces Functions Variables Enumerations Enumerator Pages
SystemHandler.h
1 /*
2  Copyright (c) 2014 by Elvis Angelaccio
3 
4  Permission is hereby granted, free of charge, to any person obtaining a copy
5  of this software and associated documentation files (the "Software"), to deal
6  in the Software without restriction, including without limitation the rights
7  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  copies of the Software, and to permit persons to whom the Software is
9  furnished to do so, subject to the following conditions:
10 
11  The above copyright notice and this permission notice shall be included in
12  all copies or substantial portions of the Software.
13 
14  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  THE SOFTWARE.
21 */
22 
23 #ifndef SYSTEM_HANDLER_H
24 #define SYSTEM_HANDLER_H
25 
26 
27 #include <string>
28 #include <map>
29 #include <vector>
30 #include <stdexcept>
31 
32 #include "../entity/DataSetSpecifier.h"
33 #include "../entity/DataSet.h"
34 
35 namespace server
36 {
37 
39  {
40 
41  public:
42 
43  SystemHandler(const std::string &dataDir, const std::string &confDir);
44 
48  void setDataDirectory(const std::string &datatDir);
49 
53  void setConfDirectory(const std::string &confDir);
54 
59  std::string initDatabase();
60 
66  std::string findNewDSS();
67 
71  void fillDssList(std::vector<std::string> &dssList);
72 
76  bool empty();
77 
82  bool holdsDss(const std::string &dss);
83 
89  bool holdsDataSet(const std::string& dssName, int sequenceNumber);
90 
91  entity::DataSetSpecifier &getDss(const std::string &dssName);
92 
93  void generateSequenceNumber(const std::string &dssName, entity::DataSet &dataSet);
94 
100  void addDataSet(const std::string &dssName, entity::DataSet &dataSet);
101 
111  std::string getStorePath(const std::string &dssName, const std::string &itemName, int sequenceNumber, entity::Group group, entity::Tag tag);
112 
119  std::string getStorePath(const std::string &dssName, int sequenceNumber);
120 
127  bool removeDataSet(const std::string &dssName, int sequenceNumber);
128 
136  entity::DataSet getDataSet(const std::string &dssName, int sequenceNumber);
137 
144  void search(const std::string &dssName, const std::map<std::string, std::string> &queryFields, std::vector<entity::SetDescriptor> &descriptorList);
145 
146  private:
147 
148  std::string dataDirectory;
149  std::string confDirectory;
150  std::map<std::string, entity::DataSetSpecifier> dssArray;
151  std::map<std::string, std::vector<entity::DataSet> > dataSetCollection;
152  std::map<std::string, int> dssSequenceNumbers;
160  bool parse(const std::string &conf);
161 
166  void addSetDescriptorField(const std::string &name, const std::string &type, entity::DataSetSpecifier &dss);
167 
172  void addDataItem(const std::string &name, const std::string &tag, const std::string &group, entity::DataSetSpecifier &dss);
173 
178  void createIndex(const std::string &path);
179 
185  void updateIndex(const std::string &path, const entity::DataSet &dataSet);
186 
191  void initFromIndex(const std::string &dssName);
192 
194  void fillDatSetCollection();
195  };
196 
200  class ParseException : public std::runtime_error
201  {
202  public:
203  ParseException(const std::string &msg) : std::runtime_error(msg) {}
204  };
205 }
206 
207 #endif
void setDataDirectory(const std::string &datatDir)
Definition: SystemHandler.cpp:71
void addDataSet(const std::string &dssName, entity::DataSet &dataSet)
Definition: SystemHandler.cpp:227
void fillDssList(std::vector< std::string > &dssList)
Definition: SystemHandler.cpp:178
bool removeDataSet(const std::string &dssName, int sequenceNumber)
Definition: SystemHandler.cpp:295
A Data Set (DS) is an instance of a DSS and is defined by a SetDescriptor and a set of DataItems...
Definition: DataSet.h:36
Definition: SystemHandler.h:38
A DataSetSpecifier (DSS) is an object representing a single configuration file of the SimDB system...
Definition: DataSetSpecifier.h:41
std::string findNewDSS()
Definition: SystemHandler.cpp:135
void setConfDirectory(const std::string &confDir)
Definition: SystemHandler.cpp:77
bool holdsDss(const std::string &dss)
Definition: SystemHandler.cpp:195
std::string getStorePath(const std::string &dssName, const std::string &itemName, int sequenceNumber, entity::Group group, entity::Tag tag)
void search(const std::string &dssName, const std::map< std::string, std::string > &queryFields, std::vector< entity::SetDescriptor > &descriptorList)
Definition: SystemHandler.cpp:372
bool empty()
Definition: SystemHandler.cpp:190
std::string initDatabase()
Definition: SystemHandler.cpp:83
Definition: SystemHandler.h:200
entity::DataSet getDataSet(const std::string &dssName, int sequenceNumber)
Definition: SystemHandler.cpp:360
Definition: Server.h:34
bool holdsDataSet(const std::string &dssName, int sequenceNumber)
Definition: SystemHandler.cpp:200