diff --git a/.gitignore b/.gitignore index bdd6c8e..6e4cb28 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ logs/ # ignore docker image files server/docker/containers/ +*.h +*.so diff --git a/Bindings/Client.go b/Bindings/Client.go index 192f109..18fc0bc 100644 --- a/Bindings/Client.go +++ b/Bindings/Client.go @@ -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() {} diff --git a/Makefile b/Makefile index a32c494..4795b7c 100644 --- a/Makefile +++ b/Makefile @@ -9,3 +9,5 @@ testcases: run: go run main.go +sharedObjects: + sh build-bindings.sh diff --git a/build-bindings.sh b/build-bindings.sh new file mode 100644 index 0000000..a794e50 --- /dev/null +++ b/build-bindings.sh @@ -0,0 +1 @@ +cd Bindings && go build -buildmode=c-shared -o p2prc.so