-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathDataBindAccessor.cpp
More file actions
94 lines (87 loc) · 3.7 KB
/
Copy pathDataBindAccessor.cpp
File metadata and controls
94 lines (87 loc) · 3.7 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (C) 2022 Intel Corporation
// SPDX-License-Identifier: MIT
#include "DataBindAccessor.h"
#include "util/Logging.h"
#include <include/cef_task.h>
#include <include/base/cef_callback.h>
#include <include/wrapper/cef_closure_task.h>
#include "util/CefValues.h"
#include <Interprocess/source/act/SymmetricActionServer.h>
#include "util/cact/TargetLostAction.h"
#include "util/cact/OverlayDiedAction.h"
#include "util/cact/PresentmonInitFailedAction.h"
#include "util/cact/StalePidAction.h"
#include "util/SignalManager.h"
namespace p2c::client::cef
{
DataBindAccessor::DataBindAccessor(CefRefPtr<CefBrowser> pBrowser, util::KernelWrapper* pKernelWrapper_)
:
pBrowser{ std::move(pBrowser) },
pKernelWrapper{ pKernelWrapper_ }
{}
bool DataBindAccessor::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
{
std::shared_lock lk{ kernelMtx };
if (pKernelWrapper)
{
// this cannot be made an async endpoint object because it deals with V8 function objects
// signals are registered before kernel and do not require its existence
if (name == "registerSignalHandler") {
if (arguments.size() == 2 && arguments[0]->IsString() && arguments[1]->IsFunction()) {
pKernelWrapper->signals.RegisterCallback(arguments[0]->GetStringValue(), { arguments[1], CefV8Context::GetCurrentContext() });
}
else {
pmlog_error("registerSignalHandler called with incorrect parameter signature");
exception = "registerSignalHandler called with incorrect parameter signature";
}
return true;
}
// async endpoint entry function
if (name == "invokeEndpoint") {
if (arguments.size() == 4 && arguments[0]->IsString() && arguments[1]->IsObject() &&
arguments[2]->IsFunction() && arguments[3]->IsFunction())
{
const auto& key = arguments[0]->GetStringValue();
if (pKernelWrapper->pInvocationManager->HasHandler(key)) {
pKernelWrapper->pInvocationManager->DispatchInvocation(key,
{ arguments[2], arguments[3], CefV8Context::GetCurrentContext() },
arguments[1]
);
}
else {
pKernelWrapper->asyncEndpoints.DispatchInvocation(key,
{ arguments[2], arguments[3], CefV8Context::GetCurrentContext() },
arguments[1],
*pBrowser,
*this
);
}
}
else
{
pmlog_error("invokeEndpoint called with incorrect parameter signature");
exception = "invokeEndpoint called with incorrect parameter signature";
}
return true;
}
}
return false;
}
void DataBindAccessor::ResolveAsyncEndpoint(uint64_t uid, bool success, CefRefPtr<CefValue> pArgs)
{
std::shared_lock lk{ kernelMtx };
if (pKernelWrapper)
{
pKernelWrapper->asyncEndpoints.ResolveInvocation(uid, success, std::move(pArgs));
}
}
const util::KernelWrapper* DataBindAccessor::GetKernelWrapper() const
{
return pKernelWrapper;
}
void DataBindAccessor::ClearKernelWrapper()
{
std::lock_guard lk{ kernelMtx };
pKernelWrapper = nullptr;
}
}