sensordatastore_internal.h 5.22 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//================================================================================
// Name        : sensordatastore_internal.h
// Author      : Axel Auweter
// Copyright   : Leibniz Supercomputing Centre
// Description : Internal interface for inserting and querying DCDB sensor data.
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2011-2016 Leibniz Supercomputing Centre
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//================================================================================
26

27
28
29
30
31
32
33
/*
 * @file
 * @brief This file contains the internal functions of the
 *        Sensor Data Store which are provided by the
 *        SensorDataStoreImpl class.
 */

34
35
#ifndef DCDB_SENSORDATASTORE_INTERNAL_H
#define DCDB_SENSORDATASTORE_INTERNAL_H
36

37
#include <string>
38

39
40
#include "dcdb/sensordatastore.h"
#include "dcdb/connection.h"
41

42
namespace DCDB {
43
44
static std::string const AggregateString[] = {"", "min", "max", "avg", "sum", "count"};
  
45
46
47
/**
 * @brief The SensorDataStoreImpl class contains all protected
 *        functions belonging to SensorDataStore which are
Michael Ott's avatar
Michael Ott committed
48
 *        hidden from the user of the libdcdb library.
49
 */
50
51
52
class SensorDataStoreImpl
{
protected:
53
  Connection*     connection;     /**< The Connection object that does the low-level stuff for us. */
54
55
  CassSession*        session;        /**< The CassSession object given by the connection. */
  const CassPrepared* preparedInsert; /**< The prepared statement for fast insertions. */
56

57
  /**
58
59
   * @brief Prepare for insertions.
   * @param ttl   A TTL that will be set for newly inserted values. Set to 0 to insert without TTL.
60
   */
61
  void prepareInsert(uint64_t ttl);
62

63
public:
64
65
66
67
  /**
   * @brief This function inserts a sensor reading into the database
   * @param sid    The SensorId object representing the sensor (typically obtained from topicToSid)
   * @param ts     The timestamp of the reading (nanoseconds since Unix epoch)
68
   * @param value  The sensor reading as 64-bit integer
69
   */
70
  void insert(SensorId* sid, uint64_t ts, int64_t value);
71

72
73
74
75
76
77
  /**
   * @brief This function sets the TTL of newly inserted readings.
   * @param ttl    The TTL to be used for new inserts in seconds.
   */
  void setTTL(uint64_t ttl);

Axel Auweter's avatar
Axel Auweter committed
78
79
80
81
82
83
84
85
  /**
   * @brief This function querie a sensor's values in
   *        the given time range.
   * @param result   The list where the results will be stored.
   * @param sid      The SensorId to query.
   * @param start    Start of the time series.
   * @param end      End of the time series.
   */
86
  void query(std::list<SensorDataStoreReading>& result, SensorId& sid, TimeStamp& start, TimeStamp& end, QueryAggregate aggregate);
Axel Auweter's avatar
Axel Auweter committed
87

88
89
90
91
92
93
94
95
96
  /**
   * @brief This function queries a sensor's values in
   *        the given time range.
   * @param cbFunc   A function to called for each reading.
   * @param userData Pointer to user data that will be returned in the callback.
   * @param sid      The SensorId to query.
   * @param start    Start of the time series.
   * @param end      End of the time series.
   */
97
  void queryCB(SensorDataStore::QueryCbFunc cbFunc, void* userData, SensorId& sid, TimeStamp& start, TimeStamp& end, QueryAggregate aggregate);
98

99
100
101
102
103
104
105
  /**
   * @brief This function queries the integrated value
   *        of a sensor for the given time range.
   * @param result   The resulting integrated value.
   * @param sid      The SensorId to query.
   * @param start    Start of the time series.
   * @param end      End of the time series.
Axel Auweter's avatar
Axel Auweter committed
106
   * @return         SDS_OK if ok, SDS_EMPTYSET if not at least 2 readings in interval.
107
   */
108
  SDSQueryResult querySum(int64_t& result, SensorId& sid, TimeStamp& start, TimeStamp& end);
109

110
111
112
113
114
115
116
117
118
119
120
121
122
  /**
   * @brief This function truncates all sensor data that is older than
   *        the specified week.
   * @param weekStamp   The 16-bit weekstamp generated from a cut-off date
   */
  void truncBeforeWeek(uint16_t weekStamp);

  /**
   * @brief This function deletes a row from the sensordatastore.
   * @param sid     SensorId object that identifies the row to be deleted.
   */
  void deleteRow(SensorId& sid);

123
124
125
126
  /**
   * @brief This is the standard constructor of the SensorDataStoreImpl class.
   * @param csb   A CassandraBackend object to do the raw database access.
   */
127
  SensorDataStoreImpl(Connection* conn);
128
129
130
131

  /**
   * @brief The standard desctructor of SensorDataStoreImpl.
   */
132
  virtual ~SensorDataStoreImpl();
133
134
};

135
136
137
} /* End of namespace DCDB */

#endif /* DCDB_SENSORDATASTORE_INTERNAL_H */