Vitaly Buka | 4615e0d | 2015-10-14 15:35:12 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Weave Authors. All rights reserved. |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Vitaly Buka | 912b698 | 2015-07-06 11:13:03 -0700 | [diff] [blame] | 5 | #ifndef LIBWEAVE_SRC_PRIVET_CLOUD_DELEGATE_H_ |
| 6 | #define LIBWEAVE_SRC_PRIVET_CLOUD_DELEGATE_H_ |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 7 | |
| 8 | #include <memory> |
| 9 | #include <set> |
| 10 | #include <string> |
| 11 | |
| 12 | #include <base/callback.h> |
| 13 | #include <base/memory/ref_counted.h> |
| 14 | #include <base/observer_list.h> |
| 15 | |
Stefan Sauer | 2d16dfa | 2015-09-25 17:08:35 +0200 | [diff] [blame] | 16 | #include "src/privet/privet_types.h" |
| 17 | #include "src/privet/security_delegate.h" |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 18 | |
| 19 | namespace base { |
| 20 | class DictionaryValue; |
| 21 | } // namespace base |
| 22 | |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 23 | namespace weave { |
| 24 | |
Vitaly Buka | 7ab89ff | 2015-06-09 22:11:40 -0700 | [diff] [blame] | 25 | class CommandManager; |
| 26 | class DeviceRegistrationInfo; |
| 27 | class StateManager; |
Vitaly Buka | 1e36367 | 2015-09-25 14:01:16 -0700 | [diff] [blame] | 28 | |
| 29 | namespace provider { |
Vitaly Buka | 823fdda | 2015-08-13 00:33:00 -0700 | [diff] [blame] | 30 | class TaskRunner; |
Vitaly Buka | 1e36367 | 2015-09-25 14:01:16 -0700 | [diff] [blame] | 31 | } |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 32 | |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 33 | namespace privet { |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 34 | |
| 35 | // Interface to provide GCD functionality for PrivetHandler. |
| 36 | // TODO(vitalybuka): Rename to BuffetDelegate. |
| 37 | class CloudDelegate { |
| 38 | public: |
| 39 | CloudDelegate(); |
| 40 | virtual ~CloudDelegate(); |
| 41 | |
Vitaly Buka | 7476342 | 2015-10-11 00:39:52 -0700 | [diff] [blame] | 42 | using CommandDoneCallback = |
| 43 | base::Callback<void(const base::DictionaryValue& commands, |
| 44 | ErrorPtr error)>; |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 45 | |
| 46 | class Observer { |
| 47 | public: |
| 48 | virtual ~Observer() = default; |
| 49 | |
| 50 | virtual void OnDeviceInfoChanged() {} |
| 51 | virtual void OnCommandDefsChanged() {} |
| 52 | virtual void OnStateChanged() {} |
| 53 | }; |
| 54 | |
Johan Euphrosine | 0b7bb9f | 2015-09-29 01:11:21 -0700 | [diff] [blame] | 55 | // Returns the ID of the device. |
| 56 | virtual std::string GetDeviceId() const = 0; |
| 57 | |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 58 | // Returns the model ID of the device. |
Vitaly Buka | 658aa36 | 2015-09-15 20:59:12 -0700 | [diff] [blame] | 59 | virtual std::string GetModelId() const = 0; |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 60 | |
| 61 | // Returns the name of device. |
Vitaly Buka | 658aa36 | 2015-09-15 20:59:12 -0700 | [diff] [blame] | 62 | virtual std::string GetName() const = 0; |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 63 | |
| 64 | // Returns the description of the device. |
| 65 | virtual std::string GetDescription() const = 0; |
| 66 | |
| 67 | // Returns the location of the device. |
| 68 | virtual std::string GetLocation() const = 0; |
| 69 | |
| 70 | // Update basic device information. |
| 71 | virtual void UpdateDeviceInfo(const std::string& name, |
| 72 | const std::string& description, |
Vitaly Buka | b624bc4 | 2015-09-29 19:13:55 -0700 | [diff] [blame] | 73 | const std::string& location) = 0; |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 74 | |
| 75 | // Returns the name of the maker. |
| 76 | virtual std::string GetOemName() const = 0; |
| 77 | |
| 78 | // Returns the model name of the device. |
| 79 | virtual std::string GetModelName() const = 0; |
| 80 | |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 81 | // Returns max scope available for anonymous user. |
| 82 | virtual AuthScope GetAnonymousMaxScope() const = 0; |
| 83 | |
| 84 | // Returns status of the GCD connection. |
| 85 | virtual const ConnectionState& GetConnectionState() const = 0; |
| 86 | |
| 87 | // Returns status of the last setup. |
| 88 | virtual const SetupState& GetSetupState() const = 0; |
| 89 | |
| 90 | // Starts GCD setup. |
| 91 | virtual bool Setup(const std::string& ticket_id, |
| 92 | const std::string& user, |
Vitaly Buka | 0801a1f | 2015-08-14 10:03:46 -0700 | [diff] [blame] | 93 | ErrorPtr* error) = 0; |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 94 | |
| 95 | // Returns cloud id if the registered device or empty string if unregistered. |
| 96 | virtual std::string GetCloudId() const = 0; |
| 97 | |
| 98 | // Returns dictionary with device state. |
| 99 | virtual const base::DictionaryValue& GetState() const = 0; |
| 100 | |
| 101 | // Returns dictionary with commands definitions. |
| 102 | virtual const base::DictionaryValue& GetCommandDef() const = 0; |
| 103 | |
| 104 | // Adds command created from the given JSON representation. |
| 105 | virtual void AddCommand(const base::DictionaryValue& command, |
| 106 | const UserInfo& user_info, |
Vitaly Buka | 7476342 | 2015-10-11 00:39:52 -0700 | [diff] [blame] | 107 | const CommandDoneCallback& callback) = 0; |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 108 | |
| 109 | // Returns command with the given ID. |
| 110 | virtual void GetCommand(const std::string& id, |
| 111 | const UserInfo& user_info, |
Vitaly Buka | 7476342 | 2015-10-11 00:39:52 -0700 | [diff] [blame] | 112 | const CommandDoneCallback& callback) = 0; |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 113 | |
| 114 | // Cancels command with the given ID. |
| 115 | virtual void CancelCommand(const std::string& id, |
| 116 | const UserInfo& user_info, |
Vitaly Buka | 7476342 | 2015-10-11 00:39:52 -0700 | [diff] [blame] | 117 | const CommandDoneCallback& callback) = 0; |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 118 | |
| 119 | // Lists commands. |
| 120 | virtual void ListCommands(const UserInfo& user_info, |
Vitaly Buka | 7476342 | 2015-10-11 00:39:52 -0700 | [diff] [blame] | 121 | const CommandDoneCallback& callback) = 0; |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 122 | |
| 123 | void AddObserver(Observer* observer) { observer_list_.AddObserver(observer); } |
| 124 | void RemoveObserver(Observer* observer) { |
| 125 | observer_list_.RemoveObserver(observer); |
| 126 | } |
| 127 | |
| 128 | void NotifyOnDeviceInfoChanged(); |
| 129 | void NotifyOnCommandDefsChanged(); |
| 130 | void NotifyOnStateChanged(); |
| 131 | |
| 132 | // Create default instance. |
| 133 | static std::unique_ptr<CloudDelegate> CreateDefault( |
Vitaly Buka | 1e36367 | 2015-09-25 14:01:16 -0700 | [diff] [blame] | 134 | provider::TaskRunner* task_runner, |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 135 | DeviceRegistrationInfo* device, |
| 136 | CommandManager* command_manager, |
| 137 | StateManager* state_manager); |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 138 | |
| 139 | private: |
Alex Vakulenko | ae1ffbc | 2015-06-15 12:53:22 -0700 | [diff] [blame] | 140 | base::ObserverList<Observer> observer_list_; |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
Vitaly Buka | b6f015a | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 143 | } // namespace privet |
| 144 | } // namespace weave |
Vitaly Buka | 7ce499f | 2015-06-09 08:04:11 -0700 | [diff] [blame] | 145 | |
Vitaly Buka | 912b698 | 2015-07-06 11:13:03 -0700 | [diff] [blame] | 146 | #endif // LIBWEAVE_SRC_PRIVET_CLOUD_DELEGATE_H_ |