MCPcopy Create free account
hub / github.com/golang/mobile / init

Function init

exp/sensor/android.go:74–102  ·  view source on GitHub ↗

init inits the manager and creates a goroutine to proxy the CGO calls. All actions related to an ALooper needs to be performed from the same OS thread. The goroutine proxy locks itself to an OS thread and handles the CGO traffic on the same thread.

()

Source from the content-addressed store, hash-verified

72// OS thread. The goroutine proxy locks itself to an OS thread and handles the
73// CGO traffic on the same thread.
74func init() {
75 go func() {
76 runtime.LockOSThread()
77 C.GoAndroid_createManager()
78
79 for {
80 v := <-inout
81 switch s := v.in.(type) {
82
83 case enableSignal:
84 usecsDelay := s.delay.Nanoseconds() / 1000
85 code := int(C.GoAndroid_enableSensor(typeToInt(s.t), C.int32_t(usecsDelay)))
86 if code != 0 {
87 *s.err = fmt.Errorf("sensor: no default %v sensor on the device", s.t)
88 }
89 case disableSignal:
90 C.GoAndroid_disableSensor(typeToInt(s.t))
91 case readSignal:
92 n := readEvents(s.dst)
93 *s.n = n
94 case closeSignal:
95 C.GoAndroid_destroyManager()
96 close(v.out)
97 return // we don't need this goroutine anymore
98 }
99 close(v.out)
100 }
101 }()
102}
103
104// enable enables the sensor t on sender. A non-nil sender is
105// required before calling enable.

Callers

nothing calls this directly

Calls 2

typeToIntFunction · 0.85
readEventsFunction · 0.85

Tested by

no test coverage detected