OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_ |
| 6 #define MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_ |
| 7 |
| 8 #include "mojo/public/c/system/handle.h" |
| 9 #include "mojo/public/c/system/result.h" |
| 10 |
| 11 namespace mojo { |
| 12 |
| 13 class ApplicationImplBase; |
| 14 |
| 15 // Sets up a message (run) loop and runs the provided application |
| 16 // implementation. |
| 17 // |
| 18 // Typical use (where |MyApplicationImpl| is an implementation of |
| 19 // |ApplicationImplBase|): |
| 20 // |
| 21 // MojoResult MojoMain(MojoHandle application_request_handle) { |
| 22 // MyApplicationImpl my_app; |
| 23 // mojo::RunApplication(application_request_handle, &my_app); |
| 24 // return MOJO_RESULT_OK; |
| 25 // } |
| 26 // |
| 27 // Note that this may actually be used on any thread (that is not already |
| 28 // running a message loop of some sort). |
| 29 // |
| 30 // |*application_impl| must remain alive until the message loop starts running |
| 31 // (thus it may own itself). |
| 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 |
| 37 // implementations (e.g., "standalone" vs "chromium"). However, |
| 38 // |ApplicationRunnerChromium| currently has additional goop specific to the |
| 39 // main thread. Probably we should have additional "MainRunApplication()" and |
| 40 // "MainTerminateApplication()" functions. |
| 41 void RunApplication(MojoHandle application_request_handle, |
| 42 ApplicationImplBase* application_impl); |
| 43 |
| 44 // 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 |
| 46 // message loop is running). This will cause |RunApplication()| to return "soon" |
| 47 // (assuming the message loop is not blocked processing some task). This may |
| 48 // cause queued work to *not* be executed. |
| 49 void TerminateApplication(); |
| 50 |
| 51 } // namespace mojo |
| 52 |
| 53 #endif // MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_ |
OLD | NEW |