Line data Source code
1 : /*! @brief This file have the interface for the IDataSource class.
2 : @file idatasource.h
3 : @author Alvaro Denis <denisacostaq@gmail.com>
4 : @date 6/19/2019
5 :
6 : @copyright
7 : @attention <h1><center><strong>COPYRIGHT © 2019 </strong>
8 : [<strong>denisacostaq</strong>][denisacostaq-URL].
9 : All rights reserved.</center></h1>
10 : @attention This file is part of [<strong>DAQs</strong>][DAQs-URL].
11 :
12 : Redistribution and use in source and binary forms, with or without
13 : modification, are permitted provided that the following conditions
14 : are met:
15 : - 1. Redistributions of source code must retain the above copyright
16 : notice, this list of conditions and the following disclaimer.
17 : - 2. Redistributions in binary form must reproduce the above copyright
18 : notice, this list of conditions and the following disclaimer in the
19 : documentation and/or other materials provided with the distribution.
20 : - 3. Neither the name of the University nor the names of its contributors
21 : may be used to endorse or promote products derived from this software
22 : without specific prior written permission.
23 :
24 : THIS PRODUCT IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 : AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 : IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 : ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28 : DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 : (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 : LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 : ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 : (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 : THIS PRODUCT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 :
35 : [denisacostaq-URL]: https://about.me/denisacostaq "Alvaro Denis Acosta"
36 : [DAQs-URL]: https://github.com/denisacostaq/DAQs "DAQs"
37 : */
38 : #ifndef DATABASE_SERVER_IDATASOURCE_H
39 : #define DATABASE_SERVER_IDATASOURCE_H
40 :
41 : #include <chrono>
42 : #include <functional>
43 : #include <string>
44 :
45 : #include "src/database-server/data-model/variable.h"
46 : #include "src/database-server/data-model/varvalue.h"
47 :
48 : /**
49 : * @brief The IDataSource class is an interface for the physycal storage.
50 : * @details A variable is related for example with sensors, like temperature,
51 : * luminosity, ... A value is for example the numerica value for a
52 : * temperature sensor.
53 : * @sa add_variable_value, add_variable_value
54 : */
55 : class IDataSource {
56 : public:
57 : enum class Err { Ok, Failed };
58 :
59 34 : IDataSource() = default;
60 34 : virtual ~IDataSource() = default;
61 : IDataSource(const IDataSource&) = delete;
62 : IDataSource& operator=(const IDataSource&) = delete;
63 : IDataSource(IDataSource&&) = default;
64 : IDataSource& operator=(IDataSource&&) = default;
65 :
66 : /**
67 : * @brief create_scheme create data storage persistence, e.g. schema for a
68 : * relational database
69 : * @return Err::Ok on succes
70 : */
71 : virtual Err create_scheme() noexcept = 0;
72 :
73 : /**
74 : * @brief add_variable add a variable to be tracket for the system (by default
75 : * the only supported variabe value type is double).
76 : * @param variable to be created in the physical storage.
77 : * @return Err::Ok on succes.
78 : * @sa add_variable_value
79 : */
80 : virtual Err add_variable(const Variable& variable) noexcept = 0;
81 :
82 : /**
83 : * @brief add_variable_value add a new value for the variable.
84 : * @param var_value variable value to be inserted in the storage.
85 : * @return Err::Ok on succes
86 : * @sa add_variable
87 : */
88 : virtual Err add_variable_value(const VarValue& var_value) noexcept = 0;
89 :
90 : /**
91 : * @brief fetch_variables get all variables
92 : * @param send_vale the variables will be send in this callback, one at a
93 : * time, index is the current value index.
94 : * @return Err::Ok on succes
95 : */
96 : virtual Err fetch_variables(
97 : const std::function<void(const Variable& var, size_t index)>&
98 : send_vale) noexcept = 0;
99 :
100 : /**
101 : * @brief fetch_variable_values get all values of a given variable
102 : * @param var_name variable name to get the values from
103 : * @param send_vale the values will be send in this callback, one at a time,
104 : * index is the current value index.
105 : * @return Err::Ok on succes
106 : */
107 : virtual Err fetch_variable_values(
108 : const std::string& var_name,
109 : const std::function<void(const VarValue& val, size_t index)>&
110 : send_vale) noexcept = 0;
111 :
112 : /**
113 : * @brief count_variable_values count all values of a given variable
114 : * @param var_name variable name to count the values from
115 : * @param send_count in this callack you can receive the number of values for
116 : * the given variable
117 : * @return Err::Ok on success
118 : */
119 : virtual Err count_variable_values(
120 : const std::string& var_name,
121 : const std::function<void(size_t count)>& send_count) noexcept = 0;
122 :
123 : /**
124 : * @brief fetch_variable_values get all values of a given variables in a date
125 : * range
126 : * @param var_name variable name to get the values from
127 : * @param start_date begin of the date range
128 : * @param end_date end of the date range
129 : * @param send_vale the values will be send in this callback, one at a time,
130 : * index is the current value index.
131 : * @return Err::Ok on succes
132 : */
133 : virtual Err fetch_variable_values(
134 : const std::string& var_name,
135 : const std::chrono::system_clock::time_point& start_date,
136 : const std::chrono::system_clock::time_point& end_date,
137 : const std::function<void(const VarValue& val, size_t index)>&
138 : send_vale) noexcept = 0;
139 :
140 : /**
141 : * @brief count_variable_values count all values of a given variable
142 : * @param var_name variable name to count the values from
143 : * @param start_date begin of the date range
144 : * @param end_date end of the date range
145 : * @param send_count in this callack you can receive the number of values for
146 : * the given variable
147 : * @return Err::Ok on success.
148 : */
149 : virtual Err count_variable_values(
150 : const std::string& var_name,
151 : const std::chrono::system_clock::time_point& start_date,
152 : const std::chrono::system_clock::time_point& end_date,
153 : const std::function<void(size_t count)>& send_count) noexcept = 0;
154 : };
155 :
156 : #endif // DATABASE_SERVER_IDATASOURCE_H
|