-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_context.go
147 lines (133 loc) · 3.26 KB
/
api_context.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import "C"
import (
"context"
"fmt"
"runtime"
config "github.com/ipfs/go-ipfs-config"
files "github.com/ipfs/go-ipfs-files"
icore "github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/go-ipfs/repo"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/plugin/loader" // This package is needed so that all the preloaded plugins are loaded automatically
)
type ErrorsHolder struct {
objects map[int64]error
next_handle int64
}
type StringsHolder struct {
objects map[int64]string
next_handle int64
}
type PluginLoadersHolder struct {
objects map[int64]*loader.PluginLoader
next_handle int64
}
type UnixfsAddOptionsHolder struct {
objects map[int64]*UnixfsAddOptionArray
next_handle int64
}
type ConfigsHolder struct {
objects map[int64]*config.Config
next_handle int64
}
type ReposHolder struct {
objects map[int64]repo.Repo
next_handle int64
}
type BuildCfgsHolder struct {
objects map[int64]*core.BuildCfg
next_handle int64
}
type CoreAPIsHolder struct {
objects map[int64]icore.CoreAPI
next_handle int64
}
type NodesHolder struct {
objects map[int64]files.Node
next_handle int64
}
/*
* Stuff all the values that need to be maintained between api calls here
*/
type libipfsAPIContext struct {
ctx context.Context
ctx_cancel context.CancelFunc
errors ErrorsHolder
strings StringsHolder
plugin_loaders PluginLoadersHolder
configs ConfigsHolder
repos ReposHolder
build_cfgs BuildCfgsHolder
core_apis CoreAPIsHolder
nodes NodesHolder
unixfs_add_options UnixfsAddOptionsHolder
}
var api_context libipfsAPIContext
/*
Initialize the IPFS library. This must be called before calling any other
ipfs_* functions.
*/
//export ipfs_Init
func ipfs_Init() {
// Setup basic enviroment to allow the API to function
ctx, cancel := context.WithCancel( context.Background() )
api_context.ctx = ctx
api_context.ctx_cancel = cancel
api_context.errors = ErrorsHolder {
objects: make(map[int64]error),
next_handle: -1,
}
api_context.strings = StringsHolder {
objects: make(map[int64]string),
next_handle: 1,
}
api_context.plugin_loaders = PluginLoadersHolder {
objects: make(map[int64]*loader.PluginLoader),
next_handle: 1,
}
api_context.configs = ConfigsHolder {
objects: make(map[int64]*config.Config),
next_handle: 1,
}
api_context.repos = ReposHolder {
objects: make(map[int64]repo.Repo),
next_handle: 1,
}
api_context.build_cfgs = BuildCfgsHolder {
objects: make(map[int64]*core.BuildCfg),
next_handle: 1,
}
api_context.core_apis = CoreAPIsHolder {
objects: make(map[int64]icore.CoreAPI),
next_handle: 1,
}
api_context.nodes = NodesHolder {
objects: make(map[int64]files.Node),
next_handle: 1,
}
api_context.unixfs_add_options = UnixfsAddOptionsHolder {
objects: make(map[int64]*UnixfsAddOptionArray),
next_handle: 1,
}
}
/*
Cleanup/teardown the IPFS library. Calling any ipfs_* functions after
calling this function is undefined.
*/
//export ipfs_Cleanup
func ipfs_Cleanup() {
// Tear down everything
api_context.ctx_cancel()
fmt.Println("ipfs closed")
}
/*
Run Goroutines. This needs to be called periodically for the library
to function.
*/
//export ipfs_RunGoroutines
func ipfs_RunGoroutines() int64 {
runtime.Gosched()
return 1
}
func main() {}