| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_APPLICATION_RUNNER_H_ | 5 #ifndef MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_RUNNER_H_ |
| 6 #define MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_RUNNER_H_ | 6 #define MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_RUNNER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "mojo/public/c/environment/logger.h" | |
| 11 #include "mojo/public/c/system/handle.h" | 10 #include "mojo/public/c/system/handle.h" |
| 12 #include "mojo/public/c/system/result.h" | 11 #include "mojo/public/c/system/result.h" |
| 13 #include "mojo/public/cpp/system/macros.h" | 12 #include "mojo/public/cpp/system/macros.h" |
| 14 | 13 |
| 15 namespace mojo { | 14 namespace mojo { |
| 16 | 15 |
| 17 class ApplicationDelegate; | 16 class ApplicationDelegate; |
| 18 | 17 |
| 19 // A utility for running an Application. The typical use case is to use | 18 // A utility for running an Application. The typical use case is to use |
| 20 // when writing your MojoMain: | 19 // when writing your MojoMain: |
| 21 // | 20 // |
| 22 // MojoResult MojoMain(MojoHandle application_request) { | 21 // MojoResult MojoMain(MojoHandle application_request) { |
| 23 // mojo::ApplicationRunner runner(new MyApplicationDelegate()); | 22 // mojo::ApplicationRunner runner(new MyApplicationDelegate()); |
| 24 // return runner.Run(application_request); | 23 // return runner.Run(application_request); |
| 25 // } | 24 // } |
| 26 // | 25 // |
| 27 // ApplicationRunner takes care of mojo environment initialization and | 26 // ApplicationRunner takes care of mojo environment initialization and |
| 28 // shutdown, and starting a RunLoop from which your application can run and | 27 // shutdown, and starting a RunLoop from which your application can run and |
| 29 // ultimately Quit(). | 28 // ultimately Quit(). |
| 30 class ApplicationRunner { | 29 class ApplicationRunner { |
| 31 public: | 30 public: |
| 32 explicit ApplicationRunner(std::unique_ptr<ApplicationDelegate> delegate); | 31 explicit ApplicationRunner(std::unique_ptr<ApplicationDelegate> delegate); |
| 33 ~ApplicationRunner(); | 32 ~ApplicationRunner(); |
| 34 | 33 |
| 35 // This replaces the underlying logger implementation with the one provided. | |
| 36 // This static method may only be called while |Run()| is running. |logger| | |
| 37 // must outlive the duration of this |Run()|, or until the subsequent | |
| 38 // |ApplicationRunner::SetDefaultLogger()|, which ever comes first. | |
| 39 static void SetDefaultLogger(const MojoLogger* logger); | |
| 40 // This static method may only be called while |Run()| is running. | |
| 41 static const MojoLogger* GetDefaultLogger(); | |
| 42 | |
| 43 // Once the various parameters have been set above, use Run to initialize an | 34 // Once the various parameters have been set above, use Run to initialize an |
| 44 // ApplicationImpl wired to the provided delegate, and run a RunLoop until | 35 // ApplicationImpl wired to the provided delegate, and run a RunLoop until |
| 45 // the application exits. | 36 // the application exits. |
| 46 MojoResult Run(MojoHandle application_request); | 37 MojoResult Run(MojoHandle application_request); |
| 47 | 38 |
| 48 private: | 39 private: |
| 49 std::unique_ptr<ApplicationDelegate> delegate_; | 40 std::unique_ptr<ApplicationDelegate> delegate_; |
| 50 | 41 |
| 51 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationRunner); | 42 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationRunner); |
| 52 }; | 43 }; |
| 53 | 44 |
| 54 } // namespace mojo | 45 } // namespace mojo |
| 55 | 46 |
| 56 #endif // MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_RUNNER_H_ | 47 #endif // MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_RUNNER_H_ |
| OLD | NEW |