OLD | NEW |
| (Empty) |
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 | |
5 #include "mojo/services/test_service/test_service_application.h" | |
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" | |
13 #include "mojo/services/test_service/test_service_impl.h" | |
14 #include "mojo/services/test_service/test_time_service_impl.h" | |
15 | |
16 namespace mojo { | |
17 namespace test { | |
18 | |
19 TestServiceApplication::TestServiceApplication() : ref_count_(0) { | |
20 } | |
21 | |
22 TestServiceApplication::~TestServiceApplication() { | |
23 } | |
24 | |
25 bool TestServiceApplication::ConfigureIncomingConnection( | |
26 ApplicationConnection* connection) { | |
27 connection->AddService<TestService>(this); | |
28 connection->AddService<TestTimeService>(this); | |
29 return true; | |
30 } | |
31 | |
32 void TestServiceApplication::Create(ApplicationConnection* connection, | |
33 InterfaceRequest<TestService> request) { | |
34 BindToRequest(new TestServiceImpl(connection, this), &request); | |
35 AddRef(); | |
36 } | |
37 | |
38 void TestServiceApplication::Create(ApplicationConnection* connection, | |
39 InterfaceRequest<TestTimeService> request) { | |
40 new TestTimeServiceImpl(connection, request.Pass()); | |
41 } | |
42 | |
43 void TestServiceApplication::AddRef() { | |
44 assert(ref_count_ >= 0); | |
45 ref_count_++; | |
46 } | |
47 | |
48 void TestServiceApplication::ReleaseRef() { | |
49 assert(ref_count_ > 0); | |
50 ref_count_--; | |
51 if (ref_count_ <= 0) | |
52 RunLoop::current()->Quit(); | |
53 } | |
54 | |
55 } // namespace test | |
56 } // namespace mojo | |
57 | |
58 MojoResult MojoMain(MojoHandle shell_handle) { | |
59 mojo::ApplicationRunner runner(new mojo::test::TestServiceApplication); | |
60 return runner.Run(shell_handle); | |
61 } | |
OLD | NEW |