forked from keybase/client
/
appstate.go
145 lines (124 loc) · 3.73 KB
/
appstate.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Auto-generated to Go types and interfaces using avdl-compiler v1.4.9 (https://github.com/keybase/node-avdl-compiler)
// Input file: avdl/keybase1/appstate.avdl
package keybase1
import (
"fmt"
"github.com/keybase/go-framed-msgpack-rpc/rpc"
context "golang.org/x/net/context"
"time"
)
type MobileAppState int
const (
MobileAppState_FOREGROUND MobileAppState = 0
MobileAppState_BACKGROUND MobileAppState = 1
MobileAppState_INACTIVE MobileAppState = 2
MobileAppState_BACKGROUNDACTIVE MobileAppState = 3
)
func (o MobileAppState) DeepCopy() MobileAppState { return o }
var MobileAppStateMap = map[string]MobileAppState{
"FOREGROUND": 0,
"BACKGROUND": 1,
"INACTIVE": 2,
"BACKGROUNDACTIVE": 3,
}
var MobileAppStateRevMap = map[MobileAppState]string{
0: "FOREGROUND",
1: "BACKGROUND",
2: "INACTIVE",
3: "BACKGROUNDACTIVE",
}
func (e MobileAppState) String() string {
if v, ok := MobileAppStateRevMap[e]; ok {
return v
}
return fmt.Sprintf("%v", int(e))
}
type MobileNetworkState int
const (
MobileNetworkState_NONE MobileNetworkState = 0
MobileNetworkState_WIFI MobileNetworkState = 1
MobileNetworkState_CELLULAR MobileNetworkState = 2
MobileNetworkState_UNKNOWN MobileNetworkState = 3
MobileNetworkState_NOTAVAILABLE MobileNetworkState = 4
)
func (o MobileNetworkState) DeepCopy() MobileNetworkState { return o }
var MobileNetworkStateMap = map[string]MobileNetworkState{
"NONE": 0,
"WIFI": 1,
"CELLULAR": 2,
"UNKNOWN": 3,
"NOTAVAILABLE": 4,
}
var MobileNetworkStateRevMap = map[MobileNetworkState]string{
0: "NONE",
1: "WIFI",
2: "CELLULAR",
3: "UNKNOWN",
4: "NOTAVAILABLE",
}
func (e MobileNetworkState) String() string {
if v, ok := MobileNetworkStateRevMap[e]; ok {
return v
}
return fmt.Sprintf("%v", int(e))
}
type UpdateMobileNetStateArg struct {
State string `codec:"state" json:"state"`
}
type PowerMonitorEventArg struct {
Event string `codec:"event" json:"event"`
}
type AppStateInterface interface {
UpdateMobileNetState(context.Context, string) error
PowerMonitorEvent(context.Context, string) error
}
func AppStateProtocol(i AppStateInterface) rpc.Protocol {
return rpc.Protocol{
Name: "keybase.1.appState",
Methods: map[string]rpc.ServeHandlerDescription{
"updateMobileNetState": {
MakeArg: func() interface{} {
var ret [1]UpdateMobileNetStateArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]UpdateMobileNetStateArg)
if !ok {
err = rpc.NewTypeError((*[1]UpdateMobileNetStateArg)(nil), args)
return
}
err = i.UpdateMobileNetState(ctx, typedArgs[0].State)
return
},
},
"powerMonitorEvent": {
MakeArg: func() interface{} {
var ret [1]PowerMonitorEventArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]PowerMonitorEventArg)
if !ok {
err = rpc.NewTypeError((*[1]PowerMonitorEventArg)(nil), args)
return
}
err = i.PowerMonitorEvent(ctx, typedArgs[0].Event)
return
},
},
},
}
}
type AppStateClient struct {
Cli rpc.GenericClient
}
func (c AppStateClient) UpdateMobileNetState(ctx context.Context, state string) (err error) {
__arg := UpdateMobileNetStateArg{State: state}
err = c.Cli.Call(ctx, "keybase.1.appState.updateMobileNetState", []interface{}{__arg}, nil, 0*time.Millisecond)
return
}
func (c AppStateClient) PowerMonitorEvent(ctx context.Context, event string) (err error) {
__arg := PowerMonitorEventArg{Event: event}
err = c.Cli.Call(ctx, "keybase.1.appState.powerMonitorEvent", []interface{}{__arg}, nil, 0*time.Millisecond)
return
}