Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package main | |
| 6 | |
| 7 import ( | |
| 8 "fmt" | |
| 9 "log" | |
| 10 | |
| 11 "code.google.com/p/go.mobile/app" | |
| 12 | |
| 13 "mojo/public/go/bindings" | |
| 14 "mojo/public/go/system" | |
| 15 | |
| 16 "examples/echo/echo" | |
| 17 "mojo/public/interfaces/application/application" | |
| 18 "mojo/public/interfaces/application/service_provider" | |
| 19 "mojo/public/interfaces/application/shell" | |
| 20 ) | |
| 21 | |
| 22 //#include "mojo/public/c/system/types.h" | |
| 23 import "C" | |
| 24 | |
| 25 // AppImpl implements mojo interface application. | |
| 26 type AppImpl struct { | |
| 27 shell *shell.ShellProxy | |
| 28 serviceProvider *service_provider.ServiceProviderProxy | |
| 29 echo *echo.EchoProxy | |
| 30 } | |
| 31 | |
| 32 func (impl *AppImpl) Initialize(inShell shell.ShellPointer, inArgs *[]string, in Url string) error { | |
| 33 impl.shell = shell.NewShellProxy(inShell, bindings.GetAsyncWaiter()) | |
| 34 // Connect to another mojo application. | |
| 35 request, pointer := service_provider.CreateMessagePipeForServiceProvider () | |
| 36 if err := impl.shell.ConnectToApplication("mojo:echo_server", &request, nil); err != nil { | |
| 37 return err | |
| 38 } | |
| 39 impl.serviceProvider = service_provider.NewServiceProviderProxy(pointer, bindings.GetAsyncWaiter()) | |
| 40 // Connect to service. | |
| 41 echoRequest, echoPointer := echo.CreateMessagePipeForEcho() | |
| 42 if err := impl.serviceProvider.ConnectToService("mojo::examples::Echo", echoRequest.PassMessagePipe()); err != nil { | |
| 43 return err | |
| 44 } | |
| 45 impl.echo = echo.NewEchoProxy(echoPointer, bindings.GetAsyncWaiter()) | |
| 46 // Send and receive echo request. | |
| 47 response, err := impl.echo.EchoString(bindings.StringPointer("Hello Go w orld!")) | |
| 48 if response != nil { | |
| 49 fmt.Println(*response) | |
|
jamesr
2015/03/12 22:26:06
question: why does this fmt.Println()...
| |
| 50 } else { | |
| 51 return fmt.Errorf("nil echo response") | |
| 52 } | |
| 53 return err | |
| 54 } | |
| 55 | |
| 56 func (impl *AppImpl) AcceptConnection(inRequestorUrl string, inServices *service _provider.ServiceProviderRequest, inExposedServices *service_provider.ServicePro viderPointer, inResolvedUrl string) error { | |
| 57 if inServices != nil { | |
| 58 inServices.Close() | |
| 59 } | |
| 60 if inExposedServices != nil { | |
| 61 inExposedServices.Close() | |
| 62 } | |
| 63 return nil | |
| 64 } | |
| 65 | |
| 66 func (impl *AppImpl) RequestQuit() error { | |
| 67 impl.echo.Close_proxy() | |
| 68 impl.serviceProvider.Close_proxy() | |
| 69 impl.shell.Close_proxy() | |
| 70 return fmt.Errorf("closed") | |
| 71 } | |
| 72 | |
| 73 //export MojoMain | |
| 74 func MojoMain(handle C.MojoHandle) C.MojoResult { | |
| 75 appHandle := system.GetCore().AcquireNativeHandle(system.MojoHandle(hand le)).ToMessagePipeHandle() | |
| 76 appRequest := application.ApplicationRequest{bindings.NewMessagePipeHand leOwner(appHandle)} | |
| 77 stub := application.NewApplicationStub(appRequest, &AppImpl{}, bindings. GetAsyncWaiter()) | |
| 78 for { | |
| 79 if err := stub.ServeRequest(); err != nil { | |
| 80 log.Println(err) | |
| 81 stub.Close() | |
| 82 break | |
| 83 } | |
| 84 } | |
| 85 return C.MOJO_RESULT_OK | |
| 86 } | |
| 87 | |
| 88 func main() { | |
| 89 app.Run(app.Callbacks{}) | |
| 90 } | |
| OLD | NEW |