| package main |
| |
| import ( |
| "crypto/sha256" |
| "encoding/hex" |
| "log" |
| "mojo/public/go/application" |
| "mojo/public/go/bindings" |
| "mojo/public/go/system" |
| "mojom/v.io/x/ref/services/discovery/ble/ble" |
| ) |
| |
| //#include "mojo/public/c/system/types.h" |
| import "C" |
| |
| type discoveryDelegate struct { |
| bleHandlerProxy *ble.PluginStopper_Proxy |
| } |
| |
| func (d *discoveryDelegate) Initialize(ctx application.Context) { |
| hash := sha256.Sum256([]byte("foobar")) |
| uuid := hash[:16] |
| hash = sha256.Sum256([]byte("key1")) |
| key1 := hex.EncodeToString(hash[:16]) |
| bleRequest, blePointer := ble.CreateMessagePipeForV23Ble() |
| ctx.ConnectToApplication("https://mojo.v.io/ble.mojo").ConnectToService(&bleRequest) |
| bleProxy := ble.NewV23BleProxy(blePointer, bindings.GetAsyncWaiter()) |
| adv := ble.Advertisement{ |
| ServiceId: uuid, |
| Service: ble.Service{ |
| Attributes: map[string]string{key1: "value1"}, |
| InstanceId: []byte("random-uuid"), |
| }, |
| } |
| handlerPtr, err := bleProxy.Advertise(adv) |
| if err != nil { |
| log.Println(err) |
| ctx.Close() |
| return |
| } |
| d.bleHandlerProxy = ble.NewPluginStopperProxy(handlerPtr, bindings.GetAsyncWaiter()) |
| } |
| |
| func (d *discoveryDelegate) AcceptConnection(conn *application.Connection) { |
| conn.Close() |
| } |
| |
| func (d *discoveryDelegate) Quit() { |
| if d.bleHandlerProxy != nil { |
| d.bleHandlerProxy.Stop() |
| } |
| } |
| |
| //export MojoMain |
| func MojoMain(handle C.MojoHandle) C.MojoResult { |
| application.Run(&discoveryDelegate{}, system.MojoHandle(handle)) |
| return C.MOJO_RESULT_OK |
| } |
| |
| func main() {} |