Vitaly Buka | 72410b2 | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 1 | // Copyright 2015 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_BASE_API_HANDLER_H_ |
| 6 | #define BUFFET_BASE_API_HANDLER_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
| 11 | #include <base/memory/weak_ptr.h> |
| 12 | |
| 13 | namespace buffet { |
| 14 | |
| 15 | class CommandInstance; |
| 16 | class CommandManager; |
| 17 | class DeviceRegistrationInfo; |
Vitaly Buka | 2f7efdb | 2015-05-27 16:00:21 -0700 | [diff] [blame] | 18 | class StateManager; |
Vitaly Buka | 72410b2 | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 19 | |
| 20 | // Handles commands from 'base' package. |
| 21 | // Objects of the class subscribe for notification from CommandManager and |
| 22 | // execute incoming commands. |
| 23 | // Handled commands: |
| 24 | // base.updateDeviceInfo |
Vitaly Buka | 2f7efdb | 2015-05-27 16:00:21 -0700 | [diff] [blame] | 25 | // base.updateBaseConfiguration |
Vitaly Buka | 72410b2 | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 26 | class BaseApiHandler final { |
| 27 | public: |
| 28 | BaseApiHandler(const base::WeakPtr<DeviceRegistrationInfo>& device_info, |
Vitaly Buka | 2f7efdb | 2015-05-27 16:00:21 -0700 | [diff] [blame] | 29 | const std::shared_ptr<StateManager>& state_manager, |
Vitaly Buka | 72410b2 | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 30 | const std::shared_ptr<CommandManager>& command_manager); |
| 31 | |
| 32 | private: |
| 33 | void OnCommandAdded(CommandInstance* command); |
Vitaly Buka | 2f7efdb | 2015-05-27 16:00:21 -0700 | [diff] [blame] | 34 | void UpdateBaseConfiguration(CommandInstance* command); |
Vitaly Buka | 72410b2 | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 35 | void UpdateDeviceInfo(CommandInstance* command); |
| 36 | |
| 37 | base::WeakPtr<DeviceRegistrationInfo> device_info_; |
Vitaly Buka | 2f7efdb | 2015-05-27 16:00:21 -0700 | [diff] [blame] | 38 | std::shared_ptr<StateManager> state_manager_; |
Vitaly Buka | 72410b2 | 2015-05-13 13:48:59 -0700 | [diff] [blame] | 39 | |
| 40 | base::WeakPtrFactory<BaseApiHandler> weak_ptr_factory_{this}; |
| 41 | DISALLOW_COPY_AND_ASSIGN(BaseApiHandler); |
| 42 | }; |
| 43 | |
| 44 | } // namespace buffet |
| 45 | |
| 46 | #endif // BUFFET_BASE_API_HANDLER_H_ |