added shared starter tests and added to Makefile to add compile .h and .so files

This commit is contained in:
2023-10-05 17:07:21 +01:00
parent a07c91c888
commit ea90348fd2
4 changed files with 41 additions and 27 deletions

2
.gitignore vendored
View File

@@ -26,3 +26,5 @@ logs/
# ignore docker image files
server/docker/containers/
*.h
*.so

View File

@@ -1,9 +1,10 @@
package Bindings
package main
import "C"
import (
"encoding/json"
"github.com/Akilan1999/p2p-rendering-computation/client"
"encoding/json"
"github.com/Akilan1999/p2p-rendering-computation/abstractions"
"github.com/Akilan1999/p2p-rendering-computation/client"
)
// The Client package where data-types
@@ -13,32 +14,40 @@ import (
//export StartContainer
func StartContainer(IP string, NumPorts int, GPU bool, ContainerName string, baseImage string) (output string) {
container, err := client.StartContainer(IP, NumPorts, GPU, ContainerName, baseImage)
if err != nil {
return err.Error()
}
jsonBytes, err := json.Marshal(container)
if err != nil {
return err.Error()
}
// Convert the JSON bytes to a string
return string(jsonBytes)
container, err := client.StartContainer(IP, NumPorts, GPU, ContainerName, baseImage)
if err != nil {
return err.Error()
}
return ConvertStructToJSONString(container)
}
//export GetSpecs
func GetSpecs(IP string) (output string) {
specs, err := client.GetSpecs(IP)
if err != nil {
return err.Error()
}
jsonBytes, err := json.Marshal(specs)
if err != nil {
return err.Error()
}
// Convert the JSON bytes to a string
return string(jsonBytes)
specs, err := client.GetSpecs(IP)
if err != nil {
return err.Error()
}
return ConvertStructToJSONString(specs)
}
//export Init
func Init(customConfig string) (output string) {
init, err := abstractions.Init(customConfig)
if err != nil {
return err.Error()
}
return ConvertStructToJSONString(init)
}
func ConvertStructToJSONString(Struct interface{}) string {
jsonBytes, err := json.Marshal(Struct)
if err != nil {
return err.Error()
}
// Convert the JSON bytes to a string
return string(jsonBytes)
}
func main() {}

View File

@@ -9,3 +9,5 @@ testcases:
run:
go run main.go
sharedObjects:
sh build-bindings.sh

1
build-bindings.sh Normal file
View File

@@ -0,0 +1 @@
cd Bindings && go build -buildmode=c-shared -o p2prc.so