blob: c81dd04c64001f08bd9c281ab25230811b1ffc23 [file] [log] [blame]
// Copyright 2015 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef LIBWEAVE_INCLUDE_WEAVE_DEVICE_H_
#define LIBWEAVE_INCLUDE_WEAVE_DEVICE_H_
#include <memory>
#include <set>
#include <string>
#include <weave/command.h>
#include <weave/export.h>
#include <weave/provider/bluetooth.h>
#include <weave/provider/config_store.h>
#include <weave/provider/dns_service_discovery.h>
#include <weave/provider/http_client.h>
#include <weave/provider/http_server.h>
#include <weave/provider/network.h>
#include <weave/provider/task_runner.h>
#include <weave/provider/wifi.h>
namespace weave {
// States of Gcd connection.
enum class GcdState {
kUnconfigured, // We have no credentials.
kConnecting, // We have credentials but not yet connected.
kConnected, // We're registered and connected to the cloud.
kInvalidCredentials, // Our registration has been revoked.
};
class Device {
public:
virtual ~Device() = default;
// Returns reference the current settings.
virtual const Settings& GetSettings() const = 0;
// Callback type for AddSettingsChangedCallback.
using SettingsChangedCallback =
base::Callback<void(const Settings& settings)>;
// Subscribes to notification settings changes.
virtual void AddSettingsChangedCallback(
const SettingsChangedCallback& callback) = 0;
// Callback type for AddCommandAddedCallback and AddCommandRemovedCallback.
using CommandCallback = base::Callback<void(Command*)>;
// Adds notification callback for a new command being added to the queue.
virtual void AddCommandAddedCallback(const CommandCallback& callback) = 0;
// Adds notification callback for a command being removed from the queue.
virtual void AddCommandRemovedCallback(const CommandCallback& callback) = 0;
// Adds a new command to the command queue.
virtual bool AddCommand(const base::DictionaryValue& command,
std::string* id,
ErrorPtr* error) = 0;
// Finds a command by the command |id|. Returns nullptr if the command with
// the given |id| is not found. The returned pointer should not be persisted
// for a long period of time.
virtual Command* FindCommand(const std::string& id) = 0;
// Sets callback which is called when stat is changed.
virtual void AddStateChangedCallback(const base::Closure& callback) = 0;
// Returns value of the single property.
// |name| is full property name, including package name. e.g. "base.network".
virtual std::unique_ptr<base::Value> GetStateProperty(
const std::string& name) const = 0;
// Sets value of the single property.
// |name| is full property name, including package name. e.g. "base.network".
virtual bool SetStateProperty(const std::string& name,
const base::Value& value,
ErrorPtr* error) = 0;
// Updates a multiple property values.
virtual bool SetStateProperties(const base::DictionaryValue& property_set,
ErrorPtr* error) = 0;
// Returns aggregated state properties across all registered packages.
virtual std::unique_ptr<base::DictionaryValue> GetState() const = 0;
// Returns current state of GCD connection.
virtual GcdState GetGcdState() const = 0;
// Callback type for GcdStatusCallback.
using GcdStateChangedCallback = base::Callback<void(GcdState state)>;
// Sets callback which is called when state of server connection changed.
virtual void AddGcdStateChangedCallback(
const GcdStateChangedCallback& callback) = 0;
// Registers the device. Returns a device ID on success.
// This is testing method and should not be used by applications.
virtual std::string Register(const std::string& ticket_id,
ErrorPtr* error) = 0;
// Handler should display pin code to the user.
using PairingBeginCallback =
base::Callback<void(const std::string& session_id,
PairingType pairing_type,
const std::vector<uint8_t>& code)>;
// Handler should stop displaying pin code.
using PairingEndCallback =
base::Callback<void(const std::string& session_id)>;
// Subscribes to notification about client pairing events.
virtual void AddPairingChangedCallbacks(
const PairingBeginCallback& begin_callback,
const PairingEndCallback& end_callback) = 0;
LIBWEAVE_EXPORT static std::unique_ptr<Device> Create(
provider::ConfigStore* config_store,
provider::TaskRunner* task_runner,
provider::HttpClient* http_client,
provider::Network* network,
provider::DnsServiceDiscovery* dns_sd,
provider::HttpServer* http_server,
provider::Wifi* wifi,
provider::Bluetooth* bluetooth_provider);
};
} // namespace weave
#endif // LIBWEAVE_INCLUDE_WEAVE_DEVICE_H_