1 // 2 // Copyright (C) 2020 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 #pragma once 17 18 #include "host/commands/modem_simulator/channel_monitor.h" 19 #include "host/commands/modem_simulator/modem_service.h" 20 #include "host/commands/modem_simulator/nvram_config.h" 21 #include "host/commands/modem_simulator/thread_looper.h" 22 23 namespace cuttlefish { 24 25 class ModemSimulator { 26 public: 27 ModemSimulator(int32_t modem_id); 28 ~ModemSimulator(); 29 30 ModemSimulator(const ModemSimulator&) = delete; 31 ModemSimulator& operator=(const ModemSimulator&) = delete; 32 33 void Initialize(std::unique_ptr<ChannelMonitor>&& channel_monitor); 34 35 void DispatchCommand(const Client& client, std::string& command); 36 37 void OnFirstClientConnected(); 38 void SaveModemState(); 39 bool IsWaitingSmsPdu(); SetRemoteClient(cuttlefish::SharedFD client,bool is_accepted)40 void SetRemoteClient(cuttlefish::SharedFD client, bool is_accepted) { 41 channel_monitor_->SetRemoteClient(client, is_accepted); 42 } 43 44 private: 45 int32_t modem_id_; 46 std::unique_ptr<ChannelMonitor> channel_monitor_; 47 std::unique_ptr<ThreadLooper> thread_looper_; 48 49 std::map<ModemServiceType, std::unique_ptr<ModemService>> modem_services_; 50 51 static void LoadNvramConfig(); 52 53 void RegisterModemService(); 54 }; 55 56 } // namespace cuttlefish 57