blob: a56b6c3c51fffc661255a2f19cdbce116806dfa1 [file] [log] [blame]
Christopher Wileya4915c42014-03-27 14:45:37 -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_MANAGER_H_
6#define BUFFET_MANAGER_H_
7
Alex Vakulenkof2784de2014-08-15 11:49:35 -07008#include <map>
Alex Vakulenko33797062014-05-12 15:55:25 -07009#include <memory>
10#include <string>
11
Alex Vakulenko132617a2014-09-04 08:59:43 -070012#include <base/macros.h>
Christopher Wileyadb901d2014-05-07 09:58:45 -070013#include <base/memory/weak_ptr.h>
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070014#include <base/values.h>
Alex Vakulenko07216fe2014-09-19 15:31:09 -070015#include <chromeos/dbus/data_serialization.h>
Alex Vakulenkof2784de2014-08-15 11:49:35 -070016#include <chromeos/dbus/dbus_object.h>
Alex Vakulenkoa8b95bc2014-08-27 11:00:57 -070017#include <chromeos/dbus/exported_property_set.h>
18#include <chromeos/errors/error.h>
Christopher Wileya4915c42014-03-27 14:45:37 -070019
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070020#include "buffet/device_registration_info.h"
Christopher Wileyaa3f29c2014-03-27 14:51:26 -070021
Christopher Wileyb5dd5ea2014-08-11 10:51:20 -070022namespace chromeos {
Christopher Wileyadb901d2014-05-07 09:58:45 -070023namespace dbus_utils {
24class ExportedObjectManager;
25} // namespace dbus_utils
Christopher Wileyb5dd5ea2014-08-11 10:51:20 -070026} // namespace chromeos
27
28namespace buffet {
29
30class CommandManager;
Alex Vakulenko07216fe2014-09-19 15:31:09 -070031class StateManager;
Christopher Wileya4915c42014-03-27 14:45:37 -070032
33// The Manager is responsible for global state of Buffet. It exposes
34// interfaces which affect the entire device such as device registration and
35// device state.
Alex Vakulenkof2784de2014-08-15 11:49:35 -070036class Manager final {
Christopher Wileya4915c42014-03-27 14:45:37 -070037 public:
Alex Vakulenkof2784de2014-08-15 11:49:35 -070038 explicit Manager(
39 const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>&
40 object_manager);
Alex Vakulenkobe9c3832014-08-24 15:05:06 -070041 void RegisterAsync(
Alex Vakulenkof2784de2014-08-15 11:49:35 -070042 const chromeos::dbus_utils::AsyncEventSequencer::CompletionAction& cb);
Christopher Wileya4915c42014-03-27 14:45:37 -070043
44 private:
Alex Vakulenkof2784de2014-08-15 11:49:35 -070045 // DBus methods:
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070046 // Handles calls to org.chromium.Buffet.Manager.CheckDeviceRegistered().
Alex Vakulenkof2784de2014-08-15 11:49:35 -070047 std::string HandleCheckDeviceRegistered(chromeos::ErrorPtr* error);
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070048 // Handles calls to org.chromium.Buffet.Manager.GetDeviceInfo().
Alex Vakulenkof2784de2014-08-15 11:49:35 -070049 std::string HandleGetDeviceInfo(chromeos::ErrorPtr* error);
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070050 // Handles calls to org.chromium.Buffet.Manager.StartRegisterDevice().
Alex Vakulenkof2784de2014-08-15 11:49:35 -070051 std::string HandleStartRegisterDevice(chromeos::ErrorPtr* error,
52 const std::map<std::string,
Alex Vakulenkoa9044342014-08-23 19:31:27 -070053 std::string>& params);
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070054 // Handles calls to org.chromium.Buffet.Manager.FinishRegisterDevice().
Alex Vakulenkof2784de2014-08-15 11:49:35 -070055 std::string HandleFinishRegisterDevice(chromeos::ErrorPtr* error,
56 const std::string& user_auth_code);
Christopher Wileya4915c42014-03-27 14:45:37 -070057 // Handles calls to org.chromium.Buffet.Manager.UpdateState().
Alex Vakulenkof2784de2014-08-15 11:49:35 -070058 void HandleUpdateState(chromeos::ErrorPtr* error,
Alex Vakulenko576c9792014-09-22 16:49:45 -070059 const chromeos::VariantDictionary& property_set);
Alex Vakulenko665c8852014-09-11 16:57:24 -070060 // Handles calls to org.chromium.Buffet.Manager.AddCommand().
61 void HandleAddCommand(chromeos::ErrorPtr* error,
62 const std::string& json_command);
Christopher Wileyb76eb292014-05-05 16:09:16 -070063 // Handles calls to org.chromium.Buffet.Manager.Test()
Alex Vakulenko7a1dc0b2014-08-15 11:45:46 -070064 std::string HandleTestMethod(chromeos::ErrorPtr* error,
65 const std::string& message);
Christopher Wileya4915c42014-03-27 14:45:37 -070066
Alex Vakulenkof2784de2014-08-15 11:49:35 -070067 chromeos::dbus_utils::DBusObject dbus_object_;
Christopher Wileya4915c42014-03-27 14:45:37 -070068
Alex Vakulenkoc2bc9a42014-07-23 10:57:58 -070069 std::shared_ptr<CommandManager> command_manager_;
Alex Vakulenko07216fe2014-09-19 15:31:09 -070070 std::shared_ptr<StateManager> state_manager_;
Alex Vakulenko1f30a622014-07-23 11:13:15 -070071 std::unique_ptr<DeviceRegistrationInfo> device_info_;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070072
Christopher Wileya4915c42014-03-27 14:45:37 -070073 DISALLOW_COPY_AND_ASSIGN(Manager);
74};
75
76} // namespace buffet
77
78#endif // BUFFET_MANAGER_H_