-
Notifications
You must be signed in to change notification settings - Fork 0
/
pro_publisher.cxx
223 lines (181 loc) · 7.03 KB
/
pro_publisher.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/******************************************************************************
(C) Copyright 2020-2022 Real-Time Innovations, Inc. All rights reserved.
The use of this software is governed by the terms specified in the
RTI Labs License Agreement, available at https://www.rti.com/terms/RTILabs.
By accessing, downloading, or otherwise using this software, you agree to
be bound by those terms.
*****************************************************************************/
/* pro_publisher.cxx
A publication of data of type dds::sensing::Camera
This file is derived from code automatically generated by the rtiddsgen
command:
rtiddsgen -language C++ -example <arch> pro.idl
Example publication of type dds::sensing::Camera automatically generated by
'rtiddsgen'. To test it, follow these steps:
(1) Compile this file and the example subscription.
(2) Start the subscription
(3) Start the publication
(4) [Optional] Specify the list of discovery initial peers and
multicast receive addresses via an environment variable or a file
(in the current working directory) called NDDS_DISCOVERY_PEERS.
You can run any number of publisher and subscriber programs, and can
add and remove them dynamically from the domain.
*/
#include <stdio.h>
#include <stdlib.h>
#include "res/types/services/Drive_t.h"
#include "res/types/data/sensing/Camera_t.h"
#include "res/types/data/sensing/Camera_tSupport.h"
#include "ndds/ndds_cpp.h"
/* Delete all entities */
static int publisher_shutdown(
DDSDomainParticipant *participant)
{
DDS_ReturnCode_t retcode;
int status = 0;
if (participant != NULL) {
retcode = participant->delete_contained_entities();
if (retcode != DDS_RETCODE_OK) {
fprintf(stderr, "delete_contained_entities error %d\n", retcode);
status = -1;
}
retcode = DDSTheParticipantFactory->delete_participant(participant);
if (retcode != DDS_RETCODE_OK) {
fprintf(stderr, "delete_participant error %d\n", retcode);
status = -1;
}
}
/* RTI Connext provides finalize_instance() method on
domain participant factory for people who want to release memory used
by the participant factory. Uncomment the following block of code for
clean destruction of the singleton. */
/*
retcode = DDSDomainParticipantFactory::finalize_instance();
if (retcode != DDS_RETCODE_OK) {
fprintf(stderr, "finalize_instance error %d\n", retcode);
status = -1;
}
*/
return status;
}
extern "C" int publisher_main(int domainId, int sample_count)
{
DDSDomainParticipant *participant = NULL;
DDSPublisher *publisher = NULL;
DDSTopic *topic = NULL;
DDSDataWriter *writer = NULL;
dds::sensing::CameraDataWriter * Camera_writer = NULL;
dds::sensing::Camera *instance = NULL;
DDS_ReturnCode_t retcode;
DDS_InstanceHandle_t instance_handle = DDS_HANDLE_NIL;
const char *type_name = NULL;
int count = 0;
DDS_Duration_t send_period = {4,0};
/* To customize participant QoS, use
the configuration file USER_QOS_PROFILES.xml */
participant = DDSTheParticipantFactory->create_participant(
domainId, DDS_PARTICIPANT_QOS_DEFAULT,
NULL /* listener */, DDS_STATUS_MASK_NONE);
if (participant == NULL) {
fprintf(stderr, "create_participant error\n");
publisher_shutdown(participant);
return -1;
}
/* To customize publisher QoS, use
the configuration file USER_QOS_PROFILES.xml */
publisher = participant->create_publisher(
DDS_PUBLISHER_QOS_DEFAULT, NULL /* listener */, DDS_STATUS_MASK_NONE);
if (publisher == NULL) {
fprintf(stderr, "create_publisher error\n");
publisher_shutdown(participant);
return -1;
}
/* Register type before creating topic */
type_name = dds::Drive::Bus::main::registered_type::Camera;
retcode = dds::sensing::CameraTypeSupport::register_type(
participant, type_name);
if (retcode != DDS_RETCODE_OK) {
fprintf(stderr, "register_type error %d\n", retcode);
publisher_shutdown(participant);
return -1;
}
/* To customize topic QoS, use
the configuration file USER_QOS_PROFILES.xml */
topic = participant->create_topic(
dds::Drive::Bus::main::topic::Camera,
type_name, DDS_TOPIC_QOS_DEFAULT, NULL /* listener */,
DDS_STATUS_MASK_NONE);
if (topic == NULL) {
fprintf(stderr, "create_topic error\n");
publisher_shutdown(participant);
return -1;
}
/* To customize data writer QoS, use
the configuration file USER_QOS_PROFILES.xml */
writer = publisher->create_datawriter(
topic, DDS_DATAWRITER_QOS_DEFAULT, NULL /* listener */,
DDS_STATUS_MASK_NONE);
if (writer == NULL) {
fprintf(stderr, "create_datawriter error\n");
publisher_shutdown(participant);
return -1;
}
Camera_writer = dds::sensing::CameraDataWriter::narrow(writer);
if (Camera_writer == NULL) {
fprintf(stderr, "DataWriter narrow error\n");
publisher_shutdown(participant);
return -1;
}
/* Create data sample for writing */
instance = dds::sensing::CameraTypeSupport::create_data();
if (instance == NULL) {
fprintf(stderr, "dds::sensing::CameraTypeSupport::create_data error\n");
publisher_shutdown(participant);
return -1;
}
/* For a data type that has a key, if the same instance is going to be
written multiple times, initialize the key here
and register the keyed instance prior to writing */
// instance_handle = dds::sensing::CameraImage_writer->register_instance(*instance);
/* Main loop */
for (count=0; (sample_count == 0) || (count < sample_count); ++count) {
printf("Writing Camera, count %d\n", count);
/* Modify the data to be sent here */
retcode = Camera_writer->write(*instance, instance_handle);
if (retcode != DDS_RETCODE_OK) {
fprintf(stderr, "write error %d\n", retcode);
}
NDDSUtility::sleep(send_period);
}
/*
retcode = Camera_writer->unregister_instance(
*instance, instance_handle);
if (retcode != DDS_RETCODE_OK) {
fprintf(stderr, "unregister instance error %d\n", retcode);
}
*/
/* Delete data sample */
retcode = dds::sensing::CameraTypeSupport::delete_data(instance);
if (retcode != DDS_RETCODE_OK) {
fprintf(stderr, "dds::sensing::CameraTypeSupport::delete_data error %d\n", retcode);
}
/* Delete all entities */
return publisher_shutdown(participant);
}
int main(int argc, char *argv[])
{
int domain_id = 0;
int sample_count = 0; /* infinite loop */
if (argc >= 2) {
domain_id = atoi(argv[1]);
}
if (argc >= 3) {
sample_count = atoi(argv[2]);
}
/* Uncomment this to turn on additional logging
NDDSConfigLogger::get_instance()->
set_verbosity_by_category(NDDS_CONFIG_LOG_CATEGORY_API,
NDDS_CONFIG_LOG_VERBOSITY_STATUS_ALL);
*/
return publisher_main(domain_id, sample_count);
}