blob: e9f5003c1da3502be4e14a91d239cebd34dbb656 [file] [log] [blame]
Alex Vakulenko95110752014-09-03 16:27:21 -07001// Copyright 2014 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
5#ifndef BUFFET_COMMANDS_DBUS_COMMAND_DISPATCHER_H_
6#define BUFFET_COMMANDS_DBUS_COMMAND_DISPATCHER_H_
7
8#include <map>
9#include <string>
10
11#include <base/macros.h>
12#include <base/memory/weak_ptr.h>
Alex Vakulenko95110752014-09-03 16:27:21 -070013
14namespace chromeos {
15namespace dbus_utils {
16class ExportedObjectManager;
17} // namespace dbus_utils
18} // namespace chromeos
19
20namespace buffet {
21
Vitaly Bukaae0f3a12015-05-11 16:27:30 -070022class CommandInstance;
23
24// Implements D-Bus dispatch of commands. When OnCommandAdded is called,
25// DBusCommandDispacher creates an instance of DBusCommandProxy object and
26// advertises it through ExportedObjectManager on D-Bus. Command handling
27// processes can watch the new D-Bus object appear and communicate with it to
28// update the command handling progress. Once command is handled,
29// DBusCommandProxy::Done() is called and the command is removed from the
30// command queue and D-Bus ExportedObjectManager.
Alex Vakulenko534a3122015-05-22 15:48:53 -070031class DBusCommandDispacher final {
Alex Vakulenko95110752014-09-03 16:27:21 -070032 public:
Vitaly Bukaae0f3a12015-05-11 16:27:30 -070033 explicit DBusCommandDispacher(const base::WeakPtr<
34 chromeos::dbus_utils::ExportedObjectManager>& object_manager);
Alex Vakulenko95110752014-09-03 16:27:21 -070035
Vitaly Bukaae0f3a12015-05-11 16:27:30 -070036 void OnCommandAdded(CommandInstance* command_instance);
Alex Vakulenko95110752014-09-03 16:27:21 -070037
38 private:
Alex Vakulenko95110752014-09-03 16:27:21 -070039 base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager> object_manager_;
Vitaly Bukaae0f3a12015-05-11 16:27:30 -070040 int next_id_{0};
Alex Vakulenko95110752014-09-03 16:27:21 -070041
42 // Default constructor is used in special circumstances such as for testing.
43 DBusCommandDispacher() = default;
44
Alex Vakulenko95110752014-09-03 16:27:21 -070045 friend class CommandManager;
46 DISALLOW_COPY_AND_ASSIGN(DBusCommandDispacher);
47};
48
49} // namespace buffet
50
51#endif // BUFFET_COMMANDS_DBUS_COMMAND_DISPATCHER_H_