diff --git a/include/ki/protocol/dml/MessageManager.h b/include/ki/protocol/dml/MessageManager.h index a051ba2..9c90996 100644 --- a/include/ki/protocol/dml/MessageManager.h +++ b/include/ki/protocol/dml/MessageManager.h @@ -17,6 +17,8 @@ namespace dml ~MessageManager(); const MessageModule *load_module(std::string filepath); + void load_module(MessageModule* module); + const MessageModule *get_module(uint8_t service_id) const; const MessageModule *get_module(const std::string &protocol_type) const; diff --git a/include/ki/protocol/dml/MessageModule.h b/include/ki/protocol/dml/MessageModule.h index c58e080..4e0c220 100644 --- a/include/ki/protocol/dml/MessageModule.h +++ b/include/ki/protocol/dml/MessageModule.h @@ -27,6 +27,7 @@ namespace dml std::string get_protocol_desription() const; void set_protocol_description(std::string protocol_description); + void add_message_template(MessageTemplate *message_template); const MessageTemplate *add_message_template(std::string name, ki::dml::Record *record, bool auto_sort = true); const MessageTemplate *get_message_template(uint8_t type) const; @@ -34,8 +35,8 @@ namespace dml void sort_lookup(); - Message *create_message(uint8_t message_type) const; - Message *create_message(std::string message_name) const; + virtual Message *create_message(uint8_t message_type) const; + virtual Message *create_message(std::string message_name) const; private: uint8_t m_service_id; std::string m_protocol_type; diff --git a/include/ki/protocol/dml/MessageTemplate.h b/include/ki/protocol/dml/MessageTemplate.h index 3f82ab2..fc51220 100644 --- a/include/ki/protocol/dml/MessageTemplate.h +++ b/include/ki/protocol/dml/MessageTemplate.h @@ -31,6 +31,7 @@ namespace dml uint8_t get_access_level() const; void set_access_level(uint8_t access_level); + const bool has_record() const; const ki::dml::Record &get_record() const; void set_record(ki::dml::Record *record); diff --git a/src/protocol/control/SessionOffer.cpp b/src/protocol/control/SessionOffer.cpp index 07627eb..c138747 100644 --- a/src/protocol/control/SessionOffer.cpp +++ b/src/protocol/control/SessionOffer.cpp @@ -49,10 +49,10 @@ namespace control void SessionOffer::write_to(std::ostream& ostream) const { dml::Record record; - record.add_field("m_session_id")->set_value(m_session_id); - record.add_field("unknown"); - record.add_field("m_timestamp")->set_value(m_timestamp); - record.add_field("m_milliseconds")->set_value(m_milliseconds); + record.add_field("m_session_id")->set_value((dml::USHRT) m_session_id); + record.add_field("unknown")->set_value((dml::UINT) 0); + record.add_field("m_timestamp")->set_value((dml::INT) m_timestamp); + record.add_field("m_milliseconds")->set_value((dml::UINT) m_milliseconds); record.write_to(ostream); } diff --git a/src/protocol/dml/Message.cpp b/src/protocol/dml/Message.cpp index 215a694..a2a3d38 100644 --- a/src/protocol/dml/Message.cpp +++ b/src/protocol/dml/Message.cpp @@ -11,10 +11,10 @@ namespace dml Message::Message(const MessageTemplate *message_template) { m_template = message_template; - if (m_template) + if (m_template && m_template->has_record()) m_record = new ki::dml::Record(m_template->get_record()); else - m_record = nullptr; + m_record = new ki::dml::Record(); } Message::~Message() diff --git a/src/protocol/dml/MessageManager.cpp b/src/protocol/dml/MessageManager.cpp index 09b105d..70c43c5 100644 --- a/src/protocol/dml/MessageManager.cpp +++ b/src/protocol/dml/MessageManager.cpp @@ -134,14 +134,20 @@ namespace dml } // Add it to our maps - m_modules.push_back(message_module); - m_service_id_map.insert({ message_module->get_service_id(), message_module }); - m_protocol_type_map.insert({ message_module->get_protocol_type(), message_module }); + m_modules.emplace_back(message_module); + m_service_id_map.emplace(message_module->get_service_id(), message_module); + m_protocol_type_map.emplace(message_module->get_protocol_type(), message_module); delete[] data; return message_module; } + void MessageManager::load_module(MessageModule* module) { + m_modules.emplace_back(module); + m_service_id_map.emplace(module->get_service_id(), module); + m_protocol_type_map.emplace(module->get_protocol_type(), module); + } + const MessageModule *MessageManager::get_module(uint8_t service_id) const { if (m_service_id_map.count(service_id) == 1) @@ -234,13 +240,13 @@ namespace dml } // Make sure that the size specified is enough to read this message - if (header.get_message_size() < message_template->get_record().get_size()) + /* if (header.get_message_size() < message_template->get_record().get_size()) { std::ostringstream oss; oss << "No message exists with type: " << (uint16_t)header.get_service_id(); oss << "(service=" << message_module->get_protocol_type() << ")"; throw value_error(oss.str(), value_error::DML_INVALID_MESSAGE_TYPE); - } + } */ // Create a new Message from the template auto *message = new Message(message_template); diff --git a/src/protocol/dml/MessageModule.cpp b/src/protocol/dml/MessageModule.cpp index 147c295..aa159ce 100644 --- a/src/protocol/dml/MessageModule.cpp +++ b/src/protocol/dml/MessageModule.cpp @@ -55,6 +55,12 @@ namespace dml m_protocol_description = protocol_description; } + void MessageModule::add_message_template(MessageTemplate *message_template) { + m_templates.push_back(message_template); + m_message_name_map.emplace(message_template->get_name(), message_template); + m_message_type_map.emplace(message_template->get_type(), message_template); + } + const MessageTemplate *MessageModule::add_message_template(std::string name, ki::dml::Record *record, bool auto_sort) { diff --git a/src/protocol/dml/MessageTemplate.cpp b/src/protocol/dml/MessageTemplate.cpp index 9e79929..4594868 100644 --- a/src/protocol/dml/MessageTemplate.cpp +++ b/src/protocol/dml/MessageTemplate.cpp @@ -76,6 +76,14 @@ namespace dml m_record->add_field("_MsgAccessLvl")->set_value(access_level); } + const bool MessageTemplate::has_record() const { + if (m_record) { + return true; + } else { + return false; + } + } + const ki::dml::Record& MessageTemplate::get_record() const { return *m_record;