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.
()
| 72 | // OS thread. The goroutine proxy locks itself to an OS thread and handles the |
| 73 | // CGO traffic on the same thread. |
| 74 | func 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. |
nothing calls this directly
no test coverage detected