blob: f168cb68365232efca41c79f2fc63a5286b259c5 [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// 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 Robinson63b637a2014-12-03 14:46:39 -08005#include "services/test_service/test_service_application.h"
James Robinson646469d2014-10-03 15:33:28 -07006
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 Robinson63b637a2014-12-03 14:46:39 -080013#include "services/test_service/test_service_impl.h"
14#include "services/test_service/test_time_service_impl.h"
James Robinson646469d2014-10-03 15:33:28 -070015
16namespace mojo {
17namespace test {
18
Geoffrey Gowan8e12b962015-02-09 16:45:05 -080019TestServiceApplication::TestServiceApplication()
20 : ref_count_(0), app_impl_(nullptr) {
James Robinson646469d2014-10-03 15:33:28 -070021}
22
23TestServiceApplication::~TestServiceApplication() {
24}
25
Geoffrey Gowan8e12b962015-02-09 16:45:05 -080026void TestServiceApplication::Initialize(ApplicationImpl* app) {
27 app_impl_ = app;
28}
29
James Robinson646469d2014-10-03 15:33:28 -070030bool TestServiceApplication::ConfigureIncomingConnection(
31 ApplicationConnection* connection) {
32 connection->AddService<TestService>(this);
33 connection->AddService<TestTimeService>(this);
34 return true;
35}
36
37void TestServiceApplication::Create(ApplicationConnection* connection,
38 InterfaceRequest<TestService> request) {
James Robinsonab60bd32015-02-12 13:02:24 -080039 new TestServiceImpl(app_impl_, this, request.Pass());
James Robinson43fd6832014-11-12 16:24:27 -080040 AddRef();
James Robinson646469d2014-10-03 15:33:28 -070041}
42
43void TestServiceApplication::Create(ApplicationConnection* connection,
44 InterfaceRequest<TestTimeService> request) {
Geoffrey Gowan8e12b962015-02-09 16:45:05 -080045 new TestTimeServiceImpl(app_impl_, request.Pass());
James Robinson646469d2014-10-03 15:33:28 -070046}
47
48void TestServiceApplication::AddRef() {
49 assert(ref_count_ >= 0);
50 ref_count_++;
51}
52
53void 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 Rudominer963aa772015-04-03 08:22:46 -070063MojoResult MojoMain(MojoHandle application_request) {
James Robinson646469d2014-10-03 15:33:28 -070064 mojo::ApplicationRunner runner(new mojo::test::TestServiceApplication);
Mitch Rudominer963aa772015-04-03 08:22:46 -070065 return runner.Run(application_request);
James Robinson646469d2014-10-03 15:33:28 -070066}