OLD | NEW |
1 # Service Manager User Guide | 1 # Service Manager User Guide |
2 | 2 |
3 ## What is the Service Manager? | 3 ## What is the Service Manager? |
4 | 4 |
5 The Service Manager is a tool that brokers connections and capabilities between | 5 The Service Manager is a tool that brokers connections and capabilities between |
6 and manages instances of components, referred to henceforth as services. | 6 and manages instances of components, referred to henceforth as services. |
7 | 7 |
8 The Service Manager performs the following functions: | 8 The Service Manager performs the following functions: |
9 | 9 |
10 * Brokering connections between services, including communicating policies such | 10 * Brokering connections between services, including communicating policies such |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 service wishes to terminate it closes the Service pipe with the Service Manager | 82 service wishes to terminate it closes the Service pipe with the Service Manager |
83 and the Service Manager destroys its corresponding instance and asks the process | 83 and the Service Manager destroys its corresponding instance and asks the process |
84 to exit. | 84 to exit. |
85 | 85 |
86 #### A simple Service example | 86 #### A simple Service example |
87 | 87 |
88 Consider this simple application that implements the Service interface: | 88 Consider this simple application that implements the Service interface: |
89 | 89 |
90 **app.cc:** | 90 **app.cc:** |
91 | 91 |
92 #include mojo/public/c/system/main.h | 92 #include "mojo/public/c/system/main.h" |
93 #include services/shell/public/cpp/application_runner.h | 93 #include "services/shell/public/cpp/application_runner.h" |
94 #include services/shell/public/cpp/connector.h | 94 #include "services/shell/public/cpp/connector.h" |
95 #include services/shell/public/cpp/connection.h | 95 #include "services/shell/public/cpp/connection.h" |
96 #include services/shell/public/cpp/identity.h | 96 #include "services/shell/public/cpp/identity.h" |
97 #include services/shell/public/cpp/service.h | 97 #include "services/shell/public/cpp/service.h" |
98 | 98 |
99 class Service : public shell::Service { | 99 class Service : public shell::Service { |
100 public: | 100 public: |
101 Service() {} | 101 Service() {} |
102 ~Service() override {} | 102 ~Service() override {} |
103 | 103 |
104 // Overridden from shell::Service: | 104 // Overridden from shell::Service: |
105 void OnStart(const shell::Identity& identity) override { | 105 void OnStart(const shell::Identity& identity) override { |
106 } | 106 } |
107 bool OnConnect(shell::Connection* connection) override { | 107 bool OnConnect(shell::Connection* connection) override { |
108 return true; | 108 return true; |
109 } | 109 } |
110 }; | 110 }; |
111 | 111 |
112 MojoResult ServiceMain(MojoHandle service_request_handle) { | 112 MojoResult ServiceMain(MojoHandle service_request_handle) { |
113 return shell::ServiceRunner(new Service).Run(service_request_handle); | 113 return shell::ServiceRunner(new Service).Run(service_request_handle); |
114 } | 114 } |
115 | 115 |
116 app_manifest.json: | 116 app_manifest.json: |
117 | 117 |
118 { | 118 { |
119 manifest_version: 1, | 119 "manifest_version": 1, |
120 name: mojo:app, | 120 "name": "mojo:app", |
121 display_name: Example App, | 121 "display_name": "Example App", |
122 capabilities: {} | 122 "capabilities": {} |
123 } | 123 } |
124 | 124 |
125 **BUILD.gn:** | 125 **BUILD.gn:** |
126 | 126 |
127 import(//mojo/public/mojo_application.gni) | 127 import("//mojo/public/mojo_application.gni") |
128 | 128 |
129 service(app) { | 129 service("app") { |
130 sources = [ app.cc ] | 130 sources = [ "app.cc" ] |
131 deps = [ //base, //mojo/shell/public/cpp ] | 131 deps = [ "//base", "//mojo/shell/public/cpp" ] |
132 data_deps = [ :manifest ] | 132 data_deps = [ ":manifest" ] |
133 } | 133 } |
134 | 134 |
135 service_manifest(manifest) { | 135 service_manifest("manifest") { |
136 name = app | 136 name = "app" |
137 source = app_manifest.json | 137 source = "app_manifest.json" |
138 } | 138 } |
139 | 139 |
140 What does all this do? Building the app target produces two files in the output | 140 What does all this do? Building the app target produces two files in the output |
141 directory: app/app.library and app/manifest.json. app.library is a DSO loaded by | 141 directory: app/app.library and app/manifest.json. app.library is a DSO loaded by |
142 the Service Manager in its own process when another service connects to the | 142 the Service Manager in its own process when another service connects to the |
143 mojo:app name. This is not the only way (nor even the most likely one) you can | 143 mojo:app name. This is not the only way (nor even the most likely one) you can |
144 implement a Service, but its the simplest and easiest to reason about. | 144 implement a Service, but its the simplest and easiest to reason about. |
145 | 145 |
146 This service doesnt do much. Its implementation of OnStart() is empty, and its | 146 This service doesnt do much. Its implementation of OnStart() is empty, and its |
147 implementation of OnConnect just returns true to allow the inbound connection to | 147 implementation of OnConnect just returns true to allow the inbound connection to |
(...skipping 25 matching lines...) Expand all Loading... |
173 we should look at how we connect to another service and bind an interface from | 173 we should look at how we connect to another service and bind an interface from |
174 it. This will lay the groundwork to understanding how to export an interface. | 174 it. This will lay the groundwork to understanding how to export an interface. |
175 | 175 |
176 ### Connecting | 176 ### Connecting |
177 | 177 |
178 Once we have a Connector, we can connect to other services and bind interfaces | 178 Once we have a Connector, we can connect to other services and bind interfaces |
179 from them. In the trivial app above we can do this directly in OnStart: | 179 from them. In the trivial app above we can do this directly in OnStart: |
180 | 180 |
181 void OnStart(const shell::Identity& identity) override { | 181 void OnStart(const shell::Identity& identity) override { |
182 scoped_ptr<shell::Connection> connection = | 182 scoped_ptr<shell::Connection> connection = |
183 connector()->Connect(mojo:service); | 183 connector()->Connect("mojo:service"); |
184 mojom::SomeInterfacePtr some_interface; | 184 mojom::SomeInterfacePtr some_interface; |
185 connection->GetInterface(&some_interface); | 185 connection->GetInterface(&some_interface); |
186 some_interface->Foo(); | 186 some_interface->Foo(); |
187 } | 187 } |
188 | 188 |
error: old chunk mismatch |
None
OLD | NEW |