supla-device
Loading...
Searching...
No Matches
notifications.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_DEVICE_NOTIFICATIONS_H_
5#define SRC_SUPLA_DEVICE_NOTIFICATIONS_H_
6
7#include <supla-common/proto.h>
8#include <supla/protocol/supla_srpc.h>
9#include <supla/element.h>
10
11#define SUPLA_NOTIF_MAX 50
12
13namespace Supla {
14
15class Notification : public Element {
16 public:
18 virtual ~Notification();
19
20 // Register a notification
21 // All notifications should be registered before SuplaDevice.begin()
22 // context - -1 device, 0..255 channel id
23 // titleSetByDevice - true if title is set by device, false if managed by
24 // server
25 // messageSetByDevice - true if message is set by device, false if managed by
26 // server
27 // soundSetByDevice - true if sound is set by device, false if managed by
28 // server
29 static bool RegisterNotification(int16_t context,
30 bool titleSetByDevice = true,
31 bool messageSetByDevice = true,
32 bool soundSetByDevice = false);
33
34 // Send a notification
35 // Notification has to be registered earlier.
36 // context - -1 device, 0..255 channel id
37 // title - title of the notification
38 // message - message of the notification
39 // soundId - sound id
40 // If any of above fields was registered as not manged by device, then this
41 // field will be ignored
42 // Return true if notification was sent
43 // Return false if notification was not sent (i.e. it wasn't registered,
44 // or Supla server connection is not ready)
45 static bool Send(int16_t context,
46 const char *title = nullptr,
47 const char *message = nullptr,
48 int soundId = 0);
49
50 static bool SendF(int16_t context, const char* title, const char *fmt, ...);
51
52 static bool IsNotificationUsed();
53
54 void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc = nullptr) override;
55
56 private:
57 static Notification* GetInstance();
58 static Notification* instance;
59
60 bool registerNotification(int16_t context,
61 bool titleSetByDevice,
62 bool messageSetByDevice,
63 bool soundSetByDevice);
64 bool send(int16_t context, const char *title, const char *message,
65 int soundId);
66 TDS_RegisterPushNotification* getContextConfig(int16_t context);
67
68 void setSrpc(Supla::Protocol::SuplaSrpc *srpc);
69
70 TDS_RegisterPushNotification notifications[SUPLA_NOTIF_MAX] = {};
71 int notificationCount = 0;
72 Supla::Protocol::SuplaSrpc *srpc = nullptr;
73 bool blockNewRegistration = false;
74};
75} // namespace Supla
76
77#endif // SRC_SUPLA_DEVICE_NOTIFICATIONS_H_
Base class for all elements of SuplaDevice.
Definition element.h:27
Definition notifications.h:15
void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc=nullptr) override
Method called each time when device successfully registers to Supla server.
Definition notifications.cpp:158
Definition supla_srpc.h:46
Definition proto.h:4174