@@ -10,18 +10,18 @@ import (
10
10
"github.com/pkg/errors"
11
11
"github.com/rs/zerolog/log"
12
12
"github.com/threefoldtech/zbus"
13
- "github.com/threefoldtech/zos4/pkg/app"
14
- "github.com/threefoldtech/zos4/pkg/environment"
15
- "github.com/threefoldtech/zos4/pkg/stubs"
13
+ "github.com/threefoldtech/zos/pkg"
14
+ "github.com/threefoldtech/zos/pkg/app"
15
+ "github.com/threefoldtech/zos/pkg/environment"
16
+ "github.com/threefoldtech/zos/pkg/stubs"
16
17
)
17
18
18
19
// should any of this be moved to pkg?
19
- type RegistrationState string
20
20
21
21
const (
22
- Failed RegistrationState = "Failed"
23
- InProgress RegistrationState = "InProgress"
24
- Done RegistrationState = "Done"
22
+ Failed pkg. RegistrationState = "Failed"
23
+ InProgress pkg. RegistrationState = "InProgress"
24
+ Done pkg. RegistrationState = "Done"
25
25
26
26
monitorAccountEvery = 30 * time .Minute
27
27
updateNodeInfoInterval = 24 * time .Hour
@@ -32,33 +32,26 @@ var (
32
32
ErrFailed = errors .New ("registration failed" )
33
33
)
34
34
35
- type State struct {
36
- NodeID uint32
37
- TwinID uint32
38
- State RegistrationState
39
- Msg string
40
- }
41
-
42
- func FailedState (err error ) State {
43
- return State {
35
+ func FailedState (err error ) pkg.State {
36
+ return pkg.State {
44
37
0 ,
45
38
0 ,
46
39
Failed ,
47
40
err .Error (),
48
41
}
49
42
}
50
43
51
- func InProgressState () State {
52
- return State {
44
+ func InProgressState () pkg. State {
45
+ return pkg. State {
53
46
0 ,
54
47
0 ,
55
48
InProgress ,
56
49
"" ,
57
50
}
58
51
}
59
52
60
- func DoneState (nodeID uint32 , twinID uint32 ) State {
61
- return State {
53
+ func DoneState (nodeID uint32 , twinID uint32 ) pkg. State {
54
+ return pkg. State {
62
55
nodeID ,
63
56
twinID ,
64
57
Done ,
@@ -67,13 +60,13 @@ func DoneState(nodeID uint32, twinID uint32) State {
67
60
}
68
61
69
62
type Registrar struct {
70
- state State
63
+ state pkg. State
71
64
mutex sync.RWMutex
72
65
}
73
66
74
67
func NewRegistrar (ctx context.Context , cl zbus.Client , env environment.Environment , info RegistrationInfo ) * Registrar {
75
68
r := Registrar {
76
- State {
69
+ pkg. State {
77
70
0 ,
78
71
0 ,
79
72
InProgress ,
@@ -86,13 +79,13 @@ func NewRegistrar(ctx context.Context, cl zbus.Client, env environment.Environme
86
79
return & r
87
80
}
88
81
89
- func (r * Registrar ) setState (s State ) {
82
+ func (r * Registrar ) setState (s pkg. State ) {
90
83
r .mutex .Lock ()
91
84
defer r .mutex .Unlock ()
92
85
r .state = s
93
86
}
94
87
95
- func (r * Registrar ) getState () State {
88
+ func (r * Registrar ) GetState () pkg. State {
96
89
r .mutex .RLock ()
97
90
defer r .mutex .RUnlock ()
98
91
return r .state
@@ -167,11 +160,11 @@ func (r *Registrar) reActivate(ctx context.Context, cl zbus.Client, env environm
167
160
}
168
161
169
162
func (r * Registrar ) NodeID () (uint32 , error ) {
170
- return r .returnIfDone (r .getState ().NodeID )
163
+ return r .returnIfDone (r .GetState ().NodeID )
171
164
}
172
165
173
166
func (r * Registrar ) TwinID () (uint32 , error ) {
174
- return r .returnIfDone (r .getState ().TwinID )
167
+ return r .returnIfDone (r .GetState ().TwinID )
175
168
}
176
169
177
170
func (r * Registrar ) returnIfDone (v uint32 ) (uint32 , error ) {
0 commit comments