mirror of https://github.com/SeanOMik/libki.git
Add some other way to add Messages other than feeding a .xml file
This commit is contained in:
parent
cc788b12b3
commit
cb27ab578c
|
@ -17,6 +17,8 @@ namespace dml
|
||||||
~MessageManager();
|
~MessageManager();
|
||||||
|
|
||||||
const MessageModule *load_module(std::string filepath);
|
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(uint8_t service_id) const;
|
||||||
const MessageModule *get_module(const std::string &protocol_type) const;
|
const MessageModule *get_module(const std::string &protocol_type) const;
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ namespace dml
|
||||||
std::string get_protocol_desription() const;
|
std::string get_protocol_desription() const;
|
||||||
void set_protocol_description(std::string protocol_description);
|
void set_protocol_description(std::string protocol_description);
|
||||||
|
|
||||||
|
void add_message_template(MessageTemplate *message_template);
|
||||||
const MessageTemplate *add_message_template(std::string name,
|
const MessageTemplate *add_message_template(std::string name,
|
||||||
ki::dml::Record *record, bool auto_sort = true);
|
ki::dml::Record *record, bool auto_sort = true);
|
||||||
const MessageTemplate *get_message_template(uint8_t type) const;
|
const MessageTemplate *get_message_template(uint8_t type) const;
|
||||||
|
@ -34,8 +35,8 @@ namespace dml
|
||||||
|
|
||||||
void sort_lookup();
|
void sort_lookup();
|
||||||
|
|
||||||
Message *create_message(uint8_t message_type) const;
|
virtual Message *create_message(uint8_t message_type) const;
|
||||||
Message *create_message(std::string message_name) const;
|
virtual Message *create_message(std::string message_name) const;
|
||||||
private:
|
private:
|
||||||
uint8_t m_service_id;
|
uint8_t m_service_id;
|
||||||
std::string m_protocol_type;
|
std::string m_protocol_type;
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace dml
|
||||||
uint8_t get_access_level() const;
|
uint8_t get_access_level() const;
|
||||||
void set_access_level(uint8_t access_level);
|
void set_access_level(uint8_t access_level);
|
||||||
|
|
||||||
|
const bool has_record() const;
|
||||||
const ki::dml::Record &get_record() const;
|
const ki::dml::Record &get_record() const;
|
||||||
void set_record(ki::dml::Record *record);
|
void set_record(ki::dml::Record *record);
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,10 @@ namespace control
|
||||||
void SessionOffer::write_to(std::ostream& ostream) const
|
void SessionOffer::write_to(std::ostream& ostream) const
|
||||||
{
|
{
|
||||||
dml::Record record;
|
dml::Record record;
|
||||||
record.add_field<dml::USHRT>("m_session_id")->set_value(m_session_id);
|
record.add_field<dml::USHRT>("m_session_id")->set_value((dml::USHRT) m_session_id);
|
||||||
record.add_field<dml::UINT>("unknown");
|
record.add_field<dml::UINT>("unknown")->set_value((dml::UINT) 0);
|
||||||
record.add_field<dml::INT>("m_timestamp")->set_value(m_timestamp);
|
record.add_field<dml::INT>("m_timestamp")->set_value((dml::INT) m_timestamp);
|
||||||
record.add_field<dml::UINT>("m_milliseconds")->set_value(m_milliseconds);
|
record.add_field<dml::UINT>("m_milliseconds")->set_value((dml::UINT) m_milliseconds);
|
||||||
record.write_to(ostream);
|
record.write_to(ostream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,10 @@ namespace dml
|
||||||
Message::Message(const MessageTemplate *message_template)
|
Message::Message(const MessageTemplate *message_template)
|
||||||
{
|
{
|
||||||
m_template = 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());
|
m_record = new ki::dml::Record(m_template->get_record());
|
||||||
else
|
else
|
||||||
m_record = nullptr;
|
m_record = new ki::dml::Record();
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::~Message()
|
Message::~Message()
|
||||||
|
|
|
@ -134,14 +134,20 @@ namespace dml
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add it to our maps
|
// Add it to our maps
|
||||||
m_modules.push_back(message_module);
|
m_modules.emplace_back(message_module);
|
||||||
m_service_id_map.insert({ message_module->get_service_id(), message_module });
|
m_service_id_map.emplace(message_module->get_service_id(), message_module);
|
||||||
m_protocol_type_map.insert({ message_module->get_protocol_type(), message_module });
|
m_protocol_type_map.emplace(message_module->get_protocol_type(), message_module);
|
||||||
|
|
||||||
delete[] data;
|
delete[] data;
|
||||||
return message_module;
|
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
|
const MessageModule *MessageManager::get_module(uint8_t service_id) const
|
||||||
{
|
{
|
||||||
if (m_service_id_map.count(service_id) == 1)
|
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
|
// 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;
|
std::ostringstream oss;
|
||||||
oss << "No message exists with type: " << (uint16_t)header.get_service_id();
|
oss << "No message exists with type: " << (uint16_t)header.get_service_id();
|
||||||
oss << "(service=" << message_module->get_protocol_type() << ")";
|
oss << "(service=" << message_module->get_protocol_type() << ")";
|
||||||
throw value_error(oss.str(), value_error::DML_INVALID_MESSAGE_TYPE);
|
throw value_error(oss.str(), value_error::DML_INVALID_MESSAGE_TYPE);
|
||||||
}
|
} */
|
||||||
|
|
||||||
// Create a new Message from the template
|
// Create a new Message from the template
|
||||||
auto *message = new Message(message_template);
|
auto *message = new Message(message_template);
|
||||||
|
|
|
@ -55,6 +55,12 @@ namespace dml
|
||||||
m_protocol_description = protocol_description;
|
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,
|
const MessageTemplate *MessageModule::add_message_template(std::string name,
|
||||||
ki::dml::Record *record, bool auto_sort)
|
ki::dml::Record *record, bool auto_sort)
|
||||||
{
|
{
|
||||||
|
|
|
@ -76,6 +76,14 @@ namespace dml
|
||||||
m_record->add_field<ki::dml::UBYT>("_MsgAccessLvl")->set_value(access_level);
|
m_record->add_field<ki::dml::UBYT>("_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
|
const ki::dml::Record& MessageTemplate::get_record() const
|
||||||
{
|
{
|
||||||
return *m_record;
|
return *m_record;
|
||||||
|
|
Loading…
Reference in New Issue