blob: 734e16d678bc7658b27489bd706af2d6ce66a20b [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
Dmitry Torokhov93924ce2019-11-05 09:48:33 -08008#include <map>
Chirantan Ekbote47428f02018-02-02 17:56:57 -08009#include <memory>
10#include <string>
11
12#include <base/macros.h>
13#include <base/memory/ref_counted.h>
14#include <base/memory/weak_ptr.h>
15#include <brillo/dbus/dbus_method_response.h>
16#include <dbus/bus.h>
17#include <dbus/object_proxy.h>
18
19namespace debugd {
20
21// Manages the vm_concierge service.
Dmitry Torokhovaa485882018-10-19 13:26:06 -070022class SimpleServiceTool {
Chirantan Ekbote47428f02018-02-02 17:56:57 -080023 public:
Dmitry Torokhovaa485882018-10-19 13:26:06 -070024 explicit SimpleServiceTool(const std::string& name,
25 scoped_refptr<dbus::Bus> bus,
26 const std::string& dbus_service_name,
27 const std::string& dbus_service_path);
28 ~SimpleServiceTool() = default;
Chirantan Ekbote47428f02018-02-02 17:56:57 -080029
Dmitry Torokhovaa485882018-10-19 13:26:06 -070030 void StartService(
Dmitry Torokhov93924ce2019-11-05 09:48:33 -080031 std::map<std::string, std::string> args,
Chirantan Ekbote47428f02018-02-02 17:56:57 -080032 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse<bool>> response);
Dmitry Torokhovaa485882018-10-19 13:26:06 -070033 void StopService();
Chirantan Ekbote47428f02018-02-02 17:56:57 -080034
35 private:
36 // Called when the owner of the concierge service changes.
37 void HandleNameOwnerChanged(const std::string& old_owner,
38 const std::string& new_owner);
39
Dmitry Torokhovaa485882018-10-19 13:26:06 -070040 // Name of the service.
41 const std::string name_;
42
Chirantan Ekbote47428f02018-02-02 17:56:57 -080043 // Connection to the system bus.
44 scoped_refptr<dbus::Bus> bus_;
45
Dmitry Torokhovaa485882018-10-19 13:26:06 -070046 // Proxy to the service dbus remote object. Owned by |bus_|.
47 dbus::ObjectProxy* proxy_;
Chirantan Ekbote47428f02018-02-02 17:56:57 -080048
49 // Whether the concierge service is running.
50 bool running_;
51
Dmitry Torokhovaa485882018-10-19 13:26:06 -070052 base::WeakPtrFactory<SimpleServiceTool> weak_factory_{this};
53 DISALLOW_COPY_AND_ASSIGN(SimpleServiceTool);
Chirantan Ekbote47428f02018-02-02 17:56:57 -080054};
55
56} // namespace debugd
57
Dmitry Torokhovdcd630c2018-10-18 16:50:24 -070058#endif // DEBUGD_SRC_SIMPLE_SERVICE_TOOL_H_