blob: 520275bc565594fb7c37124eb258ad63aab845a2 [file] [log] [blame]
Vadim Iosevichd50ea462017-03-30 16:19:08 +03001/*
2 * Copyright (c) 2017, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef _COMMANDSHANDLER_H_
31#define _COMMANDSHANDLER_H_
32
33#include <iostream>
34#include <memory>
35#include <map>
36#include "MessageParser.h"
37#include "HostDefinitions.h"
38#include <sstream>
39
40class Host;
41
42using namespace std;
43
44
45// *************************************************************************************************
46
47class CommandsHandler
48{
49public:
50 /*
Vadim Iosevich40679a12017-06-06 14:24:07 +030051 * pCommandFunction is used for the functions map - each function gets two arguments:
52 * vector of strings which holds the arguments and the number of arguments in that vector
53 */
Vadim Iosevichd50ea462017-03-30 16:19:08 +030054 typedef ResponseMessage(CommandsHandler::*pCommandFunction)(vector<string>, unsigned int);
55
56 /*
Vadim Iosevich40679a12017-06-06 14:24:07 +030057 * The constructor inserts each one of the available functions into the map - m_functionHandler - according to server type (TCP/UDP)
58 */
Vadim Iosevichd50ea462017-03-30 16:19:08 +030059 CommandsHandler(ServerType type, Host& host);
60
61 ConnectionStatus ExecuteCommand(string message, ResponseMessage &referencedResponse);
Vadim Iosevich40679a12017-06-06 14:24:07 +030062 ConnectionStatus ExecuteBinaryCommand(uint8_t* binaryInput, ResponseMessage &referencedResponse);
Vadim Iosevichd50ea462017-03-30 16:19:08 +030063
64private:
Vadim Iosevichd50ea462017-03-30 16:19:08 +030065 //m_functionHandler is a map that maps a string = command name, to a function
66 map<string, pCommandFunction> m_functionHandler;
67 Host& m_host; // a refernce to the host (enables access to deviceManager and hostInfo)
68
69 enum CommandsHandlerResponseStatus
70 {
71 chrsInvalidNumberOfArguments,
72 chrsInvalidArgument,
73 chrsOperationFailure,
74 chrsLinuxSupportOnly,
Vadim Iosevich40679a12017-06-06 14:24:07 +030075 chrsDeviceIsSilent,
Vadim Iosevichd50ea462017-03-30 16:19:08 +030076 chrsSuccess
77 };
78
Vadim Ioseviche76832c2017-11-05 09:09:14 +020079 string GetCommandsHandlerResponseStatusString(CommandsHandlerResponseStatus status);
Vadim Iosevichd50ea462017-03-30 16:19:08 +030080
81 /*
Vadim Iosevich40679a12017-06-06 14:24:07 +030082 FormatResponseMessage
83 Decorate the response message with time stamp and a success status
84 @param: successStatus - true for a successful operation, false otherwise
85 @param: message - the content of the response
86 @return: the decorated response
Vadim Iosevichd50ea462017-03-30 16:19:08 +030087 */
88 string DecorateResponseMessage(bool successStatus, string message = "");
89
90 // **********************************Commands Functions:****************************************
91 ResponseMessage GetInterfaces(vector<string> arguments, unsigned int numberOfArguments);
92
93 ResponseMessage OpenInterface(vector<string> arguments, unsigned int numberOfArguments);
94
95 ResponseMessage CloseInterface(vector<string> arguments, unsigned int numberOfArguments);
96
97 ResponseMessage Read(vector<string> arguments, unsigned int numberOfArguments);
98
99 ResponseMessage Write(vector<string> arguments, unsigned int numberOfArguments);
100
101 ResponseMessage ReadBlock(vector<string> arguments, unsigned int numberOfArguments);
102
103 ResponseMessage WriteBlock(vector<string> arguments, unsigned int numberOfArguments);
104
105 ResponseMessage InterfaceReset(vector<string> arguments, unsigned int numberOfArguments);
106
107 ResponseMessage SwReset(vector<string> arguments, unsigned int numberOfArguments);
108
109 ResponseMessage AllocPmc(vector<string> arguments, unsigned int numberOfArguments);
110
111 ResponseMessage DeallocPmc(vector<string> arguments, unsigned int numberOfArguments);
112
113 ResponseMessage CreatePmcFile(vector<string> arguments, unsigned int numberOfArguments);
114
Vadim Iosevich40679a12017-06-06 14:24:07 +0300115 ResponseMessage FindPmcFile(vector<string> arguments, unsigned int numberOfArguments);
Vadim Iosevichd50ea462017-03-30 16:19:08 +0300116
117 ResponseMessage SendWmi(vector<string> arguments, unsigned int numberOfArguments);
118
119 ResponseMessage GetTime(vector<string> arguments, unsigned int numberOfArguments);
120
Vadim Iosevich40679a12017-06-06 14:24:07 +0300121 ResponseMessage SetDriverMode(vector<string> arguments, unsigned int numberOfArguments);
Vadim Iosevichd50ea462017-03-30 16:19:08 +0300122
Vadim Iosevich40679a12017-06-06 14:24:07 +0300123 ResponseMessage GetHostManagerVersion(vector<string> arguments, unsigned int numberOfArguments);
124
125 ResponseMessage DriverControl(vector<string> arguments, unsigned int numberOfArguments);
126
Vadim Ioseviche76832c2017-11-05 09:09:14 +0200127 ResponseMessage DriverCommand(vector<string> arguments, unsigned int numberOfArguments);
128
Vadim Iosevich40679a12017-06-06 14:24:07 +0300129 ResponseMessage GenericDriverIO(vector<string> arguments, void* inputBuf, unsigned int inputBufSize);
130
131 ResponseMessage GetDeviceSilenceMode(vector<string> arguments, unsigned int numberOfArguments);
132
133 ResponseMessage SetDeviceSilenceMode(vector<string> arguments, unsigned int numberOfArguments);
Vadim Iosevichd50ea462017-03-30 16:19:08 +0300134
Vadim Ioseviche76832c2017-11-05 09:09:14 +0200135 ResponseMessage GetConnectedUsers(vector<string> arguments, unsigned int numberOfArguments);
136
137 ResponseMessage GetDeviceCapabilities(vector<string> arguments, unsigned int numberOfArguments);
138
139 bool ValidArgumentsNumber(string functionName, size_t numberOfArguments, size_t expectedNumOfArguments, string& responseMessage);
Vadim Iosevichd50ea462017-03-30 16:19:08 +0300140
141 /*
Vadim Iosevich40679a12017-06-06 14:24:07 +0300142 GetHostNetworkInfo
143 Return host's IP and host's alias as the Response
144 @param: an empty vector
145 @return: a response with a string that contains both host's IP and host's alias
Vadim Iosevichd50ea462017-03-30 16:19:08 +0300146 */
147 ResponseMessage GetHostNetworkInfo(vector<string> arguments, unsigned int numberOfArguments);
148
149 /*
Vadim Iosevich40679a12017-06-06 14:24:07 +0300150 SetHostAlias
151 Get a new alias and define it as the new host's alias
152 @param: a vector with one string representing the new alias
153 @return: a response with feedback about the operation status (success/failure)
Vadim Iosevichd50ea462017-03-30 16:19:08 +0300154 */
155 ResponseMessage SetHostAlias(vector<string> arguments, unsigned int numberOfArguments);
156
Vadim Iosevich20d50d82017-09-19 11:38:15 +0300157 ResponseMessage GetHostAlias(vector<string> arguments, unsigned int numberOfArguments);
158
Vadim Ioseviche76832c2017-11-05 09:09:14 +0200159 ResponseMessage GetHostCapabilities(vector<string> arguments, unsigned int numberOfArguments);
160
161 ResponseMessage OnTargetLogRecording(vector<string> arguments, unsigned int numberOfArguments);
162
Vadim Iosevichd50ea462017-03-30 16:19:08 +0300163 const char m_device_delimiter = ' ';
164
165 const char m_array_delimiter = ' ';
166
167 const char m_reply_feilds_delimiter = '|';
168};
169
170
171#endif // !_COMMANDSHANDLER_H_