-
Notifications
You must be signed in to change notification settings - Fork 1
/
participant.go
executable file
·63 lines (56 loc) · 2.05 KB
/
participant.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
61
62
63
package rtiddsgo
import (
"errors"
"fmt"
"unsafe"
)
// #cgo CFLAGS: -DRTI_UNIX -m64 -I/home/johan/rti_connext_dds-6.0.0/include -I/home/johan/rti_connext_dds-6.0.0/include/ndds -I/usr/include/x86_64-linux-gnu
// #cgo LDFLAGS: -L/home/johan/rti_connext_dds-6.0.0/lib/x64Linux3gcc4.8.2 -lnddscz -lnddscorez -ldl -lnsl -lm -lpthread -lrt -Wl,--no-as-needed
// #include <ndds/ndds_c.h>
import "C"
type Participant struct {
p *C.DDS_DomainParticipant
}
// New returns a new participant on "domain" with "qosProfileName" from
// "qosLibraryName". Default QoS is used if "qosLibraryName" is an empty string.
// Invoke p.Free() when done with the participant.
func New(domain int, qosLibraryName, qosProfileName string) (Participant, error) {
p := Participant{}
if len(qosLibraryName) == 0 {
p.p = C.DDS_DomainParticipantFactory_create_participant(
C.DDS_DomainParticipantFactory_get_instance(),
C.DDS_DomainId_t(domain),
&C.DDS_PARTICIPANT_QOS_DEFAULT,
nil,
C.DDS_STATUS_MASK_NONE)
} else {
p.p = C.DDS_DomainParticipantFactory_create_participant_with_profile(
C.DDS_DomainParticipantFactory_get_instance(),
C.DDS_DomainId_t(domain),
C.CString(qosLibraryName),
C.CString(qosProfileName),
nil,
C.DDS_STATUS_MASK_NONE)
}
if p.p == nil {
return p, errors.New(fmt.Sprintf("Failed to create a participant on domain %d", domain))
}
return p, nil
}
// Free deletes the participant.
func (p Participant) Free() {
C.DDS_DomainParticipant_delete_contained_entities(p.p)
C.DDS_DomainParticipantFactory_delete_participant(C.DDS_DomainParticipantFactory_get_instance(), p.p)
p.p = nil
}
// Get returns a pointer to the C domain participant. Internal use only!
func (p Participant) Get() *C.DDS_DomainParticipant {
return p.p
}
// GetUnsafe returns a pointer to the participant as an unsafe pointer.
// C types cannot be used in other packages, so Get() won't work outside
// rtiddsgo, in particular in whatever package the generated type code
// reside. Internal use only!
func (p Participant) GetUnsafe() unsafe.Pointer {
return unsafe.Pointer(p.Get())
}