12 #ifndef _UGCS_VSM_CUCS_PROCESSOR_H_
13 #define _UGCS_VSM_CUCS_PROCESSOR_H_
16 #include <ugcs/vsm/device.h>
19 #include <ugcs/vsm/transport_detector.h>
20 #include <ucs_vsm_proto.h>
21 #include <unordered_set>
44 template <
typename... Args>
48 return singleton.Get_instance(std::forward<Args>(args)...);
61 Send_ucs_message(uint32_t handle, Proto_msg_ptr message, uint32_t stream_id = 0);
64 constexpr
static uint32_t SUPPORTED_UCS_VERSION_MAJOR = 2;
65 constexpr
static uint32_t SUPPORTED_UCS_VERSION_MINOR = 14;
69 constexpr
static std::chrono::seconds WRITE_TIMEOUT = std::chrono::seconds(60);
72 constexpr
static std::chrono::seconds REGISTER_PEER_TIMEOUT = std::chrono::seconds(10);
75 constexpr
static size_t PROTO_MAX_MESSAGE_LEN = 1000000;
85 uint32_t ucs_id_counter;
89 std::chrono::seconds keep_alive_timeout = std::chrono::seconds(0);
92 Get_next_id() {
return ucs_id_counter++; }
97 Socket_address::Ptr address;
98 Optional<uint32_t> ucs_id;
99 Operation_waiter read_waiter;
102 bool reading_header =
true;
104 size_t message_size = 0;
109 bool primary =
false;
112 bool is_compatible =
true;
116 std::unordered_set<uint32_t> registered_devices;
119 std::unordered_map<uint32_t, uint32_t> pending_registrations;
122 std::chrono::time_point<std::chrono::steady_clock> last_message_time;
128 std::unordered_map<uint32_t, ugcs::vsm::proto::Telemetry_field> telemetry_cache;
129 std::unordered_map<uint32_t, ugcs::vsm::proto::Command_availability> availability_cache;
134 ugcs::vsm::proto::Vsm_message registration_message;
140 Server_context> ucs_connections;
145 Vehicle_context> vehicles;
149 Transport_detector::Ptr ucs_connector;
152 bool transport_detector_on_when_diconnected =
false;
157 On_enable()
override;
160 On_disable()
override;
170 On_incoming_connection(std::string,
int, Socket_address::Ptr,
Io_stream::Ref);
174 Schedule_next_read(Server_context& sc);
196 On_send_ucs_message(
Request::Ptr request, uint32_t handle, Proto_msg_ptr message, uint32_t stream_id);
201 ugcs::vsm::proto::Vsm_message& message);
204 Send_ucs_message_ptr(uint32_t stream_id, Proto_msg_ptr message);
209 Broadcast_message_to_ucs(ugcs::vsm::proto::Vsm_message& message);
214 ugcs::vsm::proto::Vsm_message message);
217 On_ucs_message_vehicle(
219 ugcs::vsm::proto::Vsm_message message);
222 Send_vehicle_registrations(
223 Server_context& ctx);
226 Get_device(uint32_t device_id);
229 Close_ucs_stream(
size_t stream_id);
232 Notify_device_about_ucs_connections(uint32_t device_id);
235 static Singleton<Cucs_processor> singleton;
Reference_guard< Io_stream::Ptr > Ref
Guard object.
Definition: io_stream.h:71
Io_result
Result of I/O operation.
Definition: io_stream.h:37
std::shared_ptr< Cucs_processor > Ptr
Pointer type.
Definition: cucs_processor.h:35
void Unregister_device(uint32_t handle)
Unregistration of a vehicle instance in the processor.
std::shared_ptr< Request > Ptr
Pointer type.
Definition: request_container.h:38
std::shared_ptr< Request_worker > Ptr
Pointer type.
Definition: request_worker.h:25
Request execution context.
Definition: request_context.h:24
Handles interactions with CUCS.
Definition: cucs_processor.h:34
std::shared_ptr< Device > Ptr
Pointer type.
Definition: device.h:56
Generic container for queued requests.
Definition: request_container.h:30
static Ptr Get_instance(Args &&...args)
Get global or create new processor instance.
Definition: cucs_processor.h:46
std::shared_ptr< Request_context > Ptr
Pointer type.
Definition: request_context.h:25
std::shared_ptr< Io_buffer > Ptr
Pointer type.
Definition: io_buffer.h:34
#define DEFINE_COMMON_CLASS(__class_name,...)
Use this macro to define some common attributes for a class.
Definition: utils.h:25
std::shared_ptr< Timer > Ptr
Pointer type.
Definition: timer_processor.h:46
void Register_device(Device::Ptr)
Registration of a vehicle instance in the processor.
Cucs_processor()
Default constructor.