Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: mojo/public/go/application/connection.go

Issue 1345263002: Generate Mojom Types in Go (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: GetIdentifier without a default Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/go/tests/validation_type_test.go ('k') | mojo/public/go/application/describer.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package application 5 package application
6 6
7 import ( 7 import (
8 "log" 8 "log"
9 9
10 "mojo/public/go/bindings" 10 "mojo/public/go/bindings"
11 "mojo/public/go/system" 11 "mojo/public/go/system"
12 12
13 sp "mojo/public/interfaces/application/service_provider" 13 sp "mojo/public/interfaces/application/service_provider"
14 "mojo/public/interfaces/bindings/service_describer"
14 ) 15 )
15 16
16 type connectionInfo struct { 17 type connectionInfo struct {
17 requestorURL string 18 requestorURL string
18 connectionURL string 19 connectionURL string
19 } 20 }
20 21
21 // RequestorURL returns the URL of application that established the connection. 22 // RequestorURL returns the URL of application that established the connection.
22 func (c *connectionInfo) RequestorURL() string { 23 func (c *connectionInfo) RequestorURL() string {
23 return c.requestorURL 24 return c.requestorURL
24 } 25 }
25 26
26 // ConnectionURL returns the URL that was used by the source application to 27 // ConnectionURL returns the URL that was used by the source application to
27 // establish a connection to the destination application. 28 // establish a connection to the destination application.
28 func (c *connectionInfo) ConnectionURL() string { 29 func (c *connectionInfo) ConnectionURL() string {
29 return c.connectionURL 30 return c.connectionURL
30 } 31 }
31 32
32 // ServiceRequest is an interface request for a specified mojo service. 33 // ServiceRequest is an interface request for a specified mojo service.
33 type ServiceRequest interface { 34 type ServiceRequest interface {
34 // Name returns the name of requested mojo service. 35 // Name returns the name of requested mojo service.
35 Name() string 36 Name() string
36 37
38 // ServiceDescription returns a service description, which can be querie d to
39 // examine the type information of the requested mojo service.
40 ServiceDescription() service_describer.ServiceDescription
41
37 // PassMessagePipe passes ownership of the underlying message pipe 42 // PassMessagePipe passes ownership of the underlying message pipe
38 // handle to the newly created handle object, invalidating the 43 // handle to the newly created handle object, invalidating the
39 // underlying handle object in the process. 44 // underlying handle object in the process.
40 PassMessagePipe() system.MessagePipeHandle 45 PassMessagePipe() system.MessagePipeHandle
41 } 46 }
42 47
43 // ServiceFactory provides implementation of a mojo service. 48 // ServiceFactory provides implementation of a mojo service.
44 type ServiceFactory interface { 49 type ServiceFactory interface {
45 // Name returns the name of provided mojo service. 50 // Name returns the name of provided mojo service.
46 Name() string 51 Name() string
47 52
53 // ServiceDescription returns a service description, which can be querie d to
54 // examine the type information of the provided mojo service.
rudominer 2015/10/20 21:14:06 s/the provided mojo service/the mojo service/. Th
alexfandrianto 2015/10/20 23:08:03 Done. My original reason for having it was to echo
55 ServiceDescription() service_describer.ServiceDescription
56
48 // Create binds an implementation of mojo service to the provided 57 // Create binds an implementation of mojo service to the provided
49 // message pipe and runs it. 58 // message pipe and runs it.
50 Create(pipe system.MessagePipeHandle) 59 Create(pipe system.MessagePipeHandle)
51 } 60 }
52 61
53 // Connection represents a connection to another application. An instance of 62 // Connection represents a connection to another application. An instance of
54 // this struct is passed to Delegate's AcceptConnection() function each time a 63 // this struct is passed to Delegate's AcceptConnection() function each time a
55 // connection is made to this application. 64 // connection is made to this application.
56 type Connection struct { 65 type Connection struct {
57 connectionInfo 66 connectionInfo
58 // Request for local services. Is valid until ProvideServices is called. 67 // Request for local services. Is valid until ProvideServices is called.
59 servicesRequest *sp.ServiceProvider_Request 68 servicesRequest *sp.ServiceProvider_Request
60 // Indicates that ProvideServices function was already called. 69 // Indicates that ProvideServices function was already called.
61 servicesProvided bool 70 servicesProvided bool
62 localServices *bindings.Stub 71 localServices *bindings.Stub
63 outgoingConnection *OutgoingConnection 72 outgoingConnection *OutgoingConnection
64 isClosed bool 73 isClosed bool
74 describer *ServiceDescriberFactory
65 } 75 }
66 76
67 func newConnection(requestorURL string, services *sp.ServiceProvider_Request, ex posedServices *sp.ServiceProvider_Pointer, resolvedURL string) *Connection { 77 func newConnection(requestorURL string, services *sp.ServiceProvider_Request, ex posedServices *sp.ServiceProvider_Pointer, resolvedURL string) *Connection {
68 info := connectionInfo{ 78 info := connectionInfo{
69 requestorURL, 79 requestorURL,
70 resolvedURL, 80 resolvedURL,
71 } 81 }
72 var remoteServices *sp.ServiceProvider_Proxy 82 var remoteServices *sp.ServiceProvider_Proxy
73 if exposedServices != nil { 83 if exposedServices != nil {
74 remoteServices = sp.NewServiceProviderProxy(*exposedServices, bi ndings.GetAsyncWaiter()) 84 remoteServices = sp.NewServiceProviderProxy(*exposedServices, bi ndings.GetAsyncWaiter())
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 if !ok || !connectionError.Closed() { 125 if !ok || !connectionError.Closed() {
116 log.Println(err) 126 log.Println(err)
117 } 127 }
118 break 128 break
119 } 129 }
120 } 130 }
121 }() 131 }()
122 return c.outgoingConnection 132 return c.outgoingConnection
123 } 133 }
124 134
135 // ProvideServicesWithDescriber calls ProvideServices with a ServiceDescriber.
136 // The ServiceDescriber will have knowledge of all of the services passed in.
rudominer 2015/10/20 21:14:06 This method is part of the API consumed by an appl
alexfandrianto 2015/10/20 23:08:03 I improved the comment with most of your suggestio
137 func (c *Connection) ProvideServicesWithDescriber(services ...ServiceFactory) *O utgoingConnection {
138 if c.servicesProvided {
139 panic("ProvideServices can be called only once")
rudominer 2015/10/20 21:14:06 "ProvideServices or ProvideServicesWithDescriber c
alexfandrianto 2015/10/20 23:08:03 That's true. Done.
140 }
141 mapping := make(map[string]service_describer.ServiceDescription)
142 for _, service := range services {
143 mapping[service.Name()] = service.ServiceDescription()
144 }
145 c.describer = newServiceDescriberFactory(mapping)
146 servicesWithDescriber := append(services, &service_describer.ServiceDesc riber_ServiceFactory{c.describer})
147
148 return c.ProvideServices(servicesWithDescriber...)
149 }
150
125 // Close closes both incoming and outgoing parts of the connection. 151 // Close closes both incoming and outgoing parts of the connection.
126 func (c *Connection) Close() { 152 func (c *Connection) Close() {
127 if c.servicesRequest != nil { 153 if c.servicesRequest != nil {
128 c.servicesRequest.Close() 154 c.servicesRequest.Close()
129 } 155 }
130 if c.localServices != nil { 156 if c.localServices != nil {
131 c.localServices.Close() 157 c.localServices.Close()
132 } 158 }
159 if c.describer != nil {
160 c.describer.Close()
161 }
133 if c.outgoingConnection.remoteServices != nil { 162 if c.outgoingConnection.remoteServices != nil {
134 c.outgoingConnection.remoteServices.Close_Proxy() 163 c.outgoingConnection.remoteServices.Close_Proxy()
135 } 164 }
136 c.isClosed = true 165 c.isClosed = true
137 } 166 }
138 167
139 // OutgoingConnection represents outgoing part of connection to another 168 // OutgoingConnection represents outgoing part of connection to another
140 // application. In order to close it close the |Connection| object that returned 169 // application. In order to close it close the |Connection| object that returned
141 // this |OutgoingConnection|. 170 // this |OutgoingConnection|.
142 type OutgoingConnection struct { 171 type OutgoingConnection struct {
(...skipping 24 matching lines...) Expand all
167 messagePipe.Close() 196 messagePipe.Close()
168 return nil 197 return nil
169 } 198 }
170 factory.Create(messagePipe) 199 factory.Create(messagePipe)
171 return nil 200 return nil
172 } 201 }
173 202
174 func (sp *serviceProviderImpl) AddService(factory ServiceFactory) { 203 func (sp *serviceProviderImpl) AddService(factory ServiceFactory) {
175 sp.factories[factory.Name()] = factory 204 sp.factories[factory.Name()] = factory
176 } 205 }
OLDNEW
« no previous file with comments | « mojo/go/tests/validation_type_test.go ('k') | mojo/public/go/application/describer.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698