Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 1 | // 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 Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 13 | |
| 14 | namespace chromeos { |
| 15 | namespace dbus_utils { |
| 16 | class ExportedObjectManager; |
| 17 | } // namespace dbus_utils |
| 18 | } // namespace chromeos |
| 19 | |
| 20 | namespace buffet { |
| 21 | |
Vitaly Buka | ae0f3a1 | 2015-05-11 16:27:30 -0700 | [diff] [blame] | 22 | class 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 Vakulenko | 534a312 | 2015-05-22 15:48:53 -0700 | [diff] [blame] | 31 | class DBusCommandDispacher final { |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 32 | public: |
Vitaly Buka | ae0f3a1 | 2015-05-11 16:27:30 -0700 | [diff] [blame] | 33 | explicit DBusCommandDispacher(const base::WeakPtr< |
| 34 | chromeos::dbus_utils::ExportedObjectManager>& object_manager); |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 35 | |
Vitaly Buka | ae0f3a1 | 2015-05-11 16:27:30 -0700 | [diff] [blame] | 36 | void OnCommandAdded(CommandInstance* command_instance); |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 37 | |
| 38 | private: |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 39 | base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager> object_manager_; |
Vitaly Buka | ae0f3a1 | 2015-05-11 16:27:30 -0700 | [diff] [blame] | 40 | int next_id_{0}; |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 41 | |
| 42 | // Default constructor is used in special circumstances such as for testing. |
| 43 | DBusCommandDispacher() = default; |
| 44 | |
Alex Vakulenko | 9511075 | 2014-09-03 16:27:21 -0700 | [diff] [blame] | 45 | friend class CommandManager; |
| 46 | DISALLOW_COPY_AND_ASSIGN(DBusCommandDispacher); |
| 47 | }; |
| 48 | |
| 49 | } // namespace buffet |
| 50 | |
| 51 | #endif // BUFFET_COMMANDS_DBUS_COMMAND_DISPATCHER_H_ |