Skip to content

Commit dc501a2

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
feat: add persistablebundle overlay and generate idiomatic Go bindings
1 parent a87d310 commit dc501a2

13 files changed

Lines changed: 369 additions & 0 deletions

File tree

persistablebundle/a_parcel.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

persistablebundle/binder_status_t.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

persistablebundle/errors.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

persistablebundle/functions.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

persistablebundle/p_e_r_s_i_s_t_a_b_l_e_b_u_n_d_l_e.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

persistablebundle/package.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

persistablebundle/persistable_bundle.go

Lines changed: 164 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
module: persistablebundle
2+
3+
package:
4+
go_name: persistablebundle
5+
go_import: github.com/xaionaro-go/ndk/persistablebundle
6+
doc: "Package persistablebundle provides Go bindings for Android PersistableBundle."
7+
8+
types:
9+
APersistableBundle:
10+
go_name: PersistableBundle
11+
destructor: APersistableBundle_delete
12+
13+
functions:
14+
APersistableBundle_writeToParcel:
15+
receiver: PersistableBundle
16+
go_name: WriteToParcel
17+
18+
APersistableBundle_readFromParcel:
19+
go_name: ReadFromParcel
20+
output_params:
21+
outPBundle: "*PersistableBundle"
22+
23+
APersistableBundle_size:
24+
receiver: PersistableBundle
25+
go_name: Size
26+
pure: true
27+
28+
APersistableBundle_erase:
29+
receiver: PersistableBundle
30+
go_name: Erase
31+
pure: true
32+
33+
APersistableBundle_getPersistableBundle:
34+
receiver: PersistableBundle
35+
go_name: GetPersistableBundle
36+
output_params:
37+
outBundle: "*PersistableBundle"
38+
39+
# Skip: takes const char* const* which is complex to wrap idiomatically
40+
APersistableBundle_putStringVector:
41+
skip: true
42+
43+
# Skip: functions that require APersistableBundle_stringAllocator callback
44+
APersistableBundle_getString:
45+
skip: true
46+
APersistableBundle_getStringVector:
47+
skip: true
48+
APersistableBundle_getBooleanKeys:
49+
skip: true
50+
APersistableBundle_getIntKeys:
51+
skip: true
52+
APersistableBundle_getLongKeys:
53+
skip: true
54+
APersistableBundle_getDoubleKeys:
55+
skip: true
56+
APersistableBundle_getStringKeys:
57+
skip: true
58+
APersistableBundle_getBooleanVectorKeys:
59+
skip: true
60+
APersistableBundle_getIntVectorKeys:
61+
skip: true
62+
APersistableBundle_getLongVectorKeys:
63+
skip: true
64+
APersistableBundle_getDoubleVectorKeys:
65+
skip: true
66+
APersistableBundle_getStringVectorKeys:
67+
skip: true
68+
APersistableBundle_getPersistableBundleKeys:
69+
skip: true

templates/functions.go.tmpl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ import (
1010
)
1111
{{ range $f := .FreeFunctions }}
1212
{{- if $f.OutputParams }}
13+
{{- if $f.ReturnsBool }}
14+
// {{ $f.GoName }} calls the underlying C function.
15+
func {{ $f.GoName }}({{ range $i, $p := filterOutputParams $f.Params $f.OutputParams }}{{ if $i }}, {{ end }}{{ $p.Name }} {{ $p.GoType }}{{ end }}) ({{ range $i, $op := $f.OutputParams }}{{ if $i }}, {{ end }}{{ $op.GoType }}{{ end }}, bool) {
16+
{{ range $p := stringParams (filterOutputParams $f.Params $f.OutputParams) }} {{ $p.Name }}Bytes := append([]byte({{ $p.Name }}), 0)
17+
{{ end }}{{ range $op := $f.OutputParams }} var {{ $op.CParamName }}Ptr {{ $op.CapiType }}
18+
{{ end }} ok := capi.{{ $f.CName }}({{ range $i, $p := filterOutputParams $f.Params $f.OutputParams }}{{ if $i }}, {{ end }}{{ capiArg $p }}{{ end }}{{ if filterOutputParams $f.Params $f.OutputParams }}{{ range $op := $f.OutputParams }}, &{{ $op.CParamName }}Ptr{{ end }}{{ else }}{{ range $i, $op := $f.OutputParams }}{{ if $i }}, {{ end }}&{{ $op.CParamName }}Ptr{{ end }}{{ end }})
19+
if !ok {
20+
return {{ range $op := $f.OutputParams }}{{ zeroValue $op }}, {{ end }}false
21+
}
22+
return {{ range $op := $f.OutputParams }}{{ if $op.IsHandle }}&{{ trimStarPrefix $op.GoType }}{ptr: {{ $op.CParamName }}Ptr}{{ else }}{{ $op.CParamName }}Ptr{{ end }}, {{ end }}true
23+
}
24+
{{- else }}
1325
// {{ $f.GoName }} calls the underlying C function.
1426
func {{ $f.GoName }}({{ range $i, $p := filterOutputParams $f.Params $f.OutputParams }}{{ if $i }}, {{ end }}{{ $p.Name }} {{ $p.GoType }}{{ end }}) ({{ range $i, $op := $f.OutputParams }}{{ if $i }}, {{ end }}{{ $op.GoType }}{{ end }}, error) {
1527
{{ range $p := stringParams (filterOutputParams $f.Params $f.OutputParams) }} {{ $p.Name }}Bytes := append([]byte({{ $p.Name }}), 0)
@@ -20,6 +32,7 @@ func {{ $f.GoName }}({{ range $i, $p := filterOutputParams $f.Params $f.OutputPa
2032
}
2133
return {{ range $op := $f.OutputParams }}{{ if $op.IsHandle }}&{{ trimStarPrefix $op.GoType }}{ptr: {{ $op.CParamName }}Ptr}{{ else }}{{ $op.CParamName }}Ptr{{ end }}, {{ end }}nil
2234
}
35+
{{- end }}
2336
{{- else }}
2437
// {{ $f.GoName }} calls the underlying C function.
2538
func {{ $f.GoName }}({{ range $i, $p := $f.Params }}{{ if $i }}, {{ end }}{{ $p.Name }} {{ $p.GoType }}{{ end }}){{ if $f.Returns }} {{ $f.Returns }}{{ end }} {

templates/type_file.go.tmpl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ func (h *{{ $m.ReceiverType }}) {{ $m.GoName }}({{ range $i, $p := $m.CustomCall
6767
return result(int32(capi.{{ $m.CName }}(h.ptr, {{ $m.CustomCall.Args }})))
6868
}
6969
{{- else if $m.OutputParams }}
70+
{{- if $m.ReturnsBool }}
71+
// {{ $m.GoName }} calls the underlying NDK function.
72+
func (h *{{ $m.ReceiverType }}) {{ $m.GoName }}({{ range $i, $p := filterOutputParams (skipAndFilterOut $m.Params) $m.OutputParams }}{{ if $i }}, {{ end }}{{ $p.Name }} {{ $p.GoType }}{{ end }}) ({{ range $i, $op := $m.OutputParams }}{{ if $i }}, {{ end }}{{ $op.GoType }}{{ end }}, bool) {
73+
{{ range $op := $m.OutputParams }} var {{ $op.CParamName }}Ptr {{ $op.CapiType }}
74+
{{ end }} ok := capi.{{ $m.CName }}(h.ptr{{ range skipAndFilterOut $m.Params }}, {{ capiArg . }}{{ end }}{{ range $op := $m.OutputParams }}, &{{ $op.CParamName }}Ptr{{ end }})
75+
if !ok {
76+
return {{ range $op := $m.OutputParams }}{{ zeroValue $op }}, {{ end }}false
77+
}
78+
return {{ range $op := $m.OutputParams }}{{ if $op.IsHandle }}&{{ trimStarPrefix $op.GoType }}{ptr: {{ $op.CParamName }}Ptr}{{ else }}{{ $op.CParamName }}Ptr{{ end }}, {{ end }}true
79+
}
80+
{{- else }}
7081
// {{ $m.GoName }} calls the underlying NDK function.
7182
func (h *{{ $m.ReceiverType }}) {{ $m.GoName }}({{ range $i, $p := filterOutputParams (skipAndFilterOut $m.Params) $m.OutputParams }}{{ if $i }}, {{ end }}{{ $p.Name }} {{ $p.GoType }}{{ end }}) ({{ range $i, $op := $m.OutputParams }}{{ if $i }}, {{ end }}{{ $op.GoType }}{{ end }}, error) {
7283
{{ range $op := $m.OutputParams }} var {{ $op.CParamName }}Ptr {{ $op.CapiType }}
@@ -76,6 +87,7 @@ func (h *{{ $m.ReceiverType }}) {{ $m.GoName }}({{ range $i, $p := filterOutputP
7687
}
7788
return {{ range $op := $m.OutputParams }}{{ if $op.IsHandle }}&{{ trimStarPrefix $op.GoType }}{ptr: {{ $op.CParamName }}Ptr}{{ else }}{{ $op.CParamName }}Ptr{{ end }}, {{ end }}nil
7889
}
90+
{{- end }}
7991
{{- else if and $m.CallbackParam $m.ReturnsNew }}
8092
// {{ $m.GoName }} creates a new {{ $m.ReturnsNew }} from this {{ $m.ReceiverType }}.
8193
func (h *{{ $m.ReceiverType }}) {{ $m.GoName }}({{ range $i, $p := callbackVisibleParams $m.Params $m.CallbackParam }}{{ if $i }}, {{ end }}{{ $p.Name }} {{ $p.GoType }}{{ end }}{{ if callbackVisibleParams $m.Params $m.CallbackParam }}, {{ end }}cbs {{ $m.CallbackGoType }}) (*{{ $m.ReturnsNew }}, error) {
@@ -181,6 +193,18 @@ func (h *{{ $m.ReceiverType }}) {{ $m.GoName }}({{ range $i, $p := skipAndFilter
181193
{{- end }}
182194
{{ range $f := .FreeFunctions }}
183195
{{- if $f.OutputParams }}
196+
{{- if $f.ReturnsBool }}
197+
// {{ $f.GoName }} calls the underlying C function.
198+
func {{ $f.GoName }}({{ range $i, $p := filterOutputParams $f.Params $f.OutputParams }}{{ if $i }}, {{ end }}{{ $p.Name }} {{ $p.GoType }}{{ end }}) ({{ range $i, $op := $f.OutputParams }}{{ if $i }}, {{ end }}{{ $op.GoType }}{{ end }}, bool) {
199+
{{ range $p := stringParams (filterOutputParams $f.Params $f.OutputParams) }} {{ $p.Name }}Bytes := append([]byte({{ $p.Name }}), 0)
200+
{{ end }}{{ range $op := $f.OutputParams }} var {{ $op.CParamName }}Ptr {{ $op.CapiType }}
201+
{{ end }} ok := capi.{{ $f.CName }}({{ range $i, $p := filterOutputParams $f.Params $f.OutputParams }}{{ if $i }}, {{ end }}{{ capiArg $p }}{{ end }}{{ if filterOutputParams $f.Params $f.OutputParams }}{{ range $op := $f.OutputParams }}, &{{ $op.CParamName }}Ptr{{ end }}{{ else }}{{ range $i, $op := $f.OutputParams }}{{ if $i }}, {{ end }}&{{ $op.CParamName }}Ptr{{ end }}{{ end }})
202+
if !ok {
203+
return {{ range $op := $f.OutputParams }}{{ zeroValue $op }}, {{ end }}false
204+
}
205+
return {{ range $op := $f.OutputParams }}{{ if $op.IsHandle }}&{{ trimStarPrefix $op.GoType }}{ptr: {{ $op.CParamName }}Ptr}{{ else }}{{ $op.CParamName }}Ptr{{ end }}, {{ end }}true
206+
}
207+
{{- else }}
184208
// {{ $f.GoName }} calls the underlying C function.
185209
func {{ $f.GoName }}({{ range $i, $p := filterOutputParams $f.Params $f.OutputParams }}{{ if $i }}, {{ end }}{{ $p.Name }} {{ $p.GoType }}{{ end }}) ({{ range $i, $op := $f.OutputParams }}{{ if $i }}, {{ end }}{{ $op.GoType }}{{ end }}, error) {
186210
{{ range $p := stringParams (filterOutputParams $f.Params $f.OutputParams) }} {{ $p.Name }}Bytes := append([]byte({{ $p.Name }}), 0)
@@ -191,6 +215,7 @@ func {{ $f.GoName }}({{ range $i, $p := filterOutputParams $f.Params $f.OutputPa
191215
}
192216
return {{ range $op := $f.OutputParams }}{{ if $op.IsHandle }}&{{ trimStarPrefix $op.GoType }}{ptr: {{ $op.CParamName }}Ptr}{{ else }}{{ $op.CParamName }}Ptr{{ end }}, {{ end }}nil
193217
}
218+
{{- end }}
194219
{{- else }}
195220
// {{ $f.GoName }} calls the underlying C function.
196221
func {{ $f.GoName }}({{ range $i, $p := $f.Params }}{{ if $i }}, {{ end }}{{ $p.Name }} {{ $p.GoType }}{{ end }}){{ if $f.Returns }} {{ $f.Returns }}{{ end }} {

0 commit comments

Comments
 (0)