-
Notifications
You must be signed in to change notification settings - Fork 22
/
deconz.h
94 lines (68 loc) · 2.64 KB
/
deconz.h
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
//***************************************************************************
// Automation Control
// File deconz.h
// This code is distributed under the terms and conditions of the
// GNU GENERAL PUBLIC LICENSE. See the file LICENSE for details.
// Date 04.11.2010 - 15.12.2021 Jörg Wendel
//***************************************************************************
#pragma once
#include "lib/common.h"
class Daemon;
//***************************************************************************
// Class Deconz
//***************************************************************************
class Deconz
{
public:
Deconz();
~Deconz();
int init(Daemon* parent, cDbConnection* connection);
int exit();
void setApiKey(const char* key) { apiKey = key; }
void setHttpUrl(const char* url) { httpUrl = url; }
const char* getHttpUrl() { return httpUrl.c_str(); }
const char* getApiKey() { return apiKey.c_str(); }
int query(json_t*& jResult, const char* method, const char* apiKey);
int put(json_t*& jResult, const char* uuid, json_t* jData);
int post(json_t*& jResult, const char* method, const char* payload);
int checkResult(json_t* jArray);
int queryApiKey(std::string& result);
int initDevices();
int processDevices(json_t* jData, std::string kind);
int toggle(const char* type, uint address, bool state, int bri = na, int transitiontime = na);
int color(const char* type, uint address, int hue, int saturation, int bri);
static struct lws* client_wsi; // needed???
static cMyMutex messagesInMutex;
static std::queue<std::string> messagesIn;
private:
int initWsClient();
int exitWsClient();
int service();
static int callbackDeconzWs(struct lws* wsi, enum lws_callback_reasons reason, void* user, void* in, size_t len);
//
std::string httpUrl;
std::string apiKey;
Daemon* daemon {};
std::map<std::string,uint> lights;
std::map<std::string,uint> sensors;
static cMyMutex mapsMutex;
cDbTable* tableDeconzLights {};
cDbTable* tableDeconzSensors {};
cDbStatement* selectLightByUuid {};
cDbStatement* selectSensorByUuid {};
lws_protocols protocols[2];
// sync thread stuff
struct ThreadControl
{
bool active {false};
bool close {false};
Deconz* deconz {};
int timeout {60};
};
pthread_t syncThread {0};
ThreadControl threadCtl;
static void* syncFct(void* user);
int atInMessage(const char* data);
static Deconz* singleton;
static struct lws_context* context;
};