repo_id stringlengths 19 138 | file_path stringlengths 32 200 | content stringlengths 1 12.9M | __index_level_0__ int64 0 0 |
|---|---|---|---|
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/LateJoiners/sample.h | // 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 sample.h
* This header file contains the declaration of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/
#ifndef _sample_H_
#define _sample_H_
// TODO Poner en el contexto.
#include <stdint.h>
#include <array>
#include <string>
#include <vector>
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#define eProsima_user_DllExport __declspec( dllexport )
#else
#define eProsima_user_DllExport
#endif
#else
#define eProsima_user_DllExport
#endif
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#if defined(sample_SOURCE)
#define sample_DllAPI __declspec( dllexport )
#else
#define sample_DllAPI __declspec( dllimport )
#endif // sample_SOURCE
#else
#define sample_DllAPI
#endif
#else
#define sample_DllAPI
#endif // _WIN32
namespace eprosima
{
namespace fastcdr
{
class Cdr;
}
}
/*!
* @brief This class represents the structure sample defined by the user in the IDL file.
* @ingroup SAMPLE
*/
class sample
{
public:
/*!
* @brief Default constructor.
*/
eProsima_user_DllExport sample();
/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~sample();
/*!
* @brief Copy constructor.
* @param x Reference to the object sample that will be copied.
*/
eProsima_user_DllExport sample(const sample &x);
/*!
* @brief Move constructor.
* @param x Reference to the object sample that will be copied.
*/
eProsima_user_DllExport sample(sample &&x);
/*!
* @brief Copy assignment.
* @param x Reference to the object sample that will be copied.
*/
eProsima_user_DllExport sample& operator=(const sample &x);
/*!
* @brief Move assignment.
* @param x Reference to the object sample that will be copied.
*/
eProsima_user_DllExport sample& operator=(sample &&x);
/*!
* @brief This function sets a value in member index
* @param _index New value for member index
*/
inline eProsima_user_DllExport void index(uint8_t _index)
{
m_index = _index;
}
/*!
* @brief This function returns the value of member index
* @return Value of member index
*/
inline eProsima_user_DllExport uint8_t index() const
{
return m_index;
}
/*!
* @brief This function returns a reference to member index
* @return Reference to member index
*/
inline eProsima_user_DllExport uint8_t& index()
{
return m_index;
}
/*!
* @brief This function sets a value in member key_value
* @param _key_value New value for member key_value
*/
inline eProsima_user_DllExport void key_value(uint8_t _key_value)
{
m_key_value = _key_value;
}
/*!
* @brief This function returns the value of member key_value
* @return Value of member key_value
*/
inline eProsima_user_DllExport uint8_t key_value() const
{
return m_key_value;
}
/*!
* @brief This function returns a reference to member key_value
* @return Reference to member key_value
*/
inline eProsima_user_DllExport uint8_t& key_value()
{
return m_key_value;
}
/*!
* @brief This function returns the maximum serialized size of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getMaxCdrSerializedSize(size_t current_alignment = 0);
/*!
* @brief This function returns the serialized size of a data depending on the buffer alignment.
* @param data Data which is calculated its serialized size.
* @param current_alignment Buffer alignment.
* @return Serialized size.
*/
eProsima_user_DllExport static size_t getCdrSerializedSize(const sample& data, size_t current_alignment = 0);
/*!
* @brief This function serializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serialize(eprosima::fastcdr::Cdr &cdr) const;
/*!
* @brief This function deserializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void deserialize(eprosima::fastcdr::Cdr &cdr);
/*!
* @brief This function returns the maximum serialized size of the Key of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize(size_t current_alignment = 0);
/*!
* @brief This function tells you if the Key has been defined for this type
*/
eProsima_user_DllExport static bool isKeyDefined();
/*!
* @brief This function serializes the key members of an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const;
private:
uint8_t m_index;
uint8_t m_key_value;
};
#endif // _sample_H_ | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/LateJoiners/samplePubSubTypes.cxx | // 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 samplePubSubTypes.cpp
* This header file contains the implementation of the serialization functions.
*
* This file was generated by the tool fastcdrgen.
*/
#include <fastcdr/FastBuffer.h>
#include <fastcdr/Cdr.h>
#include "samplePubSubTypes.h"
samplePubSubType::samplePubSubType() {
setName("sample");
m_typeSize = (uint32_t)sample::getMaxCdrSerializedSize() + 4 /*encapsulation*/;
m_isGetKeyDefined = sample::isKeyDefined();
m_keyBuffer = (unsigned char*)malloc(sample::getKeyMaxCdrSerializedSize()>16 ? sample::getKeyMaxCdrSerializedSize() : 16);
}
samplePubSubType::~samplePubSubType() {
if(m_keyBuffer!=nullptr)
free(m_keyBuffer);
}
bool samplePubSubType::serialize(void *data, SerializedPayload_t *payload) {
sample *p_type = (sample*) data;
eprosima::fastcdr::FastBuffer fastbuffer((char*) payload->data, payload->max_size); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);
payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
// Serialize encapsulation
ser.serialize_encapsulation();
p_type->serialize(ser); // Serialize the object:
payload->length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length
return true;
}
bool samplePubSubType::deserialize(SerializedPayload_t* payload, void* data) {
sample* p_type = (sample*) data; //Convert DATA to pointer of your type
eprosima::fastcdr::FastBuffer fastbuffer((char*)payload->data, payload->length); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR); // Object that deserializes the data.
// Deserialize encapsulation.
deser.read_encapsulation();
payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
p_type->deserialize(deser); //Deserialize the object:
return true;
}
std::function<uint32_t()> samplePubSubType::getSerializedSizeProvider(void* data) {
return [data]() -> uint32_t
{
return (uint32_t)type::getCdrSerializedSize(*static_cast<sample*>(data)) + 4 /*encapsulation*/;
};
}
void* samplePubSubType::createData() {
return (void*)new sample();
}
void samplePubSubType::deleteData(void* data) {
delete((sample*)data);
}
bool samplePubSubType::getKey(void *data, InstanceHandle_t* handle) {
if(!m_isGetKeyDefined)
return false;
sample* p_type = (sample*) data;
eprosima::fastcdr::FastBuffer fastbuffer((char*)m_keyBuffer,sample::getKeyMaxCdrSerializedSize()); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); // Object that serializes the data.
p_type->serializeKey(ser);
if(sample::getKeyMaxCdrSerializedSize()>16) {
m_md5.init();
m_md5.update(m_keyBuffer,(unsigned int)ser.getSerializedDataLength());
m_md5.finalize();
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_md5.digest[i];
}
}
else {
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_keyBuffer[i];
}
}
return true;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/deadlinepayload.cxx | // 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 deadlinepayload.cpp
* This source file contains the definition of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/
#ifdef _WIN32
// Remove linker warning LNK4221 on Visual Studio
namespace { char dummy; }
#endif
#include "deadlinepayload.h"
#include <fastcdr/Cdr.h>
#include <fastcdr/exceptions/BadParamException.h>
using namespace eprosima::fastcdr::exception;
#include <utility>
HelloMsg::HelloMsg()
{
m_deadlinekey = 0;
}
HelloMsg::~HelloMsg()
{
}
HelloMsg::HelloMsg(const HelloMsg &x)
{
m_deadlinekey = x.m_deadlinekey;
m_payload = x.m_payload;
}
HelloMsg::HelloMsg(HelloMsg &&x)
{
m_deadlinekey = x.m_deadlinekey;
m_payload = std::move(x.m_payload);
}
HelloMsg& HelloMsg::operator=(const HelloMsg &x)
{
m_deadlinekey = x.m_deadlinekey;
m_payload = x.m_payload;
return *this;
}
HelloMsg& HelloMsg::operator=(HelloMsg &&x)
{
m_deadlinekey = x.m_deadlinekey;
m_payload = std::move(x.m_payload);
return *this;
}
size_t HelloMsg::getMaxCdrSerializedSize(size_t current_alignment)
{
size_t initial_alignment = current_alignment;
current_alignment += 2 + eprosima::fastcdr::Cdr::alignment(current_alignment, 2);
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 256 + 1;
return current_alignment - initial_alignment;
}
size_t HelloMsg::getCdrSerializedSize(const HelloMsg& data, size_t current_alignment)
{
size_t initial_alignment = current_alignment;
current_alignment += 2 + eprosima::fastcdr::Cdr::alignment(current_alignment, 2);
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.payload().size() + 1;
return current_alignment - initial_alignment;
}
void HelloMsg::serialize(eprosima::fastcdr::Cdr &scdr) const
{
scdr << m_deadlinekey;
if(m_payload.length() <= 256)
scdr << m_payload;
else
throw eprosima::fastcdr::exception::BadParamException("payload field exceeds the maximum length");
}
void HelloMsg::deserialize(eprosima::fastcdr::Cdr &dcdr)
{
dcdr >> m_deadlinekey;
dcdr >> m_payload;
}
size_t HelloMsg::getKeyMaxCdrSerializedSize(size_t current_alignment)
{
size_t current_align = current_alignment;
current_align += 2 + eprosima::fastcdr::Cdr::alignment(current_align, 2);
return current_align;
}
bool HelloMsg::isKeyDefined()
{
return true;
}
void HelloMsg::serializeKey(eprosima::fastcdr::Cdr &scdr) const
{
scdr << m_deadlinekey;
} | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/deadlinepayloadPublisher.h | // 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.
#ifndef _DEADLINEPAYLOAD_PUBLISHER_H_
#define _DEADLINEPAYLOAD_PUBLISHER_H_
#include <fastrtps/fastrtps_fwd.h>
#include <fastrtps/publisher/PublisherListener.h>
#include "deadlinepayloadPubSubTypes.h"
using namespace eprosima::fastrtps;
class deadlinepayloadPublisher
{
public:
deadlinepayloadPublisher();
virtual ~deadlinepayloadPublisher();
bool init();
void run();
private:
Participant *mp_participant;
Publisher *mp_publisher;
bool double_time; //Used to force a period double on a certain key
class PubListener : public PublisherListener
{
public:
PubListener() : n_matched(0){};
~PubListener(){};
void onPublicationMatched(Publisher* pub,MatchingInfo& info);
int n_matched;
} m_listener;
HelloMsgPubSubType myType;
};
#endif // _DEADLINEPAYLOAD_PUBLISHER_H_
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/deadlinepayloadPubSubTypes.cxx | // 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 deadlinepayloadPubSubTypes.cpp
* This header file contains the implementation of the serialization functions.
*
* This file was generated by the tool fastcdrgen.
*/
#include <fastcdr/FastBuffer.h>
#include <fastcdr/Cdr.h>
#include "deadlinepayloadPubSubTypes.h"
HelloMsgPubSubType::HelloMsgPubSubType() {
setName("HelloMsg");
m_typeSize = (uint32_t)HelloMsg::getMaxCdrSerializedSize() + 4 /*encapsulation*/;
m_isGetKeyDefined = HelloMsg::isKeyDefined();
m_keyBuffer = (unsigned char*)malloc(HelloMsg::getKeyMaxCdrSerializedSize()>16 ? HelloMsg::getKeyMaxCdrSerializedSize() : 16);
}
HelloMsgPubSubType::~HelloMsgPubSubType() {
if(m_keyBuffer!=nullptr)
free(m_keyBuffer);
}
bool HelloMsgPubSubType::serialize(void *data, SerializedPayload_t *payload) {
HelloMsg *p_type = (HelloMsg*) data;
eprosima::fastcdr::FastBuffer fastbuffer((char*) payload->data, payload->max_size); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);
payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
// Serialize encapsulation
ser.serialize_encapsulation();
p_type->serialize(ser); // Serialize the object:
payload->length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length
return true;
}
bool HelloMsgPubSubType::deserialize(SerializedPayload_t* payload, void* data) {
HelloMsg* p_type = (HelloMsg*) data; //Convert DATA to pointer of your type
eprosima::fastcdr::FastBuffer fastbuffer((char*)payload->data, payload->length); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR); // Object that deserializes the data.
// Deserialize encapsulation.
deser.read_encapsulation();
payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
p_type->deserialize(deser); //Deserialize the object:
return true;
}
std::function<uint32_t()> HelloMsgPubSubType::getSerializedSizeProvider(void* data) {
return [data]() -> uint32_t {
return (uint32_t)type::getCdrSerializedSize(*static_cast<HelloMsg*>(data)) + 4 /*encapsulation*/;
};
}
void* HelloMsgPubSubType::createData() {
return (void*)new HelloMsg();
}
void HelloMsgPubSubType::deleteData(void* data) {
delete((HelloMsg*)data);
}
bool HelloMsgPubSubType::getKey(void *data, InstanceHandle_t* handle) {
if(!m_isGetKeyDefined)
return false;
HelloMsg* p_type = (HelloMsg*) data;
eprosima::fastcdr::FastBuffer fastbuffer((char*)m_keyBuffer,HelloMsg::getKeyMaxCdrSerializedSize()); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); // Object that serializes the data.
p_type->serializeKey(ser);
if(HelloMsg::getKeyMaxCdrSerializedSize()>16) {
m_md5.init();
m_md5.update(m_keyBuffer,(unsigned int)ser.getSerializedDataLength());
m_md5.finalize();
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_md5.digest[i];
}
}
else {
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_keyBuffer[i];
}
}
return true;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/CMakeLists.txt | # 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.
cmake_minimum_required(VERSION 2.8.12)
project("DeadlineQoSExample")
# Find requirements
find_package(fastcdr REQUIRED)
find_package(fastrtps REQUIRED)
# Set C++11
include(CheckCXXCompilerFlag)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_cxx_compiler_flag(--std=c++11 SUPPORTS_CXX11)
if(SUPPORTS_CXX11)
add_compile_options(--std=c++11)
else()
message(FATAL_ERROR "Compiler doesn't support C++11")
endif()
endif()
message(STATUS "Configuring DeadlineQoS example...")
file(GLOB DEADLINEQOS_EXAMPLE_SOURCES "*.cxx")
add_definitions(
-DBOOST_ASIO_STANDALONE
-DASIO_STANDALONE
)
include_directories(${PROJECT_SOURCE_DIR}/../../../thirdparty/asio/asio/include)
add_executable(DeadlineQoSExample ${DEADLINEQOS_EXAMPLE_SOURCES})
target_link_libraries(DeadlineQoSExample fastrtps fastcdr)
if(UNIX)
target_link_libraries(DeadlineQoSExample pthread)
endif()
install(TARGETS DeadlineQoSExample
RUNTIME DESTINATION examples/C++/DeadlineQoSExample/${BIN_INSTALL_DIR}
)
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/deadlinepayloadPubSubMain.cxx | // 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.
#include "deadlinepayloadPublisher.h"
#include "deadlinepayloadSubscriber.h"
#include <fastrtps/Domain.h>
#include <fastrtps/log/Log.h>
#include "asio.hpp"
using namespace eprosima;
using namespace eprosima::fastrtps;
using namespace asio;
int main(int argc, char** argv)
{
std::cout << "Starting " << std::endl;
int type = 1;
if (argc > 1)
{
if (strcmp(argv[1], "publisher") == 0)
{
type = 1;
}
else if (strcmp(argv[1], "subscriber") == 0)
{
type = 2;
}
}
else
{
std::cout << "publisher OR subscriber argument needed" << std::endl;
return 0;
}
// Register the type being used
switch(type)
{
case 1:
{
deadlinepayloadPublisher mypub;
if (mypub.init())
{
mypub.run();
}
break;
}
case 2:
{
io_service io;
steady_timer myTimer(io);
deadlinepayloadSubscriber mysub(myTimer,io);
if (mysub.init())
{
mysub.run();
}
break;
}
}
return 0;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/deadlineQoS.h | // 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.
/* DeadlineQoS
Helper class to implement a way to check if the deadline constrains is being met on each key
of the topic at hand.
*/
#ifndef _DEADLINEQOS_H_
#define _DEADLINEQOS_H_
#include <fastrtps/participant/Participant.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/subscriber/Subscriber.h>
#include <fastrtps/attributes/SubscriberAttributes.h>
#include <fastrtps/Domain.h>
#include <asio.hpp>
#include <asio/steady_timer.hpp>
#include "mapableKey.h"
#include <iostream>
#include <map>
#include <thread>
using namespace asio;
using namespace eprosima;
using namespace eprosima::fastrtps;
class deadlineQoS
{
public:
deadlineQoS(steady_timer &timer, io_service &ioserv): t(timer),io(ioserv){
init();
}
~deadlineQoS(){
delete dlqos;
}
void callback();
void setFlag(mapable_key target);
void run();
void stop();
//deadlineQoS_struct deadlineQoSlist[32];
std::map<mapable_key,bool> deadlineQoSmap;
std::mutex mapmtx;
private:
steady_timer &t;
io_service &io;
std::thread* dlqos;
void runner();
void init();
void wait();
};
#endif
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/deadlineQoS.cxx | // 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.
#include <chrono>
#include "deadlineQoS.h"
#include <string>
using namespace asio;
using namespace eprosima;
using namespace eprosima::fastrtps;
void deadlineQoS::callback()
{
mapmtx.lock();
std::cout << "Map holds " << deadlineQoSmap.size() << " different keys" << std::endl;
for(auto it = deadlineQoSmap.begin(); it != deadlineQoSmap.end(); it++){
if(it->second == false){
std::cout << "Deadline QoS on key index ";
for(int i=0;i<16;i++){
std::cout << std::to_string( it->first.value[i] );
}
std::cout << " missed." << std::endl;
}
//After checking the value, reset flag to zero
it->second = false;
}
mapmtx.unlock();
wait();
}
void deadlineQoS::wait()
{
t.expires_from_now(std::chrono::seconds(1)); //repeat rate here
t.async_wait(std::bind(&deadlineQoS::callback, this));
}
void deadlineQoS::setFlag(mapable_key target)
{
mapmtx.lock();
if(deadlineQoSmap.find(target)!=deadlineQoSmap.end()){
//Exists
deadlineQoSmap.at(target)=true;
}else{
//Does not exist
deadlineQoSmap.insert(std::pair<mapable_key,bool>(target,true));
}
//deadlineQoSmap.[target]=true;
mapmtx.unlock();
//if(index<32){
// deadlineQoSlist[index].mtx.lock();
// deadlineQoSlist[index].flag = true;
// deadlineQoSlist[index].mtx.unlock();
//}
}
void deadlineQoS::init(){
//Not really needed now
std::cout << "Deadline QoS Service started" << std::endl;
//for(int i=0;i<32;i++){
// deadlineQoSlist[i].mtx.lock();
// deadlineQoSlist[i].flag = false;
// deadlineQoSlist[i].mtx.unlock();
//}
}
void deadlineQoS::runner(){
wait();
io.run();
}
void deadlineQoS::run(){
dlqos = new std::thread(std::bind(&deadlineQoS::runner,this));
}
void deadlineQoS::stop(){
t.cancel();
io.stop();
dlqos->join();
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/Makefile | # 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.
CPP=g++
LN=g++
AR=ar
CP=cp
SYSLIBS= -ldl -lnsl -lm -lpthread -lrt
DEFINES=
COMMON_CFLAGS= -c -Wall -D__LITTLE_ENDIAN__ -std=c++11
## CHOOSE HERE BETWEEN 32 and 64 bit architecture
##32 BIT ARCH:
#COMMON_CFLAGS+= -m32 -fpic
#LDFLAGS=-m32
#64BIT ARCH:
COMMON_CFLAGS+= -m64 -fpic
LDFLAGS=-m64
CFLAGS = $(COMMON_CFLAGS) -O2
INCLUDES= -I../../../thirdparty/asio/asio/include
LIBS = -lfastcdr -lfastrtps $(SYSLIBS)
DIRECTORIES= output.dir bin.dir
all: $(DIRECTORIES) DeadlineQoSExample
DEADLINEQOSEXAMPLE_TARGET= bin/DeadlineQoSExample
DEADLINEQOSEXAMPLE_SRC_CXXFILES=
DEADLINEQOSEXAMPLE_SRC_CPPFILES= DeadlineQoSExample/deadlinepayload.cxx \
DeadlineQoSExample/deadlinepayloadPubSubTypes.cxx \
DeadlineQoSExample/deadlinepayloadPublisher.cxx \
DeadlineQoSExample/deadlinepayloadSubscriber.cxx \
DeadlineQoSExample/deadlinepayloadPubSubMain.cxx \
DeadlineQoSExample/deadlineQoS.cxx
# Project sources are copied to the current directory
DEADLINEQOSEXAMPLE_SRCS= $(DEADLINEQOSEXAMPLE_SRC_CXXFILES) $(DEADLINEQOSEXAMPLE_SRC_CPPFILES)
# Source directories
DEADLINEQOSEXAMPLE_SOURCES_DIRS_AUX= $(foreach srcdir, $(dir $(DEADLINEQOSEXAMPLE_SRCS)), $(srcdir))
DEADLINEQOSEXAMPLE_SOURCES_DIRS= $(shell echo $(DEADLINEQOSEXAMPLE_SOURCES_DIRS_AUX) | tr " " "\n" | sort | uniq | tr "\n" " ")
DEADLINEQOSEXAMPLE_OBJS = $(foreach obj,$(notdir $(addsuffix .o, $(DEADLINEQOSEXAMPLE_SRCS))), output/$(obj))
DEADLINEQOSEXAMPLE_DEPS = $(foreach dep,$(notdir $(addsuffix .d, $(DEADLINEQOSEXAMPLE_SRCS))), output/$(dep))
OBJS+= $(DEADLINEQOSEXAMPLE_OBJS)
DEPS+= $(DEADLINEQOSEXAMPLE_DEPS)
DeadlineQoSExample: $(DEADLINEQOSEXAMPLE_TARGET)
$(DEADLINEQOSEXAMPLE_TARGET): $(DEADLINEQOSEXAMPLE_OBJS)
$(LN) $(LDFLAGS) -o $(DEADLINEQOSEXAMPLE_TARGET) $(DEADLINEQOSEXAMPLE_OBJS) $(LIBS)
vpath %.cxx $(DEADLINEQOSEXAMPLE_SOURCES_DIRS)
vpath %.cpp $(DEADLINEQOSEXAMPLE_SOURCES_DIRS)
output/%.cxx.o:%.cxx
@echo Calculating dependencies $<
@$(CC) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cxx.o=%.cxx.d)
@echo Compiling $<
@$(CC) $(CFLAGS) $(INCLUDES) $< -o $@
output/%.cpp.o:%.cpp
@echo Calculating dependencies $<
@$(CPP) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cpp.o=%.cpp.d)
@echo Compiling $<
@$(CPP) $(CFLAGS) $(INCLUDES) $< -o $@
.PHONY: DeadlineQoSExample
clean:
@rm -f $(OBJS)
@rm -f $(DEPS)
ifneq ($(MAKECMDGOALS), clean)
-include $(DEPS)
endif
%.dir :
@echo "Checking directory $*"
@if [ ! -d $* ]; then \
echo "Making directory $*"; \
mkdir -p $* ; \
fi;
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/deadlinepayload.idl | struct HelloMsg
{
@Key
unsigned short deadlinekey;
string<256> payload;
}; | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/deadlinepayload.h | // 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 deadlinepayload.h
* This header file contains the declaration of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/
#ifndef _deadlinepayload_H_
#define _deadlinepayload_H_
// TODO Poner en el contexto.
#include <stdint.h>
#include <array>
#include <string>
#include <vector>
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#define eProsima_user_DllExport __declspec( dllexport )
#else
#define eProsima_user_DllExport
#endif
#else
#define eProsima_user_DllExport
#endif
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#if defined(deadlinepayload_SOURCE)
#define deadlinepayload_DllAPI __declspec( dllexport )
#else
#define deadlinepayload_DllAPI __declspec( dllimport )
#endif // deadlinepayload_SOURCE
#else
#define deadlinepayload_DllAPI
#endif
#else
#define deadlinepayload_DllAPI
#endif // _WIN32
namespace eprosima
{
namespace fastcdr
{
class Cdr;
}
}
/*!
* @brief This class represents the structure HelloMsg defined by the user in the IDL file.
* @ingroup DEADLINEPAYLOAD
*/
class HelloMsg
{
public:
/*!
* @brief Default constructor.
*/
eProsima_user_DllExport HelloMsg();
/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~HelloMsg();
/*!
* @brief Copy constructor.
* @param x Reference to the object HelloMsg that will be copied.
*/
eProsima_user_DllExport HelloMsg(const HelloMsg &x);
/*!
* @brief Move constructor.
* @param x Reference to the object HelloMsg that will be copied.
*/
eProsima_user_DllExport HelloMsg(HelloMsg &&x);
/*!
* @brief Copy assignment.
* @param x Reference to the object HelloMsg that will be copied.
*/
eProsima_user_DllExport HelloMsg& operator=(const HelloMsg &x);
/*!
* @brief Move assignment.
* @param x Reference to the object HelloMsg that will be copied.
*/
eProsima_user_DllExport HelloMsg& operator=(HelloMsg &&x);
/*!
* @brief This function sets a value in member deadlinekey
* @param _deadlinekey New value for member deadlinekey
*/
inline eProsima_user_DllExport void deadlinekey(uint16_t _deadlinekey)
{
m_deadlinekey = _deadlinekey;
}
/*!
* @brief This function returns the value of member deadlinekey
* @return Value of member deadlinekey
*/
inline eProsima_user_DllExport uint16_t deadlinekey() const
{
return m_deadlinekey;
}
/*!
* @brief This function returns a reference to member deadlinekey
* @return Reference to member deadlinekey
*/
inline eProsima_user_DllExport uint16_t& deadlinekey()
{
return m_deadlinekey;
}
/*!
* @brief This function copies the value in member payload
* @param _payload New value to be copied in member payload
*/
inline eProsima_user_DllExport void payload(const std::string &_payload)
{
m_payload = _payload;
}
/*!
* @brief This function moves the value in member payload
* @param _payload New value to be moved in member payload
*/
inline eProsima_user_DllExport void payload(std::string &&_payload)
{
m_payload = std::move(_payload);
}
/*!
* @brief This function returns a constant reference to member payload
* @return Constant reference to member payload
*/
inline eProsima_user_DllExport const std::string& payload() const
{
return m_payload;
}
/*!
* @brief This function returns a reference to member payload
* @return Reference to member payload
*/
inline eProsima_user_DllExport std::string& payload()
{
return m_payload;
}
/*!
* @brief This function returns the maximum serialized size of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getMaxCdrSerializedSize(size_t current_alignment = 0);
/*!
* @brief This function returns the serialized size of a data depending on the buffer alignment.
* @param data Data which is calculated its serialized size.
* @param current_alignment Buffer alignment.
* @return Serialized size.
*/
eProsima_user_DllExport static size_t getCdrSerializedSize(const HelloMsg& data, size_t current_alignment = 0);
/*!
* @brief This function serializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serialize(eprosima::fastcdr::Cdr &cdr) const;
/*!
* @brief This function deserializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void deserialize(eprosima::fastcdr::Cdr &cdr);
/*!
* @brief This function returns the maximum serialized size of the Key of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize(size_t current_alignment = 0);
/*!
* @brief This function tells you if the Key has been defined for this type
*/
eProsima_user_DllExport static bool isKeyDefined();
/*!
* @brief This function serializes the key members of an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const;
private:
uint16_t m_deadlinekey;
std::string m_payload;
};
#endif // _deadlinepayload_H_ | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/deadlinepayloadSubscriber.cxx | // 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.
#include <fastrtps/participant/Participant.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/subscriber/Subscriber.h>
#include <fastrtps/attributes/SubscriberAttributes.h>
#include <fastrtps/Domain.h>
#include "deadlinepayloadSubscriber.h"
deadlinepayloadSubscriber::deadlinepayloadSubscriber(asio::steady_timer &timer,asio::io_service &ioserv) : mp_participant(nullptr), mp_subscriber(nullptr), m_listener(timer,ioserv) {}
deadlinepayloadSubscriber::~deadlinepayloadSubscriber() { Domain::removeParticipant(mp_participant);}
bool deadlinepayloadSubscriber::init()
{
// Create RTPSParticipant
ParticipantAttributes PParam;
PParam.rtps.builtin.domainId = 0; //MUST BE THE SAME AS IN THE PUBLISHER
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
PParam.rtps.setName("Participant_subscriber"); //You can put the name you want
mp_participant = Domain::createParticipant(PParam);
if(mp_participant == nullptr)
return false;
//Register the type
Domain::registerType(mp_participant,(TopicDataType*) &myType);
// Create Subscriber
SubscriberAttributes Rparam;
Rparam.topic.topicKind = WITH_KEY;
Rparam.topic.topicDataType = myType.getName(); //Must be registered before the creation of the subscriber
Rparam.topic.topicName = "deadlinepayloadPubSubTopic";
Rparam.topic.resourceLimitsQos.max_instances=32;
Rparam.topic.resourceLimitsQos.max_samples_per_instance=5;
Rparam.topic.resourceLimitsQos.max_samples = 32*5;
Rparam.qos.m_reliability.kind= RELIABLE_RELIABILITY_QOS;
Rparam.topic.historyQos.depth = 5;
mp_subscriber = Domain::createSubscriber(mp_participant,Rparam,(SubscriberListener*)&m_listener);
if(mp_subscriber == nullptr)
return false;
return true;
}
void deadlinepayloadSubscriber::SubListener::onSubscriptionMatched(Subscriber* /*sub*/,MatchingInfo& info)
{
if (info.status == MATCHED_MATCHING)
{
n_matched++;
std::cout << "Subscriber matched" << std::endl;
}
else
{
n_matched--;
std::cout << "Subscriber unmatched" << std::endl;
}
}
void deadlinepayloadSubscriber::SubListener::onNewDataMessage(Subscriber* sub)
{
// Take data
HelloMsg st;
//InstanceHandle_t myHandle;
mapable_key handle;
if(sub->takeNextData(&st, &m_info))
{
if(m_info.sampleKind == ALIVE)
{
for(int i=0;i<16;i++) handle.value[i] = m_info.iHandle.value[i];
myDeadline.setFlag(handle);
}
}
}
void deadlinepayloadSubscriber::run()
{
m_listener.myDeadline.run();
std::cout << "Waiting for Data, press Enter to stop the Subscriber. "<<std::endl;
std::cout << "------------------------------------------------------"<<std::endl;
std::cin.ignore();
std::cout << "Shutting down the Subscriber." << std::endl;
m_listener.myDeadline.stop();
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/deadlinepayloadPublisher.cxx | // 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.
#include <fastrtps/participant/Participant.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/publisher/Publisher.h>
#include <fastrtps/attributes/PublisherAttributes.h>
#include <fastrtps/Domain.h>
#include <fastrtps/utils/eClock.h>
#include "deadlinepayloadPublisher.h"
deadlinepayloadPublisher::deadlinepayloadPublisher() : mp_participant(nullptr), mp_publisher(nullptr), double_time(false) {}
deadlinepayloadPublisher::~deadlinepayloadPublisher() { Domain::removeParticipant(mp_participant);}
bool deadlinepayloadPublisher::init()
{
// Create RTPSParticipant
ParticipantAttributes PParam;
PParam.rtps.builtin.domainId = 0;
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
PParam.rtps.setName("Participant_publisher"); //You can put here the name you want
mp_participant = Domain::createParticipant(PParam);
if(mp_participant == nullptr)
return false;
//Register the type
Domain::registerType(mp_participant,(TopicDataType*) &myType);
// Create Publisher
PublisherAttributes Wparam;
Wparam.topic.topicKind = WITH_KEY;
Wparam.topic.topicDataType = myType.getName(); //This type MUST be registered
Wparam.topic.topicName = "deadlinepayloadPubSubTopic";
Wparam.topic.resourceLimitsQos.max_instances=32;
Wparam.topic.resourceLimitsQos.max_samples_per_instance=5;
Wparam.topic.resourceLimitsQos.max_samples = 32*5;
Wparam.topic.historyQos.depth = 5;
Wparam.qos.m_reliability.kind= RELIABLE_RELIABILITY_QOS;
mp_publisher = Domain::createPublisher(mp_participant,Wparam,(PublisherListener*)&m_listener);
if(mp_publisher == nullptr)
return false;
std::cout << "Publisher created, waiting for Subscribers." << std::endl;
return true;
}
void deadlinepayloadPublisher::PubListener::onPublicationMatched(Publisher* /*pub*/,MatchingInfo& info)
{
if (info.status == MATCHED_MATCHING)
{
n_matched++;
std::cout << "Publisher matched" << std::endl;
}
else
{
n_matched--;
std::cout << "Publisher unmatched" << std::endl;
}
}
void deadlinepayloadPublisher::run()
{
while(m_listener.n_matched == 0)
{
eClock::my_sleep(250); // Sleep 250 ms
}
// Publication code
HelloMsg st;
std::stringstream stream;
//Filling sample message
stream << "generic payload";
st.payload(stream.str());
/* Initialize your structure here */
while(true){
eClock::my_sleep(900);
//Send messages
for(unsigned short i=0;i<32;i++){
st.deadlinekey(i); //Set key
if(i==15){ //Force key 15 message to be sent half of the times
double_time = !double_time;
if(double_time) mp_publisher->write(&st);
}else{
mp_publisher->write(&st);
}
}
}
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/README.txt | -----------------------------
| USER DEADLINE EXAMPLE |
-----------------------------
-------------------
- Purpose -
-------------------
This example shows a way to implement a Deadline QoS feature on a FastRTPS Application,
taking an example project as a starting point.
Deadline is a subscriber-based QoS provides an alarm when the period in which data is received
doesntmeet the configured requirements (i.e: data arrival is slower than expected).
When a topic has a key, each piece of data with different key is treated as a different
data source/sink and therefore a Deadline alarm is set off independently for each
key.
-------------------
-Working principle-
-------------------
The Deadline QoS is configured with a minimun data arrival frequency. In every period, a
check is performed to determine if new data has arrived for every key since the last update.
In the case a key does not have new data, the alarm for that key goes off.
This check is run with the same periodicity as the expected maximun period between samples.
Each key has a flag bit assigned to it, that becomes set to '1' every time a piece of data
with that key arrives. The Deadline check verifies the status of these flags and resets them
to '0' upon exit, meaning that, upon the next check, a '1' flag means "data received in this period"
and a '0' means "no new data". The alarm consists on a user-defined callback function that is called
when a '0' flag is found during the check.
--------------------
- Implementation -
--------------------
In this example, the Deadline QoS is implemented by the use of a helper class
DeadlineQoS. This class implements:
- A map of flag bits for each key (with mutex to ensure exclusive access).
- A method to be called from onNewDataMessage to set flags on the QoS map based on the keys.
- A predefined callback function that performs the QoS checks periodically.
- A function to activate the process.
- A deadline-missed callback function.
-------------------
- USAGE -
-------------------
To make use of the provided DeadlineQoS implementation...
- Create an instance of deadlineQoS inside your subscriber's listener.
- Activate the service by calling deadlineQoS::run()
- Use eadlineQoS::setFlag(key) to update the flag list on deadlineQoS on new data arrival.
- Specify the desired functionality on Deadline miss in deadlineQoS::callback()
It is important to configure the topic to distinguish between keys, otherwise the @key parameter
specified in the IDL will be ignored.
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/deadlinepayloadSubscriber.h | // 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 deadlinepayloadSubscriber.h
* This header file contains the declaration of the subscriber functions.
*
* This file was generated by the tool fastcdrgen.
*/
#ifndef _DEADLINEPAYLOAD_SUBSCRIBER_H_
#define _DEADLINEPAYLOAD_SUBSCRIBER_H_
#include <fastrtps/fastrtps_fwd.h>
#include <fastrtps/subscriber/SubscriberListener.h>
#include <fastrtps/subscriber/SampleInfo.h>
#include "deadlinepayloadPubSubTypes.h"
#include "deadlineQoS.h"
#include <asio.hpp>
#include <asio/steady_timer.hpp>
#include "mapableKey.h"
using namespace eprosima::fastrtps;
class deadlinepayloadSubscriber
{
public:
deadlinepayloadSubscriber(asio::steady_timer &timer,asio::io_service &io_service);
virtual ~deadlinepayloadSubscriber();
bool init();
void run();
private:
Participant *mp_participant;
Subscriber *mp_subscriber;
//io_service &io;
class SubListener : public SubscriberListener
{
public:
SubListener(asio::steady_timer &timer, asio::io_service &ioserv) : n_matched(0),n_msg(0), myDeadline(timer,ioserv){};
~SubListener(){};
void onSubscriptionMatched(Subscriber* sub,MatchingInfo& info);
void onNewDataMessage(Subscriber* sub);
SampleInfo_t m_info;
int n_matched;
int n_msg;
deadlineQoS myDeadline;
} m_listener;
HelloMsgPubSubType myType;
};
#endif // _deadlinepayload_SUBSCRIBER_H_
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/mapableKey.h | // 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.
#ifndef MAPABLEKEY_H_
#define MAPABLEKEY_H_
#include <fastrtps/participant/Participant.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/subscriber/Subscriber.h>
#include <fastrtps/attributes/SubscriberAttributes.h>
#include <fastrtps/Domain.h>
typedef struct ex_mapableKey{
octet value[16];
ex_mapableKey& operator=(const InstanceHandle_t& ihandle){
for(uint8_t i=0;i<16;i++)
{
value[i] = ihandle.value[i];
}
return *this;
}
}mapable_key;
inline bool operator<(const ex_mapableKey& ex_mapableKey1,const ex_mapableKey& ex_mapableKey2)
{
for(uint8_t i=0;i<16;++i){
if(ex_mapableKey1.value[i] < ex_mapableKey2.value[i])
return true;
}
return false;
}
#endif
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/DeadlineQoSExample/deadlinepayloadPubSubTypes.h | // 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 deadlinepayloadPubSubTypes.h
* This header file contains the declaration of the serialization functions.
*
* This file was generated by the tool fastcdrgen.
*/
#ifndef _DEADLINEPAYLOAD_PUBSUBTYPES_H_
#define _DEADLINEPAYLOAD_PUBSUBTYPES_H_
#include <fastrtps/TopicDataType.h>
using namespace eprosima::fastrtps;
#include "deadlinepayload.h"
/*!
* @brief This class represents the TopicDataType of the type HelloMsg defined by the user in the IDL file.
* @ingroup DEADLINEPAYLOAD
*/
class HelloMsgPubSubType : public TopicDataType {
public:
typedef HelloMsg type;
HelloMsgPubSubType();
virtual ~HelloMsgPubSubType();
bool serialize(void *data, SerializedPayload_t *payload);
bool deserialize(SerializedPayload_t *payload, void *data);
std::function<uint32_t()> getSerializedSizeProvider(void* data);
bool getKey(void *data, InstanceHandle_t *ihandle);
void* createData();
void deleteData(void * data);
MD5 m_md5;
unsigned char* m_keyBuffer;
};
#endif // _deadlinepayload_PUBSUBTYPE_H_ | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/RTPSTest_registered/CMakeLists.txt | # 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.
cmake_minimum_required(VERSION 2.8.12)
project("RTPSTest_registered")
# Find requirements
find_package(fastcdr REQUIRED)
find_package(fastrtps REQUIRED)
# Set C++11
include(CheckCXXCompilerFlag)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_cxx_compiler_flag(--std=c++11 SUPPORTS_CXX11)
if(SUPPORTS_CXX11)
add_compile_options(--std=c++11)
else()
message(FATAL_ERROR "Compiler doesn't support C++11")
endif()
endif()
message(STATUS "Configuring RTPSTest_registered...")
file(GLOB RTPSTESTREGISTERED_SOURCES "*.cpp")
add_executable(RTPSTest_registered ${RTPSTESTREGISTERED_SOURCES})
target_link_libraries(RTPSTest_registered fastrtps fastcdr)
install(TARGETS RTPSTest_registered
RUNTIME DESTINATION examples/C++/RTPSTest_registered/${BIN_INSTALL_DIR}
)
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/RTPSTest_registered/TestWriterRegistered.h | // 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 TestWriterRegistered.h
*
*/
#ifndef TESTWRITERREGISTERED_H_
#define TESTWRITERREGISTERED_H_
#include "fastrtps/rtps/rtps_fwd.h"
using namespace eprosima::fastrtps::rtps;
#include "fastrtps/rtps/writer/WriterListener.h"
class TestWriterRegistered {
public:
TestWriterRegistered();
virtual ~TestWriterRegistered();
RTPSParticipant* mp_participant;
RTPSWriter* mp_writer;
WriterHistory* mp_history;
bool init(); //Initialize writer
bool reg(); //Register the Writer
void run(uint16_t samples); //Run the Writer
class MyListener :public WriterListener
{
public:
MyListener():n_matched(0){};
~MyListener(){};
void onWriterMatched(RTPSWriter* writer, MatchingInfo& info)
{
if (info.status == MATCHED_MATCHING)
++n_matched;
}
int n_matched;
}m_listener;
};
#endif /* TESTWRITER_H_ */
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/RTPSTest_registered/TestReaderRegistered.cpp | // 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 TestReaderRegistered.cpp
*
*/
#include "TestReaderRegistered.h"
#include "fastrtps/rtps/reader/RTPSReader.h"
#include "fastrtps/rtps/participant/RTPSParticipant.h"
#include "fastrtps/rtps/RTPSDomain.h"
#include "fastrtps/rtps/attributes/RTPSParticipantAttributes.h"
#include "fastrtps/rtps/attributes/ReaderAttributes.h"
#include "fastrtps/rtps/attributes/HistoryAttributes.h"
#include "fastrtps/rtps/history/ReaderHistory.h"
#include "fastrtps/attributes/TopicAttributes.h"
#include "fastrtps/qos/ReaderQos.h"
using namespace eprosima;
using namespace fastrtps;
TestReaderRegistered::TestReaderRegistered():
mp_participant(nullptr),
mp_reader(nullptr),
mp_history(nullptr)
{
}
TestReaderRegistered::~TestReaderRegistered()
{
RTPSDomain::removeRTPSParticipant(mp_participant);
delete(mp_history);
}
bool TestReaderRegistered::init()
{
//CREATE PARTICIPANT
RTPSParticipantAttributes PParam;
PParam.builtin.use_SIMPLE_RTPSParticipantDiscoveryProtocol = true;
PParam.builtin.use_WriterLivelinessProtocol = true;
mp_participant = RTPSDomain::createParticipant(PParam);
if(mp_participant==nullptr)
return false;
//CREATE READERHISTORY
HistoryAttributes hatt;
hatt.payloadMaxSize = 255;
mp_history = new ReaderHistory(hatt);
//CREATE READER
ReaderAttributes ratt;
Locator_t loc(22222);
ratt.endpoint.unicastLocatorList.push_back(loc);
mp_reader = RTPSDomain::createRTPSReader(mp_participant,ratt,mp_history,&m_listener);
if(mp_reader == nullptr)
return false;
return true;
}
bool TestReaderRegistered::reg()
{
std::cout << "Registering Reader" << std::endl;
TopicAttributes Tatt;
Tatt.topicKind = NO_KEY;
Tatt.topicDataType = "string";
Tatt.topicName = "exampleTopic";
ReaderQos Rqos;
return mp_participant->registerReader(mp_reader, Tatt, Rqos);
}
void TestReaderRegistered::run()
{
printf("Press Enter to stop the Reader.\n");
std::cin.ignore();
}
void TestReaderRegistered::MyListener::onNewCacheChangeAdded(RTPSReader* reader,const CacheChange_t* const change)
{
printf("Received: %s\n",change->serializedPayload.data);
reader->getHistory()->remove_change((CacheChange_t*)change);
n_received++;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/RTPSTest_registered/Makefile | # 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.
CPP=g++
LN=g++
AR=ar
CP=cp
SYSLIBS= -ldl -lnsl -lm -lpthread -lrt
DEFINES=
COMMON_CFLAGS= -c -Wall -D__LITTLE_ENDIAN__ -std=c++11
## CHOOSE HERE BETWEEN 32 and 64 bit architecture
##32 BIT ARCH:
#COMMON_CFLAGS+= -m32 -fpic
#LDFLAGS=-m32
#64BIT ARCH:
COMMON_CFLAGS+= -m64 -fpic
LDFLAGS=-m64
CFLAGS = $(COMMON_CFLAGS) -O2
INCLUDES= -I.
LIBS = -lfastcdr -lfastrtps $(SYSLIBS)
DIRECTORIES= output.dir bin.dir
all: $(DIRECTORIES) RTPSTest_registered
RTPSTESTREGISTERED_TARGET= bin/RTPSTest_registered
RTPSTESTREGISTERED_SRC_CXXFILES=
RTPSTESTREGISTERED_SRC_CPPFILES= RTPSTest_registered/TestReaderRegistered.cpp \
RTPSTest_registered/TestWriterRegistered.cpp \
RTPSTest_registered/main_RTPSTest.cpp
# Project sources are copied to the current directory
RTPSTESTREGISTERED_SRCS= $(RTPSTESTREGISTERED_SRC_CXXFILES) $(RTPSTESTREGISTERED_SRC_CPPFILES)
# Source directories
RTPSTESTREGISTERED_SOURCES_DIRS_AUX= $(foreach srcdir, $(dir $(RTPSTESTREGISTERED_SRCS)), $(srcdir))
RTPSTESTREGISTERED_SOURCES_DIRS= $(shell echo $(RTPSTESTREGISTERED_SOURCES_DIRS_AUX) | tr " " "\n" | sort | uniq | tr "\n" " ")
RTPSTESTREGISTERED_OBJS = $(foreach obj,$(notdir $(addsuffix .o, $(RTPSTESTREGISTERED_SRCS))), output/$(obj))
RTPSTESTREGISTERED_DEPS = $(foreach dep,$(notdir $(addsuffix .d, $(RTPSTESTREGISTERED_SRCS))), output/$(dep))
OBJS+= $(RTPSTESTREGISTERED_OBJS)
DEPS+= $(RTPSTESTREGISTERED_DEPS)
RTPSTest_registered: $(RTPSTESTREGISTERED_TARGET)
$(RTPSTESTREGISTERED_TARGET): $(RTPSTESTREGISTERED_OBJS)
$(LN) $(LDFLAGS) -o $(RTPSTESTREGISTERED_TARGET) $(RTPSTESTREGISTERED_OBJS) $(LIBS)
vpath %.cxx $(RTPSTESTREGISTERED_SOURCES_DIRS)
vpath %.cpp $(RTPSTESTREGISTERED_SOURCES_DIRS)
output/%.cxx.o:%.cxx
@echo Calculating dependencies $<
@$(CC) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cxx.o=%.cxx.d)
@echo Compiling $<
@$(CC) $(CFLAGS) $(INCLUDES) $< -o $@
output/%.cpp.o:%.cpp
@echo Calculating dependencies $<
@$(CPP) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cpp.o=%.cpp.d)
@echo Compiling $<
@$(CPP) $(CFLAGS) $(INCLUDES) $< -o $@
.PHONY: RTPSTest_registered
clean:
@rm -f $(OBJS)
@rm -f $(DEPS)
ifneq ($(MAKECMDGOALS), clean)
-include $(DEPS)
endif
%.dir :
@echo "Checking directory $*"
@if [ ! -d $* ]; then \
echo "Making directory $*"; \
mkdir -p $* ; \
fi;
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/RTPSTest_registered/TestReaderRegistered.h | // 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 TestReaderRegistered.h
*
*/
#ifndef TESTREADERREGISTERED_H_
#define TESTREADERREGISTERED_H_
#include "fastrtps/rtps/rtps_fwd.h"
using namespace eprosima::fastrtps::rtps;
#include "fastrtps/rtps/reader/ReaderListener.h"
class TestReaderRegistered {
public:
TestReaderRegistered();
virtual ~TestReaderRegistered();
RTPSParticipant* mp_participant;
RTPSReader* mp_reader;
ReaderHistory* mp_history;
bool init(); //Initialization
bool reg(); //Register
void run(); //Run
class MyListener:public ReaderListener
{
public:
MyListener():n_received(0),n_matched(0){};
~MyListener(){};
void onNewCacheChangeAdded(RTPSReader* reader,const CacheChange_t* const change);
void onReaderMatched(RTPSReader* reader,MatchingInfo& info)
{
if(info.status == MATCHED_MATCHING) n_matched++;
};
uint32_t n_received;
uint32_t n_matched;
}m_listener;
};
#endif /* TESTREADER_H_ */
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/RTPSTest_registered/TestWriterRegistered.cpp | // 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 TestWriterRegistered.cpp
*
*/
#include "TestWriterRegistered.h"
#include "fastrtps/rtps/writer/RTPSWriter.h"
#include "fastrtps/rtps/participant/RTPSParticipant.h"
#include "fastrtps/rtps/RTPSDomain.h"
#include "fastrtps/rtps/attributes/RTPSParticipantAttributes.h"
#include "fastrtps/rtps/attributes/WriterAttributes.h"
#include "fastrtps/rtps/attributes/HistoryAttributes.h"
#include "fastrtps/rtps/history/WriterHistory.h"
#include "fastrtps/attributes/TopicAttributes.h"
#include "fastrtps/qos/WriterQos.h"
#include "fastrtps/utils/eClock.h"
using namespace eprosima;
using namespace fastrtps;
TestWriterRegistered::TestWriterRegistered():
mp_participant(nullptr),
mp_writer(nullptr),
mp_history(nullptr)
{
}
TestWriterRegistered::~TestWriterRegistered()
{
RTPSDomain::removeRTPSParticipant(mp_participant);
delete(mp_history);
}
bool TestWriterRegistered::init()
{
//CREATE PARTICIPANT
RTPSParticipantAttributes PParam;
PParam.builtin.use_SIMPLE_RTPSParticipantDiscoveryProtocol = true;
PParam.builtin.use_WriterLivelinessProtocol = true;
mp_participant = RTPSDomain::createParticipant(PParam);
if(mp_participant==nullptr)
return false;
//CREATE WRITERHISTORY
HistoryAttributes hatt;
hatt.payloadMaxSize = 255;
mp_history = new WriterHistory(hatt);
//CREATE WRITER
WriterAttributes watt;
mp_writer = RTPSDomain::createRTPSWriter(mp_participant,watt,mp_history,&m_listener);
if(mp_writer == nullptr)
return false;
return true;
}
bool TestWriterRegistered::reg()
{
cout << "Registering Writer" << endl;
TopicAttributes Tatt;
Tatt.topicKind = NO_KEY;
Tatt.topicDataType = "string";
Tatt.topicName = "exampleTopic";
WriterQos Wqos;
return mp_participant->registerWriter(mp_writer, Tatt, Wqos);
}
void TestWriterRegistered::run(uint16_t samples)
{
cout << "Waiting for matched Readers" << endl;
while (m_listener.n_matched==0)
{
eClock::my_sleep(250);
}
for(int i = 0;i<samples;++i )
{
CacheChange_t * ch = mp_writer->new_change([]() -> uint32_t { return 255;}, ALIVE);
#if defined(_WIN32)
ch->serializedPayload.length =
sprintf_s((char*)ch->serializedPayload.data,255, "My example string %d", i)+1;
#else
ch->serializedPayload.length =
sprintf((char*)ch->serializedPayload.data,"My example string %d",i)+1;
#endif
printf("Sending: %s\n",(char*)ch->serializedPayload.data);
mp_history->add_change(ch);
}
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/RTPSTest_registered/main_RTPSTest.cpp | // 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.
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <cstdint>
#include <sstream>
#include "fastrtps/log/Log.h"
#include "fastrtps/rtps/RTPSDomain.h"
#include "TestWriterRegistered.h"
#include "TestReaderRegistered.h"
using namespace eprosima;
using namespace fastrtps;
using namespace rtps;
using namespace std;
int main(int argc, char** argv){
cout << "Starting RTPS example" << endl;
int type;
if(argc > 1)
{
if(strcmp(argv[1],"writer")==0)
type = 1;
else if(strcmp(argv[1],"reader")==0)
type = 2;
else
{
cout << "NEEDS writer OR reader as first argument"<<endl;
return 0;
}
}
else
{
cout << "NEEDS writer OR reader ARGUMENT"<<endl;
cout << "RTPSTest writer"<<endl;
cout << "RTPSTest reader" <<endl;
return 0;
}
switch (type)
{
case 1:
{
TestWriterRegistered TW;
if(TW.init() && TW.reg())
TW.run(10);
break;
}
case 2:
{
TestReaderRegistered TR;
if(TR.init() && TR.reg())
TR.run();
break;
}
}
RTPSDomain::stopAll();
cout << "EVERYTHING STOPPED FINE"<<endl;
return 0;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/OwnershipStrengthQoSExample/OwnershipStrength.cxx | // 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 OwnershipStrength.cpp
* This source file contains the definition of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/
#ifdef _WIN32
// Remove linker warning LNK4221 on Visual Studio
namespace { char dummy; }
#endif
#include "OwnershipStrength.h"
#include <fastcdr/Cdr.h>
#include <fastcdr/exceptions/BadParamException.h>
using namespace eprosima::fastcdr::exception;
#include <utility>
ExampleMessage::ExampleMessage()
{
m_index = 0;
m_ownershipStrength = 0;
}
ExampleMessage::~ExampleMessage()
{
}
ExampleMessage::ExampleMessage(const ExampleMessage &x)
{
m_index = x.m_index;
m_ownershipStrength = x.m_ownershipStrength;
m_message = x.m_message;
}
ExampleMessage::ExampleMessage(ExampleMessage &&x)
{
m_index = x.m_index;
m_ownershipStrength = x.m_ownershipStrength;
m_message = std::move(x.m_message);
}
ExampleMessage& ExampleMessage::operator=(const ExampleMessage &x)
{
m_index = x.m_index;
m_ownershipStrength = x.m_ownershipStrength;
m_message = x.m_message;
return *this;
}
ExampleMessage& ExampleMessage::operator=(ExampleMessage &&x)
{
m_index = x.m_index;
m_ownershipStrength = x.m_ownershipStrength;
m_message = std::move(x.m_message);
return *this;
}
size_t ExampleMessage::getMaxCdrSerializedSize(size_t current_alignment)
{
size_t initial_alignment = current_alignment;
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1;
return current_alignment - initial_alignment;
}
size_t ExampleMessage::getCdrSerializedSize(const ExampleMessage& data, size_t current_alignment)
{
size_t initial_alignment = current_alignment;
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.message().size() + 1;
return current_alignment - initial_alignment;
}
void ExampleMessage::serialize(eprosima::fastcdr::Cdr &scdr) const
{
scdr << m_index;
scdr << m_ownershipStrength;
if(m_message.length() <= 255)
scdr << m_message;
else
throw eprosima::fastcdr::exception::BadParamException("message field exceeds the maximum length");
}
void ExampleMessage::deserialize(eprosima::fastcdr::Cdr &dcdr)
{
dcdr >> m_index;
dcdr >> m_ownershipStrength;
dcdr >> m_message;
}
size_t ExampleMessage::getKeyMaxCdrSerializedSize(size_t current_alignment)
{
size_t current_align = current_alignment;
return current_align;
}
bool ExampleMessage::isKeyDefined()
{
return false;
}
void ExampleMessage::serializeKey(eprosima::fastcdr::Cdr &scdr) const
{
} | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/OwnershipStrengthQoSExample/OwnershipStrengthPubSubMain.cxx | // 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 OwnershipStrengthPubSubMain.cpp
* This file acts as a main entry point to the application.
*
* This file was generated by the tool fastcdrgen.
*/
#include "OwnershipStrengthPublisher.h"
#include "OwnershipStrengthSubscriber.h"
#include <fastrtps/Domain.h>
#include <fastrtps/log/Log.h>
#include <sstream>
using namespace eprosima;
using namespace eprosima::fastrtps;
int main(int argc, char** argv)
{
std::cout << "Starting " << std::endl;
int type = 1;
if (argc > 1)
{
if (strcmp(argv[1], "publisher") == 0)
{
type = 1;
}
else if (strcmp(argv[1], "subscriber") == 0)
{
type = 2;
}
}
else
{
std::cout << "publisher OR subscriber argument needed" << std::endl;
return 0;
}
// Register the type being used
switch(type)
{
case 1:
{
OwnershipStrengthPublisher mypub;
// Takes an optional second parameter with the publisher ownership strength.
// If left out, will default to strength 10.
if (argc > 2)
{
std::stringstream ss(argv[2]);
int ownershipStrength;
ss >> ownershipStrength;
if (!ss.fail())
mypub.setOwnershipStrength(ownershipStrength);
}
if (mypub.init())
{
mypub.run();
}
break;
}
case 2:
{
OwnershipStrengthSubscriber mysub;
if (mysub.init())
{
mysub.run();
}
break;
}
}
Log::Reset();
return 0;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/OwnershipStrengthQoSExample/OwnershipStrengthPublisher.h | // 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 OwnershipStrengthPublisher.h
* This header file contains the declaration of the publisher functions.
*
* This file was generated by the tool fastcdrgen.
*/
#ifndef _OWNERSHIPTEST_PUBLISHER_H_
#define _OWNERSHIPTEST_PUBLISHER_H_
#include <fastrtps/fastrtps_fwd.h>
#include <fastrtps/publisher/PublisherListener.h>
#include "OwnershipStrengthPubSubTypes.h"
using namespace eprosima::fastrtps;
class OwnershipStrengthPublisher
{
public:
OwnershipStrengthPublisher();
virtual ~OwnershipStrengthPublisher();
bool init();
void run();
void setOwnershipStrength(unsigned int strength);
private:
Participant *mp_participant;
Publisher *mp_publisher;
class PubListener : public PublisherListener
{
public:
PubListener() : n_matched(0){};
~PubListener(){};
void onPublicationMatched(Publisher* pub,MatchingInfo& info);
int n_matched;
} m_listener;
ExampleMessagePubSubType myType;
// Keeps an ownership strength value that will be appended to each message.
unsigned int m_strength;
unsigned int m_messagesSent;
static const unsigned int DefaultStrength = 10;
};
#endif // _OWNERSHIPTEST_PUBLISHER_H_
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/OwnershipStrengthQoSExample/CMakeLists.txt | # 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.
cmake_minimum_required(VERSION 2.8.12)
project("OwnershipStrengthQoSExample")
# Find requirements
find_package(fastcdr REQUIRED)
find_package(fastrtps REQUIRED)
# Set C++11
include(CheckCXXCompilerFlag)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_cxx_compiler_flag(--std=c++11 SUPPORTS_CXX11)
if(SUPPORTS_CXX11)
add_compile_options(--std=c++11)
else()
message(FATAL_ERROR "Compiler doesn't support C++11")
endif()
endif()
message(STATUS "Configuring OwnershipStrengthQoS example...")
file(GLOB OWNERSHIPSTRENGTH_EXAMPLE_SOURCES "*.cxx")
add_executable(OwnershipStrengthQoSExample ${OWNERSHIPSTRENGTH_EXAMPLE_SOURCES})
target_link_libraries(OwnershipStrengthQoSExample fastrtps fastcdr)
install(TARGETS OwnershipStrengthQoSExample
RUNTIME DESTINATION examples/C++/OwnershipStrengthQoSExample/${BIN_INSTALL_DIR}
)
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/OwnershipStrengthQoSExample/OwnershipStrengthPubSubTypes.cxx | // 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 OwnershipStrengthPubSubTypes.cpp
* This header file contains the implementation of the serialization functions.
*
* This file was generated by the tool fastcdrgen.
*/
#include <fastcdr/FastBuffer.h>
#include <fastcdr/Cdr.h>
#include "OwnershipStrengthPubSubTypes.h"
ExampleMessagePubSubType::ExampleMessagePubSubType() {
setName("ExampleMessage");
m_typeSize = (uint32_t)ExampleMessage::getMaxCdrSerializedSize() + 4 /*encapsulation*/;
m_isGetKeyDefined = ExampleMessage::isKeyDefined();
m_keyBuffer = (unsigned char*)malloc(ExampleMessage::getKeyMaxCdrSerializedSize()>16 ? ExampleMessage::getKeyMaxCdrSerializedSize() : 16);
}
ExampleMessagePubSubType::~ExampleMessagePubSubType() {
if(m_keyBuffer!=nullptr)
free(m_keyBuffer);
}
bool ExampleMessagePubSubType::serialize(void *data, SerializedPayload_t *payload) {
ExampleMessage *p_type = (ExampleMessage*) data;
eprosima::fastcdr::FastBuffer fastbuffer((char*) payload->data, payload->max_size); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);
payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
// Serialize encapsulation
ser.serialize_encapsulation();
p_type->serialize(ser); // Serialize the object:
payload->length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length
return true;
}
bool ExampleMessagePubSubType::deserialize(SerializedPayload_t* payload, void* data) {
ExampleMessage* p_type = (ExampleMessage*) data; //Convert DATA to pointer of your type
eprosima::fastcdr::FastBuffer fastbuffer((char*)payload->data, payload->length); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR); // Object that deserializes the data.
// Deserialize encapsulation.
deser.read_encapsulation();
payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
p_type->deserialize(deser); //Deserialize the object:
return true;
}
std::function<uint32_t()> ExampleMessagePubSubType::getSerializedSizeProvider(void* data) {
return [data]() -> uint32_t {
return (uint32_t)type::getCdrSerializedSize(*static_cast<ExampleMessage*>(data)) + 4 /*encapsulation*/;
};
}
void* ExampleMessagePubSubType::createData() {
return (void*)new ExampleMessage();
}
void ExampleMessagePubSubType::deleteData(void* data) {
delete((ExampleMessage*)data);
}
bool ExampleMessagePubSubType::getKey(void *data, InstanceHandle_t* handle) {
if(!m_isGetKeyDefined)
return false;
ExampleMessage* p_type = (ExampleMessage*) data;
eprosima::fastcdr::FastBuffer fastbuffer((char*)m_keyBuffer,ExampleMessage::getKeyMaxCdrSerializedSize()); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); // Object that serializes the data.
p_type->serializeKey(ser);
if(ExampleMessage::getKeyMaxCdrSerializedSize()>16) {
m_md5.init();
m_md5.update(m_keyBuffer,(unsigned int)ser.getSerializedDataLength());
m_md5.finalize();
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_md5.digest[i];
}
}
else {
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_keyBuffer[i];
}
}
return true;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/OwnershipStrengthQoSExample/OwnershipStrengthPublisher.cxx | // 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 OwnershipStrengthPublisher.cpp
* This file contains the implementation of the publisher functions.
*
* This file was generated by the tool fastcdrgen.
*/
#include <fastrtps/participant/Participant.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/publisher/Publisher.h>
#include <fastrtps/attributes/PublisherAttributes.h>
#include <fastrtps/Domain.h>
#include <fastrtps/utils/eClock.h>
#include <sstream>
#include "OwnershipStrengthPublisher.h"
OwnershipStrengthPublisher::OwnershipStrengthPublisher()
:mp_participant(nullptr),
mp_publisher(nullptr),
m_strength(DefaultStrength)
{}
OwnershipStrengthPublisher::~OwnershipStrengthPublisher() { Domain::removeParticipant(mp_participant);}
void OwnershipStrengthPublisher::setOwnershipStrength(unsigned int strength)
{
m_strength = strength;
}
bool OwnershipStrengthPublisher::init()
{
// Create RTPSParticipant
ParticipantAttributes PParam;
PParam.rtps.builtin.domainId = 0;
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
PParam.rtps.setName("Participant_publisher");
mp_participant = Domain::createParticipant(PParam);
if(mp_participant == nullptr)
return false;
//Register the type
Domain::registerType(mp_participant,(TopicDataType*) &myType);
// Create Publisher
PublisherAttributes Wparam;
Wparam.topic.topicKind = NO_KEY;
Wparam.topic.topicDataType = myType.getName(); //This type MUST be registered
Wparam.topic.topicName = "OwnershipStrengthPubSubTopic";
mp_publisher = Domain::createPublisher(mp_participant,Wparam,(PublisherListener*)&m_listener);
if(mp_publisher == nullptr)
return false;
std::cout << "Publisher created, waiting for Subscribers." << std::endl;
return true;
}
void OwnershipStrengthPublisher::PubListener::onPublicationMatched(Publisher* /*pub*/,MatchingInfo& info)
{
if (info.status == MATCHED_MATCHING)
{
n_matched++;
std::cout << "Publisher matched" << std::endl;
}
else
{
n_matched--;
std::cout << "Publisher unmatched" << std::endl;
}
}
void OwnershipStrengthPublisher::run()
{
while(m_listener.n_matched == 0)
{
eClock::my_sleep(250); // Sleep 250 ms
}
char ch = 'y';
do
{
if(ch == 'y')
{
ExampleMessage st;
std::stringstream ss;
ss << "Hello with strength " << m_strength;
st.message(ss.str());
st.ownershipStrength(m_strength);
st.index(m_messagesSent);
mp_publisher->write(&st);
m_messagesSent++;
std::cout << "Sending message, index = " << m_messagesSent << " with strength " << m_strength << ", send another sample?(y-yes,n-stop): ";
}
else if(ch == 'n')
{
std::cout << "Stopping execution " << std::endl;
break;
}
else
{
std::cout << "Command " << ch << " not recognized, please enter \"y/n\":";
}
} while(std::cin >> ch);
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/OwnershipStrengthQoSExample/OwnershipStrength.idl | struct ExampleMessage
{
unsigned long index;
unsigned long ownershipStrength;
string message;
};
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/OwnershipStrengthQoSExample/Makefile | # 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.
CPP=g++
LN=g++
AR=ar
CP=cp
SYSLIBS= -ldl -lnsl -lm -lpthread -lrt
DEFINES=
COMMON_CFLAGS= -c -Wall -D__LITTLE_ENDIAN__ -std=c++11
## CHOOSE HERE BETWEEN 32 and 64 bit architecture
##32 BIT ARCH:
#COMMON_CFLAGS+= -m32 -fpic
#LDFLAGS=-m32
#64BIT ARCH:
COMMON_CFLAGS+= -m64 -fpic
LDFLAGS=-m64
CFLAGS = $(COMMON_CFLAGS) -O2
INCLUDES= -I.
LIBS = -lfastcdr -lfastrtps $(SYSLIBS)
DIRECTORIES= output.dir bin.dir
all: $(DIRECTORIES) OwnershipStrengthQoSExample
OWNERSHIPSTRENGTHQOSEXAMPLE_TARGET= bin/OwnershipStrengthQoSExample
OWNERSHIPSTRENGTHQOSEXAMPLE_SRC_CXXFILES=
OWNERSHIPSTRENGTHQOSEXAMPLE_SRC_CPPFILES= OwnershipStrengthQoSExample/OwnershipStrength.cxx \
OwnershipStrengthQoSExample/OwnershipStrengthPubSubTypes.cxx \
OwnershipStrengthQoSExample/OwnershipStrengthPublisher.cxx \
OwnershipStrengthQoSExample/OwnershipStrengthSubscriber.cxx \
OwnershipStrengthQoSExample/OwnershipStrengthPubSubMain.cxx \
# Project sources are copied to the current directory
OWNERSHIPSTRENGTHQOSEXAMPLE_SRCS= $(OWNERSHIPSTRENGTHQOSEXAMPLE_SRC_CXXFILES) $(OWNERSHIPSTRENGTHQOSEXAMPLE_SRC_CPPFILES)
# Source directories
OWNERSHIPSTRENGTHQOSEXAMPLE_SOURCES_DIRS_AUX= $(foreach srcdir, $(dir $(OWNERSHIPSTRENGTHQOSEXAMPLE_SRCS)), $(srcdir))
OWNERSHIPSTRENGTHQOSEXAMPLE_SOURCES_DIRS= $(shell echo $(OWNERSHIPSTRENGTHQOSEXAMPLE_SOURCES_DIRS_AUX) | tr " " "\n" | sort | uniq | tr "\n" " ")
OWNERSHIPSTRENGTHQOSEXAMPLE_OBJS = $(foreach obj,$(notdir $(addsuffix .o, $(OWNERSHIPSTRENGTHQOSEXAMPLE_SRCS))), output/$(obj))
OWNERSHIPSTRENGTHQOSEXAMPLE_DEPS = $(foreach dep,$(notdir $(addsuffix .d, $(OWNERSHIPSTRENGTHQOSEXAMPLE_SRCS))), output/$(dep))
OBJS+= $(OWNERSHIPSTRENGTHQOSEXAMPLE_OBJS)
DEPS+= $(OWNERSHIPSTRENGTHQOSEXAMPLE_DEPS)
OwnershipStrengthQoSExample: $(OWNERSHIPSTRENGTHQOSEXAMPLE_TARGET)
$(OWNERSHIPSTRENGTHQOSEXAMPLE_TARGET): $(OWNERSHIPSTRENGTHQOSEXAMPLE_OBJS)
$(LN) $(LDFLAGS) -o $(OWNERSHIPSTRENGTHQOSEXAMPLE_TARGET) $(OWNERSHIPSTRENGTHQOSEXAMPLE_OBJS) $(LIBS)
vpath %.cxx $(OWNERSHIPSTRENGTHQOSEXAMPLE_SOURCES_DIRS)
vpath %.cpp $(OWNERSHIPSTRENGTHQOSEXAMPLE_SOURCES_DIRS)
output/%.cxx.o:%.cxx
@echo Calculating dependencies $<
@$(CC) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cxx.o=%.cxx.d)
@echo Compiling $<
@$(CC) $(CFLAGS) $(INCLUDES) $< -o $@
output/%.cpp.o:%.cpp
@echo Calculating dependencies $<
@$(CPP) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cpp.o=%.cpp.d)
@echo Compiling $<
@$(CPP) $(CFLAGS) $(INCLUDES) $< -o $@
.PHONY: OwnershipStrengthQoSExample
clean:
@rm -f $(OBJS)
@rm -f $(DEPS)
ifneq ($(MAKECMDGOALS), clean)
-include $(DEPS)
endif
%.dir :
@echo "Checking directory $*"
@if [ ! -d $* ]; then \
echo "Making directory $*"; \
mkdir -p $* ; \
fi;
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/OwnershipStrengthQoSExample/OwnershipStrengthPubSubTypes.h | // 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 OwnershipStrengthPubSubTypes.h
* This header file contains the declaration of the serialization functions.
*
* This file was generated by the tool fastcdrgen.
*/
#ifndef _OWNERSHIPSTRENGTH_PUBSUBTYPES_H_
#define _OWNERSHIPSTRENGTH_PUBSUBTYPES_H_
#include <fastrtps/TopicDataType.h>
using namespace eprosima::fastrtps;
#include "OwnershipStrength.h"
/*!
* @brief This class represents the TopicDataType of the type ExampleMessage defined by the user in the IDL file.
* @ingroup OWNERSHIPSTRENGTH
*/
class ExampleMessagePubSubType : public TopicDataType {
public:
typedef ExampleMessage type;
ExampleMessagePubSubType();
virtual ~ExampleMessagePubSubType();
bool serialize(void *data, SerializedPayload_t *payload);
bool deserialize(SerializedPayload_t *payload, void *data);
std::function<uint32_t()> getSerializedSizeProvider(void* data);
bool getKey(void *data, InstanceHandle_t *ihandle);
void* createData();
void deleteData(void * data);
MD5 m_md5;
unsigned char* m_keyBuffer;
};
#endif // _OwnershipStrength_PUBSUBTYPE_H_ | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/OwnershipStrengthQoSExample/OwnershipStrengthSubscriber.cxx | // 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 OwnershipStrengthSubscriber.cpp
* This file contains the implementation of the subscriber functions.
*
* This file was generated by the tool fastcdrgen.
*/
#include <fastrtps/participant/Participant.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/subscriber/Subscriber.h>
#include <fastrtps/attributes/SubscriberAttributes.h>
#include <fastrtps/Domain.h>
#include "OwnershipStrengthSubscriber.h"
#include <algorithm>
OwnershipStrengthSubscriber::OwnershipStrengthSubscriber() : mp_participant(nullptr), mp_subscriber(nullptr) {}
OwnershipStrengthSubscriber::~OwnershipStrengthSubscriber() { Domain::removeParticipant(mp_participant);}
bool OwnershipStrengthSubscriber::init()
{
ParticipantAttributes PParam;
PParam.rtps.builtin.domainId = 0; //MUST BE THE SAME AS IN THE PUBLISHER
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
PParam.rtps.setName("Participant_subscriber"); //You can put the name you want
mp_participant = Domain::createParticipant(PParam);
if(mp_participant == nullptr)
return false;
//Register the type
Domain::registerType(mp_participant,(TopicDataType*) &myType);
// Create Subscriber
SubscriberAttributes Rparam;
Rparam.topic.topicKind = NO_KEY;
Rparam.topic.topicDataType = myType.getName(); //Must be registered before the creation of the subscriber
Rparam.topic.topicName = "OwnershipStrengthPubSubTopic";
Rparam.qos.m_reliability.kind = eprosima::fastrtps::RELIABLE_RELIABILITY_QOS;
mp_subscriber = Domain::createSubscriber(mp_participant,Rparam,(SubscriberListener*)&m_listener);
if(mp_subscriber == nullptr)
return false;
return true;
}
void OwnershipStrengthSubscriber::SubListener::onSubscriptionMatched(Subscriber* /*sub*/,MatchingInfo& info)
{
if (info.status == MATCHED_MATCHING)
{
n_matched++;
std::cout << "Subscriber matched" << std::endl;
}
else
{
n_matched--;
std::cout << "Subscriber unmatched" << std::endl;
// Must deregister here to make sure messages from weaker publishers are accepted.
// It is also possible to deregister on a lost deadline, if applicable.
m_hierarchy.DeregisterPublisher(info.remoteEndpointGuid);
}
}
bool OwnershipStrengthSubscriber::StrengthHierarchy::IsMessageStrong(const ExampleMessage& st, const SampleInfo_t& info)
{
unsigned int ownershipStrength = st.ownershipStrength();
GUID_t guid = info.sample_identity.writer_guid();
mapMutex.lock();
// The strength-GUID pair is inserted in the strength hierarchy, if unique.
strengthMap[ownershipStrength].insert(guid);
// The set of strongest writers is extracted from the back of the map (highest strength)
std::set<GUID_t>& strongestWriters = strengthMap.rbegin()->second;
// The prioritised writer is arbitrarily chosen as the one with the lowest GUID, in case of a tie.
const GUID_t& prioritisedStrongestWriter = *(strongestWriters.begin());
bool strong = (guid == prioritisedStrongestWriter);
mapMutex.unlock();
if (!strong)
std::cout << "Weak message received and discarded (strength " << ownershipStrength << ")" << std::endl;
return strong;
}
void OwnershipStrengthSubscriber::StrengthHierarchy::DeregisterPublisher(GUID_t guid)
{
mapMutex.lock();
// We walk through the hierarchy and remove the publisher GUID
for (auto &guidSet : strengthMap)
guidSet.second.erase(guid);
mapMutex.unlock();
}
void OwnershipStrengthSubscriber::SubListener::onNewDataMessage(Subscriber* sub)
{
// Take data
ExampleMessage st;
if(sub->takeNextData(&st, &m_info) &&
m_info.sampleKind == ALIVE &&
m_hierarchy.IsMessageStrong(st, m_info))
{
// User message handling here, for a strong message
++n_msg;
std::cout << "Message received with index " << n_msg << ", and strength " << st.ownershipStrength() \
<< ", reading \"" << st.message() << "\"" << std::endl;
}
}
void OwnershipStrengthSubscriber::run()
{
std::cout << "Waiting for Data, press Enter to stop the Subscriber. "<<std::endl;
std::cin.ignore();
std::cout << "Shutting down the Subscriber." << std::endl;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/OwnershipStrengthQoSExample/OwnershipStrengthSubscriber.h | // 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 OwnershipStrengthSubscriber.h
* This header file contains the declaration of the subscriber functions.
*
* This file was generated by the tool fastcdrgen.
*/
#ifndef _OWNERSHIPTEST_SUBSCRIBER_H_
#define _OWNERSHIPTEST_SUBSCRIBER_H_
#include <fastrtps/fastrtps_fwd.h>
#include <fastrtps/subscriber/SubscriberListener.h>
#include <fastrtps/subscriber/SampleInfo.h>
#include "OwnershipStrengthPubSubTypes.h"
#include <set>
#include <mutex>
#include <map>
using namespace eprosima::fastrtps;
class OwnershipStrengthSubscriber
{
public:
OwnershipStrengthSubscriber();
virtual ~OwnershipStrengthSubscriber();
bool init();
void run();
private:
Participant *mp_participant;
Subscriber *mp_subscriber;
class StrengthHierarchy
{
public:
// Automatically adds a publisher to the hierarchy, and reports back whether it is the strongest.
bool IsMessageStrong(const ExampleMessage& st, const SampleInfo_t& info);
// Deregisters a publisher removing it from the hierarchy.
void DeregisterPublisher(GUID_t guid);
// Provides an ordered hierarchy of publishers, based on the Ownership Strength QoS parameter.
std::map<unsigned int, std::set<GUID_t> > strengthMap; // Keyed by Ownership Strength
std::mutex mapMutex;
};
class SubListener : public SubscriberListener
{
public:
SubListener() : n_matched(0),n_msg(0){};
~SubListener(){};
void onSubscriptionMatched(Subscriber* sub,MatchingInfo& info);
void onNewDataMessage(Subscriber* sub);
SampleInfo_t m_info;
int n_matched;
int n_msg;
StrengthHierarchy m_hierarchy;
} m_listener;
ExampleMessagePubSubType myType;
};
#endif // _OwnershipStrength_SUBSCRIBER_H_
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/OwnershipStrengthQoSExample/README.txt | To launch this test open two or more consoles:
1) "$OwnershipStrengthQosExample subscriber"
(or "OwnershipStrengthQosExample.exe subscriber" on Windows).
2..*) "$OwnershipStrengthQosExample publisher XX"
(or "OwnershipStrengthQosExample.exe publisher XX" on Windows).
For the publishers, XX represents an Ownership Strength QoS number.
If left unspecified it will default to 10.
This example illustrates a user-level implementation of the Ownership Strength
quality of service. Inbound messages will be filtered based on their ownership
strength, so only one publisher will be allowed per topic until unmatched. The
behaviour is implemented as follows:
===============
== BEHAVIOUR ==
===============
The IDL file (OwnershipStrength.idl) defines a message type with an
ownership strength field. This field will be read by the subscriber and used
to decide whether or not a message must be processed at any given time.
OwnershipStrengthPublisher incorporates a method to define its ownership strength.
This value will be propagated to any messages sent from this publisher. The
ability to set this value is exposed through the command line as mentioned
above.
OwnershipStrengthSubscriber presents the most significant change from a default
example. Its SubscriberListener includes a field of type StrengthHierarchy.
StrengthHierarchy encapsulates a map of publishers classified by their strength,
and offers a simple API encompassing two functionalities:
* Checking whether a particular message belongs to the publisher currently
considered strongest (while implicitly registering said publisher on the
hierarchy).
* Explicitly removing a particular publisher from the hierarchy.
Whenever the subscriber receives a message, it will call "IsMessageStrong" on it,
automatically starting to keep track of the publisher that originally sent it.
This and subsequent calls to IsMessageStrong will return true if the publisher
associated with the message has the highest strength value among all registered
publishers, or in case of a tie, the lowest GUID. This return value is used to
choose whether to process the message.
The listener is responsible of explicitly removing a publisher from the hierarchy
during the unmatching process, through a call to the "DeregisterPublisher" method.
Other criteria for de-registration may also be included if desired, for example
on a lost deadline.
Internally, the strength hierarchy makes use of the ordering properties of std::map
to provide quick access to the maximum strength value, and is made thread-safe by
a C++11 mutex.
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/OwnershipStrengthQoSExample/OwnershipStrength.h | // 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 OwnershipStrength.h
* This header file contains the declaration of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/
#ifndef _OwnershipStrength_H_
#define _OwnershipStrength_H_
// TODO Poner en el contexto.
#include <stdint.h>
#include <array>
#include <string>
#include <vector>
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#define eProsima_user_DllExport __declspec( dllexport )
#else
#define eProsima_user_DllExport
#endif
#else
#define eProsima_user_DllExport
#endif
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#if defined(OwnershipStrength_SOURCE)
#define OwnershipStrength_DllAPI __declspec( dllexport )
#else
#define OwnershipStrength_DllAPI __declspec( dllimport )
#endif // OwnershipStrength_SOURCE
#else
#define OwnershipStrength_DllAPI
#endif
#else
#define OwnershipStrength_DllAPI
#endif // _WIN32
namespace eprosima
{
namespace fastcdr
{
class Cdr;
}
}
/*!
* @brief This class represents the structure ExampleMessage defined by the user in the IDL file.
* @ingroup OWNERSHIPSTRENGTH
*/
class ExampleMessage
{
public:
/*!
* @brief Default constructor.
*/
eProsima_user_DllExport ExampleMessage();
/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~ExampleMessage();
/*!
* @brief Copy constructor.
* @param x Reference to the object ExampleMessage that will be copied.
*/
eProsima_user_DllExport ExampleMessage(const ExampleMessage &x);
/*!
* @brief Move constructor.
* @param x Reference to the object ExampleMessage that will be copied.
*/
eProsima_user_DllExport ExampleMessage(ExampleMessage &&x);
/*!
* @brief Copy assignment.
* @param x Reference to the object ExampleMessage that will be copied.
*/
eProsima_user_DllExport ExampleMessage& operator=(const ExampleMessage &x);
/*!
* @brief Move assignment.
* @param x Reference to the object ExampleMessage that will be copied.
*/
eProsima_user_DllExport ExampleMessage& operator=(ExampleMessage &&x);
/*!
* @brief This function sets a value in member index
* @param _index New value for member index
*/
inline 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
*/
inline eProsima_user_DllExport uint32_t index() const
{
return m_index;
}
/*!
* @brief This function returns a reference to member index
* @return Reference to member index
*/
inline eProsima_user_DllExport uint32_t& index()
{
return m_index;
}
/*!
* @brief This function sets a value in member ownershipStrength
* @param _ownershipStrength New value for member ownershipStrength
*/
inline eProsima_user_DllExport void ownershipStrength(uint32_t _ownershipStrength)
{
m_ownershipStrength = _ownershipStrength;
}
/*!
* @brief This function returns the value of member ownershipStrength
* @return Value of member ownershipStrength
*/
inline eProsima_user_DllExport uint32_t ownershipStrength() const
{
return m_ownershipStrength;
}
/*!
* @brief This function returns a reference to member ownershipStrength
* @return Reference to member ownershipStrength
*/
inline eProsima_user_DllExport uint32_t& ownershipStrength()
{
return m_ownershipStrength;
}
/*!
* @brief This function copies the value in member message
* @param _message New value to be copied in member message
*/
inline eProsima_user_DllExport void message(const std::string &_message)
{
m_message = _message;
}
/*!
* @brief This function moves the value in member message
* @param _message New value to be moved in member message
*/
inline eProsima_user_DllExport void message(std::string &&_message)
{
m_message = std::move(_message);
}
/*!
* @brief This function returns a constant reference to member message
* @return Constant reference to member message
*/
inline eProsima_user_DllExport const std::string& message() const
{
return m_message;
}
/*!
* @brief This function returns a reference to member message
* @return Reference to member message
*/
inline eProsima_user_DllExport std::string& message()
{
return m_message;
}
/*!
* @brief This function returns the maximum serialized size of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getMaxCdrSerializedSize(size_t current_alignment = 0);
/*!
* @brief This function returns the serialized size of a data depending on the buffer alignment.
* @param data Data which is calculated its serialized size.
* @param current_alignment Buffer alignment.
* @return Serialized size.
*/
eProsima_user_DllExport static size_t getCdrSerializedSize(const ExampleMessage& data, size_t current_alignment = 0);
/*!
* @brief This function serializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serialize(eprosima::fastcdr::Cdr &cdr) const;
/*!
* @brief This function deserializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void deserialize(eprosima::fastcdr::Cdr &cdr);
/*!
* @brief This function returns the maximum serialized size of the Key of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize(size_t current_alignment = 0);
/*!
* @brief This function tells you if the Key has been defined for this type
*/
eProsima_user_DllExport static bool isKeyDefined();
/*!
* @brief This function serializes the key members of an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const;
private:
uint32_t m_index;
uint32_t m_ownershipStrength;
std::string m_message;
};
#endif // _OwnershipStrength_H_ | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/Configurability/CMakeLists.txt | # 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.
cmake_minimum_required(VERSION 2.8.12)
project("UseCaseDemonstrator")
# Find requirements
find_package(fastcdr REQUIRED)
find_package(fastrtps REQUIRED)
# Set C++11
include(CheckCXXCompilerFlag)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_cxx_compiler_flag(--std=c++11 SUPPORTS_CXX11)
if(SUPPORTS_CXX11)
add_compile_options(--std=c++11)
else()
message(FATAL_ERROR "Compiler doesn't support C++11")
endif()
endif()
message(STATUS "Configuring UseCaseDemonstrator example...")
file(GLOB USECASEDEMONSTRATOR_EXAMPLE_SOURCES "*.cxx")
add_executable(UseCasePublisher ${USECASEDEMONSTRATOR_EXAMPLE_SOURCES} UseCasePublisher.cpp)
target_link_libraries(UseCasePublisher fastrtps fastcdr)
install(TARGETS UseCasePublisher
RUNTIME DESTINATION examples/C++/UseCaseDemonstrator/${BIN_INSTALL_DIR}
)
add_executable(UseCaseSubscriber ${USECASEDEMONSTRATOR_EXAMPLE_SOURCES} UseCaseSubscriber.cpp)
target_link_libraries(UseCaseSubscriber fastrtps fastcdr)
install(TARGETS UseCaseSubscriber
RUNTIME DESTINATION examples/C++/UseCaseDemonstrator/${BIN_INSTALL_DIR}
)
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/Configurability/samplePubSubTypes.h | // 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 samplePubSubTypes.h
* This header file contains the declaration of the serialization functions.
*
* This file was generated by the tool fastcdrgen.
*/
#ifndef _SAMPLE_PUBSUBTYPES_H_
#define _SAMPLE_PUBSUBTYPES_H_
#include <fastrtps/TopicDataType.h>
using namespace eprosima::fastrtps;
#include "sample.h"
/*!
* @brief This class represents the TopicDataType of the type sample defined by the user in the IDL file.
* @ingroup SAMPLE
*/
class samplePubSubType : public TopicDataType {
public:
typedef sample type;
samplePubSubType();
virtual ~samplePubSubType();
bool serialize(void *data, SerializedPayload_t *payload);
bool deserialize(SerializedPayload_t *payload, void *data);
std::function<uint32_t()> getSerializedSizeProvider(void* data);
bool getKey(void *data, InstanceHandle_t *ihandle);
void* createData();
void deleteData(void * data);
MD5 m_md5;
unsigned char* m_keyBuffer;
};
#endif // _sample_PUBSUBTYPE_H_ | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/Configurability/UseCaseLauncher.cpp | /***
* Use Case Demonstrator for eProsima Fast RTPS
* --------------------------------------------
*
* This is an interactive program designed to show the effect of different configuration parameters on the behaviour of eProsima Fast RTPS
*
***/
#include <iostream>
#include <string>
#include <fastrtps/participant/Participant.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/subscriber/Subscriber.h>
#include <fastrtps/attributes/SubscriberAttributes.h>
#include <fastrtps/publisher/Publisher.h>
#include <fastrtps/attributes/PublisherAttributes.h>
#include <fastrtps/Domain.h>
#include <fastrtps/subscriber/SampleInfo.h>
#include <fastrtps/utils/eClock.h>
#include "samplePubSubTypes.h"
//Enums and configuration structure
enum Reliability_type { Best_Effort, Reliable };
enum Durability_type { Transient_Local, Volatile };
enum HistoryKind_type { Keep_Last, Keep_All };
enum Key_type { No_Key, With_Key};
typedef struct{
Reliability_type reliability;
Durability_type durability;
HistoryKind_type historykind;
Key_type keys;
uint16_t history_size;
uint8_t depth;
uint8_t no_keys;
uint16_t max_samples_per_key;
} example_configuration;
void pastsamples();
void latejoiners();
void keys();
void incompatible();
void safest();
void fastest();
void triggers();
int main(){
bool validinput;
std::string userchoice;
std::cout << "Welcome to eProsima Fast RTPS Use Case Demonstrator" << std::endl;
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "Choose your example:" << std::endl;
std::cout << " 1 - Past samples storage" << std::endl;
std::cout << " 2 - Late Joiners" << std::endl;
std::cout << " 3 - Keys" << std::endl;
std::cout << " 4 - Incompatible configuration" << std::endl;
std::cout << " 5 - Sample configuration: Safest" << std::endl;
std::cout << " 6 - Sample configuration: Fastest" << std::endl;
std::cout << " 7 - Sample configuration: Triggers" << std::endl;
std::cout << "Make your choice (1 to 7, q to quit): ";
validinput = false;
while(!validinput){
std::cin >> userchoice;
if(userchoice == std::string("q"))
return 0;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
validinput=true;
std::cout << "---------------------------------------------------" << std::endl;
switch(choice){
case 1:
pastsamples();
break;
case 2:
latejoiners();
break;
case 3:
keys();
break;
case 4:
incompatible();
break;
case 5:
safest();
break;
case 6:
fastest();
break;
case 7:
triggers();
break;
default:
validinput = false;
std::cout << "Please enter a valid option" << std::endl;
break;
}
}
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "Exiting..." << std::endl;
return 0;
}
void latejoiners(){
samplePubSubType sampleType;
sample my_sample;
SampleInfo_t sample_info;
ParticipantAttributes PparamPub;
PparamPub.rtps.builtin.domainId = 0;
PparamPub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamPub.rtps.setName("PublisherParticipant");
Participant *PubParticipant = Domain::createParticipant(PparamPub);
if(PubParticipant == nullptr){
std::cout << " Something went wrong while creating the Publisher Participant..." << std::endl;
return;
}
Domain::registerType(PubParticipant,(TopicDataType*) &sampleType);
//Publisher config
PublisherAttributes Pparam;
Pparam.topic.topicDataType = sampleType.getName();
Pparam.topic.topicName = "samplePubSubTopic";
Pparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Pparam.topic.topicKind = NO_KEY;
Pparam.topic.historyQos.kind = KEEP_ALL_HISTORY_QOS;
Pparam.qos.m_durability.kind = TRANSIENT_LOCAL_DURABILITY_QOS;
Pparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Pparam.topic.historyQos.depth = 50;
Pparam.topic.resourceLimitsQos.max_samples = 100;
Pparam.topic.resourceLimitsQos.max_instances = 1;
Pparam.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Publisher..." << std::endl;
Publisher *myPub= Domain::createPublisher(PubParticipant, Pparam, nullptr);
if(myPub == nullptr){
std::cout << "Something went wrong while creating the Publisher..." << std::endl;
return;
}
//Send 20 samples
std::cout << "Publishing 20 samples on the topic" << std::endl;
for(uint8_t j=0; j < 20; j++){
my_sample.index(j+1);
my_sample.key_value(1);
myPub->write(&my_sample);
}
eClock::my_sleep(1500);
ParticipantAttributes PparamSub;
PparamSub.rtps.builtin.domainId = 0;
PparamSub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamSub.rtps.setName("SubscriberParticipant");
Participant *SubParticipant = Domain::createParticipant(PparamSub);
if(SubParticipant == nullptr){
std::cout << " Something went wrong while creating the Subscriber Participant..." << std::endl;
return;
}
Domain::registerType(SubParticipant,(TopicDataType*) &sampleType);
//Transient Local Sub
SubscriberAttributes Rparam;
Rparam.topic.topicDataType = sampleType.getName();
Rparam.topic.topicName = "samplePubSubTopic";
Rparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Rparam.topic.topicKind = NO_KEY;
Rparam.topic.historyQos.kind = KEEP_ALL_HISTORY_QOS;
Rparam.qos.m_durability.kind = TRANSIENT_LOCAL_DURABILITY_QOS;
Rparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Rparam.topic.historyQos.depth = 50;
Rparam.topic.resourceLimitsQos.max_samples = 100;
Rparam.topic.resourceLimitsQos.max_instances = 1;
Rparam.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Transient Local Subscriber..." << std::endl;
Subscriber *mySub1= Domain::createSubscriber(PubParticipant, Rparam, nullptr);
if(myPub == nullptr){
std::cout << "something went wrong while creating the Transient Local Subscriber..." << std::endl;
return;
}
//Volatile Sub
SubscriberAttributes Rparam2;
Rparam2.topic.topicDataType = sampleType.getName();
Rparam2.topic.topicName = "samplePubSubTopic";
Rparam2.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Rparam2.topic.topicKind = NO_KEY;
Rparam2.topic.historyQos.kind = KEEP_ALL_HISTORY_QOS;
Rparam2.qos.m_durability.kind = VOLATILE_DURABILITY_QOS;
Rparam2.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Rparam2.topic.historyQos.depth = 50;
Rparam2.topic.resourceLimitsQos.max_samples = 100;
Rparam2.topic.resourceLimitsQos.max_instances = 1;
Rparam2.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Volatile Subscriber..." << std::endl;
Subscriber *mySub2= Domain::createSubscriber(PubParticipant, Rparam2, nullptr);
if(myPub == nullptr){
std::cout << "something went wrong while creating the Volatile Subscriber..." << std::endl;
return;
}
//Send 20 samples
std::cout << "Publishing 20 samples on the topic..." << std::endl;
for(uint8_t j=0; j < 20; j++){
my_sample.index(j+21);
my_sample.key_value(1);
myPub->write(&my_sample);
}
eClock::my_sleep(1500);
//Read the contents of both histories:
std::cout << "The Transient Local Subscriber holds: " << std::endl;
while(mySub1->readNextData(&my_sample, &sample_info)){
std::cout << std::to_string(my_sample.index()) << " ";
}
std::cout << std::endl;
std::cout << "The Volatile Subscriber holds: " << std::endl;
while(mySub2->readNextData(&my_sample, &sample_info)){
std::cout << std::to_string(my_sample.index()) << " ";
}
std::cout << std::endl;
}
void pastsamples(){
samplePubSubType sampleType;
sample my_sample;
SampleInfo_t sample_info;
ParticipantAttributes PparamPub;
PparamPub.rtps.builtin.domainId = 0;
PparamPub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamPub.rtps.setName("PublisherParticipant");
Participant *PubParticipant = Domain::createParticipant(PparamPub);
if(PubParticipant == nullptr){
std::cout << " Something went wrong while creating the Publisher Participant..." << std::endl;
return;
}
Domain::registerType(PubParticipant,(TopicDataType*) &sampleType);
//Publisher config
PublisherAttributes Pparam;
Pparam.topic.topicDataType = sampleType.getName();
Pparam.topic.topicName = "samplePubSubTopic";
Pparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Pparam.topic.topicKind = NO_KEY;
Pparam.topic.historyQos.kind = KEEP_ALL_HISTORY_QOS;
Pparam.qos.m_durability.kind = TRANSIENT_LOCAL_DURABILITY_QOS;
Pparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Pparam.topic.historyQos.depth = 50;
Pparam.topic.resourceLimitsQos.max_samples = 100;
Pparam.topic.resourceLimitsQos.max_instances = 1;
Pparam.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Publisher..." << std::endl;
Publisher *myPub= Domain::createPublisher(PubParticipant, Pparam, nullptr);
if(myPub == nullptr){
std::cout << "Something went wrong while creating the Publisher..." << std::endl;
return;
}
ParticipantAttributes PparamSub;
PparamSub.rtps.builtin.domainId = 0;
PparamSub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamSub.rtps.setName("SubscriberParticipant");
Participant *SubParticipant = Domain::createParticipant(PparamSub);
if(SubParticipant == nullptr){
std::cout << " Something went wrong while creating the Subscriber Participant..." << std::endl;
return;
}
Domain::registerType(SubParticipant,(TopicDataType*) &sampleType);
//Keep All Sub
SubscriberAttributes Rparam;
Rparam.topic.topicDataType = sampleType.getName();
Rparam.topic.topicName = "samplePubSubTopic";
Rparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Rparam.topic.topicKind = NO_KEY;
Rparam.topic.historyQos.kind = KEEP_ALL_HISTORY_QOS;
Rparam.qos.m_durability.kind = VOLATILE_DURABILITY_QOS;
Rparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Rparam.topic.historyQos.depth = 50;
Rparam.topic.resourceLimitsQos.max_samples = 100;
Rparam.topic.resourceLimitsQos.max_instances = 1;
Rparam.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Keep All Subscriber..." << std::endl;
Subscriber *mySub1= Domain::createSubscriber(PubParticipant, Rparam, nullptr);
if(myPub == nullptr){
std::cout << "something went wrong while creating the Transient Local Subscriber..." << std::endl;
return;
}
//Keep Last
SubscriberAttributes Rparam2;
Rparam2.topic.topicDataType = sampleType.getName();
Rparam2.topic.topicName = "samplePubSubTopic";
Rparam2.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Rparam2.topic.topicKind = NO_KEY;
Rparam2.topic.historyQos.kind = KEEP_LAST_HISTORY_QOS;
Rparam2.qos.m_durability.kind = VOLATILE_DURABILITY_QOS;
Rparam2.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Rparam2.topic.historyQos.depth = 10;
Rparam2.topic.resourceLimitsQos.max_samples = 100;
Rparam2.topic.resourceLimitsQos.max_instances = 1;
Rparam2.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Keep Last Subscriber with depth 10..." << std::endl;
Subscriber *mySub2= Domain::createSubscriber(PubParticipant, Rparam2, nullptr);
if(myPub == nullptr){
std::cout << "something went wrong while creating the Volatile Subscriber..." << std::endl;
return;
}
//Send 20 samples
std::cout << "Publishing 20 samples on the topic..." << std::endl;
for(uint8_t j=0; j < 20; j++){
my_sample.index(j+1);
my_sample.key_value(1);
myPub->write(&my_sample);
}
eClock::my_sleep(1500);
//Read the contents of both histories:
std::cout << "The Keep All Subscriber holds: " << std::endl;
while(mySub1->readNextData(&my_sample, &sample_info)){
std::cout << std::to_string(my_sample.index()) << " ";
}
std::cout << std::endl;
std::cout << "The Keep Last (Depth 10) Subscriber holds: " << std::endl;
while(mySub2->readNextData(&my_sample, &sample_info)){
std::cout << std::to_string(my_sample.index()) << " ";
}
std::cout << std::endl;
}
void keys(){
samplePubSubType sampleType;
sample my_sample;
SampleInfo_t sample_info;
ParticipantAttributes PparamPub;
PparamPub.rtps.builtin.domainId = 0;
PparamPub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamPub.rtps.setName("PublisherParticipant");
Participant *PubParticipant = Domain::createParticipant(PparamPub);
if(PubParticipant == nullptr){
std::cout << " Something went wrong while creating the Publisher Participant..." << std::endl;
return;
}
Domain::registerType(PubParticipant,(TopicDataType*) &sampleType);
//Publisher config
PublisherAttributes Pparam;
Pparam.topic.topicDataType = sampleType.getName();
Pparam.topic.topicName = "samplePubSubTopic";
Pparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Pparam.topic.topicKind = WITH_KEY;
Pparam.topic.historyQos.kind = KEEP_ALL_HISTORY_QOS;
Pparam.qos.m_durability.kind = VOLATILE_DURABILITY_QOS;
Pparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Pparam.topic.historyQos.depth = 10;
Pparam.topic.resourceLimitsQos.max_samples = 50;
Pparam.topic.resourceLimitsQos.max_instances = 5;
Pparam.topic.resourceLimitsQos.max_samples_per_instance = 10;
std::cout << "Creating Publisher..." << std::endl;
Publisher *myPub= Domain::createPublisher(PubParticipant, Pparam, nullptr);
if(myPub == nullptr){
std::cout << "Something went wrong while creating the Publisher..." << std::endl;
return;
}
ParticipantAttributes PparamSub;
PparamSub.rtps.builtin.domainId = 0;
PparamSub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamSub.rtps.setName("SubscriberParticipant");
Participant *SubParticipant = Domain::createParticipant(PparamSub);
if(SubParticipant == nullptr){
std::cout << " Something went wrong while creating the Subscriber Participant..." << std::endl;
return;
}
Domain::registerType(SubParticipant,(TopicDataType*) &sampleType);
//Keep All Sub
SubscriberAttributes Rparam;
Rparam.topic.topicDataType = sampleType.getName();
Rparam.topic.topicName = "samplePubSubTopic";
Rparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Rparam.topic.topicKind = WITH_KEY;
Rparam.topic.historyQos.kind = KEEP_ALL_HISTORY_QOS;
Rparam.qos.m_durability.kind = VOLATILE_DURABILITY_QOS;
Rparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Rparam.topic.historyQos.depth = 10;
Rparam.topic.resourceLimitsQos.max_samples = 100;
Rparam.topic.resourceLimitsQos.max_instances = 5;
Rparam.topic.resourceLimitsQos.max_samples_per_instance = 20;
std::cout << "Creating Subscriber..." << std::endl;
Subscriber *mySub1= Domain::createSubscriber(PubParticipant, Rparam, nullptr);
if(myPub == nullptr){
std::cout << "Something went wrong while creating the Subscriber..." << std::endl;
return;
}
//Send 20 samples
std::cout << "Publishing 5 keys, 10 samples per key..." << std::endl;
for(uint8_t i=0; i < 5; i++){
for(uint8_t j=0; j < 20; j++){
my_sample.index(j+1);
my_sample.key_value(i+1);
myPub->write(&my_sample);
}
}
eClock::my_sleep(1500);
std::cout << "Publishing 10 more samples on a key 3..." << std::endl;
for(uint8_t j=0; j < 10; j++){
my_sample.index(j+11);
my_sample.key_value(3);
myPub->write(&my_sample);
}
eClock::my_sleep(1500);
//Read the contents of both histories:
std::vector< std::pair<int,int> > sampleList;
std::cout << "The Subscriber holds: " << std::endl;
while(mySub1->readNextData(&my_sample, &sample_info)){
sampleList.push_back(std::pair<int,int>(my_sample.index(),my_sample.key_value()));
}
for(int key=1;key<=5;key++){
std::cout << " On key " << std::to_string(key) << ": ";
for(std::pair<int,int> n : sampleList){
if(n.second == key)
std::cout << std::to_string(n.first) << " ";
}
std::cout << std::endl;
}
std::cout << std::endl;
}
void incompatible(){
samplePubSubType sampleType;
sample my_sample;
SampleInfo_t sample_info;
ParticipantAttributes PparamPub;
PparamPub.rtps.builtin.domainId = 0;
PparamPub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamPub.rtps.setName("PublisherParticipant");
Participant *PubParticipant = Domain::createParticipant(PparamPub);
if(PubParticipant == nullptr){
std::cout << " Something went wrong while creating the Publisher Participant..." << std::endl;
return;
}
Domain::registerType(PubParticipant,(TopicDataType*) &sampleType);
//Publisher config
PublisherAttributes Pparam;
Pparam.topic.topicDataType = sampleType.getName();
Pparam.topic.topicName = "samplePubSubTopic";
Pparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Pparam.topic.topicKind = NO_KEY;
Pparam.topic.historyQos.kind = KEEP_ALL_HISTORY_QOS;
Pparam.qos.m_durability.kind = TRANSIENT_LOCAL_DURABILITY_QOS;
Pparam.qos.m_reliability.kind = BEST_EFFORT_RELIABILITY_QOS;
Pparam.topic.historyQos.depth = 50;
Pparam.topic.resourceLimitsQos.max_samples = 100;
Pparam.topic.resourceLimitsQos.max_instances = 1;
Pparam.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Best-Effort Publisher..." << std::endl;
Publisher *myPub= Domain::createPublisher(PubParticipant, Pparam, nullptr);
if(myPub == nullptr){
std::cout << "Something went wrong while creating the Publisher..." << std::endl;
return;
}
ParticipantAttributes PparamSub;
PparamSub.rtps.builtin.domainId = 0;
PparamSub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamSub.rtps.setName("SubscriberParticipant");
Participant *SubParticipant = Domain::createParticipant(PparamSub);
if(SubParticipant == nullptr){
std::cout << " Something went wrong while creating the Subscriber Participant..." << std::endl;
return;
}
Domain::registerType(SubParticipant,(TopicDataType*) &sampleType);
//Reliable Sub
SubscriberAttributes Rparam;
Rparam.topic.topicDataType = sampleType.getName();
Rparam.topic.topicName = "samplePubSubTopic";
Rparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Rparam.topic.topicKind = NO_KEY;
Rparam.topic.historyQos.kind = KEEP_ALL_HISTORY_QOS;
Rparam.qos.m_durability.kind = VOLATILE_DURABILITY_QOS;
Rparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Rparam.topic.historyQos.depth = 50;
Rparam.topic.resourceLimitsQos.max_samples = 100;
Rparam.topic.resourceLimitsQos.max_instances = 1;
Rparam.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Reliable Subscriber..." << std::endl;
Subscriber *mySub1= Domain::createSubscriber(PubParticipant, Rparam, nullptr);
if(myPub == nullptr){
std::cout << "something went wrong while creating the Reliable Subscriber..." << std::endl;
return;
}
//Best Effort Sub
SubscriberAttributes Rparam2;
Rparam2.topic.topicDataType = sampleType.getName();
Rparam2.topic.topicName = "samplePubSubTopic";
Rparam2.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Rparam2.topic.topicKind = NO_KEY;
Rparam2.topic.historyQos.kind = KEEP_LAST_HISTORY_QOS;
Rparam2.qos.m_durability.kind = VOLATILE_DURABILITY_QOS;
Rparam2.qos.m_reliability.kind = BEST_EFFORT_RELIABILITY_QOS;
Rparam2.topic.historyQos.depth = 10;
Rparam2.topic.resourceLimitsQos.max_samples = 100;
Rparam2.topic.resourceLimitsQos.max_instances = 1;
Rparam2.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Best Effort Subscriber with depth 10..." << std::endl;
Subscriber *mySub2= Domain::createSubscriber(PubParticipant, Rparam2, nullptr);
if(myPub == nullptr){
std::cout << "Something went wrong while creating the Best Effort Subscriber..." << std::endl;
return;
}
//Send 20 samples
std::cout << "Publishing 10 samples on the topic..." << std::endl;
for(uint8_t j=0; j < 10; j++){
my_sample.index(j+1);
my_sample.key_value(1);
myPub->write(&my_sample);
}
eClock::my_sleep(1500);
//Read the contents of both histories:
std::cout << "The Reliable Subscriber holds: " << std::endl;
while(mySub1->readNextData(&my_sample, &sample_info)){
std::cout << std::to_string(my_sample.index()) << " ";
}
std::cout << std::endl;
std::cout << "TheBest Effort Subscriber holds: " << std::endl;
while(mySub2->readNextData(&my_sample, &sample_info)){
std::cout << std::to_string(my_sample.index()) << " ";
}
std::cout << std::endl;
}
void safest(){
samplePubSubType sampleType;
sample my_sample;
SampleInfo_t sample_info;
ParticipantAttributes PparamPub;
PparamPub.rtps.builtin.domainId = 0;
PparamPub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamPub.rtps.setName("PublisherParticipant");
Participant *PubParticipant = Domain::createParticipant(PparamPub);
if(PubParticipant == nullptr){
std::cout << " Something went wrong while creating the Publisher Participant..." << std::endl;
return;
}
Domain::registerType(PubParticipant,(TopicDataType*) &sampleType);
//Publisher config
PublisherAttributes Pparam;
Pparam.topic.topicDataType = sampleType.getName();
Pparam.topic.topicName = "samplePubSubTopic";
Pparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Pparam.topic.topicKind = NO_KEY;
Pparam.topic.historyQos.kind = KEEP_ALL_HISTORY_QOS;
Pparam.qos.m_durability.kind = TRANSIENT_LOCAL_DURABILITY_QOS;
Pparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Pparam.topic.historyQos.depth = 50;
Pparam.topic.resourceLimitsQos.max_samples = 100;
Pparam.topic.resourceLimitsQos.max_instances = 1;
Pparam.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Best-Effort Publisher..." << std::endl;
Publisher *myPub= Domain::createPublisher(PubParticipant, Pparam, nullptr);
if(myPub == nullptr){
std::cout << "Something went wrong while creating the Publisher..." << std::endl;
return;
}
ParticipantAttributes PparamSub;
PparamSub.rtps.builtin.domainId = 0;
PparamSub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamSub.rtps.setName("SubscriberParticipant");
Participant *SubParticipant = Domain::createParticipant(PparamSub);
if(SubParticipant == nullptr){
std::cout << " Something went wrong while creating the Subscriber Participant..." << std::endl;
return;
}
Domain::registerType(SubParticipant,(TopicDataType*) &sampleType);
// Sub
SubscriberAttributes Rparam;
Rparam.topic.topicDataType = sampleType.getName();
Rparam.topic.topicName = "samplePubSubTopic";
Rparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Rparam.topic.topicKind = NO_KEY;
Rparam.topic.historyQos.kind = KEEP_ALL_HISTORY_QOS;
Rparam.qos.m_durability.kind = TRANSIENT_LOCAL_DURABILITY_QOS;
Rparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Rparam.topic.historyQos.depth = 50;
Rparam.topic.resourceLimitsQos.max_samples = 100;
Rparam.topic.resourceLimitsQos.max_instances = 1;
Rparam.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Subscriber..." << std::endl;
Subscriber *mySub1= Domain::createSubscriber(PubParticipant, Rparam, nullptr);
if(myPub == nullptr){
std::cout << "something went wrong while creating the Subscriber..." << std::endl;
return;
}
//Send 20 samples
std::cout << "Publishing 10 samples on the topic..." << std::endl;
for(uint8_t j=0; j < 10; j++){
my_sample.index(j+1);
my_sample.key_value(1);
myPub->write(&my_sample);
}
eClock::my_sleep(1500);
//Read the contents of both histories:
std::cout << "The Reliable Subscriber holds: " << std::endl;
while(mySub1->readNextData(&my_sample, &sample_info)){
std::cout << std::to_string(my_sample.index()) << " ";
}
std::cout << std::endl;
}
void fastest(){
samplePubSubType sampleType;
sample my_sample;
SampleInfo_t sample_info;
ParticipantAttributes PparamPub;
PparamPub.rtps.builtin.domainId = 0;
PparamPub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamPub.rtps.setName("PublisherParticipant");
Participant *PubParticipant = Domain::createParticipant(PparamPub);
if(PubParticipant == nullptr){
std::cout << " Something went wrong while creating the Publisher Participant..." << std::endl;
return;
}
Domain::registerType(PubParticipant,(TopicDataType*) &sampleType);
//Publisher config
PublisherAttributes Pparam;
Pparam.topic.topicDataType = sampleType.getName();
Pparam.topic.topicName = "samplePubSubTopic";
Pparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Pparam.topic.topicKind = NO_KEY;
Pparam.topic.historyQos.kind = KEEP_LAST_HISTORY_QOS;
Pparam.qos.m_durability.kind = VOLATILE_DURABILITY_QOS;
Pparam.qos.m_reliability.kind = BEST_EFFORT_RELIABILITY_QOS;
Pparam.topic.historyQos.depth = 50;
Pparam.topic.resourceLimitsQos.max_samples = 100;
Pparam.topic.resourceLimitsQos.max_instances = 1;
Pparam.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Best-Effort Publisher..." << std::endl;
Publisher *myPub= Domain::createPublisher(PubParticipant, Pparam, nullptr);
if(myPub == nullptr){
std::cout << "Something went wrong while creating the Publisher..." << std::endl;
return;
}
ParticipantAttributes PparamSub;
PparamSub.rtps.builtin.domainId = 0;
PparamSub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamSub.rtps.setName("SubscriberParticipant");
Participant *SubParticipant = Domain::createParticipant(PparamSub);
if(SubParticipant == nullptr){
std::cout << " Something went wrong while creating the Subscriber Participant..." << std::endl;
return;
}
Domain::registerType(SubParticipant,(TopicDataType*) &sampleType);
// Sub
SubscriberAttributes Rparam;
Rparam.topic.topicDataType = sampleType.getName();
Rparam.topic.topicName = "samplePubSubTopic";
Rparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Rparam.topic.topicKind = NO_KEY;
Rparam.topic.historyQos.kind = KEEP_LAST_HISTORY_QOS;
Rparam.qos.m_durability.kind = VOLATILE_DURABILITY_QOS;
Rparam.qos.m_reliability.kind = BEST_EFFORT_RELIABILITY_QOS;
Rparam.topic.historyQos.depth = 50;
Rparam.topic.resourceLimitsQos.max_samples = 100;
Rparam.topic.resourceLimitsQos.max_instances = 1;
Rparam.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Subscriber..." << std::endl;
Subscriber *mySub1= Domain::createSubscriber(PubParticipant, Rparam, nullptr);
if(myPub == nullptr){
std::cout << "something went wrong while creating the Subscriber..." << std::endl;
return;
}
//Send 20 samples
std::cout << "Publishing 10 samples on the topic..." << std::endl;
for(uint8_t j=0; j < 10; j++){
my_sample.index(j+1);
my_sample.key_value(1);
myPub->write(&my_sample);
}
eClock::my_sleep(1500);
//Read the contents of both histories:
std::cout << "The Reliable Subscriber holds: " << std::endl;
while(mySub1->readNextData(&my_sample, &sample_info)){
std::cout << std::to_string(my_sample.index()) << " ";
}
std::cout << std::endl;
}
void triggers(){
samplePubSubType sampleType;
sample my_sample;
SampleInfo_t sample_info;
ParticipantAttributes PparamPub;
PparamPub.rtps.builtin.domainId = 0;
PparamPub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamPub.rtps.setName("PublisherParticipant");
Participant *PubParticipant = Domain::createParticipant(PparamPub);
if(PubParticipant == nullptr){
std::cout << " Something went wrong while creating the Publisher Participant..." << std::endl;
return;
}
Domain::registerType(PubParticipant,(TopicDataType*) &sampleType);
//Publisher config
PublisherAttributes Pparam;
Pparam.topic.topicDataType = sampleType.getName();
Pparam.topic.topicName = "samplePubSubTopic";
Pparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Pparam.topic.topicKind = NO_KEY;
Pparam.topic.historyQos.kind = KEEP_LAST_HISTORY_QOS;
Pparam.qos.m_durability.kind = VOLATILE_DURABILITY_QOS;
Pparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Pparam.topic.historyQos.depth = 50;
Pparam.topic.resourceLimitsQos.max_samples = 100;
Pparam.topic.resourceLimitsQos.max_instances = 1;
Pparam.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Best-Effort Publisher..." << std::endl;
Publisher *myPub= Domain::createPublisher(PubParticipant, Pparam, nullptr);
if(myPub == nullptr){
std::cout << "Something went wrong while creating the Publisher..." << std::endl;
return;
}
ParticipantAttributes PparamSub;
PparamSub.rtps.builtin.domainId = 0;
PparamSub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamSub.rtps.setName("SubscriberParticipant");
Participant *SubParticipant = Domain::createParticipant(PparamSub);
if(SubParticipant == nullptr){
std::cout << " Something went wrong while creating the Subscriber Participant..." << std::endl;
return;
}
Domain::registerType(SubParticipant,(TopicDataType*) &sampleType);
// Sub
SubscriberAttributes Rparam;
Rparam.topic.topicDataType = sampleType.getName();
Rparam.topic.topicName = "samplePubSubTopic";
Rparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Rparam.topic.topicKind = NO_KEY;
Rparam.topic.historyQos.kind = KEEP_LAST_HISTORY_QOS;
Rparam.qos.m_durability.kind = VOLATILE_DURABILITY_QOS;
Rparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Rparam.topic.historyQos.depth = 50;
Rparam.topic.resourceLimitsQos.max_samples = 100;
Rparam.topic.resourceLimitsQos.max_instances = 1;
Rparam.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Subscriber..." << std::endl;
Subscriber *mySub1= Domain::createSubscriber(PubParticipant, Rparam, nullptr);
if(myPub == nullptr){
std::cout << "something went wrong while creating the Subscriber..." << std::endl;
return;
}
//Send 20 samples
std::cout << "Publishing 10 samples on the topic..." << std::endl;
for(uint8_t j=0; j < 10; j++){
my_sample.index(j+1);
my_sample.key_value(1);
myPub->write(&my_sample);
}
eClock::my_sleep(1500);
//Read the contents of both histories:
std::cout << "The Subscriber holds: " << std::endl;
while(mySub1->readNextData(&my_sample, &sample_info)){
std::cout << std::to_string(my_sample.index()) << " ";
}
std::cout << std::endl;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/Configurability/Makefile | # 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.
CPP=g++
LN=g++
AR=ar
CP=cp
SYSLIBS= -ldl -lnsl -lm -lpthread -lrt
DEFINES=
COMMON_CFLAGS= -c -Wall -D__LITTLE_ENDIAN__ -std=c++11
## CHOOSE HERE BETWEEN 32 and 64 bit architecture
##32 BIT ARCH:
#COMMON_CFLAGS+= -m32 -fpic
#LDFLAGS=-m32
#64BIT ARCH:
COMMON_CFLAGS+= -m64 -fpic
LDFLAGS=-m64
CFLAGS = $(COMMON_CFLAGS) -O2
INCLUDES= -I.
LIBS = -lfastcdr -lfastrtps $(SYSLIBS)
DIRECTORIES= output.dir bin.dir
all: $(DIRECTORIES) ConfigurabilityPub ConfigurabilitySub ConfigurabilityLauncher
CONFPUB_TARGET= bin/UseCasePublisher
CONFSUB_TARGET= bin/UseCaseSubscriber
CONFLAUNCHER_TARGET= bin/UseCaseLauncher
CONFIGURABILITY_SRC_CXXFILES=
CONFIGURABILITY_SRC_CPPFILES= Configurability/samplePubSubTypes.cxx \
Configurability/sample.cxx
CONFIGURABILITY_SRCS= $(CONFIGURABILITY_SRC_CXXFILES) $(CONFIGURABILITY_SRC_CPPFILES)
PUB_SRC_CPPFILE= Configurability/UseCasePublisher.cpp
SUB_SRC_CPPFILE= Configurability/UseCaseSubscriber.cpp
LAUNCHER_SRC_CPPFILE= Configurability/UseCaseLauncher.cpp
# Project sources are copied to the current directory
CONFPUB_SRCS= $(CONFIGURABILITY_SRC_CPPFILES) $(PUB_SRC_CPPFILE)
CONFSUB_SRCS= $(CONFIGURABILITY_SRC_CPPFILES) $(SUB_SRC_CPPFILE)
LAUNCHER_SRCS= $(CONFIGURABILITY_SRC_CPPFILES) $(LAUNCHER_SRC_CPPFILE)
# Source directories
CONFPUB_SOURCES_DIRS_AUX= $(foreach srcdir, $(dir $(CONFPUB_SRCS)), $(srcdir))
CONFPUB_SOURCES_DIRS= $(shell echo $(CONFPUB_SOURCES_DIRS_AUX) | tr " " "\n" | sort | uniq | tr "\n" " ")
CONFPUB_OBJS = $(foreach obj,$(notdir $(addsuffix .o, $(CONFPUB_SRCS))), output/$(obj))
CONFPUB_DEPS = $(foreach dep,$(notdir $(addsuffix .d, $(CONFPUB_SRCS))), output/$(dep))
CONFSUB_SOURCES_DIRS_AUX= $(foreach srcdir, $(dir $(CONFSUB_SRCS)), $(srcdir))
CONFSUB_SOURCES_DIRS= $(shell echo $(CONFSUB_SOURCES_DIRS_AUX) | tr " " "\n" | sort | uniq | tr "\n" " ")
CONFSUB_OBJS = $(foreach obj,$(notdir $(addsuffix .o, $(CONFSUB_SRCS))), output/$(obj))
CONFSUB_DEPS = $(foreach dep,$(notdir $(addsuffix .d, $(CONFSUB_SRCS))), output/$(dep))
LAUNCHER_SOURCES_DIRS_AUX= $(foreach srcdir, $(dir $(LAUNCHER_SRCS)), $(srcdir))
LAUNCHER_SOURCES_DIRS= $(shell echo $(LAUNCHER_SOURCES_DIRS_AUX) | tr " " "\n" | sort | uniq | tr "\n" " ")
LAUNCHER_OBJS = $(foreach obj,$(notdir $(addsuffix .o, $(LAUNCHER_SRCS))), output/$(obj))
LAUNCHER_DEPS = $(foreach dep,$(notdir $(addsuffix .d, $(LAUNCHER_SRCS))), output/$(dep))
ALL_SOURCE_DIRS = $(CONFPUB_SOURCES_DIRS) $(CONFSUB_SOURCES_DIRS) $(LAUNCHER_SOURCES_DIRS)
OBJS+= $(CONFPUB_OBJS)
DEPS+= $(CONFPUB_DEPS)
OBJS+= $(CONFSUB_OBJS)
DEPS+= $(CONFSUB_DEPS)
OBJS+= $(LAUNCHER_OBJS)
DEPS+= $(LAUNCHER_DEPS)
ConfigurabilityPub: $(CONFPUB_TARGET)
$(CONFPUB_TARGET): $(CONFPUB_OBJS)
$(LN) $(LDFLAGS) -o $(CONFPUB_TARGET) $(CONFPUB_OBJS) $(LIBS)
ConfigurabilitySub: $(CONFSUB_TARGET)
$(CONFSUB_TARGET): $(CONFSUB_OBJS)
$(LN) $(LDFLAGS) -o $(CONFSUB_TARGET) $(CONFSUB_OBJS) $(LIBS)
ConfigurabilityLauncher: $(CONFLAUNCHER_TARGET)
$(CONFLAUNCHER_TARGET): $(LAUNCHER_OBJS)
$(LN) $(LDFLAGS) -o $(CONFLAUNCHER_TARGET) $(LAUNCHER_OBJS) $(LIBS)
vpath %.cxx $(ALL_SOURCE_DIRS)
vpath %.cpp $(ALL_SOURCE_DIRS)
output/%.cxx.o:%.cxx
@echo Calculating dependencies $<
@$(CC) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cxx.o=%.cxx.d)
@echo Compiling $<
@$(CC) $(CFLAGS) $(INCLUDES) $< -o $@
output/%.cpp.o:%.cpp
@echo Calculating dependencies $<
@$(CPP) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cpp.o=%.cpp.d)
@echo Compiling $<
@$(CPP) $(CFLAGS) $(INCLUDES) $< -o $@
.PHONY: ConfigurabilityPub ConfigurabilitySub ConfigurabilityLauncher
clean:
@rm -f $(OBJS)
@rm -f $(DEPS)
ifneq ($(MAKECMDGOALS), clean)
-include $(DEPS)
endif
%.dir :
@echo "Checking directory $*"
@if [ ! -d $* ]; then \
echo "Making directory $*"; \
mkdir -p $* ; \
fi;
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/Configurability/UseCasePublisher.cpp | /***
* Use Case Demonstrator for eProsima Fast RTPS
* --------------------------------------------
*
* This is an interactive program designed to show the effect of different configuration parameters on the behaviour of eProsima Fast RTPS
*
***/
#include <iostream>
#include <string>
#include <fastrtps/participant/Participant.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/subscriber/Subscriber.h>
#include <fastrtps/attributes/SubscriberAttributes.h>
#include <fastrtps/publisher/Publisher.h>
#include <fastrtps/attributes/PublisherAttributes.h>
#include <fastrtps/Domain.h>
#include <fastrtps/subscriber/SampleInfo.h>
#include <fastrtps/utils/eClock.h>
#include "samplePubSubTypes.h"
//Enums and configuration structure
enum Reliability_type { Best_Effort, Reliable };
enum Durability_type { Transient_Local, Volatile };
enum HistoryKind_type { Keep_Last, Keep_All };
enum Key_type { No_Key, With_Key};
typedef struct{
Reliability_type reliability;
Durability_type durability;
HistoryKind_type historykind;
Key_type keys;
uint16_t history_size;
uint8_t depth;
uint8_t no_keys;
uint16_t max_samples_per_key;
} example_configuration;
int main(){
std::string userchoice;
bool validinput;
example_configuration user_configuration = {};
std::cout << "Welcome to eProsima Fast RTPS Use Case Demonstrator" << std::endl;
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "Choose your desired reliability type:" << std::endl;
std::cout << "1 - Best Effort: Messages are sent with no arrival confirmation. If a sample is lost it cannot be recovered" << std::endl;
std::cout << "2 - Reliable: The Publisher asks for arrival confirmation. Lost samples are re-sent" << std::endl;
std::cout << "Make your choice (1 or 2): " << std::endl;;
validinput = false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
if(choice == 1){
user_configuration.reliability = Best_Effort;
validinput = true;
}else if(choice == 2){
user_configuration.reliability = Reliable;
validinput = true;
}else{
std::cout << "Please enter a valid option" << std::endl;
}
}
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "Choose your desired Durability Type:" << std::endl;
std::cout << "1 - Transient Local: The Subscriber will receive samples that have been sent before it came online" << std::endl;
std::cout << "2 - Volatile: The Subscriber receives samples from the moment it comes online, not before:" << std::endl;
std::cout << "Make your choice (1 or 2): " << std::endl;
validinput = false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
if(choice == 1){
user_configuration.durability = Transient_Local;
validinput = true;
}else if(choice == 2){
user_configuration.durability = Volatile;
validinput = true;
}else{
std::cout << "Please enter a valid option" << std::endl;
}
}
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "Choose your desired History Kind:" << std::endl;
std::cout << "1 - Keep last: The History stores the last \"k\" received samples. \"k\" is configured as the \"depth\" parameter of the history." << std::endl;
std::cout << "2 - Keep all: The History stores all incoming samples until it is full." << std::endl;
std::cout << "Make your choice (1 or 2): " << std::endl;
validinput = false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
if(choice == 1){
user_configuration.historykind= Keep_Last;
validinput = true;
}else if(choice == 2){
user_configuration.historykind = Keep_All;
validinput = true;
}else{
std::cout << "Please enter a valid option" << std::endl;
}
}
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "The 'depth' parameter of the History defines how many past samples are stored before starting to overwrite them with newer ones. This only takes effect in 'Keep Last' mode." << std::endl;
std::cout << "Select your desired History depth (enter a number)" << std::endl;
validinput =false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
user_configuration.depth = choice;
validinput=true;
}
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "You can split your History in 'Instances', which act as separate data sinks that end up mapping to 'Keys' on the Publisher side. If you want to use keys, choose a number bigger than one here." << std::endl;
std::cout << "Select your desired maximum number of instances (enter a number)" << std::endl;
validinput =false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
if(choice > 0){
user_configuration.depth = choice;
}else{
user_configuration.depth = 1;
std::cout << "Defaulting to 1 instance..." << std::endl;
}
validinput=true;
}
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "If using more than one instance in the history, you can define the 'depth' on a 'per instance' level. Otherwise, this parameter does not take effect" << std::endl;
std::cout << "Select your desired instance depth (enter a number)" << std::endl;
validinput =false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
user_configuration.max_samples_per_key = choice;
validinput=true;
}
std::cout << "By using Keys you can subdivide your topic so your configuration options are applied individually to each subdivision." << std::endl;
std::cout << "Do you want to use keys? (1-yes or 2-no):" << std::endl;
validinput = false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
if(choice == 1){
user_configuration.keys= With_Key;
validinput = true;
}else if(choice == 2){
user_configuration.keys = No_Key;
validinput = true;
}else{
std::cout << "Please enter a valid option" << std::endl;
}
}
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "Lastly, you must define a global maximum size of the History. You must choose a size big enough to hold the amount of samples your previous choices indicate." << std::endl;
std::cout << "Select your desired history size (enter a number)" << std::endl;
validinput =false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
user_configuration.history_size = choice;
validinput=true;
}
samplePubSubType sampleType;
ParticipantAttributes PparamPub;
PparamPub.rtps.builtin.domainId = 0;
PparamPub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamPub.rtps.setName("PublisherParticipant");
Participant *PubParticipant = Domain::createParticipant(PparamPub);
if(PubParticipant == nullptr){
std::cout << " Something went wrong while creating the Publisher Participant..." << std::endl;
return 1;
}
Domain::registerType(PubParticipant,(TopicDataType*) &sampleType);
PublisherAttributes Pparam;
Pparam.topic.topicDataType = sampleType.getName();
Pparam.topic.topicName = "samplePubSubTopic";
Pparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
if(user_configuration.keys == With_Key)
Pparam.topic.topicKind = WITH_KEY;
else
Pparam.topic.topicKind = NO_KEY;
if(user_configuration.historykind == Keep_Last)
Pparam.topic.historyQos.kind = KEEP_LAST_HISTORY_QOS;
else
Pparam.topic.historyQos.kind = KEEP_ALL_HISTORY_QOS;
if(user_configuration.durability == Transient_Local)
Pparam.qos.m_durability.kind = TRANSIENT_LOCAL_DURABILITY_QOS;
else
Pparam.qos.m_durability.kind = VOLATILE_DURABILITY_QOS;
if(user_configuration.reliability == Reliable)
Pparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
else
Pparam.qos.m_reliability.kind = BEST_EFFORT_RELIABILITY_QOS;
Pparam.topic.historyQos.depth = user_configuration.depth;
Pparam.topic.resourceLimitsQos.max_samples = user_configuration.history_size;
Pparam.topic.resourceLimitsQos.max_instances = user_configuration.no_keys;
Pparam.topic.resourceLimitsQos.max_samples_per_instance = user_configuration.max_samples_per_key;
Publisher *myPub= Domain::createPublisher(PubParticipant, Pparam, nullptr);
if(myPub == nullptr){
std::cout << "Somthething went wrong while creating the Publisher..." << std::endl;
return 1;
}
int no_keys = 1;
sample my_sample;
if(user_configuration.keys == With_Key)
no_keys = user_configuration.no_keys;
std::string c;
bool condition = true;
int no;
while(condition){
std::cout << "Enter a number to send samples, 'q' to exit" << std::endl;
std::cin >> c;
if(c == std::string("q")){
condition = false;
}else{
try{
no = std::stoi(c);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
for(uint8_t j=0; j < no; j++){
for(uint8_t i=0; i < no_keys; i++){
my_sample.index(j+1);
my_sample.key_value(i);
myPub->write(&my_sample);
}
}
std::cout << "Sent " << std::to_string(no) << " samples." << std::endl;
}
}
return 0;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/Configurability/sample.cxx | // 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 sample.cpp
* This source file contains the definition of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/
#ifdef _WIN32
// Remove linker warning LNK4221 on Visual Studio
namespace { char dummy; }
#endif
#include "sample.h"
#include <fastcdr/Cdr.h>
#include <fastcdr/exceptions/BadParamException.h>
using namespace eprosima::fastcdr::exception;
#include <utility>
sample::sample()
{
m_index = 0;
m_key_value = 0;
}
sample::~sample()
{
}
sample::sample(const sample &x)
{
m_index = x.m_index;
m_key_value = x.m_key_value;
}
sample::sample(sample &&x)
{
m_index = x.m_index;
m_key_value = x.m_key_value;
}
sample& sample::operator=(const sample &x)
{
m_index = x.m_index;
m_key_value = x.m_key_value;
return *this;
}
sample& sample::operator=(sample &&x)
{
m_index = x.m_index;
m_key_value = x.m_key_value;
return *this;
}
size_t sample::getMaxCdrSerializedSize(size_t current_alignment)
{
size_t initial_alignment = current_alignment;
current_alignment += 1 + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
current_alignment += 1 + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
return current_alignment - initial_alignment;
}
size_t sample::getCdrSerializedSize(const sample& data, size_t current_alignment)
{
size_t initial_alignment = current_alignment;
current_alignment += 1 + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
current_alignment += 1 + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
return current_alignment - initial_alignment;
}
void sample::serialize(eprosima::fastcdr::Cdr &scdr) const
{
scdr << m_index;
scdr << m_key_value;
}
void sample::deserialize(eprosima::fastcdr::Cdr &dcdr)
{
dcdr >> m_index;
dcdr >> m_key_value;
}
size_t sample::getKeyMaxCdrSerializedSize(size_t current_alignment)
{
size_t current_align = current_alignment;
current_align += 1 + eprosima::fastcdr::Cdr::alignment(current_align, 1);
return current_align;
}
bool sample::isKeyDefined()
{
return true;
}
void sample::serializeKey(eprosima::fastcdr::Cdr &scdr) const
{
scdr << m_key_value;
} | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/Configurability/UseCaseSubscriber.cpp | /***
* Use Case Demonstrator for eProsima Fast RTPS
* --------------------------------------------
*
* This is an interactive program designed to show the effect of different configuration parameters on the behaviour of eProsima Fast RTPS
*
***/
#include <iostream>
#include <string>
#include <fastrtps/participant/Participant.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/subscriber/Subscriber.h>
#include <fastrtps/attributes/SubscriberAttributes.h>
#include <fastrtps/publisher/Publisher.h>
#include <fastrtps/attributes/PublisherAttributes.h>
#include <fastrtps/Domain.h>
#include <fastrtps/subscriber/SampleInfo.h>
#include <fastrtps/utils/eClock.h>
#include "samplePubSubTypes.h"
//Enums and configuration structure
enum Reliability_type { Best_Effort, Reliable };
enum Durability_type { Transient_Local, Volatile };
enum HistoryKind_type { Keep_Last, Keep_All };
enum Key_type { No_Key, With_Key};
typedef struct{
Reliability_type reliability;
Durability_type durability;
HistoryKind_type historykind;
Key_type keys;
uint16_t history_size;
uint8_t depth;
uint8_t no_keys;
uint16_t max_samples_per_key;
} example_configuration;
int main(){
std::string userchoice;
bool validinput;
example_configuration user_configuration = {};
std::cout << "Welcome to eProsima Fast RTPS Use Case Demonstrator" << std::endl;
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "Choose your desired reliability type:" << std::endl;
std::cout << "1 - Best Effort: Messages are sent with no arrival confirmation. If a sample is lost it cannot be recovered" << std::endl;
std::cout << "2 - Reliable: The Publisher asks for arrival confirmation. Lost samples are re-sent" << std::endl;
std::cout << "Make your choice (1 or 2): " << std::endl;;
validinput = false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
if(choice == 1){
user_configuration.reliability = Best_Effort;
validinput = true;
}else if(choice == 2){
user_configuration.reliability = Reliable;
validinput = true;
}else{
std::cout << "Please enter a valid option" << std::endl;
}
}
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "Choose your desired Durability Type:" << std::endl;
std::cout << "1 - Transient Local: The Subscriber will receive samples that have been sent before it came online" << std::endl;
std::cout << "2 - Volatile: The Subscriber receives samples from the moment it comes online, not before:" << std::endl;
std::cout << "Make your choice (1 or 2): " << std::endl;
validinput = false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
if(choice == 1){
user_configuration.durability = Transient_Local;
validinput = true;
}else if(choice == 2){
user_configuration.durability = Volatile;
validinput = true;
}else{
std::cout << "Please enter a valid option" << std::endl;
}
}
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "Choose your desired History Kind:" << std::endl;
std::cout << "1 - Keep last: The History stores the last \"k\" received samples. \"k\" is configured as the \"depth\" parameter of the history." << std::endl;
std::cout << "2 - Keep all: The History stores all incoming samples until it is full." << std::endl;
std::cout << "Make your choice (1 or 2): " << std::endl;
validinput = false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
if(choice == 1){
user_configuration.historykind= Keep_Last;
validinput = true;
}else if(choice == 2){
user_configuration.historykind = Keep_All;
validinput = true;
}else{
std::cout << "Please enter a valid option" << std::endl;
}
}
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "The 'depth' parameter of the History defines how many past samples are stored before starting to overwrite them with newer ones. This only takes effect in 'Keep Last' mode." << std::endl;
std::cout << "Select your desired History depth (enter a number)" << std::endl;
validinput =false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
user_configuration.depth = choice;
validinput=true;
}
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "You can split your History in 'Instances', which act as separate data sinks that end up mapping to 'Keys' on the Publisher side. If you want to use keys, choose a number bigger than one here." << std::endl;
std::cout << "Select your desired maximum number of instances (enter a number)" << std::endl;
validinput =false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
if(choice > 0){
user_configuration.depth = choice;
}else{
user_configuration.depth = 1;
std::cout << "Defaulting to 1 instance..." << std::endl;
}
validinput=true;
}
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "If using more than one instance in the history, you can define the 'depth' on a 'per instance' level. Otherwise, this parameter does not take effect" << std::endl;
std::cout << "Select your desired instance depth (enter a number)" << std::endl;
validinput =false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
user_configuration.max_samples_per_key = choice;
validinput=true;
}
std::cout << "By using Keys you can subdivide your topic so your configuration options are applied individually to each subdivision." << std::endl;
std::cout << "Do you want to use keys? (1-yes or 2-no):" << std::endl;
validinput = false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
if(choice == 1){
user_configuration.keys= With_Key;
validinput = true;
}else if(choice == 2){
user_configuration.keys = No_Key;
validinput = true;
}else{
std::cout << "Please enter a valid option" << std::endl;
}
}
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "Lastly, you must define a global maximum size of the History. You must choose a size big enough to hold the amount of samples your previous choices indicate." << std::endl;
std::cout << "Select your desired history size (enter a number)" << std::endl;
validinput =false;
while(!validinput){
std::cin >> userchoice;
int choice;
try{
choice = std::stoi(userchoice);
}catch(std::invalid_argument){
std::cout << "Please input a valid argument" << std::endl;
continue;
}
user_configuration.history_size = choice;
validinput=true;
}
samplePubSubType sampleType;
ParticipantAttributes PparamSub;
PparamSub.rtps.builtin.domainId = 0;
PparamSub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamSub.rtps.setName("SubscriberParticipant");
Participant *SubParticipant = Domain::createParticipant(PparamSub);
if(SubParticipant == nullptr){
std::cout << " Something went wrong while creating the Subscriber Participant..." << std::endl;
return 1;
}
Domain::registerType(SubParticipant,(TopicDataType*) &sampleType);
SubscriberAttributes Rparam;
Rparam.topic.topicDataType = sampleType.getName();
Rparam.topic.topicName = "samplePubSubTopic";
Rparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
if(user_configuration.keys == With_Key)
Rparam.topic.topicKind = WITH_KEY;
else
Rparam.topic.topicKind = NO_KEY;
if(user_configuration.historykind == Keep_Last)
Rparam.topic.historyQos.kind = KEEP_LAST_HISTORY_QOS;
else
Rparam.topic.historyQos.kind = KEEP_ALL_HISTORY_QOS;
if(user_configuration.durability == Transient_Local)
Rparam.qos.m_durability.kind = TRANSIENT_LOCAL_DURABILITY_QOS;
else
Rparam.qos.m_durability.kind = VOLATILE_DURABILITY_QOS;
if(user_configuration.reliability == Reliable)
Rparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
else
Rparam.qos.m_reliability.kind = BEST_EFFORT_RELIABILITY_QOS;
Rparam.topic.historyQos.depth = user_configuration.depth;
Rparam.topic.resourceLimitsQos.max_samples = user_configuration.history_size;
Rparam.topic.resourceLimitsQos.max_instances = user_configuration.no_keys;
Rparam.topic.resourceLimitsQos.max_samples_per_instance = user_configuration.max_samples_per_key;
Subscriber *EarlySubscriber = Domain::createSubscriber(SubParticipant, Rparam, nullptr);
if(EarlySubscriber == nullptr){
std::cout << "Something went wrong while creating the Subscriber..." << std::endl;
return 1;
}
std::cout << "Subscriber online" << std::endl;
std::string c;
bool condition = true;
sample my_sample;
SampleInfo_t sample_info;
while(condition){
std::cout << "Press 'r' to read Messages from the History or 'q' to quit" << std::endl;
std::cin >> c;
if( c == std::string("q") ){
condition = false;
}else if( c == std::string("r") ){
while(EarlySubscriber->readNextData(&my_sample, &sample_info)){
std::cout << "Sample Received! Index:" << std::to_string(my_sample.index()) << " Key:" << std::to_string(my_sample.key_value()) << std::endl;
}
}
}
return 0;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/Configurability/README.txt | --------------------------------------------------------
- Use Case Publisher-Subscriber for eProsima Fast RTPS -
--------------------------------------------------------
1 - Application description
---------------------------
eProsima Fast RTPS provides users with a wide range of configuration options. This example has the objective of providing a testing ground where you can experiment and see the influence different combinations of parameters can have on the behaviours on the Publisher/Subscriber scheme.
This example consists on two application, a configurable publisher and a subscriber for you to run your own tests:
- With the Publisher, you can choose to send any number of samples at any given moment. Each time you send a batch of samples, they will numbered starting from index '0', so it is easier to view the end of one batch and the start of the next on the Subscriber side.
- The subscriber passively stores samples. At any moment you can choose to view the stored samples.
You can run any number of Publisher and Subscribers and use them to send a variable number of sample batches each of different size, reviewing the contents of the Subscriber to observe the effects of your configuration choices on the behaviour of the network.
2 - Configuration options
--------------------------
These are the main parameters that affect the behaviour of eProsima Fast RTPS and that are used in this example:
- Reliability Kind
Defines how eProsima Fast RTPS deals upon possible packet loss during data exchanges.
+ Best Effort: No arrival confirmation. It is fast but lost samples are not re-sent.
+ Reliable: With arrival confirmation. It is slower but provides guarantee that all lost samples are re-sent and eventually received by the subscriber.
Since this application runs the Publisher and Subscriber on the same machine, data loss is highly unlikely. Therefore this option will not play a relevant role on the application behaviour.
- Durability Kind
Defines what to do with samples that exist prior to the existence of the Subscriber.
+ Volatile: Past samples are ignored, the Subscriber starts to receive data generated after it has joined the network.
+ Transient Local: Past samples are sent.
- History Kind
Defines the storage policy for past samples.
+ Keep Last: The History will save and give access to the alst "k" received samples. This "k" number is called the History Depth and can be manually set too by the user.
+ Keep All: The History will save and give access to all received samples until the maximum samples size of the History is reached.
This parameter affects cases of "late-joining" Subscribers: Subscribers that come online after data transfers on a topic have started.
- Keys
Keys allow to have multiple data endpoints within a topic as opposed to all data published in a topic going into the same "inbox".
+ On a topic without keys, all pieces of data go into a single endpoint.
+ On a topic without keys, the key field is used to determine which of the multiple endpoints the data goes into. If, for example, a history is set to transient local with depth=3 (the last three samples are stores) then eProsima FastRTPS will ensure that 3 samples per data endpoint are stored. This means that three samples are stored for each unique key instead of three samples total.
It is important to note that even if you configure a Topic and your History to be able to hold items from multiple keys, this configuration does not take effect unless you explicitly enable Keys.
- Depth
The depth is the amount of past samples that are stored in the history before starting to overwrite. Only takes effect when the History is on "Keep Last" mode.
- History Size
This accounts for the total number of samples that can be stored in the history, regardless of any other configuration option.
- Instances
Instances are the different data sinks the History is divided and act as receptors of the Keys.
- Instance size
As it happens with depth, you can define a maximun number of past samples to be stored. If you set one Instance and an instance size more restrictive than the depth, the instance size will be the limiting factor.
3. Recommended tests
---------------------
The following examples provide sample tests you can perform to see how the influence of configuration parameters affect the behaviour of eProsima Fast RTPS.
- Testing Keep-All, Keep Last and the influence of Depth.
* Select Keep-Last. Choose depth 10. Open a Publisher and write 5 samples. Then write 6 samples. Read the contents of the Subscriber.
The History will have the 6 samples from the last batch and 4 out of the 5 of the first one. The first sample is lost because it was removed to leave room for new samples.
* Select Keep-Last. Choose depth 20. Open a Publisher and write 10 samples. Then write another 10 samples. Read the contents of the Subscriber.
It will hold all 20 samples, because the number of samples written is lower or equal to the depth and not overwrite has happened yet.
* Repeat the previous tests but select Keep-All. See how the limiting factor now is the total size of the History.
-Testing a late joiner.
A late joiner is a Subscriber that joins a topic after data has been published on it.
* Select Volatile mode. Open a Publisher and post 10 samples. Start a Subscriber. Publish a sample. Read the contents of the Subscriber.
It will only hold the sample written after its creation.
* Select Transient Local mode. Open a Subscriber and post 10 samples. Start a Subscriber. Read the contents of the Subscriber.
It will hold the samples that were written before its creation.
-Testing Keys
*Turn on Keys, choose 3 keys on the Publisher and 3 instances on the Subscriber History. Choose Keep-All. Send 5 samples. Read the contents of the History.
It will containt 15 samples, 5 per key.
*Turn on keys, choose 4 keys on the Publisher and 3 instances on the Subscriber History. Choose Keep-All. Send 5 samples. Read the contents of the History.
It will contain 15 samples belonging to the 3 first unique keys that were received. The fourth key and its data is ignored.
*You can test other configuration parameters in combination with keys. Run previous test but using keys and see the effects are the same as before but in a per-key manner.
- Testing assymetric configurations
For a Publisher and a Subscriber to be able to talk, it is first necessary that they perform a matching process. For this to happen the configuration of both elements has to be compatible.
Reliability is the most common cause for two elements being unable to match. A Best-Effort mode Publisher cannot communicate with a Reliable Subscriber. If you run A Publisher and a Subscriber with these configurations, you will see that the Subscriber never receives a single sample.
- Combined cases
You can take multiple of the previous cases and combine the test subject configurations into a single execution to see how different parameters interact with each other.
- Influence of the instance size depth of the Publisher on a Transient Local late-joining Subscriber: The most restrictive depth or instance size always applies, even it is the Publisher one.
4. Built-in tests
-----------------
In addition to this Publisher and Subscriber, the examples folder of this distribution comes with a number of preset tests to exemplify the most behaviour-changing parameters:
* HistoryKind: Shows how a Keep-All Subscriber stores all samples in its History and a Keep-Last subscriber starts to overwrite when it reacher its depth.
* LateJoiners: Shows how a Transient-Local Subscriber receives past samples while Volatile starts receiving from the moment of its creation.
* Keys: Provides a working example of how data can be split into multiple endpoints based of keys.
* SampleConfig: Provides a basic Publish-Subscribe example for the three sample configurations specified in section 5.
5. Application examples
----------------------
The following list provides examples configurations for real-life scenarios, as shown in the SampleConfig examples provided with this distribution.
- Multimedia feed
Audio and Video transmission have a common characteristic: Having a stable, high datarate feed is more important than having a 100% lossless transmission.
Reliability: Best-Effort. We want to have a fast tranmission. If a sample is lost, it can be recovered via error-correcting algorithms.
Durability: Volatile. We do not mind data from the past, we want to stream what is happening in the present.
History: Keep-Last with Low Depth. Once displayed or recorded on the receiving application, they are not needed in the History.
note: In the case of video, depth can be as low as 1. A missing sample of a 50 frames per second stream represents virtually no information loss.
- Distributed measurement
Lets say we have a factory with a network of distributed temperature sensors and we want to use eProsima Fast RTPS to send data from said sensors to an automation computer which
makes decisions based on the temperature distribution. We would group all sensors within one single topic,
Reliability: Reliable. We want to make sure samples are not lost. Furthermore, since reliable more ensures data delivery, it allows us to detect hardware problems when a sensor becomes silent
Keys: We use a separate key for each sensor. That way new messages from one sensor dont affect the storage of past samples from another sensor.
Durability: Transient Local. We dont want to lose samples due a sensor losing connection temporarily.
History: Keep-Last with High Depth. We want to have access to past samples in order to be able to compute delta values.
- Event-based transmission
In some cases, you may want to transmit information only under certain circumstances that happen in your system, for example a photo from a surveillance camera when it detects movement.
In these cases and due to the low it is important that all datagrams reach their destination
Reliability: Reliable. All samples must reach their destination.
Durability: Volatile. Since corrective actions are taken as events come, past triggers provide have no use.
History: Keep-Last. No past alarm information is necessary for present-time transmissions.
Additional Settings: Reduce heartbeat period, which dictates system response velocity when a sample is lost. A lower heartbeat period equals fast response on data delivery.
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/Configurability/sample.idl | struct sample{
octet index;
@Key octet key_value;
};
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/Configurability/sample.h | // 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 sample.h
* This header file contains the declaration of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/
#ifndef _sample_H_
#define _sample_H_
// TODO Poner en el contexto.
#include <stdint.h>
#include <array>
#include <string>
#include <vector>
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#define eProsima_user_DllExport __declspec( dllexport )
#else
#define eProsima_user_DllExport
#endif
#else
#define eProsima_user_DllExport
#endif
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#if defined(sample_SOURCE)
#define sample_DllAPI __declspec( dllexport )
#else
#define sample_DllAPI __declspec( dllimport )
#endif // sample_SOURCE
#else
#define sample_DllAPI
#endif
#else
#define sample_DllAPI
#endif // _WIN32
namespace eprosima
{
namespace fastcdr
{
class Cdr;
}
}
/*!
* @brief This class represents the structure sample defined by the user in the IDL file.
* @ingroup SAMPLE
*/
class sample
{
public:
/*!
* @brief Default constructor.
*/
eProsima_user_DllExport sample();
/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~sample();
/*!
* @brief Copy constructor.
* @param x Reference to the object sample that will be copied.
*/
eProsima_user_DllExport sample(const sample &x);
/*!
* @brief Move constructor.
* @param x Reference to the object sample that will be copied.
*/
eProsima_user_DllExport sample(sample &&x);
/*!
* @brief Copy assignment.
* @param x Reference to the object sample that will be copied.
*/
eProsima_user_DllExport sample& operator=(const sample &x);
/*!
* @brief Move assignment.
* @param x Reference to the object sample that will be copied.
*/
eProsima_user_DllExport sample& operator=(sample &&x);
/*!
* @brief This function sets a value in member index
* @param _index New value for member index
*/
inline eProsima_user_DllExport void index(uint8_t _index)
{
m_index = _index;
}
/*!
* @brief This function returns the value of member index
* @return Value of member index
*/
inline eProsima_user_DllExport uint8_t index() const
{
return m_index;
}
/*!
* @brief This function returns a reference to member index
* @return Reference to member index
*/
inline eProsima_user_DllExport uint8_t& index()
{
return m_index;
}
/*!
* @brief This function sets a value in member key_value
* @param _key_value New value for member key_value
*/
inline eProsima_user_DllExport void key_value(uint8_t _key_value)
{
m_key_value = _key_value;
}
/*!
* @brief This function returns the value of member key_value
* @return Value of member key_value
*/
inline eProsima_user_DllExport uint8_t key_value() const
{
return m_key_value;
}
/*!
* @brief This function returns a reference to member key_value
* @return Reference to member key_value
*/
inline eProsima_user_DllExport uint8_t& key_value()
{
return m_key_value;
}
/*!
* @brief This function returns the maximum serialized size of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getMaxCdrSerializedSize(size_t current_alignment = 0);
/*!
* @brief This function returns the serialized size of a data depending on the buffer alignment.
* @param data Data which is calculated its serialized size.
* @param current_alignment Buffer alignment.
* @return Serialized size.
*/
eProsima_user_DllExport static size_t getCdrSerializedSize(const sample& data, size_t current_alignment = 0);
/*!
* @brief This function serializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serialize(eprosima::fastcdr::Cdr &cdr) const;
/*!
* @brief This function deserializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void deserialize(eprosima::fastcdr::Cdr &cdr);
/*!
* @brief This function returns the maximum serialized size of the Key of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize(size_t current_alignment = 0);
/*!
* @brief This function tells you if the Key has been defined for this type
*/
eProsima_user_DllExport static bool isKeyDefined();
/*!
* @brief This function serializes the key members of an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const;
private:
uint8_t m_index;
uint8_t m_key_value;
};
#endif // _sample_H_ | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/Configurability/samplePubSubTypes.cxx | // 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 samplePubSubTypes.cpp
* This header file contains the implementation of the serialization functions.
*
* This file was generated by the tool fastcdrgen.
*/
#include <fastcdr/FastBuffer.h>
#include <fastcdr/Cdr.h>
#include "samplePubSubTypes.h"
samplePubSubType::samplePubSubType() {
setName("sample");
m_typeSize = (uint32_t)sample::getMaxCdrSerializedSize() + 4 /*encapsulation*/;
m_isGetKeyDefined = sample::isKeyDefined();
m_keyBuffer = (unsigned char*)malloc(sample::getKeyMaxCdrSerializedSize()>16 ? sample::getKeyMaxCdrSerializedSize() : 16);
}
samplePubSubType::~samplePubSubType() {
if(m_keyBuffer!=nullptr)
free(m_keyBuffer);
}
bool samplePubSubType::serialize(void *data, SerializedPayload_t *payload) {
sample *p_type = (sample*) data;
eprosima::fastcdr::FastBuffer fastbuffer((char*) payload->data, payload->max_size); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);
payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
// Serialize encapsulation
ser.serialize_encapsulation();
p_type->serialize(ser); // Serialize the object:
payload->length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length
return true;
}
bool samplePubSubType::deserialize(SerializedPayload_t* payload, void* data) {
sample* p_type = (sample*) data; //Convert DATA to pointer of your type
eprosima::fastcdr::FastBuffer fastbuffer((char*)payload->data, payload->length); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR); // Object that deserializes the data.
// Deserialize encapsulation.
deser.read_encapsulation();
payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
p_type->deserialize(deser); //Deserialize the object:
return true;
}
std::function<uint32_t()> samplePubSubType::getSerializedSizeProvider(void* data) {
return [data]() -> uint32_t {
return (uint32_t)type::getCdrSerializedSize(*static_cast<sample*>(data)) + 4 /*encapsulation*/;
};
}
void* samplePubSubType::createData() {
return (void*)new sample();
}
void samplePubSubType::deleteData(void* data) {
delete((sample*)data);
}
bool samplePubSubType::getKey(void *data, InstanceHandle_t* handle) {
if(!m_isGetKeyDefined)
return false;
sample* p_type = (sample*) data;
eprosima::fastcdr::FastBuffer fastbuffer((char*)m_keyBuffer,sample::getKeyMaxCdrSerializedSize()); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); // Object that serializes the data.
p_type->serializeKey(ser);
if(sample::getKeyMaxCdrSerializedSize()>16) {
m_md5.init();
m_md5.update(m_keyBuffer,(unsigned int)ser.getSerializedDataLength());
m_md5.finalize();
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_md5.digest[i];
}
}
else {
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_keyBuffer[i];
}
}
return true;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/UserDefinedTransportExample/UserDefinedTransportExampleWriter.cpp | // 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.
#include "UserDefinedTransportExampleWriter.h"
#include <memory>
#include <fastrtps/transport/UDPv4TransportDescriptor.h>
my_WriterListener::my_WriterListener():n_matched(0){};
my_WriterListener::~my_WriterListener(){};
void my_WriterListener::onWriterMatched(RTPSWriter* writer, MatchingInfo& info)
{
if(info.status == MATCHED_MATCHING)
++n_matched;
}
void UserDefinedTransportExampleWriter::waitformatching(){
while(my_listener->n_matched == 0){}
return;
}
UserDefinedTransportExampleWriter::UserDefinedTransportExampleWriter() : my_participant(nullptr), my_writer(nullptr),
initialized_(false)
{
}
UserDefinedTransportExampleWriter::~UserDefinedTransportExampleWriter(){
if(my_participant != nullptr)
RTPSDomain::removeRTPSParticipant(my_participant);
}
void UserDefinedTransportExampleWriter::init()
{
//Creation of the participant
auto customTransport = std::make_shared<UDPv4TransportDescriptor>();
customTransport->sendBufferSize = 65536;
customTransport->receiveBufferSize = 65536;
pattr.userTransports.push_back(customTransport);
pattr.useBuiltinTransports = false;
my_participant = RTPSDomain::createParticipant(pattr);
//Creation of the Reader
my_listener = new my_WriterListener();
my_history = new WriterHistory(hattr);
my_writer= RTPSDomain::createRTPSWriter(my_participant, wattr, my_history, my_listener);
// Register type
tattr.topicKind = NO_KEY;
tattr.topicDataType = "string";
tattr.topicName = "ExampleTopic";
my_participant->registerWriter(my_writer,tattr, wqos);
initialized_ = true;
}
bool UserDefinedTransportExampleWriter::isInitialized() { return initialized_; }
void UserDefinedTransportExampleWriter::sendData(){
waitformatching();
for(int i=0;i<10;i++){
CacheChange_t * ch = my_writer->new_change([]() -> int32_t { return 255; }, ALIVE);
#if defined(_WIN32)
ch->serializedPayload.length =
sprintf_s((char*)ch->serializedPayload.data, 255, "My example string %d", i)+1;
#else
ch->serializedPayload.length =
sprintf((char*)ch->serializedPayload.data,"My example string %d",i)+1;
#endif
printf("Sending: %s\n",(char*)ch->serializedPayload.data);
my_history->add_change(ch);
}
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/UserDefinedTransportExample/CMakeLists.txt | # 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.
cmake_minimum_required(VERSION 2.8.12)
project("UserDefinedTransportExample")
# Find requirements
find_package(fastcdr REQUIRED)
find_package(fastrtps REQUIRED)
# Set C++11
include(CheckCXXCompilerFlag)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_cxx_compiler_flag(--std=c++11 SUPPORTS_CXX11)
if(SUPPORTS_CXX11)
add_compile_options(--std=c++11)
else()
message(FATAL_ERROR "Compiler doesn't support C++11")
endif()
endif()
message(STATUS "Configuring UserDefinedTransportExample...")
file(GLOB USERDEFINEDTRANSPORTEXAMPLE_SOURCES_HXX "*.cpp")
include_directories(${PROJECT_SOURCE_DIR}/../../../thirdparty/asio/asio/include)
add_executable(UserDefinedTransportExample ${USERDEFINEDTRANSPORTEXAMPLE_SOURCES_HXX})
target_link_libraries(UserDefinedTransportExample fastrtps fastcdr)
install(TARGETS UserDefinedTransportExample
RUNTIME DESTINATION examples/C++/UserDefinedTransportExample/${BIN_INSTALL_DIR})
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/UserDefinedTransportExample/UserDefinedTransportExampleReader.h | // 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.
#include <fastrtps/fastrtps_fwd.h>
#include <fastrtps/rtps/history/ReaderHistory.h>
#include <fastrtps/rtps/participant/RTPSParticipant.h>
#include <fastrtps/rtps/attributes/RTPSParticipantAttributes.h>
#include <fastrtps/rtps/reader/RTPSReader.h>
#include <fastrtps/rtps/reader/ReaderListener.h>
#include <fastrtps/rtps/attributes/ReaderAttributes.h>
#include <fastrtps/rtps/attributes/HistoryAttributes.h>
#include <fastrtps/attributes/TopicAttributes.h>
#include <fastrtps/qos/ReaderQos.h>
#include <fastrtps/rtps/RTPSDomain.h>
#include <string>
#include <list>
class my_ReaderListener: public ReaderListener
{
public:
int n_received;
my_ReaderListener();
~my_ReaderListener();
void onNewDataMessage(RTPSReader* reader, const CacheChange_t* const change);
void onReaderMatched(RTPSReader* reader,MatchingInfo& info);
};
class UserDefinedTransportExampleReader
{
private:
my_ReaderListener *my_listener;
public:
UserDefinedTransportExampleReader();
~UserDefinedTransportExampleReader();
void init();
bool isInitialized();
bool read();
private:
RTPSParticipantAttributes pattr;
RTPSParticipant *my_participant;
ReaderAttributes rattr;
RTPSReader *my_reader;
HistoryAttributes hattr;
eprosima::fastrtps::ReaderQos rqos;
eprosima::fastrtps::TopicAttributes tattr;
ReaderHistory *my_history;
bool initialized_;
};
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/UserDefinedTransportExample/Makefile | # 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.
CPP=g++
LN=g++
AR=ar
CP=cp
SYSLIBS= -ldl -lnsl -lm -lpthread -lrt
DEFINES=
COMMON_CFLAGS= -c -Wall -D__LITTLE_ENDIAN__ -std=c++11
## CHOOSE HERE BETWEEN 32 and 64 bit architecture
##32 BIT ARCH:
#COMMON_CFLAGS+= -m32 -fpic
#LDFLAGS=-m32
#64BIT ARCH:
COMMON_CFLAGS+= -m64 -fpic
LDFLAGS=-m64
CFLAGS = $(COMMON_CFLAGS) -O2
INCLUDES= -I.
LIBS = -lfastcdr -lfastrtps $(SYSLIBS)
DIRECTORIES= output.dir bin.dir
all: $(DIRECTORIES) UserDefinedTransportExample
USERDEFINEDTRANSPORTEXAMPLE_TARGET= bin/UserDefinedTransportExample
USERDEFINEDTRANSPORTEXAMPLE_SRC_CXXFILES=
USERDEFINEDTRANSPORTEXAMPLE_SRC_CPPFILES= UserDefinedTransportExample/UserDefinedTransportExampleReader.cpp \
UserDefinedTransportExample/UserDefinedTransportExampleWriter.cpp \
UserDefinedTransportExample/main.cpp
# Project sources are copied to the current directory
USERDEFINEDTRANSPORTEXAMPLE_SRCS= $(USERDEFINEDTRANSPORTEXAMPLE_SRC_CXXFILES) $(USERDEFINEDTRANSPORTEXAMPLE_SRC_CPPFILES)
# Source directories
USERDEFINEDTRANSPORTEXAMPLE_SOURCES_DIRS_AUX= $(foreach srcdir, $(dir $(USERDEFINEDTRANSPORTEXAMPLE_SRCS)), $(srcdir))
USERDEFINEDTRANSPORTEXAMPLE_SOURCES_DIRS= $(shell echo $(USERDEFINEDTRANSPORTEXAMPLE_SOURCES_DIRS_AUX) | tr " " "\n" | sort | uniq | tr "\n" " ")
USERDEFINEDTRANSPORTEXAMPLE_OBJS = $(foreach obj,$(notdir $(addsuffix .o, $(USERDEFINEDTRANSPORTEXAMPLE_SRCS))), output/$(obj))
USERDEFINEDTRANSPORTEXAMPLE_DEPS = $(foreach dep,$(notdir $(addsuffix .d, $(USERDEFINEDTRANSPORTEXAMPLE_SRCS))), output/$(dep))
OBJS+= $(USERDEFINEDTRANSPORTEXAMPLE_OBJS)
DEPS+= $(USERDEFINEDTRANSPORTEXAMPLE_DEPS)
UserDefinedTransportExample: $(USERDEFINEDTRANSPORTEXAMPLE_TARGET)
$(USERDEFINEDTRANSPORTEXAMPLE_TARGET): $(USERDEFINEDTRANSPORTEXAMPLE_OBJS)
$(LN) $(LDFLAGS) -o $(USERDEFINEDTRANSPORTEXAMPLE_TARGET) $(USERDEFINEDTRANSPORTEXAMPLE_OBJS) $(LIBS)
vpath %.cxx $(USERDEFINEDTRANSPORTEXAMPLE_SOURCES_DIRS)
vpath %.cpp $(USERDEFINEDTRANSPORTEXAMPLE_SOURCES_DIRS)
output/%.cxx.o:%.cxx
@echo Calculating dependencies $<
@$(CC) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cxx.o=%.cxx.d)
@echo Compiling $<
@$(CC) $(CFLAGS) $(INCLUDES) $< -o $@
output/%.cpp.o:%.cpp
@echo Calculating dependencies $<
@$(CPP) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cpp.o=%.cpp.d)
@echo Compiling $<
@$(CPP) $(CFLAGS) $(INCLUDES) $< -o $@
.PHONY: UserDefinedTransportExample
clean:
@rm -f $(OBJS)
@rm -f $(DEPS)
ifneq ($(MAKECMDGOALS), clean)
-include $(DEPS)
endif
%.dir :
@echo "Checking directory $*"
@if [ ! -d $* ]; then \
echo "Making directory $*"; \
mkdir -p $* ; \
fi;
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/UserDefinedTransportExample/UserDefinedTransportExampleReader.cpp | // 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.
#include "UserDefinedTransportExampleReader.h"
#include <memory>
#include <fastrtps/transport/UDPv4TransportDescriptor.h>
my_ReaderListener::my_ReaderListener() :n_received(0) {};
my_ReaderListener::~my_ReaderListener(){};
void my_ReaderListener::onNewDataMessage(RTPSReader* reader, const CacheChange_t* const change)
{
n_received++;
std::cout << "Received " << n_received << " samples so far" << std::endl;
}
void my_ReaderListener::onReaderMatched(RTPSReader* reader,MatchingInfo& info)
{
std::cout << "Matched with a Writer" << std::endl;
return;
}
UserDefinedTransportExampleReader::UserDefinedTransportExampleReader() : my_participant(nullptr), my_reader(nullptr), initialized_(false)
{
}
UserDefinedTransportExampleReader::~UserDefinedTransportExampleReader()
{
if(my_participant != nullptr)
RTPSDomain::removeRTPSParticipant(my_participant);
}
void UserDefinedTransportExampleReader::init()
{
//Creation of the participant
auto customTransport = std::make_shared<UDPv4TransportDescriptor>();
customTransport->sendBufferSize = 65536;
customTransport->receiveBufferSize = 65536;
pattr.userTransports.push_back(customTransport);
pattr.useBuiltinTransports = false;
my_participant = RTPSDomain::createParticipant(pattr);
//Creation of the Reader
my_listener = new my_ReaderListener();
my_history = new ReaderHistory(hattr);
my_reader= RTPSDomain::createRTPSReader(my_participant, rattr, my_history, my_listener);
// Register type
tattr.topicKind = NO_KEY;
tattr.topicDataType = "string";
tattr.topicName = "ExampleTopic";
my_participant->registerReader(my_reader,tattr, rqos);
initialized_ = true;
}
bool UserDefinedTransportExampleReader::read(){
while(my_listener->n_received < 9){}
return true;
}
bool UserDefinedTransportExampleReader::isInitialized() { return initialized_; }
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/UserDefinedTransportExample/UserDefinedTransportExampleWriter.h | // 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.
#include <fastrtps/fastrtps_fwd.h>
#include <fastrtps/rtps/RTPSDomain.h>
#include <fastrtps/rtps/participant/RTPSParticipant.h>
#include <fastrtps/rtps/attributes/RTPSParticipantAttributes.h>
#include <fastrtps/rtps/writer/RTPSWriter.h>
#include <fastrtps/rtps/writer/WriterListener.h>
#include <fastrtps/rtps/attributes/WriterAttributes.h>
#include <fastrtps/rtps/history/WriterHistory.h>
#include <fastrtps/rtps/attributes/HistoryAttributes.h>
#include <fastrtps/attributes/TopicAttributes.h>
#include <fastrtps/qos/WriterQos.h>
#include <string>
#include <list>
#include <stdio.h>
class my_WriterListener: public WriterListener
{
public:
my_WriterListener();
~my_WriterListener();
void onWriterMatched(RTPSWriter* writer, MatchingInfo& info);
int n_matched;
};
class UserDefinedTransportExampleWriter
{
private:
my_WriterListener *my_listener;
void waitformatching();
public:
UserDefinedTransportExampleWriter();
~UserDefinedTransportExampleWriter();
void init();
bool isInitialized();
void sendData();
private:
RTPSParticipantAttributes pattr;
RTPSParticipant *my_participant;
WriterAttributes wattr;
RTPSWriter *my_writer;
HistoryAttributes hattr;
WriterHistory *my_history;
TopicAttributes tattr;
WriterQos wqos;
bool initialized_;
};
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/UserDefinedTransportExample/main.cpp | // 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.
#include <cstring>
#include <iostream>
#include "fastrtps/rtps/RTPSDomain.h"
#include "UserDefinedTransportExampleReader.h"
#include "UserDefinedTransportExampleWriter.h"
using namespace eprosima;
using namespace fastrtps;
using namespace rtps;
using namespace std;
int main(int argc, char** argv){
if(argc > 1)
{
if(strcmp(argv[1],"Writer")==0){
UserDefinedTransportExampleWriter my_writer;
my_writer.init();
if(!my_writer.isInitialized()){
std::cout << "Unable to start a Writer" << std::endl;
return 1;
}
my_writer.sendData();
}else if(strcmp(argv[1],"Reader")==0){
UserDefinedTransportExampleReader my_reader;
my_reader.init();
if(!my_reader.isInitialized()){
std::cout << "Unable to start a Reader" << std::endl;
return 1;
}
my_reader.read();
}
}
else
{
cout << "Usage: \"UserDefinedTransportExample Writer\" or \"UserDefinedTransportExample Reader\""<<endl;
return 1;
}
RTPSDomain::stopAll();
cout << "Application exited succesfully"<<endl;
return 0;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/CMakeLists.txt | # 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.
cmake_minimum_required(VERSION 2.8.12)
project("SecureHelloWorldExample")
# Find requirements
find_package(fastcdr REQUIRED)
find_package(fastrtps REQUIRED)
# Set C++11
include(CheckCXXCompilerFlag)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_cxx_compiler_flag(--std=c++11 SUPPORTS_CXX11)
if(SUPPORTS_CXX11)
add_compile_options(--std=c++11)
else()
message(FATAL_ERROR "Compiler doesn't support C++11")
endif()
endif()
message(STATUS "Configuring SecureHelloWorld example...")
file(GLOB HELLOWORLD_EXAMPLE_SOURCES_CXX "*.cxx")
file(GLOB HELLOWORLD_EXAMPLE_SOURCES_CPP "*.cpp")
add_executable(SecureHelloWorldExample ${HELLOWORLD_EXAMPLE_SOURCES_CXX} ${HELLOWORLD_EXAMPLE_SOURCES_CPP})
target_include_directories(SecureHelloWorldExample PRIVATE)
target_link_libraries(SecureHelloWorldExample fastrtps fastcdr)
install(TARGETS SecureHelloWorldExample
RUNTIME DESTINATION examples/C++/SecureHelloWorldExample/${BIN_INSTALL_DIR})
add_custom_command(TARGET SecureHelloWorldExample POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/certs
${PROJECT_BINARY_DIR}/certs)
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/HelloWorld.idl | struct HelloWorld
{
unsigned long index;
string message;
};
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/HelloWorldPublisher.cpp | // 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 HelloWorldPublisher.cpp
*
*/
#include "HelloWorldPublisher.h"
#include <fastrtps/participant/Participant.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/attributes/PublisherAttributes.h>
#include <fastrtps/publisher/Publisher.h>
#include <fastrtps/Domain.h>
#include <fastrtps/utils/eClock.h>
HelloWorldPublisher::HelloWorldPublisher():mp_participant(nullptr),
mp_publisher(nullptr)
{
}
bool HelloWorldPublisher::init()
{
m_Hello.index(0);
m_Hello.message("HelloWorld");
ParticipantAttributes PParam;
PropertyPolicy participant_property_policy;
participant_property_policy.properties().emplace_back("dds.sec.auth.plugin",
"builtin.PKI-DH");
participant_property_policy.properties().emplace_back("dds.sec.auth.builtin.PKI-DH.identity_ca",
"file://certs/maincacert.pem");
participant_property_policy.properties().emplace_back("dds.sec.auth.builtin.PKI-DH.identity_certificate",
"file://certs/mainpubcert.pem");
participant_property_policy.properties().emplace_back("dds.sec.auth.builtin.PKI-DH.private_key",
"file://certs/mainpubkey.pem");
participant_property_policy.properties().emplace_back("dds.sec.crypto.plugin",
"builtin.AES-GCM-GMAC");
participant_property_policy.properties().emplace_back("rtps.participant.rtps_protection_kind", "ENCRYPT");
PParam.rtps.properties = participant_property_policy;
mp_participant = Domain::createParticipant(PParam);
if(mp_participant==nullptr)
return false;
//REGISTER THE TYPE
Domain::registerType(mp_participant,&m_type);
//CREATE THE PUBLISHER
PublisherAttributes Wparam;
Wparam.topic.topicKind = NO_KEY;
Wparam.topic.topicDataType = "HelloWorld";
Wparam.topic.topicName = "HelloWorldTopic";
Wparam.topic.historyQos.kind = KEEP_LAST_HISTORY_QOS;
Wparam.topic.historyQos.depth = 30;
Wparam.topic.resourceLimitsQos.max_samples = 50;
Wparam.topic.resourceLimitsQos.allocated_samples = 20;
Wparam.times.heartbeatPeriod.seconds = 2;
Wparam.times.heartbeatPeriod.fraction = 200*1000*1000;
Wparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
PropertyPolicy publisher_property_policy;
publisher_property_policy.properties().emplace_back("rtps.endpoint.submessage_protection_kind", "ENCRYPT");
publisher_property_policy.properties().emplace_back("rtps.endpoint.payload_protection_kind", "ENCRYPT");
Wparam.properties = publisher_property_policy;
mp_publisher = Domain::createPublisher(mp_participant,Wparam,(PublisherListener*)&m_listener);
if(mp_publisher == nullptr)
return false;
return true;
}
HelloWorldPublisher::~HelloWorldPublisher()
{
// TODO Auto-generated destructor stub
Domain::removeParticipant(mp_participant);
}
void HelloWorldPublisher::PubListener::onPublicationMatched(Publisher* /*pub*/,MatchingInfo& info)
{
if(info.status == MATCHED_MATCHING)
{
n_matched++;
std::cout << "Publisher matched"<<std::endl;
}
else
{
n_matched--;
std::cout << "Publisher unmatched"<<std::endl;
}
}
void HelloWorldPublisher::run(uint32_t samples)
{
for(uint32_t i = 0;i<samples;++i)
{
if(!publish())
--i;
else
{
std::cout << "Message: "<<m_Hello.message()<< " with index: "<< m_Hello.index()<< " SENT"<<std::endl;
}
}
}
bool HelloWorldPublisher::publish()
{
if(m_listener.n_matched>0)
{
m_Hello.index(m_Hello.index()+1);
mp_publisher->write((void*)&m_Hello);
return true;
}
return false;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/Makefile | # 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.
CPP=g++
LN=g++
AR=ar
CP=cp
SYSLIBS= -ldl -lnsl -lm -lpthread -lrt
DEFINES=
COMMON_CFLAGS= -c -Wall -D__LITTLE_ENDIAN__ -std=c++11
## CHOOSE HERE BETWEEN 32 and 64 bit architecture
##32 BIT ARCH:
#COMMON_CFLAGS+= -m32 -fpic
#LDFLAGS=-m32
#64BIT ARCH:
COMMON_CFLAGS+= -m64 -fpic
LDFLAGS=-m64
CFLAGS = $(COMMON_CFLAGS) -O2
INCLUDES= -I.
LIBS = -lfastcdr -lfastrtps $(SYSLIBS)
DIRECTORIES= output.dir bin.dir
all: $(DIRECTORIES) CopyCerts SecureHelloWorldExample
HELLOWORLDEXAMPLE_TARGET= bin/SecureHelloWorldExample
HELLOWORLDEXAMPLE_SRC_CXXFILES=
HELLOWORLDEXAMPLE_SRC_CPPFILES= SecureHelloWorldExample/HelloWorld.cxx \
SecureHelloWorldExample/HelloWorldPubSubTypes.cxx \
SecureHelloWorldExample/HelloWorldPublisher.cpp \
SecureHelloWorldExample/HelloWorldSubscriber.cpp \
SecureHelloWorldExample/HelloWorld_main.cpp
# Project sources are copied to the current directory
HELLOWORLDEXAMPLE_SRCS= $(HELLOWORLDEXAMPLE_SRC_CXXFILES) $(HELLOWORLDEXAMPLE_SRC_CPPFILES)
# Source directories
HELLOWORLDEXAMPLE_SOURCES_DIRS_AUX= $(foreach srcdir, $(dir $(HELLOWORLDEXAMPLE_SRCS)), $(srcdir))
HELLOWORLDEXAMPLE_SOURCES_DIRS= $(shell echo $(HELLOWORLDEXAMPLE_SOURCES_DIRS_AUX) | tr " " "\n" | sort | uniq | tr "\n" " ")
HELLOWORLDEXAMPLE_OBJS = $(foreach obj,$(notdir $(addsuffix .o, $(HELLOWORLDEXAMPLE_SRCS))), output/$(obj))
HELLOWORLDEXAMPLE_DEPS = $(foreach dep,$(notdir $(addsuffix .d, $(HELLOWORLDEXAMPLE_SRCS))), output/$(dep))
OBJS+= $(HELLOWORLDEXAMPLE_OBJS)
DEPS+= $(HELLOWORLDEXAMPLE_DEPS)
SecureHelloWorldExample: $(HELLOWORLDEXAMPLE_TARGET)
$(HELLOWORLDEXAMPLE_TARGET): $(HELLOWORLDEXAMPLE_OBJS)
$(LN) $(LDFLAGS) -o $(HELLOWORLDEXAMPLE_TARGET) $(HELLOWORLDEXAMPLE_OBJS) $(LIBS)
vpath %.cxx $(HELLOWORLDEXAMPLE_SOURCES_DIRS)
vpath %.cpp $(HELLOWORLDEXAMPLE_SOURCES_DIRS)
output/%.cxx.o:%.cxx
@echo Calculating dependencies $<
@$(CC) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cxx.o=%.cxx.d)
@echo Compiling $<
@$(CC) $(CFLAGS) $(INCLUDES) $< -o $@
output/%.cpp.o:%.cpp
@echo Calculating dependencies $<
@$(CPP) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cpp.o=%.cpp.d)
@echo Compiling $<
@$(CPP) $(CFLAGS) $(INCLUDES) $< -o $@
.PHONY: CopyCerts SecureHelloWorldExample
CopyCerts: $(DIRECTORIES)
@echo Copying certificates to binary directory
@cp certs/*.pem bin/
clean:
@rm -f $(OBJS)
@rm -f $(DEPS)
ifneq ($(MAKECMDGOALS), clean)
-include $(DEPS)
endif
%.dir :
@echo "Checking directory $*"
@if [ ! -d $* ]; then \
echo "Making directory $*"; \
mkdir -p $* ; \
fi;
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/HelloWorld.h | // 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 HelloWorld.h
* This header file contains the declaration of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/
#ifndef _HelloWorld_H_
#define _HelloWorld_H_
// TODO Poner en el contexto.
#include <stdint.h>
#include <array>
#include <string>
#include <vector>
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#define eProsima_user_DllExport __declspec( dllexport )
#else
#define eProsima_user_DllExport
#endif
#else
#define eProsima_user_DllExport
#endif
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#if defined(HelloWorld_SOURCE)
#define HelloWorld_DllAPI __declspec( dllexport )
#else
#define HelloWorld_DllAPI __declspec( dllimport )
#endif // HelloWorld_SOURCE
#else
#define HelloWorld_DllAPI
#endif
#else
#define HelloWorld_DllAPI
#endif // _WIN32
namespace eprosima
{
namespace fastcdr
{
class Cdr;
}
}
/*!
* @brief This class represents the structure HelloWorld defined by the user in the IDL file.
* @ingroup HELLOWORLD
*/
class HelloWorld
{
public:
/*!
* @brief Default constructor.
*/
eProsima_user_DllExport HelloWorld();
/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~HelloWorld();
/*!
* @brief Copy constructor.
* @param x Reference to the object HelloWorld that will be copied.
*/
eProsima_user_DllExport HelloWorld(const HelloWorld &x);
/*!
* @brief Move constructor.
* @param x Reference to the object HelloWorld that will be copied.
*/
eProsima_user_DllExport HelloWorld(HelloWorld &&x);
/*!
* @brief Copy assignment.
* @param x Reference to the object HelloWorld that will be copied.
*/
eProsima_user_DllExport HelloWorld& operator=(const HelloWorld &x);
/*!
* @brief Move assignment.
* @param x Reference to the object HelloWorld that will be copied.
*/
eProsima_user_DllExport HelloWorld& operator=(HelloWorld &&x);
/*!
* @brief This function sets a value in member index
* @param _index New value for member index
*/
inline 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
*/
inline eProsima_user_DllExport uint32_t index() const
{
return m_index;
}
/*!
* @brief This function returns a reference to member index
* @return Reference to member index
*/
inline eProsima_user_DllExport uint32_t& index()
{
return m_index;
}
/*!
* @brief This function copies the value in member message
* @param _message New value to be copied in member message
*/
inline eProsima_user_DllExport void message(const std::string &_message)
{
m_message = _message;
}
/*!
* @brief This function moves the value in member message
* @param _message New value to be moved in member message
*/
inline eProsima_user_DllExport void message(std::string &&_message)
{
m_message = std::move(_message);
}
/*!
* @brief This function returns a constant reference to member message
* @return Constant reference to member message
*/
inline eProsima_user_DllExport const std::string& message() const
{
return m_message;
}
/*!
* @brief This function returns a reference to member message
* @return Reference to member message
*/
inline eProsima_user_DllExport std::string& message()
{
return m_message;
}
/*!
* @brief This function returns the maximum serialized size of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getMaxCdrSerializedSize(size_t current_alignment = 0);
/*!
* @brief This function returns the serialized size of a data depending on the buffer alignment.
* @param data Data which is calculated its serialized size.
* @param current_alignment Buffer alignment.
* @return Serialized size.
*/
eProsima_user_DllExport static size_t getCdrSerializedSize(const HelloWorld& data, size_t current_alignment = 0);
/*!
* @brief This function serializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serialize(eprosima::fastcdr::Cdr &cdr) const;
/*!
* @brief This function deserializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void deserialize(eprosima::fastcdr::Cdr &cdr);
/*!
* @brief This function returns the maximum serialized size of the Key of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize(size_t current_alignment = 0);
/*!
* @brief This function tells you if the Key has been defined for this type
*/
eProsima_user_DllExport static bool isKeyDefined();
/*!
* @brief This function serializes the key members of an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const;
private:
uint32_t m_index;
std::string m_message;
};
#endif // _HelloWorld_H_ | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/HelloWorldPubSubTypes.cxx | // 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 HelloWorldPubSubTypes.cpp
* This header file contains the implementation of the serialization functions.
*
* This file was generated by the tool fastcdrgen.
*/
#include <fastcdr/FastBuffer.h>
#include <fastcdr/Cdr.h>
#include "HelloWorldPubSubTypes.h"
HelloWorldPubSubType::HelloWorldPubSubType() {
setName("HelloWorld");
m_typeSize = (uint32_t)HelloWorld::getMaxCdrSerializedSize() + 4 /*encapsulation*/;
m_isGetKeyDefined = HelloWorld::isKeyDefined();
m_keyBuffer = (unsigned char*)malloc(HelloWorld::getKeyMaxCdrSerializedSize()>16 ? HelloWorld::getKeyMaxCdrSerializedSize() : 16);
}
HelloWorldPubSubType::~HelloWorldPubSubType() {
if(m_keyBuffer!=nullptr)
free(m_keyBuffer);
}
bool HelloWorldPubSubType::serialize(void *data, SerializedPayload_t *payload) {
HelloWorld *p_type = (HelloWorld*) data;
eprosima::fastcdr::FastBuffer fastbuffer((char*) payload->data, payload->max_size); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);
payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
// Serialize encapsulation
ser.serialize_encapsulation();
p_type->serialize(ser); // Serialize the object:
payload->length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length
return true;
}
bool HelloWorldPubSubType::deserialize(SerializedPayload_t* payload, void* data) {
HelloWorld* p_type = (HelloWorld*) data; //Convert DATA to pointer of your type
eprosima::fastcdr::FastBuffer fastbuffer((char*)payload->data, payload->length); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR); // Object that deserializes the data.
// Deserialize encapsulation.
deser.read_encapsulation();
payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
p_type->deserialize(deser); //Deserialize the object:
return true;
}
std::function<uint32_t()> HelloWorldPubSubType::getSerializedSizeProvider(void* data) {
return [data]() -> uint32_t {
return (uint32_t)type::getCdrSerializedSize(*static_cast<HelloWorld*>(data)) + 4 /*encapsulation*/;
};
}
void* HelloWorldPubSubType::createData() {
return (void*)new HelloWorld();
}
void HelloWorldPubSubType::deleteData(void* data) {
delete((HelloWorld*)data);
}
bool HelloWorldPubSubType::getKey(void *data, InstanceHandle_t* handle) {
if(!m_isGetKeyDefined)
return false;
HelloWorld* p_type = (HelloWorld*) data;
eprosima::fastcdr::FastBuffer fastbuffer((char*)m_keyBuffer,HelloWorld::getKeyMaxCdrSerializedSize()); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); // Object that serializes the data.
p_type->serializeKey(ser);
if(HelloWorld::getKeyMaxCdrSerializedSize()>16) {
m_md5.init();
m_md5.update(m_keyBuffer,(unsigned int)ser.getSerializedDataLength());
m_md5.finalize();
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_md5.digest[i];
}
}
else {
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_keyBuffer[i];
}
}
return true;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/HelloWorldSubscriber.cpp | // 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 HelloWorldSubscriber.cpp
*
*/
#include "HelloWorldSubscriber.h"
#include <fastrtps/participant/Participant.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/attributes/SubscriberAttributes.h>
#include <fastrtps/subscriber/Subscriber.h>
#include <fastrtps/Domain.h>
#include <fastrtps/utils/eClock.h>
HelloWorldSubscriber::HelloWorldSubscriber():mp_participant(nullptr),
mp_subscriber(nullptr)
{
}
bool HelloWorldSubscriber::init()
{
ParticipantAttributes PParam;
PropertyPolicy participant_property_policy;
participant_property_policy.properties().emplace_back("dds.sec.auth.plugin",
"builtin.PKI-DH");
participant_property_policy.properties().emplace_back("dds.sec.auth.builtin.PKI-DH.identity_ca",
"file://certs/maincacert.pem");
participant_property_policy.properties().emplace_back("dds.sec.auth.builtin.PKI-DH.identity_certificate",
"file://certs/mainsubcert.pem");
participant_property_policy.properties().emplace_back("dds.sec.auth.builtin.PKI-DH.private_key",
"file://certs/mainsubkey.pem");
participant_property_policy.properties().emplace_back("dds.sec.crypto.plugin",
"builtin.AES-GCM-GMAC");
participant_property_policy.properties().emplace_back("rtps.participant.rtps_protection_kind", "ENCRYPT");
PParam.rtps.properties = participant_property_policy;
mp_participant = Domain::createParticipant(PParam);
if(mp_participant==nullptr)
return false;
//REGISTER THE TYPE
Domain::registerType(mp_participant,&m_type);
//CREATE THE SUBSCRIBER
SubscriberAttributes Rparam;
Rparam.topic.topicKind = NO_KEY;
Rparam.topic.topicDataType = "HelloWorld";
Rparam.topic.topicName = "HelloWorldTopic";
Rparam.topic.historyQos.kind = KEEP_LAST_HISTORY_QOS;
Rparam.topic.historyQos.depth = 30;
Rparam.topic.resourceLimitsQos.max_samples = 50;
Rparam.topic.resourceLimitsQos.allocated_samples = 20;
Rparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
PropertyPolicy subscriber_property_policy;
subscriber_property_policy.properties().emplace_back("rtps.endpoint.submessage_protection_kind", "ENCRYPT");
subscriber_property_policy.properties().emplace_back("rtps.endpoint.payload_protection_kind", "ENCRYPT");
Rparam.properties = subscriber_property_policy;
mp_subscriber = Domain::createSubscriber(mp_participant,Rparam,(SubscriberListener*)&m_listener);
if(mp_subscriber == nullptr)
return false;
return true;
}
HelloWorldSubscriber::~HelloWorldSubscriber() {
// TODO Auto-generated destructor stub
Domain::removeParticipant(mp_participant);
}
void HelloWorldSubscriber::SubListener::onSubscriptionMatched(Subscriber* /*sub*/,MatchingInfo& info)
{
if(info.status == MATCHED_MATCHING)
{
n_matched++;
std::cout << "Subscriber matched"<<std::endl;
}
else
{
n_matched--;
std::cout << "Subscriber unmatched"<<std::endl;
}
}
void HelloWorldSubscriber::SubListener::onNewDataMessage(Subscriber* sub)
{
if(sub->takeNextData((void*)&m_Hello, &m_info))
{
if(m_info.sampleKind == ALIVE)
{
this->n_samples++;
// Print your structure data here.
std::cout << "Message "<<m_Hello.message()<< " "<< m_Hello.index()<< " RECEIVED"<<std::endl;
}
}
}
void HelloWorldSubscriber::run()
{
std::cout << "Subscriber running. Please press enter to stop the Subscriber" << std::endl;
std::cin.ignore();
}
void HelloWorldSubscriber::run(uint32_t number)
{
std::cout << "Subscriber running until "<< number << "samples have been received"<<std::endl;
while(number < this->m_listener.n_samples)
eClock::my_sleep(500);
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/HelloWorld.cxx | // 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 HelloWorld.cpp
* This source file contains the definition of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/
#ifdef _WIN32
// Remove linker warning LNK4221 on Visual Studio
namespace { char dummy; }
#endif
#include "HelloWorld.h"
#include <fastcdr/Cdr.h>
#include <fastcdr/exceptions/BadParamException.h>
using namespace eprosima::fastcdr::exception;
#include <utility>
HelloWorld::HelloWorld()
{
m_index = 0;
}
HelloWorld::~HelloWorld()
{
}
HelloWorld::HelloWorld(const HelloWorld &x)
{
m_index = x.m_index;
m_message = x.m_message;
}
HelloWorld::HelloWorld(HelloWorld &&x)
{
m_index = x.m_index;
m_message = std::move(x.m_message);
}
HelloWorld& HelloWorld::operator=(const HelloWorld &x)
{
m_index = x.m_index;
m_message = x.m_message;
return *this;
}
HelloWorld& HelloWorld::operator=(HelloWorld &&x)
{
m_index = x.m_index;
m_message = std::move(x.m_message);
return *this;
}
size_t HelloWorld::getMaxCdrSerializedSize(size_t current_alignment)
{
size_t initial_alignment = current_alignment;
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1;
return current_alignment - initial_alignment;
}
size_t HelloWorld::getCdrSerializedSize(const HelloWorld& data, size_t current_alignment)
{
size_t initial_alignment = current_alignment;
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.message().size() + 1;
return current_alignment - initial_alignment;
}
void HelloWorld::serialize(eprosima::fastcdr::Cdr &scdr) const
{
scdr << m_index;
if(m_message.length() <= 255)
scdr << m_message;
else
throw eprosima::fastcdr::exception::BadParamException("message field exceeds the maximum length");
}
void HelloWorld::deserialize(eprosima::fastcdr::Cdr &dcdr)
{
dcdr >> m_index;
dcdr >> m_message;
}
size_t HelloWorld::getKeyMaxCdrSerializedSize(size_t current_alignment)
{
size_t current_align = current_alignment;
return current_align;
}
bool HelloWorld::isKeyDefined()
{
return false;
}
void HelloWorld::serializeKey(eprosima::fastcdr::Cdr &scdr) const
{
} | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/HelloWorldPublisher.h | // 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 HelloWorldPublisher.h
*
*/
#ifndef HELLOWORLDPUBLISHER_H_
#define HELLOWORLDPUBLISHER_H_
#include "HelloWorldPubSubTypes.h"
#include <fastrtps/fastrtps_fwd.h>
#include <fastrtps/attributes/PublisherAttributes.h>
#include <fastrtps/publisher/PublisherListener.h>
using namespace eprosima::fastrtps;
#include "HelloWorld.h"
class HelloWorldPublisher {
public:
HelloWorldPublisher();
virtual ~HelloWorldPublisher();
//!Initialize
bool init();
//!Publish a sample
bool publish();
//!Run for number samples
void run(uint32_t number);
private:
HelloWorld m_Hello;
Participant* mp_participant;
Publisher* mp_publisher;
class PubListener:public PublisherListener
{
public:
PubListener():n_matched(0){};
~PubListener(){};
void onPublicationMatched(Publisher* pub,MatchingInfo& info);
int n_matched;
}m_listener;
HelloWorldPubSubType m_type;
};
#endif /* HELLOWORLDPUBLISHER_H_ */
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/HelloWorldSubscriber.h | // 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 HelloWorldSubscriber.h
*
*/
#ifndef HELLOWORLDSUBSCRIBER_H_
#define HELLOWORLDSUBSCRIBER_H_
#include "HelloWorldPubSubTypes.h"
#include <fastrtps/fastrtps_fwd.h>
#include <fastrtps/attributes/SubscriberAttributes.h>
#include <fastrtps/subscriber/SubscriberListener.h>
#include <fastrtps/subscriber/SampleInfo.h>
using namespace eprosima::fastrtps;
#include "HelloWorld.h"
class HelloWorldSubscriber {
public:
HelloWorldSubscriber();
virtual ~HelloWorldSubscriber();
//!Initialize the subscriber
bool init();
//!RUN the subscriber
void run();
//!Run the subscriber until number samples have been recevied.
void run(uint32_t number);
private:
Participant* mp_participant;
Subscriber* mp_subscriber;
public:
class SubListener:public SubscriberListener
{
public:
SubListener():n_matched(0),n_samples(0){};
~SubListener(){};
void onSubscriptionMatched(Subscriber* sub,MatchingInfo& info);
void onNewDataMessage(Subscriber* sub);
HelloWorld m_Hello;
SampleInfo_t m_info;
int n_matched;
uint32_t n_samples;
}m_listener;
private:
HelloWorldPubSubType m_type;
};
#endif /* HELLOWORLDSUBSCRIBER_H_ */
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/HelloWorldPubSubTypes.h | // 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 HelloWorldPubSubTypes.h
* This header file contains the declaration of the serialization functions.
*
* This file was generated by the tool fastcdrgen.
*/
#ifndef _HELLOWORLD_PUBSUBTYPES_H_
#define _HELLOWORLD_PUBSUBTYPES_H_
#include <fastrtps/TopicDataType.h>
using namespace eprosima::fastrtps;
#include "HelloWorld.h"
/*!
* @brief This class represents the TopicDataType of the type HelloWorld defined by the user in the IDL file.
* @ingroup HELLOWORLD
*/
class HelloWorldPubSubType : public TopicDataType {
public:
typedef HelloWorld type;
HelloWorldPubSubType();
virtual ~HelloWorldPubSubType();
bool serialize(void *data, SerializedPayload_t *payload);
bool deserialize(SerializedPayload_t *payload, void *data);
std::function<uint32_t()> getSerializedSizeProvider(void* data);
bool getKey(void *data, InstanceHandle_t *ihandle);
void* createData();
void deleteData(void * data);
MD5 m_md5;
unsigned char* m_keyBuffer;
};
#endif // _HelloWorld_PUBSUBTYPE_H_ | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/README.txt | To launch this test open two different consoles:
In the first one launch: HelloWorldExample publisher (or HelloWorldExample.exe publisher on windows).
In the second one: HelloWorldExample subscriber.
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/HelloWorld_main.cpp | // 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 HelloWorld_main.cpp
*
*/
#include "HelloWorldPublisher.h"
#include "HelloWorldSubscriber.h"
#include <fastrtps/Domain.h>
#include <fastrtps/utils/eClock.h>
#include <fastrtps/log/Log.h>
#include <fastrtps/rtps/rtps_all.h>
using namespace eprosima;
using namespace fastrtps;
using namespace rtps;
int main(int argc, char** argv)
{
std::cout << "Starting "<< std::endl;
int type = 1;
if(argc > 1)
{
if(strcmp(argv[1],"publisher")==0)
type = 1;
else if(strcmp(argv[1],"subscriber")==0)
type = 2;
}
else
{
std::cout << "publisher OR subscriber argument needed"<<std::endl;
Log::Reset();
return 0;
}
//Log::SetVerbosity(Log::Info);
//Log::SetCategoryFilter(std::regex("(SECURITY)"));
switch(type)
{
case 1:
{
HelloWorldPublisher mypub;
if(mypub.init())
{
mypub.run(10);
}
break;
}
case 2:
{
HelloWorldSubscriber mysub;
if(mysub.init())
{
mysub.run();
}
break;
}
}
Domain::stopAll();
Log::Reset();
return 0;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/certs/mainsubcert.pem | Certificate:
Data:
Version: 1 (0x0)
Serial Number: 4 (0x4)
Signature Algorithm: ecdsa-with-SHA256
Issuer: C=ES, ST=MA, L=Tres Cantos, O=eProsima, CN=eProsima Main Test CA/emailAddress=mainca@eprosima.com
Validity
Not Before: Jan 13 10:56:04 2017 GMT
Not After : Jan 11 10:56:04 2027 GMT
Subject: C=ES, ST=MA, O=eProsima, CN=Main Subscriber/emailAddress=mainsub@eprosima.com
Subject Public Key Info:
Public Key Algorithm: id-ecPublicKey
Public-Key: (256 bit)
pub:
04:b2:3a:08:d6:13:6f:24:01:84:b5:8e:8a:03:85:
c3:ff:69:73:71:4b:7d:48:ba:b0:d6:c9:da:19:05:
fd:2b:82:74:ff:28:27:4f:19:ad:b5:10:21:ad:b7:
cf:55:4c:dc:76:af:d6:c1:ba:71:f5:d1:f6:c5:ed:
0f:8c:c7:32:53
ASN1 OID: prime256v1
NIST CURVE: P-256
Signature Algorithm: ecdsa-with-SHA256
30:45:02:20:41:ef:44:b7:ae:0e:59:f4:85:c5:bc:c9:c1:97:
a7:d8:d0:73:c6:c9:c8:db:76:d7:26:39:f7:38:72:7b:16:e5:
02:21:00:b0:d0:a0:d0:2e:fb:a6:be:dd:e7:18:0d:3a:d8:16:
48:d3:c8:f6:b7:cd:1b:ab:ec:43:6a:4a:2c:46:72:3f:1b
-----BEGIN CERTIFICATE-----
MIIB3DCCAYICAQQwCgYIKoZIzj0EAwIwgYcxCzAJBgNVBAYTAkVTMQswCQYDVQQI
DAJNQTEUMBIGA1UEBwwLVHJlcyBDYW50b3MxETAPBgNVBAoMCGVQcm9zaW1hMR4w
HAYDVQQDDBVlUHJvc2ltYSBNYWluIFRlc3QgQ0ExIjAgBgkqhkiG9w0BCQEWE21h
aW5jYUBlcHJvc2ltYS5jb20wHhcNMTcwMTEzMTA1NjA0WhcNMjcwMTExMTA1NjA0
WjBsMQswCQYDVQQGEwJFUzELMAkGA1UECAwCTUExETAPBgNVBAoMCGVQcm9zaW1h
MRgwFgYDVQQDDA9NYWluIFN1YnNjcmliZXIxIzAhBgkqhkiG9w0BCQEWFG1haW5z
dWJAZXByb3NpbWEuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEsjoI1hNv
JAGEtY6KA4XD/2lzcUt9SLqw1snaGQX9K4J0/ygnTxmttRAhrbfPVUzcdq/Wwbpx
9dH2xe0PjMcyUzAKBggqhkjOPQQDAgNIADBFAiBB70S3rg5Z9IXFvMnBl6fY0HPG
ycjbdtcmOfc4cnsW5QIhALDQoNAu+6a+3ecYDTrYFkjTyPa3zRur7ENqSixGcj8b
-----END CERTIFICATE-----
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/certs/mainpubkey.pem | -----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgcaE/ImRrmNmlwVK1
k2XGGdTbF7r+cTcUIu/UNGWlPQuhRANCAARf6MbUrquzCq+QUjLCWR89+lrp/3Nn
WSrWW69p9XoLQr/RaHjcl4GwudcE7p7xhRBhZ9Aq9i7Rb0MBSa4L2fjb
-----END PRIVATE KEY-----
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/certs/maincacert.pem | -----BEGIN CERTIFICATE-----
MIICADCCAaYCCQCdSuCeL23ASzAKBggqhkjOPQQDAjCBhzELMAkGA1UEBhMCRVMx
CzAJBgNVBAgMAk1BMRQwEgYDVQQHDAtUcmVzIENhbnRvczERMA8GA1UECgwIZVBy
b3NpbWExHjAcBgNVBAMMFWVQcm9zaW1hIE1haW4gVGVzdCBDQTEiMCAGCSqGSIb3
DQEJARYTbWFpbmNhQGVwcm9zaW1hLmNvbTAeFw0xNjEwMTAwODUyMzJaFw0yNjEw
MDgwODUyMzJaMIGHMQswCQYDVQQGEwJFUzELMAkGA1UECAwCTUExFDASBgNVBAcM
C1RyZXMgQ2FudG9zMREwDwYDVQQKDAhlUHJvc2ltYTEeMBwGA1UEAwwVZVByb3Np
bWEgTWFpbiBUZXN0IENBMSIwIAYJKoZIhvcNAQkBFhNtYWluY2FAZXByb3NpbWEu
Y29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEUGJ6UEKcc6gyhcfCSxkR5XMl
zJDH3zPDBkstKoupzbqs5xmNmJ0NwhZSGCdtajN0moYXA3sJ0guxWxfzufvfOjAK
BggqhkjOPQQDAgNIADBFAiA6ZflfRbTEylCUl9swqcKbfZK5yZ1nGsChgb3N5GTy
HQIhAJquZQHhg/wz2NzyKuTigpGbjrc47vakqTYxylt8RDnJ
-----END CERTIFICATE-----
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/certs/mainpubcert.pem | Certificate:
Data:
Version: 1 (0x0)
Serial Number: 1 (0x1)
Signature Algorithm: ecdsa-with-SHA256
Issuer: C=ES, ST=MA, L=Tres Cantos, O=eProsima, CN=eProsima Main Test CA/emailAddress=mainca@eprosima.com
Validity
Not Before: Oct 10 08:56:59 2016 GMT
Not After : Oct 8 08:56:59 2026 GMT
Subject: C=ES, ST=MA, O=eProsima, CN=Main Publisher/emailAddress=mainpub@eprosima.com
Subject Public Key Info:
Public Key Algorithm: id-ecPublicKey
Public-Key: (256 bit)
pub:
04:5f:e8:c6:d4:ae:ab:b3:0a:af:90:52:32:c2:59:
1f:3d:fa:5a:e9:ff:73:67:59:2a:d6:5b:af:69:f5:
7a:0b:42:bf:d1:68:78:dc:97:81:b0:b9:d7:04:ee:
9e:f1:85:10:61:67:d0:2a:f6:2e:d1:6f:43:01:49:
ae:0b:d9:f8:db
ASN1 OID: prime256v1
NIST CURVE: P-256
Signature Algorithm: ecdsa-with-SHA256
30:46:02:21:00:a4:67:71:cd:cb:10:44:7a:a5:e4:f4:8a:1b:
65:f4:8d:97:0c:36:7c:cf:d3:34:25:b0:94:0c:0e:13:77:0b:
a6:02:21:00:fd:9c:5c:47:89:ff:e4:1c:1e:7a:cd:71:68:47:
f9:57:6a:d1:84:71:1f:d4:45:28:0e:84:7f:d9:33:b3:89:ee
-----BEGIN CERTIFICATE-----
MIIB3DCCAYECAQEwCgYIKoZIzj0EAwIwgYcxCzAJBgNVBAYTAkVTMQswCQYDVQQI
DAJNQTEUMBIGA1UEBwwLVHJlcyBDYW50b3MxETAPBgNVBAoMCGVQcm9zaW1hMR4w
HAYDVQQDDBVlUHJvc2ltYSBNYWluIFRlc3QgQ0ExIjAgBgkqhkiG9w0BCQEWE21h
aW5jYUBlcHJvc2ltYS5jb20wHhcNMTYxMDEwMDg1NjU5WhcNMjYxMDA4MDg1NjU5
WjBrMQswCQYDVQQGEwJFUzELMAkGA1UECAwCTUExETAPBgNVBAoMCGVQcm9zaW1h
MRcwFQYDVQQDDA5NYWluIFB1Ymxpc2hlcjEjMCEGCSqGSIb3DQEJARYUbWFpbnB1
YkBlcHJvc2ltYS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARf6MbUrquz
Cq+QUjLCWR89+lrp/3NnWSrWW69p9XoLQr/RaHjcl4GwudcE7p7xhRBhZ9Aq9i7R
b0MBSa4L2fjbMAoGCCqGSM49BAMCA0kAMEYCIQCkZ3HNyxBEeqXk9IobZfSNlww2
fM/TNCWwlAwOE3cLpgIhAP2cXEeJ/+QcHnrNcWhH+Vdq0YRxH9RFKA6Ef9kzs4nu
-----END CERTIFICATE-----
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/SecureHelloWorldExample/certs/mainsubkey.pem | -----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgzpO/H2ao5ztIrcRM
GRhAsD2Mey+SKpL6Yz+64XTPtAmhRANCAASyOgjWE28kAYS1jooDhcP/aXNxS31I
urDWydoZBf0rgnT/KCdPGa21ECGtt89VTNx2r9bBunH10fbF7Q+MxzJT
-----END PRIVATE KEY-----
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HelloWorldExample/CMakeLists.txt | # 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.
cmake_minimum_required(VERSION 2.8.12)
project("HelloWorldExample")
# Find requirements
find_package(fastcdr REQUIRED)
find_package(fastrtps REQUIRED)
# Set C++11
include(CheckCXXCompilerFlag)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_cxx_compiler_flag(--std=c++11 SUPPORTS_CXX11)
if(SUPPORTS_CXX11)
add_compile_options(--std=c++11)
else()
message(FATAL_ERROR "Compiler doesn't support C++11")
endif()
endif()
message(STATUS "Configuring HelloWorld example...")
file(GLOB HELLOWORLD_EXAMPLE_SOURCES_CXX "*.cxx")
file(GLOB HELLOWORLD_EXAMPLE_SOURCES_CPP "*.cpp")
add_executable(HelloWorldExample ${HELLOWORLD_EXAMPLE_SOURCES_CXX} ${HELLOWORLD_EXAMPLE_SOURCES_CPP})
target_link_libraries(HelloWorldExample fastrtps fastcdr)
install(TARGETS HelloWorldExample
RUNTIME DESTINATION examples/C++/HelloWorldExample/${BIN_INSTALL_DIR})
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HelloWorldExample/HelloWorld.idl | struct HelloWorld
{
unsigned long index;
string message;
};
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HelloWorldExample/HelloWorldPublisher.cpp | // 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 HelloWorldPublisher.cpp
*
*/
#include "HelloWorldPublisher.h"
#include <fastrtps/participant/Participant.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/attributes/PublisherAttributes.h>
#include <fastrtps/publisher/Publisher.h>
#include <fastrtps/Domain.h>
#include <fastrtps/utils/eClock.h>
HelloWorldPublisher::HelloWorldPublisher():mp_participant(nullptr),
mp_publisher(nullptr)
{
}
bool HelloWorldPublisher::init()
{
m_Hello.index(0);
m_Hello.message("HelloWorld");
ParticipantAttributes PParam;
PParam.rtps.defaultSendPort = 11511;
PParam.rtps.use_IP6_to_send = true;
PParam.rtps.builtin.use_SIMPLE_RTPSParticipantDiscoveryProtocol = true;
PParam.rtps.builtin.use_SIMPLE_EndpointDiscoveryProtocol = true;
PParam.rtps.builtin.m_simpleEDP.use_PublicationReaderANDSubscriptionWriter = true;
PParam.rtps.builtin.m_simpleEDP.use_PublicationWriterANDSubscriptionReader = true;
PParam.rtps.builtin.domainId = 80;
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
PParam.rtps.setName("Participant_pub");
mp_participant = Domain::createParticipant(PParam);
if(mp_participant==nullptr)
return false;
//REGISTER THE TYPE
Domain::registerType(mp_participant,&m_type);
//CREATE THE PUBLISHER
PublisherAttributes Wparam;
Wparam.topic.topicKind = NO_KEY;
Wparam.topic.topicDataType = "HelloWorld";
Wparam.topic.topicName = "HelloWorldTopic";
Wparam.topic.historyQos.kind = KEEP_LAST_HISTORY_QOS;
Wparam.topic.historyQos.depth = 30;
Wparam.topic.resourceLimitsQos.max_samples = 50;
Wparam.topic.resourceLimitsQos.allocated_samples = 20;
Wparam.times.heartbeatPeriod.seconds = 2;
Wparam.times.heartbeatPeriod.fraction = 200*1000*1000;
Wparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
mp_publisher = Domain::createPublisher(mp_participant,Wparam,(PublisherListener*)&m_listener);
if(mp_publisher == nullptr)
return false;
return true;
}
HelloWorldPublisher::~HelloWorldPublisher()
{
// TODO Auto-generated destructor stub
Domain::removeParticipant(mp_participant);
}
void HelloWorldPublisher::PubListener::onPublicationMatched(Publisher* /*pub*/,MatchingInfo& info)
{
if(info.status == MATCHED_MATCHING)
{
n_matched++;
std::cout << "Publisher matched"<<std::endl;
}
else
{
n_matched--;
std::cout << "Publisher unmatched"<<std::endl;
}
}
void HelloWorldPublisher::run(uint32_t samples)
{
for(uint32_t i = 0;i<samples;++i)
{
if(!publish())
--i;
else
{
std::cout << "Message: "<<m_Hello.message()<< " with index: "<< m_Hello.index()<< " SENT"<<std::endl;
}
eClock::my_sleep(25);
}
}
bool HelloWorldPublisher::publish()
{
if(m_listener.n_matched>0)
{
m_Hello.index(m_Hello.index()+1);
mp_publisher->write((void*)&m_Hello);
return true;
}
return false;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HelloWorldExample/Makefile | # 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.
CPP=g++
LN=g++
AR=ar
CP=cp
SYSLIBS= -ldl -lnsl -lm -lpthread -lrt
DEFINES=
COMMON_CFLAGS= -c -Wall -D__LITTLE_ENDIAN__ -std=c++11
## CHOOSE HERE BETWEEN 32 and 64 bit architecture
##32 BIT ARCH:
#COMMON_CFLAGS+= -m32 -fpic
#LDFLAGS=-m32
#64BIT ARCH:
COMMON_CFLAGS+= -m64 -fpic
LDFLAGS=-m64
CFLAGS = $(COMMON_CFLAGS) -O2
INCLUDES= -I.
LIBS = -lfastcdr -lfastrtps $(SYSLIBS)
DIRECTORIES= output.dir bin.dir
all: $(DIRECTORIES) HelloWorldExample
HELLOWORLDEXAMPLE_TARGET= bin/HelloWorldExample
HELLOWORLDEXAMPLE_SRC_CXXFILES=
HELLOWORLDEXAMPLE_SRC_CPPFILES= HelloWorldExample/HelloWorld.cxx \
HelloWorldExample/HelloWorldPubSubTypes.cxx \
HelloWorldExample/HelloWorldPublisher.cpp \
HelloWorldExample/HelloWorldSubscriber.cpp \
HelloWorldExample/HelloWorld_main.cpp
# Project sources are copied to the current directory
HELLOWORLDEXAMPLE_SRCS= $(HELLOWORLDEXAMPLE_SRC_CXXFILES) $(HELLOWORLDEXAMPLE_SRC_CPPFILES)
# Source directories
HELLOWORLDEXAMPLE_SOURCES_DIRS_AUX= $(foreach srcdir, $(dir $(HELLOWORLDEXAMPLE_SRCS)), $(srcdir))
HELLOWORLDEXAMPLE_SOURCES_DIRS= $(shell echo $(HELLOWORLDEXAMPLE_SOURCES_DIRS_AUX) | tr " " "\n" | sort | uniq | tr "\n" " ")
HELLOWORLDEXAMPLE_OBJS = $(foreach obj,$(notdir $(addsuffix .o, $(HELLOWORLDEXAMPLE_SRCS))), output/$(obj))
HELLOWORLDEXAMPLE_DEPS = $(foreach dep,$(notdir $(addsuffix .d, $(HELLOWORLDEXAMPLE_SRCS))), output/$(dep))
OBJS+= $(HELLOWORLDEXAMPLE_OBJS)
DEPS+= $(HELLOWORLDEXAMPLE_DEPS)
HelloWorldExample: $(HELLOWORLDEXAMPLE_TARGET)
$(HELLOWORLDEXAMPLE_TARGET): $(HELLOWORLDEXAMPLE_OBJS)
$(LN) $(LDFLAGS) -o $(HELLOWORLDEXAMPLE_TARGET) $(HELLOWORLDEXAMPLE_OBJS) $(LIBS)
vpath %.cxx $(HELLOWORLDEXAMPLE_SOURCES_DIRS)
vpath %.cpp $(HELLOWORLDEXAMPLE_SOURCES_DIRS)
output/%.cxx.o:%.cxx
@echo Calculating dependencies $<
@$(CC) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cxx.o=%.cxx.d)
@echo Compiling $<
@$(CC) $(CFLAGS) $(INCLUDES) $< -o $@
output/%.cpp.o:%.cpp
@echo Calculating dependencies $<
@$(CPP) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cpp.o=%.cpp.d)
@echo Compiling $<
@$(CPP) $(CFLAGS) $(INCLUDES) $< -o $@
.PHONY: HelloWorldExample
clean:
@rm -f $(OBJS)
@rm -f $(DEPS)
ifneq ($(MAKECMDGOALS), clean)
-include $(DEPS)
endif
%.dir :
@echo "Checking directory $*"
@if [ ! -d $* ]; then \
echo "Making directory $*"; \
mkdir -p $* ; \
fi;
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HelloWorldExample/HelloWorld.h | // 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 HelloWorld.h
* This header file contains the declaration of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/
#ifndef _HelloWorld_H_
#define _HelloWorld_H_
// TODO Poner en el contexto.
#include <stdint.h>
#include <array>
#include <string>
#include <vector>
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#define eProsima_user_DllExport __declspec( dllexport )
#else
#define eProsima_user_DllExport
#endif
#else
#define eProsima_user_DllExport
#endif
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#if defined(HelloWorld_SOURCE)
#define HelloWorld_DllAPI __declspec( dllexport )
#else
#define HelloWorld_DllAPI __declspec( dllimport )
#endif // HelloWorld_SOURCE
#else
#define HelloWorld_DllAPI
#endif
#else
#define HelloWorld_DllAPI
#endif // _WIN32
namespace eprosima
{
namespace fastcdr
{
class Cdr;
}
}
/*!
* @brief This class represents the structure HelloWorld defined by the user in the IDL file.
* @ingroup HELLOWORLD
*/
class HelloWorld
{
public:
/*!
* @brief Default constructor.
*/
eProsima_user_DllExport HelloWorld();
/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~HelloWorld();
/*!
* @brief Copy constructor.
* @param x Reference to the object HelloWorld that will be copied.
*/
eProsima_user_DllExport HelloWorld(const HelloWorld &x);
/*!
* @brief Move constructor.
* @param x Reference to the object HelloWorld that will be copied.
*/
eProsima_user_DllExport HelloWorld(HelloWorld &&x);
/*!
* @brief Copy assignment.
* @param x Reference to the object HelloWorld that will be copied.
*/
eProsima_user_DllExport HelloWorld& operator=(const HelloWorld &x);
/*!
* @brief Move assignment.
* @param x Reference to the object HelloWorld that will be copied.
*/
eProsima_user_DllExport HelloWorld& operator=(HelloWorld &&x);
/*!
* @brief This function sets a value in member index
* @param _index New value for member index
*/
inline 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
*/
inline eProsima_user_DllExport uint32_t index() const
{
return m_index;
}
/*!
* @brief This function returns a reference to member index
* @return Reference to member index
*/
inline eProsima_user_DllExport uint32_t& index()
{
return m_index;
}
/*!
* @brief This function copies the value in member message
* @param _message New value to be copied in member message
*/
inline eProsima_user_DllExport void message(const std::string &_message)
{
m_message = _message;
}
/*!
* @brief This function moves the value in member message
* @param _message New value to be moved in member message
*/
inline eProsima_user_DllExport void message(std::string &&_message)
{
m_message = std::move(_message);
}
/*!
* @brief This function returns a constant reference to member message
* @return Constant reference to member message
*/
inline eProsima_user_DllExport const std::string& message() const
{
return m_message;
}
/*!
* @brief This function returns a reference to member message
* @return Reference to member message
*/
inline eProsima_user_DllExport std::string& message()
{
return m_message;
}
/*!
* @brief This function returns the maximum serialized size of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getMaxCdrSerializedSize(size_t current_alignment = 0);
/*!
* @brief This function returns the serialized size of a data depending on the buffer alignment.
* @param data Data which is calculated its serialized size.
* @param current_alignment Buffer alignment.
* @return Serialized size.
*/
eProsima_user_DllExport static size_t getCdrSerializedSize(const HelloWorld& data, size_t current_alignment = 0);
/*!
* @brief This function serializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serialize(eprosima::fastcdr::Cdr &cdr) const;
/*!
* @brief This function deserializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void deserialize(eprosima::fastcdr::Cdr &cdr);
/*!
* @brief This function returns the maximum serialized size of the Key of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize(size_t current_alignment = 0);
/*!
* @brief This function tells you if the Key has been defined for this type
*/
eProsima_user_DllExport static bool isKeyDefined();
/*!
* @brief This function serializes the key members of an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const;
private:
uint32_t m_index;
std::string m_message;
};
#endif // _HelloWorld_H_ | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HelloWorldExample/HelloWorldPubSubTypes.cxx | // 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 HelloWorldPubSubTypes.cpp
* This header file contains the implementation of the serialization functions.
*
* This file was generated by the tool fastcdrgen.
*/
#include <fastcdr/FastBuffer.h>
#include <fastcdr/Cdr.h>
#include "HelloWorldPubSubTypes.h"
HelloWorldPubSubType::HelloWorldPubSubType() {
setName("HelloWorld");
m_typeSize = (uint32_t)HelloWorld::getMaxCdrSerializedSize() + 4 /*encapsulation*/;
m_isGetKeyDefined = HelloWorld::isKeyDefined();
m_keyBuffer = (unsigned char*)malloc(HelloWorld::getKeyMaxCdrSerializedSize()>16 ? HelloWorld::getKeyMaxCdrSerializedSize() : 16);
}
HelloWorldPubSubType::~HelloWorldPubSubType() {
if(m_keyBuffer!=nullptr)
free(m_keyBuffer);
}
bool HelloWorldPubSubType::serialize(void *data, SerializedPayload_t *payload) {
HelloWorld *p_type = (HelloWorld*) data;
eprosima::fastcdr::FastBuffer fastbuffer((char*) payload->data, payload->max_size); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);
payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
// Serialize encapsulation
ser.serialize_encapsulation();
p_type->serialize(ser); // Serialize the object:
payload->length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length
return true;
}
bool HelloWorldPubSubType::deserialize(SerializedPayload_t* payload, void* data) {
HelloWorld* p_type = (HelloWorld*) data; //Convert DATA to pointer of your type
eprosima::fastcdr::FastBuffer fastbuffer((char*)payload->data, payload->length); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR); // Object that deserializes the data.
// Deserialize encapsulation.
deser.read_encapsulation();
payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
p_type->deserialize(deser); //Deserialize the object:
return true;
}
std::function<uint32_t()> HelloWorldPubSubType::getSerializedSizeProvider(void* data) {
return [data]() -> uint32_t {
return (uint32_t)type::getCdrSerializedSize(*static_cast<HelloWorld*>(data)) + 4 /*encapsulation*/;
};
}
void* HelloWorldPubSubType::createData() {
return (void*)new HelloWorld();
}
void HelloWorldPubSubType::deleteData(void* data) {
delete((HelloWorld*)data);
}
bool HelloWorldPubSubType::getKey(void *data, InstanceHandle_t* handle) {
if(!m_isGetKeyDefined)
return false;
HelloWorld* p_type = (HelloWorld*) data;
eprosima::fastcdr::FastBuffer fastbuffer((char*)m_keyBuffer,HelloWorld::getKeyMaxCdrSerializedSize()); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); // Object that serializes the data.
p_type->serializeKey(ser);
if(HelloWorld::getKeyMaxCdrSerializedSize()>16) {
m_md5.init();
m_md5.update(m_keyBuffer,(unsigned int)ser.getSerializedDataLength());
m_md5.finalize();
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_md5.digest[i];
}
}
else {
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_keyBuffer[i];
}
}
return true;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HelloWorldExample/HelloWorldSubscriber.cpp | // 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 HelloWorldSubscriber.cpp
*
*/
#include "HelloWorldSubscriber.h"
#include <fastrtps/participant/Participant.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/attributes/SubscriberAttributes.h>
#include <fastrtps/subscriber/Subscriber.h>
#include <fastrtps/Domain.h>
#include <fastrtps/utils/eClock.h>
HelloWorldSubscriber::HelloWorldSubscriber():mp_participant(nullptr),
mp_subscriber(nullptr)
{
}
bool HelloWorldSubscriber::init()
{
ParticipantAttributes PParam;
PParam.rtps.defaultSendPort = 10043;
PParam.rtps.builtin.use_SIMPLE_RTPSParticipantDiscoveryProtocol = true;
PParam.rtps.builtin.use_SIMPLE_EndpointDiscoveryProtocol = true;
PParam.rtps.builtin.m_simpleEDP.use_PublicationReaderANDSubscriptionWriter = true;
PParam.rtps.builtin.m_simpleEDP.use_PublicationWriterANDSubscriptionReader = true;
PParam.rtps.builtin.domainId = 80;
PParam.rtps.builtin.leaseDuration = c_TimeInfinite;
PParam.rtps.setName("Participant_sub");
mp_participant = Domain::createParticipant(PParam);
if(mp_participant==nullptr)
return false;
//REGISTER THE TYPE
Domain::registerType(mp_participant,&m_type);
//CREATE THE SUBSCRIBER
SubscriberAttributes Rparam;
Rparam.topic.topicKind = NO_KEY;
Rparam.topic.topicDataType = "HelloWorld";
Rparam.topic.topicName = "HelloWorldTopic";
Rparam.topic.historyQos.kind = KEEP_LAST_HISTORY_QOS;
Rparam.topic.historyQos.depth = 30;
Rparam.topic.resourceLimitsQos.max_samples = 50;
Rparam.topic.resourceLimitsQos.allocated_samples = 20;
Rparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
mp_subscriber = Domain::createSubscriber(mp_participant,Rparam,(SubscriberListener*)&m_listener);
if(mp_subscriber == nullptr)
return false;
return true;
}
HelloWorldSubscriber::~HelloWorldSubscriber() {
// TODO Auto-generated destructor stub
Domain::removeParticipant(mp_participant);
}
void HelloWorldSubscriber::SubListener::onSubscriptionMatched(Subscriber* /*sub*/,MatchingInfo& info)
{
if(info.status == MATCHED_MATCHING)
{
n_matched++;
std::cout << "Subscriber matched"<<std::endl;
}
else
{
n_matched--;
std::cout << "Subscriber unmatched"<<std::endl;
}
}
void HelloWorldSubscriber::SubListener::onNewDataMessage(Subscriber* sub)
{
if(sub->takeNextData((void*)&m_Hello, &m_info))
{
if(m_info.sampleKind == ALIVE)
{
this->n_samples++;
// Print your structure data here.
std::cout << "Message "<<m_Hello.message()<< " "<< m_Hello.index()<< " RECEIVED"<<std::endl;
}
}
}
void HelloWorldSubscriber::run()
{
std::cout << "Subscriber running. Please press enter to stop the Subscriber" << std::endl;
std::cin.ignore();
}
void HelloWorldSubscriber::run(uint32_t number)
{
std::cout << "Subscriber running until "<< number << "samples have been received"<<std::endl;
while(number < this->m_listener.n_samples)
eClock::my_sleep(500);
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HelloWorldExample/HelloWorld.cxx | // 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 HelloWorld.cpp
* This source file contains the definition of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/
#ifdef _WIN32
// Remove linker warning LNK4221 on Visual Studio
namespace { char dummy; }
#endif
#include "HelloWorld.h"
#include <fastcdr/Cdr.h>
#include <fastcdr/exceptions/BadParamException.h>
using namespace eprosima::fastcdr::exception;
#include <utility>
HelloWorld::HelloWorld()
{
m_index = 0;
}
HelloWorld::~HelloWorld()
{
}
HelloWorld::HelloWorld(const HelloWorld &x)
{
m_index = x.m_index;
m_message = x.m_message;
}
HelloWorld::HelloWorld(HelloWorld &&x)
{
m_index = x.m_index;
m_message = std::move(x.m_message);
}
HelloWorld& HelloWorld::operator=(const HelloWorld &x)
{
m_index = x.m_index;
m_message = x.m_message;
return *this;
}
HelloWorld& HelloWorld::operator=(HelloWorld &&x)
{
m_index = x.m_index;
m_message = std::move(x.m_message);
return *this;
}
size_t HelloWorld::getMaxCdrSerializedSize(size_t current_alignment)
{
size_t initial_alignment = current_alignment;
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1;
return current_alignment - initial_alignment;
}
size_t HelloWorld::getCdrSerializedSize(const HelloWorld& data, size_t current_alignment)
{
size_t initial_alignment = current_alignment;
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.message().size() + 1;
return current_alignment - initial_alignment;
}
void HelloWorld::serialize(eprosima::fastcdr::Cdr &scdr) const
{
scdr << m_index;
if(m_message.length() <= 255)
scdr << m_message;
else
throw eprosima::fastcdr::exception::BadParamException("message field exceeds the maximum length");
}
void HelloWorld::deserialize(eprosima::fastcdr::Cdr &dcdr)
{
dcdr >> m_index;
dcdr >> m_message;
}
size_t HelloWorld::getKeyMaxCdrSerializedSize(size_t current_alignment)
{
size_t current_align = current_alignment;
return current_align;
}
bool HelloWorld::isKeyDefined()
{
return false;
}
void HelloWorld::serializeKey(eprosima::fastcdr::Cdr &scdr) const
{
} | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HelloWorldExample/HelloWorldPublisher.h | // 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 HelloWorldPublisher.h
*
*/
#ifndef HELLOWORLDPUBLISHER_H_
#define HELLOWORLDPUBLISHER_H_
#include "HelloWorldPubSubTypes.h"
#include <fastrtps/fastrtps_fwd.h>
#include <fastrtps/attributes/PublisherAttributes.h>
#include <fastrtps/publisher/PublisherListener.h>
using namespace eprosima::fastrtps;
#include "HelloWorld.h"
class HelloWorldPublisher {
public:
HelloWorldPublisher();
virtual ~HelloWorldPublisher();
//!Initialize
bool init();
//!Publish a sample
bool publish();
//!Run for number samples
void run(uint32_t number);
private:
HelloWorld m_Hello;
Participant* mp_participant;
Publisher* mp_publisher;
class PubListener:public PublisherListener
{
public:
PubListener():n_matched(0){};
~PubListener(){};
void onPublicationMatched(Publisher* pub,MatchingInfo& info);
int n_matched;
}m_listener;
HelloWorldPubSubType m_type;
};
#endif /* HELLOWORLDPUBLISHER_H_ */
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HelloWorldExample/HelloWorldSubscriber.h | // 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 HelloWorldSubscriber.h
*
*/
#ifndef HELLOWORLDSUBSCRIBER_H_
#define HELLOWORLDSUBSCRIBER_H_
#include "HelloWorldPubSubTypes.h"
#include <fastrtps/fastrtps_fwd.h>
#include <fastrtps/attributes/SubscriberAttributes.h>
#include <fastrtps/subscriber/SubscriberListener.h>
#include <fastrtps/subscriber/SampleInfo.h>
using namespace eprosima::fastrtps;
#include "HelloWorld.h"
class HelloWorldSubscriber {
public:
HelloWorldSubscriber();
virtual ~HelloWorldSubscriber();
//!Initialize the subscriber
bool init();
//!RUN the subscriber
void run();
//!Run the subscriber until number samples have been recevied.
void run(uint32_t number);
private:
Participant* mp_participant;
Subscriber* mp_subscriber;
public:
class SubListener:public SubscriberListener
{
public:
SubListener():n_matched(0),n_samples(0){};
~SubListener(){};
void onSubscriptionMatched(Subscriber* sub,MatchingInfo& info);
void onNewDataMessage(Subscriber* sub);
HelloWorld m_Hello;
SampleInfo_t m_info;
int n_matched;
uint32_t n_samples;
}m_listener;
private:
HelloWorldPubSubType m_type;
};
#endif /* HELLOWORLDSUBSCRIBER_H_ */
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HelloWorldExample/HelloWorldPubSubTypes.h | // 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 HelloWorldPubSubTypes.h
* This header file contains the declaration of the serialization functions.
*
* This file was generated by the tool fastcdrgen.
*/
#ifndef _HELLOWORLD_PUBSUBTYPES_H_
#define _HELLOWORLD_PUBSUBTYPES_H_
#include <fastrtps/TopicDataType.h>
using namespace eprosima::fastrtps;
#include "HelloWorld.h"
/*!
* @brief This class represents the TopicDataType of the type HelloWorld defined by the user in the IDL file.
* @ingroup HELLOWORLD
*/
class HelloWorldPubSubType : public TopicDataType {
public:
typedef HelloWorld type;
HelloWorldPubSubType();
virtual ~HelloWorldPubSubType();
bool serialize(void *data, SerializedPayload_t *payload);
bool deserialize(SerializedPayload_t *payload, void *data);
std::function<uint32_t()> getSerializedSizeProvider(void* data);
bool getKey(void *data, InstanceHandle_t *ihandle);
void* createData();
void deleteData(void * data);
MD5 m_md5;
unsigned char* m_keyBuffer;
};
#endif // _HelloWorld_PUBSUBTYPE_H_ | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HelloWorldExample/README.txt | To launch this test open two different consoles:
In the first one launch: HelloWorldExample publisher (or HelloWorldExample.exe publisher on windows).
In the second one: HelloWorldExample subscriber.
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HelloWorldExample/HelloWorld_main.cpp | // 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 HelloWorld_main.cpp
*
*/
#include "HelloWorldPublisher.h"
#include "HelloWorldSubscriber.h"
#include <fastrtps/Domain.h>
#include <fastrtps/utils/eClock.h>
#include <fastrtps/log/Log.h>
using namespace eprosima;
using namespace fastrtps;
using namespace rtps;
int main(int argc, char** argv)
{
std::cout << "Starting "<< std::endl;
int type = 1;
if(argc > 1)
{
if(strcmp(argv[1],"publisher")==0)
type = 1;
else if(strcmp(argv[1],"subscriber")==0)
type = 2;
}
else
{
std::cout << "publisher OR subscriber argument needed" << std::endl;
Log::Reset();
return 0;
}
switch(type)
{
case 1:
{
HelloWorldPublisher mypub;
if(mypub.init())
{
mypub.run(10);
}
break;
}
case 2:
{
HelloWorldSubscriber mysub;
if(mysub.init())
{
mysub.run();
}
break;
}
}
Domain::stopAll();
Log::Reset();
return 0;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HistoryKind/CMakeLists.txt | # 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.
cmake_minimum_required(VERSION 2.8.12)
project("UseCaseDemonstrator")
# Find requirements
find_package(fastcdr REQUIRED)
find_package(fastrtps REQUIRED)
# Set C++11
include(CheckCXXCompilerFlag)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_cxx_compiler_flag(--std=c++11 SUPPORTS_CXX11)
if(SUPPORTS_CXX11)
add_compile_options(--std=c++11)
else()
message(FATAL_ERROR "Compiler doesn't support C++11")
endif()
endif()
message(STATUS "Configuring UseCaseDemonstrator example...")
file(GLOB USECASEDEMONSTRATOR_EXAMPLE_SOURCES "*.cxx")
add_executable(historykind ${USECASEDEMONSTRATOR_EXAMPLE_SOURCES} pastsamples.cpp)
target_link_libraries(historykind fastrtps fastcdr)
install(TARGETS historykind
RUNTIME DESTINATION examples/C++/UseCaseDemonstrator/${BIN_INSTALL_DIR}
)
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HistoryKind/samplePubSubTypes.h | // 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 samplePubSubTypes.h
* This header file contains the declaration of the serialization functions.
*
* This file was generated by the tool fastcdrgen.
*/
#ifndef _SAMPLE_PUBSUBTYPES_H_
#define _SAMPLE_PUBSUBTYPES_H_
#include <fastrtps/TopicDataType.h>
using namespace eprosima::fastrtps;
#include "sample.h"
/*!
* @brief This class represents the TopicDataType of the type sample defined by the user in the IDL file.
* @ingroup SAMPLE
*/
class samplePubSubType : public TopicDataType {
public:
typedef sample type;
samplePubSubType();
virtual ~samplePubSubType();
bool serialize(void *data, SerializedPayload_t *payload);
bool deserialize(SerializedPayload_t *payload, void *data);
std::function<uint32_t()> getSerializedSizeProvider(void* data);
bool getKey(void *data, InstanceHandle_t *ihandle);
void* createData();
void deleteData(void * data);
MD5 m_md5;
unsigned char* m_keyBuffer;
};
#endif // _sample_PUBSUBTYPE_H_ | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HistoryKind/Makefile | # 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.
CPP=g++
LN=g++
AR=ar
CP=cp
SYSLIBS= -ldl -lnsl -lm -lpthread -lrt
DEFINES=
COMMON_CFLAGS= -c -Wall -D__LITTLE_ENDIAN__ -std=c++11
## CHOOSE HERE BETWEEN 32 and 64 bit architecture
##32 BIT ARCH:
#COMMON_CFLAGS+= -m32 -fpic
#LDFLAGS=-m32
#64BIT ARCH:
COMMON_CFLAGS+= -m64 -fpic
LDFLAGS=-m64
CFLAGS = $(COMMON_CFLAGS) -O2
INCLUDES= -I.
LIBS = -lfastcdr -lfastrtps $(SYSLIBS)
DIRECTORIES= output.dir bin.dir
all: $(DIRECTORIES) HistoryKind
HISTORYKIND_TARGET= bin/HistoryKind
HISTORYKIND_SRC_CXXFILES=
HISTORYKIND_SRC_CPPFILES= HistoryKind/pastsamples.cpp \
HistoryKind/sample.cxx \
HistoryKind/samplePubSubTypes.cxx
# Project sources are copied to the current directory
HISTORYKIND_SRCS= $(HISTORYKIND_SRC_CXXFILES) $(HISTORYKIND_SRC_CPPFILES)
# Source directories
HISTORYKIND_SOURCES_DIRS_AUX= $(foreach srcdir, $(dir $(HISTORYKIND_SRCS)), $(srcdir))
HISTORYKIND_SOURCES_DIRS= $(shell echo $(HISTORYKIND_SOURCES_DIRS_AUX) | tr " " "\n" | sort | uniq | tr "\n" " ")
HISTORYKIND_OBJS = $(foreach obj,$(notdir $(addsuffix .o, $(HISTORYKIND_SRCS))), output/$(obj))
HISTORYKIND_DEPS = $(foreach dep,$(notdir $(addsuffix .d, $(HISTORYKIND_SRCS))), output/$(dep))
OBJS+= $(HISTORYKIND_OBJS)
DEPS+= $(HISTORYKIND_DEPS)
HistoryKind: $(HISTORYKIND_TARGET)
$(HISTORYKIND_TARGET): $(HISTORYKIND_OBJS)
$(LN) $(LDFLAGS) -o $(HISTORYKIND_TARGET) $(HISTORYKIND_OBJS) $(LIBS)
vpath %.cxx $(HISTORYKIND_SOURCES_DIRS)
vpath %.cpp $(HISTORYKIND_SOURCES_DIRS)
output/%.cxx.o:%.cxx
@echo Calculating dependencies $<
@$(CC) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cxx.o=%.cxx.d)
@echo Compiling $<
@$(CC) $(CFLAGS) $(INCLUDES) $< -o $@
output/%.cpp.o:%.cpp
@echo Calculating dependencies $<
@$(CPP) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cpp.o=%.cpp.d)
@echo Compiling $<
@$(CPP) $(CFLAGS) $(INCLUDES) $< -o $@
.PHONY: HistoryKind
clean:
@rm -f $(OBJS)
@rm -f $(DEPS)
ifneq ($(MAKECMDGOALS), clean)
-include $(DEPS)
endif
%.dir :
@echo "Checking directory $*"
@if [ ! -d $* ]; then \
echo "Making directory $*"; \
mkdir -p $* ; \
fi;
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HistoryKind/sample.cxx | // 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 sample.cpp
* This source file contains the definition of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/
#ifdef _WIN32
// Remove linker warning LNK4221 on Visual Studio
namespace { char dummy; }
#endif
#include "sample.h"
#include <fastcdr/Cdr.h>
#include <fastcdr/exceptions/BadParamException.h>
using namespace eprosima::fastcdr::exception;
#include <utility>
sample::sample()
{
m_index = 0;
m_key_value = 0;
}
sample::~sample()
{
}
sample::sample(const sample &x)
{
m_index = x.m_index;
m_key_value = x.m_key_value;
}
sample::sample(sample &&x)
{
m_index = x.m_index;
m_key_value = x.m_key_value;
}
sample& sample::operator=(const sample &x)
{
m_index = x.m_index;
m_key_value = x.m_key_value;
return *this;
}
sample& sample::operator=(sample &&x)
{
m_index = x.m_index;
m_key_value = x.m_key_value;
return *this;
}
size_t sample::getMaxCdrSerializedSize(size_t current_alignment)
{
size_t initial_alignment = current_alignment;
current_alignment += 1 + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
current_alignment += 1 + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
return current_alignment - initial_alignment;
}
size_t sample::getCdrSerializedSize(const sample& data, size_t current_alignment)
{
size_t initial_alignment = current_alignment;
current_alignment += 1 + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
current_alignment += 1 + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
return current_alignment - initial_alignment;
}
void sample::serialize(eprosima::fastcdr::Cdr &scdr) const
{
scdr << m_index;
scdr << m_key_value;
}
void sample::deserialize(eprosima::fastcdr::Cdr &dcdr)
{
dcdr >> m_index;
dcdr >> m_key_value;
}
size_t sample::getKeyMaxCdrSerializedSize(size_t current_alignment)
{
size_t current_align = current_alignment;
current_align += 1 + eprosima::fastcdr::Cdr::alignment(current_align, 1);
return current_align;
}
bool sample::isKeyDefined()
{
return true;
}
void sample::serializeKey(eprosima::fastcdr::Cdr &scdr) const
{
scdr << m_key_value;
} | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HistoryKind/pastsamples.cpp | #include <iostream>
#include <string>
#include <fastrtps/participant/Participant.h>
#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/subscriber/Subscriber.h>
#include <fastrtps/attributes/SubscriberAttributes.h>
#include <fastrtps/publisher/Publisher.h>
#include <fastrtps/attributes/PublisherAttributes.h>
#include <fastrtps/Domain.h>
#include <fastrtps/subscriber/SampleInfo.h>
#include <fastrtps/utils/eClock.h>
#include "samplePubSubTypes.h"
//Enums and configuration structure
enum Reliability_type { Best_Effort, Reliable };
enum Durability_type { Transient_Local, Volatile };
enum HistoryKind_type { Keep_Last, Keep_All };
enum Key_type { No_Key, With_Key};
typedef struct{
Reliability_type reliability;
Durability_type durability;
HistoryKind_type historykind;
Key_type keys;
uint16_t history_size;
uint8_t depth;
uint8_t no_keys;
uint16_t max_samples_per_key;
} example_configuration;
void pastsamples();
int main(){
pastsamples();
return 0;
}
void pastsamples(){
samplePubSubType sampleType;
sample my_sample;
SampleInfo_t sample_info;
ParticipantAttributes PparamPub;
PparamPub.rtps.builtin.domainId = 0;
PparamPub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamPub.rtps.setName("PublisherParticipant");
Participant *PubParticipant = Domain::createParticipant(PparamPub);
if(PubParticipant == nullptr){
std::cout << " Something went wrong while creating the Publisher Participant..." << std::endl;
return;
}
Domain::registerType(PubParticipant,(TopicDataType*) &sampleType);
//Publisher config
PublisherAttributes Pparam;
Pparam.topic.topicDataType = sampleType.getName();
Pparam.topic.topicName = "samplePubSubTopic";
Pparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Pparam.topic.topicKind = NO_KEY;
Pparam.topic.historyQos.kind = KEEP_ALL_HISTORY_QOS;
Pparam.qos.m_durability.kind = TRANSIENT_LOCAL_DURABILITY_QOS;
Pparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Pparam.topic.historyQos.depth = 50;
Pparam.topic.resourceLimitsQos.max_samples = 100;
Pparam.topic.resourceLimitsQos.max_instances = 1;
Pparam.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Publisher..." << std::endl;
Publisher *myPub= Domain::createPublisher(PubParticipant, Pparam, nullptr);
if(myPub == nullptr){
std::cout << "Something went wrong while creating the Publisher..." << std::endl;
return;
}
ParticipantAttributes PparamSub;
PparamSub.rtps.builtin.domainId = 0;
PparamSub.rtps.builtin.leaseDuration = c_TimeInfinite;
PparamSub.rtps.setName("SubscriberParticipant");
Participant *SubParticipant = Domain::createParticipant(PparamSub);
if(SubParticipant == nullptr){
std::cout << " Something went wrong while creating the Subscriber Participant..." << std::endl;
return;
}
Domain::registerType(SubParticipant,(TopicDataType*) &sampleType);
//Keep All Sub
SubscriberAttributes Rparam;
Rparam.topic.topicDataType = sampleType.getName();
Rparam.topic.topicName = "samplePubSubTopic";
Rparam.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Rparam.topic.topicKind = NO_KEY;
Rparam.topic.historyQos.kind = KEEP_ALL_HISTORY_QOS;
Rparam.qos.m_durability.kind = VOLATILE_DURABILITY_QOS;
Rparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Rparam.topic.historyQos.depth = 50;
Rparam.topic.resourceLimitsQos.max_samples = 100;
Rparam.topic.resourceLimitsQos.max_instances = 1;
Rparam.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Keep All Subscriber..." << std::endl;
Subscriber *mySub1= Domain::createSubscriber(PubParticipant, Rparam, nullptr);
if(myPub == nullptr){
std::cout << "something went wrong while creating the Transient Local Subscriber..." << std::endl;
return;
}
//Keep Last
SubscriberAttributes Rparam2;
Rparam2.topic.topicDataType = sampleType.getName();
Rparam2.topic.topicName = "samplePubSubTopic";
Rparam2.historyMemoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE;
Rparam2.topic.topicKind = NO_KEY;
Rparam2.topic.historyQos.kind = KEEP_LAST_HISTORY_QOS;
Rparam2.qos.m_durability.kind = VOLATILE_DURABILITY_QOS;
Rparam2.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
Rparam2.topic.historyQos.depth = 10;
Rparam2.topic.resourceLimitsQos.max_samples = 100;
Rparam2.topic.resourceLimitsQos.max_instances = 1;
Rparam2.topic.resourceLimitsQos.max_samples_per_instance = 100;
std::cout << "Creating Keep Last Subscriber with depth 10..." << std::endl;
Subscriber *mySub2= Domain::createSubscriber(PubParticipant, Rparam2, nullptr);
if(myPub == nullptr){
std::cout << "something went wrong while creating the Volatile Subscriber..." << std::endl;
return;
}
//Send 20 samples
std::cout << "Publishing 20 samples on the topic..." << std::endl;
for(uint8_t j=0; j < 20; j++){
my_sample.index(j+1);
my_sample.key_value(1);
myPub->write(&my_sample);
}
eClock::my_sleep(1500);
//Read the contents of both histories:
std::cout << "The Keep All Subscriber holds: " << std::endl;
while(mySub1->readNextData(&my_sample, &sample_info)){
std::cout << std::to_string(my_sample.index()) << " ";
}
std::cout << std::endl;
std::cout << "The Keep Last (Depth 10) Subscriber holds: " << std::endl;
while(mySub2->readNextData(&my_sample, &sample_info)){
std::cout << std::to_string(my_sample.index()) << " ";
}
std::cout << std::endl;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HistoryKind/README.txt | ------------------------------------------------
- Use Case Example: History Kind for eProsima Fast RTPS -
------------------------------------------------
1 - Application description
---------------------------
eProsima Fast RTPS provides users with a wide range of configuration options. This example has the objective of providing a testing ground where you can experiment and see the influence different combinations of parameters can have on the behaviours on the Publisher/Subscriber scheme.
This example is a supplement to the UseCaseLauncher example, consisting on an application which ilustrates the effect the different kinds of Subscriber Histories have on sample storage.
2 - Configuration options
--------------------------
These are the main parameters that affect the behaviour of eProsima Fast RTPS and that are used in the Use Case set of example:
- Reliability Kind
Defines how eProsima Fast RTPS deals upon possible packet loss during data exchanges.
+ Best Effort: No arrival confirmation. It is fast but lost samples are not re-sent.
+ Reliable: With arrival confirmation. It is slower but provides guarantee that all lost samples are re-sent and eventually received by the subscriber.
Since this application runs the Publisher and Subscriber on the same machine, data loss is highly unlikely. Therefore this option will not play a relevant role on the application behaviour.
- Durability Kind
Defines what to do with samples that exist prior to the existence of the Subscriber.
+ Volatile: Past samples are ignored, the Subscriber starts to receive data generated after it has joined the network.
+ Transient Local: Past samples are sent.
- History Kind
Defines the storage policy for past samples.
+ Keep Last: The History will save and give access to the alst "k" received samples. This "k" number is called the History Depth and can be manually set too by the user.
+ Keep All: The History will save and give access to all received samples until the maximum samples size of the History is reached.
This parameter affects cases of "late-joining" Subscribers: Subscribers that come online after data transfers on a topic have started.
- Keys
Keys allow to have multiple data endpoints within a topic as opposed to all data published in a topic going into the same "inbox".
+ On a topic without keys, all pieces of data go into a single endpoint.
+ On a topic without keys, the key field is used to determine which of the multiple endpoints the data goes into. If, for example, a history is set to transient local with depth=3 (the last three samples are stores) then eProsima FastRTPS will ensure that 3 samples per data endpoint are stored. This means that three samples are stored for each unique key instead of three samples total.
It is important to note that even if you configure a Topic and your History to be able to hold items from multiple keys, this configuration does not take effect unless you explicitly enable Keys.
- Depth
The depth is the amount of past samples that are stored in the history before starting to overwrite. Only takes effect when the History is on "Keep Last" mode.
- History Size
This accounts for the total number of samples that can be stored in the history, regardless of any other configuration option.
- Instances
Instances are the different data sinks the History is divided and act as receptors of the Keys.
- Instance size
As it happens with depth, you can define a maximun number of past samples to be stored. If you set one Instance and an instance size more restrictive than the depth, the instance size will be the limiting factor.
3. Application behaviour
------------------------
This application spawns a Publisher and two Subscribers, one Keep-All and one Keep-Last with depth 10. Then it will publish 20 samples. After inspecting the contents of both subscribers histories you will see the following:
* The Keep-All subscriber holds the 20 samples, because it stores all samples up to the maximum size of the History.
* The Keep-Last subscriber holds samples 11 to 20. This is because after storing 10 samples (its depth) it startes to overwrite past samples.
4. Built-in tests
-----------------
Other than this application, he Use Case set of examples contains the following pre-defined demonstrators:
* Late joiners: Shows how a Transient-Local Subscriber receives past samples while Volatile starts receiving from the moment of its creation.
* Keys: Provides a working example of how data can be split into multiple endpoints based of keys.
* SampleConfig: Provides a basic Publish-Subscribe example for the three sample configurations specified in section 5.
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HistoryKind/sample.idl | struct sample{
octet index;
@Key octet key_value;
};
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HistoryKind/sample.h | // 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 sample.h
* This header file contains the declaration of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/
#ifndef _sample_H_
#define _sample_H_
// TODO Poner en el contexto.
#include <stdint.h>
#include <array>
#include <string>
#include <vector>
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#define eProsima_user_DllExport __declspec( dllexport )
#else
#define eProsima_user_DllExport
#endif
#else
#define eProsima_user_DllExport
#endif
#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#if defined(sample_SOURCE)
#define sample_DllAPI __declspec( dllexport )
#else
#define sample_DllAPI __declspec( dllimport )
#endif // sample_SOURCE
#else
#define sample_DllAPI
#endif
#else
#define sample_DllAPI
#endif // _WIN32
namespace eprosima
{
namespace fastcdr
{
class Cdr;
}
}
/*!
* @brief This class represents the structure sample defined by the user in the IDL file.
* @ingroup SAMPLE
*/
class sample
{
public:
/*!
* @brief Default constructor.
*/
eProsima_user_DllExport sample();
/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~sample();
/*!
* @brief Copy constructor.
* @param x Reference to the object sample that will be copied.
*/
eProsima_user_DllExport sample(const sample &x);
/*!
* @brief Move constructor.
* @param x Reference to the object sample that will be copied.
*/
eProsima_user_DllExport sample(sample &&x);
/*!
* @brief Copy assignment.
* @param x Reference to the object sample that will be copied.
*/
eProsima_user_DllExport sample& operator=(const sample &x);
/*!
* @brief Move assignment.
* @param x Reference to the object sample that will be copied.
*/
eProsima_user_DllExport sample& operator=(sample &&x);
/*!
* @brief This function sets a value in member index
* @param _index New value for member index
*/
inline eProsima_user_DllExport void index(uint8_t _index)
{
m_index = _index;
}
/*!
* @brief This function returns the value of member index
* @return Value of member index
*/
inline eProsima_user_DllExport uint8_t index() const
{
return m_index;
}
/*!
* @brief This function returns a reference to member index
* @return Reference to member index
*/
inline eProsima_user_DllExport uint8_t& index()
{
return m_index;
}
/*!
* @brief This function sets a value in member key_value
* @param _key_value New value for member key_value
*/
inline eProsima_user_DllExport void key_value(uint8_t _key_value)
{
m_key_value = _key_value;
}
/*!
* @brief This function returns the value of member key_value
* @return Value of member key_value
*/
inline eProsima_user_DllExport uint8_t key_value() const
{
return m_key_value;
}
/*!
* @brief This function returns a reference to member key_value
* @return Reference to member key_value
*/
inline eProsima_user_DllExport uint8_t& key_value()
{
return m_key_value;
}
/*!
* @brief This function returns the maximum serialized size of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getMaxCdrSerializedSize(size_t current_alignment = 0);
/*!
* @brief This function returns the serialized size of a data depending on the buffer alignment.
* @param data Data which is calculated its serialized size.
* @param current_alignment Buffer alignment.
* @return Serialized size.
*/
eProsima_user_DllExport static size_t getCdrSerializedSize(const sample& data, size_t current_alignment = 0);
/*!
* @brief This function serializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serialize(eprosima::fastcdr::Cdr &cdr) const;
/*!
* @brief This function deserializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void deserialize(eprosima::fastcdr::Cdr &cdr);
/*!
* @brief This function returns the maximum serialized size of the Key of an object
* depending on the buffer alignment.
* @param current_alignment Buffer alignment.
* @return Maximum serialized size.
*/
eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize(size_t current_alignment = 0);
/*!
* @brief This function tells you if the Key has been defined for this type
*/
eProsima_user_DllExport static bool isKeyDefined();
/*!
* @brief This function serializes the key members of an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const;
private:
uint8_t m_index;
uint8_t m_key_value;
};
#endif // _sample_H_ | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/HistoryKind/samplePubSubTypes.cxx | // 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 samplePubSubTypes.cpp
* This header file contains the implementation of the serialization functions.
*
* This file was generated by the tool fastcdrgen.
*/
#include <fastcdr/FastBuffer.h>
#include <fastcdr/Cdr.h>
#include "samplePubSubTypes.h"
samplePubSubType::samplePubSubType() {
setName("sample");
m_typeSize = (uint32_t)sample::getMaxCdrSerializedSize() + 4 /*encapsulation*/;
m_isGetKeyDefined = sample::isKeyDefined();
m_keyBuffer = (unsigned char*)malloc(sample::getKeyMaxCdrSerializedSize()>16 ? sample::getKeyMaxCdrSerializedSize() : 16);
}
samplePubSubType::~samplePubSubType() {
if(m_keyBuffer!=nullptr)
free(m_keyBuffer);
}
bool samplePubSubType::serialize(void *data, SerializedPayload_t *payload) {
sample *p_type = (sample*) data;
eprosima::fastcdr::FastBuffer fastbuffer((char*) payload->data, payload->max_size); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);
payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
// Serialize encapsulation
ser.serialize_encapsulation();
p_type->serialize(ser); // Serialize the object:
payload->length = (uint32_t)ser.getSerializedDataLength(); //Get the serialized length
return true;
}
bool samplePubSubType::deserialize(SerializedPayload_t* payload, void* data) {
sample* p_type = (sample*) data; //Convert DATA to pointer of your type
eprosima::fastcdr::FastBuffer fastbuffer((char*)payload->data, payload->length); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR); // Object that deserializes the data.
// Deserialize encapsulation.
deser.read_encapsulation();
payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
p_type->deserialize(deser); //Deserialize the object:
return true;
}
std::function<uint32_t()> samplePubSubType::getSerializedSizeProvider(void* data) {
return [data]() -> uint32_t {
return (uint32_t)type::getCdrSerializedSize(*static_cast<sample*>(data)) + 4 /*encapsulation*/;
};
}
void* samplePubSubType::createData() {
return (void*)new sample();
}
void samplePubSubType::deleteData(void* data) {
delete((sample*)data);
}
bool samplePubSubType::getKey(void *data, InstanceHandle_t* handle) {
if(!m_isGetKeyDefined)
return false;
sample* p_type = (sample*) data;
eprosima::fastcdr::FastBuffer fastbuffer((char*)m_keyBuffer,sample::getKeyMaxCdrSerializedSize()); // Object that manages the raw buffer.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); // Object that serializes the data.
p_type->serializeKey(ser);
if(sample::getKeyMaxCdrSerializedSize()>16) {
m_md5.init();
m_md5.update(m_keyBuffer,(unsigned int)ser.getSerializedDataLength());
m_md5.finalize();
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_md5.digest[i];
}
}
else {
for(uint8_t i = 0;i<16;++i) {
handle->value[i] = m_keyBuffer[i];
}
}
return true;
}
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/Keys/CMakeLists.txt | # 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.
cmake_minimum_required(VERSION 2.8.12)
project("UseCaseDemonstrator")
# Find requirements
find_package(fastcdr REQUIRED)
find_package(fastrtps REQUIRED)
# Set C++11
include(CheckCXXCompilerFlag)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_cxx_compiler_flag(--std=c++11 SUPPORTS_CXX11)
if(SUPPORTS_CXX11)
add_compile_options(--std=c++11)
else()
message(FATAL_ERROR "Compiler doesn't support C++11")
endif()
endif()
message(STATUS "Configuring UseCaseDemonstrator example...")
file(GLOB USECASEDEMONSTRATOR_EXAMPLE_SOURCES "*.cxx")
add_executable(keys ${USECASEDEMONSTRATOR_EXAMPLE_SOURCES} keys.cpp)
target_link_libraries(keys fastrtps fastcdr)
install(TARGETS keys
RUNTIME DESTINATION examples/C++/UseCaseDemonstrator/${BIN_INSTALL_DIR}
)
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/Keys/samplePubSubTypes.h | // 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 samplePubSubTypes.h
* This header file contains the declaration of the serialization functions.
*
* This file was generated by the tool fastcdrgen.
*/
#ifndef _SAMPLE_PUBSUBTYPES_H_
#define _SAMPLE_PUBSUBTYPES_H_
#include <fastrtps/TopicDataType.h>
using namespace eprosima::fastrtps;
#include "sample.h"
/*!
* @brief This class represents the TopicDataType of the type sample defined by the user in the IDL file.
* @ingroup SAMPLE
*/
class samplePubSubType : public TopicDataType {
public:
typedef sample type;
samplePubSubType();
virtual ~samplePubSubType();
bool serialize(void *data, SerializedPayload_t *payload);
bool deserialize(SerializedPayload_t *payload, void *data);
std::function<uint32_t()> getSerializedSizeProvider(void* data);
bool getKey(void *data, InstanceHandle_t *ihandle);
void* createData();
void deleteData(void * data);
MD5 m_md5;
unsigned char* m_keyBuffer;
};
#endif // _sample_PUBSUBTYPE_H_ | 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/Keys/Makefile | # 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.
CPP=g++
LN=g++
AR=ar
CP=cp
SYSLIBS= -ldl -lnsl -lm -lpthread -lrt
DEFINES=
COMMON_CFLAGS= -c -Wall -D__LITTLE_ENDIAN__ -std=c++11
## CHOOSE HERE BETWEEN 32 and 64 bit architecture
##32 BIT ARCH:
#COMMON_CFLAGS+= -m32 -fpic
#LDFLAGS=-m32
#64BIT ARCH:
COMMON_CFLAGS+= -m64 -fpic
LDFLAGS=-m64
CFLAGS = $(COMMON_CFLAGS) -O2
INCLUDES= -I.
LIBS = -lfastcdr -lfastrtps $(SYSLIBS)
DIRECTORIES= output.dir bin.dir
all: $(DIRECTORIES) Keys
KEYS_TARGET= bin/Keys
KEYS_SRC_CXXFILES=
KEYS_SRC_CPPFILES= Keys/keys.cpp \
Keys/sample.cxx \
Keys/samplePubSubTypes.cxx
# Project sources are copied to the current directory
KEYS_SRCS= $(KEYS_SRC_CXXFILES) $(KEYS_SRC_CPPFILES)
# Source directories
KEYS_SOURCES_DIRS_AUX= $(foreach srcdir, $(dir $(KEYS_SRCS)), $(srcdir))
KEYS_SOURCES_DIRS= $(shell echo $(KEYS_SOURCES_DIRS_AUX) | tr " " "\n" | sort | uniq | tr "\n" " ")
KEYS_OBJS = $(foreach obj,$(notdir $(addsuffix .o, $(KEYS_SRCS))), output/$(obj))
KEYS_DEPS = $(foreach dep,$(notdir $(addsuffix .d, $(KEYS_SRCS))), output/$(dep))
OBJS+= $(KEYS_OBJS)
DEPS+= $(KEYS_DEPS)
Keys: $(KEYS_TARGET)
$(KEYS_TARGET): $(KEYS_OBJS)
$(LN) $(LDFLAGS) -o $(KEYS_TARGET) $(KEYS_OBJS) $(LIBS)
vpath %.cxx $(KEYS_SOURCES_DIRS)
vpath %.cpp $(KEYS_SOURCES_DIRS)
output/%.cxx.o:%.cxx
@echo Calculating dependencies $<
@$(CC) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cxx.o=%.cxx.d)
@echo Compiling $<
@$(CC) $(CFLAGS) $(INCLUDES) $< -o $@
output/%.cpp.o:%.cpp
@echo Calculating dependencies $<
@$(CPP) $(CFLAGS) -MM $(CFLAGS) $(INCLUDES) $< | sed "s/^.*:/output\/&/g" > $(@:%.cpp.o=%.cpp.d)
@echo Compiling $<
@$(CPP) $(CFLAGS) $(INCLUDES) $< -o $@
.PHONY: Keys
clean:
@rm -f $(OBJS)
@rm -f $(DEPS)
ifneq ($(MAKECMDGOALS), clean)
-include $(DEPS)
endif
%.dir :
@echo "Checking directory $*"
@if [ ! -d $* ]; then \
echo "Making directory $*"; \
mkdir -p $* ; \
fi;
| 0 |
apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++ | apollo_public_repos/apollo-platform/ros/third_party/fast-rtps_aarch64/share/fastrtps/examples/C++/Keys/sample.cxx | // 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 sample.cpp
* This source file contains the definition of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/
#ifdef _WIN32
// Remove linker warning LNK4221 on Visual Studio
namespace { char dummy; }
#endif
#include "sample.h"
#include <fastcdr/Cdr.h>
#include <fastcdr/exceptions/BadParamException.h>
using namespace eprosima::fastcdr::exception;
#include <utility>
sample::sample()
{
m_index = 0;
m_key_value = 0;
}
sample::~sample()
{
}
sample::sample(const sample &x)
{
m_index = x.m_index;
m_key_value = x.m_key_value;
}
sample::sample(sample &&x)
{
m_index = x.m_index;
m_key_value = x.m_key_value;
}
sample& sample::operator=(const sample &x)
{
m_index = x.m_index;
m_key_value = x.m_key_value;
return *this;
}
sample& sample::operator=(sample &&x)
{
m_index = x.m_index;
m_key_value = x.m_key_value;
return *this;
}
size_t sample::getMaxCdrSerializedSize(size_t current_alignment)
{
size_t initial_alignment = current_alignment;
current_alignment += 1 + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
current_alignment += 1 + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
return current_alignment - initial_alignment;
}
size_t sample::getCdrSerializedSize(const sample& data, size_t current_alignment)
{
size_t initial_alignment = current_alignment;
current_alignment += 1 + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
current_alignment += 1 + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
return current_alignment - initial_alignment;
}
void sample::serialize(eprosima::fastcdr::Cdr &scdr) const
{
scdr << m_index;
scdr << m_key_value;
}
void sample::deserialize(eprosima::fastcdr::Cdr &dcdr)
{
dcdr >> m_index;
dcdr >> m_key_value;
}
size_t sample::getKeyMaxCdrSerializedSize(size_t current_alignment)
{
size_t current_align = current_alignment;
current_align += 1 + eprosima::fastcdr::Cdr::alignment(current_align, 1);
return current_align;
}
bool sample::isKeyDefined()
{
return true;
}
void sample::serializeKey(eprosima::fastcdr::Cdr &scdr) const
{
scdr << m_key_value;
} | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.