MCPcopy Create free account
hub / github.com/OpenDDS/OpenDDS / sub_program

Function sub_program

tests/DCPS/FindTopic/findtopic.cpp:38–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36using namespace std;
37
38int sub_program(DDS::DomainParticipant* participant)
39{
40 const DDS::Duration_t timeout = {0, 0};
41 // Doing a find_topic will require us to call delete topic twice, see
42 // 7.1.2.2.1.11 from the dds spec
43 DDS::Topic_var topic2 = participant->find_topic("Movie Discussion List", timeout);
44 if (!topic2) {
45 ACE_ERROR_RETURN((LM_ERROR, "%N:%l: main() ERROR: Not able to find topic\n"), EXIT_FAILURE);
46 }
47
48 // Now using topic2 we create a second publisher and datawriter
49 DDS::Publisher_var pub2 = participant->create_publisher(PUBLISHER_QOS_DEFAULT, 0, 0);
50 if (!pub2) {
51 ACE_ERROR_RETURN((LM_ERROR, "%N:%l: main() ERROR: create_publisher 2 failed!\n"), EXIT_FAILURE);
52 }
53
54 DDS::DataWriter_var dw2 = pub2->create_datawriter(topic2, DATAWRITER_QOS_DEFAULT, 0, 0);
55 if (!dw2) {
56 ACE_ERROR_RETURN((LM_ERROR, "%N:%l: main() ERROR: create_datawriter 2 failed!\n"), EXIT_FAILURE);
57 }
58
59 // Do now a find for topic "Movie Discussion List", that should return a new topic which we directly
60 // delete again which should work because this new topic is not used.
61 DDS::Topic_var topic3 = participant->find_topic("Movie Discussion List", timeout);
62 if (!topic3) {
63 ACE_ERROR_RETURN((LM_ERROR, "%N:%l: main() ERROR: Not able to find topic 3\n"), EXIT_FAILURE);
64 }
65 // topic2 and topic3 should have the same instance handles
66 if (topic2->get_instance_handle() != topic3->get_instance_handle()) {
67 ACE_ERROR_RETURN((LM_ERROR, "%N:%l: main() ERROR: topic2 and topic3 should have the same instance handles\n"), EXIT_FAILURE);
68 }
69 // Now delete the topic3 again
70 const DDS::ReturnCode_t retcode6 = participant->delete_topic(topic3);
71 if (retcode6 != DDS::RETCODE_OK) {
72 ACE_ERROR_RETURN((LM_ERROR, "%N:%l: main() ERROR: should be able to delete topic 3\n"), EXIT_FAILURE);
73 }
74 topic3 = 0;
75
76 // Now the second part will cleanup its datawriter/publisher
77 const DDS::ReturnCode_t retcode12 = pub2->delete_datawriter(dw2);
78 if (retcode12 != DDS::RETCODE_OK) {
79 ACE_ERROR_RETURN((LM_ERROR, "%N:%l: main() ERROR: should be able to delete datawriter 2\n"), EXIT_FAILURE);
80 }
81 dw2 = 0;
82
83 const DDS::ReturnCode_t retcode9 = participant->delete_publisher(pub2);
84 if (retcode9 != DDS::RETCODE_OK) {
85 ACE_ERROR_RETURN((LM_ERROR, "%N:%l: main() ERROR: should be able to delete publisher 2\n"), EXIT_FAILURE);
86 }
87 pub2 = 0;
88
89 // Now we should be able to delete out topic2, we deleted the entities we created
90 const DDS::ReturnCode_t retcode4 = participant->delete_topic(topic2);
91 if (retcode4 != DDS::RETCODE_OK) {
92 ACE_ERROR_RETURN((LM_ERROR, "%N:%l: main() ERROR: should be able to delete topic\n"), EXIT_FAILURE);
93 }
94
95 return EXIT_SUCCESS;

Callers 1

ACE_TMAINFunction · 0.85

Calls 7

delete_topicMethod · 0.80
delete_datawriterMethod · 0.80
delete_publisherMethod · 0.80
find_topicMethod · 0.45
create_publisherMethod · 0.45
create_datawriterMethod · 0.45
get_instance_handleMethod · 0.45

Tested by

no test coverage detected