blob: 73b49ef6c59c7c620acd92844c7c4b0271e238f7 (
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
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <cstring>
#include <string>
#include "base/at_exit.h"
#include "build/build_config.h"
#include "chrome/test/chromedriver/chromedriver.h"
#if defined(OS_WIN)
#include <windows.h>
#endif
#if defined(OS_WIN)
#define EXPORT __declspec(dllexport)
#else
#define EXPORT __attribute__((visibility("default")))
#endif
namespace {
base::AtExitManager* g_at_exit = NULL;
} // namespace
extern "C" {
// Synchronously executes the given command. Thread safe.
// Every call dynamically allocates a |response| string, which must be
// deallocated by calling |Free|. This |response| string is not guaranteed
// to be null terminated, and may contain null characters within. You
// should use the given response size to construct the string.
void EXPORT ExecuteCommand(
const char* command,
unsigned int command_size,
char** response,
unsigned int* response_size) {
std::string command_str(command, command_size);
std::string json;
ExecuteCommand(command_str, &json);
*response = new char[json.length()];
std::memcpy(*response, json.c_str(), json.length());
*response_size = json.length();
}
void EXPORT Free(char* p) {
delete [] p;
}
} // extern "C"
#if defined(OS_WIN)
BOOL APIENTRY DllMain(HMODULE module, DWORD reason, void* reserved) {
if (reason == DLL_PROCESS_ATTACH)
g_at_exit = new base::AtExitManager();
if (reason == DLL_PROCESS_DETACH)
delete g_at_exit;
return TRUE;
}
#else
void __attribute__((constructor)) OnLoad(void) {
g_at_exit = new base::AtExitManager();
}
void __attribute__((destructor)) OnUnload(void) {
delete g_at_exit;
}
#endif
|