mirror of
https://gitee.com/openharmony/msdp_device_status
synced 2024-11-27 09:41:43 +00:00
Merge branch 'master' of https://gitee.com/openharmony/msdp_device_status into tlv
Change-Id: I3ed18c7391c9a28d48e0138ad8b07d8a1d8955c9
This commit is contained in:
commit
a10a3927e6
19
BUILD.gn
19
BUILD.gn
@ -16,6 +16,10 @@ import("device_status.gni")
|
||||
group("devicestatus_service_group") {
|
||||
deps = []
|
||||
|
||||
if (fusion_intention_framework) {
|
||||
deps += [ "${device_status_root_path}/intention/cooperate/server:intention_cooperate" ]
|
||||
}
|
||||
|
||||
if (fusion_rust_enabled) {
|
||||
deps += [
|
||||
"${device_status_root_path}/rust/ipc/server:fusion_ipc_server_ffi",
|
||||
@ -29,21 +33,6 @@ group("devicestatus_service_group") {
|
||||
}
|
||||
}
|
||||
|
||||
group("intention_group") {
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/cooperate/server:intention_cooperate",
|
||||
"${device_status_root_path}/intention/data:cooperate_params",
|
||||
"${device_status_root_path}/intention/data:drag_params",
|
||||
"${device_status_root_path}/intention/frameworks/client:intention_client",
|
||||
"${device_status_root_path}/intention/ipc:intention_ipc",
|
||||
"${device_status_root_path}/intention/plugins/drag:intention_drag",
|
||||
"${device_status_root_path}/intention/scheduler/plugin_manager:plugin_manager",
|
||||
"${device_status_root_path}/intention/scheduler/task_scheduler:task_scheduler",
|
||||
"${device_status_root_path}/intention/scheduler/timer_manager:timer_manager",
|
||||
"${device_status_root_path}/intention/services/intention_service:intention_service",
|
||||
]
|
||||
}
|
||||
|
||||
group("device_status_tests") {
|
||||
testonly = true
|
||||
deps = [
|
||||
|
@ -26,7 +26,6 @@
|
||||
"common_event_service",
|
||||
"napi",
|
||||
"image_framework",
|
||||
"build_framework",
|
||||
"eventhandler",
|
||||
"distributed_input",
|
||||
"device_manager",
|
||||
@ -37,7 +36,6 @@
|
||||
"window_manager",
|
||||
"hitrace",
|
||||
"ability_base",
|
||||
"huks",
|
||||
"graphic_2d",
|
||||
"udmf",
|
||||
"device_info_manager",
|
||||
|
@ -14,10 +14,11 @@
|
||||
import("//build/ohos.gni")
|
||||
|
||||
declare_args() {
|
||||
fusion_intention_framework = false
|
||||
fusion_rust_enabled = false
|
||||
fusion_interaction_coordination = false
|
||||
fusion_drag_enable_monitor = false
|
||||
fusion_drag_enable_interceptor = true
|
||||
fusion_drag_enable_monitor = true
|
||||
fusion_drag_enable_interceptor = false
|
||||
device_status_sensor_enable = true
|
||||
if (defined(global_parts_info)) {
|
||||
if (!defined(global_parts_info.sensors_sensor)) {
|
||||
@ -45,6 +46,10 @@ intention_root_path = "//base/msdp/device_status/intention"
|
||||
|
||||
device_status_default_defines = []
|
||||
|
||||
if (fusion_intention_framework) {
|
||||
device_status_default_defines += [ "OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK" ]
|
||||
}
|
||||
|
||||
if (defined(fusion_interaction_motion_drag) && fusion_interaction_motion_drag) {
|
||||
device_status_default_defines += [ "OHOS_BUILD_ENABLE_MOTION_DRAG" ]
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include "js_cooperate_manager.h"
|
||||
|
||||
#include "coordination_manager_impl.h"
|
||||
#include "devicestatus_define.h"
|
||||
#include "interaction_manager.h"
|
||||
#include "util_napi.h"
|
||||
|
@ -15,6 +15,9 @@ import("../../../../../device_status.gni")
|
||||
|
||||
ohos_shared_library("cooperate") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
|
@ -46,12 +46,12 @@ public:
|
||||
std::shared_ptr<JsCoordinationManager> GetJsCoordinationMgr();
|
||||
|
||||
private:
|
||||
static napi_value PrepareCompatible(napi_env env, napi_callback_info info, bool isCheckPermission = false);
|
||||
static napi_value UnprepareCompatible(napi_env env, napi_callback_info info, bool isCheckPermission = false);
|
||||
static napi_value ActivateCompatible(napi_env env, napi_callback_info info, bool isCheckPermission = false);
|
||||
static napi_value DeactivateCompatible(napi_env env, napi_callback_info info, bool isCheckPermission = false);
|
||||
static napi_value PrepareCompatible(napi_env env, napi_callback_info info, bool isCompatible = false);
|
||||
static napi_value UnprepareCompatible(napi_env env, napi_callback_info info, bool isCompatible = false);
|
||||
static napi_value ActivateCompatible(napi_env env, napi_callback_info info, bool isCompatible = false);
|
||||
static napi_value DeactivateCompatible(napi_env env, napi_callback_info info, bool isCompatible = false);
|
||||
static napi_value GetCrossingSwitchStateCompatible(napi_env env,
|
||||
napi_callback_info info, bool isCheckPermission = false);
|
||||
napi_callback_info info, bool isCompatible = false);
|
||||
|
||||
static napi_value CreateInstance(napi_env env);
|
||||
static napi_value JsConstructor(napi_env env, napi_callback_info info);
|
||||
|
@ -30,13 +30,13 @@ public:
|
||||
DISALLOW_COPY_AND_MOVE(JsCoordinationManager);
|
||||
~JsCoordinationManager() = default;
|
||||
|
||||
napi_value Prepare(napi_env env, bool isCheckPermission, napi_value handle = nullptr);
|
||||
napi_value Unprepare(napi_env env, bool isCheckPermission, napi_value handle = nullptr);
|
||||
napi_value Prepare(napi_env env, bool isCompatible, napi_value handle = nullptr);
|
||||
napi_value Unprepare(napi_env env, bool isCompatible, napi_value handle = nullptr);
|
||||
napi_value Activate(napi_env env, const std::string &remoteNetworkDescriptor,
|
||||
int32_t startDeviceId, bool isCheckPermission, napi_value handle = nullptr);
|
||||
napi_value Deactivate(napi_env env, bool isUnchained, bool isCheckPermission, napi_value handle = nullptr);
|
||||
int32_t startDeviceId, bool isCompatible, napi_value handle = nullptr);
|
||||
napi_value Deactivate(napi_env env, bool isUnchained, bool isCompatible, napi_value handle = nullptr);
|
||||
napi_value GetCrossingSwitchState(napi_env env, const std::string &networkId,
|
||||
bool isCheckPermission, napi_value handle = nullptr);
|
||||
bool isCompatible, napi_value handle = nullptr);
|
||||
void ResetEnv();
|
||||
void RegisterListener(napi_env env, const std::string &type, napi_value handle);
|
||||
void UnregisterListener(napi_env env, const std::string &type, napi_value handle = nullptr);
|
||||
|
@ -68,7 +68,7 @@ napi_value JsCoordinationContext::PrepareCooperate(napi_env env, napi_callback_i
|
||||
return PrepareCompatible(env, info, true);
|
||||
}
|
||||
|
||||
napi_value JsCoordinationContext::PrepareCompatible(napi_env env, napi_callback_info info, bool isCheckPermission)
|
||||
napi_value JsCoordinationContext::PrepareCompatible(napi_env env, napi_callback_info info, bool isCompatible)
|
||||
{
|
||||
size_t argc = 1;
|
||||
napi_value argv[1] = { nullptr };
|
||||
@ -79,13 +79,13 @@ napi_value JsCoordinationContext::PrepareCompatible(napi_env env, napi_callback_
|
||||
std::shared_ptr<JsCoordinationManager> jsCoordinationMgr = jsDev->GetJsCoordinationMgr();
|
||||
CHKPP(jsCoordinationMgr);
|
||||
if (argc == 0) {
|
||||
return jsCoordinationMgr->Prepare(env, isCheckPermission);
|
||||
return jsCoordinationMgr->Prepare(env, isCompatible);
|
||||
}
|
||||
if (!UtilNapi::TypeOf(env, argv[0], napi_function)) {
|
||||
THROWERR(env, COMMON_PARAMETER_ERROR, "callback", "function");
|
||||
return nullptr;
|
||||
}
|
||||
return jsCoordinationMgr->Prepare(env, isCheckPermission, argv[0]);
|
||||
return jsCoordinationMgr->Prepare(env, isCompatible, argv[0]);
|
||||
}
|
||||
|
||||
napi_value JsCoordinationContext::Unprepare(napi_env env, napi_callback_info info)
|
||||
@ -100,7 +100,7 @@ napi_value JsCoordinationContext::UnprepareCooperate(napi_env env, napi_callback
|
||||
return UnprepareCompatible(env, info, true);
|
||||
}
|
||||
|
||||
napi_value JsCoordinationContext::UnprepareCompatible(napi_env env, napi_callback_info info, bool isCheckPermission)
|
||||
napi_value JsCoordinationContext::UnprepareCompatible(napi_env env, napi_callback_info info, bool isCompatible)
|
||||
{
|
||||
size_t argc = 1;
|
||||
napi_value argv[1] = { nullptr };
|
||||
@ -111,13 +111,13 @@ napi_value JsCoordinationContext::UnprepareCompatible(napi_env env, napi_callbac
|
||||
std::shared_ptr<JsCoordinationManager> jsCoordinationMgr = jsDev->GetJsCoordinationMgr();
|
||||
CHKPP(jsCoordinationMgr);
|
||||
if (argc == 0) {
|
||||
return jsCoordinationMgr->Unprepare(env, isCheckPermission);
|
||||
return jsCoordinationMgr->Unprepare(env, isCompatible);
|
||||
}
|
||||
if (!UtilNapi::TypeOf(env, argv[0], napi_function)) {
|
||||
THROWERR(env, COMMON_PARAMETER_ERROR, "callback", "function");
|
||||
return nullptr;
|
||||
}
|
||||
return jsCoordinationMgr->Unprepare(env, isCheckPermission, argv[0]);
|
||||
return jsCoordinationMgr->Unprepare(env, isCompatible, argv[0]);
|
||||
}
|
||||
|
||||
napi_value JsCoordinationContext::Activate(napi_env env, napi_callback_info info)
|
||||
@ -132,7 +132,7 @@ napi_value JsCoordinationContext::ActivateCooperate(napi_env env, napi_callback_
|
||||
return ActivateCompatible(env, info, true);
|
||||
}
|
||||
|
||||
napi_value JsCoordinationContext::ActivateCompatible(napi_env env, napi_callback_info info, bool isCheckPermission)
|
||||
napi_value JsCoordinationContext::ActivateCompatible(napi_env env, napi_callback_info info, bool isCompatible)
|
||||
{
|
||||
size_t argc = 3;
|
||||
napi_value argv[3] = { nullptr };
|
||||
@ -162,13 +162,13 @@ napi_value JsCoordinationContext::ActivateCompatible(napi_env env, napi_callback
|
||||
std::shared_ptr<JsCoordinationManager> jsCoordinationMgr = jsDev->GetJsCoordinationMgr();
|
||||
CHKPP(jsCoordinationMgr);
|
||||
if (argc == 2) {
|
||||
return jsCoordinationMgr->Activate(env, remoteNetworkId, startDeviceId, isCheckPermission);
|
||||
return jsCoordinationMgr->Activate(env, remoteNetworkId, startDeviceId, isCompatible);
|
||||
}
|
||||
if (!UtilNapi::TypeOf(env, argv[2], napi_function)) {
|
||||
THROWERR(env, COMMON_PARAMETER_ERROR, "callback", "function");
|
||||
return nullptr;
|
||||
}
|
||||
return jsCoordinationMgr->Activate(env, std::string(remoteNetworkId), startDeviceId, isCheckPermission, argv[2]);
|
||||
return jsCoordinationMgr->Activate(env, std::string(remoteNetworkId), startDeviceId, isCompatible, argv[2]);
|
||||
}
|
||||
|
||||
napi_value JsCoordinationContext::Deactivate(napi_env env, napi_callback_info info)
|
||||
@ -183,7 +183,7 @@ napi_value JsCoordinationContext::DeactivateCooperate(napi_env env, napi_callbac
|
||||
return DeactivateCompatible(env, info, true);
|
||||
}
|
||||
|
||||
napi_value JsCoordinationContext::DeactivateCompatible(napi_env env, napi_callback_info info, bool isCheckPermission)
|
||||
napi_value JsCoordinationContext::DeactivateCompatible(napi_env env, napi_callback_info info, bool isCompatible)
|
||||
{
|
||||
size_t argc = 2;
|
||||
napi_value argv[2] = { nullptr };
|
||||
@ -205,13 +205,13 @@ napi_value JsCoordinationContext::DeactivateCompatible(napi_env env, napi_callba
|
||||
std::shared_ptr<JsCoordinationManager> jsCoordinationMgr = jsDev->GetJsCoordinationMgr();
|
||||
CHKPP(jsCoordinationMgr);
|
||||
if (argc == 1) {
|
||||
return jsCoordinationMgr->Deactivate(env, isUnchained, isCheckPermission);
|
||||
return jsCoordinationMgr->Deactivate(env, isUnchained, isCompatible);
|
||||
}
|
||||
if (!UtilNapi::TypeOf(env, argv[1], napi_function)) {
|
||||
THROWERR(env, COMMON_PARAMETER_ERROR, "callback", "function");
|
||||
return nullptr;
|
||||
}
|
||||
return jsCoordinationMgr->Deactivate(env, isUnchained, isCheckPermission, argv[1]);
|
||||
return jsCoordinationMgr->Deactivate(env, isUnchained, isCompatible, argv[1]);
|
||||
}
|
||||
|
||||
napi_value JsCoordinationContext::GetCrossingSwitchState(napi_env env, napi_callback_info info)
|
||||
@ -227,7 +227,7 @@ napi_value JsCoordinationContext::GetCooperateSwitchState(napi_env env, napi_cal
|
||||
}
|
||||
|
||||
napi_value JsCoordinationContext::GetCrossingSwitchStateCompatible(napi_env env,
|
||||
napi_callback_info info, bool isCheckPermission)
|
||||
napi_callback_info info, bool isCompatible)
|
||||
{
|
||||
size_t argc = 2;
|
||||
napi_value argv[2] = { nullptr };
|
||||
@ -252,13 +252,13 @@ napi_value JsCoordinationContext::GetCrossingSwitchStateCompatible(napi_env env,
|
||||
std::shared_ptr<JsCoordinationManager> jsCoordinationMgr = jsDev->GetJsCoordinationMgr();
|
||||
CHKPP(jsCoordinationMgr);
|
||||
if (argc == 1) {
|
||||
return jsCoordinationMgr->GetCrossingSwitchState(env, networkIdTemp, isCheckPermission);
|
||||
return jsCoordinationMgr->GetCrossingSwitchState(env, networkIdTemp, isCompatible);
|
||||
}
|
||||
if (!UtilNapi::TypeOf(env, argv[1], napi_function)) {
|
||||
THROWERR(env, COMMON_PARAMETER_ERROR, "callback", "function");
|
||||
return nullptr;
|
||||
}
|
||||
return jsCoordinationMgr->GetCrossingSwitchState(env, networkIdTemp, isCheckPermission, argv[1]);
|
||||
return jsCoordinationMgr->GetCrossingSwitchState(env, networkIdTemp, isCompatible, argv[1]);
|
||||
}
|
||||
|
||||
napi_value JsCoordinationContext::On(napi_env env, napi_callback_info info)
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include "js_coordination_manager.h"
|
||||
|
||||
#include "coordination_manager_impl.h"
|
||||
#include "devicestatus_define.h"
|
||||
#include "interaction_manager.h"
|
||||
#include "util_napi.h"
|
||||
@ -27,14 +26,14 @@ namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "JsCoordinationManager" };
|
||||
} // namespace
|
||||
|
||||
napi_value JsCoordinationManager::Prepare(napi_env env, bool isCheckPermission, napi_value handle)
|
||||
napi_value JsCoordinationManager::Prepare(napi_env env, bool isCompatible, napi_value handle)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
sptr<JsUtil::CallbackInfo> cb = new (std::nothrow) JsUtil::CallbackInfo();
|
||||
CHKPP(cb);
|
||||
napi_value result = CreateCallbackInfo(env, handle, cb);
|
||||
auto callback = std::bind(EmitJsPrepare, cb, std::placeholders::_1, std::placeholders::_2);
|
||||
int32_t errCode = INTERACTION_MGR->PrepareCoordination(callback, isCheckPermission);
|
||||
int32_t errCode = INTERACTION_MGR->PrepareCoordination(callback, isCompatible);
|
||||
if (errCode != RET_OK) {
|
||||
RELEASE_CALLBACKINFO(cb->env, cb->ref);
|
||||
}
|
||||
@ -42,14 +41,14 @@ napi_value JsCoordinationManager::Prepare(napi_env env, bool isCheckPermission,
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value JsCoordinationManager::Unprepare(napi_env env, bool isCheckPermission, napi_value handle)
|
||||
napi_value JsCoordinationManager::Unprepare(napi_env env, bool isCompatible, napi_value handle)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
sptr<JsUtil::CallbackInfo> cb = new (std::nothrow) JsUtil::CallbackInfo();
|
||||
CHKPP(cb);
|
||||
napi_value result = CreateCallbackInfo(env, handle, cb);
|
||||
auto callback = std::bind(EmitJsPrepare, cb, std::placeholders::_1, std::placeholders::_2);
|
||||
int32_t errCode = INTERACTION_MGR->UnprepareCoordination(callback, isCheckPermission);
|
||||
int32_t errCode = INTERACTION_MGR->UnprepareCoordination(callback, isCompatible);
|
||||
if (errCode != RET_OK) {
|
||||
RELEASE_CALLBACKINFO(cb->env, cb->ref);
|
||||
}
|
||||
@ -58,7 +57,7 @@ napi_value JsCoordinationManager::Unprepare(napi_env env, bool isCheckPermission
|
||||
}
|
||||
|
||||
napi_value JsCoordinationManager::Activate(napi_env env, const std::string &remoteNetworkId,
|
||||
int32_t startDeviceId, bool isCheckPermission, napi_value handle)
|
||||
int32_t startDeviceId, bool isCompatible, napi_value handle)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
sptr<JsUtil::CallbackInfo> cb = new (std::nothrow) JsUtil::CallbackInfo();
|
||||
@ -66,7 +65,7 @@ napi_value JsCoordinationManager::Activate(napi_env env, const std::string &remo
|
||||
napi_value result = CreateCallbackInfo(env, handle, cb);
|
||||
auto callback = std::bind(EmitJsActivate, cb, std::placeholders::_1, std::placeholders::_2);
|
||||
int32_t errCode = INTERACTION_MGR->ActivateCoordination(
|
||||
remoteNetworkId, startDeviceId, callback, isCheckPermission);
|
||||
remoteNetworkId, startDeviceId, callback, isCompatible);
|
||||
if (errCode != RET_OK) {
|
||||
RELEASE_CALLBACKINFO(cb->env, cb->ref);
|
||||
}
|
||||
@ -75,14 +74,14 @@ napi_value JsCoordinationManager::Activate(napi_env env, const std::string &remo
|
||||
}
|
||||
|
||||
napi_value JsCoordinationManager::Deactivate(napi_env env,
|
||||
bool isUnchained, bool isCheckPermission, napi_value handle)
|
||||
bool isUnchained, bool isCompatible, napi_value handle)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
sptr<JsUtil::CallbackInfo> cb = new (std::nothrow) JsUtil::CallbackInfo();
|
||||
CHKPP(cb);
|
||||
napi_value result = CreateCallbackInfo(env, handle, cb);
|
||||
auto callback = std::bind(EmitJsDeactivate, cb, std::placeholders::_1, std::placeholders::_2);
|
||||
int32_t errCode = INTERACTION_MGR->DeactivateCoordination(isUnchained, callback, isCheckPermission);
|
||||
int32_t errCode = INTERACTION_MGR->DeactivateCoordination(isUnchained, callback, isCompatible);
|
||||
if (errCode != RET_OK) {
|
||||
RELEASE_CALLBACKINFO(cb->env, cb->ref);
|
||||
}
|
||||
@ -91,14 +90,14 @@ napi_value JsCoordinationManager::Deactivate(napi_env env,
|
||||
}
|
||||
|
||||
napi_value JsCoordinationManager::GetCrossingSwitchState(napi_env env,
|
||||
const std::string &networkId, bool isCheckPermission, napi_value handle)
|
||||
const std::string &networkId, bool isCompatible, napi_value handle)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
sptr<JsUtil::CallbackInfo> cb = new (std::nothrow) JsUtil::CallbackInfo();
|
||||
CHKPP(cb);
|
||||
napi_value result = CreateCallbackInfo(env, handle, cb);
|
||||
auto callback = std::bind(EmitJsGetCrossingSwitchState, cb, std::placeholders::_1);
|
||||
int32_t errCode = INTERACTION_MGR->GetCoordinationState(networkId, callback, isCheckPermission);
|
||||
int32_t errCode = INTERACTION_MGR->GetCoordinationState(networkId, callback, isCompatible);
|
||||
if (errCode != RET_OK) {
|
||||
RELEASE_CALLBACKINFO(cb->env, cb->ref);
|
||||
}
|
||||
|
@ -157,9 +157,9 @@ void JsEventTarget::AddListener(napi_env env, const std::string &type, napi_valu
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
std::string listenerType = type;
|
||||
bool isCheckPermission = false;
|
||||
bool isCompatible = false;
|
||||
if (type == COOPERATE_MESSAGE_NAME) {
|
||||
isCheckPermission = true;
|
||||
isCompatible = true;
|
||||
listenerType = COOPERATE_NAME;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
@ -186,7 +186,7 @@ void JsEventTarget::AddListener(napi_env env, const std::string &type, napi_valu
|
||||
iter->second.push_back(monitor);
|
||||
if (!isListeningProcess_) {
|
||||
isListeningProcess_ = true;
|
||||
INTERACTION_MGR->RegisterCoordinationListener(shared_from_this(), isCheckPermission);
|
||||
INTERACTION_MGR->RegisterCoordinationListener(shared_from_this(), isCompatible);
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,9 +194,9 @@ void JsEventTarget::RemoveListener(napi_env env, const std::string &type, napi_v
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
std::string listenerType = type;
|
||||
bool isCheckPermission = false;
|
||||
bool isCompatible = false;
|
||||
if (type == COOPERATE_MESSAGE_NAME) {
|
||||
isCheckPermission = true;
|
||||
isCompatible = true;
|
||||
listenerType = COOPERATE_NAME;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
@ -220,7 +220,7 @@ void JsEventTarget::RemoveListener(napi_env env, const std::string &type, napi_v
|
||||
MONITOR_LABEL:
|
||||
if (iter->second.empty() && isListeningProcess_) {
|
||||
isListeningProcess_ = false;
|
||||
INTERACTION_MGR->UnregisterCoordinationListener(shared_from_this(), isCheckPermission);
|
||||
INTERACTION_MGR->UnregisterCoordinationListener(shared_from_this(), isCompatible);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,9 @@ import("../../../../../device_status.gni")
|
||||
|
||||
ohos_shared_library("draginteraction") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
static napi_value Export(napi_env env, napi_value exports);
|
||||
static napi_value On(napi_env env, napi_callback_info info);
|
||||
static napi_value Off(napi_env env, napi_callback_info info);
|
||||
static napi_value GetDataSummary(napi_env env, napi_callback_info info);
|
||||
|
||||
private:
|
||||
static napi_value CreateInstance(napi_env env);
|
||||
|
@ -42,6 +42,7 @@ public:
|
||||
void OnDragMessage(DragState state) override;
|
||||
void RegisterListener(napi_env env, napi_value handle);
|
||||
void UnregisterListener(napi_env env, napi_value handle = nullptr);
|
||||
napi_value GetDataSummary(napi_env env);
|
||||
|
||||
private:
|
||||
struct CallbackInfo : public RefBase {
|
||||
|
@ -217,6 +217,16 @@ napi_value JsDragContext::Off(napi_env env, napi_callback_info info)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value JsDragContext::GetDataSummary(napi_env env, napi_callback_info info)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
JsDragContext *jsDev = JsDragContext::GetInstance(env);
|
||||
CHKPP(jsDev);
|
||||
auto jsDragMgr = jsDev->GetJsDragMgr();
|
||||
CHKPP(jsDragMgr);
|
||||
return jsDragMgr->GetDataSummary(env);
|
||||
}
|
||||
|
||||
void JsDragContext::DeclareDragData(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_value startMsg = nullptr;
|
||||
@ -245,7 +255,8 @@ void JsDragContext::DeclareDragInterface(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_property_descriptor functions[] = {
|
||||
DECLARE_NAPI_STATIC_FUNCTION("on", On),
|
||||
DECLARE_NAPI_STATIC_FUNCTION("off", Off)
|
||||
DECLARE_NAPI_STATIC_FUNCTION("off", Off),
|
||||
DECLARE_NAPI_STATIC_FUNCTION("getDataSummary", GetDataSummary)
|
||||
};
|
||||
CHKRV(napi_define_properties(env, exports,
|
||||
sizeof(functions) / sizeof(*functions), functions), DEFINE_PROPERTIES);
|
||||
|
@ -48,6 +48,32 @@ bool JsDragManager::IsSameHandle(napi_env env, napi_value handle, napi_ref ref)
|
||||
return isEqual;
|
||||
}
|
||||
|
||||
napi_value JsDragManager::GetDataSummary(napi_env env)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
std::map<std::string, int64_t> summarys;
|
||||
if (INTERACTION_MGR->GetDragSummary(summarys) != RET_OK) {
|
||||
FI_HILOGE("Failed to GetDragSummary");
|
||||
return nullptr;
|
||||
}
|
||||
napi_value arr = nullptr;
|
||||
CHKRP(napi_create_array(env, &arr), CREATE_ARRAY);
|
||||
uint32_t index = 0;
|
||||
for (const auto &summary : summarys) {
|
||||
napi_value dataType = nullptr;
|
||||
CHKRP(napi_create_string_utf8(env, summary.first.c_str(), NAPI_AUTO_LENGTH, &dataType), CREATE_STRING_UTF8);
|
||||
napi_value dataSize = nullptr;
|
||||
CHKRP(napi_create_int64(env, summary.second, &dataSize), CREATE_INT64);
|
||||
napi_value object = nullptr;
|
||||
CHKRP(napi_create_object(env, &object), CREATE_OBJECT);
|
||||
CHKRP(napi_set_named_property(env, object, "dataType", dataType), SET_NAMED_PROPERTY);
|
||||
CHKRP(napi_set_named_property(env, object, "dataSize", dataSize), SET_NAMED_PROPERTY);
|
||||
CHKRP(napi_set_element(env, arr, index, object), SET_ELEMENT);
|
||||
++index;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
void JsDragManager::RegisterListener(napi_env env, napi_value handle)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
|
@ -82,7 +82,7 @@ bool DeviceStatusEvent::SaveCallbackByEvent(int32_t eventType, napi_value handle
|
||||
}
|
||||
auto iter = events_.find(eventType);
|
||||
if (iter == events_.end()) {
|
||||
FI_HILOGE("EventType:%{public}d not exists", eventType);
|
||||
FI_HILOGE("eventType:%{public}d not exists", eventType);
|
||||
events_[eventType] = std::list<std::shared_ptr<DeviceStatusEventListener>>();
|
||||
}
|
||||
if (events_[eventType].empty()) {
|
||||
|
@ -45,15 +45,15 @@ public:
|
||||
CoordinationManagerImpl() = default;
|
||||
~CoordinationManagerImpl() = default;
|
||||
|
||||
int32_t RegisterCoordinationListener(CoordinationListenerPtr listener, bool isCheckPermission = false);
|
||||
int32_t UnregisterCoordinationListener(CoordinationListenerPtr listener, bool isCheckPermission = false);
|
||||
int32_t PrepareCoordination(FuncCoordinationMessage callback, bool isCheckPermission = false);
|
||||
int32_t UnprepareCoordination(FuncCoordinationMessage callback, bool isCheckPermission = false);
|
||||
int32_t RegisterCoordinationListener(CoordinationListenerPtr listener, bool isCompatible = false);
|
||||
int32_t UnregisterCoordinationListener(CoordinationListenerPtr listener, bool isCompatible = false);
|
||||
int32_t PrepareCoordination(FuncCoordinationMessage callback, bool isCompatible = false);
|
||||
int32_t UnprepareCoordination(FuncCoordinationMessage callback, bool isCompatible = false);
|
||||
int32_t ActivateCoordination(const std::string &remoteNetworkId, int32_t startDeviceId,
|
||||
FuncCoordinationMessage callback, bool isCheckPermission = false);
|
||||
int32_t DeactivateCoordination(bool isUnchained, FuncCoordinationMessage callback, bool isCheckPermission = false);
|
||||
FuncCoordinationMessage callback, bool isCompatible = false);
|
||||
int32_t DeactivateCoordination(bool isUnchained, FuncCoordinationMessage callback, bool isCompatible = false);
|
||||
int32_t GetCoordinationState(const std::string &networkId,
|
||||
FuncCoordinationState callback, bool isCheckPermission = false);
|
||||
FuncCoordinationState callback, bool isCompatible = false);
|
||||
void OnDevCoordinationListener(const std::string networkId, CoordinationMessage msg);
|
||||
void OnCoordinationMessageEvent(int32_t userData, const std::string networkId, CoordinationMessage msg);
|
||||
void OnCoordinationStateEvent(int32_t userData, bool state);
|
||||
|
@ -62,6 +62,7 @@ public:
|
||||
int32_t EnterTextEditorArea(bool enable);
|
||||
int32_t GetDragAction(DragAction &dragAction);
|
||||
int32_t GetExtraInfo(std::string &extraInfo);
|
||||
int32_t AddPrivilege();
|
||||
|
||||
private:
|
||||
std::mutex mtx_;
|
||||
|
@ -34,19 +34,19 @@ public:
|
||||
DISALLOW_MOVE(InteractionManagerImpl);
|
||||
bool InitClient();
|
||||
int32_t RegisterCoordinationListener(
|
||||
std::shared_ptr<ICoordinationListener> listener, bool isCheckPermission = false);
|
||||
std::shared_ptr<ICoordinationListener> listener, bool isCompatible = false);
|
||||
int32_t UnregisterCoordinationListener(
|
||||
std::shared_ptr<ICoordinationListener> listener, bool isCheckPermission = false);
|
||||
std::shared_ptr<ICoordinationListener> listener, bool isCompatible = false);
|
||||
int32_t PrepareCoordination(
|
||||
std::function<void(std::string, CoordinationMessage)> callback, bool isCheckPermission = false);
|
||||
std::function<void(std::string, CoordinationMessage)> callback, bool isCompatible = false);
|
||||
int32_t UnprepareCoordination(
|
||||
std::function<void(std::string, CoordinationMessage)> callback, bool isCheckPermission = false);
|
||||
std::function<void(std::string, CoordinationMessage)> callback, bool isCompatible = false);
|
||||
int32_t ActivateCoordination(const std::string &remoteNetworkId, int32_t startDeviceId,
|
||||
std::function<void(std::string, CoordinationMessage)> callback, bool isCheckPermission = false);
|
||||
std::function<void(std::string, CoordinationMessage)> callback, bool isCompatible = false);
|
||||
int32_t DeactivateCoordination(bool isUnchained, std::function<void(std::string, CoordinationMessage)> callback,
|
||||
bool isCheckPermission = false);
|
||||
bool isCompatible = false);
|
||||
int32_t GetCoordinationState(const std::string &networkId, std::function<void(bool)> callback,
|
||||
bool isCheckPermission = false);
|
||||
bool isCompatible = false);
|
||||
int32_t UpdateDragStyle(DragCursorStyle style);
|
||||
int32_t StartDrag(const DragData &dragData, std::shared_ptr<IStartDragListener> listener);
|
||||
int32_t StopDrag(const DragDropResult &dropResult);
|
||||
@ -69,6 +69,7 @@ public:
|
||||
int32_t EnterTextEditorArea(bool enable);
|
||||
int32_t GetDragAction(DragAction &dragAction);
|
||||
int32_t GetExtraInfo(std::string &extraInfo);
|
||||
int32_t AddPrivilege();
|
||||
|
||||
private:
|
||||
void InitMsgHandler();
|
||||
|
@ -26,7 +26,7 @@ namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "CoordinationManagerImpl" };
|
||||
} // namespace
|
||||
|
||||
int32_t CoordinationManagerImpl::RegisterCoordinationListener(CoordinationListenerPtr listener, bool isCheckPermission)
|
||||
int32_t CoordinationManagerImpl::RegisterCoordinationListener(CoordinationListenerPtr listener, bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CHKPR(listener, RET_ERR);
|
||||
@ -39,7 +39,7 @@ int32_t CoordinationManagerImpl::RegisterCoordinationListener(CoordinationListen
|
||||
}
|
||||
if (!isListeningProcess_) {
|
||||
FI_HILOGI("Start monitoring");
|
||||
int32_t ret = DeviceStatusClient::GetInstance().RegisterCoordinationListener(isCheckPermission);
|
||||
int32_t ret = DeviceStatusClient::GetInstance().RegisterCoordinationListener(isCompatible);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Failed to register, ret:%{public}d", ret);
|
||||
return ret;
|
||||
@ -51,7 +51,7 @@ int32_t CoordinationManagerImpl::RegisterCoordinationListener(CoordinationListen
|
||||
}
|
||||
|
||||
int32_t CoordinationManagerImpl::UnregisterCoordinationListener(
|
||||
CoordinationListenerPtr listener, bool isCheckPermission)
|
||||
CoordinationListenerPtr listener, bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
@ -69,12 +69,12 @@ int32_t CoordinationManagerImpl::UnregisterCoordinationListener(
|
||||
LISTENER_LABEL:
|
||||
if (isListeningProcess_ && devCoordinationListener_.empty()) {
|
||||
isListeningProcess_ = false;
|
||||
return DeviceStatusClient::GetInstance().UnregisterCoordinationListener(isCheckPermission);
|
||||
return DeviceStatusClient::GetInstance().UnregisterCoordinationListener(isCompatible);
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t CoordinationManagerImpl::PrepareCoordination(FuncCoordinationMessage callback, bool isCheckPermission)
|
||||
int32_t CoordinationManagerImpl::PrepareCoordination(FuncCoordinationMessage callback, bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
@ -84,7 +84,7 @@ int32_t CoordinationManagerImpl::PrepareCoordination(FuncCoordinationMessage cal
|
||||
FI_HILOGE("userData exceeds the maximum");
|
||||
return RET_ERR;
|
||||
}
|
||||
int32_t ret = DeviceStatusClient::GetInstance().PrepareCoordination(userData_, isCheckPermission);
|
||||
int32_t ret = DeviceStatusClient::GetInstance().PrepareCoordination(userData_, isCompatible);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Prepare coordination failed");
|
||||
return ret;
|
||||
@ -94,7 +94,7 @@ int32_t CoordinationManagerImpl::PrepareCoordination(FuncCoordinationMessage cal
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t CoordinationManagerImpl::UnprepareCoordination(FuncCoordinationMessage callback, bool isCheckPermission)
|
||||
int32_t CoordinationManagerImpl::UnprepareCoordination(FuncCoordinationMessage callback, bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CoordinationEvent event;
|
||||
@ -104,7 +104,7 @@ int32_t CoordinationManagerImpl::UnprepareCoordination(FuncCoordinationMessage c
|
||||
FI_HILOGE("userData exceeds the maximum");
|
||||
return RET_ERR;
|
||||
}
|
||||
int32_t ret = DeviceStatusClient::GetInstance().UnprepareCoordination(userData_, isCheckPermission);
|
||||
int32_t ret = DeviceStatusClient::GetInstance().UnprepareCoordination(userData_, isCompatible);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Unprepare coordination failed");
|
||||
return ret;
|
||||
@ -115,7 +115,7 @@ int32_t CoordinationManagerImpl::UnprepareCoordination(FuncCoordinationMessage c
|
||||
}
|
||||
|
||||
int32_t CoordinationManagerImpl::ActivateCoordination(const std::string &remoteNetworkId,
|
||||
int32_t startDeviceId, FuncCoordinationMessage callback, bool isCheckPermission)
|
||||
int32_t startDeviceId, FuncCoordinationMessage callback, bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
@ -126,7 +126,7 @@ int32_t CoordinationManagerImpl::ActivateCoordination(const std::string &remoteN
|
||||
return RET_ERR;
|
||||
}
|
||||
int32_t ret = DeviceStatusClient::GetInstance().ActivateCoordination(
|
||||
userData_, remoteNetworkId, startDeviceId, isCheckPermission);
|
||||
userData_, remoteNetworkId, startDeviceId, isCompatible);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Activate coordination failed");
|
||||
return ret;
|
||||
@ -137,7 +137,7 @@ int32_t CoordinationManagerImpl::ActivateCoordination(const std::string &remoteN
|
||||
}
|
||||
|
||||
int32_t CoordinationManagerImpl::DeactivateCoordination(bool isUnchained, FuncCoordinationMessage callback,
|
||||
bool isCheckPermission)
|
||||
bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
@ -147,7 +147,7 @@ int32_t CoordinationManagerImpl::DeactivateCoordination(bool isUnchained, FuncCo
|
||||
FI_HILOGE("userData exceeds the maximum");
|
||||
return RET_ERR;
|
||||
}
|
||||
int32_t ret = DeviceStatusClient::GetInstance().DeactivateCoordination(userData_, isUnchained, isCheckPermission);
|
||||
int32_t ret = DeviceStatusClient::GetInstance().DeactivateCoordination(userData_, isUnchained, isCompatible);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Deactivate coordination failed");
|
||||
return ret;
|
||||
@ -158,7 +158,7 @@ int32_t CoordinationManagerImpl::DeactivateCoordination(bool isUnchained, FuncCo
|
||||
}
|
||||
|
||||
int32_t CoordinationManagerImpl::GetCoordinationState(
|
||||
const std::string &networkId, FuncCoordinationState callback, bool isCheckPermission)
|
||||
const std::string &networkId, FuncCoordinationState callback, bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
@ -168,7 +168,7 @@ int32_t CoordinationManagerImpl::GetCoordinationState(
|
||||
FI_HILOGE("userData exceeds the maximum");
|
||||
return RET_ERR;
|
||||
}
|
||||
int32_t ret = DeviceStatusClient::GetInstance().GetCoordinationState(userData_, networkId, isCheckPermission);
|
||||
int32_t ret = DeviceStatusClient::GetInstance().GetCoordinationState(userData_, networkId, isCompatible);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Get coordination state failed");
|
||||
return ret;
|
||||
|
@ -307,6 +307,11 @@ int32_t DragManagerImpl::GetExtraInfo(std::string &extraInfo)
|
||||
{
|
||||
return DeviceStatusClient::GetInstance().GetExtraInfo(extraInfo);
|
||||
}
|
||||
|
||||
int32_t DragManagerImpl::AddPrivilege()
|
||||
{
|
||||
return DeviceStatusClient::GetInstance().AddPrivilege();
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
@ -17,7 +17,11 @@
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
#include "drag_data.h"
|
||||
#ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
#include "intention_manager.h"
|
||||
#else
|
||||
#include "interaction_manager_impl.h"
|
||||
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
@ -31,45 +35,45 @@ InteractionManager *InteractionManager::GetInstance()
|
||||
}
|
||||
|
||||
int32_t InteractionManager::RegisterCoordinationListener(std::shared_ptr<ICoordinationListener> listener,
|
||||
bool isCheckPermission)
|
||||
bool isCompatible)
|
||||
{
|
||||
return INTER_MGR_IMPL.RegisterCoordinationListener(listener, isCheckPermission);
|
||||
return INTER_MGR_IMPL.RegisterCoordinationListener(listener, isCompatible);
|
||||
}
|
||||
|
||||
int32_t InteractionManager::UnregisterCoordinationListener(std::shared_ptr<ICoordinationListener> listener,
|
||||
bool isCheckPermission)
|
||||
bool isCompatible)
|
||||
{
|
||||
return INTER_MGR_IMPL.UnregisterCoordinationListener(listener, isCheckPermission);
|
||||
return INTER_MGR_IMPL.UnregisterCoordinationListener(listener, isCompatible);
|
||||
}
|
||||
|
||||
int32_t InteractionManager::PrepareCoordination(std::function<void(const std::string&, CoordinationMessage)> callback,
|
||||
bool isCheckPermission)
|
||||
bool isCompatible)
|
||||
{
|
||||
return INTER_MGR_IMPL.PrepareCoordination(callback, isCheckPermission);
|
||||
return INTER_MGR_IMPL.PrepareCoordination(callback, isCompatible);
|
||||
}
|
||||
|
||||
int32_t InteractionManager::UnprepareCoordination(std::function<void(const std::string&, CoordinationMessage)> callback,
|
||||
bool isCheckPermission)
|
||||
bool isCompatible)
|
||||
{
|
||||
return INTER_MGR_IMPL.UnprepareCoordination(callback, isCheckPermission);
|
||||
return INTER_MGR_IMPL.UnprepareCoordination(callback, isCompatible);
|
||||
}
|
||||
|
||||
int32_t InteractionManager::ActivateCoordination(const std::string &remoteNetworkId, int32_t startDeviceId,
|
||||
std::function<void(const std::string&, CoordinationMessage)> callback, bool isCheckPermission)
|
||||
std::function<void(const std::string&, CoordinationMessage)> callback, bool isCompatible)
|
||||
{
|
||||
return INTER_MGR_IMPL.ActivateCoordination(remoteNetworkId, startDeviceId, callback, isCheckPermission);
|
||||
return INTER_MGR_IMPL.ActivateCoordination(remoteNetworkId, startDeviceId, callback, isCompatible);
|
||||
}
|
||||
|
||||
int32_t InteractionManager::DeactivateCoordination(bool isUnchained,
|
||||
std::function<void(const std::string&, CoordinationMessage)> callback, bool isCheckPermission)
|
||||
std::function<void(const std::string&, CoordinationMessage)> callback, bool isCompatible)
|
||||
{
|
||||
return INTER_MGR_IMPL.DeactivateCoordination(isUnchained, callback, isCheckPermission);
|
||||
return INTER_MGR_IMPL.DeactivateCoordination(isUnchained, callback, isCompatible);
|
||||
}
|
||||
|
||||
int32_t InteractionManager::GetCoordinationState(
|
||||
const std::string &networkId, std::function<void(bool)> callback, bool isCheckPermission)
|
||||
const std::string &networkId, std::function<void(bool)> callback, bool isCompatible)
|
||||
{
|
||||
return INTER_MGR_IMPL.GetCoordinationState(networkId, callback, isCheckPermission);
|
||||
return INTER_MGR_IMPL.GetCoordinationState(networkId, callback, isCompatible);
|
||||
}
|
||||
|
||||
int32_t InteractionManager::UpdateDragStyle(DragCursorStyle style)
|
||||
@ -182,6 +186,11 @@ int32_t InteractionManager::GetExtraInfo(std::string &extraInfo)
|
||||
{
|
||||
return INTER_MGR_IMPL.GetExtraInfo(extraInfo);
|
||||
}
|
||||
|
||||
int32_t InteractionManager::AddPrivilege()
|
||||
{
|
||||
return INTER_MGR_IMPL.AddPrivilege();
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
@ -28,10 +28,8 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "Interac
|
||||
} // namespace
|
||||
|
||||
InteractionManagerImpl::InteractionManagerImpl() {}
|
||||
InteractionManagerImpl::~InteractionManagerImpl()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
}
|
||||
|
||||
InteractionManagerImpl::~InteractionManagerImpl() {}
|
||||
|
||||
bool InteractionManagerImpl::InitClient()
|
||||
{
|
||||
@ -82,7 +80,7 @@ void InteractionManagerImpl::InitMsgHandler()
|
||||
}
|
||||
|
||||
int32_t InteractionManagerImpl::RegisterCoordinationListener(std::shared_ptr<ICoordinationListener> listener,
|
||||
bool isCheckPermission)
|
||||
bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
@ -91,32 +89,32 @@ int32_t InteractionManagerImpl::RegisterCoordinationListener(std::shared_ptr<ICo
|
||||
FI_HILOGE("Get client is nullptr");
|
||||
return RET_ERR;
|
||||
}
|
||||
return coordinationManagerImpl_.RegisterCoordinationListener(listener, isCheckPermission);
|
||||
return coordinationManagerImpl_.RegisterCoordinationListener(listener, isCompatible);
|
||||
#else
|
||||
FI_HILOGW("Coordination does not support");
|
||||
(void)(listener);
|
||||
(void)(isCheckPermission);
|
||||
(void)(isCompatible);
|
||||
return ERROR_UNSUPPORT;
|
||||
#endif // OHOS_BUILD_ENABLE_COORDINATION
|
||||
}
|
||||
|
||||
int32_t InteractionManagerImpl::UnregisterCoordinationListener(std::shared_ptr<ICoordinationListener> listener,
|
||||
bool isCheckPermission)
|
||||
bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
return coordinationManagerImpl_.UnregisterCoordinationListener(listener, isCheckPermission);
|
||||
return coordinationManagerImpl_.UnregisterCoordinationListener(listener, isCompatible);
|
||||
#else
|
||||
FI_HILOGW("Coordination does not support");
|
||||
(void)(listener);
|
||||
(void)(isCheckPermission);
|
||||
(void)(isCompatible);
|
||||
return ERROR_UNSUPPORT;
|
||||
#endif // OHOS_BUILD_ENABLE_COORDINATION
|
||||
}
|
||||
|
||||
int32_t InteractionManagerImpl::PrepareCoordination(std::function<void(std::string, CoordinationMessage)> callback,
|
||||
bool isCheckPermission)
|
||||
bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
@ -125,17 +123,17 @@ int32_t InteractionManagerImpl::PrepareCoordination(std::function<void(std::stri
|
||||
FI_HILOGE("Get client is nullptr");
|
||||
return RET_ERR;
|
||||
}
|
||||
return coordinationManagerImpl_.PrepareCoordination(callback, isCheckPermission);
|
||||
return coordinationManagerImpl_.PrepareCoordination(callback, isCompatible);
|
||||
#else
|
||||
FI_HILOGW("Coordination does not support");
|
||||
(void)(callback);
|
||||
(void)(isCheckPermission);
|
||||
(void)(isCompatible);
|
||||
return ERROR_UNSUPPORT;
|
||||
#endif // OHOS_BUILD_ENABLE_COORDINATION
|
||||
}
|
||||
|
||||
int32_t InteractionManagerImpl::UnprepareCoordination(std::function<void(std::string, CoordinationMessage)> callback,
|
||||
bool isCheckPermission)
|
||||
bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
@ -144,17 +142,17 @@ int32_t InteractionManagerImpl::UnprepareCoordination(std::function<void(std::st
|
||||
FI_HILOGE("Get client is nullptr");
|
||||
return RET_ERR;
|
||||
}
|
||||
return coordinationManagerImpl_.UnprepareCoordination(callback, isCheckPermission);
|
||||
return coordinationManagerImpl_.UnprepareCoordination(callback, isCompatible);
|
||||
#else
|
||||
FI_HILOGW("Coordination does not support");
|
||||
(void)(callback);
|
||||
(void)(isCheckPermission);
|
||||
(void)(isCompatible);
|
||||
return ERROR_UNSUPPORT;
|
||||
#endif // OHOS_BUILD_ENABLE_COORDINATION
|
||||
}
|
||||
|
||||
int32_t InteractionManagerImpl::ActivateCoordination(const std::string &remoteNetworkId, int32_t startDeviceId,
|
||||
std::function<void(std::string, CoordinationMessage)> callback, bool isCheckPermission)
|
||||
std::function<void(std::string, CoordinationMessage)> callback, bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
@ -163,19 +161,19 @@ int32_t InteractionManagerImpl::ActivateCoordination(const std::string &remoteNe
|
||||
FI_HILOGE("Get client is nullptr");
|
||||
return RET_ERR;
|
||||
}
|
||||
return coordinationManagerImpl_.ActivateCoordination(remoteNetworkId, startDeviceId, callback, isCheckPermission);
|
||||
return coordinationManagerImpl_.ActivateCoordination(remoteNetworkId, startDeviceId, callback, isCompatible);
|
||||
#else
|
||||
FI_HILOGW("Coordination does not support");
|
||||
(void)(remoteNetworkId);
|
||||
(void)(startDeviceId);
|
||||
(void)(callback);
|
||||
(void)(isCheckPermission);
|
||||
(void)(isCompatible);
|
||||
return ERROR_UNSUPPORT;
|
||||
#endif // OHOS_BUILD_ENABLE_COORDINATION
|
||||
}
|
||||
|
||||
int32_t InteractionManagerImpl::DeactivateCoordination(bool isUnchained,
|
||||
std::function<void(std::string, CoordinationMessage)> callback, bool isCheckPermission)
|
||||
std::function<void(std::string, CoordinationMessage)> callback, bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
@ -184,17 +182,17 @@ int32_t InteractionManagerImpl::DeactivateCoordination(bool isUnchained,
|
||||
FI_HILOGE("Get client is nullptr");
|
||||
return RET_ERR;
|
||||
}
|
||||
return coordinationManagerImpl_.DeactivateCoordination(isUnchained, callback, isCheckPermission);
|
||||
return coordinationManagerImpl_.DeactivateCoordination(isUnchained, callback, isCompatible);
|
||||
#else
|
||||
FI_HILOGW("Coordination does not support");
|
||||
(void)(callback);
|
||||
(void)(isCheckPermission);
|
||||
(void)(isCompatible);
|
||||
return ERROR_UNSUPPORT;
|
||||
#endif // OHOS_BUILD_ENABLE_COORDINATION
|
||||
}
|
||||
|
||||
int32_t InteractionManagerImpl::GetCoordinationState(
|
||||
const std::string &networkId, std::function<void(bool)> callback, bool isCheckPermission)
|
||||
const std::string &networkId, std::function<void(bool)> callback, bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
@ -203,11 +201,11 @@ int32_t InteractionManagerImpl::GetCoordinationState(
|
||||
FI_HILOGE("Get client is nullptr");
|
||||
return RET_ERR;
|
||||
}
|
||||
return coordinationManagerImpl_.GetCoordinationState(networkId, callback, isCheckPermission);
|
||||
return coordinationManagerImpl_.GetCoordinationState(networkId, callback, isCompatible);
|
||||
#else
|
||||
(void)(networkId);
|
||||
(void)(callback);
|
||||
(void)(isCheckPermission);
|
||||
(void)(isCompatible);
|
||||
FI_HILOGW("Coordination does not support");
|
||||
return ERROR_UNSUPPORT;
|
||||
#endif // OHOS_BUILD_ENABLE_COORDINATION
|
||||
@ -378,6 +376,12 @@ int32_t InteractionManagerImpl::EnterTextEditorArea(bool enable)
|
||||
CALL_DEBUG_ENTER;
|
||||
return dragManagerImpl_.EnterTextEditorArea(enable);
|
||||
}
|
||||
|
||||
int32_t InteractionManagerImpl::AddPrivilege()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return dragManagerImpl_.AddPrivilege();
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
@ -69,8 +69,8 @@ public:
|
||||
void TearDown();
|
||||
static void SetUpTestCase();
|
||||
static std::shared_ptr<Media::PixelMap> CreatePixelMap(int32_t width, int32_t height);
|
||||
static std::optional<DragData> CreateDragData(int32_t sourceType, int32_t pointerId,
|
||||
int32_t dragNum, int32_t shadowNum);
|
||||
static std::optional<DragData> CreateDragData(int32_t sourceType, int32_t pointerId, int32_t dragNum,
|
||||
bool hasCoordinateCorrected, int32_t shadowNum);
|
||||
};
|
||||
|
||||
void InteractionDragDrawingTest::SetUpTestCase() {}
|
||||
@ -138,7 +138,7 @@ private:
|
||||
};
|
||||
|
||||
std::optional<DragData> InteractionDragDrawingTest::CreateDragData(int32_t sourceType,
|
||||
int32_t pointerId, int32_t dragNum, int32_t shadowNum)
|
||||
int32_t pointerId, int32_t dragNum, bool hasCoordinateCorrected, int32_t shadowNum)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DragData dragData;
|
||||
@ -161,6 +161,7 @@ std::optional<DragData> InteractionDragDrawingTest::CreateDragData(int32_t sourc
|
||||
dragData.displayY = DISPLAY_Y;
|
||||
dragData.displayId = DISPLAY_ID;
|
||||
dragData.hasCanceledAnimation = HAS_CANCELED_ANIMATION;
|
||||
dragData.hasCoordinateCorrected = hasCoordinateCorrected;
|
||||
return dragData;
|
||||
}
|
||||
|
||||
@ -174,7 +175,7 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Mouse_DragNum_On
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::optional<DragData> dragData = CreateDragData(
|
||||
MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, SHADOW_NUM_ONE);
|
||||
MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
|
||||
ASSERT_TRUE(dragData);
|
||||
std::promise<bool> promiseFlag;
|
||||
std::future<bool> futureFlag = promiseFlag.get_future();
|
||||
@ -226,7 +227,7 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Mouse_DragNum_Mu
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
std::optional<DragData> dragData = CreateDragData(
|
||||
MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_MULTIPLE, SHADOW_NUM_ONE);
|
||||
MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_MULTIPLE, false, SHADOW_NUM_ONE);
|
||||
ASSERT_TRUE(dragData);
|
||||
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
|
||||
std::make_shared<TestStartDragListener>(callback));
|
||||
@ -271,7 +272,7 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Touchscreen_Drag
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
std::optional<DragData> dragData = CreateDragData(
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, SHADOW_NUM_ONE);
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
|
||||
ASSERT_TRUE(dragData);
|
||||
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
|
||||
std::make_shared<TestStartDragListener>(callback));
|
||||
@ -306,7 +307,7 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Touchscreen_Drag
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::optional<DragData> dragData = CreateDragData(
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_MULTIPLE, SHADOW_NUM_ONE);
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_MULTIPLE, false, SHADOW_NUM_ONE);
|
||||
ASSERT_TRUE(dragData);
|
||||
std::promise<bool> promiseFlag;
|
||||
std::future<bool> futureFlag = promiseFlag.get_future();
|
||||
@ -355,7 +356,7 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_UpdateShadowPic,
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
std::optional<DragData> dragData = CreateDragData(
|
||||
MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, SHADOW_NUM_ONE);
|
||||
MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
|
||||
ASSERT_TRUE(dragData);
|
||||
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
|
||||
std::make_shared<TestStartDragListener>(callback));
|
||||
@ -393,7 +394,7 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Mouse_Animation,
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
std::optional<DragData> dragData = CreateDragData(
|
||||
MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, SHADOW_NUM_ONE);
|
||||
MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
|
||||
ASSERT_TRUE(dragData);
|
||||
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
|
||||
std::make_shared<TestStartDragListener>(callback));
|
||||
@ -426,7 +427,7 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Touchscreen_Anim
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
std::optional<DragData> dragData = CreateDragData(
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, SHADOW_NUM_ONE);
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
|
||||
ASSERT_TRUE(dragData);
|
||||
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
|
||||
std::make_shared<TestStartDragListener>(callback));
|
||||
@ -458,7 +459,7 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_ONE_Shadow, Test
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
std::optional<DragData> dragData = CreateDragData(
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, SHADOW_NUM_ONE);
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
|
||||
ASSERT_TRUE(dragData);
|
||||
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
|
||||
std::make_shared<TestStartDragListener>(callback));
|
||||
@ -490,7 +491,7 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Multiple_Shadow,
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
std::optional<DragData> dragData = CreateDragData(
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, SHADOW_NUM_MULTIPLE);
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_MULTIPLE);
|
||||
ASSERT_TRUE(dragData);
|
||||
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
|
||||
std::make_shared<TestStartDragListener>(callback));
|
||||
@ -522,7 +523,7 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Too_Much_Shadow,
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
std::optional<DragData> dragData = CreateDragData(
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, SHADOW_NUM_TOO_MUCH);
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_TOO_MUCH);
|
||||
ASSERT_TRUE(dragData);
|
||||
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
|
||||
std::make_shared<TestStartDragListener>(callback));
|
||||
@ -554,7 +555,7 @@ HWTEST_F(InteractionDragDrawingTest, EnterTextEditorArea001, TestSize.Level1)
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
std::optional<DragData> dragData = CreateDragData(
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, SHADOW_NUM_ONE);
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
|
||||
ASSERT_TRUE(dragData);
|
||||
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
|
||||
std::make_shared<TestStartDragListener>(callback));
|
||||
@ -587,7 +588,7 @@ HWTEST_F(InteractionDragDrawingTest, EnterTextEditorArea002, TestSize.Level1)
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
std::optional<DragData> dragData = CreateDragData(
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, SHADOW_NUM_ONE);
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
|
||||
ASSERT_TRUE(dragData);
|
||||
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
|
||||
std::make_shared<TestStartDragListener>(callback));
|
||||
@ -599,6 +600,22 @@ HWTEST_F(InteractionDragDrawingTest, EnterTextEditorArea002, TestSize.Level1)
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: EnterTextEditorArea003
|
||||
* @tc.desc: abnormal test for pixelMap 8dp bit movement effect
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(InteractionDragDrawingTest, EnterTextEditorArea003, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::optional<DragData> dragData = CreateDragData(
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, true, SHADOW_NUM_ONE);
|
||||
ASSERT_TRUE(dragData);
|
||||
int32_t ret = InteractionManager::GetInstance()->EnterTextEditorArea(true);
|
||||
EXPECT_EQ(ret, RET_ERR);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
@ -47,7 +47,6 @@ constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
|
||||
constexpr int32_t TIME_WAIT_FOR_INJECT_MS { 80 };
|
||||
constexpr int32_t TIME_WAIT_FOR_TOUCH_DOWN_MS { 1000 };
|
||||
constexpr int32_t PROMISE_WAIT_SPAN_MS { 2000 };
|
||||
constexpr int32_t TIME_WAIT_FOR_NOTIFY_LINSTER { 600 };
|
||||
constexpr int32_t TEST_PIXEL_MAP_WIDTH { 200 };
|
||||
constexpr int32_t TEST_PIXEL_MAP_HEIGHT { 200 };
|
||||
constexpr int32_t MAX_PIXEL_MAP_WIDTH { 600 };
|
||||
@ -73,14 +72,14 @@ constexpr bool HAS_CUSTOM_ANIMATION { true };
|
||||
constexpr int32_t MOVE_STEP { 10 };
|
||||
constexpr int32_t FOREGROUND_COLOR_IN { 0x33FF0000 };
|
||||
constexpr int32_t FOREGROUND_COLOR_OUT { 0x00000000 };
|
||||
constexpr int32_t RADIUS_IN { 42 };
|
||||
constexpr int32_t RADIUS_OUT { 42 };
|
||||
constexpr int32_t ANIMATION_DURATION { 500 };
|
||||
constexpr int64_t DOWN_TIME { 1 };
|
||||
const std::string UD_KEY { "Unified data key" };
|
||||
const std::string EXTRA_INFO { "{ \"drag_allow_distributed\" : false }" };
|
||||
const std::string SYSTEM_CORE { "system_core" };
|
||||
const std::string SYSTEM_BASIC { "system_basic" };
|
||||
const std::string CURVE_NAME { "cubic-bezier" };
|
||||
const std::string EXTRA_INFO { "{ \"drag_corner_radius\": 20, \"drag_allow_distributed\": false }" };
|
||||
const std::string FILTER_INFO { "{ \"dip_scale\": 3.5 }" };
|
||||
int32_t g_deviceMouseId { -1 };
|
||||
int32_t g_deviceTouchId { -1 };
|
||||
int32_t g_screenWidth { 720 };
|
||||
@ -122,6 +121,7 @@ public:
|
||||
static void SimulateDownKeyEvent(int32_t key);
|
||||
static void SimulateUpKeyEvent(int32_t key);
|
||||
static void PrintDragAction(DragAction dragAction);
|
||||
static void AssignToAnimation(PreviewAnimation &animation);
|
||||
};
|
||||
|
||||
void InteractionManagerTest::SetPermission(const std::string &level, const char** perms, size_t permAmount)
|
||||
@ -191,15 +191,9 @@ private:
|
||||
class SubscriptListenerTest : public ISubscriptListener {
|
||||
public:
|
||||
SubscriptListenerTest() {}
|
||||
explicit SubscriptListenerTest(const std::string& name) : moduleName_(name)
|
||||
{
|
||||
futureFlag_ = promiseFlag_.get_future();
|
||||
}
|
||||
explicit SubscriptListenerTest(const std::string& name) : moduleName_(name) {}
|
||||
void OnMessage(DragCursorStyle style) override
|
||||
{
|
||||
if (style != dragStyle_) {
|
||||
promiseFlag_.set_value(true);
|
||||
}
|
||||
SetDragSyle(style);
|
||||
if (moduleName_.empty()) {
|
||||
moduleName_ = std::string("SubscriptListenerTest");
|
||||
@ -235,10 +229,6 @@ private:
|
||||
return type;
|
||||
}
|
||||
|
||||
public:
|
||||
std::promise<bool> promiseFlag_;
|
||||
std::future<bool> futureFlag_;
|
||||
|
||||
private:
|
||||
DragCursorStyle dragStyle_ { DragCursorStyle::DEFAULT };
|
||||
std::string moduleName_;
|
||||
@ -374,6 +364,8 @@ std::optional<DragData> InteractionManagerTest::CreateDragData(const std::pair<i
|
||||
dragData.displayY = location.second;
|
||||
dragData.displayId = displayId;
|
||||
dragData.hasCanceledAnimation = HAS_CANCELED_ANIMATION;
|
||||
dragData.extraInfo = EXTRA_INFO;
|
||||
dragData.filterInfo = FILTER_INFO;
|
||||
return dragData;
|
||||
}
|
||||
|
||||
@ -566,6 +558,13 @@ void InteractionManagerTest::PrintDragAction(DragAction dragAction)
|
||||
}
|
||||
}
|
||||
|
||||
void InteractionManagerTest::AssignToAnimation(PreviewAnimation &animation)
|
||||
{
|
||||
animation.duration = ANIMATION_DURATION;
|
||||
animation.curveName = CURVE_NAME;
|
||||
animation.curve = { 0.33, 0, 0.67, 1 };
|
||||
}
|
||||
|
||||
class InputEventCallbackTest : public MMI::IInputEventConsumer {
|
||||
public:
|
||||
InputEventCallbackTest() {}
|
||||
@ -603,8 +602,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_RegisterCoordinationList
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_BASIC, g_basics, sizeof(g_basics) / sizeof(g_basics[0]));
|
||||
std::shared_ptr<ICoordinationListener> consumer = nullptr;
|
||||
bool isCheckPermission = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->RegisterCoordinationListener(consumer, isCheckPermission);
|
||||
bool isCompatible = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->RegisterCoordinationListener(consumer, isCompatible);
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
ASSERT_EQ(ret, RET_ERR);
|
||||
#else
|
||||
@ -634,14 +633,14 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_RegisterCoordinationList
|
||||
};
|
||||
std::shared_ptr<CoordinationListenerTest> consumer =
|
||||
std::make_shared<CoordinationListenerTest>();
|
||||
bool isCheckPermission = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->RegisterCoordinationListener(consumer, isCheckPermission);
|
||||
bool isCompatible = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->RegisterCoordinationListener(consumer, isCompatible);
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
#else
|
||||
ASSERT_EQ(ret, ERROR_UNSUPPORT);
|
||||
#endif // OHOS_BUILD_ENABLE_COORDINATION
|
||||
ret = InteractionManager::GetInstance()->UnregisterCoordinationListener(consumer, isCheckPermission);
|
||||
ret = InteractionManager::GetInstance()->UnregisterCoordinationListener(consumer, isCompatible);
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
#else
|
||||
@ -661,8 +660,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_UnregisterCoordinationLi
|
||||
CALL_TEST_DEBUG;
|
||||
SetPermission(SYSTEM_BASIC, g_basics, sizeof(g_basics) / sizeof(g_basics[0]));
|
||||
std::shared_ptr<ICoordinationListener> consumer = nullptr;
|
||||
bool isCheckPermission = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->UnregisterCoordinationListener(consumer, isCheckPermission);
|
||||
bool isCompatible = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->UnregisterCoordinationListener(consumer, isCompatible);
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
#else
|
||||
@ -687,8 +686,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_PrepareCoordination, Tes
|
||||
FI_HILOGD("Prepare coordination success, listener:%{public}s", listener.c_str());
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
bool isCheckPermission = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->PrepareCoordination(fun, isCheckPermission);
|
||||
bool isCompatible = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->PrepareCoordination(fun, isCompatible);
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
|
||||
@ -714,8 +713,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_UnprepareCoordination, T
|
||||
FI_HILOGD("Prepare coordination success, listener:%{public}s", listener.c_str());
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
bool isCheckPermission = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->UnprepareCoordination(fun, isCheckPermission);
|
||||
bool isCompatible = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->UnprepareCoordination(fun, isCompatible);
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
|
||||
@ -741,9 +740,9 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_ActivateCoordination, Te
|
||||
FI_HILOGD("Start coordination success");
|
||||
(void) listener;
|
||||
};
|
||||
bool isCheckPermission = true;
|
||||
bool isCompatible = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->ActivateCoordination(remoteNetworkId, startDeviceId,
|
||||
fun, isCheckPermission);
|
||||
fun, isCompatible);
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
ASSERT_NE(ret, RET_OK);
|
||||
#else
|
||||
@ -766,13 +765,13 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_DeactivateCoordination,
|
||||
FI_HILOGD("Stop coordination success");
|
||||
(void) listener;
|
||||
};
|
||||
bool isCheckPermission = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->DeactivateCoordination(false, fun, isCheckPermission);
|
||||
bool isCompatible = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->DeactivateCoordination(false, fun, isCompatible);
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
ASSERT_NE(ret, RET_OK);
|
||||
#else
|
||||
ASSERT_EQ(ret, ERROR_UNSUPPORT);
|
||||
ret = InteractionManager::GetInstance()->DeactivateCoordination(true, fun, isCheckPermission);
|
||||
ret = InteractionManager::GetInstance()->DeactivateCoordination(true, fun, isCompatible);
|
||||
ASSERT_EQ(ret, ERROR_UNSUPPORT);
|
||||
#endif // OHOS_BUILD_ENABLE_COORDINATION
|
||||
RemovePermission();
|
||||
@ -792,8 +791,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_GetCoordinationState_Abn
|
||||
auto fun = [](bool state) {
|
||||
FI_HILOGD("Get coordination state failed, state:%{public}d", state);
|
||||
};
|
||||
bool isCheckPermission = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->GetCoordinationState(networkId, fun, isCheckPermission);
|
||||
bool isCompatible = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->GetCoordinationState(networkId, fun, isCompatible);
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
ASSERT_NE(ret, RET_OK);
|
||||
#else
|
||||
@ -819,8 +818,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_GetCoordinationState_Nor
|
||||
FI_HILOGD("Get coordination state success, state:%{public}d", state);
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
bool isCheckPermission = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->GetCoordinationState(networkId, fun, isCheckPermission);
|
||||
bool isCompatible = true;
|
||||
int32_t ret = InteractionManager::GetInstance()->GetCoordinationState(networkId, fun, isCompatible);
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) != std::future_status::timeout);
|
||||
@ -1049,22 +1048,23 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_SubscriptListener_002, T
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
ret = InteractionManager::GetInstance()->SetDragWindowVisible(true);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
DragCursorStyle style = DragCursorStyle::DEFAULT;
|
||||
DragCursorStyle style = DragCursorStyle::COPY;
|
||||
ret = InteractionManager::GetInstance()->UpdateDragStyle(style);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
style = DragCursorStyle::MOVE;
|
||||
ret = InteractionManager::GetInstance()->UpdateDragStyle(style);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
|
||||
EXPECT_TRUE(listener->futureFlag_.wait_for(std::chrono::milliseconds(TIME_WAIT_FOR_NOTIFY_LINSTER)) !=
|
||||
std::future_status::timeout);
|
||||
DragCursorStyle recvStyle = listener->GetDragStyle();
|
||||
FI_HILOGD("Recived style:%{public}d, expected style:%{public}d", static_cast<int32_t>(recvStyle),
|
||||
static_cast<int32_t>(style));
|
||||
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
|
||||
SimulateUpPointerEvent(
|
||||
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
|
||||
InteractionManager::GetInstance()->StopDrag(dropResult);
|
||||
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
|
||||
std::future_status::timeout);
|
||||
DragCursorStyle recvStyle = listener->GetDragStyle();
|
||||
FI_HILOGD("Recived style:%{public}d, expected style:%{public}d", static_cast<int32_t>(recvStyle),
|
||||
static_cast<int32_t>(style));
|
||||
ret = InteractionManager::GetInstance()->RemoveSubscriptListener(listener);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
}
|
||||
@ -1371,9 +1371,12 @@ HWTEST_F(InteractionManagerTest, TouchEventDispatch, TestSize.Level1)
|
||||
if (g_deviceTouchId < 0) {
|
||||
ASSERT_TRUE(g_deviceTouchId < 0);
|
||||
} else {
|
||||
auto callback = [](const DragNotifyMsg& notifyMessage) {
|
||||
std::promise<bool> promiseFlag;
|
||||
std::future<bool> futureFlag = promiseFlag.get_future();
|
||||
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
|
||||
FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
|
||||
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
SimulateDownPointerEvent(
|
||||
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
|
||||
@ -1397,6 +1400,8 @@ HWTEST_F(InteractionManagerTest, TouchEventDispatch, TestSize.Level1)
|
||||
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
|
||||
ret = InteractionManager::GetInstance()->StopDrag(dropResult);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
|
||||
std::future_status::timeout);
|
||||
}
|
||||
RemovePermission();
|
||||
}
|
||||
@ -1414,9 +1419,12 @@ HWTEST_F(InteractionManagerTest, MouseEventDispatch, TestSize.Level1)
|
||||
if (g_deviceMouseId < 0) {
|
||||
ASSERT_TRUE(g_deviceMouseId < 0);
|
||||
} else {
|
||||
auto callback = [](const DragNotifyMsg& notifyMessage) {
|
||||
std::promise<bool> promiseFlag;
|
||||
std::future<bool> futureFlag = promiseFlag.get_future();
|
||||
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
|
||||
FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
|
||||
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
SimulateDownPointerEvent(
|
||||
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, 0);
|
||||
@ -1439,6 +1447,8 @@ HWTEST_F(InteractionManagerTest, MouseEventDispatch, TestSize.Level1)
|
||||
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
|
||||
ret = InteractionManager::GetInstance()->StopDrag(dropResult);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
|
||||
std::future_status::timeout);
|
||||
}
|
||||
RemovePermission();
|
||||
}
|
||||
@ -1855,17 +1865,15 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_UpdatePreviewStyle, Test
|
||||
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { enterPos.first, enterPos.second },
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
|
||||
PreviewStyle previewStyleIn;
|
||||
previewStyleIn.types = { PreviewType::FOREGROUND_COLOR, PreviewType::RADIUS };
|
||||
previewStyleIn.types = { PreviewType::FOREGROUND_COLOR };
|
||||
previewStyleIn.foregroundColor = FOREGROUND_COLOR_IN;
|
||||
previewStyleIn.radius = RADIUS_IN;
|
||||
ret = InteractionManager::GetInstance()->UpdatePreviewStyle(previewStyleIn);
|
||||
EXPECT_EQ(ret, RET_OK);
|
||||
SimulateMovePointerEvent({ enterPos.first, enterPos.second }, { leavePos.first, leavePos.second },
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
|
||||
PreviewStyle previewStyleOut;
|
||||
previewStyleOut.types = { PreviewType::FOREGROUND_COLOR, PreviewType::RADIUS };
|
||||
previewStyleOut.types = { PreviewType::FOREGROUND_COLOR };
|
||||
previewStyleOut.foregroundColor = FOREGROUND_COLOR_OUT;
|
||||
previewStyleOut.radius = RADIUS_OUT;
|
||||
ret = InteractionManager::GetInstance()->UpdatePreviewStyle(previewStyleOut);
|
||||
EXPECT_EQ(ret, RET_OK);
|
||||
SimulateMovePointerEvent({ leavePos.first, leavePos.second }, { DRAG_DST_X, DRAG_DST_Y },
|
||||
@ -1907,25 +1915,19 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_UpdatePreviewStyleWithAn
|
||||
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { enterPos.first, enterPos.second },
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
|
||||
PreviewStyle previewStyleIn;
|
||||
previewStyleIn.types = { PreviewType::FOREGROUND_COLOR, PreviewType::RADIUS };
|
||||
previewStyleIn.types = { PreviewType::FOREGROUND_COLOR };
|
||||
previewStyleIn.foregroundColor = FOREGROUND_COLOR_IN;
|
||||
previewStyleIn.radius = RADIUS_IN;
|
||||
PreviewAnimation animationIn;
|
||||
animationIn.duration = 500;
|
||||
animationIn.curveName = CURVE_NAME;
|
||||
animationIn.curve = { 0.33, 0, 0.67, 1 };
|
||||
AssignToAnimation(animationIn);
|
||||
ret = InteractionManager::GetInstance()->UpdatePreviewStyleWithAnimation(previewStyleIn, animationIn);
|
||||
EXPECT_EQ(ret, RET_OK);
|
||||
SimulateMovePointerEvent({ enterPos.first, enterPos.second }, { leavePos.first, leavePos.second },
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
|
||||
PreviewStyle previewStyleOut;
|
||||
previewStyleOut.types = { PreviewType::FOREGROUND_COLOR, PreviewType::RADIUS };
|
||||
previewStyleOut.types = { PreviewType::FOREGROUND_COLOR };
|
||||
previewStyleOut.foregroundColor = FOREGROUND_COLOR_OUT;
|
||||
previewStyleOut.radius = RADIUS_OUT;
|
||||
PreviewAnimation animationOut;
|
||||
animationOut.duration = 500;
|
||||
animationOut.curveName = CURVE_NAME;
|
||||
animationOut.curve = { 0.33, 0, 0.67, 1 };
|
||||
AssignToAnimation(animationOut);
|
||||
ret = InteractionManager::GetInstance()->UpdatePreviewStyleWithAnimation(previewStyleOut, animationOut);
|
||||
EXPECT_EQ(ret, RET_OK);
|
||||
SimulateMovePointerEvent({ leavePos.first, leavePos.second }, { DRAG_DST_X, DRAG_DST_Y },
|
||||
@ -1951,7 +1953,6 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_GetExtraInfo, TestSize.L
|
||||
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
|
||||
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
|
||||
ASSERT_TRUE(dragData);
|
||||
dragData->extraInfo = EXTRA_INFO;
|
||||
std::promise<bool> promiseFlag;
|
||||
std::future<bool> futureFlag = promiseFlag.get_future();
|
||||
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
|
||||
@ -2032,8 +2033,6 @@ HWTEST_F(InteractionManagerTest, GetDragAction_001, TestSize.Level1)
|
||||
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
SimulateDownPointerEvent(
|
||||
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
|
||||
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
|
||||
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
|
||||
ASSERT_TRUE(dragData);
|
||||
@ -2045,8 +2044,6 @@ HWTEST_F(InteractionManagerTest, GetDragAction_001, TestSize.Level1)
|
||||
EXPECT_EQ(ret, RET_OK);
|
||||
EXPECT_EQ(dragAction, DragAction::MOVE);
|
||||
PrintDragAction(dragAction);
|
||||
SimulateUpPointerEvent(
|
||||
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
|
||||
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
|
||||
InteractionManager::GetInstance()->StopDrag(dropResult);
|
||||
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
|
||||
@ -2071,15 +2068,15 @@ HWTEST_F(InteractionManagerTest, GetDragAction_002, TestSize.Level1)
|
||||
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
SimulateDownPointerEvent(
|
||||
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_INJECT_MS));
|
||||
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
|
||||
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
|
||||
ASSERT_TRUE(dragData);
|
||||
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
|
||||
std::make_shared<TestStartDragListener>(callback));
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
|
||||
SimulateDownKeyEvent(MMI::KeyEvent::KEYCODE_CTRL_LEFT);
|
||||
DragAction dragAction { DragAction::INVALID };
|
||||
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
|
||||
@ -2103,9 +2100,6 @@ HWTEST_F(InteractionManagerTest, GetDragAction_002, TestSize.Level1)
|
||||
EXPECT_EQ(dragAction, DragAction::MOVE);
|
||||
PrintDragAction(dragAction);
|
||||
ClearUpKeyEvent();
|
||||
SimulateUpPointerEvent(
|
||||
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_INJECT_MS));
|
||||
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
|
||||
InteractionManager::GetInstance()->StopDrag(dropResult);
|
||||
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
|
||||
@ -2113,6 +2107,155 @@ HWTEST_F(InteractionManagerTest, GetDragAction_002, TestSize.Level1)
|
||||
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
|
||||
EXPECT_EQ(ret, RET_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: InteractionManagerTest_GetDragAction_003
|
||||
* @tc.desc: Get drag action with simple press and release keyboard events of keys in start drag
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(InteractionManagerTest, GetDragAction_003, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
if (g_deviceMouseId < 0) {
|
||||
ASSERT_TRUE(g_deviceMouseId < 0);
|
||||
} else {
|
||||
int32_t ret = RET_ERR;
|
||||
std::promise<bool> promiseFlag;
|
||||
std::future<bool> futureFlag = promiseFlag.get_future();
|
||||
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
|
||||
FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
|
||||
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
|
||||
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
|
||||
ASSERT_TRUE(dragData);
|
||||
ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
|
||||
std::make_shared<TestStartDragListener>(callback));
|
||||
DragAction dragAction { DragAction::INVALID };
|
||||
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
|
||||
EXPECT_EQ(ret, RET_OK);
|
||||
EXPECT_EQ(dragAction, DragAction::MOVE);
|
||||
PrintDragAction(dragAction);
|
||||
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
|
||||
InteractionManager::GetInstance()->StopDrag(dropResult);
|
||||
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
|
||||
std::future_status::timeout);
|
||||
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
|
||||
EXPECT_EQ(ret, RET_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: InteractionManagerTest_GetDragAction_004
|
||||
* @tc.desc: Get drag action with multiple press and release keyboard events of keys in dragging
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(InteractionManagerTest, GetDragAction_004, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::promise<bool> promiseFlag;
|
||||
std::future<bool> futureFlag = promiseFlag.get_future();
|
||||
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
|
||||
FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
|
||||
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
|
||||
ASSERT_TRUE(dragData);
|
||||
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
|
||||
std::make_shared<TestStartDragListener>(callback));
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
|
||||
SimulateDownKeyEvent(MMI::KeyEvent::KEYCODE_CTRL_LEFT);
|
||||
SimulateDownKeyEvent(MMI::KeyEvent::KEYCODE_A);
|
||||
DragAction dragAction { DragAction::INVALID };
|
||||
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
|
||||
EXPECT_EQ(ret, RET_OK);
|
||||
EXPECT_EQ(dragAction, DragAction::COPY);
|
||||
SimulateUpKeyEvent(MMI::KeyEvent::KEYCODE_A);
|
||||
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
|
||||
EXPECT_EQ(ret, RET_OK);
|
||||
EXPECT_EQ(dragAction, DragAction::COPY);
|
||||
ClearUpKeyEvent();
|
||||
SimulateDownKeyEvent(MMI::KeyEvent::KEYCODE_B);
|
||||
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
|
||||
EXPECT_EQ(ret, RET_OK);
|
||||
EXPECT_EQ(dragAction, DragAction::COPY);
|
||||
SimulateUpKeyEvent(MMI::KeyEvent::KEYCODE_CTRL_LEFT);
|
||||
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
|
||||
EXPECT_EQ(ret, RET_OK);
|
||||
EXPECT_EQ(dragAction, DragAction::MOVE);
|
||||
ClearUpKeyEvent();
|
||||
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
|
||||
InteractionManager::GetInstance()->StopDrag(dropResult);
|
||||
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
|
||||
std::future_status::timeout);
|
||||
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
|
||||
EXPECT_EQ(ret, RET_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: InteractionManagerTest_GetDragAction_005
|
||||
* @tc.desc: Get style notification with multiple press and release keyboard events of keys in dragging
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(InteractionManagerTest, GetDragAction_005, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
auto listener = std::make_shared<SubscriptListenerTest>("SubscriptListener");
|
||||
int32_t ret = InteractionManager::GetInstance()->AddSubscriptListener(listener);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
std::promise<bool> promiseFlag;
|
||||
std::future<bool> futureFlag = promiseFlag.get_future();
|
||||
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
|
||||
FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
|
||||
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
|
||||
promiseFlag.set_value(true);
|
||||
};
|
||||
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
|
||||
ASSERT_TRUE(dragData);
|
||||
ret = InteractionManager::GetInstance()->StartDrag(dragData.value(),
|
||||
std::make_shared<TestStartDragListener>(callback));
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
|
||||
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
|
||||
DragCursorStyle recvStyle = listener->GetDragStyle();
|
||||
EXPECT_EQ(recvStyle, DragCursorStyle::MOVE);
|
||||
SimulateDownKeyEvent(MMI::KeyEvent::KEYCODE_CTRL_LEFT);
|
||||
SimulateDownKeyEvent(MMI::KeyEvent::KEYCODE_B);
|
||||
recvStyle = listener->GetDragStyle();
|
||||
EXPECT_EQ(recvStyle, DragCursorStyle::COPY);
|
||||
SimulateUpKeyEvent(MMI::KeyEvent::KEYCODE_CTRL_LEFT);
|
||||
ClearUpKeyEvent();
|
||||
recvStyle = listener->GetDragStyle();
|
||||
EXPECT_EQ(recvStyle, DragCursorStyle::MOVE);
|
||||
SimulateDownKeyEvent(MMI::KeyEvent::KEYCODE_CTRL_RIGHT);
|
||||
recvStyle = listener->GetDragStyle();
|
||||
EXPECT_EQ(recvStyle, DragCursorStyle::COPY);
|
||||
SimulateUpKeyEvent(MMI::KeyEvent::KEYCODE_B);
|
||||
ClearUpKeyEvent();
|
||||
recvStyle = listener->GetDragStyle();
|
||||
EXPECT_EQ(recvStyle, DragCursorStyle::COPY);
|
||||
SimulateUpKeyEvent(MMI::KeyEvent::KEYCODE_CTRL_RIGHT);
|
||||
ClearUpKeyEvent();
|
||||
recvStyle = listener->GetDragStyle();
|
||||
EXPECT_EQ(recvStyle, DragCursorStyle::MOVE);
|
||||
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
|
||||
InteractionManager::GetInstance()->StopDrag(dropResult);
|
||||
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
|
||||
std::future_status::timeout);
|
||||
recvStyle = listener->GetDragStyle();
|
||||
EXPECT_EQ(recvStyle, DragCursorStyle::MOVE);
|
||||
ret = InteractionManager::GetInstance()->RemoveSubscriptListener(listener);
|
||||
ASSERT_EQ(ret, RET_OK);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
@ -48,7 +48,6 @@ ohos_shared_library("deviceagent") {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"image_framework:image_native",
|
||||
"ipc:ipc_single",
|
||||
]
|
||||
|
||||
|
@ -253,6 +253,13 @@ void Client::OnConnected()
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
int32_t Client::Socket()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
int32_t Client::Socket()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
@ -268,6 +275,7 @@ int32_t Client::Socket()
|
||||
FI_HILOGD("Call GetClientSocketFdOfAllocedSocketPair return fd:%{public}d", fd_);
|
||||
return fd_;
|
||||
}
|
||||
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
|
||||
void Client::Stop()
|
||||
{
|
||||
|
@ -218,54 +218,54 @@ int32_t DeviceStatusClient::GetCoordinationState(int32_t userData, const std::st
|
||||
|
||||
#else // OHOS_BUILD_ENABLE_RUST_IMPL
|
||||
|
||||
int32_t DeviceStatusClient::RegisterCoordinationListener(bool isCheckPermission)
|
||||
int32_t DeviceStatusClient::RegisterCoordinationListener(bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->RegisterCoordinationListener(isCheckPermission);
|
||||
return devicestatusProxy_->RegisterCoordinationListener(isCompatible);
|
||||
}
|
||||
|
||||
int32_t DeviceStatusClient::UnregisterCoordinationListener(bool isCheckPermission)
|
||||
int32_t DeviceStatusClient::UnregisterCoordinationListener(bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->UnregisterCoordinationListener(isCheckPermission);
|
||||
return devicestatusProxy_->UnregisterCoordinationListener(isCompatible);
|
||||
}
|
||||
|
||||
int32_t DeviceStatusClient::PrepareCoordination(int32_t userData, bool isCheckPermission)
|
||||
int32_t DeviceStatusClient::PrepareCoordination(int32_t userData, bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->PrepareCoordination(userData, isCheckPermission);
|
||||
return devicestatusProxy_->PrepareCoordination(userData, isCompatible);
|
||||
}
|
||||
|
||||
int32_t DeviceStatusClient::UnprepareCoordination(int32_t userData, bool isCheckPermission)
|
||||
int32_t DeviceStatusClient::UnprepareCoordination(int32_t userData, bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->UnprepareCoordination(userData, isCheckPermission);
|
||||
return devicestatusProxy_->UnprepareCoordination(userData, isCompatible);
|
||||
}
|
||||
|
||||
int32_t DeviceStatusClient::ActivateCoordination(int32_t userData,
|
||||
const std::string &remoteNetworkId, int32_t startDeviceId, bool isCheckPermission)
|
||||
const std::string &remoteNetworkId, int32_t startDeviceId, bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->ActivateCoordination(userData, remoteNetworkId, startDeviceId, isCheckPermission);
|
||||
return devicestatusProxy_->ActivateCoordination(userData, remoteNetworkId, startDeviceId, isCompatible);
|
||||
}
|
||||
|
||||
int32_t DeviceStatusClient::DeactivateCoordination(int32_t userData, bool isUnchained, bool isCheckPermission)
|
||||
int32_t DeviceStatusClient::DeactivateCoordination(int32_t userData, bool isUnchained, bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->DeactivateCoordination(userData, isUnchained, isCheckPermission);
|
||||
return devicestatusProxy_->DeactivateCoordination(userData, isUnchained, isCompatible);
|
||||
}
|
||||
|
||||
int32_t DeviceStatusClient::GetCoordinationState(int32_t userData, const std::string &networkId, bool isCheckPermission)
|
||||
int32_t DeviceStatusClient::GetCoordinationState(int32_t userData, const std::string &networkId, bool isCompatible)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->GetCoordinationState(userData, networkId, isCheckPermission);
|
||||
return devicestatusProxy_->GetCoordinationState(userData, networkId, isCompatible);
|
||||
}
|
||||
|
||||
#endif // OHOS_BUILD_ENABLE_RUST_IMPL
|
||||
@ -491,6 +491,13 @@ int32_t DeviceStatusClient::EnterTextEditorArea(bool enable)
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->EnterTextEditorArea(enable);
|
||||
}
|
||||
|
||||
int32_t DeviceStatusClient::AddPrivilege()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->AddPrivilege();
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
189
hisysevent.yaml
189
hisysevent.yaml
@ -24,3 +24,192 @@ UNSUBSCRIBE:
|
||||
UID: {type: INT32, desc: unsubscribes from the device status uid}
|
||||
PACKAGE_NAME: {type: STRING, desc: devicestatus pkgname}
|
||||
TYPE: {type: INT32, desc: deviceStatus type}
|
||||
|
||||
PREPARE_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: prepare coordination}
|
||||
MONITOR_ID: {type: INT32, desc: Monitor_Id}
|
||||
ISOPEN: {type: BOOL, desc: IsOpen}
|
||||
MSG: {type: STRING, desc: Prepare Coordination Successfully}
|
||||
|
||||
PREPARE_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: prepare coordination}
|
||||
MONITOR_ID: {type: INT32, desc: Monitor_Id}
|
||||
ISOPEN: {type: BOOL, desc: IsOpen}
|
||||
MSG: {type: STRING, desc: Prepare Coordination Failed}
|
||||
|
||||
UNPREPARE_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: unprepare coordination}
|
||||
ISCLOSE: {type: BOOL, desc: IsClose}
|
||||
MSG: {type: STRING, desc: Unprepare Coordination Successfully}
|
||||
|
||||
UNPREPARE_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: unprepare coordination}
|
||||
ISCLOSE: {type: BOOL, desc: IsClose}
|
||||
MSG: {type: STRING, desc: Unprepare Coordination Failed}
|
||||
|
||||
ACTIVATE_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: start remote coordination}
|
||||
LOCALNETWORKID: {type: STRING, desc: localNetworkId}
|
||||
REMOTENETWORKID: {type: STRING, desc: remoteNetworkId}
|
||||
MSG: {type: STRING, desc: Start Remote Coordination Successfully}
|
||||
|
||||
ACTIVATE_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: start remote coordination}
|
||||
LOCALNETWORKID: {type: STRING, desc: localNetworkId}
|
||||
REMOTENETWORKID: {type: STRING, desc: remoteNetworkId}
|
||||
MSG: {type: STRING, desc: Start Remote Coordination Failed}
|
||||
|
||||
ACTIVATE_RESULT:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: Start Remote Accordination Result}
|
||||
REMOTENETWORKID: {type: STRING, desc: remoteNetWorkId}
|
||||
ISSUCCESS: {type: BOOL, desc: IsSuccess}
|
||||
MSG: {type: STRING, desc: Start Remote Accordination Result Failed}
|
||||
|
||||
DEACTIVATE_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: stop remote coordination}
|
||||
REMOTENETWORKID: {type: STRING, desc: remoteNetWorkId}
|
||||
SESSIONID: {type: INT32, desc: sessionId}
|
||||
MSG: {type: STRING, desc: Stop Remote Accordination Successfully}
|
||||
|
||||
DEACTIVATE_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: stop remote coordination}
|
||||
REMOTENETWORKID: {type: STRING, desc: remoteNetWorkId}
|
||||
SESSIONID: {type: INT32, desc: sessionId}
|
||||
MSG: {type: STRING, desc: Stop Remote Accordination Failed}
|
||||
|
||||
DEACTIVATE_RESULT:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: stop remote coordination result}
|
||||
REMOTENETWORKID: {type: STRING, desc: remoteNetWorkId}
|
||||
SESSIONID: {type: INT32, desc: sessionId}
|
||||
MSG: {type: STRING, desc: Stop Remote Accordination Result Failed}
|
||||
|
||||
D_INPUT_START_REMOTE_INPUT:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: distributed input start remote input}
|
||||
REMOTENETWORKID: {type: STRING, desc: remoteNetWorkId}
|
||||
ORIGINNETWORKID: {type: STRING, desc: originNetWorkId}
|
||||
MSG: {type: STRING, desc: D_input Start Remote Input Failed}
|
||||
|
||||
D_INPUT_STOP_REMOTE_INPUT_O:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: distributed input stop remote input}
|
||||
REMOTENETWORKID: {type: STRING, desc: remoteNetWorkId}
|
||||
ORIGINNETWORKID: {type: STRING, desc: originNetWorkId}
|
||||
MSG: {type: STRING, desc: D_input Stop Remote Input Failed}
|
||||
|
||||
D_INPUT_STOP_REMOTE_INPUT_T:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: distributed input stop remote input}
|
||||
ORIGINNETWORKID: {type: STRING, desc: originNetWorkId}
|
||||
MSG: {type: STRING, desc: D_input Stop Remote Input Failed}
|
||||
|
||||
D_INPUT_PREPARE_REMOTE_INPUT_O:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: distributed input prepare remote input}
|
||||
DEVICEID: {type: STRING, desc: deviceId}
|
||||
MSG: {type: STRING, desc: D_input Prepare Remote Input Failed}
|
||||
|
||||
D_INPUT_PREPARE_REMOTE_INPUT_T:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: distributed input prepare remote input}
|
||||
REMOTENETWORKID: {type: STRING, desc: remoteNetWorkId}
|
||||
ORIGINNETWORKID: {type: STRING, desc: originNetWorkId}
|
||||
MSG: {type: STRING, desc: D_input Prepare Remote Input Failed}
|
||||
|
||||
D_INPUT_UNPREPARE_REMOTE_INPUT_O:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: distributed input unprepare remote input}
|
||||
DEVICEID: {type: STRING, desc: deviceId}
|
||||
MSG: {type: STRING, desc: D_input Unprepare Remote Input Failed}
|
||||
|
||||
D_INPUT_UNPREPARE_REMOTE_INPUT_T:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: distributed input unprepare remote input}
|
||||
REMOTENETWORKID: {type: STRING, desc: remoteNetWorkId}
|
||||
ORIGINNETWORKID: {type: STRING, desc: originNetWorkId}
|
||||
MSG: {type: STRING, desc: D_input Unprepare Remote Input Failed}
|
||||
|
||||
OPEN_SOFUBUS_RESULT:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: open softbus result}
|
||||
REMOTENETWORKID: {type: STRING, desc: remoteNetWorkId}
|
||||
PARA: {type: INT32, desc: tag information}
|
||||
MSG: {type: STRING, desc: Open SoftBus Result Failed}
|
||||
|
||||
START_DRAG_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: start drag}
|
||||
MSG: {type: STRING, desc: Start Drag Successfully}
|
||||
CURDRAGSTATE: {type: STRING, desc: dragstate}
|
||||
|
||||
START_DRAG_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: start drag}
|
||||
MSG: {type: STRING, desc: Start Drag Failed}
|
||||
CURDRAGSTATE: {type: STRING, desc: dragstate}
|
||||
|
||||
SET_DRAG_WINDOW_VISIBLE_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: Set Drag Window Visible}
|
||||
MSG: {type: STRING, desc: Set Drag Window Visible Successfully}
|
||||
ISVISBLE: {type: BOOL, desc: IsVisible}
|
||||
CURDRAGSTATE: {type: STRING, desc: dragstate}
|
||||
|
||||
SET_DRAG_WINDOW_VISIBLE_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: Set Drag Window Visible}
|
||||
MSG: {type: STRING, desc: Set Drag Window Visible Failed}
|
||||
ISVISBLE: {type: BOOL, desc: IsVisible}
|
||||
CURDRAGSTATE: {type: STRING, desc: dragstate}
|
||||
|
||||
UPDATE_DRAG_STYLE_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: Update Drag Style}
|
||||
MSG: {type: STRING, desc: Update Drag Style Successfully}
|
||||
DRAGSTYLE: {type: STRING, desc: dragstyle}
|
||||
|
||||
|
||||
UPDATE_DRAG_STYLE_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: Update Drag Style}
|
||||
MSG: {type: STRING, desc: Update Drag Style Failed}
|
||||
DRAGSTYLE: {type: STRING, desc: dragstyle}
|
||||
|
||||
SEND_TOKENID:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: Send Drag Data}
|
||||
MSG: {type: STRING, desc: Send Token Id Failed}
|
||||
TARGETID: {type: INT32, desc: targetTid}
|
||||
UDKEY: {type: STRING, desc: udkey}
|
||||
|
||||
STOP_DRAG_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: Stop Drag}
|
||||
MSG: {type: STRING, desc: Stop Drag Successfully}
|
||||
CURDRAGSTATE: {type: STRING, desc: dragstate}
|
||||
ANIMATE: {type: BOOL, desc: animate}
|
||||
|
||||
STOP_DRAG_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: Stop Drag}
|
||||
MSG: {type: STRING, desc: Stop Drag Failed}
|
||||
CURDRAGSTATE: {type: STRING, desc: dragstate}
|
||||
ANIMATE: {type: BOOL, desc: animate}
|
||||
|
||||
NOTIFY_DRAG_RESULT_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: Notify Drag Result}
|
||||
MSG: {type: STRING, desc: Notify Drag Result Successfully}
|
||||
DRAGRESULT: {type: STRING, desc: DragResult}
|
||||
|
||||
NOTIFY_DRAG_RESULT_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: Notify Drag Result}
|
||||
MSG: {type: STRING, desc: Notify Drag Result Failed}
|
||||
DRAGRESULT: {type: STRING, desc: DragResult}
|
||||
|
||||
COOPERATE_DRAG_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: Cooperate Drag}
|
||||
MSG: {type: STRING, desc: On Coordination And The State Change Successfully}
|
||||
PRESTATE: {type: STRING, desc: PreviousState}
|
||||
UPDATESTATE: {type: STRING, desc: UpdateState}
|
||||
|
||||
COOPERATE_DRAG_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: Cooperate Drag}
|
||||
MSG: {type: STRING, desc: The Current Coordination State Is Out}
|
||||
CURSTATE: {type: STRING, desc: CurrentState}
|
||||
|
||||
COOPERATE_DRAG_RESULT_SUCCESS:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: deviceStatus, desc: Cooperate Drag Result}
|
||||
MSG: {type: STRING, desc: Coordination Drag Result Successfully}
|
||||
DEVICEID: {type: STRING, desc: remotedeviceId}
|
||||
SESSIONID: {type: STRING, desc: sessionId}
|
||||
CURSTATE: {type: STRING, desc: CurCoordinationState}
|
||||
|
||||
COOPERATE_DRAG_RESULT_FAILED:
|
||||
__BASE: {type: FAULT, level: MINOR, tag: deviceStatus, desc: Cooperate Drag Result}
|
||||
MSG: {type: STRING, desc: Coordination Drag Result Failed}
|
||||
DEVICEID: {type: STRING, desc: remotedeviceId}
|
||||
SESSIONID: {type: STRING, desc: sessionId}
|
||||
CURSTATE: {type: STRING, desc: CurCoordinationState}
|
82
intention/adapters/input_adapter/include/input_adapter.h
Normal file
82
intention/adapters/input_adapter/include/input_adapter.h
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INPUT_ADAPTER_H
|
||||
#define INPUT_ADAPTER_H
|
||||
|
||||
#include "input_manager.h"
|
||||
#include "i_input_event_consumer.h"
|
||||
#include "i_input_event_filter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class InputAdapter {
|
||||
struct PointerFilter : public MMI::IInputEventFilter {
|
||||
explicit PointerFilter(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb) : callback_(cb) {}
|
||||
bool OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
inline void UpdateCurrentFilterId(int32_t filterId)
|
||||
{
|
||||
filterId_ = filterId;
|
||||
}
|
||||
bool OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
|
||||
private:
|
||||
std::function<void (std::shared_ptr<MMI::PointerEvent>)> callback_;
|
||||
mutable int32_t filterId_ { -1 };
|
||||
};
|
||||
|
||||
class InterceptorConsumer : public MMI::IInputEventConsumer {
|
||||
public:
|
||||
explicit InterceptorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointerCallback,
|
||||
std::function<void (std::shared_ptr<MMI::KeyEvent>)> keyCallback)
|
||||
: pointerCallback_(pointerCallback),
|
||||
keyCallback_(keyCallback) {}
|
||||
void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override;
|
||||
private:
|
||||
std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointerCallback_;
|
||||
std::function<void (std::shared_ptr<MMI::keyEvent>)> keyCallback_;
|
||||
};
|
||||
|
||||
class MonitorConsumer : public MMI::IInputEventConsumer {
|
||||
public:
|
||||
explicit MonitorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb) : callback_(cb) {}
|
||||
void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override;
|
||||
private:
|
||||
std::function<void (std::shared_ptr<MMI::PointerEvent>)> callback_;
|
||||
};
|
||||
public:
|
||||
int32_t AddMonitor(std::function<void (std::shared_ptr<MMI::PointerEvent>)> callback);
|
||||
int32_t AddInterceptor(std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointerCallback,
|
||||
std::function<void (std::shared_ptr<MMI::KeyEvent>)> keyCallback, uint32_t deviceTags);
|
||||
int32_t AddFilter(std::function<void(std::shared_ptr<MMI::PointerEvent>)> callback);
|
||||
void RemoveMonitor();
|
||||
void RemoveInterceptor();
|
||||
void RemoveFilter(int32_t filterId);
|
||||
private:
|
||||
int32_t monitorId_ { -1 };
|
||||
int32_t interceptorId_ { -1 };
|
||||
Channel<CooperateEvent>::Sender sender_;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // INPUT_ADAPTER_H
|
115
intention/adapters/input_adapter/src/input_adapter.cpp
Normal file
115
intention/adapters/input_adapter/src/input_adapter.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "input_adapter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
|
||||
bool InputAdapter::PointerFilter::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
|
||||
{
|
||||
CHKPV(pointerEvent);
|
||||
pointerCallback_(pointerEvent);
|
||||
}
|
||||
|
||||
void InputAdapter::InterceptorConsumer::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const
|
||||
{
|
||||
CHKPV(keyEvent);
|
||||
keyCallback_(keyEvent);
|
||||
}
|
||||
|
||||
void InputAdapter::InterceptorConsumer::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
|
||||
{
|
||||
CHKPV(pointerEvent);
|
||||
pointerCallback_(pointerEvent);
|
||||
}
|
||||
|
||||
void InputAdapter::InterceptorConsumer::OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const {}
|
||||
|
||||
void InputAdapter::MonitorConsumer::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const {}
|
||||
|
||||
void InputAdapter::MonitorConsumer::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
|
||||
{
|
||||
CHKPV(pointerEvent);
|
||||
callback_(pointerEvent);
|
||||
}
|
||||
|
||||
void InputAdapter::MonitorConsumer::OnInputEvent(std::shared_ptr<MMI::AxisEvent>) const {}
|
||||
|
||||
int32_t InputAdapter::AddMonitor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> callback)
|
||||
{
|
||||
auto monitor = std::make_shared<MonitorConsumer>(callback);
|
||||
monitorId_ = MMI::InputManager::GetInstance()->AddMonitor(monitor);
|
||||
if (monitorId_ <= 0) {
|
||||
FI_HILOGE("Failed to add monitor, error code:%{public}d", monitorId_);
|
||||
monitorId_ = -1;
|
||||
return RET_ERR;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t InputAdapter::AddInterceptor(std::function<void(std::shared_ptr<MMI::PointerEvent>)> pointerCallback,
|
||||
std::function<void(std::shared_ptr<MMI::KeyEvent>)> keyCallback, uint32_t deviceTags)
|
||||
{
|
||||
auto interceptor = std::make_shared<InterceptorConsumer>(pointerCallback, keyCallback);
|
||||
interceptorId_ = MMI::InputManager::GetInstance()->AddInterceptor(interceptor, COORDINATION_PRIORITY, deviceTags);
|
||||
if (interceptorId_ <= 0) {
|
||||
FI_HILOGE("Failed to add interceptor, error code:%{public}d", interceptorId_);
|
||||
DeactivateCoordination(isUnchained_);
|
||||
return RET_ERR;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t InputAdapter::AddFilter(std::function<void(std::shared_ptr<MMI::PointerEvent>)> callback)
|
||||
{
|
||||
int32_t POINTER_DEFAULT_PRIORITY = 220;
|
||||
auto filter = std::make_shared<PointerFilter>(callback);
|
||||
uint32_t touchTags = CapabilityToTags(MMI::INPUT_DEV_CAP_POINTER);
|
||||
if (filterId_ >= 0) {
|
||||
RemoveFilter(filterId_);
|
||||
}
|
||||
filterId_ =
|
||||
MMI::InputManager::GetInstance()->AddInputEventFilter(filter, POINTER_DEFAULT_PRIORITY, touchTags);
|
||||
if (filterId_ < 0) {
|
||||
return;
|
||||
}
|
||||
filter->UpdateCurrentFilterId(filterId_);
|
||||
}
|
||||
|
||||
void InputAdapter::RemoveMonitor()
|
||||
{
|
||||
if ((monitorId_ >= MIN_HANDLER_ID) && (monitorId_ < std::numeric_limits<int32_t>::max())) {
|
||||
MMI::InputManager::GetInstance()->RemoveMonitor(monitorId_);
|
||||
monitorId_ = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void InputAdapter::RemoveInterceptor()
|
||||
{
|
||||
if ((interceptorId_ >= MIN_HANDLER_ID) && (interceptorId_ < std::numeric_limits<int32_t>::max())) {
|
||||
MMI::InputManager::GetInstance()->RemoveInterceptor(interceptorId_);
|
||||
interceptorId_ = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void InputAdapter::RemoveFilter(int32_t filterId)
|
||||
{
|
||||
MMI::InputManager::GetInstance()->RemoveInputEventFilter(filterId);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
@ -20,6 +20,9 @@ config("intention_channel_public_config") {
|
||||
|
||||
ohos_source_set("intention_channel") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
|
@ -19,6 +19,9 @@ config("intention_epoll_public_config") {
|
||||
|
||||
ohos_source_set("intention_epoll") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
|
65
intention/cooperate/client/BUILD.gn
Normal file
65
intention/cooperate/client/BUILD.gn
Normal file
@ -0,0 +1,65 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("../../../device_status.gni")
|
||||
|
||||
config("intention_cooperate_client_public_config") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${device_status_interfaces_path}/innerkits/interaction/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_source_set("intention_cooperate_client") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${device_status_interfaces_path}/innerkits/interaction/include",
|
||||
]
|
||||
|
||||
sources = [ "src/cooperate_client.cpp" ]
|
||||
|
||||
public_configs = [ ":intention_cooperate_client_public_config" ]
|
||||
|
||||
defines = device_status_default_defines
|
||||
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/cooperate/data:intention_cooperate_data",
|
||||
"${device_status_root_path}/intention/data:intention_data",
|
||||
"${device_status_root_path}/intention/ipc/socket:intention_socket_connection",
|
||||
"${device_status_root_path}/intention/ipc/tunnel:intention_tunnel_client",
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_root_path}/utils/common:devicestatus_util",
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"input:libmmi-client",
|
||||
]
|
||||
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
||||
part_name = "${device_status_part_name}"
|
||||
}
|
92
intention/cooperate/client/include/cooperate_client.h
Normal file
92
intention/cooperate/client/include/cooperate_client.h
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef COOPERATE_CLIENT_H
|
||||
#define COOPERATE_CLIENT_H
|
||||
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
#include "coordination_message.h"
|
||||
#include "i_coordination_listener.h"
|
||||
#include "i_hotarea_listener.h"
|
||||
#include "i_tunnel_client.h"
|
||||
#include "net_packet.h"
|
||||
#include "socket_client.h"
|
||||
#include "stream_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class CooperateClient final {
|
||||
public:
|
||||
using CooperateMessageCallback = std::function<void(const std::string&, CoordinationMessage)>;
|
||||
using CooperateStateCallback = std::function<void(bool)>;
|
||||
using CooperateListenerPtr = std::shared_ptr<ICoordinationListener>;
|
||||
using HotAreaListenerPtr = std::shared_ptr<IHotAreaListener>;
|
||||
|
||||
struct CooperateEvent {
|
||||
CooperateEvent(CooperateMessageCallback callback) : msgCb(callback) {}
|
||||
CooperateEvent(CooperateStateCallback callback) : stateCb(callback) {}
|
||||
|
||||
CooperateMessageCallback msgCb;
|
||||
CooperateStateCallback stateCb;
|
||||
};
|
||||
|
||||
CooperateClient() = default;
|
||||
~CooperateClient() = default;
|
||||
DISALLOW_COPY_AND_MOVE(CooperateClient);
|
||||
|
||||
int32_t RegisterListener(ITunnelClient &tunnel,
|
||||
CooperateListenerPtr listener, bool isCheckPermission = false);
|
||||
int32_t UnregisterListener(ITunnelClient &tunnel,
|
||||
CooperateListenerPtr listener, bool isCheckPermission = false);
|
||||
int32_t Enable(ITunnelClient &tunnel,
|
||||
CooperateMessageCallback callback, bool isCheckPermission = false);
|
||||
int32_t Disable(ITunnelClient &tunnel,
|
||||
CooperateMessageCallback callback, bool isCheckPermission = false);
|
||||
int32_t Start(ITunnelClient &tunnel,
|
||||
const std::string &remoteNetworkId, int32_t startDeviceId,
|
||||
CooperateMessageCallback callback, bool isCheckPermission = false);
|
||||
int32_t Stop(ITunnelClient &tunnel,
|
||||
bool isUnchained, CooperateMessageCallback callback,
|
||||
bool isCheckPermission = false);
|
||||
int32_t GetCooperateState(ITunnelClient &tunnel,
|
||||
const std::string &networkId, CooperateStateCallback callback,
|
||||
bool isCheckPermission = false);
|
||||
int32_t AddHotAreaListener(ITunnelClient &tunnel, HotAreaListenerPtr listener);
|
||||
int32_t RemoveHotAreaListener(ITunnelClient &tunnel, HotAreaListenerPtr listener = nullptr);
|
||||
|
||||
int32_t OnCoordinationListener(const StreamClient &client, NetPacket &pkt);
|
||||
int32_t OnCoordinationMessage(const StreamClient &client, NetPacket &pkt);
|
||||
int32_t OnCoordinationState(const StreamClient &client, NetPacket &pkt);
|
||||
int32_t OnHotAreaListener(const StreamClient &client, NetPacket &pkt);
|
||||
|
||||
private:
|
||||
int32_t GenerateRequestID();
|
||||
|
||||
std::list<CooperateListenerPtr> devCooperateListener_;
|
||||
std::map<int32_t, CooperateEvent> devCooperateEvent_;
|
||||
mutable std::mutex mtx_;
|
||||
std::atomic_bool isListeningProcess_ { false };
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // COOPERATE_CLIENT_H
|
216
intention/cooperate/client/src/cooperate_client.cpp
Normal file
216
intention/cooperate/client/src/cooperate_client.cpp
Normal file
@ -0,0 +1,216 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "cooperate_client.h"
|
||||
|
||||
#include "cooperate_params.h"
|
||||
#include "default_params.h"
|
||||
#include "devicestatus_define.h"
|
||||
#include "devicestatus_func_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "CooperateClient" };
|
||||
} // namespace
|
||||
|
||||
int32_t CooperateClient::RegisterListener(ITunnelClient &tunnel,
|
||||
CooperateListenerPtr listener, bool isCheckPermission)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CHKPR(listener, RET_ERR);
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
for (const auto &item : devCooperateListener_) {
|
||||
if (item == listener) {
|
||||
FI_HILOGE("The listener already exists");
|
||||
return RET_ERR;
|
||||
}
|
||||
}
|
||||
if (!isListeningProcess_) {
|
||||
FI_HILOGI("Start monitoring");
|
||||
DefaultParam param;
|
||||
DefaultReply reply;
|
||||
|
||||
int32_t ret = tunnel.AddWatch(Intention::COOPERATE, CooperateRequestID::REGISTER_LISTENER, param, reply);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Failed to register, ret:%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
isListeningProcess_ = true;
|
||||
}
|
||||
devCooperateListener_.push_back(listener);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t CooperateClient::UnregisterListener(ITunnelClient &tunnel,
|
||||
CooperateListenerPtr listener, bool isCheckPermission)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
if (listener == nullptr) {
|
||||
devCooperateListener_.clear();
|
||||
goto listenerLabel;
|
||||
}
|
||||
for (auto it = devCooperateListener_.begin(); it != devCooperateListener_.end(); ++it) {
|
||||
if (*it == listener) {
|
||||
devCooperateListener_.erase(it);
|
||||
goto listenerLabel;
|
||||
}
|
||||
}
|
||||
|
||||
listenerLabel:
|
||||
if (isListeningProcess_ && devCooperateListener_.empty()) {
|
||||
isListeningProcess_ = false;
|
||||
DefaultParam param;
|
||||
DefaultReply reply;
|
||||
return tunnel.RemoveWatch(Intention::COOPERATE, CooperateRequestID::UNREGISTER_LISTENER, param, reply);
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t CooperateClient::Enable(ITunnelClient &tunnel,
|
||||
CooperateMessageCallback callback, bool isCheckPermission)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
CooperateEvent event { callback };
|
||||
DefaultParam param { GenerateRequestID() };
|
||||
DefaultReply reply;
|
||||
|
||||
int32_t ret = tunnel.Enable(Intention::COOPERATE, param, reply);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Prepare cooperate failed");
|
||||
return ret;
|
||||
}
|
||||
devCooperateEvent_.insert_or_assign(param.userData, event);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t CooperateClient::Disable(ITunnelClient &tunnel,
|
||||
CooperateMessageCallback callback, bool isCheckPermission)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
CooperateEvent event { callback };
|
||||
DefaultParam param { GenerateRequestID() };
|
||||
DefaultReply reply;
|
||||
|
||||
int32_t ret = tunnel.Disable(Intention::COOPERATE, param, reply);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Unprepare cooperate failed");
|
||||
return ret;
|
||||
}
|
||||
devCooperateEvent_.insert_or_assign(param.userData, event);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t CooperateClient::Start(ITunnelClient &tunnel, const std::string &remoteNetworkId,
|
||||
int32_t startDeviceId, CooperateMessageCallback callback, bool isCheckPermission)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
CooperateEvent event { callback };
|
||||
StartCooperateParam param { GenerateRequestID(), remoteNetworkId, startDeviceId, isCheckPermission };
|
||||
DefaultReply reply;
|
||||
|
||||
int32_t ret = tunnel.Start(Intention::COOPERATE, param, reply);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Activate cooperate failed");
|
||||
return ret;
|
||||
}
|
||||
devCooperateEvent_.insert_or_assign(param.userData, event);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t CooperateClient::Stop(ITunnelClient &tunnel,
|
||||
bool isUnchained, CooperateMessageCallback callback, bool isCheckPermission)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
CooperateEvent event { callback };
|
||||
StopCooperateParam param { GenerateRequestID(), isUnchained, isCheckPermission };
|
||||
DefaultReply reply;
|
||||
|
||||
int32_t ret = tunnel.Stop(Intention::COOPERATE, param, reply);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Deactivate cooperate failed");
|
||||
return ret;
|
||||
}
|
||||
devCooperateEvent_.insert_or_assign(param.userData, event);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t CooperateClient::GetCooperateState(ITunnelClient &tunnel,
|
||||
const std::string &networkId, CooperateStateCallback callback, bool isCheckPermission)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
CooperateEvent event { callback };
|
||||
GetCooperateStateParam param { GenerateRequestID(), networkId, isCheckPermission };
|
||||
DefaultReply reply;
|
||||
|
||||
int32_t ret = tunnel.GetParam(Intention::COOPERATE, CooperateRequestID::GET_COOPERATE_STATE, param, reply);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Get cooperate state failed");
|
||||
return ret;
|
||||
}
|
||||
devCooperateEvent_.insert_or_assign(param.userData, event);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t CooperateClient::AddHotAreaListener(ITunnelClient &tunnel, HotAreaListenerPtr listener)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t CooperateClient::RemoveHotAreaListener(ITunnelClient &tunnel, HotAreaListenerPtr listener)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t CooperateClient::GenerateRequestID()
|
||||
{
|
||||
static int32_t requestId { 0 };
|
||||
|
||||
if (requestId == std::numeric_limits<int32_t>::max()) {
|
||||
FI_HILOGE("Request ID exceeds the maximum");
|
||||
requestId = 0;
|
||||
}
|
||||
return requestId++;
|
||||
}
|
||||
|
||||
int32_t CooperateClient::OnCoordinationListener(const StreamClient &client, NetPacket &pkt)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t CooperateClient::OnCoordinationMessage(const StreamClient &client, NetPacket &pkt)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t CooperateClient::OnCoordinationState(const StreamClient &client, NetPacket &pkt)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t CooperateClient::OnHotAreaListener(const StreamClient &client, NetPacket &pkt)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
29
intention/plugins/cooperate/BUILD.gn → intention/cooperate/data/BUILD.gn
Executable file → Normal file
29
intention/plugins/cooperate/BUILD.gn → intention/cooperate/data/BUILD.gn
Executable file → Normal file
@ -13,12 +13,15 @@
|
||||
|
||||
import("../../../device_status.gni")
|
||||
|
||||
config("cooperate_public_config") {
|
||||
config("intention_cooperate_data_public_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("intention_cooperate") {
|
||||
ohos_source_set("intention_cooperate_data") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
@ -26,33 +29,21 @@ ohos_shared_library("intention_cooperate") {
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${intention_root_path}/data/cooperate/include",
|
||||
"${device_status_root_path}/utils/ipc/include",
|
||||
"${intention_root_path}/data/include",
|
||||
]
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
sources = [
|
||||
"src/cooperate.cpp",
|
||||
"src/state_machine.cpp",
|
||||
]
|
||||
sources = [ "src/cooperate_params.cpp" ]
|
||||
|
||||
public_configs = [ ":cooperate_public_config" ]
|
||||
|
||||
defines = device_status_default_defines
|
||||
public_configs = [ ":intention_cooperate_data_public_config" ]
|
||||
|
||||
deps = [
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_utils_path}:devicestatus_util",
|
||||
"${intention_root_path}/data:cooperate_params",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"input:libmmi-client",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
@ -16,60 +16,53 @@
|
||||
#ifndef COOPERATE_PARAMS_H
|
||||
#define COOPERATE_PARAMS_H
|
||||
|
||||
#include "i_plugin.h"
|
||||
#include "intention_identity.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
enum CooperateParam : uint32_t {
|
||||
PREPARE,
|
||||
STATE,
|
||||
REGISTER
|
||||
};
|
||||
|
||||
struct DefaultCooperateParam final : public ParamBase {
|
||||
DefaultCooperateParam() = default;
|
||||
DefaultCooperateParam(int32_t userData);
|
||||
bool Marshalling(Parcel &data) const override;
|
||||
bool Unmarshalling(Parcel &data) override;
|
||||
|
||||
int32_t userData { -1 };
|
||||
};
|
||||
|
||||
struct DefaultCooperateReply final : public ParamBase {
|
||||
bool Marshalling(Parcel &data) const override;
|
||||
bool Unmarshalling(Parcel &data) override;
|
||||
enum CooperateRequestID : uint32_t {
|
||||
UNKNOWN_COOPERATE_ACTION,
|
||||
REGISTER_LISTENER,
|
||||
UNREGISTER_LISTENER,
|
||||
REGISTER_HOTAREA_LISTENER,
|
||||
UNREGISTER_HOTAREA_LISTENER,
|
||||
GET_COOPERATE_STATE,
|
||||
};
|
||||
|
||||
struct StartCooperateParam final : public ParamBase {
|
||||
StartCooperateParam() = default;
|
||||
StartCooperateParam(int32_t userData, const std::string &remoteNetworkId, int32_t startDeviceId);
|
||||
bool Marshalling(Parcel &data) const override;
|
||||
bool Unmarshalling(Parcel &data) override;
|
||||
StartCooperateParam(int32_t userData, const std::string &remoteNetworkId,
|
||||
int32_t startDeviceId, bool checkPermission);
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
std::string remoteNetworkId;
|
||||
int32_t startDeviceId { -1 };
|
||||
int32_t userData { -1 };
|
||||
int32_t startDeviceId { -1 };
|
||||
bool checkPermission { false };
|
||||
};
|
||||
|
||||
struct StopCooperateParam final : public ParamBase {
|
||||
StopCooperateParam() = default;
|
||||
StopCooperateParam(int32_t userData, bool isUnchained);
|
||||
bool Marshalling(Parcel &data) const override;
|
||||
bool Unmarshalling(Parcel &data) override;
|
||||
StopCooperateParam(int32_t userData, bool isUnchained, bool checkPermission);
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
int32_t userData { -1 };
|
||||
bool isUnchained { false };
|
||||
bool checkPermission { false };
|
||||
};
|
||||
|
||||
struct GetCooperateStateParam final : public ParamBase {
|
||||
GetCooperateStateParam() = default;
|
||||
GetCooperateStateParam(std::string networkId, int32_t userData);
|
||||
bool Marshalling(Parcel &data) const override;
|
||||
bool Unmarshalling(Parcel &data) override;
|
||||
GetCooperateStateParam(int32_t userData, const std::string &networkId, bool checkPermission);
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
std::string networkId;
|
||||
int32_t userData { -1 };
|
||||
bool checkPermission { false };
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
93
intention/cooperate/data/src/cooperate_params.cpp
Normal file
93
intention/cooperate/data/src/cooperate_params.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "cooperate_params.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
|
||||
StartCooperateParam::StartCooperateParam(int32_t userData, const std::string &remoteNetworkId,
|
||||
int32_t startDeviceId, bool checkPermission)
|
||||
: remoteNetworkId(remoteNetworkId), userData(userData),
|
||||
startDeviceId(startDeviceId), checkPermission(checkPermission)
|
||||
{}
|
||||
|
||||
bool StartCooperateParam::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return (
|
||||
parcel.WriteString(remoteNetworkId) &&
|
||||
parcel.WriteInt32(startDeviceId) &&
|
||||
parcel.WriteInt32(userData) &&
|
||||
parcel.WriteBool(checkPermission)
|
||||
);
|
||||
}
|
||||
|
||||
bool StartCooperateParam::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return (
|
||||
parcel.ReadString(remoteNetworkId) &&
|
||||
parcel.ReadInt32(startDeviceId) &&
|
||||
parcel.ReadInt32(userData) &&
|
||||
parcel.ReadBool(checkPermission)
|
||||
);
|
||||
}
|
||||
|
||||
StopCooperateParam::StopCooperateParam(int32_t userData, bool isUnchained, bool checkPermission)
|
||||
: userData(userData), isUnchained(isUnchained), checkPermission(checkPermission)
|
||||
{}
|
||||
|
||||
bool StopCooperateParam::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return (
|
||||
parcel.WriteBool(isUnchained) &&
|
||||
parcel.WriteBool(checkPermission) &&
|
||||
parcel.WriteInt32(userData)
|
||||
);
|
||||
}
|
||||
|
||||
bool StopCooperateParam::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return (
|
||||
parcel.ReadBool(isUnchained) &&
|
||||
parcel.ReadBool(checkPermission) &&
|
||||
parcel.ReadInt32(userData)
|
||||
);
|
||||
}
|
||||
|
||||
GetCooperateStateParam::GetCooperateStateParam(int32_t userData, const std::string &networkId, bool checkPermission)
|
||||
: networkId(networkId), userData(userData), checkPermission(checkPermission)
|
||||
{}
|
||||
|
||||
bool GetCooperateStateParam::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return (
|
||||
parcel.WriteInt32(userData) &&
|
||||
parcel.WriteString(networkId) &&
|
||||
parcel.WriteBool(checkPermission)
|
||||
);
|
||||
}
|
||||
|
||||
bool GetCooperateStateParam::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return (
|
||||
parcel.ReadInt32(userData) &&
|
||||
parcel.ReadString(networkId) &&
|
||||
parcel.ReadBool(checkPermission)
|
||||
);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
@ -13,12 +13,15 @@
|
||||
|
||||
import("../../../device_status.gni")
|
||||
|
||||
config("cooperate_public_config") {
|
||||
config("intention_cooperate_public_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("intention_cooperate") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
@ -26,57 +29,66 @@ ohos_shared_library("intention_cooperate") {
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${intention_root_path}/data/cooperate/include",
|
||||
"${intention_root_path}/data/include",
|
||||
"${intention_root_path}/interfaces/include",
|
||||
"${device_status_root_path}/utils/ipc/include",
|
||||
"${intention_root_path}/data/include",
|
||||
]
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
sources = [
|
||||
"src/cooperate.cpp",
|
||||
"src/cooperate_device_manager.cpp",
|
||||
"src/cooperate_event_handler.cpp",
|
||||
"src/cooperate_event_manager.cpp",
|
||||
"src/cooperate_manager.cpp",
|
||||
"src/cooperate_sm.cpp",
|
||||
"src/cooperate_softbus_adapter.cpp",
|
||||
"src/cooperate_state_free.cpp",
|
||||
"src/cooperate_state_in.cpp",
|
||||
"src/cooperate_state_out.cpp",
|
||||
"src/cooperate_util.cpp",
|
||||
"src/device_profile_adapter.cpp",
|
||||
"src/distributed_input_adapter.cpp",
|
||||
"src/i_cooperate_state.cpp",
|
||||
]
|
||||
sources = [ "src/cooperate.cpp" ]
|
||||
|
||||
public_configs = [ ":cooperate_public_config" ]
|
||||
public_configs = [ ":intention_cooperate_public_config" ]
|
||||
|
||||
defines = device_status_default_defines
|
||||
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_root_path}/utils/common:devicestatus_util",
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hilog:libhilog",
|
||||
"image_framework:image_native",
|
||||
"input:libmmi-client",
|
||||
]
|
||||
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
||||
part_name = "${device_status_part_name}"
|
||||
}
|
||||
|
||||
config("intention_cooperate_server_public_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_source_set("intention_cooperate_server") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
sources = [ "src/cooperate_server.cpp" ]
|
||||
|
||||
public_configs = [ ":intention_cooperate_server_public_config" ]
|
||||
|
||||
defines = device_status_default_defines
|
||||
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/cooperate/data:intention_cooperate_data",
|
||||
"${device_status_root_path}/intention/data:intention_data",
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_root_path}/utils/common:devicestatus_util",
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
"${device_status_utils_path}:devicestatus_util",
|
||||
"${intention_root_path}/data:cooperate_params",
|
||||
"//third_party/cJSON:cjson",
|
||||
"//third_party/openssl:libcrypto_shared",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"device_info_manager:distributed_device_profile_client",
|
||||
"device_manager:devicemanagersdk",
|
||||
"distributed_input:libdinput_sdk",
|
||||
"dsoftbus:softbus_client",
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"image_framework:image_native",
|
||||
"input:libmmi-client",
|
||||
"ipc:ipc_single",
|
||||
"window_manager:libdm",
|
||||
]
|
||||
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
||||
|
@ -16,31 +16,36 @@
|
||||
#ifndef COOPERATE_H
|
||||
#define COOPERATE_H
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
#include "i_context.h"
|
||||
#include "i_plugin.h"
|
||||
#include "cooperate_manager.h"
|
||||
#include "i_cooperate.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class Cooperate : public IPlugin {
|
||||
class Cooperate final : public ICooperate {
|
||||
public:
|
||||
Cooperate(IContext *context);
|
||||
virtual ~Cooperate() = default;
|
||||
~Cooperate() = default;
|
||||
DISALLOW_COPY_AND_MOVE(Cooperate);
|
||||
|
||||
int32_t Enable(CallingContext &context, Parcel &data, Parcel &reply);
|
||||
int32_t Disable(CallingContext &context, Parcel &data, Parcel &reply);
|
||||
int32_t Start(CallingContext &context, Parcel &data, Parcel &reply);
|
||||
int32_t Stop(CallingContext &context, Parcel &data, Parcel &reply);
|
||||
int32_t AddWatch(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply);
|
||||
int32_t RemoveWatch(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply);
|
||||
int32_t SetParam(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply);
|
||||
int32_t GetParam(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply);
|
||||
int32_t Control(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply);
|
||||
int32_t RegisterListener(int32_t pid) override;
|
||||
int32_t UnregisterListener(int32_t pid) override;
|
||||
int32_t RegisterHotAreaListener(int32_t pid) override;
|
||||
int32_t UnregisterHotAreaListener(int32_t pid) override;
|
||||
|
||||
int32_t Enable(int32_t pid) override;
|
||||
int32_t Disable(int32_t pid) override;
|
||||
int32_t Start(int32_t pid, int32_t userData, const std::string &remoteNetworkId, int32_t startDeviceId) override;
|
||||
int32_t Stop(int32_t pid, int32_t userData, bool isUnchained) override;
|
||||
|
||||
int32_t GetCooperateState(int32_t pid, int32_t userData, const std::string &networkId) override;
|
||||
|
||||
void Dump(int32_t fd) override;
|
||||
|
||||
private:
|
||||
IContext *context_ { nullptr };
|
||||
CooperateManager cooperateMgr_;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
|
@ -23,11 +23,10 @@
|
||||
#include "nocopyable.h"
|
||||
#include "refbase.h"
|
||||
#include "singleton.h"
|
||||
#include "stream_session.h"
|
||||
|
||||
#include "cooperate_message.h"
|
||||
#include "fi_log.h"
|
||||
#include "coordination_message.h"
|
||||
#include "i_context.h"
|
||||
#include "i_socket_session.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
@ -38,11 +37,11 @@ public:
|
||||
enum EventType { LISTENER, ENABLE, START, STOP, STATE };
|
||||
struct EventInfo : public RefBase {
|
||||
EventType type { LISTENER };
|
||||
SessionPtr sess { nullptr };
|
||||
std::shared_ptr<ISocketSession> sess { nullptr };
|
||||
MessageId msgId { MessageId::INVALID };
|
||||
int32_t userData { -1 };
|
||||
std::string networkId;
|
||||
CooperateMessage msg { CooperateMessage::PREPARE };
|
||||
CoordinationMessage msg { CoordinationMessage::PREPARE };
|
||||
bool state { false };
|
||||
};
|
||||
|
||||
@ -50,19 +49,19 @@ public:
|
||||
|
||||
void AddCooperateEvent(sptr<EventInfo> event);
|
||||
void RemoveCooperateEvent(sptr<EventInfo> event);
|
||||
int32_t OnCooperateMessage(CooperateMessage msg, const std::string &networkId = "");
|
||||
void OnEnable(CooperateMessage msg, const std::string &networkId = "");
|
||||
void OnStart(CooperateMessage msg, const std::string &networkId = "");
|
||||
void OnStop(CooperateMessage msg, const std::string &networkId = "");
|
||||
int32_t OnCooperateMessage(CoordinationMessage msg, const std::string &networkId = "");
|
||||
void OnEnable(CoordinationMessage msg, const std::string &networkId = "");
|
||||
void OnStart(CoordinationMessage msg, const std::string &networkId = "");
|
||||
void OnStop(CoordinationMessage msg, const std::string &networkId = "");
|
||||
void OnGetCrossingSwitchState(bool state);
|
||||
void OnErrorMessage(EventType type, CooperateMessage msg);
|
||||
void OnErrorMessage(EventType type, CoordinationMessage msg);
|
||||
void SetIContext(IContext *context);
|
||||
IContext* GetIContext() const;
|
||||
|
||||
private:
|
||||
void NotifyCooperateMessage(SessionPtr sess, MessageId msgId, int32_t userData,
|
||||
const std::string &networkId, CooperateMessage msg);
|
||||
void NotifyCooperateState(SessionPtr sess, MessageId msgId, int32_t userData, bool state);
|
||||
void NotifyCooperateMessage(std::shared_ptr<ISocketSession> sess,
|
||||
MessageId msgId, int32_t userData, const std::string &networkId, CoordinationMessage msg);
|
||||
void NotifyCooperateState(std::shared_ptr<ISocketSession> sess, MessageId msgId, int32_t userData, bool state);
|
||||
|
||||
private:
|
||||
std::mutex lock_;
|
||||
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef COOPERATE_MANAGER_H
|
||||
#define COOPERATE_MANAGER_H
|
||||
|
||||
#include "stream_session.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class CooperateManager {
|
||||
public:
|
||||
CooperateManager() = default;
|
||||
~CooperateManager() = default;
|
||||
|
||||
void PrepareCooperate();
|
||||
void UnprepareCooperate();
|
||||
int32_t ActivateCooperate(SessionPtr sess,
|
||||
int32_t userData,
|
||||
const std::string &remoteNetworkId,
|
||||
int32_t startDeviceId);
|
||||
int32_t DeactivateCooperate(SessionPtr sess, int32_t userData, bool isUnchained);
|
||||
int32_t GetCooperateState(SessionPtr sess, int32_t userData, const std::string &networkId);
|
||||
int32_t RegisterCooperateListener(SessionPtr sess);
|
||||
int32_t UnregisterCooperateListener(SessionPtr sess);
|
||||
void Dump(int32_t fd);
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // COOPERATE_MANAGER_H
|
49
intention/cooperate/server/include/cooperate_server.h
Normal file
49
intention/cooperate/server/include/cooperate_server.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef COOPERATE_SERVER_H
|
||||
#define COOPERATE_SERVER_H
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
#include "i_context.h"
|
||||
#include "i_plugin.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class CooperateServer final : public IPlugin {
|
||||
public:
|
||||
CooperateServer(IContext *context);
|
||||
~CooperateServer() = default;
|
||||
DISALLOW_COPY_AND_MOVE(CooperateServer);
|
||||
|
||||
int32_t Enable(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Disable(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Start(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Stop(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t AddWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t RemoveWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t SetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t GetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Control(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
|
||||
private:
|
||||
IContext *context_ { nullptr };
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // COOPERATE_SERVER_H
|
@ -110,7 +110,7 @@ public:
|
||||
void SetAbsolutionLocation(double xPercent, double yPercent);
|
||||
DISALLOW_COPY_AND_MOVE(CooperateSM);
|
||||
void Init();
|
||||
void OnSessionLost(SessionPtr session);
|
||||
void OnSessionLost(std::shared_ptr<ISocketSession> session);
|
||||
void PrepareCooperate();
|
||||
void UnprepareCooperate();
|
||||
int32_t ActivateCooperate(const std::string &remoteNetworkId, int32_t startDeviceId);
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "session.h"
|
||||
|
||||
#include "cooperate_util.h"
|
||||
#include "json_parser.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
|
@ -18,26 +18,9 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
struct JsonParser {
|
||||
JsonParser() = default;
|
||||
~JsonParser()
|
||||
{
|
||||
if (json != nullptr) {
|
||||
cJSON_Delete(json);
|
||||
json = nullptr;
|
||||
}
|
||||
}
|
||||
operator cJSON *()
|
||||
{
|
||||
return json;
|
||||
}
|
||||
cJSON *json { nullptr };
|
||||
};
|
||||
namespace COOPERATE {
|
||||
std::string GetLocalNetworkId();
|
||||
} // namespace COOPERATE
|
||||
|
@ -35,12 +35,12 @@ public:
|
||||
virtual ~ICooperateState() = default;
|
||||
virtual int32_t ActivateCooperate(const std::string &remoteNetworkId, int32_t startDeviceId)
|
||||
{
|
||||
return static_cast<int32_t>(CooperateMessage::COOPERATE_FAIL);
|
||||
return static_cast<int32_t>(CoordinationMessage::COORDINATION_FAIL);
|
||||
}
|
||||
virtual int32_t DeactivateCooperate(const std::string &networkId, bool isUnchained,
|
||||
const std::pair<std::string, std::string> &preparedNetworkId)
|
||||
{
|
||||
return static_cast<int32_t>(CooperateMessage::COOPERATE_FAIL);
|
||||
return static_cast<int32_t>(CoordinationMessage::COORDINATION_FAIL);
|
||||
}
|
||||
virtual void OnKeyboardOnline(const std::string &dhid, const std::pair<std::string, std::string> &networkIds) {}
|
||||
virtual void SetStartDeviceDhid(const std::string &startDeviceDhid) {}
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include "cooperate.h"
|
||||
|
||||
#include "cooperate_params.h"
|
||||
#include "devicestatus_define.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -29,100 +28,72 @@ Cooperate::Cooperate(IContext *context)
|
||||
: context_(context)
|
||||
{}
|
||||
|
||||
int32_t Cooperate::Enable(CallingContext &context, Parcel &data, Parcel &reply)
|
||||
int32_t Cooperate::RegisterListener(int32_t pid)
|
||||
{
|
||||
cooperateMgr_.PrepareCooperate();
|
||||
return RET_OK;
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t Cooperate::Disable(CallingContext &context, Parcel &data, Parcel &reply)
|
||||
int32_t Cooperate::UnregisterListener(int32_t pid)
|
||||
{
|
||||
cooperateMgr_.UnprepareCooperate();
|
||||
return RET_OK;
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t Cooperate::Start(CallingContext &context, Parcel &data, Parcel &reply)
|
||||
int32_t Cooperate::RegisterHotAreaListener(int32_t pid)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t Cooperate::UnregisterHotAreaListener(int32_t pid)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t Cooperate::Enable(int32_t pid)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t Cooperate::Disable(int32_t pid)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t Cooperate::Start(int32_t pid, int32_t userData, const std::string &remoteNetworkId, int32_t startDeviceId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CHKPR(context_, RET_ERR);
|
||||
StartCooperateParam param;
|
||||
if (!param.Unmarshalling(data)) {
|
||||
FI_HILOGE("Failed to unmarshalling param");
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t ret = cooperateMgr_.ActivateCooperate(context.session, param.userData, param.remoteNetworkId,
|
||||
param.startDeviceId);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Activate cooperate failed, ret:%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t Cooperate::Stop(CallingContext &context, Parcel &data, Parcel &reply)
|
||||
int32_t Cooperate::Stop(int32_t pid, int32_t userData, bool isUnchained)
|
||||
{
|
||||
StopCooperateParam param;
|
||||
if (!param.Unmarshalling(data)) {
|
||||
FI_HILOGE("Failed to unmarshalling param");
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t ret = cooperateMgr_.DeactivateCooperate(context.session, param.userData, param.isUnchained);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Deactivate cooperate failed, ret:%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t Cooperate::AddWatch(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply)
|
||||
{
|
||||
int32_t ret = cooperateMgr_.RegisterCooperateListener(context.session);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Register cooperate listener failed, ret:%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t Cooperate::RemoveWatch(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply)
|
||||
{
|
||||
int32_t ret = cooperateMgr_.UnregisterCooperateListener(context.session);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Unregister cooperate listener failed, ret:%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t Cooperate::SetParam(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply)
|
||||
int32_t Cooperate::GetCooperateState(int32_t pid, int32_t userData, const std::string &networkId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t Cooperate::GetParam(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply)
|
||||
void Cooperate::Dump(int32_t fd)
|
||||
{
|
||||
GetCooperateStateParam param;
|
||||
if (!param.Unmarshalling(data)) {
|
||||
FI_HILOGE("Failed to unmarshalling param");
|
||||
return RET_ERR;
|
||||
CALL_DEBUG_ENTER;
|
||||
}
|
||||
|
||||
int32_t ret = cooperateMgr_.GetCooperateState(context.session, param.userData, param.deviceId);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Get cooperate state failed");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t Cooperate::Control(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply)
|
||||
extern "C" ICooperate* CreateInstance(IContext *context)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
extern "C" IPlugin* CreateInstance(IContext *context)
|
||||
{
|
||||
CHKPP(context);
|
||||
return new (std::nothrow) Cooperate(context);
|
||||
}
|
||||
|
||||
extern "C" void DestroyInstance(IPlugin *instance)
|
||||
extern "C" void DestroyInstance(ICooperate *instance)
|
||||
{
|
||||
if (instance != nullptr) {
|
||||
delete instance;
|
||||
|
@ -49,6 +49,7 @@ void CooperateEventManager::AddCooperateEvent(sptr<EventInfo> event)
|
||||
void CooperateEventManager::RemoveCooperateEvent(sptr<EventInfo> event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
if (remoteCooperateCallbacks_.empty() || event == nullptr) {
|
||||
FI_HILOGE("Remove listener failed");
|
||||
return;
|
||||
@ -61,7 +62,7 @@ void CooperateEventManager::RemoveCooperateEvent(sptr<EventInfo> event)
|
||||
}
|
||||
}
|
||||
|
||||
int32_t CooperateEventManager::OnCooperateMessage(CooperateMessage msg, const std::string &networkId)
|
||||
int32_t CooperateEventManager::OnCooperateMessage(CoordinationMessage msg, const std::string &networkId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
@ -77,7 +78,7 @@ int32_t CooperateEventManager::OnCooperateMessage(CooperateMessage msg, const st
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void CooperateEventManager::OnEnable(CooperateMessage msg, const std::string &networkId)
|
||||
void CooperateEventManager::OnEnable(CoordinationMessage msg, const std::string &networkId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
@ -87,7 +88,7 @@ void CooperateEventManager::OnEnable(CooperateMessage msg, const std::string &ne
|
||||
cooperateCallbacks_[EventType::ENABLE] = nullptr;
|
||||
}
|
||||
|
||||
void CooperateEventManager::OnStart(CooperateMessage msg, const std::string &networkId)
|
||||
void CooperateEventManager::OnStart(CoordinationMessage msg, const std::string &networkId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
@ -97,7 +98,7 @@ void CooperateEventManager::OnStart(CooperateMessage msg, const std::string &net
|
||||
cooperateCallbacks_[EventType::START] = nullptr;
|
||||
}
|
||||
|
||||
void CooperateEventManager::OnStop(CooperateMessage msg, const std::string &networkId)
|
||||
void CooperateEventManager::OnStop(CoordinationMessage msg, const std::string &networkId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
@ -117,7 +118,7 @@ void CooperateEventManager::OnGetCrossingSwitchState(bool state)
|
||||
cooperateCallbacks_[EventType::STATE] = nullptr;
|
||||
}
|
||||
|
||||
void CooperateEventManager::OnErrorMessage(EventType type, CooperateMessage msg)
|
||||
void CooperateEventManager::OnErrorMessage(EventType type, CoordinationMessage msg)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
sptr<EventInfo> info = cooperateCallbacks_[type];
|
||||
@ -136,8 +137,8 @@ IContext* CooperateEventManager::GetIContext() const
|
||||
return context_;
|
||||
}
|
||||
|
||||
void CooperateEventManager::NotifyCooperateMessage(
|
||||
SessionPtr sess, MessageId msgId, int32_t userData, const std::string &networkId, CooperateMessage msg)
|
||||
void CooperateEventManager::NotifyCooperateMessage(std::shared_ptr<ISocketSession> sess,
|
||||
MessageId msgId, int32_t userData, const std::string &networkId, CoordinationMessage msg)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CHKPV(sess);
|
||||
@ -153,7 +154,8 @@ void CooperateEventManager::NotifyCooperateMessage(
|
||||
}
|
||||
}
|
||||
|
||||
void CooperateEventManager::NotifyCooperateState(SessionPtr sess, MessageId msgId, int32_t userData, bool state)
|
||||
void CooperateEventManager::NotifyCooperateState(std::shared_ptr<ISocketSession> sess,
|
||||
MessageId msgId, int32_t userData, bool state)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CHKPV(sess);
|
||||
|
@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "cooperate_manager.h"
|
||||
|
||||
#include "cooperate_event_manager.h"
|
||||
#include "cooperate_sm.h"
|
||||
#include "cooperate_util.h"
|
||||
#include "distributed_input_adapter.h"
|
||||
#include "proto.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "CooperateManager" };
|
||||
} // namespace
|
||||
|
||||
void CooperateManager::PrepareCooperate()
|
||||
{
|
||||
COOR_SM->PrepareCooperate();
|
||||
}
|
||||
|
||||
void CooperateManager::UnprepareCooperate()
|
||||
{
|
||||
COOR_SM->UnprepareCooperate();
|
||||
}
|
||||
|
||||
int32_t CooperateManager::ActivateCooperate(SessionPtr sess, int32_t userData,
|
||||
const std::string& remoteNetworkId, int32_t startDeviceId)
|
||||
{
|
||||
sptr<CooperateEventManager::EventInfo> event = new (std::nothrow) CooperateEventManager::EventInfo();
|
||||
CHKPR(event, RET_ERR);
|
||||
event->type = CooperateEventManager::EventType::START;
|
||||
event->sess = sess;
|
||||
event->msgId = MessageId::COORDINATION_MESSAGE;
|
||||
event->userData = userData;
|
||||
COOR_EVENT_MGR->AddCooperateEvent(event);
|
||||
int32_t ret = COOR_SM->ActivateCooperate(remoteNetworkId, startDeviceId);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("ActivateCooperate failed, ret:%{public}d", ret);
|
||||
COOR_EVENT_MGR->OnErrorMessage(event->type, static_cast<CooperateMessage>(ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t CooperateManager::DeactivateCooperate(SessionPtr sess, int32_t userData, bool isUnchained)
|
||||
{
|
||||
sptr<CooperateEventManager::EventInfo> event = new (std::nothrow) CooperateEventManager::EventInfo();
|
||||
CHKPR(event, RET_ERR);
|
||||
event->type = CooperateEventManager::EventType::STOP;
|
||||
event->sess = sess;
|
||||
event->msgId = MessageId::COORDINATION_MESSAGE;
|
||||
event->userData = userData;
|
||||
COOR_EVENT_MGR->AddCooperateEvent(event);
|
||||
int32_t ret = COOR_SM->DeactivateCooperate(isUnchained);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Deactivate cooperate manager failed, ret:%{public}d", ret);
|
||||
COOR_EVENT_MGR->OnErrorMessage(event->type, static_cast<CooperateMessage>(ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t CooperateManager::GetCooperateState(SessionPtr sess, int32_t userData, const std::string &networkId)
|
||||
{
|
||||
sptr<CooperateEventManager::EventInfo> event = new (std::nothrow) CooperateEventManager::EventInfo();
|
||||
CHKPR(event, RET_ERR);
|
||||
event->type = CooperateEventManager::EventType::STATE;
|
||||
event->sess = sess;
|
||||
event->msgId = MessageId::COORDINATION_GET_STATE;
|
||||
event->userData = userData;
|
||||
COOR_EVENT_MGR->AddCooperateEvent(event);
|
||||
int32_t ret = COOR_SM->GetCooperateState(networkId);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Get cooperate manager state failed");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t CooperateManager::RegisterCooperateListener(SessionPtr sess)
|
||||
{
|
||||
sptr<CooperateEventManager::EventInfo> event = new (std::nothrow) CooperateEventManager::EventInfo();
|
||||
CHKPR(event, RET_ERR);
|
||||
event->type = CooperateEventManager::EventType::LISTENER;
|
||||
event->sess = sess;
|
||||
event->msgId = MessageId::COORDINATION_ADD_LISTENER;
|
||||
COOR_EVENT_MGR->AddCooperateEvent(event);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t CooperateManager::UnregisterCooperateListener(SessionPtr sess)
|
||||
{
|
||||
sptr<CooperateEventManager::EventInfo> event = new (std::nothrow) CooperateEventManager::EventInfo();
|
||||
CHKPR(event, RET_ERR);
|
||||
event->type = CooperateEventManager::EventType::LISTENER;
|
||||
event->sess = sess;
|
||||
COOR_EVENT_MGR->RemoveCooperateEvent(event);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void CooperateManager::Dump(int32_t fd)
|
||||
{
|
||||
COOR_SM->Dump(fd);
|
||||
}
|
||||
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
162
intention/cooperate/server/src/cooperate_server.cpp
Normal file
162
intention/cooperate/server/src/cooperate_server.cpp
Normal file
@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "cooperate_server.h"
|
||||
|
||||
#include "cooperate_params.h"
|
||||
#include "devicestatus_define.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "CooperateServer" };
|
||||
} // namespace
|
||||
|
||||
CooperateServer::CooperateServer(IContext *context)
|
||||
: context_(context)
|
||||
{}
|
||||
|
||||
int32_t CooperateServer::Enable(CallingContext &context, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CHKPR(context_, RET_ERR);
|
||||
ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
|
||||
CHKPR(cooperate, RET_ERR);
|
||||
cooperate->Enable(context.pid);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t CooperateServer::Disable(CallingContext &context, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CHKPR(context_, RET_ERR);
|
||||
ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
|
||||
CHKPR(cooperate, RET_ERR);
|
||||
cooperate->Disable(context.pid);
|
||||
context_->GetPluginManager().UnloadCooperate();
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t CooperateServer::Start(CallingContext &context, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
StartCooperateParam param;
|
||||
if (!param.Unmarshalling(data)) {
|
||||
FI_HILOGE("StartCooperateParam::Unmarshalling fail");
|
||||
return RET_ERR;
|
||||
}
|
||||
CHKPR(context_, RET_ERR);
|
||||
ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
|
||||
CHKPR(cooperate, RET_ERR);
|
||||
return cooperate->Start(context.pid, param.userData, param.remoteNetworkId, param.startDeviceId);
|
||||
}
|
||||
|
||||
int32_t CooperateServer::Stop(CallingContext &context, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
StopCooperateParam param;
|
||||
if (!param.Unmarshalling(data)) {
|
||||
FI_HILOGE("StopCooperateParam::Unmarshalling fail");
|
||||
return RET_ERR;
|
||||
}
|
||||
CHKPR(context_, RET_ERR);
|
||||
ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
|
||||
CHKPR(cooperate, RET_ERR);
|
||||
return cooperate->Stop(context.pid, param.userData, param.isUnchained);
|
||||
}
|
||||
|
||||
int32_t CooperateServer::AddWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
switch (id) {
|
||||
case CooperateRequestID::REGISTER_LISTENER: {
|
||||
CHKPR(context_, RET_ERR);
|
||||
ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
|
||||
CHKPR(cooperate, RET_ERR);
|
||||
return cooperate->RegisterListener(context.pid);
|
||||
}
|
||||
case CooperateRequestID::REGISTER_HOTAREA_LISTENER: {
|
||||
CHKPR(context_, RET_ERR);
|
||||
ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
|
||||
CHKPR(cooperate, RET_ERR);
|
||||
return cooperate->RegisterHotAreaListener(context.pid);
|
||||
}
|
||||
default: {
|
||||
FI_HILOGE("Unexpected request ID (%{public}u)", id);
|
||||
return RET_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t CooperateServer::RemoveWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
switch (id) {
|
||||
case CooperateRequestID::UNREGISTER_LISTENER: {
|
||||
CHKPR(context_, RET_ERR);
|
||||
ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
|
||||
CHKPR(cooperate, RET_ERR);
|
||||
return cooperate->UnregisterListener(context.pid);
|
||||
}
|
||||
case CooperateRequestID::UNREGISTER_HOTAREA_LISTENER: {
|
||||
CHKPR(context_, RET_ERR);
|
||||
ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
|
||||
CHKPR(cooperate, RET_ERR);
|
||||
return cooperate->UnregisterHotAreaListener(context.pid);
|
||||
}
|
||||
default: {
|
||||
FI_HILOGE("Unexpected request ID (%{public}u)", id);
|
||||
return RET_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t CooperateServer::SetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t CooperateServer::GetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
switch (id) {
|
||||
case CooperateRequestID::GET_COOPERATE_STATE: {
|
||||
GetCooperateStateParam param;
|
||||
if (!param.Unmarshalling(data)) {
|
||||
FI_HILOGE("GetCooperateStateParam::Unmarshalling fail");
|
||||
return RET_ERR;
|
||||
}
|
||||
CHKPR(context_, RET_ERR);
|
||||
ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
|
||||
CHKPR(cooperate, RET_ERR);
|
||||
return cooperate->GetCooperateState(context.pid, param.userData, param.networkId);
|
||||
}
|
||||
default: {
|
||||
FI_HILOGE("Unexpected request ID (%{public}u)", id);
|
||||
return RET_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t CooperateServer::Control(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
@ -26,7 +26,6 @@
|
||||
|
||||
#include "cooperate_device_manager.h"
|
||||
#include "cooperate_event_manager.h"
|
||||
#include "cooperate_message.h"
|
||||
#include "cooperate_softbus_adapter.h"
|
||||
#include "cooperate_state_free.h"
|
||||
#include "cooperate_state_in.h"
|
||||
@ -92,7 +91,7 @@ void CooperateSM::OnReset(const std::string &networkId)
|
||||
Reset(networkId);
|
||||
}
|
||||
|
||||
void CooperateSM::OnSessionLost(SessionPtr session)
|
||||
void CooperateSM::OnSessionLost(std::shared_ptr<ISocketSession> session)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CHKPV(session);
|
||||
@ -148,10 +147,10 @@ void CooperateSM::Reset(bool adjustAbsolutionLocation)
|
||||
void CooperateSM::OnCooperateChanged(const std::string &networkId, bool isOpen)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CooperateMessage msg = isOpen ? CooperateMessage::PREPARE : CooperateMessage::UNPREPARE;
|
||||
CoordinationMessage msg = isOpen ? CoordinationMessage::PREPARE : CoordinationMessage::UNPREPARE;
|
||||
auto *context = COOR_EVENT_MGR->GetIContext();
|
||||
CHKPV(context);
|
||||
int32_t ret = context->GetTaskScheduler().PostAsyncTask(
|
||||
int32_t ret = context->GetDelegateTasks().PostAsyncTask(
|
||||
std::bind(&CooperateEventManager::OnCooperateMessage, COOR_EVENT_MGR, msg, networkId));
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Posting async task failed");
|
||||
@ -196,7 +195,7 @@ int32_t CooperateSM::GetCooperateState(const std::string &networkId)
|
||||
CALL_INFO_TRACE;
|
||||
if (networkId.empty()) {
|
||||
FI_HILOGE("Transfer network id is empty");
|
||||
return static_cast<int32_t>(CooperateMessage::PARAMETER_ERROR);
|
||||
return static_cast<int32_t>(CoordinationMessage::PARAMETER_ERROR);
|
||||
}
|
||||
bool state = DP_ADAPTER->GetCrossingSwitchState(networkId);
|
||||
COOR_EVENT_MGR->OnGetCrossingSwitchState(state);
|
||||
@ -235,12 +234,12 @@ int32_t CooperateSM::ActivateCooperate(const std::string &remoteNetworkId, int32
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
if (isStarting_) {
|
||||
FI_HILOGE("In transition state, not process");
|
||||
return static_cast<int32_t>(CooperateMessage::COOPERATE_FAIL);
|
||||
return static_cast<int32_t>(CoordinationMessage::COORDINATION_FAIL);
|
||||
}
|
||||
UpdateMouseLocation();
|
||||
if (COOR_SOFTBUS_ADAPTER->OpenInputSoftbus(remoteNetworkId) != RET_OK) {
|
||||
FI_HILOGE("Open input softbus failed");
|
||||
return static_cast<int32_t>(CooperateMessage::COOPERATE_FAIL);
|
||||
return static_cast<int32_t>(CoordinationMessage::COORDINATION_FAIL);
|
||||
}
|
||||
isStarting_ = true;
|
||||
SetSinkNetworkId(remoteNetworkId);
|
||||
@ -306,8 +305,8 @@ void CooperateSM::StartRemoteCooperate(const std::string &remoteNetworkId, bool
|
||||
CHKPV(context);
|
||||
COOR_SM->SetSinkNetworkId(remoteNetworkId);
|
||||
FI_HILOGD("The remoteNetworkId:%{public}s", remoteNetworkId.substr(0, SUBSTR_NETWORKID_LEN).c_str());
|
||||
int32_t ret = context->GetTaskScheduler().PostAsyncTask(std::bind(&CooperateEventManager::OnCooperateMessage,
|
||||
COOR_EVENT_MGR, CooperateMessage::ACTIVATE, remoteNetworkId));
|
||||
int32_t ret = context->GetDelegateTasks().PostAsyncTask(std::bind(&CooperateEventManager::OnCooperateMessage,
|
||||
COOR_EVENT_MGR, CoordinationMessage::ACTIVATE, remoteNetworkId));
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Posting async task failed");
|
||||
}
|
||||
@ -348,10 +347,10 @@ void CooperateSM::StartRemoteCooperateResult(bool isSuccess, const std::string &
|
||||
return;
|
||||
}
|
||||
startDeviceDhid_ = startDeviceDhid;
|
||||
CooperateMessage msg = isSuccess ? CooperateMessage::ACTIVATE_SUCCESS : CooperateMessage::ACTIVATE_FAIL;
|
||||
CoordinationMessage msg = isSuccess ? CoordinationMessage::ACTIVATE_SUCCESS : CoordinationMessage::ACTIVATE_FAIL;
|
||||
auto *context = COOR_EVENT_MGR->GetIContext();
|
||||
CHKPV(context);
|
||||
int32_t ret = context->GetTaskScheduler().PostAsyncTask(
|
||||
int32_t ret = context->GetDelegateTasks().PostAsyncTask(
|
||||
std::bind(&CooperateEventManager::OnCooperateMessage, COOR_EVENT_MGR, msg, ""));
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Posting async task failed");
|
||||
@ -523,7 +522,7 @@ void CooperateSM::NotifyRemoteStartFail(const std::string &remoteNetworkId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
COOR_SOFTBUS_ADAPTER->StartRemoteCooperateResult(remoteNetworkId, false, "", 0, 0);
|
||||
COOR_EVENT_MGR->OnStart(CooperateMessage::ACTIVATE_FAIL);
|
||||
COOR_EVENT_MGR->OnStart(CoordinationMessage::ACTIVATE_FAIL);
|
||||
}
|
||||
|
||||
void CooperateSM::NotifyRemoteStartSuccess(const std::string &remoteNetworkId, const std::string &startDeviceDhid)
|
||||
@ -531,7 +530,7 @@ void CooperateSM::NotifyRemoteStartSuccess(const std::string &remoteNetworkId, c
|
||||
CALL_DEBUG_ENTER;
|
||||
COOR_SOFTBUS_ADAPTER->StartRemoteCooperateResult(remoteNetworkId, true, startDeviceDhid, mouseLocation_.first,
|
||||
mouseLocation_.second);
|
||||
COOR_EVENT_MGR->OnStart(CooperateMessage::ACTIVATE_SUCCESS);
|
||||
COOR_EVENT_MGR->OnStart(CoordinationMessage::ACTIVATE_SUCCESS);
|
||||
}
|
||||
|
||||
void CooperateSM::NotifyRemoteStopFinish(bool isSuccess, const std::string &remoteNetworkId)
|
||||
@ -539,9 +538,9 @@ void CooperateSM::NotifyRemoteStopFinish(bool isSuccess, const std::string &remo
|
||||
CALL_DEBUG_ENTER;
|
||||
COOR_SOFTBUS_ADAPTER->StopRemoteCooperateResult(remoteNetworkId, isSuccess);
|
||||
if (!isSuccess) {
|
||||
COOR_EVENT_MGR->OnStop(CooperateMessage::COOPERATE_FAIL);
|
||||
COOR_EVENT_MGR->OnStop(CoordinationMessage::COORDINATION_FAIL);
|
||||
} else {
|
||||
COOR_EVENT_MGR->OnStop(CooperateMessage::DEACTIVATE_SUCCESS);
|
||||
COOR_EVENT_MGR->OnStop(CoordinationMessage::DEACTIVATE_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -754,10 +753,10 @@ void CooperateSM::OnDeviceOffline(const std::string &networkId)
|
||||
}
|
||||
}
|
||||
if ((currentState_ == CooperateState::STATE_IN) && (sinkNetworkId_ == networkId)) {
|
||||
COOR_EVENT_MGR->OnCooperateMessage(CooperateMessage::SESSION_CLOSED);
|
||||
COOR_EVENT_MGR->OnCooperateMessage(CoordinationMessage::SESSION_CLOSED);
|
||||
}
|
||||
if ((currentState_ == CooperateState::STATE_OUT) && (remoteNetworkId_ == networkId)) {
|
||||
COOR_EVENT_MGR->OnCooperateMessage(CooperateMessage::SESSION_CLOSED);
|
||||
COOR_EVENT_MGR->OnCooperateMessage(CoordinationMessage::SESSION_CLOSED);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1099,10 +1098,10 @@ void CooperateSM::SetUnchainStatus(bool isUnchained)
|
||||
void CooperateSM::NotifyChainRemoved()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CooperateMessage msg = CooperateMessage::SESSION_CLOSED;
|
||||
CoordinationMessage msg = CoordinationMessage::SESSION_CLOSED;
|
||||
auto *context = COOR_EVENT_MGR->GetIContext();
|
||||
CHKPV(context);
|
||||
int32_t ret = context->GetTaskScheduler().PostAsyncTask(
|
||||
int32_t ret = context->GetDelegateTasks().PostAsyncTask(
|
||||
std::bind(&CooperateEventManager::OnCooperateMessage, COOR_EVENT_MGR, msg, ""));
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Posting async task failed");
|
||||
@ -1152,7 +1151,7 @@ void CooperateSM::RegisterSessionCallback()
|
||||
FI_HILOGI("Recv session callback status:%{public}u", status);
|
||||
if (status == P2P_SESSION_CLOSED) {
|
||||
preparedNetworkId_ = std::pair("", "");
|
||||
COOR_EVENT_MGR->OnCooperateMessage(CooperateMessage::SESSION_CLOSED);
|
||||
COOR_EVENT_MGR->OnCooperateMessage(CoordinationMessage::SESSION_CLOSED);
|
||||
Reset();
|
||||
}
|
||||
});
|
||||
@ -1166,7 +1165,7 @@ bool PointerFilter::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent
|
||||
FI_HILOGI("Current event is down");
|
||||
auto *context = COOR_EVENT_MGR->GetIContext();
|
||||
CHKPF(context);
|
||||
int32_t ret = context->GetTaskScheduler().PostAsyncTask(
|
||||
int32_t ret = context->GetDelegateTasks().PostAsyncTask(
|
||||
std::bind(&MMI::InputManager::RemoveInputEventFilter, MMI::InputManager::GetInstance(), filterId_));
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Posting async task failed");
|
||||
|
@ -311,6 +311,7 @@ int32_t CooperateSoftbusAdapter::StartRemoteCooperate(const std::string &localNe
|
||||
}
|
||||
FI_HILOGD("isPointerButtonPressed:%{public}d", isPointerButtonPressed);
|
||||
cJSON *jsonStr = cJSON_CreateObject();
|
||||
CHKPR(jsonStr, RET_ERR);
|
||||
cJSON_AddItemToObject(jsonStr, FI_SOFTBUS_KEY_CMD_TYPE, cJSON_CreateNumber(REMOTE_COOPERATE_START));
|
||||
cJSON_AddItemToObject(jsonStr, FI_SOFTBUS_KEY_LOCAL_DEVICE_ID, cJSON_CreateString(localNetworkId.c_str()));
|
||||
cJSON_AddItemToObject(jsonStr, FI_SOFTBUS_KEY_SESSION_ID, cJSON_CreateNumber(sessionId));
|
||||
@ -345,6 +346,7 @@ int32_t CooperateSoftbusAdapter::StartRemoteCooperateResult(const std::string &r
|
||||
}
|
||||
int32_t sessionId = sessionDevs_[remoteNetworkId];
|
||||
cJSON *jsonStr = cJSON_CreateObject();
|
||||
CHKPR(jsonStr, RET_ERR);
|
||||
cJSON_AddItemToObject(jsonStr, FI_SOFTBUS_KEY_CMD_TYPE, cJSON_CreateNumber(REMOTE_COOPERATE_START_RES));
|
||||
cJSON_AddItemToObject(jsonStr, FI_SOFTBUS_KEY_RESULT, cJSON_CreateBool(isSuccess));
|
||||
cJSON_AddItemToObject(jsonStr, FI_SOFTBUS_KEY_START_DHID, cJSON_CreateString(startDeviceDhid.c_str()));
|
||||
@ -372,6 +374,7 @@ int32_t CooperateSoftbusAdapter::StopRemoteCooperate(const std::string &remoteNe
|
||||
}
|
||||
int32_t sessionId = sessionDevs_[remoteNetworkId];
|
||||
cJSON *jsonStr = cJSON_CreateObject();
|
||||
CHKPR(jsonStr, RET_ERR);
|
||||
cJSON_AddItemToObject(jsonStr, FI_SOFTBUS_KEY_CMD_TYPE, cJSON_CreateNumber(REMOTE_COOPERATE_STOP));
|
||||
cJSON_AddItemToObject(jsonStr, FI_SOFTBUS_KEY_RESULT, cJSON_CreateBool(isUnchained));
|
||||
cJSON_AddItemToObject(jsonStr, FI_SOFTBUS_KEY_SESSION_ID, cJSON_CreateNumber(sessionId));
|
||||
@ -397,6 +400,7 @@ int32_t CooperateSoftbusAdapter::StopRemoteCooperateResult(const std::string &re
|
||||
}
|
||||
int32_t sessionId = sessionDevs_[remoteNetworkId];
|
||||
cJSON *jsonStr = cJSON_CreateObject();
|
||||
CHKPR(jsonStr, RET_ERR);
|
||||
cJSON_AddItemToObject(jsonStr, FI_SOFTBUS_KEY_CMD_TYPE, cJSON_CreateNumber(REMOTE_COOPERATE_STOP_RES));
|
||||
cJSON_AddItemToObject(jsonStr, FI_SOFTBUS_KEY_RESULT, cJSON_CreateBool(isSuccess));
|
||||
cJSON_AddItemToObject(jsonStr, FI_SOFTBUS_KEY_SESSION_ID, cJSON_CreateNumber(sessionId));
|
||||
@ -474,6 +478,7 @@ int32_t CooperateSoftbusAdapter::StartCooperateOtherResult(const std::string &or
|
||||
}
|
||||
int32_t sessionId = sessionDevs_[originNetworkId];
|
||||
cJSON *jsonStr = cJSON_CreateObject();
|
||||
CHKPR(jsonStr, RET_ERR);
|
||||
cJSON_AddItemToObject(jsonStr, FI_SOFTBUS_KEY_CMD_TYPE, cJSON_CreateNumber(REMOTE_COOPERATE_STOP_OTHER_RES));
|
||||
cJSON_AddItemToObject(jsonStr, FI_SOFTBUS_KEY_OTHER_DEVICE_ID, cJSON_CreateString(remoteNetworkId.c_str()));
|
||||
cJSON_AddItemToObject(jsonStr, FI_SOFTBUS_KEY_SESSION_ID, cJSON_CreateNumber(sessionId));
|
||||
@ -491,13 +496,13 @@ int32_t CooperateSoftbusAdapter::StartCooperateOtherResult(const std::string &or
|
||||
void CooperateSoftbusAdapter::HandleSessionData(int32_t sessionId, const std::string &message)
|
||||
{
|
||||
if (message.empty()) {
|
||||
FI_HILOGE("Message is empty");
|
||||
FI_HILOGE("message is empty");
|
||||
return;
|
||||
}
|
||||
JsonParser parser;
|
||||
parser.json = cJSON_Parse(message.c_str());
|
||||
if (!cJSON_IsObject(parser.json)) {
|
||||
FI_HILOGI("Parser json is not object");
|
||||
FI_HILOGI("parser json is not object");
|
||||
if (message.size() < sizeof(DataPacket)) {
|
||||
FI_HILOGE("Data packet is incomplete");
|
||||
return;
|
||||
@ -508,10 +513,10 @@ void CooperateSoftbusAdapter::HandleSessionData(int32_t sessionId, const std::st
|
||||
return;
|
||||
}
|
||||
if (registerRecvs_.find(dataPacket->messageId) == registerRecvs_.end()) {
|
||||
FI_HILOGW("Message:%{public}d does not register", dataPacket->messageId);
|
||||
FI_HILOGW("message:%{public}d does not register", dataPacket->messageId);
|
||||
return;
|
||||
}
|
||||
FI_HILOGI("Message:%{public}d", dataPacket->messageId);
|
||||
FI_HILOGI("message:%{public}d", dataPacket->messageId);
|
||||
if ((dataPacket->messageId == DRAGGING_DATA) ||
|
||||
(dataPacket->messageId == STOPDRAG_DATA) ||
|
||||
(dataPacket->messageId == IS_PULL_UP) ||
|
||||
@ -637,6 +642,7 @@ int32_t CooperateSoftbusAdapter::SendData(const std::string &networkId, MessageI
|
||||
free(dataPacket);
|
||||
return RET_ERR;
|
||||
}
|
||||
std::unique_lock<std::mutex> sessionLock(operationMutex_);
|
||||
int32_t result = SendBytes(sessionDevs_[networkId], dataPacket, sizeof(DataPacket) + dataLen);
|
||||
free(dataPacket);
|
||||
if (result != RET_OK) {
|
||||
|
@ -31,18 +31,18 @@ int32_t CooperateStateFree::ActivateCooperate(
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
if (remoteNetworkId.empty()) {
|
||||
FI_HILOGE("RemoteNetworkId is empty");
|
||||
return static_cast<int32_t>(CooperateMessage::PARAMETER_ERROR);
|
||||
FI_HILOGE("remoteNetworkId is empty");
|
||||
return static_cast<int32_t>(CoordinationMessage::PARAMETER_ERROR);
|
||||
}
|
||||
std::string localNetworkId = COOPERATE::GetLocalNetworkId();
|
||||
if (localNetworkId.empty() || remoteNetworkId == localNetworkId) {
|
||||
FI_HILOGE("Input Parameters error");
|
||||
return static_cast<int32_t>(CooperateMessage::PARAMETER_ERROR);
|
||||
return static_cast<int32_t>(CoordinationMessage::PARAMETER_ERROR);
|
||||
}
|
||||
int32_t ret = COOR_SOFTBUS_ADAPTER->StartRemoteCooperate(localNetworkId, remoteNetworkId, true);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Start input device cooperate failed");
|
||||
return static_cast<int32_t>(CooperateMessage::COOPERATE_FAIL);
|
||||
return static_cast<int32_t>(CoordinationMessage::COORDINATION_FAIL);
|
||||
}
|
||||
std::string taskName = "process_start_task";
|
||||
std::function<void()> handleProcessStartFunc =
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
#include "cooperate_device_manager.h"
|
||||
#include "cooperate_event_manager.h"
|
||||
#include "cooperate_message.h"
|
||||
#include "cooperate_sm.h"
|
||||
#include "cooperate_softbus_adapter.h"
|
||||
#include "cooperate_util.h"
|
||||
@ -37,18 +36,18 @@ int32_t CooperateStateIn::ActivateCooperate(const std::string &remoteNetworkId,
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
if (remoteNetworkId.empty()) {
|
||||
FI_HILOGE("RemoteNetworkId is empty");
|
||||
return static_cast<int32_t>(CooperateMessage::PARAMETER_ERROR);
|
||||
FI_HILOGE("remoteNetworkId is empty");
|
||||
return static_cast<int32_t>(CoordinationMessage::PARAMETER_ERROR);
|
||||
}
|
||||
std::string localNetworkId = COOPERATE::GetLocalNetworkId();
|
||||
if (localNetworkId.empty() || remoteNetworkId == localNetworkId) {
|
||||
FI_HILOGE("Input Parameters error");
|
||||
return static_cast<int32_t>(CooperateMessage::PARAMETER_ERROR);
|
||||
return static_cast<int32_t>(CoordinationMessage::PARAMETER_ERROR);
|
||||
}
|
||||
int32_t ret = COOR_SOFTBUS_ADAPTER->StartRemoteCooperate(localNetworkId, remoteNetworkId, false);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Start cooperate failed");
|
||||
return static_cast<int32_t>(CooperateMessage::COOPERATE_FAIL);
|
||||
return static_cast<int32_t>(CoordinationMessage::COORDINATION_FAIL);
|
||||
}
|
||||
std::string taskName = "process_start_task";
|
||||
std::function<void()> handleProcessStartFunc =
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
#include "cooperate_device_manager.h"
|
||||
#include "cooperate_event_manager.h"
|
||||
#include "cooperate_message.h"
|
||||
#include "cooperate_sm.h"
|
||||
#include "cooperate_softbus_adapter.h"
|
||||
#include "cooperate_util.h"
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include "cooperate_util.h"
|
||||
#include "devicestatus_define.h"
|
||||
#include "json_parser.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
@ -51,6 +52,7 @@ int32_t DeviceProfileAdapter::UpdateCrossingSwitchState(bool state, const std::v
|
||||
profile.SetServiceId(SERVICE_ID);
|
||||
profile.SetServiceType(SERVICE_TYPE);
|
||||
cJSON *data = cJSON_CreateObject();
|
||||
CHKPR(data, RET_ERR);
|
||||
cJSON_AddItemToObject(data, characteristicsName_.c_str(), cJSON_CreateNumber(state));
|
||||
char *smsg = cJSON_Print(data);
|
||||
cJSON_Delete(data);
|
||||
@ -85,6 +87,7 @@ int32_t DeviceProfileAdapter::UpdateCrossingSwitchState(bool state)
|
||||
profile.SetServiceId(SERVICE_ID);
|
||||
profile.SetServiceType(SERVICE_TYPE);
|
||||
cJSON *data = cJSON_CreateObject();
|
||||
CHKPR(data, RET_ERR);
|
||||
cJSON_AddItemToObject(data, characteristicsName_.c_str(), cJSON_CreateNumber(state));
|
||||
char *smsg = cJSON_Print(data);
|
||||
cJSON_Delete(data);
|
||||
@ -103,12 +106,12 @@ bool DeviceProfileAdapter::GetCrossingSwitchState(const std::string &networkId)
|
||||
JsonParser parser;
|
||||
parser.json = cJSON_Parse(jsonData.c_str());
|
||||
if (!cJSON_IsObject(parser.json)) {
|
||||
FI_HILOGE("Parser json is not object");
|
||||
FI_HILOGE("parser json is not object");
|
||||
return false;
|
||||
}
|
||||
cJSON* state = cJSON_GetObjectItemCaseSensitive(parser.json, characteristicsName_.c_str());
|
||||
if (!cJSON_IsNumber(state)) {
|
||||
FI_HILOGE("State is not number type");
|
||||
FI_HILOGE("state is not number type");
|
||||
return false;
|
||||
}
|
||||
return (static_cast<bool>(state->valueint));
|
||||
|
@ -85,7 +85,7 @@ int32_t ICooperateState::StartRemoteInput(int32_t startDeviceId)
|
||||
std::vector<std::string> inputDeviceDhids = COOR_DEV_MGR->GetCooperateDhids(startDeviceId);
|
||||
if (inputDeviceDhids.empty()) {
|
||||
COOR_SM->OnStartFinish(false, networkIds.first, startDeviceId);
|
||||
return static_cast<int32_t>(CooperateMessage::COOPERATE_FAIL);
|
||||
return static_cast<int32_t>(CoordinationMessage::COORDINATION_FAIL);
|
||||
}
|
||||
int32_t ret = D_INPUT_ADAPTER->StartRemoteInput(networkIds.first, networkIds.second, inputDeviceDhids,
|
||||
[this, remoteNetworkId = networkIds.first, startDeviceId](bool isSuccess) {
|
||||
@ -93,7 +93,7 @@ int32_t ICooperateState::StartRemoteInput(int32_t startDeviceId)
|
||||
});
|
||||
if (ret != RET_OK) {
|
||||
COOR_SM->OnStartFinish(false, networkIds.first, startDeviceId);
|
||||
return static_cast<int32_t>(CooperateMessage::COOPERATE_FAIL);
|
||||
return static_cast<int32_t>(CoordinationMessage::COORDINATION_FAIL);
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
88
intention/cooperate/state_machine/include/cooperate_free.h
Normal file
88
intention/cooperate/state_machine/include/cooperate_free.h
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef COOPERATE_FREE_H
|
||||
#define COOPERATE_FREE_H
|
||||
|
||||
#include "i_cooperate_state.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class CooperateFree : public ICooperateState
|
||||
{
|
||||
public:
|
||||
CooperateFree();
|
||||
~CooperateFree() = default;
|
||||
void OnEvent(Context &context, CooperateEvent &event) override;
|
||||
void OnEnterState(Context &context) override;
|
||||
void OnLeaveState(Context &context) override;
|
||||
|
||||
private:
|
||||
class Initial final : public ICooperateStep
|
||||
{
|
||||
public:
|
||||
Initial(CooperateFree &parent);
|
||||
~Initial() = default;
|
||||
|
||||
void OnEvent(Context &context, CooperateEvent &event) override;
|
||||
void OnProgress(Context &context, CooperateEvent &event) override;
|
||||
void OnReset(Context &context, CooperateEvent &event) override;
|
||||
|
||||
static void BuildChains(std::shared_ptr<Initial> self, CooperateFree &parent);
|
||||
|
||||
private:
|
||||
void OnStart(Context &context, CooperateEvent &event);
|
||||
|
||||
std::shared_ptr<ICooperateStep> start_ { nullptr };
|
||||
};
|
||||
|
||||
class PrepareRemoteInput final : public ICooperateStep
|
||||
{
|
||||
public:
|
||||
PrepareRemoteInput(CooperateFree &parent, std::shared_ptr<ICooperateStep> prev);
|
||||
~PrepareRemoteInput() = default;
|
||||
|
||||
void OnEvent(Context &context, CooperateEvent &event) override;
|
||||
void OnProgress(Context &context, CooperateEvent &event) override;
|
||||
void OnReset(Context &context, CooperateEvent &event) override;
|
||||
};
|
||||
|
||||
class StartRemoteInput final : public ICooperateStep
|
||||
{
|
||||
public:
|
||||
StartRemoteInput(CooperateFree &parent, std::shared_ptr<ICooperateStep> prev);
|
||||
~StartRemoteInput() = default;
|
||||
|
||||
void OnEvent(Context &context, CooperateEvent &event) override;
|
||||
void OnProgress(Context &context, CooperateEvent &event) override;
|
||||
void OnReset(Context &context, CooperateEvent &event) override;
|
||||
};
|
||||
|
||||
class OpenSession final : public ICooperateStep
|
||||
{
|
||||
public:
|
||||
OpenSession(CooperateFree &parent, std::shared_ptr<ICooperateStep> prev);
|
||||
~OpenSession() = default;
|
||||
|
||||
void OnEvent(Context &context, CooperateEvent &event) override;
|
||||
void OnProgress(Context &context, CooperateEvent &event) override;
|
||||
void OnReset(Context &context, CooperateEvent &event) override;
|
||||
};
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // COOPERATE_FREE_H
|
52
intention/cooperate/state_machine/include/state_machine.h
Normal file
52
intention/cooperate/state_machine/include/state_machine.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef STATE_MACHINE_H
|
||||
#define STATE_MACHINE_H
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
|
||||
#include "i_cooperate_state.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class StateMachine {
|
||||
public:
|
||||
enum CooperateState : size_t {
|
||||
COOPERATE_STATE_FREE = 0,
|
||||
COOPERATE_STATE_OUT,
|
||||
COOPERATE_STATE_IN,
|
||||
NUM_COOPERATE_STATES,
|
||||
};
|
||||
|
||||
StateMachine();
|
||||
~StateMachine() = default;
|
||||
|
||||
int32_t Init(Channel<CooperateEvent>::Sender sender);
|
||||
void OnEvent(const CooperateEvent &event);
|
||||
|
||||
private:
|
||||
void UpdateState(const UpdateStateEvent &event);
|
||||
|
||||
size_t current_ { 0 };
|
||||
std::array<std::shared_ptr<ICooperateState>, NUM_COOPERATE_STATES> states_;
|
||||
Context context_;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // STATE_MACHINE_H
|
114
intention/cooperate/state_machine/src/cooperate.cpp
Normal file
114
intention/cooperate/state_machine/src/cooperate.cpp
Normal file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "cooperate.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "Cooperate" };
|
||||
} // namespace
|
||||
int32_t Cooperate::Init()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
auto [sender, receiver] = Channel<Cooperate>::OpenChannel();
|
||||
sender_ = sender;
|
||||
receiver_ = receiver;
|
||||
return sm_.Init(sender);
|
||||
}
|
||||
|
||||
int32_t Cooperate::Enable()
|
||||
{
|
||||
running_.store(true);
|
||||
worker_ = std::thread(std::bind(&Cooperate::Loop, this));
|
||||
FI_HILOGD("enable cooperate");
|
||||
sender_.Send(CooperateEvent(CooperateEventType::ENABLE));
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void Cooperate::Disable()
|
||||
{
|
||||
sender_.Send(CooperateEvent(CooperateEventType::DISABLE));
|
||||
sender_.Send(CooperateEvent(CooperateEventType::QUIT));
|
||||
if (worker_.joinable()) {
|
||||
worker_.join();
|
||||
}
|
||||
}
|
||||
|
||||
int32_t Cooperate::StartCooperate(int32_t userData, const std::string &remoteNetworkId, int32_t startDeviceId)
|
||||
{
|
||||
StartCooperateEvent event {
|
||||
.userData = userData,
|
||||
.remoteNetworkId = remoteNetworkId,
|
||||
.startDeviceId = startDeviceId
|
||||
};
|
||||
sender_.Send(CooperateEvent(CooperateEventType::START, event));
|
||||
|
||||
std::thread([this, &remoteNetworkId, startDeviceId] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
sender_.Send(CooperateEvent(CooperateEventType::PREPARE_DINPUT_RESULT,
|
||||
StartRemoteInputResult {
|
||||
.source = "local",
|
||||
.sink = remoteNetworkId,
|
||||
.startDeviceId = startDeviceId,
|
||||
.success = true }));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
sender_.Send(CooperateEvent(CooperateEventType::START_DINPUT_RESULT,
|
||||
StartRemoteInputResult {
|
||||
.source = "local",
|
||||
.sink = remoteNetworkId,
|
||||
.startDeviceId = startDeviceId,
|
||||
.success = true }));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
sender_.Send(CooperateEvent(CooperateEventType::POINTER_MOVE,
|
||||
PointerMoveEvent {
|
||||
.deviceId = 13,
|
||||
}
|
||||
));
|
||||
}).detach();
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t Cooperate::StopCooperate(int32_t userData, bool isUnchained)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
void Cooperate::Loop()
|
||||
{
|
||||
while (running_.load()) {
|
||||
CooperateEvent event = receiver_.Receive();
|
||||
switch (event.type) {
|
||||
case CooperateEventType::NOOP : {
|
||||
FI_HILOGD("noop");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
break;
|
||||
}
|
||||
case CooperateEventType::QUIT : {
|
||||
FI_HILOGD("quit");
|
||||
running_.store(false);
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
sm_.OnEvent(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
185
intention/cooperate/state_machine/src/cooperate_free.cpp
Normal file
185
intention/cooperate/state_machine/src/cooperate_free.cpp
Normal file
@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "cooperate_free.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "CooperateFree" };
|
||||
} // namespace
|
||||
CooperateFree::CooperateFree()
|
||||
{
|
||||
auto initial = std::make_shared<Initial>(*this);
|
||||
Initial::BuildChains(initial, *this);
|
||||
current_ = initial;
|
||||
}
|
||||
|
||||
void CooperateFree::OnEvent(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
if (current_ != nullptr) {
|
||||
current_->OnEvent(context, event);
|
||||
} else {
|
||||
FI_HILOGE("In CooperateFree::OnEvent, current step is null");
|
||||
}
|
||||
}
|
||||
|
||||
void CooperateFree::OnEnterState(Context &context)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
}
|
||||
|
||||
void CooperateFree::OnLeaveState(Context &context)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
}
|
||||
|
||||
CooperateFree::Initial::Initial(CooperateFree &parent) : ICooperateStep(parent, nullptr)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
}
|
||||
|
||||
void CooperateFree::Initial::OnEvent(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
switch (event.type) {
|
||||
case CooperateEventType::DISABLE : {
|
||||
break;
|
||||
}
|
||||
case CooperateEventType::START : {
|
||||
OnStart(context, event);
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CooperateFree::Initial::OnProgress(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
}
|
||||
|
||||
void CooperateFree::Initial::OnReset(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
}
|
||||
|
||||
void CooperateFree::Initial::BuildChains(std::shared_ptr<Initial> self, CooperateFree &parent)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
auto s1 = std::make_shared<PrepareRemoteInput>(parent, self);
|
||||
self->start_ = s1;
|
||||
auto s2 = std::make_shared<StartRemoteInput>(parent, s1);
|
||||
s1->SetNext(s2);
|
||||
s2->SetNext(self);
|
||||
}
|
||||
|
||||
void CooperateFree::Initial::OnStart(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
StartCooperateEvent ev = std::get<StartCooperateEvent>(event.event);
|
||||
context.cooperated_ = ev.remoteNetworkId;
|
||||
if (start_ != nullptr) {
|
||||
Switch(start_);
|
||||
start_->OnProgress(context, event);
|
||||
}
|
||||
}
|
||||
|
||||
CooperateFree::PrepareRemoteInput::PrepareRemoteInput(CooperateFree &parent, std::shared_ptr<ICooperateStep> prev)
|
||||
: ICooperateStep(parent, prev)
|
||||
{}
|
||||
|
||||
void CooperateFree::PrepareRemoteInput::OnEvent(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
switch (event.type) {
|
||||
case CooperateEventType::PREPARE_DINPUT_RESULT: {
|
||||
StartRemoteInputResult result = std::get<StartRemoteInputResult>(event.event);
|
||||
if (result.success) {
|
||||
Proceed(context, event);
|
||||
} else {
|
||||
Reset(context, event);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CooperateFree::PrepareRemoteInput::OnProgress(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
}
|
||||
|
||||
void CooperateFree::PrepareRemoteInput::OnReset(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
Reset(context, event);
|
||||
}
|
||||
|
||||
CooperateFree::StartRemoteInput::StartRemoteInput(CooperateFree &parent, std::shared_ptr<ICooperateStep> prev)
|
||||
: ICooperateStep(parent, prev)
|
||||
{}
|
||||
|
||||
void CooperateFree::StartRemoteInput::OnEvent(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
switch (event.type) {
|
||||
case CooperateEventType::START_DINPUT_RESULT: {
|
||||
StartRemoteInputResult result = std::get<StartRemoteInputResult>(event.event);
|
||||
if (result.success) {
|
||||
context.sender.Send(CooperateEvent(CooperateEventType::UPDATE_STATE,
|
||||
UpdateStateEvent { .current = 1 }));
|
||||
Proceed(context, event);
|
||||
} else {
|
||||
Reset(context, event);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CooperateFree::StartRemoteInput::OnProgress(Context &context, CooperateEvent &event)
|
||||
{}
|
||||
|
||||
void CooperateFree::StartRemoteInput::OnReset(Context &context, CooperateEvent &event)
|
||||
{}
|
||||
|
||||
CooperateFree::OpenSession::OpenSession(CooperateFree &parent, std::shared_ptr<ICooperateStep> prev)
|
||||
: ICooperateStep(parent, prev)
|
||||
{}
|
||||
|
||||
void CooperateFree::OpenSession::OnEvent(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
}
|
||||
|
||||
void CooperateFree::OpenSession::OnProgress(Context &context, CooperateEvent &event)
|
||||
{}
|
||||
|
||||
void CooperateFree::OpenSession::OnReset(Context &context, CooperateEvent &event)
|
||||
{}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
102
intention/cooperate/state_machine/src/cooperate_in.cpp
Normal file
102
intention/cooperate/state_machine/src/cooperate_in.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "cooperate_in.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "CooperateIn" };
|
||||
} // namespace
|
||||
CooperateIn::CooperateIn()
|
||||
{}
|
||||
|
||||
void CooperateIn::OnEvent(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
}
|
||||
|
||||
void CooperateIn::OnEnterState(Context & context)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
}
|
||||
|
||||
void CooperateIn::OnLeaveState(Context & context)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
}
|
||||
|
||||
void CooperateIn::Initial::OnEvent(Context &context, CooperateEvent &event)
|
||||
{}
|
||||
|
||||
void CooperateIn::Initial::OnProgress(Context &context, CooperateEvent &event)
|
||||
{}
|
||||
|
||||
void CooperateIn::Initial::OnReset(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
switch (event.type) {
|
||||
case CooperateEventType::POINTER_MOVE : {
|
||||
// 当前设备上连接的鼠标发生移动,重置穿越状态。
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CooperateIn::PrepareRemoteInput::OnEvent(Context &context, CooperateEvent &event)
|
||||
{}
|
||||
|
||||
void CooperateIn::PrepareRemoteInput::OnProgress(Context &context, CooperateEvent &event)
|
||||
{}
|
||||
|
||||
void CooperateIn::PrepareRemoteInput::OnReset(Context &context, CooperateEvent &event)
|
||||
{
|
||||
if (context.isUnchain_) {
|
||||
UnprepareRemoteInput(prepared_.first, prepared_.second);
|
||||
}
|
||||
Reset(context, event);
|
||||
}
|
||||
|
||||
void CooperateIn::StartRemoteInput::OnEvent(Context &context, CooperateEvent &event)
|
||||
{
|
||||
switch (event.type) {
|
||||
case CooperateEventType::POINTER_MOVE : {
|
||||
PointerMoveEvent e = std::get<PointerMoveEvent>(event.event);
|
||||
if (context.startDeviceId_ != context.devMgr_.GetDhid(e.deviceId)) {
|
||||
// 当前设备上连接的鼠标发生移动,需要重置穿越状态。
|
||||
if (prev_ != nullptr) {
|
||||
prev_->OnReset(context, event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CooperateIn::StartRemoteInput::OnProgress(Context &context, CooperateEvent &event)
|
||||
{}
|
||||
|
||||
void CooperateIn::StartRemoteInput::OnReset(Context &context, CooperateEvent &event)
|
||||
{}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
135
intention/cooperate/state_machine/src/cooperate_out.cpp
Normal file
135
intention/cooperate/state_machine/src/cooperate_out.cpp
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "cooperate_out.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "CooperateOut" };
|
||||
} // namespace
|
||||
CooperateOut::CooperateOut()
|
||||
{
|
||||
auto initial = std::make_shared<Initial>(*this);
|
||||
Initial::BuildChains(initial, *this);
|
||||
current_ = initial;
|
||||
}
|
||||
|
||||
void CooperateOut::OnEvent(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
if (current_ != nullptr) {
|
||||
current_->OnEvent(context, event);
|
||||
} else {
|
||||
FI_HILOGE("current_ step is null");
|
||||
}
|
||||
}
|
||||
|
||||
void CooperateOut::OnEnterState(Context & context)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
}
|
||||
|
||||
void CooperateOut::OnLeaveState(Context & context)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
}
|
||||
|
||||
CooperateOut::Initial::Initial(CooperateOut &parent) : ICooperateStep(parent, nullptr)
|
||||
{}
|
||||
|
||||
void CooperateOut::Initial::OnEvent(Context &context, CooperateEvent &event)
|
||||
{
|
||||
switch (event.type) {
|
||||
case CooperateEventType::POINTER_MOVE : {
|
||||
PointerMoveEvent e = std::get<PointerMoveEvent>(event.event);
|
||||
if (context.startDeviceId_ != context.devMgr_.GetDhid(e.deviceId)) {
|
||||
// 当前谁被上连接的鼠标发生移动,需要重置穿越状态。
|
||||
FI_HILOGD("Pointer moved, reset cooperate");
|
||||
if (stop_ != nullptr) {
|
||||
Switch (stop_);
|
||||
stop_->OnProgress(context, event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CooperateOut::Initial::OnProgress(Context &context, CooperateEvent &event)
|
||||
{}
|
||||
|
||||
void CooperateOut::Initial::OnReset(Context &context, CooperateEvent &event)
|
||||
{}
|
||||
|
||||
void CooperateOut::Initial::BuildChains(std::shared_ptr<Initial> self, CooperateOut &parent)
|
||||
{
|
||||
auto s1 = std::make_shared<StopRemoteInput>(parent, self);
|
||||
self->stop_ = s1;
|
||||
auto s2 = std::make_shared<UnprepareRemoteInput>(parent, self);
|
||||
s1->SetNext(s2);
|
||||
s2->SetNext(self);
|
||||
}
|
||||
|
||||
CooperateOut::StopRemoteInput::StopRemoteInput(CooperateOut &parent, std::shared_ptr<ICooperateStep> prev)
|
||||
: ICooperateStep(parent, prev)
|
||||
{}
|
||||
|
||||
void CooperateOut::StopRemoteInput::OnEvent(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
}
|
||||
|
||||
void CooperateOut::StopRemoteInput::OnProgress(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
Proceed(context, event);
|
||||
}
|
||||
|
||||
void CooperateOut::StopRemoteInput::OnReset(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
}
|
||||
|
||||
CooperateOut::UnprepareRemoteInput::UnprepareRemoteInput(CooperateOut &parent, std::shared_ptr<ICooperateStep> prev)
|
||||
: ICooperateStep(parent, prev)
|
||||
{}
|
||||
|
||||
void CooperateOut::UnprepareRemoteInput::OnEvent(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
}
|
||||
|
||||
void CooperateOut::UnprepareRemoteInput::OnProgress(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
FI_HILOGD("Unprepare remote input remote: %{public}s", context.cooperated_.c_str());
|
||||
context.sender.Send(CooperateEvent(CooperateEventType::UPDATE_STATE, UpdateStateEvent {
|
||||
.current = 0,
|
||||
}));
|
||||
Proceed(context, event);
|
||||
}
|
||||
|
||||
void CooperateOut::UnprepareRemoteInput::OnReset(Context &context, CooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
81
intention/cooperate/state_machine/src/state_machine.cpp
Normal file
81
intention/cooperate/state_machine/src/state_machine.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "state_machine.h"
|
||||
|
||||
#include "cooperate_free.h"
|
||||
#include "cooperate_in.h"
|
||||
#include "cooperate_out.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "StateMachine" };
|
||||
} // namespace
|
||||
|
||||
StateMachine::StateMachine()
|
||||
: states_ {
|
||||
std::make_shared<CooperateFree>(),
|
||||
std::make_shared<CooperateOut>(),
|
||||
std::make_shared<CooperateIn>(),
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
int32_t StateMachine::Init(Channel<CooperateEvent>::Sender sender)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
context_.sender = sender;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void StateMachine::OnEvent(CooperateEvent &event)
|
||||
{
|
||||
switch (event.type) {
|
||||
case CooperateEventType::UPDATE_STATE : {
|
||||
UpdateState(std::get<UpdateStateEvent>(event.event));
|
||||
break;
|
||||
}
|
||||
case CooperateEventType::ENABLE : {
|
||||
break;
|
||||
}
|
||||
case CooperateEventType::DISABLE : {
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
if (states_[current_] != nullptr) {
|
||||
states_[current_]->OnEvent(context_, event);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StateMachine::UpdateState(UpdateStateEvent &event)
|
||||
{
|
||||
if ((event.current < NUM_COOPERATE_STATES) && (event.current != current_)) {
|
||||
if (states_[current_] != nullptr) {
|
||||
states_[current_]->OnLeave(context_);
|
||||
}
|
||||
current_ = event.current;
|
||||
if (states_[current_] != nullptr) {
|
||||
states_[current_]->OnEvent(context_);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
@ -13,20 +13,15 @@
|
||||
|
||||
import("../../device_status.gni")
|
||||
|
||||
config("params_public_config") {
|
||||
config("intention_data_public_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
config("cooperate_params_config") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"cooperate/include",
|
||||
"${device_status_root_path}/utils/ipc/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_source_set("cooperate_params") {
|
||||
ohos_source_set("intention_data") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
@ -34,62 +29,23 @@ ohos_source_set("cooperate_params") {
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
sources = [ "cooperate/src/cooperate_params.cpp" ]
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
configs = [ ":cooperate_params_config" ]
|
||||
sources = [ "src/default_params.cpp" ]
|
||||
|
||||
public_configs = [ ":params_public_config" ]
|
||||
public_configs = [ ":intention_data_public_config" ]
|
||||
|
||||
deps = [ "${device_status_utils_path}:devicestatus_util" ]
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_utils_path}:devicestatus_util",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"image_framework:image_native",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
||||
subsystem_name = "msdp"
|
||||
part_name = "${device_status_part_name}"
|
||||
}
|
||||
|
||||
config("drag_params_config") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"drag/include",
|
||||
"${device_status_root_path}/utils/ipc/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_source_set("drag_params") {
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
sources = [
|
||||
"drag/src/drag_data_manager.cpp",
|
||||
"drag/src/drag_params.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":drag_params_config" ]
|
||||
|
||||
public_configs = [ ":params_public_config" ]
|
||||
|
||||
deps = [ "${device_status_utils_path}:devicestatus_util" ]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"image_framework:image_native",
|
||||
"input:libmmi-client",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
||||
subsystem_name = "msdp"
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
||||
part_name = "${device_status_part_name}"
|
||||
}
|
||||
|
@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "cooperate_params.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
|
||||
DefaultCooperateParam::DefaultCooperateParam(int32_t userData)
|
||||
: userData(userData)
|
||||
{}
|
||||
|
||||
bool DefaultCooperateParam::Marshalling(Parcel &data) const
|
||||
{
|
||||
return data.WriteInt32(userData);
|
||||
}
|
||||
|
||||
bool DefaultCooperateParam::Unmarshalling(Parcel &data)
|
||||
{
|
||||
return data.ReadInt32(userData);
|
||||
}
|
||||
|
||||
bool DefaultCooperateReply::Marshalling(Parcel &data) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DefaultCooperateReply::Unmarshalling(Parcel &data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
StartCooperateParam::StartCooperateParam(int32_t userData, const std::string &remoteNetworkId, int32_t startDeviceId)
|
||||
: remoteNetworkId(remoteNetworkId),
|
||||
startDeviceId(startDeviceId),
|
||||
userData(userData)
|
||||
{}
|
||||
|
||||
bool StartCooperateParam::Marshalling(Parcel &data) const
|
||||
{
|
||||
return (
|
||||
data.WriteInt32(userData) &&
|
||||
data.WriteString(remoteNetworkId) &&
|
||||
data.WriteInt32(startDeviceId)
|
||||
);
|
||||
}
|
||||
|
||||
bool StartCooperateParam::Unmarshalling(Parcel &data)
|
||||
{
|
||||
return (
|
||||
data.ReadInt32(userData) &&
|
||||
data.ReadString(remoteNetworkId) &&
|
||||
data.ReadInt32(startDeviceId)
|
||||
);
|
||||
}
|
||||
|
||||
GetCooperateStateParam::GetCooperateStateParam(std::string networkId, int32_t userData)
|
||||
: networkId(networkId),
|
||||
userData(userData)
|
||||
{}
|
||||
|
||||
bool GetCooperateStateParam::Marshalling(Parcel &data) const
|
||||
{
|
||||
return (
|
||||
data.WriteInt32(userData) &&
|
||||
data.WriteString(networkId)
|
||||
);
|
||||
}
|
||||
|
||||
bool GetCooperateStateParam::Unmarshalling(Parcel &data)
|
||||
{
|
||||
return (
|
||||
data.ReadInt32(userData) &&
|
||||
data.ReadString(networkId)
|
||||
);
|
||||
}
|
||||
|
||||
StopCooperateParam::StopCooperateParam(int32_t userData, bool isUnchained)
|
||||
: userData(userData), isUnchained(isUnchained)
|
||||
{}
|
||||
|
||||
bool StopCooperateParam::Marshalling(Parcel &data) const
|
||||
{
|
||||
return (
|
||||
data.WriteInt32(userData) &&
|
||||
data.WriteBool(isUnchained)
|
||||
);
|
||||
}
|
||||
|
||||
bool StopCooperateParam::Unmarshalling(Parcel &data)
|
||||
{
|
||||
return (
|
||||
data.ReadInt32(userData) &&
|
||||
data.ReadBool(isUnchained)
|
||||
);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
40
intention/data/include/default_params.h
Normal file
40
intention/data/include/default_params.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INTENTION_DEFAULT_PARAMS_H
|
||||
#define INTENTION_DEFAULT_PARAMS_H
|
||||
|
||||
#include "intention_identity.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
struct DefaultParam final : public ParamBase {
|
||||
DefaultParam() = default;
|
||||
DefaultParam(int32_t userData);
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
int32_t userData { -1 };
|
||||
};
|
||||
|
||||
struct DefaultReply final : public ParamBase {
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // INTENTION_DEFAULT_PARAMS_H
|
46
intention/data/src/default_params.cpp
Normal file
46
intention/data/src/default_params.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "default_params.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
DefaultParam::DefaultParam(int32_t userData)
|
||||
: userData(userData)
|
||||
{}
|
||||
|
||||
bool DefaultParam::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return parcel.WriteInt32(userData);
|
||||
}
|
||||
|
||||
bool DefaultParam::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return parcel.ReadInt32(userData);
|
||||
}
|
||||
|
||||
bool DefaultReply::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DefaultReply::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
@ -11,22 +11,20 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("../../device_status.gni")
|
||||
import("../../../device_status.gni")
|
||||
|
||||
config("ipc_public_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
config("ipc_config") {
|
||||
config("intention_cooperate_data_public_config") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${intention_root_path}/data/include",
|
||||
"${device_status_root_path}/utils/ipc/include",
|
||||
"${device_status_root_path}/interfaces/innerkits/interaction/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_source_set("intention_ipc") {
|
||||
ohos_source_set("intention_drag_data") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
@ -34,25 +32,22 @@ ohos_source_set("intention_ipc") {
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
sources = [
|
||||
"src/intention_proxy.cpp",
|
||||
"src/intention_stub.cpp",
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${device_status_root_path}/interfaces/innerkits/interaction/include",
|
||||
]
|
||||
|
||||
configs = [ ":ipc_config" ]
|
||||
sources = [ "src/drag_params.cpp" ]
|
||||
|
||||
public_configs = [ ":ipc_public_config" ]
|
||||
public_configs = [ ":intention_cooperate_data_public_config" ]
|
||||
|
||||
deps = [ "${device_status_utils_path}:devicestatus_util" ]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"image_framework:image_native",
|
||||
"ipc:ipc_core",
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_root_path}/utils/common:devicestatus_util",
|
||||
]
|
||||
|
||||
subsystem_name = "msdp"
|
||||
external_deps = [ "image_framework:image_native" ]
|
||||
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
||||
part_name = "${device_status_part_name}"
|
||||
}
|
212
intention/drag/data/include/drag_params.h
Normal file
212
intention/drag/data/include/drag_params.h
Normal file
@ -0,0 +1,212 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef DRAG_PARAMS_H
|
||||
#define DRAG_PARAMS_H
|
||||
#include <memory>
|
||||
|
||||
#include "drag_data.h"
|
||||
#include "intention_identity.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
enum DragRequestID : uint32_t {
|
||||
UNKNOWN_DRAG_ACTION,
|
||||
ADD_DRAG_LISTENER,
|
||||
REMOVE_DRAG_LISTENER,
|
||||
ADD_SUBSCRIPT_LISTENER,
|
||||
REMOVE_SUBSCRIPT_LISTENER,
|
||||
SET_DRAG_WINDOW_VISIBLE,
|
||||
UPDATE_DRAG_STYLE,
|
||||
UPDATE_SHADOW_PIC,
|
||||
GET_DRAG_TARGET_PID,
|
||||
GET_UDKEY,
|
||||
GET_SHADOW_OFFSET,
|
||||
GET_DRAG_DATA,
|
||||
UPDATE_PREVIEW_STYLE,
|
||||
UPDATE_PREVIEW_STYLE_WITH_ANIMATION,
|
||||
GET_DRAG_SUMMARY,
|
||||
GET_DRAG_STATE,
|
||||
ENTER_TEXT_EDITOR_AREA,
|
||||
GET_DRAG_ACTION,
|
||||
GET_EXTRA_INFO,
|
||||
};
|
||||
|
||||
struct StartDragParam final : public ParamBase {
|
||||
StartDragParam(DragData &dragData);
|
||||
StartDragParam(const DragData &dragData);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
// For efficiency, we want to avoid copying 'DragData' whenever possible.
|
||||
// Considering the 'Start drag' scenario, we use 'StartDragParam' simply
|
||||
// as wrapper of 'DragData' and serialize 'DragData' in the right same
|
||||
// call. We do not dereference 'DragData' or keep a reference to it for
|
||||
// later use. In this case, we can safely keep a pointer to the input 'DragData'.
|
||||
DragData *dragDataPtr_ { nullptr };
|
||||
const DragData *cDragDataPtr_ { nullptr };
|
||||
};
|
||||
|
||||
struct StopDragParam final : public ParamBase {
|
||||
StopDragParam() = default;
|
||||
StopDragParam(const DragDropResult &dropResult);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
DragDropResult dropResult_ {};
|
||||
};
|
||||
|
||||
struct SetDragWindowVisibleParam final : public ParamBase {
|
||||
SetDragWindowVisibleParam() = default;
|
||||
SetDragWindowVisibleParam(bool visible);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
bool visible_ { false };
|
||||
};
|
||||
|
||||
struct UpdateDragStyleParam final : public ParamBase {
|
||||
UpdateDragStyleParam() = default;
|
||||
UpdateDragStyleParam(DragCursorStyle style);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
DragCursorStyle cursorStyle_ { DragCursorStyle::DEFAULT };
|
||||
};
|
||||
|
||||
struct UpdateShadowPicParam final : public ParamBase {
|
||||
UpdateShadowPicParam() = default;
|
||||
UpdateShadowPicParam(const ShadowInfo &shadowInfo);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
ShadowInfo shadowInfo_ {};
|
||||
};
|
||||
|
||||
struct GetDragTargetPidReply : public ParamBase {
|
||||
GetDragTargetPidReply() = default;
|
||||
GetDragTargetPidReply(int32_t pid);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
int32_t targetPid_ { -1 };
|
||||
};
|
||||
|
||||
struct GetUdKeyReply final : public ParamBase {
|
||||
GetUdKeyReply() = default;
|
||||
GetUdKeyReply(std::string &&udKey);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
std::string udKey_;
|
||||
};
|
||||
|
||||
struct GetShadowOffsetReply final : public ParamBase {
|
||||
GetShadowOffsetReply() = default;
|
||||
GetShadowOffsetReply(int32_t offsetX, int32_t offsetY, int32_t width, int32_t height);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
int32_t offsetX_ { -1 };
|
||||
int32_t offsetY_ { -1 };
|
||||
int32_t width_ { -1 };
|
||||
int32_t height_ { -1 };
|
||||
};
|
||||
|
||||
using GetDragDataReply = StartDragParam;
|
||||
|
||||
struct UpdatePreviewStyleParam final : public ParamBase {
|
||||
UpdatePreviewStyleParam() = default;
|
||||
UpdatePreviewStyleParam(const PreviewStyle &previewStyle);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
PreviewStyle previewStyle_;
|
||||
};
|
||||
|
||||
struct UpdatePreviewAnimationParam final : public ParamBase {
|
||||
UpdatePreviewAnimationParam() = default;
|
||||
UpdatePreviewAnimationParam(const PreviewStyle &previewStyle, const PreviewAnimation &animation);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
PreviewStyle previewStyle_ {};
|
||||
PreviewAnimation previewAnimation_ {};
|
||||
};
|
||||
|
||||
struct GetDragSummaryReply final : public ParamBase {
|
||||
GetDragSummaryReply() = default;
|
||||
GetDragSummaryReply(std::map<std::string, int64_t> &&summaries);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
std::map<std::string, int64_t> summaries_;
|
||||
};
|
||||
|
||||
struct GetDragStateReply final : public ParamBase {
|
||||
GetDragStateReply() = default;
|
||||
GetDragStateReply(DragState dragState);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
DragState dragState_ { DragState::ERROR };
|
||||
};
|
||||
|
||||
struct EnterTextEditorAreaParam final : public ParamBase {
|
||||
EnterTextEditorAreaParam() = default;
|
||||
EnterTextEditorAreaParam(bool enable);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
bool enable_ { false };
|
||||
};
|
||||
|
||||
struct GetDragActionReply final : public ParamBase {
|
||||
GetDragActionReply() = default;
|
||||
GetDragActionReply(DragAction dragAction);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
DragAction dragAction_ { DragAction::INVALID };
|
||||
};
|
||||
|
||||
struct GetExtraInfoReply final : public ParamBase {
|
||||
GetExtraInfoReply() = default;
|
||||
GetExtraInfoReply(std::string &&extraInfo);
|
||||
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
std::string extraInfo_;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // DRAG_PARAMS_H
|
311
intention/drag/data/src/drag_params.cpp
Normal file
311
intention/drag/data/src/drag_params.cpp
Normal file
@ -0,0 +1,311 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "drag_params.h"
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
#include "drag_data_packer.h"
|
||||
#include "preview_style_packer.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
|
||||
StartDragParam::StartDragParam(DragData &dragData)
|
||||
{
|
||||
dragDataPtr_ = &dragData;
|
||||
}
|
||||
|
||||
StartDragParam::StartDragParam(const DragData &dragData)
|
||||
{
|
||||
cDragDataPtr_ = &dragData;
|
||||
}
|
||||
|
||||
bool StartDragParam::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return (
|
||||
(cDragDataPtr_ != nullptr) &&
|
||||
(DragDataPacker::Marshalling(*cDragDataPtr_, parcel) == RET_OK)
|
||||
);
|
||||
}
|
||||
|
||||
bool StartDragParam::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return (
|
||||
(dragDataPtr_ != nullptr) &&
|
||||
(DragDataPacker::UnMarshalling(parcel, *dragDataPtr_) == RET_OK)
|
||||
);
|
||||
}
|
||||
|
||||
StopDragParam::StopDragParam(const DragDropResult &dropResult)
|
||||
: dropResult_(dropResult)
|
||||
{}
|
||||
|
||||
bool StopDragParam::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return (
|
||||
parcel.WriteInt32(static_cast<int32_t>(dropResult_.result)) &&
|
||||
parcel.WriteInt32(dropResult_.windowId) &&
|
||||
parcel.WriteBool(dropResult_.hasCustomAnimation)
|
||||
);
|
||||
}
|
||||
|
||||
bool StopDragParam::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
int32_t result { -1 };
|
||||
if (!parcel.ReadInt32(result) ||
|
||||
(result < static_cast<int32_t>(DragResult::DRAG_SUCCESS)) ||
|
||||
(result > static_cast<int32_t>(DragResult::DRAG_EXCEPTION))) {
|
||||
return false;
|
||||
}
|
||||
dropResult_.result = static_cast<DragResult>(result);
|
||||
return (
|
||||
parcel.ReadInt32(dropResult_.windowId) &&
|
||||
parcel.ReadBool(dropResult_.hasCustomAnimation)
|
||||
);
|
||||
}
|
||||
|
||||
SetDragWindowVisibleParam::SetDragWindowVisibleParam(bool visible)
|
||||
: visible_(visible)
|
||||
{}
|
||||
|
||||
bool SetDragWindowVisibleParam::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return parcel.WriteBool(visible_);
|
||||
}
|
||||
|
||||
bool SetDragWindowVisibleParam::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return parcel.ReadBool(visible_);
|
||||
}
|
||||
|
||||
UpdateDragStyleParam::UpdateDragStyleParam(DragCursorStyle style)
|
||||
: cursorStyle_(style)
|
||||
{}
|
||||
|
||||
bool UpdateDragStyleParam::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return parcel.WriteInt32(static_cast<int32_t>(cursorStyle_));
|
||||
}
|
||||
|
||||
bool UpdateDragStyleParam::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
int32_t style { -1 };
|
||||
if (!parcel.ReadInt32(style) ||
|
||||
(style < static_cast<int32_t>(DragCursorStyle::DEFAULT)) ||
|
||||
(style > static_cast<int32_t>(DragCursorStyle::MOVE))) {
|
||||
return false;
|
||||
}
|
||||
cursorStyle_ = static_cast<DragCursorStyle>(style);
|
||||
return true;
|
||||
}
|
||||
|
||||
UpdateShadowPicParam::UpdateShadowPicParam(const ShadowInfo &shadowInfo)
|
||||
: shadowInfo_(shadowInfo)
|
||||
{}
|
||||
|
||||
bool UpdateShadowPicParam::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return (
|
||||
(shadowInfo_.pixelMap != nullptr) &&
|
||||
shadowInfo_.pixelMap->Marshalling(parcel) &&
|
||||
parcel.WriteInt32(shadowInfo_.x) &&
|
||||
parcel.WriteInt32(shadowInfo_.y)
|
||||
);
|
||||
}
|
||||
|
||||
bool UpdateShadowPicParam::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
shadowInfo_.pixelMap = std::shared_ptr<Media::PixelMap>(Media::PixelMap::Unmarshalling(parcel));
|
||||
return (
|
||||
(shadowInfo_.pixelMap != nullptr) &&
|
||||
parcel.ReadInt32(shadowInfo_.x) &&
|
||||
parcel.ReadInt32(shadowInfo_.y)
|
||||
);
|
||||
}
|
||||
|
||||
GetDragTargetPidReply::GetDragTargetPidReply(int32_t pid)
|
||||
: targetPid_(pid)
|
||||
{}
|
||||
|
||||
bool GetDragTargetPidReply::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return parcel.WriteInt32(targetPid_);
|
||||
}
|
||||
|
||||
bool GetDragTargetPidReply::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return parcel.ReadInt32(targetPid_);
|
||||
}
|
||||
|
||||
GetUdKeyReply::GetUdKeyReply(std::string &&udKey)
|
||||
: udKey_(std::move(udKey))
|
||||
{}
|
||||
|
||||
bool GetUdKeyReply::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return parcel.WriteString(udKey_);
|
||||
}
|
||||
|
||||
bool GetUdKeyReply::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return parcel.ReadString(udKey_);
|
||||
}
|
||||
|
||||
GetShadowOffsetReply::GetShadowOffsetReply(int32_t offsetX, int32_t offsetY, int32_t width, int32_t height)
|
||||
: offsetX_(offsetX), offsetY_(offsetY), width_(width), height_(height)
|
||||
{}
|
||||
|
||||
bool GetShadowOffsetReply::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return (
|
||||
parcel.WriteInt32(offsetX_) &&
|
||||
parcel.WriteInt32(offsetY_) &&
|
||||
parcel.WriteInt32(width_) &&
|
||||
parcel.WriteInt32(height_)
|
||||
);
|
||||
}
|
||||
|
||||
bool GetShadowOffsetReply::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return (
|
||||
parcel.ReadInt32(offsetX_) &&
|
||||
parcel.ReadInt32(offsetY_) &&
|
||||
parcel.ReadInt32(width_) &&
|
||||
parcel.ReadInt32(height_)
|
||||
);
|
||||
}
|
||||
|
||||
UpdatePreviewStyleParam::UpdatePreviewStyleParam(const PreviewStyle &previewStyle)
|
||||
: previewStyle_(previewStyle)
|
||||
{}
|
||||
|
||||
bool UpdatePreviewStyleParam::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return (PreviewStylePacker::Marshalling(previewStyle_, parcel) == RET_OK);
|
||||
}
|
||||
|
||||
bool UpdatePreviewStyleParam::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return (PreviewStylePacker::UnMarshalling(parcel, previewStyle_) == RET_OK);
|
||||
}
|
||||
|
||||
UpdatePreviewAnimationParam::UpdatePreviewAnimationParam(
|
||||
const PreviewStyle &previewStyle, const PreviewAnimation &animation)
|
||||
: previewStyle_(previewStyle), previewAnimation_(animation)
|
||||
{}
|
||||
|
||||
bool UpdatePreviewAnimationParam::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return (
|
||||
(PreviewStylePacker::Marshalling(previewStyle_, parcel) == RET_OK) &&
|
||||
(PreviewAnimationPacker::Marshalling(previewAnimation_, parcel) == RET_OK)
|
||||
);
|
||||
}
|
||||
|
||||
bool UpdatePreviewAnimationParam::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return (
|
||||
(PreviewStylePacker::UnMarshalling(parcel, previewStyle_) == RET_OK) &&
|
||||
(PreviewAnimationPacker::UnMarshalling(parcel, previewAnimation_) == RET_OK)
|
||||
);
|
||||
}
|
||||
|
||||
GetDragSummaryReply::GetDragSummaryReply(std::map<std::string, int64_t> &&summaries)
|
||||
: summaries_(std::move(summaries))
|
||||
{}
|
||||
|
||||
bool GetDragSummaryReply::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return (SummaryPacker::Marshalling(summaries_, parcel) == RET_OK);
|
||||
}
|
||||
|
||||
bool GetDragSummaryReply::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return (SummaryPacker::UnMarshalling(parcel, summaries_) == RET_OK);
|
||||
}
|
||||
|
||||
GetDragStateReply::GetDragStateReply(DragState dragState)
|
||||
: dragState_(dragState)
|
||||
{}
|
||||
|
||||
bool GetDragStateReply::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return parcel.WriteInt32(static_cast<int32_t>(dragState_));
|
||||
}
|
||||
|
||||
bool GetDragStateReply::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
int32_t dragState { -1 };
|
||||
if (!parcel.ReadInt32(dragState) ||
|
||||
(dragState < static_cast<int32_t>(DragState::ERROR)) ||
|
||||
(dragState > static_cast<int32_t>(DragState::MOTION_DRAGGING))) {
|
||||
return false;
|
||||
}
|
||||
dragState_ = static_cast<DragState>(dragState);
|
||||
return true;
|
||||
}
|
||||
|
||||
EnterTextEditorAreaParam::EnterTextEditorAreaParam(bool enable)
|
||||
: enable_(enable)
|
||||
{}
|
||||
|
||||
bool EnterTextEditorAreaParam::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return parcel.WriteBool(enable_);
|
||||
}
|
||||
|
||||
bool EnterTextEditorAreaParam::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return parcel.ReadBool(enable_);
|
||||
}
|
||||
|
||||
GetDragActionReply::GetDragActionReply(DragAction dragAction)
|
||||
: dragAction_(dragAction)
|
||||
{}
|
||||
|
||||
bool GetDragActionReply::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return parcel.WriteInt32(static_cast<int32_t>(dragAction_));
|
||||
}
|
||||
|
||||
bool GetDragActionReply::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
int32_t dragAction { -1 };
|
||||
if (!parcel.ReadInt32(dragAction) ||
|
||||
(dragAction < static_cast<int32_t>(DragAction::INVALID)) ||
|
||||
(dragAction > static_cast<int32_t>(DragAction::COPY))) {
|
||||
return false;
|
||||
}
|
||||
dragAction_ = static_cast<DragAction>(dragAction);
|
||||
return true;
|
||||
}
|
||||
|
||||
GetExtraInfoReply::GetExtraInfoReply(std::string &&extraInfo)
|
||||
: extraInfo_(std::move(extraInfo))
|
||||
{}
|
||||
|
||||
bool GetExtraInfoReply::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return parcel.WriteString(extraInfo_);
|
||||
}
|
||||
|
||||
bool GetExtraInfoReply::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return parcel.ReadString(extraInfo_);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
98
intention/drag/server/BUILD.gn
Executable file
98
intention/drag/server/BUILD.gn
Executable file
@ -0,0 +1,98 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("../../../device_status.gni")
|
||||
|
||||
config("intention_drag_public_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("intention_drag") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
sources = []
|
||||
|
||||
public_configs = [ ":intention_drag_public_config" ]
|
||||
|
||||
defines = device_status_default_defines
|
||||
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_root_path}/utils/common:devicestatus_util",
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"input:libmmi-client",
|
||||
"ipc:ipc_single",
|
||||
]
|
||||
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
||||
part_name = "${device_status_part_name}"
|
||||
}
|
||||
|
||||
config("intention_drag_server_public_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_source_set("intention_drag_server") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
sources = [ "src/drag_server.cpp" ]
|
||||
|
||||
public_configs = [ ":intention_drag_server_public_config" ]
|
||||
|
||||
defines = device_status_default_defines
|
||||
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/data:intention_data",
|
||||
"${device_status_root_path}/intention/drag/data:intention_drag_data",
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_root_path}/utils/common:devicestatus_util",
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"image_framework:image_native",
|
||||
"input:libmmi-client",
|
||||
]
|
||||
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
||||
part_name = "${device_status_part_name}"
|
||||
}
|
49
intention/drag/server/include/drag_server.h
Normal file
49
intention/drag/server/include/drag_server.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef DRAG_SERVER_H
|
||||
#define DRAG_SERVER_H
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
#include "i_context.h"
|
||||
#include "i_plugin.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class DragServer final : public IPlugin {
|
||||
public:
|
||||
DragServer(IContext *context);
|
||||
~DragServer() = default;
|
||||
DISALLOW_COPY_AND_MOVE(DragServer);
|
||||
|
||||
int32_t Enable(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Disable(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Start(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Stop(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t AddWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t RemoveWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t SetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t GetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Control(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
|
||||
private:
|
||||
IContext *context_ { nullptr };
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // DRAG_SERVER_H
|
161
intention/drag/server/src/drag_server.cpp
Normal file
161
intention/drag/server/src/drag_server.cpp
Normal file
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "drag_server.h"
|
||||
|
||||
#include "drag_params.h"
|
||||
#include "devicestatus_define.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "DragServer" };
|
||||
} // namespace
|
||||
|
||||
DragServer::DragServer(IContext *context)
|
||||
: context_(context)
|
||||
{}
|
||||
|
||||
int32_t DragServer::Enable(CallingContext &context, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t DragServer::Disable(CallingContext &context, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t DragServer::Start(CallingContext &context, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DragData dragData {};
|
||||
StartDragParam param { dragData };
|
||||
|
||||
if (!param.Unmarshalling(data)) {
|
||||
FI_HILOGE("Failed to unmarshalling param");
|
||||
return RET_ERR;
|
||||
}
|
||||
CHKPR(context_, RET_ERR);
|
||||
FI_HILOGD("Start drag");
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t DragServer::Stop(CallingContext &context, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
StopDragParam param {};
|
||||
|
||||
if (!param.Unmarshalling(data)) {
|
||||
FI_HILOGE("Failed to unmarshalling param");
|
||||
return RET_ERR;
|
||||
}
|
||||
CHKPR(context_, RET_ERR);
|
||||
FI_HILOGD("Stop drag");
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t DragServer::AddWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
switch (id) {
|
||||
case DragRequestID::ADD_DRAG_LISTENER: {
|
||||
FI_HILOGD("Add drag listener");
|
||||
return RET_OK;
|
||||
}
|
||||
case DragRequestID::ADD_SUBSCRIPT_LISTENER: {
|
||||
FI_HILOGD("Add subscript listener");
|
||||
return RET_OK;
|
||||
}
|
||||
default: {
|
||||
FI_HILOGE("Unexpected request ID (%{public}u)", id);
|
||||
return RET_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DragServer::RemoveWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
switch (id) {
|
||||
case DragRequestID::ADD_DRAG_LISTENER: {
|
||||
FI_HILOGD("Remove drag listener");
|
||||
return RET_OK;
|
||||
}
|
||||
case DragRequestID::ADD_SUBSCRIPT_LISTENER: {
|
||||
FI_HILOGD("Remove subscript listener");
|
||||
return RET_OK;
|
||||
}
|
||||
default: {
|
||||
FI_HILOGE("Unexpected request ID (%{public}u)", id);
|
||||
return RET_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DragServer::SetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
switch (id) {
|
||||
case DragRequestID::UPDATE_SHADOW_PIC: {
|
||||
UpdateShadowPicParam param {};
|
||||
|
||||
if (!param.Unmarshalling(data)) {
|
||||
FI_HILOGE("UpdateShadowPicParam::Unmarshalling fail");
|
||||
return RET_ERR;
|
||||
}
|
||||
FI_HILOGD("Updata shadow pic");
|
||||
return RET_OK;
|
||||
}
|
||||
default: {
|
||||
FI_HILOGE("Unexpected request ID (%{public}u)", id);
|
||||
return RET_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DragServer::GetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
switch (id) {
|
||||
case DragRequestID::GET_DRAG_DATA: {
|
||||
DragData dragData {};
|
||||
FI_HILOGD("Get drag data");
|
||||
GetDragDataReply dragDataReply { dragData };
|
||||
|
||||
if (!dragDataReply.Marshalling(reply)) {
|
||||
FI_HILOGE("GetDragDataReply::Marshalling fail");
|
||||
return RET_ERR;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
default: {
|
||||
FI_HILOGE("Unexpected request ID (%{public}u)", id);
|
||||
return RET_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t DragServer::Control(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
@ -28,6 +28,9 @@ config("intention_public_config") {
|
||||
|
||||
ohos_shared_library("intention_client") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
@ -44,9 +47,6 @@ ohos_shared_library("intention_client") {
|
||||
deps = [
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
"${device_status_utils_path}:devicestatus_util",
|
||||
"${intention_root_path}/data:cooperate_params",
|
||||
"${intention_root_path}/data:drag_params",
|
||||
"${intention_root_path}/ipc:intention_ipc",
|
||||
]
|
||||
|
||||
public_configs = [ ":intention_public_config" ]
|
||||
|
@ -1,299 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <if_system_ability_manager.h>
|
||||
#include <iservice_registry.h>
|
||||
#include <system_ability_definition.h>
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_object.h"
|
||||
|
||||
#include "cooperate_manager_impl.h"
|
||||
#include "devicestatus_define.h"
|
||||
#include "drag_manager_impl.h"
|
||||
#include "include/util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr ::OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "IntentionClient" };
|
||||
} // namespace
|
||||
|
||||
IntentionClient::IntentionClient() {}
|
||||
|
||||
IntentionClient::~IntentionClient()
|
||||
{
|
||||
if (devicestatusProxy_ != nullptr) {
|
||||
auto remoteObject = devicestatusProxy_->AsObject();
|
||||
if (remoteObject != nullptr) {
|
||||
remoteObject->RemoveDeathRecipient(deathRecipient_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t IntentionClient::Enable(uint32_t intention, ParamBase &data, ParamBase &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
MessageParcel dataParcel;
|
||||
if (!dataParcel.WriteInterfaceToken(IntentionProxy::GetDescriptor())) {
|
||||
FI_HILOGE("Enable, write descriptor failed");
|
||||
return RET_ERR;
|
||||
}
|
||||
data.Marshalling(dataParcel);
|
||||
|
||||
if (Connect() != RET_OK) {
|
||||
FI_HILOGE("Enable, failed to connect IntentionService");
|
||||
return RET_ERR;
|
||||
}
|
||||
MessageParcel replyParcel;
|
||||
int32_t ret = devicestatusProxy_->Enable(intention, dataParcel, replyParcel);
|
||||
if (ret == RET_OK) {
|
||||
reply.Unmarshalling(replyParcel);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t IntentionClient::Disable(uint32_t intention, ParamBase &data, ParamBase &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
MessageParcel dataParcel;
|
||||
if (!dataParcel.WriteInterfaceToken(IntentionProxy::GetDescriptor())) {
|
||||
FI_HILOGE("Disable, write descriptor failed");
|
||||
return RET_ERR;
|
||||
}
|
||||
data.Marshalling(dataParcel);
|
||||
|
||||
if (Connect() != RET_OK) {
|
||||
FI_HILOGE("Disable, failed to connect IntentionService");
|
||||
return RET_ERR;
|
||||
}
|
||||
MessageParcel replyParcel;
|
||||
int32_t ret = devicestatusProxy_->Disable(intention, dataParcel, replyParcel);
|
||||
if (ret == RET_OK) {
|
||||
reply.Unmarshalling(replyParcel);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t IntentionClient::Start(uint32_t intention, ParamBase &data, ParamBase &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
MessageParcel dataParcel;
|
||||
if (!dataParcel.WriteInterfaceToken(IntentionProxy::GetDescriptor())) {
|
||||
FI_HILOGE("Start, write descriptor failed");
|
||||
return RET_ERR;
|
||||
}
|
||||
data.Marshalling(dataParcel);
|
||||
|
||||
if (Connect() != RET_OK) {
|
||||
FI_HILOGE("Start, failed to connect IntentionService");
|
||||
return RET_ERR;
|
||||
}
|
||||
MessageParcel replyParcel;
|
||||
int32_t ret = devicestatusProxy_->Start(intention, dataParcel, replyParcel);
|
||||
if (ret == RET_OK) {
|
||||
reply.Unmarshalling(replyParcel);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t IntentionClient::Stop(uint32_t intention, ParamBase &data, ParamBase &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
MessageParcel dataParcel;
|
||||
if (!dataParcel.WriteInterfaceToken(IntentionProxy::GetDescriptor())) {
|
||||
FI_HILOGE("Stop, write descriptor failed");
|
||||
return RET_ERR;
|
||||
}
|
||||
data.Marshalling(dataParcel);
|
||||
|
||||
if (Connect() != RET_OK) {
|
||||
FI_HILOGE("Stop, failed to connect IntentionService");
|
||||
return RET_ERR;
|
||||
}
|
||||
MessageParcel replyParcel;
|
||||
int32_t ret = devicestatusProxy_->Stop(intention, dataParcel, replyParcel);
|
||||
if (ret == RET_OK) {
|
||||
reply.Unmarshalling(replyParcel);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t IntentionClient::AddWatch(uint32_t intention, uint32_t id, ParamBase &data, ParamBase &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
MessageParcel dataParcel;
|
||||
if (!dataParcel.WriteInterfaceToken(IntentionProxy::GetDescriptor())) {
|
||||
FI_HILOGE("Add watch, write descriptor failed");
|
||||
return RET_ERR;
|
||||
}
|
||||
data.Marshalling(dataParcel);
|
||||
|
||||
if (Connect() != RET_OK) {
|
||||
FI_HILOGE("Add watch, failed to connect IntentionService");
|
||||
return RET_ERR;
|
||||
}
|
||||
MessageParcel replyParcel;
|
||||
int32_t ret = devicestatusProxy_->AddWatch(intention, id, dataParcel, replyParcel);
|
||||
if (ret == RET_OK) {
|
||||
reply.Unmarshalling(replyParcel);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t IntentionClient::RemoveWatch(uint32_t intention, uint32_t id, ParamBase &data, ParamBase &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
MessageParcel dataParcel;
|
||||
if (!dataParcel.WriteInterfaceToken(IntentionProxy::GetDescriptor())) {
|
||||
FI_HILOGE("Remove watch, write descriptor failed");
|
||||
return RET_ERR;
|
||||
}
|
||||
data.Marshalling(dataParcel);
|
||||
|
||||
if (Connect() != RET_OK) {
|
||||
FI_HILOGE("Remove watch, failed to connect IntentionService");
|
||||
return RET_ERR;
|
||||
}
|
||||
MessageParcel replyParcel;
|
||||
int32_t ret = devicestatusProxy_->RemoveWatch(intention, id, dataParcel, replyParcel);
|
||||
if (ret == RET_OK) {
|
||||
reply.Unmarshalling(replyParcel);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t IntentionClient::SetParam(uint32_t intention, uint32_t id, ParamBase &data, ParamBase &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
MessageParcel dataParcel;
|
||||
if (!dataParcel.WriteInterfaceToken(IntentionProxy::GetDescriptor())) {
|
||||
FI_HILOGE("Set param, write descriptor failed");
|
||||
return RET_ERR;
|
||||
}
|
||||
data.Marshalling(dataParcel);
|
||||
|
||||
if (Connect() != RET_OK) {
|
||||
FI_HILOGE("Set param, failed to connect IntentionService");
|
||||
return RET_ERR;
|
||||
}
|
||||
MessageParcel replyParcel;
|
||||
int32_t ret = devicestatusProxy_->SetParam(intention, id, dataParcel, replyParcel);
|
||||
if (ret == RET_OK) {
|
||||
reply.Unmarshalling(replyParcel);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t IntentionClient::GetParam(uint32_t intention, uint32_t id, ParamBase &data, ParamBase &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
MessageParcel dataParcel;
|
||||
if (!dataParcel.WriteInterfaceToken(IntentionProxy::GetDescriptor())) {
|
||||
FI_HILOGE("Get param, write descriptor failed");
|
||||
return RET_ERR;
|
||||
}
|
||||
data.Marshalling(dataParcel);
|
||||
|
||||
if (Connect() != RET_OK) {
|
||||
FI_HILOGE("Get param, failed to connect IntentionService");
|
||||
return RET_ERR;
|
||||
}
|
||||
MessageParcel replyParcel;
|
||||
int32_t ret = devicestatusProxy_->GetParam(intention, id, dataParcel, replyParcel);
|
||||
if (ret == RET_OK) {
|
||||
reply.Unmarshalling(replyParcel);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t IntentionClient::Control(uint32_t intention, uint32_t id, ParamBase &data, ParamBase &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
MessageParcel dataParcel;
|
||||
if (!dataParcel.WriteInterfaceToken(IntentionProxy::GetDescriptor())) {
|
||||
FI_HILOGE("Control, write descriptor failed");
|
||||
return RET_ERR;
|
||||
}
|
||||
data.Marshalling(dataParcel);
|
||||
|
||||
if (Connect() != RET_OK) {
|
||||
FI_HILOGE("Control, failed to connect IntentionService");
|
||||
return RET_ERR;
|
||||
}
|
||||
MessageParcel replyParcel;
|
||||
int32_t ret = devicestatusProxy_->Control(intention, id, dataParcel, replyParcel);
|
||||
if (ret == RET_OK) {
|
||||
reply.Unmarshalling(replyParcel);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ErrCode IntentionClient::Connect()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (devicestatusProxy_ != nullptr) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
sptr<ISystemAbilityManager> sa = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
CHKPR(sa, E_DEVICESTATUS_GET_SYSTEM_ABILITY_MANAGER_FAILED);
|
||||
|
||||
sptr<IRemoteObject> remoteObject = sa->CheckSystemAbility(MSDP_DEVICESTATUS_SERVICE_ID);
|
||||
CHKPR(remoteObject, E_DEVICESTATUS_GET_SERVICE_FAILED);
|
||||
|
||||
deathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new (std::nothrow) IntentionDeathRecipient());
|
||||
CHKPR(deathRecipient_, ERR_NO_MEMORY);
|
||||
|
||||
if (remoteObject->IsProxyObject()) {
|
||||
if (!remoteObject->AddDeathRecipient(deathRecipient_)) {
|
||||
FI_HILOGE("Add death recipient to DeviceStatus service failed");
|
||||
return E_DEVICESTATUS_ADD_DEATH_RECIPIENT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
devicestatusProxy_ = iface_cast<IIntention>(remoteObject);
|
||||
FI_HILOGD("Connecting IntentionService success");
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void IntentionClient::ResetProxy(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
CHKPV(devicestatusProxy_);
|
||||
auto serviceRemote = devicestatusProxy_->AsObject();
|
||||
if ((serviceRemote != nullptr) && (serviceRemote == remote.promote())) {
|
||||
serviceRemote->RemoveDeathRecipient(deathRecipient_);
|
||||
devicestatusProxy_ = nullptr;
|
||||
}
|
||||
if (deathListener_ != nullptr) {
|
||||
FI_HILOGI("Notify death listener");
|
||||
deathListener_();
|
||||
}
|
||||
}
|
||||
|
||||
void IntentionClient::IntentionDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CHKPV(remote);
|
||||
IntentionClient::GetInstance().ResetProxy(remote);
|
||||
FI_HILOGD("Recv death notice");
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
147
intention/ipc/socket/BUILD.gn
Executable file
147
intention/ipc/socket/BUILD.gn
Executable file
@ -0,0 +1,147 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("../../../device_status.gni")
|
||||
|
||||
config("intention_socket_server_public_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_source_set("intention_socket_server") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
defines = device_status_default_defines
|
||||
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
sources = [
|
||||
"src/socket_params.cpp",
|
||||
"src/socket_server.cpp",
|
||||
]
|
||||
|
||||
public_configs = [ ":intention_socket_server_public_config" ]
|
||||
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_root_path}/utils/common:devicestatus_util",
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"hilog:libhilog",
|
||||
"image_framework:image_native",
|
||||
"input:libmmi-client",
|
||||
]
|
||||
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
||||
part_name = "${device_status_part_name}"
|
||||
}
|
||||
|
||||
config("intention_socket_session_manager_public_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_source_set("intention_socket_session_manager") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
defines = device_status_default_defines
|
||||
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
sources = [
|
||||
"src/socket_session.cpp",
|
||||
"src/socket_session_manager.cpp",
|
||||
]
|
||||
|
||||
public_configs = [ ":intention_socket_session_manager_public_config" ]
|
||||
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/common/epoll:intention_epoll",
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_root_path}/utils/common:devicestatus_util",
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hilog:libhilog",
|
||||
"image_framework:image_native",
|
||||
"input:libmmi-client",
|
||||
]
|
||||
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
||||
part_name = "${device_status_part_name}"
|
||||
}
|
||||
|
||||
config("intention_socket_connection_public_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_source_set("intention_socket_connection") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
defines = device_status_default_defines
|
||||
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
sources = [
|
||||
"src/socket_client.cpp",
|
||||
"src/socket_connection.cpp",
|
||||
"src/socket_params.cpp",
|
||||
]
|
||||
|
||||
public_configs = [ ":intention_socket_connection_public_config" ]
|
||||
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/common/epoll:intention_epoll",
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_root_path}/utils/common:devicestatus_util",
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
]
|
||||
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
||||
part_name = "${device_status_part_name}"
|
||||
}
|
60
intention/ipc/socket/include/socket_client.h
Normal file
60
intention/ipc/socket/include/socket_client.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SOCKET_CLIENT_H
|
||||
#define SOCKET_CLIENT_H
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
#include "i_tunnel_client.h"
|
||||
#include "net_packet.h"
|
||||
#include "proto.h"
|
||||
#include "socket_connection.h"
|
||||
#include "stream_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class SocketClient final : public StreamClient {
|
||||
public:
|
||||
SocketClient(std::shared_ptr<ITunnelClient> tunnel);
|
||||
DISALLOW_COPY_AND_MOVE(SocketClient);
|
||||
~SocketClient();
|
||||
|
||||
bool RegisterEvent(MessageId id, std::function<int32_t(const StreamClient&, NetPacket&)> callback);
|
||||
bool Start();
|
||||
void Stop() override;
|
||||
bool CheckValidFd() const;
|
||||
|
||||
private:
|
||||
bool StartEventRunner();
|
||||
bool Connect();
|
||||
int32_t Socket() override;
|
||||
void OnPacket(NetPacket &pkt);
|
||||
void OnDisconnected() override;
|
||||
void Reconnect();
|
||||
void OnMsgHandler(const StreamClient &client, NetPacket &pkt);
|
||||
|
||||
std::weak_ptr<ITunnelClient> tunnel_;
|
||||
mutable std::mutex lock_;
|
||||
std::map<MessageId, std::function<int32_t(const StreamClient&, NetPacket&)>> callbacks_;
|
||||
std::shared_ptr<SocketConnection> socket_ { nullptr };
|
||||
std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ { nullptr };
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // SOCKET_CLIENT_H
|
63
intention/ipc/socket/include/socket_connection.h
Normal file
63
intention/ipc/socket/include/socket_connection.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SOCKET_CONNECTION_H
|
||||
#define SOCKET_CONNECTION_H
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "file_descriptor_listener.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
#include "circle_stream_buffer.h"
|
||||
#include "net_packet.h"
|
||||
#include "stream_socket.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class SocketConnection final : public AppExecFwk::FileDescriptorListener, StreamSocket {
|
||||
public:
|
||||
SocketConnection(int32_t socketFd,
|
||||
std::function<void(NetPacket&)> recv,
|
||||
std::function<void()> onDisconnected);
|
||||
~SocketConnection();
|
||||
DISALLOW_COPY_AND_MOVE(SocketConnection);
|
||||
|
||||
int32_t GetFd() const;
|
||||
|
||||
void OnReadable(int32_t fd) override;
|
||||
void OnShutdown(int32_t fd) override;
|
||||
void OnException(int32_t fd) override;
|
||||
|
||||
static std::shared_ptr<SocketConnection> Connect(std::function<int32_t()> socket,
|
||||
std::function<void(NetPacket&)> recv, std::function<void()> onDisconnected);
|
||||
|
||||
private:
|
||||
int32_t socketFd_ { -1 };
|
||||
std::function<void(NetPacket&)> recv_;
|
||||
std::function<void()> onDisconnected_;
|
||||
CircleStreamBuffer buffer_;
|
||||
};
|
||||
|
||||
inline int32_t SocketConnection::GetFd() const
|
||||
{
|
||||
return socketFd_;
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // SOCKET_CONNECTION_H
|
53
intention/ipc/socket/include/socket_params.h
Normal file
53
intention/ipc/socket/include/socket_params.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SOCKET_PARAMS_H
|
||||
#define SOCKET_PARAMS_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "intention_identity.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
enum SocketAction : uint32_t {
|
||||
SOCKET_ACTION_UNKNOWN,
|
||||
SOCKET_ACTION_CONNECT,
|
||||
};
|
||||
|
||||
struct AllocSocketPairParam final : public ParamBase {
|
||||
AllocSocketPairParam() = default;
|
||||
AllocSocketPairParam(const std::string &programName, int32_t moduleType);
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
std::string programName;
|
||||
int32_t moduleType { -1 };
|
||||
};
|
||||
|
||||
struct AllocSocketPairReply final : public ParamBase {
|
||||
AllocSocketPairReply() = default;
|
||||
AllocSocketPairReply(int32_t tokenType, int32_t socketFd);
|
||||
bool Marshalling(MessageParcel &parcel) const override;
|
||||
bool Unmarshalling(MessageParcel &parcel) override;
|
||||
|
||||
int32_t tokenType { -1 };
|
||||
int32_t socketFd { -1 };
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // SOCKET_PARAMS_H
|
49
intention/ipc/socket/include/socket_server.h
Normal file
49
intention/ipc/socket/include/socket_server.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SOCKET_SERVER_H
|
||||
#define SOCKET_SERVER_H
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
#include "i_context.h"
|
||||
#include "i_plugin.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class SocketServer final : public IPlugin {
|
||||
public:
|
||||
SocketServer(IContext *context);
|
||||
~SocketServer() = default;
|
||||
DISALLOW_COPY_AND_MOVE(SocketServer);
|
||||
|
||||
int32_t Enable(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Disable(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Start(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Stop(CallingContext &context, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t AddWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t RemoveWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t SetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t GetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Control(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
|
||||
private:
|
||||
IContext *context_ { nullptr };
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // SOCKET_SERVER_H
|
70
intention/ipc/socket/include/socket_session.h
Normal file
70
intention/ipc/socket/include/socket_session.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SOCKET_SESSION_H
|
||||
#define SOCKET_SESSION_H
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
#include "i_epoll_event_source.h"
|
||||
#include "i_socket_session.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class SocketSession final : public ISocketSession, public IEpollEventSource {
|
||||
public:
|
||||
SocketSession(const std::string &programName, int32_t moduleType,
|
||||
int32_t tokenType, int32_t fd, int32_t uid, int32_t pid);
|
||||
DISALLOW_COPY_AND_MOVE(SocketSession);
|
||||
~SocketSession();
|
||||
|
||||
bool SendMsg(NetPacket &pkt) const override;
|
||||
|
||||
int32_t GetUid() const override;
|
||||
int32_t GetPid() const override;
|
||||
std::string ToString() const override;
|
||||
|
||||
int32_t GetFd() const override;
|
||||
void Dispatch(const struct epoll_event &ev) override;
|
||||
|
||||
private:
|
||||
bool SendMsg(const char *buf, size_t size) const;
|
||||
|
||||
private:
|
||||
int32_t fd_ { -1 };
|
||||
int32_t uid_ { -1 };
|
||||
int32_t pid_ { -1 };
|
||||
int32_t tokenType_ { TokenType::TOKEN_INVALID };
|
||||
};
|
||||
|
||||
inline int32_t SocketSession::GetUid() const
|
||||
{
|
||||
return uid_;
|
||||
}
|
||||
|
||||
inline int32_t SocketSession::GetPid() const
|
||||
{
|
||||
return pid_;
|
||||
}
|
||||
|
||||
inline int32_t SocketSession::GetFd() const
|
||||
{
|
||||
return fd_;
|
||||
}
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
} // namespace DeviceStatus
|
||||
#endif // SOCKET_SESSION_H
|
69
intention/ipc/socket/include/socket_session_manager.h
Normal file
69
intention/ipc/socket/include/socket_session_manager.h
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SOCKET_SESSION_MANAGER_H
|
||||
#define SOCKET_SESSION_MANAGER_H
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
#include "epoll_manager.h"
|
||||
#include "i_epoll_event_source.h"
|
||||
#include "i_socket_session_manager.h"
|
||||
#include "socket_session.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class SocketSessionManager final : public ISocketSessionManager, public IEpollEventSource {
|
||||
public:
|
||||
SocketSessionManager() = default;
|
||||
~SocketSessionManager() = default;
|
||||
DISALLOW_COPY_AND_MOVE(SocketSessionManager);
|
||||
|
||||
int32_t Init();
|
||||
|
||||
void AddSessionDeletedCallback(int32_t pid, std::function<void(SocketSessionPtr)> callback) override;
|
||||
int32_t AllocSocketFd(const std::string& programName, int32_t moduleType, int32_t tokenType,
|
||||
int32_t uid, int32_t pid, int32_t& clientFd) override;
|
||||
SocketSessionPtr FindSessionByPid(int32_t pid) const override;
|
||||
|
||||
int32_t GetFd() const override;
|
||||
void Dispatch(const struct epoll_event &ev) override;
|
||||
|
||||
private:
|
||||
bool SetBufferSize(int32_t sockFd, int32_t bufSize);
|
||||
void DispatchOne();
|
||||
void ReleaseSession(int32_t fd);
|
||||
std::shared_ptr<SocketSession> FindSession(int32_t fd) const;
|
||||
bool AddSession(std::shared_ptr<SocketSession> session);
|
||||
void DumpSession(const std::string& title) const;
|
||||
void NotifySessionDeleted(std::shared_ptr<SocketSession> sessionPtr);
|
||||
|
||||
EpollManager epollMgr_;
|
||||
std::map<int32_t, std::shared_ptr<SocketSession>> sessions_;
|
||||
std::map<int32_t, std::function<void(SocketSessionPtr)>> callbacks_;
|
||||
};
|
||||
|
||||
inline int32_t SocketSessionManager::GetFd() const
|
||||
{
|
||||
return epollMgr_.GetFd();
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // SOCKET_SESSION_MANAGER_H
|
177
intention/ipc/socket/src/socket_client.cpp
Normal file
177
intention/ipc/socket/src/socket_client.cpp
Normal file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "socket_client.h"
|
||||
|
||||
#include "event_handler.h"
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
#include "intention_identity.h"
|
||||
#include "socket_params.h"
|
||||
#include "time_cost_chk.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "SocketClient" };
|
||||
const std::string THREAD_NAME { "os_ClientEventHandler" };
|
||||
}
|
||||
|
||||
SocketClient::SocketClient(std::shared_ptr<ITunnelClient> tunnel)
|
||||
: tunnel_(tunnel)
|
||||
{}
|
||||
|
||||
SocketClient::~SocketClient()
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
|
||||
bool SocketClient::RegisterEvent(MessageId id, std::function<int32_t(const StreamClient&, NetPacket&)> callback)
|
||||
{
|
||||
std::lock_guard guard(lock_);
|
||||
auto [_, inserted] = callbacks_.emplace(id, callback);
|
||||
return inserted;
|
||||
}
|
||||
|
||||
bool SocketClient::Start()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard guard(lock_);
|
||||
return (
|
||||
StartEventRunner() &&
|
||||
Connect()
|
||||
);
|
||||
}
|
||||
|
||||
void SocketClient::Stop()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard guard(lock_);
|
||||
eventHandler_.reset();
|
||||
socket_.reset();
|
||||
}
|
||||
|
||||
bool SocketClient::CheckValidFd() const
|
||||
{
|
||||
std::lock_guard guard(lock_);
|
||||
return ((socket_ != nullptr) && (socket_->GetFd() > 0));
|
||||
}
|
||||
|
||||
bool SocketClient::StartEventRunner()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CHK_PID_AND_TID();
|
||||
if (eventHandler_ != nullptr) {
|
||||
return true;
|
||||
}
|
||||
auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME);
|
||||
CHKPF(runner);
|
||||
eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
|
||||
FI_HILOGI("Create event handler, thread name:%{public}s", runner->GetRunnerThreadName().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SocketClient::Connect()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
if (socket_ != nullptr) {
|
||||
return true;
|
||||
}
|
||||
auto socket = SocketConnection::Connect(
|
||||
std::bind(&SocketClient::Socket, this),
|
||||
std::bind(&SocketClient::OnPacket, this, std::placeholders::_1),
|
||||
std::bind(&SocketClient::OnDisconnected, this));
|
||||
CHKPF(socket);
|
||||
CHKPF(eventHandler_);
|
||||
auto errCode = eventHandler_->AddFileDescriptorListener(socket->GetFd(),
|
||||
AppExecFwk::FILE_DESCRIPTOR_INPUT_EVENT, socket, "DeviceStatusTask");
|
||||
if (errCode != ERR_OK) {
|
||||
FI_HILOGE("AddFileDescriptorListener(%{public}d) failed (%{public}u)", socket->GetFd(), errCode);
|
||||
return false;
|
||||
}
|
||||
socket_ = socket;
|
||||
FI_HILOGD("SocketClient started successfully");
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t SocketClient::Socket()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::shared_ptr<ITunnelClient> tunnel = tunnel_.lock();
|
||||
CHKPR(tunnel, RET_ERR);
|
||||
AllocSocketPairParam param { GetProgramName(), CONNECT_MODULE_TYPE_FI_CLIENT };
|
||||
AllocSocketPairReply reply;
|
||||
|
||||
int32_t ret = tunnel->Control(Intention::SOCKET, SocketAction::SOCKET_ACTION_CONNECT, param, reply);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("ITunnelClient::Control fail");
|
||||
return -1;
|
||||
}
|
||||
FI_HILOGD("Connected to intention service (%{public}d)", reply.socketFd);
|
||||
return reply.socketFd;
|
||||
}
|
||||
|
||||
void SocketClient::OnPacket(NetPacket &pkt)
|
||||
{
|
||||
std::lock_guard guard(lock_);
|
||||
OnMsgHandler(*this, pkt);
|
||||
}
|
||||
|
||||
void SocketClient::OnDisconnected()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard guard(lock_);
|
||||
CHKPV(eventHandler_);
|
||||
if (socket_ != nullptr) {
|
||||
eventHandler_->RemoveFileDescriptorListener(socket_->GetFd());
|
||||
eventHandler_->RemoveAllEvents();
|
||||
socket_.reset();
|
||||
}
|
||||
if (!eventHandler_->PostTask(std::bind(&SocketClient::Reconnect, this), CLIENT_RECONNECT_COOLING_TIME)) {
|
||||
FI_HILOGE("Failed to post reconnection task");
|
||||
}
|
||||
}
|
||||
|
||||
void SocketClient::Reconnect()
|
||||
{
|
||||
std::lock_guard guard(lock_);
|
||||
if (Connect()) {
|
||||
return;
|
||||
}
|
||||
CHKPV(eventHandler_);
|
||||
if (!eventHandler_->PostTask(std::bind(&SocketClient::Reconnect, this), CLIENT_RECONNECT_COOLING_TIME)) {
|
||||
FI_HILOGE("Failed to post reconnection task");
|
||||
}
|
||||
}
|
||||
|
||||
void SocketClient::OnMsgHandler(const StreamClient &client, NetPacket &pkt)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
MessageId id = pkt.GetMsgId();
|
||||
TimeCostChk chk("SocketClient::OnMsgHandler", "overtime 300(us)", MAX_OVER_TIME, id);
|
||||
auto iter = callbacks_.find(id);
|
||||
if (iter == callbacks_.end()) {
|
||||
FI_HILOGE("Unknown msg id:%{public}d", id);
|
||||
return;
|
||||
}
|
||||
int32_t ret = iter->second(client, pkt);
|
||||
if (ret < 0) {
|
||||
FI_HILOGE("Msg handling failed, id:%{public}d, ret:%{public}d", id, ret);
|
||||
}
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
98
intention/ipc/socket/src/socket_connection.cpp
Normal file
98
intention/ipc/socket/src/socket_connection.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "socket_connection.h"
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
#include "include/util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "SocketConnection" };
|
||||
} // namespace
|
||||
|
||||
SocketConnection::SocketConnection(int32_t socketFd,
|
||||
std::function<void(NetPacket&)> recv,
|
||||
std::function<void()> onDisconnected)
|
||||
: socketFd_(socketFd), recv_(recv), onDisconnected_(onDisconnected)
|
||||
{}
|
||||
|
||||
SocketConnection::~SocketConnection()
|
||||
{
|
||||
if ((socketFd_ >= 0) && (::close(socketFd_) != 0)) {
|
||||
FI_HILOGE("close(%{public}d) failed:%{public}s", socketFd_, ::strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<SocketConnection> SocketConnection::Connect(std::function<int32_t()> socket,
|
||||
std::function<void(NetPacket&)> recv, std::function<void()> onDisconnected)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CHKPP(socket);
|
||||
int32_t sockFd = socket();
|
||||
if (sockFd < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_shared<SocketConnection>(sockFd, recv, onDisconnected);
|
||||
}
|
||||
|
||||
void SocketConnection::OnReadable(int32_t fd)
|
||||
{
|
||||
char buf[MAX_PACKET_BUF_SIZE] {};
|
||||
ssize_t numRead;
|
||||
|
||||
do {
|
||||
numRead = ::recv(fd, buf, sizeof(buf), MSG_DONTWAIT);
|
||||
if (numRead > 0) {
|
||||
buffer_.Write(buf, numRead);
|
||||
OnReadPackets(buffer_, recv_);
|
||||
} else if (numRead < 0) {
|
||||
if (errno == EINTR) {
|
||||
FI_HILOGD("recv was interrupted, read again");
|
||||
continue;
|
||||
}
|
||||
if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
|
||||
FI_HILOGW("No available data");
|
||||
} else {
|
||||
FI_HILOGE("recv failed:%{public}s", ::strerror(errno));
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
FI_HILOGE("EOF happened");
|
||||
OnShutdown(fd);
|
||||
break;
|
||||
}
|
||||
} while (numRead == sizeof(buf));
|
||||
}
|
||||
|
||||
void SocketConnection::OnShutdown(int32_t fd)
|
||||
{
|
||||
if (onDisconnected_) {
|
||||
onDisconnected_();
|
||||
}
|
||||
}
|
||||
|
||||
void SocketConnection::OnException(int32_t fd)
|
||||
{
|
||||
OnShutdown(fd);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
62
intention/ipc/socket/src/socket_params.cpp
Normal file
62
intention/ipc/socket/src/socket_params.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "socket_params.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
AllocSocketPairParam::AllocSocketPairParam(const std::string &programName, int32_t moduleType)
|
||||
: programName(programName), moduleType(moduleType)
|
||||
{}
|
||||
|
||||
bool AllocSocketPairParam::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return (
|
||||
parcel.WriteString(programName) &&
|
||||
parcel.WriteInt32(moduleType)
|
||||
);
|
||||
}
|
||||
|
||||
bool AllocSocketPairParam::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return (
|
||||
parcel.ReadString(programName) &&
|
||||
parcel.ReadInt32(moduleType)
|
||||
);
|
||||
}
|
||||
|
||||
AllocSocketPairReply::AllocSocketPairReply(int32_t tokenType, int32_t socketFd)
|
||||
: tokenType(tokenType), socketFd(socketFd)
|
||||
{}
|
||||
|
||||
bool AllocSocketPairReply::Marshalling(MessageParcel &parcel) const
|
||||
{
|
||||
return (
|
||||
parcel.WriteInt32(tokenType) &&
|
||||
parcel.WriteFileDescriptor(socketFd)
|
||||
);
|
||||
}
|
||||
|
||||
bool AllocSocketPairReply::Unmarshalling(MessageParcel &parcel)
|
||||
{
|
||||
return (
|
||||
parcel.ReadInt32(tokenType) &&
|
||||
((socketFd = parcel.ReadFileDescriptor()) >= 0)
|
||||
);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
112
intention/ipc/socket/src/socket_server.cpp
Normal file
112
intention/ipc/socket/src/socket_server.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "socket_server.h"
|
||||
|
||||
#include "accesstoken_kit.h"
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
#include "socket_params.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "SocketServer" };
|
||||
} // namespace
|
||||
|
||||
SocketServer::SocketServer(IContext *context)
|
||||
: context_(context)
|
||||
{}
|
||||
|
||||
int32_t SocketServer::Enable(CallingContext &context, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t SocketServer::Disable(CallingContext &context, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t SocketServer::Start(CallingContext &context, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t SocketServer::Stop(CallingContext &context, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t SocketServer::AddWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t SocketServer::RemoveWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t SocketServer::SetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t SocketServer::GetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t SocketServer::Control(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
if (id != SocketAction::SOCKET_ACTION_CONNECT) {
|
||||
FI_HILOGE("Unsupported action");
|
||||
return RET_ERR;
|
||||
}
|
||||
AllocSocketPairParam param;
|
||||
if (!param.Unmarshalling(data)) {
|
||||
FI_HILOGE("AllocSocketPairParam::Unmarshalling fail");
|
||||
return RET_ERR;
|
||||
}
|
||||
int32_t tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(context.tokenId);
|
||||
int32_t clientFd { -1 };
|
||||
CHKPR(context_, RET_ERR);
|
||||
int32_t ret = context_->GetSocketSessionManager().AllocSocketFd(
|
||||
param.programName, param.moduleType, tokenType, context.uid, context.pid, clientFd);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("AllocSocketFd failed");
|
||||
return RET_ERR;
|
||||
}
|
||||
AllocSocketPairReply replyData(tokenType, clientFd);
|
||||
if (!replyData.Marshalling(reply)) {
|
||||
FI_HILOGE("AllocSocketPairReply::Marshalling fail");
|
||||
return RET_ERR;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
118
intention/ipc/socket/src/socket_session.cpp
Normal file
118
intention/ipc/socket/src/socket_session.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "socket_session.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "proto.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "SocketSession" };
|
||||
} // namespace
|
||||
|
||||
SocketSession::SocketSession(const std::string &programName, int32_t moduleType,
|
||||
int32_t tokenType, int32_t fd, int32_t uid, int32_t pid)
|
||||
: fd_(fd), uid_(uid), pid_(pid), tokenType_(tokenType)
|
||||
{}
|
||||
|
||||
SocketSession::~SocketSession()
|
||||
{
|
||||
if ((fd_ >= 0) && (::close(fd_) != 0)) {
|
||||
FI_HILOGE("close(%{public}d) failed:%{public}s", fd_, ::strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
bool SocketSession::SendMsg(NetPacket &pkt) const
|
||||
{
|
||||
if (pkt.ChkRWError()) {
|
||||
FI_HILOGE("Read and write status is error");
|
||||
return false;
|
||||
}
|
||||
StreamBuffer buf;
|
||||
pkt.MakeData(buf);
|
||||
return SendMsg(buf.Data(), buf.Size());
|
||||
}
|
||||
|
||||
bool SocketSession::SendMsg(const char *buf, size_t size) const
|
||||
{
|
||||
CHKPF(buf);
|
||||
if ((size == 0) || (size > MAX_PACKET_BUF_SIZE)) {
|
||||
FI_HILOGE("buf size:%{public}zu", size);
|
||||
return false;
|
||||
}
|
||||
if (fd_ < 0) {
|
||||
FI_HILOGE("The fd_ is less than 0");
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t idx = 0;
|
||||
int32_t retryCount = 0;
|
||||
const int32_t bufSize = static_cast<int32_t>(size);
|
||||
int32_t remSize = bufSize;
|
||||
while (remSize > 0 && retryCount < SEND_RETRY_LIMIT) {
|
||||
retryCount += 1;
|
||||
ssize_t count = send(fd_, &buf[idx], remSize, MSG_DONTWAIT | MSG_NOSIGNAL);
|
||||
if (count < 0) {
|
||||
if (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK) {
|
||||
usleep(SEND_RETRY_SLEEP_TIME);
|
||||
FI_HILOGW("Continue for errno EAGAIN|EINTR|EWOULDBLOCK, errno:%{public}d", errno);
|
||||
continue;
|
||||
}
|
||||
FI_HILOGE("Send return failed, error:%{public}d, fd:%{public}d", errno, fd_);
|
||||
return false;
|
||||
}
|
||||
idx += count;
|
||||
remSize -= count;
|
||||
if (remSize > 0) {
|
||||
usleep(SEND_RETRY_SLEEP_TIME);
|
||||
}
|
||||
}
|
||||
if (retryCount >= SEND_RETRY_LIMIT || remSize != 0) {
|
||||
FI_HILOGE("Send too many times:%{public}d/%{public}d, size:%{public}d/%{public}d, fd:%{public}d",
|
||||
retryCount, SEND_RETRY_LIMIT, idx, bufSize, fd_);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string SocketSession::ToString() const
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "fd = " << fd_
|
||||
<< ((fd_ < 0) ? ", closed" : ", opened")
|
||||
<< ", pid = " << pid_
|
||||
<< ", tokenType = " << tokenType_
|
||||
<< std::endl;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
void SocketSession::Dispatch(const struct epoll_event &ev)
|
||||
{
|
||||
if ((ev.events & EPOLLIN) == EPOLLIN) {
|
||||
FI_HILOGD("Data received (%{public}d)", fd_);
|
||||
} else if ((ev.events & (EPOLLHUP | EPOLLERR)) != 0) {
|
||||
FI_HILOGE("Epoll hangup:%{public}s", ::strerror(errno));
|
||||
}
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
206
intention/ipc/socket/src/socket_session_manager.cpp
Normal file
206
intention/ipc/socket/src/socket_session_manager.cpp
Normal file
@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "socket_session_manager.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "SocketSessionManager" };
|
||||
constexpr int32_t MAX_EPOLL_EVENTS { 64 };
|
||||
} // namespace
|
||||
|
||||
int32_t SocketSessionManager::Init()
|
||||
{
|
||||
return epollMgr_.Open();
|
||||
}
|
||||
|
||||
int32_t SocketSessionManager::AllocSocketFd(const std::string& programName, int32_t moduleType, int32_t tokenType,
|
||||
int32_t uid, int32_t pid, int32_t& clientFd)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
int32_t sockFds[2] { -1, -1 };
|
||||
|
||||
if (::socketpair(AF_UNIX, SOCK_STREAM, 0, sockFds) != 0) {
|
||||
FI_HILOGE("Call socketpair failed, errno:%{public}s", ::strerror(errno));
|
||||
return RET_ERR;
|
||||
}
|
||||
static constexpr size_t BUFFER_SIZE { 32 * 1024 };
|
||||
static constexpr size_t NATIVE_BUFFER_SIZE { 64 * 1024 };
|
||||
std::shared_ptr<SocketSession> session { nullptr };
|
||||
|
||||
if (!SetBufferSize(sockFds[0], BUFFER_SIZE)) {
|
||||
goto CLOSE_SOCK;
|
||||
}
|
||||
if (!SetBufferSize(sockFds[1], tokenType == TokenType::TOKEN_NATIVE ? NATIVE_BUFFER_SIZE : BUFFER_SIZE)) {
|
||||
goto CLOSE_SOCK;
|
||||
}
|
||||
|
||||
session = std::make_shared<SocketSession>(programName, moduleType, tokenType, sockFds[0], uid, pid);
|
||||
if (epollMgr_.Add(*session) != RET_OK) {
|
||||
goto CLOSE_SOCK;
|
||||
}
|
||||
if (!AddSession(session)) {
|
||||
FI_HILOGE("AddSession failed, errCode:%{public}d", ADD_SESSION_FAIL);
|
||||
goto CLOSE_SOCK;
|
||||
}
|
||||
|
||||
clientFd = sockFds[1];
|
||||
return RET_OK;
|
||||
|
||||
CLOSE_SOCK:
|
||||
if (::close(sockFds[0]) != 0) {
|
||||
FI_HILOGE("close(%{public}d) failed:%{public}s", sockFds[0], ::strerror(errno));
|
||||
}
|
||||
if (::close(sockFds[1]) != 0) {
|
||||
FI_HILOGE("close(%{public}d) failed:%{public}s", sockFds[1], ::strerror(errno));
|
||||
}
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
bool SocketSessionManager::SetBufferSize(int32_t sockFd, int32_t bufSize)
|
||||
{
|
||||
if (::setsockopt(sockFd, SOL_SOCKET, SO_SNDBUF, &bufSize, sizeof(bufSize)) != 0) {
|
||||
FI_HILOGE("setsockopt(%{public}d) failed:%{public}s", sockFd, ::strerror(errno));
|
||||
return false;
|
||||
}
|
||||
if (::setsockopt(sockFd, SOL_SOCKET, SO_RCVBUF, &bufSize, sizeof(bufSize)) != 0) {
|
||||
FI_HILOGE("setsockopt(%{public}d) failed:%{public}s", sockFd, ::strerror(errno));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
SocketSessionPtr SocketSessionManager::FindSessionByPid(int32_t pid) const
|
||||
{
|
||||
auto iter = std::find_if(sessions_.cbegin(), sessions_.cend(),
|
||||
[pid](const auto &item) {
|
||||
return ((item.second != nullptr) && (item.second->GetPid() == pid));
|
||||
});
|
||||
return (iter != sessions_.cend() ? iter->second : nullptr);
|
||||
}
|
||||
|
||||
void SocketSessionManager::Dispatch(const struct epoll_event &ev)
|
||||
{
|
||||
if ((ev.events & EPOLLIN) == EPOLLIN) {
|
||||
DispatchOne();
|
||||
} else if ((ev.events & (EPOLLHUP | EPOLLERR)) != 0) {
|
||||
FI_HILOGE("Epoll hangup:%{public}s", ::strerror(errno));
|
||||
/// TODO: Add error handling here.
|
||||
}
|
||||
}
|
||||
|
||||
void SocketSessionManager::DispatchOne()
|
||||
{
|
||||
struct epoll_event evs[MAX_EPOLL_EVENTS];
|
||||
int32_t cnt = epollMgr_.WaitTimeout(evs, MAX_EPOLL_EVENTS, 0);
|
||||
|
||||
for (int32_t index = 0; index < cnt; ++index) {
|
||||
IEpollEventSource *source = reinterpret_cast<IEpollEventSource *>(evs[index].data.ptr);
|
||||
CHKPC(source);
|
||||
if ((evs[index].events & EPOLLIN) == EPOLLIN) {
|
||||
source->Dispatch(evs[index]);
|
||||
} else if ((evs[index].events & (EPOLLHUP | EPOLLERR)) != 0) {
|
||||
FI_HILOGE("Epoll hangup:%{public}s", ::strerror(errno));
|
||||
ReleaseSession(source->GetFd());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SocketSessionManager::ReleaseSession(int32_t fd)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
if (auto iter = sessions_.find(fd); iter != sessions_.end()) {
|
||||
auto session = iter->second;
|
||||
sessions_.erase(iter);
|
||||
|
||||
if (session != nullptr) {
|
||||
epollMgr_.Remove(*session);
|
||||
NotifySessionDeleted(session);
|
||||
}
|
||||
}
|
||||
DumpSession("DelSession");
|
||||
}
|
||||
|
||||
std::shared_ptr<SocketSession> SocketSessionManager::FindSession(int32_t fd) const
|
||||
{
|
||||
auto iter = sessions_.find(fd);
|
||||
return (iter != sessions_.cend() ? iter->second : nullptr);
|
||||
}
|
||||
|
||||
void SocketSessionManager::DumpSession(const std::string &title) const
|
||||
{
|
||||
FI_HILOGD("in %s:%s", __func__, title.c_str());
|
||||
int32_t i = 0;
|
||||
|
||||
for (auto &[_, session] : sessions_) {
|
||||
CHKPC(session);
|
||||
FI_HILOGD("%{public}d, %s", i, session->ToString().c_str());
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
bool SocketSessionManager::AddSession(std::shared_ptr<SocketSession> session)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CHKPF(session);
|
||||
if (sessions_.size() >= MAX_SESSION_ALARM) {
|
||||
FI_HILOGE("The number of connections exceeds limit(%{public}zu)", MAX_SESSION_ALARM);
|
||||
return false;
|
||||
}
|
||||
auto [_, inserted] = sessions_.emplace(session->GetFd(), session);
|
||||
if (!inserted) {
|
||||
FI_HILOGE("Session(%{public}d) has been recorded", session->GetFd());
|
||||
return false;
|
||||
}
|
||||
DumpSession("AddSession");
|
||||
return true;
|
||||
}
|
||||
|
||||
void SocketSessionManager::AddSessionDeletedCallback(int32_t pid, std::function<void(SocketSessionPtr)> callback)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
if (callback == nullptr) {
|
||||
FI_HILOGE("Callback is none");
|
||||
return;
|
||||
}
|
||||
auto [_, inserted] = callbacks_.emplace(pid, callback);
|
||||
if (!inserted) {
|
||||
FI_HILOGW("Duplicate addtion of session-lost callback for (%{public}d)", pid);
|
||||
}
|
||||
}
|
||||
|
||||
void SocketSessionManager::NotifySessionDeleted(std::shared_ptr<SocketSession> session)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
FI_HILOGD("Session lost, pid:%{public}d", session->GetPid());
|
||||
if (auto iter = callbacks_.find(session->GetPid()); iter != callbacks_.end()) {
|
||||
if (iter->second) {
|
||||
iter->second(session);
|
||||
}
|
||||
callbacks_.erase(iter);
|
||||
}
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
81
intention/ipc/tunnel/BUILD.gn
Normal file
81
intention/ipc/tunnel/BUILD.gn
Normal file
@ -0,0 +1,81 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("../../../device_status.gni")
|
||||
|
||||
config("intention_tunnel_public_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_source_set("intention_tunnel_client") {
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
sources = [
|
||||
"src/intention_proxy.cpp",
|
||||
"src/tunnel_client.cpp",
|
||||
]
|
||||
|
||||
public_configs = [ ":intention_tunnel_public_config" ]
|
||||
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_utils_path}:devicestatus_util",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
||||
part_name = "${device_status_part_name}"
|
||||
}
|
||||
|
||||
ohos_source_set("intention_tunnel_server") {
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
sources = [ "src/intention_stub.cpp" ]
|
||||
|
||||
public_configs = [ ":intention_tunnel_public_config" ]
|
||||
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_utils_path}:devicestatus_util",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
||||
part_name = "${device_status_part_name}"
|
||||
}
|
@ -18,8 +18,10 @@
|
||||
#ifndef I_INTENTION_H
|
||||
#define I_INTENTION_H
|
||||
|
||||
#include <iremote_broker.h>
|
||||
#include <message_parcel.h>
|
||||
#include "iremote_broker.h"
|
||||
#include "message_parcel.h"
|
||||
|
||||
#include "intention_identity.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
@ -32,30 +34,30 @@ namespace DeviceStatus {
|
||||
class IIntention : public IRemoteBroker {
|
||||
public:
|
||||
// Enable the service identified by [`intention`].
|
||||
virtual int32_t Enable(uint32_t intention, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
virtual int32_t Enable(Intention intention, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
// Disable the service identified by [`intention`].
|
||||
virtual int32_t Disable(uint32_t intention, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
virtual int32_t Disable(Intention intention, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
// Start the service identified by [`intention`].
|
||||
virtual int32_t Start(uint32_t intention, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
virtual int32_t Start(Intention intention, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
// Stop the service identified by [`intention`].
|
||||
virtual int32_t Stop(uint32_t intention, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
virtual int32_t Stop(Intention intention, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
// Add a watch of state of service, with the service identified by [`intention`],
|
||||
// the state to watch identified by [`id`], parameters packed in [`data`] parcel.
|
||||
virtual int32_t AddWatch(uint32_t intention, uint32_t id, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
virtual int32_t AddWatch(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
// Remove a watch of state of service.
|
||||
virtual int32_t RemoveWatch(uint32_t intention, uint32_t id, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
virtual int32_t RemoveWatch(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
// Set a parameter of service, with the service identified by [`intention`],
|
||||
// the parameter identified by [`id`], and values packed in [`data`] parcel.
|
||||
virtual int32_t SetParam(uint32_t intention, uint32_t id, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
virtual int32_t SetParam(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
// Get a parameter of service, with the service identified by [`intention`],
|
||||
// the parameter identified by [`id`].
|
||||
virtual int32_t GetParam(uint32_t intention, uint32_t id, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
virtual int32_t GetParam(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
// Interact with service identified by [`intention`] for general purpose. This interface
|
||||
// supplements functions of previous intefaces. Functionalities of this interface is
|
||||
// service spicific.
|
||||
virtual int32_t Control(uint32_t intention, uint32_t id, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
virtual int32_t Control(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply) = 0;
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.msdp.Idevicestatus");
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.msdp.devicestatus.intention");
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
@ -17,7 +17,7 @@
|
||||
#define INTENTION_PROXY_H
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
#include <nocopyable.h>
|
||||
#include "nocopyable.h"
|
||||
|
||||
#include "i_intention.h"
|
||||
|
||||
@ -26,20 +26,19 @@ namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class IntentionProxy : public IRemoteProxy<IIntention> {
|
||||
public:
|
||||
explicit IntentionProxy(const sptr<IRemoteObject>& impl)
|
||||
: IRemoteProxy<IIntention>(impl) {}
|
||||
explicit IntentionProxy(const sptr<IRemoteObject> &impl);
|
||||
DISALLOW_COPY_AND_MOVE(IntentionProxy);
|
||||
~IntentionProxy() = default;
|
||||
|
||||
int32_t Enable(uint32_t intention, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Disable(uint32_t intention, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Start(uint32_t intention, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Stop(uint32_t intention, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t AddWatch(uint32_t intention, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t RemoveWatch(uint32_t intention, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t SetParam(uint32_t intention, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t GetParam(uint32_t intention, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Control(uint32_t intention, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Enable(Intention intention, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Disable(Intention intention, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Start(Intention intention, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Stop(Intention intention, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t AddWatch(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t RemoveWatch(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t SetParam(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t GetParam(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
int32_t Control(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<IntentionProxy> delegator_;
|
@ -16,12 +16,9 @@
|
||||
#ifndef INTENTION_STUB_H
|
||||
#define INTENTION_STUB_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <iremote_stub.h>
|
||||
#include "iremote_stub.h"
|
||||
#include "message_option.h"
|
||||
#include "message_parcel.h"
|
||||
#include <nocopyable.h>
|
||||
|
||||
#include "i_intention.h"
|
||||
|
||||
@ -31,7 +28,6 @@ namespace DeviceStatus {
|
||||
class IntentionStub : public IRemoteStub<IIntention> {
|
||||
public:
|
||||
IntentionStub() = default;
|
||||
DISALLOW_COPY_AND_MOVE(IntentionStub);
|
||||
virtual ~IntentionStub() = default;
|
||||
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user