Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/cpp/iedriver/IEServer.cpp
2867 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
17
#include "IEServer.h"
18
19
#include "logging.h"
20
21
#include "IESession.h"
22
#include "FileUtilities.h"
23
24
namespace webdriver {
25
26
IEServer::IEServer(int port,
27
const std::string& host,
28
const std::string& log_level,
29
const std::string& log_file,
30
const std::string& version,
31
const std::string& acl) : Server(port, host, log_level, log_file, acl) {
32
LOG(TRACE) << "Entering IEServer::IEServer";
33
LOG(INFO) << "Driver version: " << version;
34
this->version_ = version;
35
this->AddCommand("/session/:sessionid/ie/script/background", "POST", "executeBackgroundScript");
36
}
37
38
IEServer::~IEServer(void) {
39
}
40
41
SessionHandle IEServer::InitializeSession() {
42
LOG(TRACE) << "Entering IEServer::InitializeSession";
43
SessionHandle session_handle(new IESession());
44
SessionParameters params;
45
params.port = this->port();
46
session_handle->Initialize(reinterpret_cast<void*>(&params));
47
return session_handle;
48
}
49
50
std::string IEServer::GetStatus() {
51
LOG(TRACE) << "Entering IEServer::GetStatus";
52
SYSTEM_INFO system_info;
53
::ZeroMemory(&system_info, sizeof(SYSTEM_INFO));
54
::GetNativeSystemInfo(&system_info);
55
56
std::string os_version = FileUtilities::GetFileVersion("kernel32.dll");
57
58
std::string arch = "x86";
59
if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
60
arch = "x64";
61
}
62
63
Json::Value build;
64
build["version"] = this->version_;
65
66
Json::Value os;
67
os["arch"] = arch;
68
os["name"] = "windows";
69
os["version"] = os_version;
70
71
bool is_ready = this->session_count() < 1;
72
std::string message = "Ready to create session";
73
if (!is_ready) {
74
message = "Maximum number of sessions already created";
75
}
76
77
Json::Value status;
78
status["build"] = build;
79
status["os"] = os;
80
status["ready"] = is_ready;
81
status["message"] = message;
82
Response response;
83
response.SetSuccessResponse(status);
84
return response.Serialize();
85
}
86
87
void IEServer::ShutDown() {
88
LOG(TRACE) << "Entering IEServer::ShutDown";
89
DWORD process_id = ::GetCurrentProcessId();
90
std::wstring process_id_string = std::to_wstring(static_cast<long long>(process_id));
91
std::wstring event_name = IESERVER_SHUTDOWN_EVENT_NAME + process_id_string;
92
HANDLE event_handle = ::OpenEvent(EVENT_MODIFY_STATE,
93
FALSE,
94
event_name.c_str());
95
if (event_handle) {
96
::SetEvent(event_handle);
97
::CloseHandle(event_handle);
98
}
99
}
100
101
} //namespace webdriver
102
103