FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
DDSCoreExample/src/HelloPublisher.java at master · FIUDiscoveryLab/DDSCoreExample · GitHub
FIUDiscoveryLab
DDSCoreExample
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
DDSCoreExample
/
src
/
HelloPublisher.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
90 lines (81 loc) · 3.76 KB
Breadcrumbs
DDSCoreExample
/
src
/
HelloPublisher.java
Copy path
File metadata and controls
90 lines (81 loc) · 3.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
// ****************************************************************************
// (c) Copyright, Real-Time Innovations, All rights reserved.
//
// Permission to modify and use for internal purposes granted.
// This software is provided "as is", without warranty, express or implied.
//
// ****************************************************************************
import
java
.
io
.
BufferedReader
;
import
java
.
io
.
IOException
;
import
java
.
io
.
InputStreamReader
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
List
;
import
com
.
rti
.
dds
.
domain
.
DomainParticipant
;
import
com
.
rti
.
dds
.
domain
.
DomainParticipantFactory
;
import
com
.
rti
.
dds
.
domain
.
DomainParticipantFactoryQos
;
import
com
.
rti
.
dds
.
infrastructure
.
InstanceHandle_t
;
import
com
.
rti
.
dds
.
infrastructure
.
RETCODE_ERROR
;
import
com
.
rti
.
dds
.
infrastructure
.
StatusKind
;
import
com
.
rti
.
dds
.
publication
.
Publisher
;
import
com
.
rti
.
dds
.
topic
.
Topic
;
import
com
.
rti
.
dds
.
type
.
builtin
.
StringDataWriter
;
import
com
.
rti
.
dds
.
type
.
builtin
.
StringTypeSupport
;
import
com
.
rti
.
dds
.
subscription
.
Subscriber
;
//****************************************************************************
public
class
HelloPublisher
{
public
static
final
void
main
(
String
[]
args
) {
DomainParticipant
participant
=
DomainParticipantFactory
.
get_instance
().
create_participant
(
0
,
// Domain ID = 0
DomainParticipantFactory
.
PARTICIPANT_QOS_DEFAULT
,
null
,
// listener
StatusKind
.
STATUS_MASK_NONE
);
if
(
participant
==
null
) {
System
.
err
.
println
(
"Unable to create domain participant"
);
return
;
}
// Create the topic "Hello World" for the String type
Topic
topic
=
participant
.
create_topic
(
"Hello, World"
,
StringTypeSupport
.
get_type_name
(),
DomainParticipant
.
TOPIC_QOS_DEFAULT
,
null
,
// listener
StatusKind
.
STATUS_MASK_NONE
);
if
(
topic
==
null
) {
System
.
err
.
println
(
"Unable to create topic."
);
return
;
}
// Create the data writer using the default publisher
StringDataWriter
dataWriter
=
(
StringDataWriter
)
participant
.
create_datawriter
(
topic
,
Publisher
.
DATAWRITER_QOS_DEFAULT
,
null
,
// listener
StatusKind
.
STATUS_MASK_NONE
);
if
(
dataWriter
==
null
) {
System
.
err
.
println
(
"Unable to create data writer
\n
"
);
return
;
}
System
.
out
.
println
(
"Ready to write data."
);
System
.
out
.
println
(
"When the subscriber is ready, you can start writing."
);
System
.
out
.
print
(
"Press CTRL+C to terminate or enter an empty line to do a clean shutdown.
\n
\n
"
);
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
));
try
{
while
(
true
) {
System
.
out
.
print
(
"Please type a message> "
);
String
toWrite
=
reader
.
readLine
();
if
(
toWrite
==
null
)
break
;
// shouldn't happen
dataWriter
.
write
(
toWrite
,
InstanceHandle_t
.
HANDLE_NIL
);
if
(
toWrite
.
equals
(
""
))
break
;
}
}
catch
(
IOException
e
) {
// This exception can be thrown from the BufferedReader class
e
.
printStackTrace
();
}
catch
(
RETCODE_ERROR
e
) {
// This exception can be thrown from DDS write operation
e
.
printStackTrace
();
}
System
.
out
.
println
(
"Exiting..."
);
participant
.
delete_contained_entities
();
DomainParticipantFactory
.
get_instance
().
delete_participant
(
participant
);
}
}
Back
|
FazBrowse Home
|
New Git URL