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