Go to the documentation of this file.00001
00023 #include <string>
00024 #include <iostream>
00025 #include <sstream>
00026 #include <vector>
00027 #include "ccpp_dds_dcps.h"
00028 #include "opensplice_dds_comm/check_status.h"
00029 #include "opensplice_dds_comm/ccpp_GSDFPacket.h"
00030 #include "opensplice_dds_comm/example_main.h"
00031 #include "opensplice_dds_comm/publisher.h"
00032
00033 using namespace DDS;
00034
00035 namespace opensplice_dds_comm{
00036
00037 Publisher::Publisher(const std::string& topic_name)
00038 {
00039 domain = 0;
00040 topic_name_ = topic_name.data();
00041 GSDFPacketTypeName = NULL;
00042
00043
00044 dpf = DomainParticipantFactory::get_instance ();
00045 checkHandle(dpf.in(), "DDS::DomainParticipantFactory::get_instance");
00046 participant = dpf->create_participant(domain, PARTICIPANT_QOS_DEFAULT, NULL, STATUS_MASK_NONE);
00047 checkHandle(participant.in(), "DDS::DomainParticipantFactory::create_participant");
00048
00049
00050 GSDFPacketTS = new GSDFPacketTypeSupport();
00051 checkHandle(GSDFPacketTS.in(), "new GSDFPacketTypeSupport");
00052 GSDFPacketTypeName = GSDFPacketTS->get_type_name();
00053 status = GSDFPacketTS->register_type(
00054 participant.in(),
00055 GSDFPacketTypeName);
00056 checkStatus(status, "micros_swarm_framework::GSDFPacketTypeSupport::register_type");
00057
00058
00059 status = participant->get_default_topic_qos(topic_qos);
00060 checkStatus(status, "DDS::DomainParticipant::get_default_topic_qos");
00061 topic_qos.reliability.kind = BEST_EFFORT_RELIABILITY_QOS;
00062
00063 topic_qos.durability_service.history_kind = KEEP_LAST_HISTORY_QOS;
00064
00065
00066
00067 status = participant->set_default_topic_qos(topic_qos);
00068 checkStatus(status, "DDS::DomainParticipant::set_default_topic_qos");
00069
00070
00071 GSDFPacketTopic = participant->create_topic(
00072 topic_name_,
00073 GSDFPacketTypeName,
00074 topic_qos,
00075 NULL,
00076 STATUS_MASK_NONE);
00077 checkHandle(GSDFPacketTopic.in(), "DDS::DomainParticipant::create_topic (GSDFPacket)");
00078
00079
00080 status = participant->get_default_publisher_qos (pub_qos);
00081 checkStatus(status, "DDS::DomainParticipant::get_default_publisher_qos");
00082 pub_qos.partition.name.length(1);
00083 pub_qos.partition.name[0] = "micros_swarm_framework_partion";
00084
00085
00086 publisher_ = participant->create_publisher(pub_qos, NULL, STATUS_MASK_NONE);
00087 checkHandle(publisher_.in(), "DDS::DomainParticipant::create_publisher");
00088
00089 status = publisher_->get_default_datawriter_qos(dw_qos);
00090 dw_qos.destination_order.kind = BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS;
00091 dw_qos.history.kind = KEEP_ALL_HISTORY_QOS;
00092
00093
00094 dw_qos.durability.kind = VOLATILE_DURABILITY_QOS;
00095
00096
00097 parentWriter = publisher_->create_datawriter(
00098 GSDFPacketTopic.in(),
00099 dw_qos,
00100 NULL,
00101 STATUS_MASK_NONE);
00102 checkHandle(parentWriter, "DDS::Publisher::create_datawriter (GSDFPacket)");
00103
00104
00105 GSDFPacketDW = GSDFPacketDataWriter::_narrow(parentWriter);
00106 checkHandle(GSDFPacketDW.in(), "micros_swarm_framework::GSDFPacketDataWriter::_narrow");
00107 }
00108
00109 void Publisher::publish(const GSDFPacket& packet)
00110 {
00111 status = GSDFPacketDW->write(packet, DDS::HANDLE_NIL);
00112 checkStatus(status, "micros_swarm_framework::GSDFPacketDataWriter::write");
00113 }
00114
00115 Publisher::~Publisher()
00116 {
00117
00118 status = publisher_->delete_datawriter(GSDFPacketDW.in() );
00119 checkStatus(status, "DDS::Publisher::delete_datawriter (GSDFPacketDW)");
00120
00121
00122 status = participant->delete_publisher(publisher_.in() );
00123 checkStatus(status, "DDS::DomainParticipant::delete_publisher");
00124
00125 status = participant->delete_topic( GSDFPacketTopic.in() );
00126 checkStatus(status, "DDS::DomainParticipant::delete_topic (GSDFPacketTopic)");
00127
00128
00129 string_free(GSDFPacketTypeName);
00130
00131
00132 status = dpf->delete_participant( participant.in() );
00133 checkStatus(status, "DDS::DomainParticipantFactory::delete_participant");
00134
00135
00136 }
00137 };