blob: 35e6e2547b440d3b335bf00a7898fa0edb0c61d7 [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>
Alex Vakulenkoe03af6d2015-04-20 11:00:54 -070011#include <vector>
Alex Vakulenko33797062014-05-12 15:55:25 -070012
Christopher Wileye0fdeee2015-02-07 18:29:32 -080013#include <base/files/file_path.h>
Alex Vakulenko132617a2014-09-04 08:59:43 -070014#include <base/macros.h>
Christopher Wileyadb901d2014-05-07 09:58:45 -070015#include <base/memory/weak_ptr.h>
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070016#include <base/values.h>
Alex Vakulenko07216fe2014-09-19 15:31:09 -070017#include <chromeos/dbus/data_serialization.h>
Alex Vakulenkof2784de2014-08-15 11:49:35 -070018#include <chromeos/dbus/dbus_object.h>
Alex Vakulenkoa8b95bc2014-08-27 11:00:57 -070019#include <chromeos/dbus/exported_property_set.h>
20#include <chromeos/errors/error.h>
Christopher Wileya4915c42014-03-27 14:45:37 -070021
Alex Vakulenko9ea5a322015-04-17 15:35:34 -070022#include "buffet/commands/command_manager.h"
Alex Vakulenko3cb466c2014-04-15 11:36:32 -070023#include "buffet/device_registration_info.h"
Alex Vakulenko2348e422014-11-21 08:57:57 -080024#include "buffet/org.chromium.Buffet.Manager.h"
Christopher Wileyaa3f29c2014-03-27 14:51:26 -070025
Christopher Wileyb5dd5ea2014-08-11 10:51:20 -070026namespace chromeos {
Christopher Wileyadb901d2014-05-07 09:58:45 -070027namespace dbus_utils {
28class ExportedObjectManager;
29} // namespace dbus_utils
Christopher Wileyb5dd5ea2014-08-11 10:51:20 -070030} // namespace chromeos
31
32namespace buffet {
33
Vitaly Buka72410b22015-05-13 13:48:59 -070034class BaseApiHandler;
35class BuffetConfig;
Alex Vakulenko57123b22014-10-28 13:50:16 -070036class StateChangeQueue;
Alex Vakulenko07216fe2014-09-19 15:31:09 -070037class StateManager;
Christopher Wileya4915c42014-03-27 14:45:37 -070038
Alex Vakulenko2348e422014-11-21 08:57:57 -080039template<typename... Types>
40using DBusMethodResponse =
Alex Vakulenko41f73a92015-04-24 18:09:32 -070041 std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<Types...>>;
Alex Vakulenko2348e422014-11-21 08:57:57 -080042
Christopher Wileya4915c42014-03-27 14:45:37 -070043// The Manager is responsible for global state of Buffet. It exposes
44// interfaces which affect the entire device such as device registration and
45// device state.
Alex Vakulenko2348e422014-11-21 08:57:57 -080046class Manager final : public org::chromium::Buffet::ManagerInterface {
Christopher Wileya4915c42014-03-27 14:45:37 -070047 public:
Alex Vakulenkof2784de2014-08-15 11:49:35 -070048 explicit Manager(
49 const base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager>&
50 object_manager);
Alex Vakulenko57123b22014-10-28 13:50:16 -070051 ~Manager();
52
Vitaly Buka76e70592015-04-16 11:39:02 -070053 void Start(
Christopher Wileye0fdeee2015-02-07 18:29:32 -080054 const base::FilePath& config_path,
55 const base::FilePath& state_path,
Christopher Wileybb5b8482015-02-12 13:42:16 -080056 const base::FilePath& test_definitions_path,
Christopher Wileyd732bd02015-04-07 11:11:18 -070057 bool xmpp_enabled,
Alex Vakulenkof2784de2014-08-15 11:49:35 -070058 const chromeos::dbus_utils::AsyncEventSequencer::CompletionAction& cb);
Christopher Wileya4915c42014-03-27 14:45:37 -070059
60 private:
Alex Vakulenkof2784de2014-08-15 11:49:35 -070061 // DBus methods:
Alex Vakulenko2348e422014-11-21 08:57:57 -080062 void CheckDeviceRegistered(DBusMethodResponse<std::string> response) override;
Alex Vakulenko2348e422014-11-21 08:57:57 -080063 void GetDeviceInfo(DBusMethodResponse<std::string> response) override;
Alex Vakulenko2348e422014-11-21 08:57:57 -080064 void RegisterDevice(DBusMethodResponse<std::string> response,
Vitaly Bukacad2e332015-05-14 23:33:32 -070065 const std::string& ticket_id) override;
Vitaly Bukafa947062015-04-17 00:41:31 -070066 bool UpdateDeviceInfo(chromeos::ErrorPtr* error,
67 const std::string& in_name,
68 const std::string& in_description,
69 const std::string& in_location) override;
Vitaly Bukaff81db62015-05-14 21:25:45 -070070 bool UpdateServiceConfig(chromeos::ErrorPtr* error,
71 const std::string& client_id,
72 const std::string& client_secret,
73 const std::string& api_key,
74 const std::string& oauth_url,
75 const std::string& service_url) override;
Alex Vakulenko2348e422014-11-21 08:57:57 -080076 void UpdateState(DBusMethodResponse<> response,
77 const chromeos::VariantDictionary& property_set) override;
Alex Vakulenko61ad4db2015-01-20 10:50:04 -080078 bool GetState(chromeos::ErrorPtr* error, std::string* state) override;
Vitaly Buka64fc5fc2015-03-24 12:42:24 -070079 void AddCommand(DBusMethodResponse<std::string> response,
Vitaly Bukab2098422015-05-31 23:32:46 -070080 const std::string& json_command,
81 const std::string& in_user_role) override;
Vitaly Buka3886e8f2015-03-24 11:39:40 -070082 void GetCommand(DBusMethodResponse<std::string> response,
83 const std::string& id) override;
Alex Vakulenkoe03af6d2015-04-20 11:00:54 -070084 void SetCommandVisibility(
Alex Vakulenko41f73a92015-04-24 18:09:32 -070085 std::unique_ptr<chromeos::dbus_utils::DBusMethodResponse<>> response,
Alex Vakulenkoe03af6d2015-04-20 11:00:54 -070086 const std::vector<std::string>& in_names,
87 const std::string& in_visibility) override;
Alex Vakulenko2348e422014-11-21 08:57:57 -080088 std::string TestMethod(const std::string& message) override;
Christopher Wileya4915c42014-03-27 14:45:37 -070089
Vitaly Bukaaabadee2015-03-18 23:33:44 -070090 void OnCommandDefsChanged();
Vitaly Bukadbb8c352015-05-27 09:27:08 -070091 void OnStateChanged();
Vitaly Bukaee7a3af2015-05-14 16:57:23 -070092 void OnRegistrationChanged(RegistrationStatus status);
93 void OnConfigChanged(const BuffetConfig& config);
Christopher Wileyc900e482015-02-15 15:42:04 -080094
Alex Vakulenko2348e422014-11-21 08:57:57 -080095 org::chromium::Buffet::ManagerAdaptor dbus_adaptor_{this};
Alex Vakulenkof2784de2014-08-15 11:49:35 -070096 chromeos::dbus_utils::DBusObject dbus_object_;
Christopher Wileya4915c42014-03-27 14:45:37 -070097
Alex Vakulenkoc2bc9a42014-07-23 10:57:58 -070098 std::shared_ptr<CommandManager> command_manager_;
Alex Vakulenko57123b22014-10-28 13:50:16 -070099 std::unique_ptr<StateChangeQueue> state_change_queue_;
Alex Vakulenko07216fe2014-09-19 15:31:09 -0700100 std::shared_ptr<StateManager> state_manager_;
Alex Vakulenko1f30a622014-07-23 11:13:15 -0700101 std::unique_ptr<DeviceRegistrationInfo> device_info_;
Vitaly Buka72410b22015-05-13 13:48:59 -0700102 std::unique_ptr<BaseApiHandler> base_api_handler_;
Alex Vakulenko3cb466c2014-04-15 11:36:32 -0700103
Vitaly Buka5e6ff6c2015-05-11 15:41:33 -0700104 base::WeakPtrFactory<Manager> weak_ptr_factory_{this};
Christopher Wileya4915c42014-03-27 14:45:37 -0700105 DISALLOW_COPY_AND_ASSIGN(Manager);
106};
107
108} // namespace buffet
109
110#endif // BUFFET_MANAGER_H_