00001 #ifndef _DDS_PUBLISHER_H
00002 #define _DDS_PUBLISHER_H
00003
00004 #include <DDSHelper.h>
00005 #include <dds/DCPS/PublisherImpl.h>
00006
00007 namespace ddsnc{
00008
00019
00020 class DDSPublisher : public ::ddsnc::DDSHelper{
00021 private:
00022 DDS::Publisher_var pub;
00023 OpenDDS::DCPS::PublisherImpl *pub_impl;
00024 DDS::DataWriter_var dw;
00025
00026 DDS::InstanceHandle_t handler;
00027
00028 int attachToTransport();
00029
00038 void initialize();
00039
00046 void initializeDataWriter();
00047
00053 int createPublisher();
00054
00055 protected:
00056 DDS::PublisherQos pubQos;
00057
00058 public:
00059 DDS::DataWriterQos dwQos;
00076 DDSPublisher(const char *channelName):
00077 ::ddsnc::DDSHelper(channelName)
00078 {
00079 initialize();
00080 }
00081
00082
00098 template <class D, class DW, class DWVAR, class TSV, class TSI>
00099 void publishData(D data)
00100 {
00101 if(initialized==false){
00102
00103 TSV ts;
00104 ts = new TSI();
00105 if(DDS::RETCODE_OK != ts->register_type(participant.in(),""))
00106 std::cerr << "register_type failed" << std::endl;
00107
00108 initializeTopic(ts->get_type_name());
00109 if(CORBA::is_nil(topic.in()))
00110 std::cerr<< "Topic is nil" << std::endl;
00111 initializeDataWriter();
00112 initialized=true;
00113 }
00114 DWVAR dataWriter = DW::_narrow(dw.in());
00115 handler = dataWriter->_cxx_register(data);
00116 dataWriter->write(data,handler);
00117 }
00118
00119 ~DDSPublisher()
00120 {
00121 }
00122
00123
00124 };
00125 }
00126
00127 #define PUBLISH_DATA(publisher_p, idlStruct, message) \
00128 { \
00129 publisher_p->publishData<idlStruct, idlStruct##DataWriter, \
00130 idlStruct##DataWriter_var, \
00131 idlStruct##TypeSupport_var, idlStruct##TypeSupportImpl> (message); \
00132 }
00133 #endif