27 #include "ccpp_dds_dcps.h" 37 Publisher::Publisher(
const std::string& topic_name)
40 topic_name_ = topic_name.data();
41 GSDFPacketTypeName = NULL;
44 dpf = DomainParticipantFactory::get_instance ();
45 checkHandle(dpf.in(),
"DDS::DomainParticipantFactory::get_instance");
46 participant = dpf->create_participant(domain, PARTICIPANT_QOS_DEFAULT, NULL, STATUS_MASK_NONE);
47 checkHandle(participant.in(),
"DDS::DomainParticipantFactory::create_participant");
51 checkHandle(GSDFPacketTS.in(),
"new GSDFPacketTypeSupport");
52 GSDFPacketTypeName = GSDFPacketTS->get_type_name();
53 status = GSDFPacketTS->register_type(
56 checkStatus(status,
"micros_swarm_framework::GSDFPacketTypeSupport::register_type");
59 status = participant->get_default_topic_qos(topic_qos);
60 checkStatus(status,
"DDS::DomainParticipant::get_default_topic_qos");
61 topic_qos.reliability.kind = BEST_EFFORT_RELIABILITY_QOS;
63 topic_qos.durability_service.history_kind = KEEP_LAST_HISTORY_QOS;
67 status = participant->set_default_topic_qos(topic_qos);
68 checkStatus(status,
"DDS::DomainParticipant::set_default_topic_qos");
71 GSDFPacketTopic = participant->create_topic(
77 checkHandle(GSDFPacketTopic.in(),
"DDS::DomainParticipant::create_topic (GSDFPacket)");
80 status = participant->get_default_publisher_qos (pub_qos);
81 checkStatus(status,
"DDS::DomainParticipant::get_default_publisher_qos");
82 pub_qos.partition.name.length(1);
83 pub_qos.partition.name[0] =
"micros_swarm_framework_partion";
86 publisher_ = participant->create_publisher(pub_qos, NULL, STATUS_MASK_NONE);
87 checkHandle(publisher_.in(),
"DDS::DomainParticipant::create_publisher");
89 status = publisher_->get_default_datawriter_qos(dw_qos);
90 dw_qos.destination_order.kind = BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS;
91 dw_qos.history.kind = KEEP_ALL_HISTORY_QOS;
94 dw_qos.durability.kind = VOLATILE_DURABILITY_QOS;
97 parentWriter = publisher_->create_datawriter(
102 checkHandle(parentWriter,
"DDS::Publisher::create_datawriter (GSDFPacket)");
105 GSDFPacketDW = GSDFPacketDataWriter::_narrow(parentWriter);
106 checkHandle(GSDFPacketDW.in(),
"micros_swarm_framework::GSDFPacketDataWriter::_narrow");
111 status = GSDFPacketDW->write(packet, DDS::HANDLE_NIL);
112 checkStatus(status,
"micros_swarm_framework::GSDFPacketDataWriter::write");
115 Publisher::~Publisher()
118 status = publisher_->delete_datawriter(GSDFPacketDW.in() );
119 checkStatus(status,
"DDS::Publisher::delete_datawriter (GSDFPacketDW)");
122 status = participant->delete_publisher(publisher_.in() );
123 checkStatus(status,
"DDS::DomainParticipant::delete_publisher");
125 status = participant->delete_topic( GSDFPacketTopic.in() );
126 checkStatus(status,
"DDS::DomainParticipant::delete_topic (GSDFPacketTopic)");
129 string_free(GSDFPacketTypeName);
132 status = dpf->delete_participant( participant.in() );
133 checkStatus(status,
"DDS::DomainParticipantFactory::delete_participant");
void checkStatus(DDS::ReturnCode_t status, const char *info)
void checkHandle(void *handle, const char *info)