sensordatastore_internal.h 3.23 KB
Newer Older
1
2
3
4
5
6
7
/*
 * dcdb_internal.h
 *
 * Internal data structures and definitions for the DCDB Library
 *
 */

8
9
10
11
12
13
14
/*
 * @file
 * @brief This file contains the internal functions of the
 *        Sensor Data Store which are provided by the
 *        SensorDataStoreImpl class.
 */

15
16
17
#ifndef DCDB_INTERNAL_H
#define DCDB_INTERNAL_H

18
#include <string>
19
20

#include "sensordatastore.h"
21
#include "connection.h"
22

23
24
25
26
27
/**
 * @brief The SensorDataStoreImpl class contains all protected
 *        functions belonging to SensorDataStore which are
 *        hidden from the user of the DCDBLib library.
 */
28
29
30
class SensorDataStoreImpl
{
protected:
31
32
33
  DCDBConnection*     connection;     /**< The DCDBCOnnection object that does the low-level stuff for us. */
  CassSession*        session;        /**< The CassSession object given by the connection. */
  const CassPrepared* preparedInsert; /**< The prepared statement for fast insertions. */
34

35
  /**
36
37
   * @brief Prepare for insertions.
   * @param ttl   A TTL that will be set for newly inserted values. Set to 0 to insert without TTL.
38
   */
39
  void prepareInsert(uint64_t ttl);
40

41
public:
42
43
44
45
  /**
   * @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)
46
   * @param value  The sensor reading as 64-bit integer
47
   */
48
  void insert(SensorId* sid, uint64_t ts, int64_t value);
49

50
51
52
53
54
55
  /**
   * @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
56
57
58
59
60
61
62
63
64
65
  /**
   * @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.
   */
  void query(std::list<SensorDataStoreReading>& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end);

66
67
68
69
70
71
72
  /**
   * @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
73
   * @return         SDS_OK if ok, SDS_EMPTYSET if not at least 2 readings in interval.
74
   */
Axel Auweter's avatar
Axel Auweter committed
75
  SDSQueryResult querySum(int64_t& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end);
76

77
78
79
80
81
82
83
84
85
86
87
88
89
  /**
   * @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);

90
91
92
93
  /**
   * @brief This is the standard constructor of the SensorDataStoreImpl class.
   * @param csb   A CassandraBackend object to do the raw database access.
   */
94
  SensorDataStoreImpl(DCDBConnection* conn);
95
96
97
98

  /**
   * @brief The standard desctructor of SensorDataStoreImpl.
   */
99
  virtual ~SensorDataStoreImpl();
100
101
};

102
#endif