2019-06-13 16:09:05 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
// #include "uplink_definitions.h"
|
|
|
|
import "C"
|
|
|
|
import (
|
2019-06-15 12:23:12 +01:00
|
|
|
libuplink "storj.io/storj/lib/uplink"
|
2019-06-13 16:09:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Project is a scoped uplink.Project
|
|
|
|
type Project struct {
|
|
|
|
scope
|
2019-06-15 12:23:12 +01:00
|
|
|
*libuplink.Project
|
2019-06-13 16:09:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//export open_project
|
|
|
|
// open_project opens project using uplink
|
2019-06-24 03:06:14 +01:00
|
|
|
func open_project(uplinkHandle C.UplinkRef, satelliteAddr *C.char, apikeyHandle C.APIKeyRef, cerr **C.char) C.ProjectRef {
|
2019-06-15 12:23:12 +01:00
|
|
|
uplink, ok := universe.Get(uplinkHandle._handle).(*Uplink)
|
2019-06-13 16:09:05 +01:00
|
|
|
if !ok {
|
|
|
|
*cerr = C.CString("invalid uplink")
|
2019-06-15 12:23:12 +01:00
|
|
|
return C.ProjectRef{}
|
2019-06-13 16:09:05 +01:00
|
|
|
}
|
|
|
|
|
2019-06-15 12:23:12 +01:00
|
|
|
apikey, ok := universe.Get(apikeyHandle._handle).(libuplink.APIKey)
|
2019-06-13 16:09:05 +01:00
|
|
|
if !ok {
|
|
|
|
*cerr = C.CString("invalid apikey")
|
2019-06-15 12:23:12 +01:00
|
|
|
return C.ProjectRef{}
|
2019-06-13 16:09:05 +01:00
|
|
|
}
|
|
|
|
|
2019-06-15 12:23:12 +01:00
|
|
|
scope := uplink.scope.child()
|
2019-06-13 16:09:05 +01:00
|
|
|
|
2019-06-24 03:06:14 +01:00
|
|
|
project, err := uplink.OpenProject(scope.ctx, C.GoString(satelliteAddr), apikey)
|
2019-06-13 16:09:05 +01:00
|
|
|
if err != nil {
|
|
|
|
*cerr = C.CString(err.Error())
|
2019-06-15 12:23:12 +01:00
|
|
|
return C.ProjectRef{}
|
2019-06-13 16:09:05 +01:00
|
|
|
}
|
|
|
|
|
2019-06-15 12:23:12 +01:00
|
|
|
return C.ProjectRef{universe.Add(&Project{scope, project})}
|
2019-06-13 16:09:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//export close_project
|
|
|
|
// close_project closes the project.
|
2019-06-15 12:23:12 +01:00
|
|
|
func close_project(projectHandle C.ProjectRef, cerr **C.char) {
|
2019-06-13 16:09:05 +01:00
|
|
|
project, ok := universe.Get(projectHandle._handle).(*Project)
|
|
|
|
if !ok {
|
2019-06-15 12:23:12 +01:00
|
|
|
*cerr = C.CString("invalid project")
|
2019-06-13 16:09:05 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
universe.Del(projectHandle._handle)
|
|
|
|
defer project.cancel()
|
|
|
|
|
|
|
|
if err := project.Close(); err != nil {
|
|
|
|
*cerr = C.CString(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|