25 #include "ccpp_dds_dcps.h" 37 Subscriber::Subscriber(
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 (
48 PARTICIPANT_QOS_DEFAULT,
51 checkHandle(participant,
"DDS::DomainParticipantFactory::create_participant");
55 checkHandle(GSDFPacketTS.in(),
"new GSDFPacketTypeSupport");
56 GSDFPacketTypeName = GSDFPacketTS->get_type_name();
57 status = GSDFPacketTS->register_type(
60 checkStatus(status,
"NetworkPartitionsData::GSDFPacketTypeSupport::register_type");
63 status = participant->get_default_topic_qos(topic_qos);
64 checkStatus(status,
"DDS::DomainParticipant::get_default_topic_qos");
66 topic_qos.reliability.kind = BEST_EFFORT_RELIABILITY_QOS;
68 topic_qos.durability_service.history_kind = KEEP_LAST_HISTORY_QOS;
72 status = participant->set_default_topic_qos(topic_qos);
73 checkStatus(status,
"DDS::DomainParticipant::set_default_topic_qos");
76 GSDFPacketTopic = participant->create_topic(
82 checkHandle(GSDFPacketTopic.in(),
"DDS::DomainParticipant::create_topic (GSDFPacket)");
85 status = participant->get_default_subscriber_qos (sub_qos);
86 checkStatus(status,
"DDS::DomainParticipant::get_default_subscriber_qos");
87 sub_qos.partition.name.length(1);
88 std::string partition_name=
"micros_swarm_framework_partion";
89 sub_qos.partition.name[0] = partition_name.data();
92 subscriber_ = participant->create_subscriber(sub_qos, NULL, STATUS_MASK_NONE);
93 checkHandle(subscriber_.in(),
"DDS::DomainParticipant::create_subscriber");
95 status = subscriber_->get_default_datareader_qos(dr_qos);
96 dr_qos.history.kind = KEEP_ALL_HISTORY_QOS;
98 dr_qos.destination_order.kind = BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS;
100 dr_qos.durability.kind = VOLATILE_DURABILITY_QOS;
103 parentReader = subscriber_->create_datareader(
104 GSDFPacketTopic.in(),
108 checkHandle(parentReader,
"DDS::Subscriber::create_datareader");
111 GSDFPacketDR = GSDFPacketDataReader::_narrow(parentReader);
112 checkHandle(GSDFPacketDR.in(),
"NetworkPartitionsData::GSDFPacketDataReader::_narrow");
124 DDS::StatusMask mask = DDS::DATA_AVAILABLE_STATUS;
126 GSDFPacketDR->set_listener(myListener, mask);
137 DDS::StatusMask mask = DDS::DATA_AVAILABLE_STATUS;
139 GSDFPacketDR->set_listener(myListener, mask);
142 Subscriber::~Subscriber()
145 status = subscriber_->delete_datareader(GSDFPacketDR.in());
146 checkStatus(status,
"DDS::Subscriber::delete_datareader");
149 status = participant->delete_subscriber(subscriber_.in());
150 checkStatus(status,
"DDS::DomainParticipant::delete_subscriber");
153 status = participant->delete_topic(GSDFPacketTopic.in());
154 checkStatus(status,
"DDS::DomainParticipant::delete_topic (GSDFPacketTopic)");
157 string_free(GSDFPacketTypeName);
160 status = dpf->delete_participant(participant.in());
161 checkStatus(status,
"DDS::DomainParticipantFactory::delete_participant");
void checkStatus(DDS::ReturnCode_t status, const char *info)
void callBack(const opensplice_dds_broker::GSDFPacket &packet)
void checkHandle(void *handle, const char *info)
boost::function< void(const GSDFPacket &)> callBack_