1 /* 2 * Copyright 2018 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 <unistd.h> 20 #include <cstdint> 21 #include <memory> 22 #include <string> 23 #include <unordered_map> 24 #include <vector> 25 26 #include "model/devices/device.h" 27 #include "phy_layer_factory.h" 28 #include "test_channel_transport.h" 29 #include "test_model.h" 30 31 namespace test_vendor_lib { 32 33 class TestCommandHandler { 34 public: 35 // Sets all of the methods to be used as callbacks in the HciHandler. 36 TestCommandHandler(TestModel& test_model); 37 38 ~TestCommandHandler() = default; 39 40 // Dispatches the action corresponding to the command specified by |name|. 41 void HandleCommand(const std::string& name, const std::vector<std::string>& args); 42 43 // Dispatches the action corresponding to the command specified by |name|. 44 void RegisterSendResponse(const std::function<void(const std::string&)> callback); 45 46 // Commands: 47 48 // Add a device 49 void Add(const std::vector<std::string>& args); 50 51 // Add a remote device 52 void AddRemote(const std::vector<std::string>& args); 53 54 // Remove devices by index 55 void Del(const std::vector<std::string>& args); 56 57 // Add phy 58 void AddPhy(const std::vector<std::string>& args); 59 60 // Remove phy by name 61 void DelPhy(const std::vector<std::string>& args); 62 63 // Add device to phy 64 void AddDeviceToPhy(const std::vector<std::string>& args); 65 66 // Remove device from phy 67 void DelDeviceFromPhy(const std::vector<std::string>& args); 68 69 // List the devices that the test knows about 70 void List(const std::vector<std::string>& args); 71 72 // Timer management functions 73 void SetTimerPeriod(const std::vector<std::string>& args); 74 75 void StartTimer(const std::vector<std::string>& args); 76 77 void StopTimer(const std::vector<std::string>& args); 78 79 // For manual testing 80 void AddDefaults(); 81 82 private: 83 TestModel& model_; 84 85 std::string response_string_; 86 87 std::unordered_map<std::string, std::function<void(const std::vector<std::string>&)>> active_commands_; 88 89 std::function<void(const std::string&)> send_response_; 90 91 TestCommandHandler(const TestCommandHandler& cmdPckt) = delete; 92 TestCommandHandler& operator=(const TestCommandHandler& cmdPckt) = delete; 93 }; 94 95 } // namespace test_vendor_lib 96