-
Notifications
You must be signed in to change notification settings - Fork 14
/
file.go
74 lines (59 loc) · 1.72 KB
/
file.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 gopi
import "strings"
/*
This file contains interface defininitons for filesystem
interface:
* Polling files for read and write conitions
* Polling filesystems for changes (TODO)
*/
/////////////////////////////////////////////////////////////////////
// TYPES
type (
// Read and Write flags
FilePollFlags uint
// FilePollFunc is the handler for file polling
FilePollFunc func(uintptr, FilePollFlags)
)
/////////////////////////////////////////////////////////////////////
// INTERFACES
type FilePoll interface {
// Watch a file descriptor for changes
Watch(uintptr, FilePollFlags, FilePollFunc) error
// Unwatch a file descriptor
Unwatch(uintptr) error
}
////////////////////////////////////////////////////////////////////////////////
// CONSTANTS
const (
FILEPOLL_FLAG_READ FilePollFlags = (1 << iota) // File descriptor ready for reading
FILEPOLL_FLAG_WRITE // File descriptor ready for writing
FILEPOLL_FLAG_NONE FilePollFlags = 0
FILEPOLL_FLAG_MIN FilePollFlags = FILEPOLL_FLAG_READ
FILEPOLL_FLAG_MAX FilePollFlags = FILEPOLL_FLAG_WRITE
)
////////////////////////////////////////////////////////////////////////////////
// STRINGIFY
func (f FilePollFlags) String() string {
str := ""
if f == FILEPOLL_FLAG_NONE {
return f.StringFlag()
}
for v := FILEPOLL_FLAG_MIN; v <= FILEPOLL_FLAG_MAX; v <<= 1 {
if f&v == v {
str += v.StringFlag() + "|"
}
}
return strings.TrimSuffix(str, "|")
}
func (f FilePollFlags) StringFlag() string {
switch f {
case FILEPOLL_FLAG_NONE:
return "FILEPOLL_FLAG_NONE"
case FILEPOLL_FLAG_READ:
return "FILEPOLL_FLAG_READ"
case FILEPOLL_FLAG_WRITE:
return "FILEPOLL_FLAG_WRITE"
default:
return "[?? Invalid FilePollFlags value]"
}
}