forked from sternix/wl
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcommon.go
55 lines (42 loc) · 739 Bytes
/
common.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
package wl
import (
"context"
)
type ProxyId uint32
type Dispatcher interface {
Dispatch(context.Context, *Event)
}
type Proxy interface {
Context() *Context
SetContext(c *Context)
Id() ProxyId
SetId(id ProxyId)
}
type BaseProxy struct {
id ProxyId
ctx *Context
}
func (p *BaseProxy) Id() ProxyId {
return p.id
}
func (p *BaseProxy) SetId(id ProxyId) {
p.id = id
}
func (p *BaseProxy) Context() *Context {
return p.ctx
}
func (p *BaseProxy) SetContext(c *Context) {
p.ctx = c
}
type Handler interface {
Handle(ev interface{})
}
type eventHandler struct {
f func(interface{})
}
func HandlerFunc(f func(interface{})) Handler {
return &eventHandler{f}
}
func (h *eventHandler) Handle(ev interface{}) {
h.f(ev)
}