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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*
* Copyright 2017 Samsung Electronics Co., Ltd
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef COMMON_MODEL_ALARM_CONSUMER_H
#define COMMON_MODEL_ALARM_CONSUMER_H
#include "Model/DataProvider.h"
#include <data_control_sql.h>
namespace Common
{
namespace Model
{
class Alarm;
/**
* @brief Provides access to alarm database.
*/
class EXPORT_API AlarmConsumer
{
public:
typedef ::Model::DataProvider::DataList DataList;
/**
* @brief Called when requested Alarm(s) is received.
* @param[in] dataList List of received Alarm objects
*/
typedef std::function<void(DataList dataList)> GetCallback;
/**
* @brief Called when result of insert, update or delete is received.
* @param[in] isSuccess Whether operation was successful
* @param[in] alarmId Alarm Id if alarm was inserted
*/
typedef std::function<void(bool isSuccess, int alarmId)> ResultCallback;
/**
* @return Consumer singleton instance.
*/
static AlarmConsumer &getInstance();
/**
* @return Data control provider handle.
*/
data_control_h getProvider() const;
/**
* @brief Retrieve alarm from database by ID.
* @param[in] id Alarm ID
* @param[in] callback Callback to be called when alarm is received
*/
void getAlarm(int id, GetCallback callback);
/**
* @brief Retrieve alarm from database that matches specified alarm by time and repeat.
* @param[in] alarm Alarm to compare against
* @param[in] callback Callback to be called when alarm is received
*/
void getAlarm(const Alarm &alarm, GetCallback callback);
/**
* @brief Retrieve all alarms from database.
* @param[in] callback Callback to be called when alarms are received
*/
void getAlarms(GetCallback callback);
/**
* @brief Convenience wrapper to insert new or update existing alarm.
* @see insertAlarm()
* @see updateAlarm()
*/
void saveAlarm(const Alarm &alarm, ResultCallback callback);
/**
* @brief Insert alarm into database.
* @param[in] alarm Alarm to insert
* @param[in] callback Callback to be called when operation is complete
*/
void insertAlarm(const Alarm &alarm, ResultCallback callback);
/**
* @brief Update existing alarm in the database.
* @param[in] alarm Alarm to update
* @param[in] callback Callback to be called when operation is complete
*/
void updateAlarm(const Alarm &alarm, ResultCallback callback);
/**
* @brief Delete alarm from the database.
* @param[in] id Alarm ID
* @param[in] callback Callback to be called when operation is complete
*/
void deleteAlarm(int id, ResultCallback callback);
private:
AlarmConsumer();
~AlarmConsumer();
void selectAlarms(const char *where, GetCallback callback);
void onSelectResponse(int requestId, data_control_h provider,
result_set_cursor result, bool isSuccess, const char *error);
void onInsertResponse(int requestId, data_control_h provider,
long long id, bool isSuccess, const char *error);
void onUpdateResponse(int requestId, data_control_h provider,
bool isSuccess, const char *error);
void onDeleteResponse(int requestId, data_control_h provider,
bool isSuccess, const char *error);
data_control_h m_Provider;
std::vector<std::pair<int, ResultCallback>> m_ResultCallbacks;
std::vector<std::pair<int, GetCallback>> m_GetCallbacks;
};
}
}
#endif /* COMMON_MODEL_ALARM_CONSUMER_H */
|