blob: e476a97a677da7b74d14c8fb3858c06835309f87 [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package main
import (
"fmt"
"log"
"code.google.com/p/go.mobile/app"
"mojo/public/go/application"
"mojo/public/go/bindings"
"mojo/public/go/system"
"examples/echo/echo"
)
//#include "mojo/public/c/system/types.h"
import "C"
type EchoClientDelegate struct {
echo *echo.EchoProxy
}
func (delegate *EchoClientDelegate) Initialize(ctx application.Context) {
echoRequest, echoPointer := echo.CreateMessagePipeForEcho()
ctx.ConnectToApplication("mojo:echo_server").ConnectToService(&echoRequest)
delegate.echo = echo.NewEchoProxy(echoPointer, bindings.GetAsyncWaiter())
response, err := delegate.echo.EchoString(bindings.StringPointer("Hello, Go world!"))
if response != nil {
fmt.Println(*response)
} else {
log.Println(err)
}
}
func (delegate *EchoClientDelegate) AcceptConnection(connection *application.Connection) {
connection.Close()
}
func (delegate *EchoClientDelegate) Quit() {
delegate.echo.Close_proxy()
}
//export MojoMain
func MojoMain(handle C.MojoHandle) C.MojoResult {
application.Run(&EchoClientDelegate{}, system.MojoHandle(handle))
return C.MOJO_RESULT_OK
}
func main() {
app.Run(app.Callbacks{})
}