// Copyright 2015 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef BUFFET_MANAGER_H_ #define BUFFET_MANAGER_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include "android/weave/BnWeaveServiceManager.h" #include "buffet/binder_weave_service.h" #include "buffet/buffet_config.h" namespace buffet { class BluetoothClient; class HttpTransportClient; class MdnsClient; class ShillClient; class WebServClient; // The Manager is responsible for global state of Buffet. It exposes // interfaces which affect the entire device such as device registration and // device state. class Manager final : public android::weave::BnWeaveServiceManager { public: struct Options { bool xmpp_enabled = true; bool disable_privet = false; bool enable_ping = false; std::set device_whitelist; BuffetConfig::Options config_options; }; Manager(const Options& options, const scoped_refptr& bus); ~Manager() override; void Start(brillo::dbus_utils::AsyncEventSequencer* sequencer); void Stop(); private: void RestartWeave(brillo::dbus_utils::AsyncEventSequencer* sequencer); void CreateDevice(); // Binder methods for IWeaveServiceManager: using WeaveServiceManagerNotificationListener = android::sp; android::binder::Status connect( const android::sp& client) override; android::binder::Status registerNotificationListener( const WeaveServiceManagerNotificationListener& listener) override; android::binder::Status getDeviceId(android::String16* id) override; android::binder::Status getCloudId(android::String16* id) override; android::binder::Status getDeviceName(android::String16* name) override; android::binder::Status getDeviceDescription( android::String16* description) override; android::binder::Status getDeviceLocation( android::String16* location) override; android::binder::Status getOemName(android::String16* name) override; android::binder::Status getModelName(android::String16* name) override; android::binder::Status getModelId(android::String16* id) override; android::binder::Status getPairingSessionId(android::String16* id) override; android::binder::Status getPairingMode(android::String16* mode) override; android::binder::Status getPairingCode(android::String16* code) override; android::binder::Status getState(android::String16* state) override; android::binder::Status getTraits(android::String16* traits) override; android::binder::Status getComponents(android::String16* components) override; void OnTraitDefsChanged(); void OnComponentTreeChanged(); void OnGcdStateChanged(weave::GcdState state); void OnConfigChanged(const weave::Settings& settings); void OnPairingStart(const std::string& session_id, weave::PairingType pairing_type, const std::vector& code); void OnPairingEnd(const std::string& session_id); void CreateServicesForClients(); void OnClientDisconnected( const android::sp& client); void OnNotificationListenerDestroyed( const WeaveServiceManagerNotificationListener& notification_listener); void NotifyServiceManagerChange(const std::vector& notification_ids); void OnRebootDevice(const std::weak_ptr& cmd); void RebootDeviceNow(); Options options_; scoped_refptr bus_; class TaskRunner; std::unique_ptr task_runner_; std::unique_ptr bluetooth_client_; std::unique_ptr config_; std::unique_ptr http_client_; std::unique_ptr shill_client_; std::unique_ptr mdns_client_; std::unique_ptr web_serv_client_; std::unique_ptr device_; std::vector> pending_clients_; std::map, android::sp> services_; std::set notification_listeners_; android::PowerManagerClient power_manager_client_; // State properties. std::string cloud_id_; std::string device_id_; std::string device_name_; std::string device_description_; std::string device_location_; std::string oem_name_; std::string model_name_; std::string model_id_; std::string pairing_session_id_; std::string pairing_mode_; std::string pairing_code_; std::string state_; base::WeakPtrFactory weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(Manager); }; } // namespace buffet #endif // BUFFET_MANAGER_H_