-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoption.go
More file actions
40 lines (28 loc) · 1.09 KB
/
option.go
File metadata and controls
40 lines (28 loc) · 1.09 KB
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
package binder
// Option configures a Transport.
type Option interface {
apply(*Config)
}
// Options is a slice of Option.
type Options []Option
// Config applies all options to the default configuration and returns the result.
func (opts Options) Config() Config {
cfg := DefaultConfig()
for _, o := range opts {
o.apply(&cfg)
}
return cfg
}
type maxThreadsOption struct{ n uint32 }
func (o maxThreadsOption) apply(c *Config) { c.MaxThreads = o.n }
// WithMaxThreads sets the maximum number of Binder threads.
func WithMaxThreads(n uint32) Option { return maxThreadsOption{n: n} }
type mapSizeOption struct{ n uint32 }
func (o mapSizeOption) apply(c *Config) { c.MapSize = o.n }
// WithMapSize sets the mmap size for the Binder driver.
func WithMapSize(n uint32) Option { return mapSizeOption{n: n} }
type devicePathOption struct{ path string }
func (o devicePathOption) apply(c *Config) { c.DevicePath = o.path }
// WithDevicePath sets the binder device path (e.g. "/dev/hwbinder").
// Defaults to "/dev/binder".
func WithDevicePath(path string) Option { return devicePathOption{path: path} }