1//
2// Copyright (C) 2015 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17#ifndef APMANAGER_DBUS_SERVICE_DBUS_ADAPTOR_H_
18#define APMANAGER_DBUS_SERVICE_DBUS_ADAPTOR_H_
19
20#include <base/macros.h>
21
22#include <dbus_bindings/org.chromium.apmanager.Service.h>
23
24#include "apmanager/error.h"
25#include "apmanager/service_adaptor_interface.h"
26
27namespace apmanager {
28
29class Service;
30
31class ServiceDBusAdaptor : public org::chromium::apmanager::ServiceInterface,
32                           public ServiceAdaptorInterface {
33 public:
34  ServiceDBusAdaptor(const scoped_refptr<dbus::Bus>& bus,
35                     brillo::dbus_utils::ExportedObjectManager* object_manager,
36                     Service* service);
37  ~ServiceDBusAdaptor() override;
38
39  // Implementation of org::chromium::apmanager::ServiceInterface
40  void Start(
41      std::unique_ptr<brillo::dbus_utils::DBusMethodResponse<>>
42          response) override;
43  bool Stop(brillo::ErrorPtr* dbus_error) override;
44
45  // Implementation of ServiceAdaptorInterface.
46  RPCObjectIdentifier GetRpcObjectIdentifier() override;
47  void SetConfig(Config* config) override;
48  void SetState(const std::string& state) override;
49
50 private:
51  void OnStartCompleted(
52      std::unique_ptr<brillo::dbus_utils::DBusMethodResponse<>> response,
53      const Error& error);
54
55  org::chromium::apmanager::ServiceAdaptor adaptor_;
56  dbus::ObjectPath object_path_;
57  brillo::dbus_utils::DBusObject dbus_object_;
58  Service* service_;
59
60  DISALLOW_COPY_AND_ASSIGN(ServiceDBusAdaptor);
61};
62
63}  // namespace apmanager
64
65#endif  // APMANAGER_DBUS_SERVICE_DBUS_ADAPTOR_H_
66