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