-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnotelib.go
93 lines (83 loc) · 3.1 KB
/
notelib.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2017 Blues Inc. All rights reserved.
// Use of this source code is governed by licenses granted by the
// copyright holder including that found in the LICENSE file.
// Package notelib notelib.go has certain internal definitions, placed here so that
// they parallel the clang version.
package notelib
import (
"net/http"
"sync"
"time"
"github.com/blues/note-go/note"
)
// noteboxBody is the is the Body field within each note
// within the notebox. Each note's unique ID is constructed
// as a structured name of the form <endpointID>|<notefileID>.
// EndpointID is a unique string assigned to each endpoint.
// NotefileID is a unique string assigned to each notefile.
// All NoteID's without the | separator are reserved for
// future use, and at that time we will augment the Body
// data structure to accomodate the new type of data.
const TemplateFlagClearAfterSync = 0x00000001
type notefileDesc struct {
// Optional metadata about the notefile
Info *note.NotefileInfo `json:"i,omitempty"`
// Storage method and physical location
Storage string `json:"s,omitempty"`
// Template info
BodyTemplate string `json:"B,omitempty"`
PayloadTemplate uint32 `json:"P,omitempty"`
TemplateFormat uint32 `json:"f,omitempty"`
TemplatePort uint16 `json:"X,omitempty"`
TemplateFlags uint32 `json:"d,omitempty"`
}
type noteboxBody struct {
// Used when Note ID is of the form "endpointID|notefileID"
Notefile notefileDesc `json:"n,omitempty"`
}
// OpenNotefile is the in-memory data structure for an open notefile
type OpenNotefile struct {
// Locks access to just this data structure
lock sync.RWMutex
// This notefile's containing box
box *Notebox
// Number of current users of the notefile who are
// counting on the notefile address to be stable
openCount int32
// The time of last close where refcnt wne to 0
closeTime time.Time
// Modification count at point of last checkpoint
modCountAfterCheckpoint int
// The address of the open notefile
notefile *Notefile
// This notefile's storage object
storage string
// Whether or not this notefile has been deleted
deleted bool
}
// NoteboxInstance is the in-memory data structure for an open notebox
type NoteboxInstance struct {
// Map of POINTERS to OpenNotefiles, indexed by storage object.
// These must be pointers so that we can look it up and bump refcnt
// atomically without a lock.
openfiles sync.Map
// This notebox's storage object
storage string
// The endpoint ID that is to be used for all operations on the notebox
endpointID string
}
// Notebox is the in-memory data structure for an open notebox
type Notebox struct {
// Map of the Notefiles, indexed by storage object
instance *NoteboxInstance
// Default parameters to be passed to notefiles being opened in notebox
defaultEventFn EventFunc // The function to call when notifying of a change
defaultEventSession *HubSession // And a parameter TODO rename
defaultEventDeviceUID string
defaultEventDeviceSN string
defaultEventProductUID string
defaultEventAppUID string
// For HTTP access control
clientHTTPReq *http.Request
clientHTTPRsp http.ResponseWriter
}