-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhue_sensor_command_posix.hpp
65 lines (56 loc) · 2.08 KB
/
hue_sensor_command_posix.hpp
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
/*
* Copyright (C) 2018-2019 Ivan Schréter ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This copyright notice MUST APPEAR in all copies of the software!
*/
/*!
* @file
* @brief Command handler to post commands to Hue bridge via virtual sensor using POSIX sockets.
*/
#pragma once
#include "embedded/hue_sensor_command.hpp"
class hue_sensor_command_posix : public hue_sensor_command
{
public:
/*!
* @brief Construct command hander to send commands to the Hue bridge via a sensor.
*
* @param ip IP address of the bride.
* @param api_key API key assigned by the bridge.
* @param sensor_id sensor ID assigned by the bridge.
*
* The command handler PUTs to the Sensor URL in form
* <tt>http://<ip>/api/<api_key>/sensors/<sensor_id></tt>.
* It PUTs JSON document in the form:
* <tt>{"state":{"status": <value>}}</tt>
*/
explicit hue_sensor_command_posix(uint32_t ip, const char* api_key, int sensor_id) noexcept :
hue_sensor_command(ip, api_key, sensor_id)
{}
/// Get FD to poll on, if any.
int get_fd() const noexcept { return fd_; }
/// Get events to poll for.
short get_events() const noexcept;
/// Process events on file descriptor.
virtual void poll() override;
/// Get current timestamp.
virtual int64_t timestamp() noexcept override;
private:
/// Start connecting to the remote side.
virtual bool start_connect() override;
/// File descriptor of the current connection, if any.
int fd_ = -1;
};