supla-device
Loading...
Searching...
No Matches
notifications.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#ifndef SRC_SUPLA_DEVICE_NOTIFICATIONS_H_
20#define SRC_SUPLA_DEVICE_NOTIFICATIONS_H_
21
22#include <supla-common/proto.h>
23#include <supla/protocol/supla_srpc.h>
24#include <supla/element.h>
25
26#define SUPLA_NOTIF_MAX 50
27
28namespace Supla {
29
30class Notification : public Element {
31 public:
32 Notification();
33 virtual ~Notification();
34
35 // Register a notification
36 // All notifications should be registered before SuplaDevice.begin()
37 // context - -1 device, 0..255 channel id
38 // titleSetByDevice - true if title is set by device, false if managed by
39 // server
40 // messageSetByDevice - true if message is set by device, false if managed by
41 // server
42 // soundSetByDevice - true if sound is set by device, false if managed by
43 // server
44 static bool RegisterNotification(int16_t context,
45 bool titleSetByDevice = true,
46 bool messageSetByDevice = true,
47 bool soundSetByDevice = false);
48
49 // Send a notification
50 // Notification has to be registered earlier.
51 // context - -1 device, 0..255 channel id
52 // title - title of the notification
53 // message - message of the notification
54 // soundId - sound id
55 // If any of above fields was registered as not manged by device, then this
56 // field will be ignored
57 // Return true if notification was sent
58 // Return false if notification was not sent (i.e. it wasn't registered,
59 // or Supla server connection is not ready)
60 static bool Send(int16_t context,
61 const char *title = nullptr,
62 const char *message = nullptr,
63 int soundId = 0);
64
65 static bool SendF(int16_t context, const char* title, const char *fmt, ...);
66
67 static bool IsNotificationUsed();
68
69 void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc = nullptr) override;
70
71 private:
72 static Notification* GetInstance();
73 static Notification* instance;
74
75 bool registerNotification(int16_t context,
76 bool titleSetByDevice,
77 bool messageSetByDevice,
78 bool soundSetByDevice);
79 bool send(int16_t context, const char *title, const char *message,
80 int soundId);
81 TDS_RegisterPushNotification* getContextConfig(int16_t context);
82
83 void setSrpc(Supla::Protocol::SuplaSrpc *srpc);
84
85 TDS_RegisterPushNotification notifications[SUPLA_NOTIF_MAX] = {};
86 int notificationCount = 0;
87 Supla::Protocol::SuplaSrpc *srpc = nullptr;
88 bool blockNewRegistration = false;
89};
90} // namespace Supla
91
92#endif // SRC_SUPLA_DEVICE_NOTIFICATIONS_H_
void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc=nullptr) override
Method called each time when device successfully registers to Supla server.
Definition notifications.cpp:173
Definition supla_srpc.h:55
Definition proto.h:3624