~aleteoryx/muditaos

ref: ba1a6f25274d9f8d181739ab371cca4490591165 muditaos/module-services/service-time/AlarmRepository.hpp -rw-r--r-- 4.5 KiB
ba1a6f25 — Paweł Joński [BH-691] Alarms handling 4 years ago
                                                                                
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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


#include <module-sys/Service/Service.hpp>
#include <time/dateCommon.hpp>

#include <ctime>
#include <vector>

struct EventRecord;
struct SingleEvent;
struct AlarmEventRecord;

/**
 * @brief Basic interface alarm API
 */
namespace alarms
{
    using OnGetAlarmEventCallback          = std::function<void(AlarmEventRecord)>;
    using OnGetAlarmEventsCallback         = std::function<void(std::vector<AlarmEventRecord>)>;
    using OnGetAlarmEventsInRangeCallback  = std::function<void(std::vector<AlarmEventRecord>)>;
    using OnAddAlarmEventCallback          = std::function<void(bool)>;
    using OnUpdateAlarmEventCallback       = std::function<void(bool)>;
    using OnRemoveAlarmEventCallback       = std::function<void(bool)>;
    using OnGetNextCallback                = std::function<void(std::vector<AlarmEventRecord>)>;
    using OnGetAlarmEventsRecurringInRange = std::function<void(std::vector<AlarmEventRecord>)>;

    class AbstractAlarmEventsRepository
    {
      public:
        /**
         * Default destructor
         */
        virtual ~AbstractAlarmEventsRepository() noexcept = default;

        /**
         * Get alarm from the alarm repository
         * @param AlarmEventRecord Id in the alarm repository
         * @retval alarm status and Event structure
         */
        virtual void getAlarmEvent(const std::uint32_t alarmId, const OnGetAlarmEventCallback &callback) = 0;

        /**
         * Get alarms Ids from the alarm repository
         * @param offset of the first alarm in the alarm repo
         * @param limit number of alarms ids to be returned
         */
        virtual void getAlarmEvents(std::uint32_t offset,
                                    std::uint32_t limit,
                                    const OnGetAlarmEventsCallback &callback) = 0;

        /**
         * Get alarms from the alarm repository
         * @param start time point for first alarm to be returned
         * @param end time point for last alarm to be returned
         */
        virtual void getAlarmEventsInRange(TimePoint start,
                                           TimePoint end,
                                           std::uint32_t offset,
                                           std::uint32_t limit,
                                           const OnGetAlarmEventsInRangeCallback &callback) = 0;

        /**
         * Add alarm to the alarm repository
         * @param AlarmEventRecord structure
         * @retval operation status
         */
        virtual void addAlarmEvent(const AlarmEventRecord &alarmEvent, const OnAddAlarmEventCallback &callback) = 0;

        /**
         * Update alarm in the alarm repository
         * @param AlarmEventRecord structure
         * @retval operation status
         */
        virtual void updateAlarmEvent(const AlarmEventRecord &alarmEvent,
                                      const OnUpdateAlarmEventCallback &callback) = 0;

        /**
         * Remove alarm from the alarm repository
         * @param id of the alarm to be deleted
         * @retval operation status
         */
        virtual void removeAlarmEvent(const std::uint32_t id, const OnRemoveAlarmEventCallback &callback) = 0;

        /**
         * Get next alarm starting with or following timepoint
         * @param start time point from which following events will be returned
         * @param offset of the first alarm in the alarm repo
         * @param limit number of alarms ids to be returned
         */
        virtual void getNext(TimePoint start,
                             std::uint32_t offset,
                             std::uint32_t limit,
                             const OnGetNextCallback &callback) = 0;

        /**
         * Get next recurring alarm in specified range
         * @param start start of search range
         * @param end enf of search range
         * @param offset of the first alarm in the alarm repo
         * @param limit number of alarms ids to be returned
         */
        virtual void getAlarmEventsRecurringInRange(TimePoint start,
                                                    TimePoint end,
                                                    std::uint32_t offset,
                                                    std::uint32_t limit,
                                                    const OnGetAlarmEventsRecurringInRange &callback) = 0;
    };
} // namespace alarms