• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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 #ifndef __VTS_AGENT_REQUEST_HANDLER_H__
18 #define __VTS_AGENT_REQUEST_HANDLER_H__
19 
20 #include <string>
21 #include <vector>
22 
23 #include <VtsDriverCommUtil.h>
24 
25 #include "SocketClientToDriver.h"
26 #include "test/vts/proto/AndroidSystemControlMessage.pb.h"
27 #include "test/vts/proto/VtsDriverControlMessage.pb.h"
28 
29 using namespace std;
30 using namespace google::protobuf;
31 
32 namespace android {
33 namespace vts {
34 
35 // Class which contains actual methods to handle the runner requests.
36 class AgentRequestHandler : public VtsDriverCommUtil {
37  public:
AgentRequestHandler(const char * spec_dir_path,const char * hal_path32,const char * hal_path64,const char * shell_path32,const char * shell_path64)38   AgentRequestHandler(const char* spec_dir_path, const char* hal_path32,
39                       const char* hal_path64, const char* shell_path32,
40                       const char* shell_path64)
41       : VtsDriverCommUtil(),
42         service_name_(),
43         driver_client_(NULL),
44         driver_hal_spec_dir_path_(spec_dir_path),
45         driver_hal_binary32_(hal_path32),
46         driver_hal_binary64_(hal_path64),
47         driver_shell_binary32_(shell_path32),
48         driver_shell_binary64_(shell_path64) {}
49 
50 
51   // handles a new session.
52   bool ProcessOneCommand();
53 
54  protected:
55   // for the LIST_HAL command
56   bool ListHals(
57       const ::google::protobuf::RepeatedPtrField<::std::string>& base_paths);
58 
59   // for the SET_HOST_INFO command.
60   bool SetHostInfo(const int callback_port);
61 
62   // for the CHECK_DRIVER_SERVICE command
63   bool CheckDriverService(const string& service_name, bool* live);
64 
65   // for the LAUNCH_DRIVER_SERVICE command
66   bool LaunchDriverService(
67       const AndroidSystemControlCommandMessage& command_msg);
68 
69   // for the VTS_AGENT_COMMAND_READ_SPECIFICATION`
70   bool ReadSpecification(
71       const AndroidSystemControlCommandMessage& command_message);
72 
73   // for the LIST_APIS command
74   bool ListApis();
75 
76   // for the CALL_API command
77   bool CallApi(const string& call_payload, const string& uid);
78 
79   // for the VTS_AGENT_COMMAND_GET_ATTRIBUTE
80   bool GetAttribute(const string& payload);
81 
82   // for the EXECUTE_SHELL command
83   bool ExecuteShellCommand(
84       const AndroidSystemControlCommandMessage& command_message);
85 
86   // Returns a default response message.
87   bool DefaultResponse();
88 
89  protected:
90   // the currently opened, connected service name.
91   string service_name_;
92   // the port number of a host-side callback server.
93   int callback_port_;
94   // the socket client of a launched or connected driver.
95   VtsDriverSocketClient* driver_client_;
96 
97   void CreateSystemControlResponseFromDriverControlResponse(
98       const VtsDriverControlResponseMessage& driver_control_response_message,
99       AndroidSystemControlResponseMessage* system_control_response_message);
100 
101   const string driver_hal_spec_dir_path_;
102   const string driver_hal_binary32_;
103   const string driver_hal_binary64_;
104   const string driver_shell_binary32_;
105   const string driver_shell_binary64_;
106 };
107 
108 }  // namespace vts
109 }  // namespace android
110 
111 #endif
112