-
Notifications
You must be signed in to change notification settings - Fork 1
/
publisher.go
executable file
·43 lines (38 loc) · 1 KB
/
publisher.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
package rtiddsgo
import (
"errors"
)
// #include <ndds/ndds_c.h>
import "C"
type Publisher struct {
pub *C.DDS_Publisher
p Participant
}
// CreatePublisher returns a new publisher with "qosProfileName" from
// "qosLibraryName". Default QoS is used if "qosLibraryName" is an empty string.
// Invoke p.Free() when done with the publisher.
func (p Participant) CreatePublisher(qosLibraryName, qosProfileName string) (Publisher, error) {
pub := Publisher{p: p}
if len(qosLibraryName) == 0 {
pub.pub = C.DDS_DomainParticipant_create_publisher(
pub.p.p,
&C.DDS_PUBLISHER_QOS_DEFAULT,
nil,
C.DDS_STATUS_MASK_NONE)
} else {
pub.pub = C.DDS_DomainParticipant_create_publisher_with_profile(
pub.p.p,
C.CString(qosLibraryName),
C.CString(qosProfileName),
nil,
C.DDS_STATUS_MASK_NONE)
}
if pub.pub == nil {
return pub, errors.New("Failed to create a publisher")
}
return pub, nil
}
func (pub Publisher) Free() {
C.DDS_DomainParticipant_delete_publisher(pub.p.p, pub.pub)
pub.pub = nil
}