James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
James Robinson | 63b637a | 2014-12-03 14:46:39 -0800 | [diff] [blame] | 5 | #include "services/test_service/test_service_application.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 6 | |
| 7 | #include <assert.h> |
| 8 | |
| 9 | #include "mojo/public/c/system/main.h" |
| 10 | #include "mojo/public/cpp/application/application_connection.h" |
| 11 | #include "mojo/public/cpp/application/application_runner.h" |
| 12 | #include "mojo/public/cpp/utility/run_loop.h" |
James Robinson | 63b637a | 2014-12-03 14:46:39 -0800 | [diff] [blame] | 13 | #include "services/test_service/test_service_impl.h" |
| 14 | #include "services/test_service/test_time_service_impl.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 15 | |
| 16 | namespace mojo { |
| 17 | namespace test { |
| 18 | |
Geoffrey Gowan | 8e12b96 | 2015-02-09 16:45:05 -0800 | [diff] [blame] | 19 | TestServiceApplication::TestServiceApplication() |
| 20 | : ref_count_(0), app_impl_(nullptr) { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | TestServiceApplication::~TestServiceApplication() { |
| 24 | } |
| 25 | |
Geoffrey Gowan | 8e12b96 | 2015-02-09 16:45:05 -0800 | [diff] [blame] | 26 | void TestServiceApplication::Initialize(ApplicationImpl* app) { |
| 27 | app_impl_ = app; |
| 28 | } |
| 29 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 30 | bool TestServiceApplication::ConfigureIncomingConnection( |
| 31 | ApplicationConnection* connection) { |
| 32 | connection->AddService<TestService>(this); |
| 33 | connection->AddService<TestTimeService>(this); |
| 34 | return true; |
| 35 | } |
| 36 | |
| 37 | void TestServiceApplication::Create(ApplicationConnection* connection, |
| 38 | InterfaceRequest<TestService> request) { |
James Robinson | ab60bd3 | 2015-02-12 13:02:24 -0800 | [diff] [blame] | 39 | new TestServiceImpl(app_impl_, this, request.Pass()); |
James Robinson | 43fd683 | 2014-11-12 16:24:27 -0800 | [diff] [blame] | 40 | AddRef(); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void TestServiceApplication::Create(ApplicationConnection* connection, |
| 44 | InterfaceRequest<TestTimeService> request) { |
Geoffrey Gowan | 8e12b96 | 2015-02-09 16:45:05 -0800 | [diff] [blame] | 45 | new TestTimeServiceImpl(app_impl_, request.Pass()); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | void TestServiceApplication::AddRef() { |
| 49 | assert(ref_count_ >= 0); |
| 50 | ref_count_++; |
| 51 | } |
| 52 | |
| 53 | void TestServiceApplication::ReleaseRef() { |
| 54 | assert(ref_count_ > 0); |
| 55 | ref_count_--; |
| 56 | if (ref_count_ <= 0) |
| 57 | RunLoop::current()->Quit(); |
| 58 | } |
| 59 | |
| 60 | } // namespace test |
| 61 | } // namespace mojo |
| 62 | |
Mitch Rudominer | 963aa77 | 2015-04-03 08:22:46 -0700 | [diff] [blame] | 63 | MojoResult MojoMain(MojoHandle application_request) { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 64 | mojo::ApplicationRunner runner(new mojo::test::TestServiceApplication); |
Mitch Rudominer | 963aa77 | 2015-04-03 08:22:46 -0700 | [diff] [blame] | 65 | return runner.Run(application_request); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 66 | } |