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 <string_view> 21 22 #include "controller/chip.h" 23 #include "model.pb.h" 24 25 namespace netsim { 26 namespace controller { 27 28 class Device; 29 30 class Chip { 31 friend Device; 32 33 public: 34 explicit Chip(uint32_t id, uint32_t facade_id, common::ChipKind kind, 35 std::string name, std::string device_name, 36 std::string manufacturer = "", std::string product_name = "") id(id)37 : id(id), 38 facade_id(facade_id), 39 kind(kind), 40 name(std::move(name)), 41 device_name(std::move(device_name)), 42 manufacturer(std::move(manufacturer)), 43 product_name(std::move(product_name)), 44 capture(model::State::OFF){}; 45 ~Chip()46 ~Chip(){}; 47 48 /** 49 * Patch processing for the chip. Validate and move state from the request 50 * into the parent's model::Chip changing the ChipFacade as needed. 51 */ 52 void Patch(const model::Chip &request); 53 54 model::Chip Get(); 55 /** 56 * Reset the state of the chip to defaults. 57 */ 58 void Reset(); 59 60 /** 61 * Remove resources own by the chip and remove it from the chip emulator. 62 */ 63 void Remove(); 64 const uint32_t id; // Global id. 65 const uint32_t facade_id; 66 67 protected: 68 const common::ChipKind kind; 69 const std::string name; 70 const std::string device_name; 71 // These are patchable 72 std::string manufacturer; 73 std::string product_name; 74 model::State capture; 75 }; 76 77 } // namespace controller 78 } // namespace netsim 79