1. 新建车牌识别程序。

main
baocm 9 months ago
parent 755cefd0fb
commit f77169189b

@ -41,6 +41,18 @@ target_link_libraries(Demo fastcdr fastdds
System_lib
)
# HttpServer Application.
add_executable(HttpServer
httpserver/main.cxx
httpserver/Publisher.cxx
httpserver/Subscriber.cxx
httpserver/httpserver.cxx
)
target_include_directories(HttpServer PRIVATE httpserver)
target_link_libraries(HttpServer fastcdr fastdds
System_lib
)
# Print Application.
add_executable(Print
print/main.cxx

@ -0,0 +1,198 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*!
* @file Publisher.cxx
* This file contains the implementation of the publisher functions.
*
* This file was generated by the tool fastddsgen.
*/
#include "Publisher.hpp"
#include <condition_variable>
#include <csignal>
#include <stdexcept>
#include <thread>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/dds/publisher/DataWriter.hpp>
#include <fastdds/dds/publisher/Publisher.hpp>
#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
#include <fastdds/dds/publisher/qos/PublisherQos.hpp>
#include "SystemPubSubTypes.hpp"
#include "json.hpp"
using json = nlohmann::json;
using namespace eprosima::fastdds::dds;
PublisherApp::PublisherApp(
const int& domain_id)
: factory_(nullptr)
, participant_(nullptr)
, publisher_(nullptr)
, topic_(nullptr)
, writer_(nullptr)
, type_(new LicencePlateRspPubSubType())
, matched_(0)
, samples_sent_(0)
, stop_(false)
{
//
// Create the participant
DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT;
pqos.name("HttpServer_pub_participant");
pqos.wire_protocol().builtin.discovery_config.leaseDuration = Duration_t(60, 0);
pqos.wire_protocol().builtin.discovery_config.leaseDuration_announcementperiod = Duration_t(30, 0);
factory_ = DomainParticipantFactory::get_shared_instance();
participant_ = factory_->create_participant(domain_id, pqos, nullptr, StatusMask::none());
if (participant_ == nullptr)
{
throw std::runtime_error("HttpServerPub Participant initialization failed");
}
// Register the type
type_.register_type(participant_);
// Create the publisher
PublisherQos pub_qos = PUBLISHER_QOS_DEFAULT;
participant_->get_default_publisher_qos(pub_qos);
publisher_ = participant_->create_publisher(pub_qos, nullptr, StatusMask::none());
if (publisher_ == nullptr)
{
throw std::runtime_error("LicencePlateRsp Publisher initialization failed");
}
// Create the topic
TopicQos topic_qos = TOPIC_QOS_DEFAULT;
participant_->get_default_topic_qos(topic_qos);
topic_ = participant_->create_topic("LicencePlateRspTopic", type_.get_type_name(), topic_qos);
if (topic_ == nullptr)
{
throw std::runtime_error("LicencePlateRsp Topic initialization failed");
}
// Create the data writer
DataWriterQos writer_qos = DATAWRITER_QOS_DEFAULT;
publisher_->get_default_datawriter_qos(writer_qos);
writer_qos.reliability().kind = ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
writer_qos.durability().kind = DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS;
writer_qos.history().kind = HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
writer_ = publisher_->create_datawriter(topic_, writer_qos, this, StatusMask::all());
if (writer_ == nullptr)
{
throw std::runtime_error("LicencePlateRsp DataWriter initialization failed");
}
}
PublisherApp::~PublisherApp()
{
if (nullptr != participant_)
{
// Delete DDS entities contained within the DomainParticipant
participant_->delete_contained_entities();
// Delete DomainParticipant
factory_->delete_participant(participant_);
}
}
void PublisherApp::on_publication_matched(
DataWriter* writer,
const PublicationMatchedStatus& info)
{
if (info.current_count_change == 1)
{
{
std::lock_guard<std::mutex> lock(mutex_);
matched_ = info.current_count;
}
std::cout << writer->get_topic()->get_name() << " Publisher matched." << std::endl;
cv_.notify_one();
}
else if (info.current_count_change == -1)
{
{
std::lock_guard<std::mutex> lock(mutex_);
matched_ = info.current_count;
}
std::cout << writer->get_topic()->get_name() << " Publisher unmatched." << std::endl;
}
else
{
std::cout << info.current_count_change
<< " is not a valid value for PublicationMatchedStatus current count change" << std::endl;
}
}
void PublisherApp::run(std::shared_ptr<HTTPServer> handler)
{
while (!is_stopped())
{
handler->run();
if (handler->PostMsg.empty() != true)
{
json j = json::parse(handler->PostMsg);
std::cout << "车牌: " << j["AlarmInfoPlate"]["result"]["PlateResult"]["license"] << std::endl;
LicencePlateRsp rsp;
rsp.licence() = j["AlarmInfoPlate"]["result"]["PlateResult"]["license"];
writer_->write(&rsp);
handler->PostMsg.clear();
}
// Wait for period or stop event
std::unique_lock<std::mutex> period_lock(mutex_);
cv_.wait_for(period_lock, std::chrono::milliseconds(period_ms_), [this]()
{
return is_stopped();
});
}
}
bool PublisherApp::publish()
{
bool ret = false;
// Wait for the data endpoints discovery
std::unique_lock<std::mutex> matched_lock(mutex_);
cv_.wait(matched_lock, [&]()
{
// at least one has been discovered
return ((matched_ > 0) || is_stopped());
});
if (!is_stopped())
{
/* Initialize your structure here */
WeighRsp sample_;
ret = (RETCODE_OK == writer_->write(&sample_));
}
return ret;
}
bool PublisherApp::is_stopped()
{
return stop_.load();
}
void PublisherApp::stop()
{
stop_.store(true);
cv_.notify_one();
}

@ -0,0 +1,76 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*!
* @file PublisherApp.hpp
* This header file contains the declaration of the publisher functions.
*
* This file was generated by the tool fastddsgen.
*/
#ifndef FAST_DDS_GENERATED__PUBLISHERAPP_HPP
#define FAST_DDS_GENERATED__PUBLISHERAPP_HPP
#include <condition_variable>
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/publisher/DataWriterListener.hpp>
#include <fastdds/dds/topic/TypeSupport.hpp>
#include "httpserver.hpp"
class PublisherApp : public eprosima::fastdds::dds::DataWriterListener
{
public:
PublisherApp(
const int& domain_id);
~PublisherApp();
//! Publisher matched method
void on_publication_matched(
eprosima::fastdds::dds::DataWriter* writer,
const eprosima::fastdds::dds::PublicationMatchedStatus& info) override;
//! Run publisher
void run(std::shared_ptr<HTTPServer> handler);
//! Trigger the end of execution
void stop();
private:
//! Return the current state of execution
bool is_stopped();
//! Publish a sample
bool publish();
std::shared_ptr<eprosima::fastdds::dds::DomainParticipantFactory> factory_;
eprosima::fastdds::dds::DomainParticipant* participant_;
eprosima::fastdds::dds::Publisher* publisher_;
eprosima::fastdds::dds::Topic* topic_;
eprosima::fastdds::dds::DataWriter* writer_;
eprosima::fastdds::dds::TypeSupport type_;
std::condition_variable cv_;
int32_t matched_;
std::mutex mutex_;
const uint32_t period_ms_ = 100; // in ms
uint16_t samples_sent_;
std::atomic<bool> stop_;
};
#endif // FAST_DDS_GENERATED__PUBLISHERAPP_HPP

@ -0,0 +1,159 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*!
* @file Subscriber.cxx
* This file contains the implementation of the subscriber functions.
*
* This file was generated by the tool fastddsgen.
*/
#include "Subscriber.hpp"
#include <condition_variable>
#include <stdexcept>
#include <fastdds/dds/core/status/SubscriptionMatchedStatus.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/subscriber/DataReader.hpp>
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
#include <fastdds/dds/subscriber/qos/SubscriberQos.hpp>
#include <fastdds/dds/subscriber/SampleInfo.hpp>
#include <fastdds/dds/subscriber/Subscriber.hpp>
#include "SystemPubSubTypes.hpp"
using namespace eprosima::fastdds::dds;
SubscriberApp::SubscriberApp(
const int& domain_id)
: factory_(nullptr)
, participant_(nullptr)
, subscriber_(nullptr)
, topic_(nullptr)
, reader_(nullptr)
, type_(new LicencePlateReqPubSubType())
, samples_received_(0)
, stop_(false)
{
// Create the participant
DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT;
pqos.name("HttpServer_sub_participant");
pqos.wire_protocol().builtin.discovery_config.leaseDuration = Duration_t(60, 0);
pqos.wire_protocol().builtin.discovery_config.leaseDuration_announcementperiod = Duration_t(30, 0);
factory_ = DomainParticipantFactory::get_shared_instance();
participant_ = factory_->create_participant(domain_id, pqos, nullptr, StatusMask::none());
if (participant_ == nullptr)
{
throw std::runtime_error("HttpServerSub Participant initialization failed");
}
// Register the type
type_.register_type(participant_);
// Create the subscriber
SubscriberQos sub_qos = SUBSCRIBER_QOS_DEFAULT;
participant_->get_default_subscriber_qos(sub_qos);
subscriber_ = participant_->create_subscriber(sub_qos, nullptr, StatusMask::none());
if (subscriber_ == nullptr)
{
throw std::runtime_error("LicencePlateReq Subscriber initialization failed");
}
// Create the topic
TopicQos topic_qos = TOPIC_QOS_DEFAULT;
participant_->get_default_topic_qos(topic_qos);
topic_ = participant_->create_topic("LicencePlateReqTopic", type_.get_type_name(), topic_qos);
if (topic_ == nullptr)
{
throw std::runtime_error("LicencePlateReq Topic initialization failed");
}
// Create the reader
DataReaderQos reader_qos = DATAREADER_QOS_DEFAULT;
subscriber_->get_default_datareader_qos(reader_qos);
reader_qos.reliability().kind = ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
reader_qos.durability().kind = DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS;
reader_qos.history().kind = HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
reader_ = subscriber_->create_datareader(topic_, reader_qos, this, StatusMask::all());
if (reader_ == nullptr)
{
throw std::runtime_error("LicencePlateReq DataReader initialization failed");
}
}
SubscriberApp::~SubscriberApp()
{
if (nullptr != participant_)
{
// Delete DDS entities contained within the DomainParticipant
participant_->delete_contained_entities();
// Delete DomainParticipant
factory_->delete_participant(participant_);
}
}
void SubscriberApp::on_subscription_matched(
DataReader* reader,
const SubscriptionMatchedStatus& info)
{
if (info.current_count_change == 1)
{
std::cout << reader->get_topicdescription()->get_name() << " Subscriber matched." << std::endl;
}
else if (info.current_count_change == -1)
{
std::cout << reader->get_topicdescription()->get_name() << " Subscriber unmatched." << std::endl;
}
else
{
std::cout << info.current_count_change
<< " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl;
}
}
void SubscriberApp::on_data_available(
DataReader* reader)
{
LicencePlateReq sample_;
SampleInfo info;
while ((!is_stopped()) && (RETCODE_OK == reader->take_next_sample(&sample_, &info)))
{
if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data)
{
std::cout << "Sample '" << std::to_string(++samples_received_) << "' RECEIVED" << std::endl;
}
}
}
void SubscriberApp::run()
{
std::unique_lock<std::mutex> lck(terminate_cv_mtx_);
terminate_cv_.wait(lck, [this]
{
return is_stopped();
});
}
bool SubscriberApp::is_stopped()
{
return stop_.load();
}
void SubscriberApp::stop()
{
stop_.store(true);
terminate_cv_.notify_all();
}

@ -0,0 +1,75 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*!
* @file SubscriberApp.hpp
* This header file contains the declaration of the subscriber functions.
*
* This file was generated by the tool fastddsgen.
*/
#ifndef FAST_DDS_GENERATED__SUBSCRIBERAPP_HPP
#define FAST_DDS_GENERATED__SUBSCRIBERAPP_HPP
#include <condition_variable>
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/subscriber/DataReaderListener.hpp>
#include <fastdds/dds/topic/TypeSupport.hpp>
#include "System.hpp"
class SubscriberApp : public eprosima::fastdds::dds::DataReaderListener
{
public:
SubscriberApp(
const int& domain_id);
virtual ~SubscriberApp();
//! Subscription callback
void on_data_available(
eprosima::fastdds::dds::DataReader* reader) override;
//! Subscriber matched method
void on_subscription_matched(
eprosima::fastdds::dds::DataReader* reader,
const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) override;
//! Run subscriber
void run();
//! Trigger the end of execution
void stop();
private:
//! Return the current state of execution
bool is_stopped();
std::shared_ptr<eprosima::fastdds::dds::DomainParticipantFactory> factory_;
eprosima::fastdds::dds::DomainParticipant* participant_;
eprosima::fastdds::dds::Subscriber* subscriber_;
eprosima::fastdds::dds::Topic* topic_;
eprosima::fastdds::dds::DataReader* reader_;
eprosima::fastdds::dds::TypeSupport type_;
uint16_t samples_received_;
std::atomic<bool> stop_;
mutable std::mutex terminate_cv_mtx_;
std::condition_variable terminate_cv_;
};
#endif // FAST_DDS_GENERATED__SUBSCRIBERAPP_HPP

@ -0,0 +1,640 @@
#include "httpserver.hpp"
#include <iostream>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <memory>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <signal.h>
#include <fcntl.h>
#include <ctime>
// ==================== 工具函数实现 ====================
std::string HTTPServer::urlDecode(const std::string &encoded)
{
std::string decoded;
for (size_t i = 0; i < encoded.length(); ++i)
{
if (encoded[i] == '%' && i + 2 < encoded.length())
{
int hex;
std::istringstream hexStream(encoded.substr(i + 1, 2));
if (hexStream >> std::hex >> hex)
{
decoded += static_cast<char>(hex);
i += 2;
}
else
{
decoded += encoded[i];
}
}
else if (encoded[i] == '+')
{
decoded += ' ';
}
else
{
decoded += encoded[i];
}
}
return decoded;
}
std::map<std::string, std::string> HTTPServer::parseQueryString(const std::string &query)
{
std::map<std::string, std::string> params;
std::istringstream stream(query);
std::string pair;
while (std::getline(stream, pair, '&'))
{
size_t equalsPos = pair.find('=');
if (equalsPos != std::string::npos)
{
std::string key = urlDecode(pair.substr(0, equalsPos));
std::string value = urlDecode(pair.substr(equalsPos + 1));
params[key] = value;
}
else if (!pair.empty())
{
params[urlDecode(pair)] = "";
}
}
return params;
}
std::map<std::string, std::string> HTTPServer::parseHeaders(const std::string &headers)
{
std::map<std::string, std::string> header_map;
std::istringstream stream(headers);
std::string line;
while (std::getline(stream, line))
{
if (line.empty() || line == "\r")
continue;
// 移除可能的回车符
if (!line.empty() && line.back() == '\r')
{
line.pop_back();
}
size_t colonPos = line.find(':');
if (colonPos != std::string::npos)
{
std::string key = line.substr(0, colonPos);
// 跳过冒号和空格
size_t value_start = colonPos + 1;
while (value_start < line.length() && line[value_start] == ' ')
{
value_start++;
}
std::string value = line.substr(value_start);
header_map[key] = value;
}
}
return header_map;
}
std::string HTTPServer::getContentType(const std::map<std::string, std::string> &headers)
{
auto it = headers.find("Content-Type");
if (it != headers.end())
{
return it->second;
}
return "";
}
int HTTPServer::getContentLength(const std::map<std::string, std::string> &headers)
{
auto it = headers.find("Content-Length");
if (it != headers.end())
{
try
{
return std::stoi(it->second);
}
catch (const std::exception &e)
{
std::cerr << "解析Content-Length错误: " << e.what() << std::endl;
return 0;
}
}
return 0;
}
void HTTPServer::sendResponse(int client_socket, const std::string &response,
const std::string &content_type)
{
std::string httpResponse =
"HTTP/1.1 200 OK\r\n"
"Content-Type: " +
content_type + "\r\n"
"Content-Length: " +
std::to_string(response.length()) + "\r\n"
"Connection: close\r\n"
"\r\n" +
response;
send(client_socket, httpResponse.c_str(), httpResponse.length(), 0);
}
void HTTPServer::sendError(int client_socket, int code, const std::string &message)
{
std::string response = "<html><body><h1>" + std::to_string(code) + " " + message + "</h1></body></html>";
std::string httpResponse =
"HTTP/1.1 " + std::to_string(code) + " " + message + "\r\n"
"Content-Type: text/html; charset=utf-8\r\n"
"Content-Length: " +
std::to_string(response.length()) + "\r\n"
"Connection: close\r\n"
"\r\n" +
response;
send(client_socket, httpResponse.c_str(), httpResponse.length(), 0);
}
void HTTPServer::sendJSONResponse(int client_socket, const std::string &json)
{
sendResponse(client_socket, json, "application/json");
}
// ==================== 私有方法实现 ====================
std::string HTTPServer::readFullRequest(int client_socket, int timeout_ms)
{
std::string request;
char buffer[4096];
fd_set read_fds;
struct timeval timeout;
// 设置非阻塞模式
int flags = fcntl(client_socket, F_GETFL, 0);
fcntl(client_socket, F_SETFL, flags | O_NONBLOCK);
// 设置超时
timeout.tv_sec = timeout_ms / 1000;
timeout.tv_usec = (timeout_ms % 1000) * 1000;
while (true) {
FD_ZERO(&read_fds);
FD_SET(client_socket, &read_fds);
int activity = select(client_socket + 1, &read_fds, nullptr, nullptr, &timeout);
if (activity < 0) {
std::cerr << "select error" << std::endl;
break;
} else if (activity == 0) {
// 超时,检查是否已经有数据
if (!request.empty()) {
break;
}
std::cerr << "read timeout" << std::endl;
break;
}
if (FD_ISSET(client_socket, &read_fds)) {
ssize_t bytes_read = recv(client_socket, buffer, sizeof(buffer) - 1, 0);
if (bytes_read > 0) {
buffer[bytes_read] = '\0';
request.append(buffer, bytes_read);
// 检查是否已经收到完整的请求
if (isRequestComplete(request)) {
break;
}
} else if (bytes_read == 0) {
// 连接关闭
break;
} else {
if (errno != EAGAIN && errno != EWOULDBLOCK) {
std::cerr << "recv error: " << strerror(errno) << std::endl;
}
break;
}
}
}
// 恢复阻塞模式
fcntl(client_socket, F_SETFL, flags);
return request;
}
bool HTTPServer::isRequestComplete(const std::string& request)
{
// 查找请求头和请求体的分隔符
size_t header_end = request.find("\r\n\r\n");
if (header_end == std::string::npos) {
return false; // 没有找到完整头部
}
// 提取头部部分
std::string headers_part = request.substr(0, header_end);
// 解析Content-Length
int content_length = getContentLength(parseHeaders(headers_part));
// 如果有Content-Length检查是否收到完整body
if (content_length > 0) {
size_t body_start = header_end + 4;
if (request.length() >= body_start + content_length) {
return true;
}
return false;
}
// 如果没有Content-Length检查是否以空行结尾表示没有body
if (request.length() >= header_end + 4 && request.substr(header_end + 4).empty()) {
return true;
}
// 对于没有Content-Length的GET请求有分隔符就认为完整
if (request.find("GET") == 0 || request.find("HEAD") == 0) {
return true;
}
return false;
}
void HTTPServer::logRequest(const std::string& method, const std::string& client_ip,
const std::map<std::string, std::string>& headers)
{
// 获取当前时间
std::time_t now = std::time(nullptr);
char time_str[100];
std::strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", std::localtime(&now));
std::cout << "[" << time_str << "] " << client_ip << " " << method;
auto user_agent = headers.find("User-Agent");
if (user_agent != headers.end()) {
std::cout << " (" << user_agent->second.substr(0, 50) << ")";
}
std::cout << std::endl;
}
void HTTPServer::handleConnection(int client_socket, const std::string& client_ip)
{
// 读取完整的请求
std::string request = readFullRequest(client_socket);
if (!request.empty()) {
handleRequest(client_socket, request);
} else {
std::cerr << "收到空请求或读取失败" << std::endl;
sendError(client_socket, 400, "Bad Request");
}
close(client_socket);
}
void HTTPServer::handleRequest(int client_socket, const std::string& request)
{
// 提取请求行
size_t line_end = request.find("\r\n");
if (line_end == std::string::npos) {
sendError(client_socket, 400, "Bad Request");
return;
}
std::string request_line = request.substr(0, line_end);
std::istringstream iss(request_line);
std::string method, path, protocol;
iss >> method >> path >> protocol;
// 提取头部
std::string headers_str;
size_t headers_end = request.find("\r\n\r\n");
if (headers_end != std::string::npos) {
headers_str = request.substr(line_end + 2, headers_end - line_end - 2);
}
auto headers = parseHeaders(headers_str);
for (const auto& header : headers) {
std::cout << header.first << ": " << header.second << std::endl;
}
// 记录请求日志
logRequest(method, "", headers);
// 处理请求
if (method == "POST") {
handlePOST(client_socket, request, headers);
} else if (method == "GET") {
handleGET(client_socket, request_line);
} else {
sendError(client_socket, 405, "Method Not Allowed");
}
}
void HTTPServer::handlePOST(int client_socket, const std::string& request,
const std::map<std::string, std::string>& headers)
{
std::cout << "\n=== 收到POST请求 ===\n";
// 获取请求体
int contentLength = getContentLength(headers);
std::string body;
if (contentLength > 0) {
size_t bodyPos = request.find("\r\n\r\n");
if (bodyPos != std::string::npos) {
bodyPos += 4; // 跳过空行
if (bodyPos < request.length()) {
body = request.substr(bodyPos);
// 确保body长度不超过Content-Length
if (body.length() > static_cast<size_t>(contentLength)) {
body = body.substr(0, contentLength);
}
}
}
}
std::cout << "请求体长度: " << body.length() << " 字节" << std::endl;
// 如果有自定义处理器,使用它
if (custom_handler) {
custom_handler(client_socket, request, headers, body);
return;
}
// 默认处理逻辑
std::string contentType = getContentType(headers);
std::string response;
if (contentType.find("application/x-www-form-urlencoded") != std::string::npos) {
// 表单数据
auto params = parseQueryString(body);
response = "<html><body><h1>POST数据已接收</h1>";
response += "<h2>表单数据:</h2>";
if (params.empty()) {
response += "<p>没有表单数据</p>";
response += "<p>原始body: " + body + "</p>";
} else {
response += "<ul>";
for (const auto& param : params) {
response += "<li><strong>" + param.first + ":</strong> " + param.second + "</li>";
}
response += "</ul>";
}
response += "</body></html>";
// 打印到控制台
std::cout << "\n解析的表单数据:\n";
for (const auto& param : params) {
std::cout << param.first << " = " << param.second << std::endl;
}
} else if (contentType.find("application/Json") != std::string::npos) {
// JSON数据
this->PostMsg = body;
response = "<html><body><h1>JSON数据已接收</h1>";
response += "<h2>原始JSON:</h2>";
response += "<pre>" + body + "</pre>";
response += "</body></html>";
std::cout << "\nJSON数据:\n" << body << std::endl;
} else {
// 其他类型
response = "<html><body><h1>数据已接收</h1>";
response += "<p>Content-Type: " + (contentType.empty() ? "未指定" : contentType) + "</p>";
response += "<p>数据长度: " + std::to_string(body.length()) + " 字节</p>";
if (!body.empty() && body.length() < 1000) {
response += "<h2>原始数据:</h2>";
response += "<pre>" + body + "</pre>";
} else if (!body.empty()) {
response += "<h2>原始数据前1000字节:</h2>";
response += "<pre>" + body.substr(0, 1000) + "...</pre>";
}
response += "</body></html>";
std::cout << "\n原始数据:\n" << body.substr(0, std::min(body.length(), (size_t)500)) << std::endl;
if (body.length() > 500) {
std::cout << "... (只显示前500字节)" << std::endl;
}
}
sendResponse(client_socket, response);
std::cout << "\n=== 处理完成 ===\n\n";
}
void HTTPServer::handleGET(int client_socket, const std::string& request_line)
{
std::istringstream iss(request_line);
std::string method, path, protocol;
iss >> method >> path >> protocol;
// 默认提供测试表单页面
std::string response =
"<html>"
"<head><title>HTTP POST测试服务器</title>"
"<meta charset=\"utf-8\">"
"<style>"
"body { font-family: Arial, sans-serif; margin: 40px; }"
".container { max-width: 800px; margin: 0 auto; }"
"form { margin: 20px 0; padding: 20px; border: 1px solid #ddd; background: #f9f9f9; }"
"h2 { color: #333; border-bottom: 2px solid #007bff; padding-bottom: 10px; }"
"input, textarea, select { width: 100%; margin: 10px 0; padding: 8px; border: 1px solid #ccc; border-radius: 4px; }"
"button { padding: 10px 20px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; }"
"button:hover { background: #0056b3; }"
".log { background: #333; color: #fff; padding: 15px; border-radius: 4px; font-family: monospace; margin-top: 20px; }"
"</style>"
"<script>"
"function submitForm(formId, contentType) {"
" const form = document.getElementById(formId);"
" const formData = new FormData(form);"
" let body;"
" let headers = { 'Content-Type': contentType };"
" "
" if (contentType === 'application/json') {"
" const obj = {};"
" formData.forEach((value, key) => obj[key] = value);"
" body = JSON.stringify(obj);"
" } else if (contentType === 'application/x-www-form-urlencoded') {"
" const params = new URLSearchParams();"
" formData.forEach((value, key) => params.append(key, value));"
" body = params.toString();"
" } else {"
" body = formData;"
" }"
" "
" fetch('/', {"
" method: 'POST',"
" headers: headers,"
" body: contentType === 'multipart/form-data' ? formData : body"
" }).then(res => res.text()).then(html => {"
" document.getElementById('result').innerHTML = html;"
" document.getElementById('result').scrollIntoView();"
" });"
" return false;"
"}"
"</script>"
"</head>"
"<body>"
"<div class='container'>"
"<h1>HTTP POST测试服务器</h1>"
"<p>服务器运行在端口 " + std::to_string(port) + "</p>"
"<h2>1. 表单提交测试 (application/x-www-form-urlencoded)</h2>"
"<form id='form1' onsubmit='return submitForm(\"form1\", \"application/x-www-form-urlencoded\")'>"
"<label>姓名: <input type='text' name='name' value='张三' required></label><br>"
"<label>邮箱: <input type='email' name='email' value='test@example.com' required></label><br>"
"<label>消息: <textarea name='message' rows='4'>这是一个测试消息</textarea></label><br>"
"<button type='submit'>提交表单数据</button>"
"</form>"
"<h2>2. JSON提交测试 (application/json)</h2>"
"<form id='form2' onsubmit='return submitForm(\"form2\", \"application/json\")'>"
"<label>用户名: <input type='text' name='username' value='john_doe'></label><br>"
"<label>分数: <input type='number' name='score' value='95'></label><br>"
"<button type='submit'>提交JSON数据</button>"
"</form>"
"<h2>3. 使用curl测试</h2>"
"<div class='log'>"
"<p>表单数据:</p>"
"<code>curl -X POST http://localhost:" + std::to_string(port) + "/ \\<br>"
" -H \"Content-Type: application/x-www-form-urlencoded\" \\<br>"
" -d \"name=张三&email=test@example.com&message=Hello%20World\"</code><br><br>"
"<p>JSON数据:</p>"
"<code>curl -X POST http://localhost:" + std::to_string(port) + "/ \\<br>"
" -H \"Content-Type: application/json\" \\<br>"
" -d '{\"name\":\"李四\",\"age\":25,\"city\":\"北京\"}'</code>"
"</div>"
"<div id='result'></div>"
"</div>"
"</body></html>";
sendResponse(client_socket, response);
}
// ==================== 公有方法实现 ====================
HTTPServer::HTTPServer(int port) : port(port), server_fd(-1), custom_handler(nullptr) {}
HTTPServer::~HTTPServer() {
stop();
}
bool HTTPServer::start() {
// 创建socket
server_fd = socket(AF_INET, SOCK_STREAM, 0);
if (server_fd == -1) {
std::cerr << "创建socket失败: " << strerror(errno) << std::endl;
return false;
}
// 设置socket选项避免地址占用
int opt = 1;
if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) {
std::cerr << "设置socket选项失败: " << strerror(errno) << std::endl;
close(server_fd);
return false;
}
// 绑定地址和端口
struct sockaddr_in address;
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(port);
if (bind(server_fd, (struct sockaddr*)&address, sizeof(address)) < 0) {
std::cerr << "绑定端口 " << port << " 失败: " << strerror(errno) << std::endl;
close(server_fd);
return false;
}
// 开始监听
if (listen(server_fd, 10) < 0) {
std::cerr << "监听失败: " << strerror(errno) << std::endl;
close(server_fd);
return false;
}
std::cout << "HTTP服务器启动成功监听端口: " << port << std::endl;
std::cout << "访问 http://localhost:" << port << " 进行测试" << std::endl;
std::cout << "按 Ctrl+C 停止服务器" << std::endl;
return true;
}
void HTTPServer::run()
{
fd_set readfds;
struct timeval timeout;
FD_ZERO(&readfds);
FD_SET(server_fd, &readfds);
// 设置1秒超时
timeout.tv_sec = 1;
timeout.tv_usec = 0;
int activity = select(server_fd + 1, &readfds, NULL, NULL, &timeout);
if (activity < 0)
{
std::cerr << "select error: " << strerror(errno) << std::endl;
return;
}
if (activity == 0)
{
// 超时,检查是否应该停止
return;
}
if (FD_ISSET(server_fd, &readfds))
{
struct sockaddr_in client_address;
socklen_t client_len = sizeof(client_address);
int client_socket = accept(server_fd, (struct sockaddr *)&client_address, &client_len);
if (client_socket < 0)
{
std::cerr << "接受连接失败: " << strerror(errno) << std::endl;
return;
}
char client_ip[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &client_address.sin_addr, client_ip, INET_ADDRSTRLEN);
handleConnection(client_socket, client_ip);
}
}
void HTTPServer::stop()
{
if (server_fd != -1)
{
close(server_fd);
server_fd = -1;
std::cout << "服务器已停止" << std::endl;
}
}
void HTTPServer::SetPort(int port)
{
this->port = port;
}
void HTTPServer::setRequestHandler(const RequestHandler& handler) {
custom_handler = handler;
}

@ -0,0 +1,65 @@
#ifndef HTTP_SERVER_H
#define HTTP_SERVER_H
#include <string>
#include <map>
#include <vector>
#include <functional>
class HTTPServer {
public:
// 构造函数和析构函数
HTTPServer(int port = 8080);
~HTTPServer();
//消息
std::string PostMsg;
// 服务器控制方法
bool start();
void run();
void stop();
void SetPort(int port);
// 回调函数类型定义
using RequestHandler = std::function<void(int, const std::string&, const std::map<std::string, std::string>&, const std::string&)>;
// 设置自定义请求处理器
void setRequestHandler(const RequestHandler& handler);
// 静态工具方法
static std::string urlDecode(const std::string& encoded);
static std::map<std::string, std::string> parseQueryString(const std::string& query);
static std::map<std::string, std::string> parseHeaders(const std::string& headers);
static std::string getContentType(const std::map<std::string, std::string>& headers);
static int getContentLength(const std::map<std::string, std::string>& headers);
// 响应方法
static void sendResponse(int client_socket, const std::string& response,
const std::string& content_type = "text/html; charset=utf-8");
static void sendError(int client_socket, int code, const std::string& message);
static void sendJSONResponse(int client_socket, const std::string& json);
private:
// 私有方法
std::string readFullRequest(int client_socket, int timeout_ms = 5000);
bool isRequestComplete(const std::string& request);
void handleConnection(int client_socket, const std::string& client_ip);
void handleRequest(int client_socket, const std::string& request);
void handlePOST(int client_socket, const std::string& request,
const std::map<std::string, std::string>& headers);
void handleGET(int client_socket, const std::string& request_line);
void logRequest(const std::string& method, const std::string& client_ip,
const std::map<std::string, std::string>& headers);
// 私有成员变量
int server_fd;
int port;
RequestHandler custom_handler;
// 禁用复制和赋值
HTTPServer(const HTTPServer&) = delete;
HTTPServer& operator=(const HTTPServer&) = delete;
};
#endif // HTTP_SERVER_H

@ -0,0 +1,144 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*!
* @file main.cxx
* This file acts as a main entry point to the application.
*
* This file was generated by the tool fastddsgen.
*/
#include <csignal>
#include <cstring>
#include <functional>
#include <iostream>
#include <stdexcept>
#include <thread>
#include <fastdds/dds/log/Log.hpp>
#include "Subscriber.hpp"
#include "Publisher.hpp"
#include "httpserver.hpp"
#define VERSION "v1.0"
using eprosima::fastdds::dds::Log;
std::function<void(int)> stop_handler;
void signal_handler(
int signum)
{
stop_handler(signum);
}
std::string parse_signal(
const int& signum)
{
switch (signum)
{
case SIGINT:
return "SIGINT";
case SIGTERM:
return "SIGTERM";
#ifndef _WIN32
case SIGQUIT:
return "SIGQUIT";
case SIGHUP:
return "SIGHUP";
#endif // _WIN32
default:
return "UNKNOWN SIGNAL";
}
}
int main(int argc, char** argv)
{
auto ret = EXIT_SUCCESS;
std::shared_ptr<SubscriberApp> sub;
std::shared_ptr<PublisherApp> pub;
std::shared_ptr<HTTPServer> dev;
int domain_id = 0;
int port = 8080;
for (int i = 1; i < argc; i++)
{
if (strcmp(argv[i], "--domain") == 0 && i + 1 < argc)
{
domain_id = atoi(argv[++i]);
}
else if (strcmp(argv[i], "--port") == 0 && i + 1 < argc)
{
port = atoi(argv[++i]);
}
else if (strcmp(argv[i], "--version") == 0)
{
std::cout << "Vesrion: " << VERSION << "\n";
return EXIT_SUCCESS;
}
else if (strcmp(argv[i], "--help") == 0)
{
std::cout << "Usage: [options]\n"
<< "Options:\n"
<< " --domain Set domain ID\n"
<< " --port Set port name (e.g., 8080)\n"
<< " --version Show software Version\n"
<< " --help Show this help message\n";
return EXIT_SUCCESS;
}
else
{
std::cerr << "Unknown option: " << argv[i] << "\n";
std::cout << "Usage: [options]\n"
<< "Options:\n"
<< " --domain Set domain ID\n"
<< " --port Set port name (e.g., 8080)\n"
<< " --version Show software Version\n"
<< " --help Show this help message\n";
return EXIT_FAILURE;
}
}
sub = std::make_shared<SubscriberApp>(domain_id);
pub = std::make_shared<PublisherApp>(domain_id);
dev = std::make_shared<HTTPServer>();
dev->SetPort(port);
dev->start();
std::thread pub_thread(&PublisherApp::run, pub, dev);
std::cout << "Program is running. Please press Ctrl+C to stop at any time." << std::endl;
stop_handler = [&](int signum)
{
std::cout << "\n" << parse_signal(signum) << " received, stopping " << argv[1]
<< " execution." << std::endl;
pub->stop();
};
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
#ifndef _WIN32
signal(SIGQUIT, signal_handler);
signal(SIGHUP, signal_handler);
#endif // _WIN32
pub_thread.join();
Log::Reset();
return ret;
}

@ -0,0 +1,14 @@
#ifndef _MSG_HPP_
#define _MSG_HPP_
#include <queue>
#include <mutex>
#include "System.hpp"
class MsgData {
public:
static std::queue<PrintReq> PrintReq_queue_;
static std::mutex queue_cv_mtx_;
};
#endif

@ -52,6 +52,346 @@
#define SYSTEM_DllAPI
#endif // _WIN32
/*!
* @brief This class represents the structure LicencePlateReq defined by the user in the IDL file.
* @ingroup System
*/
class LicencePlateReq
{
public:
/*!
* @brief Default constructor.
*/
eProsima_user_DllExport LicencePlateReq()
{
}
/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~LicencePlateReq()
{
}
/*!
* @brief Copy constructor.
* @param x Reference to the object LicencePlateReq that will be copied.
*/
eProsima_user_DllExport LicencePlateReq(
const LicencePlateReq& x)
{
m_index = x.m_index;
m_msg = x.m_msg;
}
/*!
* @brief Move constructor.
* @param x Reference to the object LicencePlateReq that will be copied.
*/
eProsima_user_DllExport LicencePlateReq(
LicencePlateReq&& x) noexcept
{
m_index = x.m_index;
m_msg = std::move(x.m_msg);
}
/*!
* @brief Copy assignment.
* @param x Reference to the object LicencePlateReq that will be copied.
*/
eProsima_user_DllExport LicencePlateReq& operator =(
const LicencePlateReq& x)
{
m_index = x.m_index;
m_msg = x.m_msg;
return *this;
}
/*!
* @brief Move assignment.
* @param x Reference to the object LicencePlateReq that will be copied.
*/
eProsima_user_DllExport LicencePlateReq& operator =(
LicencePlateReq&& x) noexcept
{
m_index = x.m_index;
m_msg = std::move(x.m_msg);
return *this;
}
/*!
* @brief Comparison operator.
* @param x LicencePlateReq object to compare.
*/
eProsima_user_DllExport bool operator ==(
const LicencePlateReq& x) const
{
return (m_index == x.m_index &&
m_msg == x.m_msg);
}
/*!
* @brief Comparison operator.
* @param x LicencePlateReq object to compare.
*/
eProsima_user_DllExport bool operator !=(
const LicencePlateReq& x) const
{
return !(*this == x);
}
/*!
* @brief This function sets a value in member index
* @param _index New value for member index
*/
eProsima_user_DllExport void index(
uint32_t _index)
{
m_index = _index;
}
/*!
* @brief This function returns the value of member index
* @return Value of member index
*/
eProsima_user_DllExport uint32_t index() const
{
return m_index;
}
/*!
* @brief This function returns a reference to member index
* @return Reference to member index
*/
eProsima_user_DllExport uint32_t& index()
{
return m_index;
}
/*!
* @brief This function copies the value in member msg
* @param _msg New value to be copied in member msg
*/
eProsima_user_DllExport void msg(
const std::map<std::string, std::string>& _msg)
{
m_msg = _msg;
}
/*!
* @brief This function moves the value in member msg
* @param _msg New value to be moved in member msg
*/
eProsima_user_DllExport void msg(
std::map<std::string, std::string>&& _msg)
{
m_msg = std::move(_msg);
}
/*!
* @brief This function returns a constant reference to member msg
* @return Constant reference to member msg
*/
eProsima_user_DllExport const std::map<std::string, std::string>& msg() const
{
return m_msg;
}
/*!
* @brief This function returns a reference to member msg
* @return Reference to member msg
*/
eProsima_user_DllExport std::map<std::string, std::string>& msg()
{
return m_msg;
}
private:
uint32_t m_index{0};
std::map<std::string, std::string> m_msg;
};
/*!
* @brief This class represents the structure LicencePlateRsp defined by the user in the IDL file.
* @ingroup System
*/
class LicencePlateRsp
{
public:
/*!
* @brief Default constructor.
*/
eProsima_user_DllExport LicencePlateRsp()
{
}
/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~LicencePlateRsp()
{
}
/*!
* @brief Copy constructor.
* @param x Reference to the object LicencePlateRsp that will be copied.
*/
eProsima_user_DllExport LicencePlateRsp(
const LicencePlateRsp& x)
{
m_index = x.m_index;
m_licence = x.m_licence;
}
/*!
* @brief Move constructor.
* @param x Reference to the object LicencePlateRsp that will be copied.
*/
eProsima_user_DllExport LicencePlateRsp(
LicencePlateRsp&& x) noexcept
{
m_index = x.m_index;
m_licence = std::move(x.m_licence);
}
/*!
* @brief Copy assignment.
* @param x Reference to the object LicencePlateRsp that will be copied.
*/
eProsima_user_DllExport LicencePlateRsp& operator =(
const LicencePlateRsp& x)
{
m_index = x.m_index;
m_licence = x.m_licence;
return *this;
}
/*!
* @brief Move assignment.
* @param x Reference to the object LicencePlateRsp that will be copied.
*/
eProsima_user_DllExport LicencePlateRsp& operator =(
LicencePlateRsp&& x) noexcept
{
m_index = x.m_index;
m_licence = std::move(x.m_licence);
return *this;
}
/*!
* @brief Comparison operator.
* @param x LicencePlateRsp object to compare.
*/
eProsima_user_DllExport bool operator ==(
const LicencePlateRsp& x) const
{
return (m_index == x.m_index &&
m_licence == x.m_licence);
}
/*!
* @brief Comparison operator.
* @param x LicencePlateRsp object to compare.
*/
eProsima_user_DllExport bool operator !=(
const LicencePlateRsp& x) const
{
return !(*this == x);
}
/*!
* @brief This function sets a value in member index
* @param _index New value for member index
*/
eProsima_user_DllExport void index(
uint32_t _index)
{
m_index = _index;
}
/*!
* @brief This function returns the value of member index
* @return Value of member index
*/
eProsima_user_DllExport uint32_t index() const
{
return m_index;
}
/*!
* @brief This function returns a reference to member index
* @return Reference to member index
*/
eProsima_user_DllExport uint32_t& index()
{
return m_index;
}
/*!
* @brief This function copies the value in member licence
* @param _licence New value to be copied in member licence
*/
eProsima_user_DllExport void licence(
const std::string& _licence)
{
m_licence = _licence;
}
/*!
* @brief This function moves the value in member licence
* @param _licence New value to be moved in member licence
*/
eProsima_user_DllExport void licence(
std::string&& _licence)
{
m_licence = std::move(_licence);
}
/*!
* @brief This function returns a constant reference to member licence
* @return Constant reference to member licence
*/
eProsima_user_DllExport const std::string& licence() const
{
return m_licence;
}
/*!
* @brief This function returns a reference to member licence
* @return Reference to member licence
*/
eProsima_user_DllExport std::string& licence()
{
return m_licence;
}
private:
uint32_t m_index{0};
std::string m_licence;
};
/*!
* @brief This class represents the structure PrintReq defined by the user in the IDL file.
* @ingroup System

@ -1,4 +1,16 @@
@extensibility(APPENDABLE)
struct LicencePlateReq
{
unsigned long index;
map<string, string> msg;
};
struct LicencePlateRsp
{
unsigned long index;
string licence;
};
struct PrintReq
{
unsigned long index;

@ -27,6 +27,12 @@
constexpr uint32_t PrintReq_max_cdr_typesize {16UL};
constexpr uint32_t PrintReq_max_key_cdr_typesize {0UL};
constexpr uint32_t LicencePlateRsp_max_cdr_typesize {268UL};
constexpr uint32_t LicencePlateRsp_max_key_cdr_typesize {0UL};
constexpr uint32_t LicencePlateReq_max_cdr_typesize {16UL};
constexpr uint32_t LicencePlateReq_max_key_cdr_typesize {0UL};
constexpr uint32_t WeighReq_max_cdr_typesize {16UL};
constexpr uint32_t WeighReq_max_key_cdr_typesize {0UL};
@ -43,6 +49,14 @@ namespace fastcdr {
class Cdr;
class CdrSizeCalculator;
eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const LicencePlateReq& data);
eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const LicencePlateRsp& data);
eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const PrintReq& data);

@ -34,6 +34,184 @@ using namespace eprosima::fastcdr::exception;
namespace eprosima {
namespace fastcdr {
template<>
eProsima_user_DllExport size_t calculate_serialized_size(
eprosima::fastcdr::CdrSizeCalculator& calculator,
const LicencePlateReq& data,
size_t& current_alignment)
{
static_cast<void>(data);
eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding();
size_t calculated_size {calculator.begin_calculate_type_serialized_size(
eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
current_alignment)};
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0),
data.index(), current_alignment);
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1),
data.msg(), current_alignment);
calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment);
return calculated_size;
}
template<>
eProsima_user_DllExport void serialize(
eprosima::fastcdr::Cdr& scdr,
const LicencePlateReq& data)
{
eprosima::fastcdr::Cdr::state current_state(scdr);
scdr.begin_serialize_type(current_state,
eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR);
scdr
<< eprosima::fastcdr::MemberId(0) << data.index()
<< eprosima::fastcdr::MemberId(1) << data.msg()
;
scdr.end_serialize_type(current_state);
}
template<>
eProsima_user_DllExport void deserialize(
eprosima::fastcdr::Cdr& cdr,
LicencePlateReq& data)
{
cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
[&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool
{
bool ret_value = true;
switch (mid.id)
{
case 0:
dcdr >> data.index();
break;
case 1:
dcdr >> data.msg();
break;
default:
ret_value = false;
break;
}
return ret_value;
});
}
void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const LicencePlateReq& data)
{
static_cast<void>(scdr);
static_cast<void>(data);
scdr << data.index();
scdr << data.msg();
}
template<>
eProsima_user_DllExport size_t calculate_serialized_size(
eprosima::fastcdr::CdrSizeCalculator& calculator,
const LicencePlateRsp& data,
size_t& current_alignment)
{
static_cast<void>(data);
eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding();
size_t calculated_size {calculator.begin_calculate_type_serialized_size(
eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
current_alignment)};
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0),
data.index(), current_alignment);
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1),
data.licence(), current_alignment);
calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment);
return calculated_size;
}
template<>
eProsima_user_DllExport void serialize(
eprosima::fastcdr::Cdr& scdr,
const LicencePlateRsp& data)
{
eprosima::fastcdr::Cdr::state current_state(scdr);
scdr.begin_serialize_type(current_state,
eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR);
scdr
<< eprosima::fastcdr::MemberId(0) << data.index()
<< eprosima::fastcdr::MemberId(1) << data.licence()
;
scdr.end_serialize_type(current_state);
}
template<>
eProsima_user_DllExport void deserialize(
eprosima::fastcdr::Cdr& cdr,
LicencePlateRsp& data)
{
cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
[&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool
{
bool ret_value = true;
switch (mid.id)
{
case 0:
dcdr >> data.index();
break;
case 1:
dcdr >> data.licence();
break;
default:
ret_value = false;
break;
}
return ret_value;
});
}
void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const LicencePlateRsp& data)
{
static_cast<void>(scdr);
static_cast<void>(data);
scdr << data.index();
scdr << data.licence();
}
template<>
eProsima_user_DllExport size_t calculate_serialized_size(
eprosima::fastcdr::CdrSizeCalculator& calculator,

@ -31,6 +31,370 @@ using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t;
using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t;
using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t;
LicencePlateReqPubSubType::LicencePlateReqPubSubType()
{
set_name("LicencePlateReq");
uint32_t type_size = LicencePlateReq_max_cdr_typesize;
type_size += static_cast<uint32_t>(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */
max_serialized_type_size = type_size + 4; /*encapsulation*/
is_compute_key_provided = false;
uint32_t key_length = LicencePlateReq_max_key_cdr_typesize > 16 ? LicencePlateReq_max_key_cdr_typesize : 16;
key_buffer_ = reinterpret_cast<unsigned char*>(malloc(key_length));
memset(key_buffer_, 0, key_length);
}
LicencePlateReqPubSubType::~LicencePlateReqPubSubType()
{
if (key_buffer_ != nullptr)
{
free(key_buffer_);
}
}
bool LicencePlateReqPubSubType::serialize(
const void* const data,
SerializedPayload_t& payload,
DataRepresentationId_t data_representation)
{
const LicencePlateReq* p_type = static_cast<const LicencePlateReq*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.max_size);
// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2);
payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
ser.set_encoding_flag(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR :
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2);
try
{
// Serialize encapsulation
ser.serialize_encapsulation();
// Serialize the object.
ser << *p_type;
ser.set_dds_cdr_options({0,0});
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}
// Get the serialized length
payload.length = static_cast<uint32_t>(ser.get_serialized_data_length());
return true;
}
bool LicencePlateReqPubSubType::deserialize(
SerializedPayload_t& payload,
void* data)
{
try
{
// Convert DATA to pointer of your type
LicencePlateReq* p_type = static_cast<LicencePlateReq*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.length);
// Object that deserializes the data.
eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN);
// Deserialize encapsulation.
deser.read_encapsulation();
payload.encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
// Deserialize the object.
deser >> *p_type;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}
return true;
}
uint32_t LicencePlateReqPubSubType::calculate_serialized_size(
const void* const data,
DataRepresentationId_t data_representation)
{
try
{
eprosima::fastcdr::CdrSizeCalculator calculator(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2);
size_t current_alignment {0};
return static_cast<uint32_t>(calculator.calculate_serialized_size(
*static_cast<const LicencePlateReq*>(data), current_alignment)) +
4u /*encapsulation*/;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return 0;
}
}
void* LicencePlateReqPubSubType::create_data()
{
return reinterpret_cast<void*>(new LicencePlateReq());
}
void LicencePlateReqPubSubType::delete_data(
void* data)
{
delete(reinterpret_cast<LicencePlateReq*>(data));
}
bool LicencePlateReqPubSubType::compute_key(
SerializedPayload_t& payload,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}
LicencePlateReq data;
if (deserialize(payload, static_cast<void*>(&data)))
{
return compute_key(static_cast<void*>(&data), handle, force_md5);
}
return false;
}
bool LicencePlateReqPubSubType::compute_key(
const void* const data,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}
const LicencePlateReq* p_type = static_cast<const LicencePlateReq*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(key_buffer_),
LicencePlateReq_max_key_cdr_typesize);
// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2);
ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2);
eprosima::fastcdr::serialize_key(ser, *p_type);
if (force_md5 || LicencePlateReq_max_key_cdr_typesize > 16)
{
md5_.init();
md5_.update(key_buffer_, static_cast<unsigned int>(ser.get_serialized_data_length()));
md5_.finalize();
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = md5_.digest[i];
}
}
else
{
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = key_buffer_[i];
}
}
return true;
}
void LicencePlateReqPubSubType::register_type_object_representation()
{
register_LicencePlateReq_type_identifier(type_identifiers_);
}
LicencePlateRspPubSubType::LicencePlateRspPubSubType()
{
set_name("LicencePlateRsp");
uint32_t type_size = LicencePlateRsp_max_cdr_typesize;
type_size += static_cast<uint32_t>(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */
max_serialized_type_size = type_size + 4; /*encapsulation*/
is_compute_key_provided = false;
uint32_t key_length = LicencePlateRsp_max_key_cdr_typesize > 16 ? LicencePlateRsp_max_key_cdr_typesize : 16;
key_buffer_ = reinterpret_cast<unsigned char*>(malloc(key_length));
memset(key_buffer_, 0, key_length);
}
LicencePlateRspPubSubType::~LicencePlateRspPubSubType()
{
if (key_buffer_ != nullptr)
{
free(key_buffer_);
}
}
bool LicencePlateRspPubSubType::serialize(
const void* const data,
SerializedPayload_t& payload,
DataRepresentationId_t data_representation)
{
const LicencePlateRsp* p_type = static_cast<const LicencePlateRsp*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.max_size);
// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2);
payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
ser.set_encoding_flag(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR :
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2);
try
{
// Serialize encapsulation
ser.serialize_encapsulation();
// Serialize the object.
ser << *p_type;
ser.set_dds_cdr_options({0,0});
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}
// Get the serialized length
payload.length = static_cast<uint32_t>(ser.get_serialized_data_length());
return true;
}
bool LicencePlateRspPubSubType::deserialize(
SerializedPayload_t& payload,
void* data)
{
try
{
// Convert DATA to pointer of your type
LicencePlateRsp* p_type = static_cast<LicencePlateRsp*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.length);
// Object that deserializes the data.
eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN);
// Deserialize encapsulation.
deser.read_encapsulation();
payload.encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
// Deserialize the object.
deser >> *p_type;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}
return true;
}
uint32_t LicencePlateRspPubSubType::calculate_serialized_size(
const void* const data,
DataRepresentationId_t data_representation)
{
try
{
eprosima::fastcdr::CdrSizeCalculator calculator(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2);
size_t current_alignment {0};
return static_cast<uint32_t>(calculator.calculate_serialized_size(
*static_cast<const LicencePlateRsp*>(data), current_alignment)) +
4u /*encapsulation*/;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return 0;
}
}
void* LicencePlateRspPubSubType::create_data()
{
return reinterpret_cast<void*>(new LicencePlateRsp());
}
void LicencePlateRspPubSubType::delete_data(
void* data)
{
delete(reinterpret_cast<LicencePlateRsp*>(data));
}
bool LicencePlateRspPubSubType::compute_key(
SerializedPayload_t& payload,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}
LicencePlateRsp data;
if (deserialize(payload, static_cast<void*>(&data)))
{
return compute_key(static_cast<void*>(&data), handle, force_md5);
}
return false;
}
bool LicencePlateRspPubSubType::compute_key(
const void* const data,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}
const LicencePlateRsp* p_type = static_cast<const LicencePlateRsp*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(key_buffer_),
LicencePlateRsp_max_key_cdr_typesize);
// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2);
ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2);
eprosima::fastcdr::serialize_key(ser, *p_type);
if (force_md5 || LicencePlateRsp_max_key_cdr_typesize > 16)
{
md5_.init();
md5_.update(key_buffer_, static_cast<unsigned int>(ser.get_serialized_data_length()));
md5_.finalize();
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = md5_.digest[i];
}
}
else
{
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = key_buffer_[i];
}
}
return true;
}
void LicencePlateRspPubSubType::register_type_object_representation()
{
register_LicencePlateRsp_type_identifier(type_identifiers_);
}
PrintReqPubSubType::PrintReqPubSubType()
{
set_name("PrintReq");

@ -38,6 +38,168 @@
#endif // FASTDDS_GEN_API_VER
/*!
* @brief This class represents the TopicDataType of the type LicencePlateReq defined by the user in the IDL file.
* @ingroup System
*/
class LicencePlateReqPubSubType : public eprosima::fastdds::dds::TopicDataType
{
public:
typedef LicencePlateReq type;
eProsima_user_DllExport LicencePlateReqPubSubType();
eProsima_user_DllExport ~LicencePlateReqPubSubType() override;
eProsima_user_DllExport bool serialize(
const void* const data,
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
eProsima_user_DllExport bool deserialize(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
void* data) override;
eProsima_user_DllExport uint32_t calculate_serialized_size(
const void* const data,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
eProsima_user_DllExport bool compute_key(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;
eProsima_user_DllExport bool compute_key(
const void* const data,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;
eProsima_user_DllExport void* create_data() override;
eProsima_user_DllExport void delete_data(
void* data) override;
//Register TypeObject representation in Fast DDS TypeObjectRegistry
eProsima_user_DllExport void register_type_object_representation() override;
#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
eProsima_user_DllExport inline bool is_bounded() const override
{
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
eProsima_user_DllExport inline bool is_plain(
eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override
{
static_cast<void>(data_representation);
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
eProsima_user_DllExport inline bool construct_sample(
void* memory) const override
{
static_cast<void>(memory);
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
private:
eprosima::fastdds::MD5 md5_;
unsigned char* key_buffer_;
};
/*!
* @brief This class represents the TopicDataType of the type LicencePlateRsp defined by the user in the IDL file.
* @ingroup System
*/
class LicencePlateRspPubSubType : public eprosima::fastdds::dds::TopicDataType
{
public:
typedef LicencePlateRsp type;
eProsima_user_DllExport LicencePlateRspPubSubType();
eProsima_user_DllExport ~LicencePlateRspPubSubType() override;
eProsima_user_DllExport bool serialize(
const void* const data,
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
eProsima_user_DllExport bool deserialize(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
void* data) override;
eProsima_user_DllExport uint32_t calculate_serialized_size(
const void* const data,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
eProsima_user_DllExport bool compute_key(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;
eProsima_user_DllExport bool compute_key(
const void* const data,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;
eProsima_user_DllExport void* create_data() override;
eProsima_user_DllExport void delete_data(
void* data) override;
//Register TypeObject representation in Fast DDS TypeObjectRegistry
eProsima_user_DllExport void register_type_object_representation() override;
#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
eProsima_user_DllExport inline bool is_bounded() const override
{
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
eProsima_user_DllExport inline bool is_plain(
eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override
{
static_cast<void>(data_representation);
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
eProsima_user_DllExport inline bool construct_sample(
void* memory) const override
{
static_cast<void>(memory);
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
private:
eprosima::fastdds::MD5 md5_;
unsigned char* key_buffer_;
};
/*!
* @brief This class represents the TopicDataType of the type PrintReq defined by the user in the IDL file.
* @ingroup System

@ -38,6 +38,274 @@
using namespace eprosima::fastdds::dds::xtypes;
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_LicencePlateReq_type_identifier(
TypeIdentifierPair& type_ids_LicencePlateReq)
{
ReturnCode_t return_code_LicencePlateReq {eprosima::fastdds::dds::RETCODE_OK};
return_code_LicencePlateReq =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"LicencePlateReq", type_ids_LicencePlateReq);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_LicencePlateReq)
{
StructTypeFlag struct_flags_LicencePlateReq = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
false, false);
QualifiedTypeName type_name_LicencePlateReq = "LicencePlateReq";
eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_LicencePlateReq;
eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_LicencePlateReq;
AppliedAnnotationSeq tmp_ann_custom_LicencePlateReq;
eprosima::fastcdr::optional<AppliedVerbatimAnnotation> verbatim_LicencePlateReq;
if (!tmp_ann_custom_LicencePlateReq.empty())
{
ann_custom_LicencePlateReq = tmp_ann_custom_LicencePlateReq;
}
CompleteTypeDetail detail_LicencePlateReq = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_LicencePlateReq, ann_custom_LicencePlateReq, type_name_LicencePlateReq.to_string());
CompleteStructHeader header_LicencePlateReq;
header_LicencePlateReq = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_LicencePlateReq);
CompleteStructMemberSeq member_seq_LicencePlateReq;
{
TypeIdentifierPair type_ids_index;
ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK};
return_code_index =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"_uint32_t", type_ids_index);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_index)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"index Structure member TypeIdentifier unknown to TypeObjectRegistry.");
return;
}
StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_index = 0x00000000;
bool common_index_ec {false};
CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))};
if (!common_index_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent.");
return;
}
MemberName name_index = "index";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_index;
ann_custom_LicencePlateReq.reset();
CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_LicencePlateReq);
CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index);
TypeObjectUtils::add_complete_struct_member(member_seq_LicencePlateReq, member_index);
}
{
TypeIdentifierPair type_ids_msg;
ReturnCode_t return_code_msg {eprosima::fastdds::dds::RETCODE_OK};
return_code_msg =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded", type_ids_msg);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_msg)
{
return_code_msg =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_string_unbounded", type_ids_msg);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_msg)
{
{
SBound bound = 0;
StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn,
"anonymous_string_unbounded", type_ids_msg))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
}
bool element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec {false};
TypeIdentifier* element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_msg, element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec))};
if (!element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded inconsistent element TypeIdentifier.");
return;
}
return_code_msg =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_string_unbounded", type_ids_msg);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_msg)
{
{
SBound bound = 0;
StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn,
"anonymous_string_unbounded", type_ids_msg))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
}
bool key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec {false};
TypeIdentifier* key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_msg, key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec))};
if (!key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded inconsistent key TypeIdentifier.");
return;
}
EquivalenceKind equiv_kind_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = EK_BOTH;
if ((EK_COMPLETE == key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d()) ||
(TI_PLAIN_SEQUENCE_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->seq_sdefn().header().equiv_kind()) ||
(TI_PLAIN_SEQUENCE_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->seq_ldefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->array_sdefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->array_ldefn().header().equiv_kind()) ||
(TI_PLAIN_MAP_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && (EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_sdefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_sdefn().header().equiv_kind())) ||
(TI_PLAIN_MAP_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && (EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_ldefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_ldefn().header().equiv_kind())))
{
equiv_kind_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = EK_COMPLETE;
}
CollectionElementFlag element_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = 0;
CollectionElementFlag key_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = 0;
PlainCollectionHeader header_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded, element_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded);
{
SBound bound = 0;
PlainMapSTypeDefn map_sdefn = TypeObjectUtils::build_plain_map_s_type_defn(header_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded, bound,
eprosima::fastcdr::external<TypeIdentifier>(element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded), key_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded,
eprosima::fastcdr::external<TypeIdentifier>(key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded));
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_s_map_type_identifier(map_sdefn, "anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded", type_ids_msg))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
}
StructMemberFlag member_flags_msg = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_msg = 0x00000001;
bool common_msg_ec {false};
CommonStructMember common_msg {TypeObjectUtils::build_common_struct_member(member_id_msg, member_flags_msg, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_msg, common_msg_ec))};
if (!common_msg_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure msg member TypeIdentifier inconsistent.");
return;
}
MemberName name_msg = "msg";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_msg;
ann_custom_LicencePlateReq.reset();
CompleteMemberDetail detail_msg = TypeObjectUtils::build_complete_member_detail(name_msg, member_ann_builtin_msg, ann_custom_LicencePlateReq);
CompleteStructMember member_msg = TypeObjectUtils::build_complete_struct_member(common_msg, detail_msg);
TypeObjectUtils::add_complete_struct_member(member_seq_LicencePlateReq, member_msg);
}
CompleteStructType struct_type_LicencePlateReq = TypeObjectUtils::build_complete_struct_type(struct_flags_LicencePlateReq, header_LicencePlateReq, member_seq_LicencePlateReq);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_struct_type_object(struct_type_LicencePlateReq, type_name_LicencePlateReq.to_string(), type_ids_LicencePlateReq))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"LicencePlateReq already registered in TypeObjectRegistry for a different type.");
}
}
}
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_LicencePlateRsp_type_identifier(
TypeIdentifierPair& type_ids_LicencePlateRsp)
{
ReturnCode_t return_code_LicencePlateRsp {eprosima::fastdds::dds::RETCODE_OK};
return_code_LicencePlateRsp =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"LicencePlateRsp", type_ids_LicencePlateRsp);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_LicencePlateRsp)
{
StructTypeFlag struct_flags_LicencePlateRsp = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
false, false);
QualifiedTypeName type_name_LicencePlateRsp = "LicencePlateRsp";
eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_LicencePlateRsp;
eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_LicencePlateRsp;
CompleteTypeDetail detail_LicencePlateRsp = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_LicencePlateRsp, ann_custom_LicencePlateRsp, type_name_LicencePlateRsp.to_string());
CompleteStructHeader header_LicencePlateRsp;
header_LicencePlateRsp = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_LicencePlateRsp);
CompleteStructMemberSeq member_seq_LicencePlateRsp;
{
TypeIdentifierPair type_ids_index;
ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK};
return_code_index =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"_uint32_t", type_ids_index);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_index)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"index Structure member TypeIdentifier unknown to TypeObjectRegistry.");
return;
}
StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_index = 0x00000000;
bool common_index_ec {false};
CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))};
if (!common_index_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent.");
return;
}
MemberName name_index = "index";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_index;
ann_custom_LicencePlateRsp.reset();
CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_LicencePlateRsp);
CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index);
TypeObjectUtils::add_complete_struct_member(member_seq_LicencePlateRsp, member_index);
}
{
TypeIdentifierPair type_ids_licence;
ReturnCode_t return_code_licence {eprosima::fastdds::dds::RETCODE_OK};
return_code_licence =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_string_unbounded", type_ids_licence);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_licence)
{
{
SBound bound = 0;
StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn,
"anonymous_string_unbounded", type_ids_licence))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
}
StructMemberFlag member_flags_licence = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_licence = 0x00000001;
bool common_licence_ec {false};
CommonStructMember common_licence {TypeObjectUtils::build_common_struct_member(member_id_licence, member_flags_licence, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_licence, common_licence_ec))};
if (!common_licence_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure licence member TypeIdentifier inconsistent.");
return;
}
MemberName name_licence = "licence";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_licence;
ann_custom_LicencePlateRsp.reset();
CompleteMemberDetail detail_licence = TypeObjectUtils::build_complete_member_detail(name_licence, member_ann_builtin_licence, ann_custom_LicencePlateRsp);
CompleteStructMember member_licence = TypeObjectUtils::build_complete_struct_member(common_licence, detail_licence);
TypeObjectUtils::add_complete_struct_member(member_seq_LicencePlateRsp, member_licence);
}
CompleteStructType struct_type_LicencePlateRsp = TypeObjectUtils::build_complete_struct_type(struct_flags_LicencePlateRsp, header_LicencePlateRsp, member_seq_LicencePlateRsp);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_struct_type_object(struct_type_LicencePlateRsp, type_name_LicencePlateRsp.to_string(), type_ids_LicencePlateRsp))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"LicencePlateRsp already registered in TypeObjectRegistry for a different type.");
}
}
}
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_PrintReq_type_identifier(
TypeIdentifierPair& type_ids_PrintReq)
@ -54,13 +322,6 @@ void register_PrintReq_type_identifier(
QualifiedTypeName type_name_PrintReq = "PrintReq";
eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_PrintReq;
eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_PrintReq;
AppliedAnnotationSeq tmp_ann_custom_PrintReq;
eprosima::fastcdr::optional<AppliedVerbatimAnnotation> verbatim_PrintReq;
if (!tmp_ann_custom_PrintReq.empty())
{
ann_custom_PrintReq = tmp_ann_custom_PrintReq;
}
CompleteTypeDetail detail_PrintReq = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_PrintReq, ann_custom_PrintReq, type_name_PrintReq.to_string());
CompleteStructHeader header_PrintReq;
header_PrintReq = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_PrintReq);

@ -37,6 +37,30 @@
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
/**
* @brief Register LicencePlateReq related TypeIdentifier.
* Fully-descriptive TypeIdentifiers are directly registered.
* Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is
* indirectly registered as well.
*
* @param[out] TypeIdentifier of the registered type.
* The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers.
* Invalid TypeIdentifier is returned in case of error.
*/
eProsima_user_DllExport void register_LicencePlateReq_type_identifier(
eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids);
/**
* @brief Register LicencePlateRsp related TypeIdentifier.
* Fully-descriptive TypeIdentifiers are directly registered.
* Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is
* indirectly registered as well.
*
* @param[out] TypeIdentifier of the registered type.
* The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers.
* Invalid TypeIdentifier is returned in case of error.
*/
eProsima_user_DllExport void register_LicencePlateRsp_type_identifier(
eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids);
/**
* @brief Register PrintReq related TypeIdentifier.
* Fully-descriptive TypeIdentifiers are directly registered.

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save