1 /* 2 * Copyright 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <memory> 20 #include <optional> 21 #include <vector> 22 23 #include "common.pb.h" 24 #include "controller/device.h" 25 #include "model.pb.h" 26 27 namespace netsim { 28 namespace controller { 29 30 class SceneController { 31 public: 32 SceneController(const SceneController &) = delete; 33 SceneController &operator=(const SceneController &) = delete; 34 SceneController(SceneController &&) = delete; 35 SceneController &operator=(SceneController &&) = delete; 36 37 static SceneController &Singleton(); 38 39 // When a packet stream goes away the chip is removed. When there are no more 40 // chips the device is remove. 41 void RemoveChip(uint32_t device_id, uint32_t chip_id); 42 43 std::tuple<uint32_t, uint32_t, uint32_t> AddChip( 44 const std::string &guid, const std::string &device_name, 45 common::ChipKind chip_kind, const std::string &chip_name = "", 46 const std::string &manufacturer = "", 47 const std::string &product_name = ""); 48 49 bool PatchDevice(const model::Device &); 50 51 float GetDistance(uint32_t, uint32_t); 52 53 model::Scene Get(); 54 55 void Reset(); 56 57 std::optional<std::chrono::seconds> GetShutdownTime(); 58 59 std::unordered_map<uint32_t, std::shared_ptr<Device>> devices_; 60 61 protected: 62 friend class SceneControllerTest; 63 friend class FrontendServerTest; 64 65 std::shared_ptr<Device> GetDevice(const std::string &guid, 66 const std::string &name); 67 std::shared_ptr<Device> MatchDevice(const std::string &query); 68 69 private: 70 SceneController() = default; // Disallow instantiation outside of the class. 71 72 void RemoveDevice(uint32_t device_id); 73 74 std::mutex mutex_; 75 std::optional<std::chrono::time_point<std::chrono::system_clock>> 76 inactive_timestamp_{std::chrono::system_clock::now()}; 77 }; 78 79 } // namespace controller 80 } // namespace netsim 81