| 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 // |RunMainApplication()| and |RunApplication()| set up a message (run) loop and |
| 16 // implementation. The return value will be the one provided to | 16 // run the provided application implementation. |RunMainApplication()| should be |
| 17 // |TerminateApplication()|. | 17 // used on the application's main thread (e.g., from |MojoMain()|) and may do |
| 18 // additional initialization. (In the case of the "standalone" implementation, |
| 19 // the two are equivalent.) The return value will be the one provided to |
| 20 // |TerminateMainApplication()| or |TerminateApplication()|, respectively. |
| 18 // | 21 // |
| 19 // Typical use (where |MyApplicationImpl| is an implementation of | 22 // Typical use (where |MyApplicationImpl| is an implementation of |
| 20 // |ApplicationImplBase|): | 23 // |ApplicationImplBase|): |
| 21 // | 24 // |
| 22 // MojoResult MojoMain(MojoHandle application_request_handle) { | 25 // MojoResult MojoMain(MojoHandle application_request_handle) { |
| 23 // MyApplicationImpl my_app; | 26 // MyApplicationImpl my_app; |
| 24 // return mojo::RunApplication(application_request_handle, &my_app); | 27 // return mojo::RunMainApplication(application_request_handle, &my_app); |
| 25 // } | 28 // } |
| 26 // | 29 // |
| 27 // Note that this may actually be used on any thread (that is not already | 30 // |RunApplication()| may be used on secondary threads (that are not already |
| 28 // running a message loop of some sort). | 31 // running a message loop of some sort). |
| 29 // | 32 // |
| 30 // |*application_impl| must remain alive until the message loop starts running | 33 // |*application_impl| must remain alive until the message loop starts running |
| 31 // (thus it may own itself). | 34 // (thus it may own itself). |
| 32 // | 35 MojoResult RunMainApplication(MojoHandle application_request_handle, |
| 33 // TODO(vtl): Maybe this should be like |Environment|, with different possible | 36 ApplicationImplBase* application_impl); |
| 34 // implementations (e.g., "standalone" vs "chromium"). However, | |
| 35 // |ApplicationRunnerChromium| currently has additional goop specific to the | |
| 36 // main thread. Probably we should have additional "RunMainApplication()" and | |
| 37 // "TerminateMainApplication()" functions. | |
| 38 MojoResult RunApplication(MojoHandle application_request_handle, | 37 MojoResult RunApplication(MojoHandle application_request_handle, |
| 39 ApplicationImplBase* application_impl); | 38 ApplicationImplBase* application_impl); |
| 40 | 39 |
| 41 // Terminates the currently-running application. This may only be called from | 40 // |TerminateMainApplication()| and |TerminateApplication()| terminate the |
| 42 // "inside" |RunApplication()| (i.e., it is on the stack, which means that the | 41 // application that is running on the current thread. They may only be called |
| 43 // message loop is running). This will cause |RunApplication()| to return "soon" | 42 // from "inside" |RunMainApplication()| and |RunApplication()| respectively |
| 43 // (i.e., |Run[Main]Application()| is on the stack, which means that the message |
| 44 // loop is running). They will cause |Run[Main]Application()| to return "soon" |
| 44 // (assuming the message loop is not blocked processing some task), with return | 45 // (assuming the message loop is not blocked processing some task), with return |
| 45 // value |result|. This may cause queued work to *not* be executed. This should | 46 // value |result|. They may cause queued work to *not* be executed. They should |
| 46 // be executed at most once (per |RunApplication()|). | 47 // be executed at most once (per |Run[Main]Application()|). |
| 48 void TerminateMainApplication(MojoResult result); |
| 47 void TerminateApplication(MojoResult result); | 49 void TerminateApplication(MojoResult result); |
| 48 | 50 |
| 49 } // namespace mojo | 51 } // namespace mojo |
| 50 | 52 |
| 51 #endif // MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_ | 53 #endif // MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_ |
| OLD | NEW |