| Index: examples/go/echo_server.go
|
| diff --git a/examples/go/echo_server.go b/examples/go/echo_server.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7cb71eeb37dd1f71ce2b013e542b2a30532abbde
|
| --- /dev/null
|
| +++ b/examples/go/echo_server.go
|
| @@ -0,0 +1,100 @@
|
| +package main
|
| +
|
| +import (
|
| + "fmt"
|
| + "log"
|
| +
|
| + "code.google.com/p/go.mobile/app"
|
| +
|
| + "mojo/public/go/bindings"
|
| + "mojo/public/go/system"
|
| +
|
| + "examples/echo/echo"
|
| + "mojo/public/interfaces/application/application"
|
| + "mojo/public/interfaces/application/service_provider"
|
| + "mojo/public/interfaces/application/shell"
|
| +)
|
| +
|
| +//#include "mojo/public/c/system/types.h"
|
| +import "C"
|
| +
|
| +// ServiceProviderImpl implements mojo interface echo.
|
| +type EchoImpl struct{}
|
| +
|
| +func (echo *EchoImpl) EchoString(inValue *string) (outValue *string, err error) {
|
| + log.Println(*inValue)
|
| + return inValue, nil
|
| +}
|
| +
|
| +// ServiceProviderImpl implements mojo interface service provider.
|
| +type ServiceProviderImpl struct{}
|
| +
|
| +func (impl *ServiceProviderImpl) ConnectToService(inInterfaceName string, inPipe system.MessagePipeHandle) error {
|
| + if inInterfaceName != "mojo::examples::Echo" {
|
| + inPipe.Close()
|
| + return nil
|
| + }
|
| + request := echo.EchoRequest{bindings.NewMessagePipeHandleOwner(inPipe)}
|
| + echoStub := echo.NewEchoStub(request, &EchoImpl{}, bindings.GetAsyncWaiter())
|
| + go func() {
|
| + for {
|
| + if err := echoStub.ServeRequest(); err != nil {
|
| + log.Println(err)
|
| + echoStub.Close()
|
| + break
|
| + }
|
| + }
|
| + }()
|
| + return nil
|
| +}
|
| +
|
| +// AppImpl implements mojo interface application.
|
| +type AppImpl struct {
|
| + shell *shell.ShellProxy
|
| +}
|
| +
|
| +func (impl *AppImpl) Initialize(inShell shell.ShellPointer, inArgs *[]string, inUrl string) error {
|
| + impl.shell = shell.NewShellProxy(inShell, bindings.GetAsyncWaiter())
|
| + return nil
|
| +}
|
| +
|
| +func (impl *AppImpl) AcceptConnection(inRequestorUrl string, inServices *service_provider.ServiceProviderRequest, inExposedServices *service_provider.ServiceProviderPointer, inResolvedUrl string) error {
|
| + if inServices == nil {
|
| + return nil
|
| + }
|
| + serviceProviderStub := service_provider.NewServiceProviderStub(*inServices, &ServiceProviderImpl{}, bindings.GetAsyncWaiter())
|
| + go func() {
|
| + for {
|
| + if err := serviceProviderStub.ServeRequest(); err != nil {
|
| + log.Println(err)
|
| + serviceProviderStub.Close()
|
| + break
|
| + }
|
| + }
|
| + }()
|
| + return nil
|
| +}
|
| +
|
| +func (impl *AppImpl) RequestQuit() error {
|
| + impl.shell.Close_proxy()
|
| + return fmt.Errorf("closed")
|
| +}
|
| +
|
| +//export MojoMain
|
| +func MojoMain(handle C.MojoHandle) C.MojoResult {
|
| + appHandle := system.GetCore().AcquireNativeHandle(system.MojoHandle(handle)).ToMessagePipeHandle()
|
| + appRequest := application.ApplicationRequest{bindings.NewMessagePipeHandleOwner(appHandle)}
|
| + stub := application.NewApplicationStub(appRequest, &AppImpl{}, bindings.GetAsyncWaiter())
|
| + for {
|
| + if err := stub.ServeRequest(); err != nil {
|
| + log.Println(err)
|
| + stub.Close()
|
| + break
|
| + }
|
| + }
|
| + return C.MOJO_RESULT_OK
|
| +}
|
| +
|
| +func main() {
|
| + app.Run(app.Callbacks{})
|
| +}
|
|
|