summaryrefslogtreecommitdiff
path: root/dds_io_pub/dds_io_pub.cpp
diff options
context:
space:
mode:
authorguest <guest@c30cbac5-9f56-4f76-8ed5-5c34e48a65ae>2007-10-10 08:11:16 +0000
committerguest <guest@c30cbac5-9f56-4f76-8ed5-5c34e48a65ae>2007-10-10 08:11:16 +0000
commitcf15d52a8d98f69623bcacda785d71872551f040 (patch)
tree4fb0124a4de9cf19807828240f2cd36bd5235696 /dds_io_pub/dds_io_pub.cpp
parentd3d7bd1ec32c3b37c512cbc59b5860f2eb75de35 (diff)
Initial import.
git-svn-id: svn+ssh://mecka.net/home/svn/dds@5 c30cbac5-9f56-4f76-8ed5-5c34e48a65ae
Diffstat (limited to 'dds_io_pub/dds_io_pub.cpp')
-rw-r--r--dds_io_pub/dds_io_pub.cpp218
1 files changed, 218 insertions, 0 deletions
diff --git a/dds_io_pub/dds_io_pub.cpp b/dds_io_pub/dds_io_pub.cpp
new file mode 100644
index 0000000..acb67f9
--- /dev/null
+++ b/dds_io_pub/dds_io_pub.cpp
@@ -0,0 +1,218 @@
+//============================================================================
+// Name : dds_publisher.cpp
+// Author :
+// Version :
+// Copyright : Your copyright notice
+// Description : Hello World in C++, Ansi-style
+//============================================================================
+
+#include <iostream>
+using namespace std;
+
+#include "PortTypeSupportImpl.h"
+#include "Writer.h"
+
+#include <dds/DCPS/Service_Participant.h>
+#include <dds/DCPS/Marked_Default_Qos.h>
+#include <dds/DCPS/PublisherImpl.h>
+#include <dds/DCPS/transport/framework/TheTransportFactory.h>
+#include <dds/DCPS/transport/simpleTCP/SimpleTcpConfiguration.h>
+#ifdef ACE_AS_STATIC_LIBS
+#include <dds/DCPS/transport/simpleTCP/SimpleTcp.h>
+#include <dds/DCPS/transport/simpleUnreliableDgram/SimpleUnreliableDgram.h>
+#include <dds/DCPS/transport/ReliableMulticast/ReliableMulticast.h>
+#endif
+
+#include <ace/streams.h>
+#include "ace/Get_Opt.h"
+
+using namespace IOTest;
+
+OpenDDS::DCPS::TransportIdType transport_impl_id = 1;
+
+int
+parse_args (int argc, char *argv[])
+{
+ ACE_Get_Opt get_opts (argc, argv, "t:");
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ {
+ switch (c)
+ {
+ case 't':
+ if (ACE_OS::strcmp (get_opts.opt_arg (), "udp") == 0) {
+ transport_impl_id = 2;
+ }
+ else if (ACE_OS::strcmp (get_opts.opt_arg (), "mcast") == 0) {
+ transport_impl_id = 3;
+ }
+ else if (ACE_OS::strcmp (get_opts.opt_arg (), "reliable_mcast") == 0) {
+ transport_impl_id = 4;
+ }
+ // test with DEFAULT_SIMPLE_TCP_ID.
+ else if (ACE_OS::strcmp (get_opts.opt_arg (), "default_tcp") == 0) {
+ transport_impl_id = OpenDDS::DCPS::DEFAULT_SIMPLE_TCP_ID;
+ }
+ // test with DEFAULT_SIMPLE_UDP_ID.
+ else if (ACE_OS::strcmp (get_opts.opt_arg (), "default_udp") == 0) {
+ transport_impl_id = OpenDDS::DCPS::DEFAULT_SIMPLE_UDP_ID;
+ }
+ else if (ACE_OS::strcmp (get_opts.opt_arg (), "default_mcast_pub") == 0) {
+ transport_impl_id = OpenDDS::DCPS::DEFAULT_SIMPLE_MCAST_PUB_ID;
+ }
+ break;
+ case '?':
+ default:
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "usage: %s "
+ "-t <tcp/udp/default> "
+ "\n",
+ argv [0]),
+ -1);
+ }
+ }
+ // Indicates sucessful parsing of the command line
+ return 0;
+}
+
+
+
+int main(int argc, char** argv) {
+
+ try
+ {
+ DDS::DomainParticipantFactory_var dpf =
+ TheParticipantFactoryWithArgs(argc, argv);
+
+ cout<<"DomainParticpantFactory ok\n";
+
+ DDS::DomainParticipant_var participant =
+ dpf->create_participant(411,
+ PARTICIPANT_QOS_DEFAULT,
+ DDS::DomainParticipantListener::_nil());
+
+ if (CORBA::is_nil (participant.in ())) {
+ cerr << "create_participant failed." << endl;
+ return 1;
+ }
+
+ cout<<"DomainParticpant ok\n";
+
+ if (parse_args (argc, argv) == -1) {
+ return -1;
+ }
+
+ PortTypeSupport_var pts = new PortTypeSupportImpl();
+
+ if (DDS::RETCODE_OK != pts->register_type(participant.in (), "")) {
+ cerr << "register_type failed." << endl;
+ exit(1);
+ }
+
+ cout<<"PortTypeSupport registered\n";
+
+ CORBA::String_var type_name = pts->get_type_name ();
+
+ DDS::TopicQos topic_qos;
+ participant->get_default_topic_qos(topic_qos);
+ DDS::Topic_var topic =
+ participant->create_topic ("IOTest",
+ type_name.in (),
+ topic_qos,
+ DDS::TopicListener::_nil());
+ if (CORBA::is_nil (topic.in ())) {
+ cerr << "create_topic failed." << endl;
+ exit(1);
+ }
+
+ cout<<"Topic created\n";
+
+ OpenDDS::DCPS::TransportImpl_rch tcp_impl =
+ TheTransportFactory->create_transport_impl (transport_impl_id,
+ ::OpenDDS::DCPS::AUTO_CONFIG);
+
+ cout<<"Transport ok\n";
+
+ DDS::Publisher_var pub =
+ participant->create_publisher(PUBLISHER_QOS_DEFAULT,
+ DDS::PublisherListener::_nil());
+ if (CORBA::is_nil (pub.in ())) {
+ cerr << "create_publisher failed." << endl;
+ exit(1);
+ }
+
+ cout<<"Publisher created\n";
+
+ // Attach the publisher to the transport.
+ OpenDDS::DCPS::PublisherImpl* pub_impl =
+ OpenDDS::DCPS::reference_to_servant<OpenDDS::DCPS::PublisherImpl> (pub.in ());
+ if (0 == pub_impl) {
+ cerr << "Failed to obtain publisher servant" << endl;
+ exit(1);
+ }
+
+ cout<<"Servant obtained\n";
+
+ OpenDDS::DCPS::AttachStatus status = pub_impl->attach_transport(tcp_impl.in());
+ if (status != OpenDDS::DCPS::ATTACH_OK) {
+ std::string status_str;
+ switch (status) {
+ case OpenDDS::DCPS::ATTACH_BAD_TRANSPORT:
+ status_str = "ATTACH_BAD_TRANSPORT";
+ break;
+ case OpenDDS::DCPS::ATTACH_ERROR:
+ status_str = "ATTACH_ERROR";
+ break;
+ case OpenDDS::DCPS::ATTACH_INCOMPATIBLE_QOS:
+ status_str = "ATTACH_INCOMPATIBLE_QOS";
+ break;
+ default:
+ status_str = "Unknown Status";
+ break;
+ }
+ cerr << "Failed to attach to the transport. Status == "
+ << status_str.c_str() << endl;
+ exit(1);
+ }
+
+ cout<<"Status ok\n";
+
+ // Create the datawriter
+ DDS::DataWriterQos dw_qos;
+ pub->get_default_datawriter_qos (dw_qos);
+ DDS::DataWriter_var dw =
+ pub->create_datawriter(topic.in (),
+ dw_qos,
+ DDS::DataWriterListener::_nil());
+ if (CORBA::is_nil (dw.in ())) {
+ cerr << "create_datawriter failed." << endl;
+ exit(1);
+ }
+ Writer* writer = new Writer(dw.in());
+
+ cout<<"starting Datawriter...\n";
+
+ writer->start ();
+ while ( !writer->is_finished()) {
+ ACE_Time_Value small(0,250000);
+ ACE_OS::sleep (small);
+ }
+
+ // Cleanup
+ writer->end ();
+ delete writer;
+ participant->delete_contained_entities();
+ dpf->delete_participant(participant.in ());
+ TheTransportFactory->release();
+ TheServiceParticipant->shutdown ();
+ }
+ catch (CORBA::Exception& e)
+ {
+ cerr << "PUB: Exception caught in main.cpp:" << endl
+ << e << endl;
+ exit(1);
+ }
+
+ return 0;
+}