5 #ifndef _UGCS_VSM_DEVICE_H_
6 #define _UGCS_VSM_DEVICE_H_
8 #include <ugcs/vsm/property.h>
11 #include <ugcs/vsm/optional.h>
12 #include <ugcs/vsm/subsystem.h>
16 #include <unordered_map>
17 #include <unordered_set>
31 ugcs::vsm::proto::Status_code = ugcs::vsm::proto::STATUS_OK,
32 const std::
string& description = std::
string());
35 Proto_msg_ptr response =
nullptr;
38 uint32_t stream_id = 0;
40 ugcs::vsm::proto::Vsm_message request;
47 Socket_address::Ptr address;
51 std::chrono::time_point<std::chrono::steady_clock> last_message_time;
54 class Device:
public std::enable_shared_from_this<Device>
65 proto::Device_type type,
94 Is_enabled() {
return is_enabled;}
104 ugcs::vsm::proto::Vsm_message message,
105 Response_sender completion_handler = Response_sender(),
111 Register(ugcs::vsm::proto::Vsm_message&);
114 template<
typename Type>
117 const std::string& name,
119 proto::Field_semantic semantic = proto::FIELD_SEMANTIC_DEFAULT)
121 auto it = properties.find(name);
122 if (it == properties.end()) {
124 properties.emplace(name, f);
127 it->second->Set_value(value);
137 Get_completion_ctx();
140 Set_failsafe_actions(
Property::Ptr p, std::initializer_list<proto::Failsafe_action> actions);
157 Dump_command(
const ugcs::vsm::proto::Device_command &);
160 Add_subsystem(proto::Subsystem_type);
164 Get_processing_ctx();
210 float progress = -1.0,
211 const std::string& description = std::string());
214 Send_ucs_message(Proto_msg_ptr msg);
221 Add_status_message(
const std::string& m);
234 #define CREATE_COMMIT_SCOPE auto auto_device_commit_scope = Commit_scope(*this)
238 Commit_to_ucs(
bool log_message =
false);
240 const proto::Device_type device_type;
245 std::chrono::time_point<std::chrono::system_clock> begin_of_epoch;
247 std::vector<Subsystem::Ptr> subsystems;
253 std::list<std::string> device_status_messages;
255 uint32_t my_handle = 0;
258 bool is_enabled =
false;
260 std::unordered_map<std::string, Property::Ptr> properties;
265 #define DEVICE_LOG(level_, vehicle_, fmt_, ...) \
266 _LOG_WRITE_MSG(level_, "[%d] " fmt_, \
267 (vehicle_).Get_session_id(), ## __VA_ARGS__)
272 #define DEVICE_LOG_DBG(vehicle_, fmt_, ...) \
273 DEVICE_LOG(::ugcs::vsm::Log::Level::DEBUGGING, vehicle_, fmt_, ## __VA_ARGS__)
275 #define DEVICE_LOG_INF(vehicle_, fmt_, ...) \
276 DEVICE_LOG(::ugcs::vsm::Log::Level::INFO, vehicle_, fmt_, ## __VA_ARGS__)
278 #define DEVICE_LOG_WRN(vehicle_, fmt_, ...) \
279 DEVICE_LOG(::ugcs::vsm::Log::Level::WARNING, vehicle_, fmt_, ## __VA_ARGS__)
281 #define DEVICE_LOG_ERR(vehicle_, fmt_, ...) \
282 DEVICE_LOG(::ugcs::vsm::Log::Level::ERROR, vehicle_, fmt_, ## __VA_ARGS__)
static Ptr Create(Args &&...args)
Create an instance.
Definition: property.h:18
Generic request for implementing inter-threads communications and asynchronous operations.
Definition: request_container.h:37
std::shared_ptr< Property > Ptr
Pointer type.
Definition: property.h:18
virtual void On_enable()
Device enable event handler.
Definition: device.h:184
virtual void Handle_ucs_info(std::vector< Ucs_info >)
Called when number of ucs connections change.
Definition: device.h:176
virtual void On_disable()
Device disable event handler.
Definition: device.h:191
Generic callback which can be used to define and create an instance of an abstract callable operation...
std::shared_ptr< Request_worker > Ptr
Pointer type.
Definition: request_worker.h:25
Request execution context.
Definition: request_context.h:24
Definition: property.h:16
Helper class for proxying callback invocation.
Definition: callback.h:699
std::shared_ptr< Vsm_command > Ptr
Pointer type.
Definition: subsystem.h:24
std::shared_ptr< Device > Ptr
Pointer type.
Definition: device.h:56
std::shared_ptr< Request_context > Ptr
Pointer type.
Definition: request_context.h:25
std::shared_ptr< Subsystem > Ptr
Pointer type.
Definition: subsystem.h:88
#define DEFINE_COMMON_CLASS(__class_name,...)
Use this macro to define some common attributes for a class.
Definition: utils.h:25
T value
Stored value (in wire byte order).
Definition: endian.h:376
std::shared_ptr< Ucs_request > Ptr
Pointer type.
Definition: device.h:24