forked from remogatto/mandala
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresourcemanager.go
More file actions
60 lines (51 loc) · 1.43 KB
/
resourcemanager.go
File metadata and controls
60 lines (51 loc) · 1.43 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package mandala
import (
"unsafe"
"github.com/tideland/goas/v2/loop"
)
var (
// The path in which the framework will search for resources.
ResourcePath string = "android/res"
)
type LoadResourceResponse struct {
// The buffer containing the resource.
Buffer []byte
// The error eventually generated by the reading operation.
Error error
}
// The type of request to send to ResourceManager in order to read the
// resource.
type LoadResourceRequest struct {
// The path of the resource file, for example
// "res/drawable/gopher.png". ResourcePath will be prefixed to
// Filename.
Filename string
// Response is a channel for receiving the response from the
// resource manager.
Response chan LoadResourceResponse
}
func resourceLoopFunc(activity chan unsafe.Pointer, request chan interface{}) loop.LoopFunc {
var act unsafe.Pointer
return func(l loop.Loop) error {
for {
select {
case act = <-activity:
case untypedRequest := <-request:
switch req := untypedRequest.(type) {
case LoadResourceRequest:
buf, err := loadResource(act, req.Filename)
req.Response <- LoadResourceResponse{buf, err}
}
}
}
}
}
// ReadResource reads a resource named filename and send the response
// to the given responseCh channel.
func ReadResource(filename string, responseCh chan LoadResourceResponse) {
request := LoadResourceRequest{
Filename: filename,
Response: responseCh,
}
ResourceManager() <- request
}