OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_ | 5 #ifndef MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_ |
6 #define MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_ | 6 #define MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_ |
7 | 7 |
8 #include "mojo/public/c/system/handle.h" | 8 #include "mojo/public/c/system/handle.h" |
9 #include "mojo/public/c/system/result.h" | 9 #include "mojo/public/c/system/result.h" |
10 | 10 |
11 namespace mojo { | 11 namespace mojo { |
12 | 12 |
13 class ApplicationImplBase; | 13 class ApplicationImplBase; |
14 | 14 |
15 // Sets up a message (run) loop and runs the provided application | 15 // Sets up a message (run) loop and runs the provided application |
16 // implementation. | 16 // implementation. The return value will be the one provided to |
| 17 // |TerminateApplication()|. |
17 // | 18 // |
18 // Typical use (where |MyApplicationImpl| is an implementation of | 19 // Typical use (where |MyApplicationImpl| is an implementation of |
19 // |ApplicationImplBase|): | 20 // |ApplicationImplBase|): |
20 // | 21 // |
21 // MojoResult MojoMain(MojoHandle application_request_handle) { | 22 // MojoResult MojoMain(MojoHandle application_request_handle) { |
22 // MyApplicationImpl my_app; | 23 // MyApplicationImpl my_app; |
23 // mojo::RunApplication(application_request_handle, &my_app); | 24 // return mojo::RunApplication(application_request_handle, &my_app); |
24 // return MOJO_RESULT_OK; | |
25 // } | 25 // } |
26 // | 26 // |
27 // Note that this may actually be used on any thread (that is not already | 27 // Note that this may actually be used on any thread (that is not already |
28 // running a message loop of some sort). | 28 // running a message loop of some sort). |
29 // | 29 // |
30 // |*application_impl| must remain alive until the message loop starts running | 30 // |*application_impl| must remain alive until the message loop starts running |
31 // (thus it may own itself). | 31 // (thus it may own itself). |
32 // | 32 // |
33 // TODO(vtl): Possibly this should return a |MojoResult| and | |
34 // |TerminateApplication()| should take a |MojoResult| argument (which this | |
35 // returns), but to communicate that value requires TLS. | |
36 // TODO(vtl): Maybe this should be like |Environment|, with different possible | 33 // TODO(vtl): Maybe this should be like |Environment|, with different possible |
37 // implementations (e.g., "standalone" vs "chromium"). However, | 34 // implementations (e.g., "standalone" vs "chromium"). However, |
38 // |ApplicationRunnerChromium| currently has additional goop specific to the | 35 // |ApplicationRunnerChromium| currently has additional goop specific to the |
39 // main thread. Probably we should have additional "MainRunApplication()" and | 36 // main thread. Probably we should have additional "RunMainApplication()" and |
40 // "MainTerminateApplication()" functions. | 37 // "TerminateMainApplication()" functions. |
41 void RunApplication(MojoHandle application_request_handle, | 38 MojoResult RunApplication(MojoHandle application_request_handle, |
42 ApplicationImplBase* application_impl); | 39 ApplicationImplBase* application_impl); |
43 | 40 |
44 // Terminates the currently-running application. This may only be called from | 41 // Terminates the currently-running application. This may only be called from |
45 // "inside" |RunApplication()| (i.e., it is on the stack, which means that the | 42 // "inside" |RunApplication()| (i.e., it is on the stack, which means that the |
46 // message loop is running). This will cause |RunApplication()| to return "soon" | 43 // message loop is running). This will cause |RunApplication()| to return "soon" |
47 // (assuming the message loop is not blocked processing some task). This may | 44 // (assuming the message loop is not blocked processing some task), with return |
48 // cause queued work to *not* be executed. | 45 // value |result|. This may cause queued work to *not* be executed. This should |
49 void TerminateApplication(); | 46 // be executed at most once (per |RunApplication()|). |
| 47 void TerminateApplication(MojoResult result); |
50 | 48 |
51 } // namespace mojo | 49 } // namespace mojo |
52 | 50 |
53 #endif // MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_ | 51 #endif // MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_ |
OLD | NEW |