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