blob: 5c3e9946e1e80ef28a2e2e329345974a90ecc3eb [file] [log] [blame]
Chirantan Ekbote47428f02018-02-02 17:56:57 -08001// Copyright 2018 The Chromium OS 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
Dmitry Torokhovdcd630c2018-10-18 16:50:24 -07005#ifndef DEBUGD_SRC_SIMPLE_SERVICE_TOOL_H_
6#define DEBUGD_SRC_SIMPLE_SERVICE_TOOL_H_
Chirantan Ekbote47428f02018-02-02 17:56:57 -08007
8#include <memory>
9#include <string>
10
11#include <base/macros.h>
12#include <base/memory/ref_counted.h>
13#include <base/memory/weak_ptr.h>
14#include <brillo/dbus/dbus_method_response.h>
15#include <dbus/bus.h>
16#include <dbus/object_proxy.h>
17
18namespace debugd {
19
20// Manages the vm_concierge service.
Dmitry Torokhovaa485882018-10-19 13:26:06 -070021class SimpleServiceTool {
Chirantan Ekbote47428f02018-02-02 17:56:57 -080022 public:
Dmitry Torokhovaa485882018-10-19 13:26:06 -070023 explicit SimpleServiceTool(const std::string& name,
24 scoped_refptr<dbus::Bus> bus,
25 const std::string& dbus_service_name,
26 const std::string& dbus_service_path);
27 ~SimpleServiceTool() = default;
Chirantan Ekbote47428f02018-02-02 17:56:57 -080028
Dmitry Torokhovaa485882018-10-19 13:26:06 -070029 void StartService(
Chirantan Ekbote47428f02018-02-02 17:56:57 -080030 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse<bool>> response);
Dmitry Torokhovaa485882018-10-19 13:26:06 -070031 void StopService();
Chirantan Ekbote47428f02018-02-02 17:56:57 -080032
33 private:
34 // Called when the owner of the concierge service changes.
35 void HandleNameOwnerChanged(const std::string& old_owner,
36 const std::string& new_owner);
37
Dmitry Torokhovaa485882018-10-19 13:26:06 -070038 // Name of the service.
39 const std::string name_;
40
Chirantan Ekbote47428f02018-02-02 17:56:57 -080041 // Connection to the system bus.
42 scoped_refptr<dbus::Bus> bus_;
43
Dmitry Torokhovaa485882018-10-19 13:26:06 -070044 // Proxy to the service dbus remote object. Owned by |bus_|.
45 dbus::ObjectProxy* proxy_;
Chirantan Ekbote47428f02018-02-02 17:56:57 -080046
47 // Whether the concierge service is running.
48 bool running_;
49
Dmitry Torokhovaa485882018-10-19 13:26:06 -070050 base::WeakPtrFactory<SimpleServiceTool> weak_factory_{this};
51 DISALLOW_COPY_AND_ASSIGN(SimpleServiceTool);
Chirantan Ekbote47428f02018-02-02 17:56:57 -080052};
53
54} // namespace debugd
55
Dmitry Torokhovdcd630c2018-10-18 16:50:24 -070056#endif // DEBUGD_SRC_SIMPLE_SERVICE_TOOL_H_