| 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/result.h> | |
| 9 #include <mojo/system/handle.h> | |
| 10 | |
| 11 namespace mojo { | |
| 12 | |
| 13 class ApplicationImplBase; | |
| 14 | |
| 15 // Base class for options to |RunApplication()|. An implementation of these | |
| 16 // functions may (but need not, in which case no options are available) | |
| 17 // separately provide an implementation subclass, which would be specific to | |
| 18 // that implementation. (The "standalone" implementation has no options.) | |
| 19 class RunApplicationOptions { | |
| 20 protected: | |
| 21 RunApplicationOptions() {} | |
| 22 ~RunApplicationOptions() {} | |
| 23 }; | |
| 24 | |
| 25 // |RunApplication()| sets up a message (run) loop and runs the provided | |
| 26 // application implementation. The return value will be the one provided to | |
| 27 // |TerminateApplication()|. | |
| 28 // | |
| 29 // Typical use (where |MyApplicationImpl| is an implementation of | |
| 30 // |ApplicationImplBase|): | |
| 31 // | |
| 32 // MojoResult MojoMain(MojoHandle application_request_handle) { | |
| 33 // MyApplicationImpl my_app; | |
| 34 // return mojo::RunApplication(application_request_handle, &my_app); | |
| 35 // } | |
| 36 // | |
| 37 // Note that |RunApplication()| may also be used on secondary threads (that are | |
| 38 // not already running a message loop of some sort). | |
| 39 // | |
| 40 // |*application_impl| must remain alive until the message loop starts running | |
| 41 // (thus it may own itself). If |options| is non-null, then it must point to an | |
| 42 // instance of an implementation-specific subclass of |RunApplicationOptions|; | |
| 43 // |*options| must remain alive for the duration of the call. | |
| 44 MojoResult RunApplication(MojoHandle application_request_handle, | |
| 45 ApplicationImplBase* application_impl, | |
| 46 const RunApplicationOptions* options = nullptr); | |
| 47 | |
| 48 // |TerminateApplication()| terminates the application that is running on the | |
| 49 // current thread. It may only be called from "inside" |RunApplication()| (i.e., | |
| 50 // with |RunApplication()| on the stack, which means that the message loop is | |
| 51 // running). It causes |RunApplication()| to return "soon" (assuming the message | |
| 52 // loop is not blocked processing some task), with return value |result|. It may | |
| 53 // cause queued work to *not* be executed. It should be executed at most once | |
| 54 // (per |RunApplication()|). | |
| 55 void TerminateApplication(MojoResult result); | |
| 56 | |
| 57 } // namespace mojo | |
| 58 | |
| 59 #endif // MOJO_PUBLIC_CPP_APPLICATION_RUN_APPLICATION_H_ | |
| OLD | NEW |