blob: 5c3e9946e1e80ef28a2e2e329345974a90ecc3eb [file] [log] [blame]
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DEBUGD_SRC_SIMPLE_SERVICE_TOOL_H_
#define DEBUGD_SRC_SIMPLE_SERVICE_TOOL_H_
#include <memory>
#include <string>
#include <base/macros.h>
#include <base/memory/ref_counted.h>
#include <base/memory/weak_ptr.h>
#include <brillo/dbus/dbus_method_response.h>
#include <dbus/bus.h>
#include <dbus/object_proxy.h>
namespace debugd {
// Manages the vm_concierge service.
class SimpleServiceTool {
public:
explicit SimpleServiceTool(const std::string& name,
scoped_refptr<dbus::Bus> bus,
const std::string& dbus_service_name,
const std::string& dbus_service_path);
~SimpleServiceTool() = default;
void StartService(
std::unique_ptr<brillo::dbus_utils::DBusMethodResponse<bool>> response);
void StopService();
private:
// Called when the owner of the concierge service changes.
void HandleNameOwnerChanged(const std::string& old_owner,
const std::string& new_owner);
// Name of the service.
const std::string name_;
// Connection to the system bus.
scoped_refptr<dbus::Bus> bus_;
// Proxy to the service dbus remote object. Owned by |bus_|.
dbus::ObjectProxy* proxy_;
// Whether the concierge service is running.
bool running_;
base::WeakPtrFactory<SimpleServiceTool> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(SimpleServiceTool);
};
} // namespace debugd
#endif // DEBUGD_SRC_SIMPLE_SERVICE_TOOL_H_