| 194 | } |
| 195 | |
| 196 | bool IESession::ExecuteCommand(const std::string& serialized_command, |
| 197 | std::string* serialized_response) { |
| 198 | LOG(TRACE) << "Entering IESession::ExecuteCommand"; |
| 199 | |
| 200 | // Sending a command consists of five actions: |
| 201 | // 1. Setting the command to be executed |
| 202 | // 2. Executing the command |
| 203 | // 3. Waiting for the response to be populated |
| 204 | // 4. Retrieving the response |
| 205 | // 5. Retrieving whether the command sent caused the session to be ready for shutdown |
| 206 | LRESULT set_command_result = ::SendMessage(this->executor_window_handle_, |
| 207 | WD_SET_COMMAND, |
| 208 | NULL, |
| 209 | reinterpret_cast<LPARAM>(serialized_command.c_str())); |
| 210 | while (set_command_result == 0) { |
| 211 | ::Sleep(500); |
| 212 | set_command_result = ::SendMessage(this->executor_window_handle_, |
| 213 | WD_SET_COMMAND, |
| 214 | NULL, |
| 215 | reinterpret_cast<LPARAM>(serialized_command.c_str())); |
| 216 | } |
| 217 | ::PostMessage(this->executor_window_handle_, |
| 218 | WD_EXEC_COMMAND, |
| 219 | NULL, |
| 220 | NULL); |
| 221 | |
| 222 | int response_length = static_cast<int>(::SendMessage(this->executor_window_handle_, |
| 223 | WD_GET_RESPONSE_LENGTH, |
| 224 | NULL, |
| 225 | NULL)); |
| 226 | LOG(TRACE) << "Beginning wait for response length to be not zero"; |
| 227 | while (response_length == 0) { |
| 228 | // Sleep a short time to prevent thread starvation on single-core machines. |
| 229 | ::Sleep(10); |
| 230 | response_length = static_cast<int>(::SendMessage(this->executor_window_handle_, |
| 231 | WD_GET_RESPONSE_LENGTH, |
| 232 | NULL, |
| 233 | NULL)); |
| 234 | } |
| 235 | LOG(TRACE) << "Found non-zero response length"; |
| 236 | |
| 237 | // Must add one to the length to handle the terminating character. |
| 238 | std::vector<char> response_buffer(response_length + 1); |
| 239 | ::SendMessage(this->executor_window_handle_, |
| 240 | WD_GET_RESPONSE, |
| 241 | NULL, |
| 242 | reinterpret_cast<LPARAM>(&response_buffer[0])); |
| 243 | *serialized_response = &response_buffer[0]; |
| 244 | bool session_is_valid = ::SendMessage(this->executor_window_handle_, |
| 245 | WD_IS_SESSION_VALID, |
| 246 | NULL, |
| 247 | NULL) != 0; |
| 248 | return session_is_valid; |
| 249 | } |
| 250 | |
| 251 | } // namespace webdriver |
no test coverage detected