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 // ServiceProviderImpl implements mojo interface echo. | |
26 type EchoImpl struct{} | |
27 | |
28 func (echo *EchoImpl) EchoString(inValue *string) (outValue *string, err error) { | |
29 log.Println(*inValue) | |
jamesr
2015/03/12 22:26:06
...but this one log.Println()s?
| |
30 return inValue, nil | |
31 } | |
32 | |
33 // ServiceProviderImpl implements mojo interface service provider. | |
34 type ServiceProviderImpl struct{} | |
35 | |
36 func (impl *ServiceProviderImpl) ConnectToService(inInterfaceName string, inPipe system.MessagePipeHandle) error { | |
37 if inInterfaceName != "mojo::examples::Echo" { | |
38 inPipe.Close() | |
39 return nil | |
40 } | |
41 request := echo.EchoRequest{bindings.NewMessagePipeHandleOwner(inPipe)} | |
42 echoStub := echo.NewEchoStub(request, &EchoImpl{}, bindings.GetAsyncWait er()) | |
43 go func() { | |
44 for { | |
45 if err := echoStub.ServeRequest(); err != nil { | |
46 log.Println(err) | |
47 echoStub.Close() | |
48 break | |
49 } | |
50 } | |
51 }() | |
52 return nil | |
53 } | |
54 | |
55 // AppImpl implements mojo interface application. | |
56 type AppImpl struct { | |
57 shell *shell.ShellProxy | |
58 } | |
59 | |
60 func (impl *AppImpl) Initialize(inShell shell.ShellPointer, inArgs *[]string, in Url string) error { | |
61 impl.shell = shell.NewShellProxy(inShell, bindings.GetAsyncWaiter()) | |
62 return nil | |
63 } | |
64 | |
65 func (impl *AppImpl) AcceptConnection(inRequestorUrl string, inServices *service _provider.ServiceProviderRequest, inExposedServices *service_provider.ServicePro viderPointer, inResolvedUrl string) error { | |
66 if inExposedServices != nil { | |
67 inExposedServices.Close() | |
68 } | |
69 if inServices == nil { | |
70 return nil | |
71 } | |
72 serviceProviderStub := service_provider.NewServiceProviderStub(*inServic es, &ServiceProviderImpl{}, bindings.GetAsyncWaiter()) | |
73 go func() { | |
74 for { | |
75 if err := serviceProviderStub.ServeRequest(); err != nil { | |
76 log.Println(err) | |
77 serviceProviderStub.Close() | |
78 break | |
79 } | |
80 } | |
81 }() | |
82 return nil | |
83 } | |
84 | |
85 func (impl *AppImpl) RequestQuit() error { | |
86 impl.shell.Close_proxy() | |
87 return fmt.Errorf("closed") | |
88 } | |
89 | |
90 //export MojoMain | |
91 func MojoMain(handle C.MojoHandle) C.MojoResult { | |
92 appHandle := system.GetCore().AcquireNativeHandle(system.MojoHandle(hand le)).ToMessagePipeHandle() | |
93 appRequest := application.ApplicationRequest{bindings.NewMessagePipeHand leOwner(appHandle)} | |
94 stub := application.NewApplicationStub(appRequest, &AppImpl{}, bindings. GetAsyncWaiter()) | |
95 for { | |
96 if err := stub.ServeRequest(); err != nil { | |
97 log.Println(err) | |
98 stub.Close() | |
99 break | |
100 } | |
101 } | |
102 return C.MOJO_RESULT_OK | |
103 } | |
104 | |
105 func main() { | |
106 app.Run(app.Callbacks{}) | |
107 } | |
OLD | NEW |