-
Notifications
You must be signed in to change notification settings - Fork 1
/
topic.go
executable file
·60 lines (53 loc) · 1.31 KB
/
topic.go
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
package rtiddsgo
import (
"errors"
"unsafe"
)
// #include <stdlib.h>
// #include <ndds/ndds_c.h>
import "C"
type Topic struct {
t *C.DDS_Topic
p Participant
name, typeName *C.char
}
// CreateTopic returns a new topic with "qosProfileName" from
// "qosLibraryName". Default QoS is used in "qosLibraryName" if an empty string.
// Invoke p.Free() when done with the topic.
func (p Participant) CreateTopic(name, typeName string, qosLibraryName, qosProfileName string) (Topic, error) {
t := Topic{p: p, name: C.CString(name), typeName: C.CString(typeName)}
if len(qosLibraryName) == 0 {
t.t = C.DDS_DomainParticipant_create_topic(
t.p.p,
t.name,
t.typeName,
&C.DDS_TOPIC_QOS_DEFAULT,
nil,
C.DDS_STATUS_MASK_NONE)
} else {
t.t = C.DDS_DomainParticipant_create_topic_with_profile(
t.p.p,
t.name,
t.typeName,
C.CString(qosLibraryName),
C.CString(qosProfileName),
nil,
C.DDS_STATUS_MASK_NONE)
}
if t.t == nil {
return t, errors.New("Failed to create a topic")
}
return t, nil
}
func (t Topic) Free() {
C.DDS_DomainParticipant_delete_topic(t.p.p, t.t)
t.t = nil
C.free(unsafe.Pointer(t.name))
C.free(unsafe.Pointer(t.typeName))
}
func (t Topic) description() *C.DDS_TopicDescription {
if t.t == nil {
return nil
}
return t.t._as_TopicDescription
}