-
Notifications
You must be signed in to change notification settings - Fork 8
/
Buffer.go
74 lines (56 loc) · 1.14 KB
/
Buffer.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
package gowl
import (
"bytes"
)
var _ bytes.Buffer
type Buffer struct {
id int32
releaseListeners []chan BufferRelease
events []func(b *Buffer, msg message) error
name string
}
func NewBuffer() (b *Buffer) {
b = new(Buffer)
b.name = "Buffer"
b.releaseListeners = make([]chan BufferRelease, 0)
b.events = append(b.events, bufferRelease)
return
}
func (b *Buffer) HandleEvent(msg message) {
if b.events[msg.opcode] != nil {
b.events[msg.opcode](b, msg)
}
}
func (b *Buffer) SetId(id int32) {
b.id = id
}
func (b *Buffer) Id() int32 {
return b.id
}
func (b *Buffer) Name() string {
return b.name
}
////
//// REQUESTS
////
func (b *Buffer) Destroy() {
sendrequest(b, "wl_buffer_destroy", )
}
////
//// EVENTS
////
type BufferRelease struct {
}
func (b *Buffer) AddReleaseListener(channel chan BufferRelease) {
b.releaseListeners = append(b.releaseListeners, channel)
}
func bufferRelease(b *Buffer, msg message) (err error) {
var data BufferRelease
// Dispatch events
for _,channel := range b.releaseListeners {
go func () {
channel <- data
} ()
}
return
}