| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "log" | 9 "log" |
| 10 | 10 |
| 11 "code.google.com/p/go.mobile/app" | 11 "code.google.com/p/go.mobile/app" |
| 12 | 12 |
| 13 "mojo/public/go/application" | 13 "mojo/public/go/application" |
| 14 "mojo/public/go/bindings" | 14 "mojo/public/go/bindings" |
| 15 "mojo/public/go/system" | 15 "mojo/public/go/system" |
| 16 | 16 |
| 17 "examples/echo/echo" | 17 "examples/echo/echo" |
| 18 ) | 18 ) |
| 19 | 19 |
| 20 //#include "mojo/public/c/system/types.h" | 20 //#include "mojo/public/c/system/types.h" |
| 21 import "C" | 21 import "C" |
| 22 | 22 |
| 23 type EchoClientDelegate struct { | 23 type EchoClientDelegate struct { |
| 24 echo *echo.EchoProxy | 24 echo *echo.EchoProxy |
| 25 } | 25 } |
| 26 | 26 |
| 27 func (delegate *EchoClientDelegate) Initialize(ctx application.Context) { | 27 func (delegate *EchoClientDelegate) Initialize(ctx application.Context) { |
| 28 echoRequest, echoPointer := echo.CreateMessagePipeForEcho() | 28 echoRequest, echoPointer := echo.CreateMessagePipeForEcho() |
| 29 » ctx.ConnectToApplication("mojo:echo_server").ConnectToService(&echoReque
st) | 29 » ctx.ConnectToApplication("mojo:go_echo_server").ConnectToService(&echoRe
quest) |
| 30 delegate.echo = echo.NewEchoProxy(echoPointer, bindings.GetAsyncWaiter()
) | 30 delegate.echo = echo.NewEchoProxy(echoPointer, bindings.GetAsyncWaiter()
) |
| 31 response, err := delegate.echo.EchoString(bindings.StringPointer("Hello,
Go world!")) | 31 response, err := delegate.echo.EchoString(bindings.StringPointer("Hello,
Go world!")) |
| 32 if response != nil { | 32 if response != nil { |
| 33 » » fmt.Println(*response) | 33 » » fmt.Printf("client: %s\n", *response) |
| 34 } else { | 34 } else { |
| 35 log.Println(err) | 35 log.Println(err) |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 func (delegate *EchoClientDelegate) AcceptConnection(connection *application.Con
nection) { | 39 func (delegate *EchoClientDelegate) AcceptConnection(connection *application.Con
nection) { |
| 40 connection.Close() | 40 connection.Close() |
| 41 } | 41 } |
| 42 | 42 |
| 43 func (delegate *EchoClientDelegate) Quit() { | 43 func (delegate *EchoClientDelegate) Quit() { |
| 44 delegate.echo.Close_proxy() | 44 delegate.echo.Close_proxy() |
| 45 } | 45 } |
| 46 | 46 |
| 47 //export MojoMain | 47 //export MojoMain |
| 48 func MojoMain(handle C.MojoHandle) C.MojoResult { | 48 func MojoMain(handle C.MojoHandle) C.MojoResult { |
| 49 application.Run(&EchoClientDelegate{}, system.MojoHandle(handle)) | 49 application.Run(&EchoClientDelegate{}, system.MojoHandle(handle)) |
| 50 return C.MOJO_RESULT_OK | 50 return C.MOJO_RESULT_OK |
| 51 } | 51 } |
| 52 | 52 |
| 53 func main() { | 53 func main() { |
| 54 app.Run(app.Callbacks{}) | 54 app.Run(app.Callbacks{}) |
| 55 } | 55 } |
| OLD | NEW |