Chirantan Ekbote | 47428f0 | 2018-02-02 17:56:57 -0800 | [diff] [blame] | 1 | // 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 Torokhov | dcd630c | 2018-10-18 16:50:24 -0700 | [diff] [blame] | 5 | #ifndef DEBUGD_SRC_SIMPLE_SERVICE_TOOL_H_ |
| 6 | #define DEBUGD_SRC_SIMPLE_SERVICE_TOOL_H_ |
Chirantan Ekbote | 47428f0 | 2018-02-02 17:56:57 -0800 | [diff] [blame] | 7 | |
| 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 | |
| 18 | namespace debugd { |
| 19 | |
| 20 | // Manages the vm_concierge service. |
Dmitry Torokhov | aa48588 | 2018-10-19 13:26:06 -0700 | [diff] [blame] | 21 | class SimpleServiceTool { |
Chirantan Ekbote | 47428f0 | 2018-02-02 17:56:57 -0800 | [diff] [blame] | 22 | public: |
Dmitry Torokhov | aa48588 | 2018-10-19 13:26:06 -0700 | [diff] [blame] | 23 | 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 Ekbote | 47428f0 | 2018-02-02 17:56:57 -0800 | [diff] [blame] | 28 | |
Dmitry Torokhov | aa48588 | 2018-10-19 13:26:06 -0700 | [diff] [blame] | 29 | void StartService( |
Chirantan Ekbote | 47428f0 | 2018-02-02 17:56:57 -0800 | [diff] [blame] | 30 | std::unique_ptr<brillo::dbus_utils::DBusMethodResponse<bool>> response); |
Dmitry Torokhov | aa48588 | 2018-10-19 13:26:06 -0700 | [diff] [blame] | 31 | void StopService(); |
Chirantan Ekbote | 47428f0 | 2018-02-02 17:56:57 -0800 | [diff] [blame] | 32 | |
| 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 Torokhov | aa48588 | 2018-10-19 13:26:06 -0700 | [diff] [blame] | 38 | // Name of the service. |
| 39 | const std::string name_; |
| 40 | |
Chirantan Ekbote | 47428f0 | 2018-02-02 17:56:57 -0800 | [diff] [blame] | 41 | // Connection to the system bus. |
| 42 | scoped_refptr<dbus::Bus> bus_; |
| 43 | |
Dmitry Torokhov | aa48588 | 2018-10-19 13:26:06 -0700 | [diff] [blame] | 44 | // Proxy to the service dbus remote object. Owned by |bus_|. |
| 45 | dbus::ObjectProxy* proxy_; |
Chirantan Ekbote | 47428f0 | 2018-02-02 17:56:57 -0800 | [diff] [blame] | 46 | |
| 47 | // Whether the concierge service is running. |
| 48 | bool running_; |
| 49 | |
Dmitry Torokhov | aa48588 | 2018-10-19 13:26:06 -0700 | [diff] [blame] | 50 | base::WeakPtrFactory<SimpleServiceTool> weak_factory_{this}; |
| 51 | DISALLOW_COPY_AND_ASSIGN(SimpleServiceTool); |
Chirantan Ekbote | 47428f0 | 2018-02-02 17:56:57 -0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | } // namespace debugd |
| 55 | |
Dmitry Torokhov | dcd630c | 2018-10-18 16:50:24 -0700 | [diff] [blame] | 56 | #endif // DEBUGD_SRC_SIMPLE_SERVICE_TOOL_H_ |