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