OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
joystick_protocol.hpp
1#pragma once
2
3#include <ossia/network/base/protocol.hpp>
4#include <ossia/network/common/complex_type.hpp>
5#include <ossia/network/common/device_parameter.hpp>
6#include <ossia/network/context_functions.hpp>
7#include <ossia/network/domain/domain.hpp>
8
9#include <vector>
10
11typedef struct _SDL_Joystick SDL_Joystick;
12
13namespace ossia::net
14{
15class joystick_protocol_manager;
16struct joystick_event_processor;
17
18struct OSSIA_EXPORT joystick_info
19{
20 static unsigned int get_joystick_count();
21 static const char* get_joystick_name(const int index);
22 static bool get_joystick_is_gamepad(const int index);
23 static int32_t get_joystick_id(const int index);
24 static void write_joystick_uuid(const int index, uint8_t* dst);
25
26 // {device id, device index} or {-1, -1} if no suitable joystick is available
27 static std::pair<int32_t, int32_t> get_available_id_for_uid(const uint8_t* uid);
28};
29
30class OSSIA_EXPORT joystick_protocol final : public ossia::net::protocol_base
31{
32 friend class joystick_protocol_manager;
33 friend struct joystick_event_processor;
34
35public:
36 joystick_protocol(
37 ossia::net::network_context_ptr, const int32_t joystick_id,
38 const int joystick_index);
39 joystick_protocol(const joystick_protocol&) = delete;
40 joystick_protocol(joystick_protocol&&) = delete;
41 joystick_protocol& operator=(const joystick_protocol&) = delete;
42 joystick_protocol& operator=(joystick_protocol&&) = delete;
43 ~joystick_protocol() override;
44
45 void set_device(ossia::net::device_base& dev) override;
46
47 bool pull(ossia::net::parameter_base& param) override;
48 bool push(const ossia::net::parameter_base& param, const ossia::value& v) override;
49 bool push_raw(const ossia::net::full_parameter_data&) override;
50 bool observe(ossia::net::parameter_base& param, bool enable) override;
51
52 bool update(ossia::net::node_base&) override;
53 void stop() override;
54
55private:
56 joystick_protocol_manager& m_manager;
57 joystick_event_processor& m_processor;
58 ossia::net::network_context_ptr m_ctx{};
59
60 ossia::net::device_base* m_device{};
61
62 std::vector<device_parameter*> m_axis_parameters;
63 std::vector<device_parameter*> m_hat_parameters;
64 std::vector<device_parameter*> m_ball_parameters;
65 std::vector<device_parameter*> m_button_parameters;
66
67 int32_t m_joystick_id{};
68 SDL_Joystick* m_joystick{};
69};
70}
Root of a device tree.
Definition ossia/network/base/device.hpp:58
The node_base class.
Definition node.hpp:48
The parameter_base class.
Definition ossia/network/base/parameter.hpp:48
The protocol_base class.
Definition protocol.hpp:40
The value class.
Definition value.hpp:173
Full information about a parameter.
Definition parameter_data.hpp:61