mirror of
https://gitee.com/openharmony/msdp_device_status
synced 2025-02-21 08:14:07 +00:00
add interface RegisterThumbnailDraw UnregisterThumbnailDraw
Signed-off-by: mayunteng_1 <mayunteng@huawei.com> Change-Id: If837518e210a89b5569c009e8420b90a1476400e
This commit is contained in:
parent
8ab3d1b957
commit
3b701d04a9
@ -37,8 +37,8 @@ public:
|
||||
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);
|
||||
void ResetEnv();
|
||||
void RegisterThumbnailDraw(napi_env env, size_t argc, napi_value* argv);
|
||||
void UnregisterThumbnailDraw(napi_env env);
|
||||
void RegisterThumbnailDraw(napi_env env, napi_value* argv);
|
||||
void UnregisterThumbnailDraw(napi_env env, napi_value argv);
|
||||
|
||||
private:
|
||||
struct CallbackInfo : public RefBase {
|
||||
@ -46,19 +46,26 @@ private:
|
||||
napi_ref ref { nullptr };
|
||||
};
|
||||
|
||||
struct ThumbnailDrawCb : public RefBase {
|
||||
napi_env env { nullptr };
|
||||
napi_ref ref[3] { nullptr };
|
||||
int32_t errCode { -1 };
|
||||
napi_deferred deferred { nullptr };
|
||||
bool isApi9 { false };
|
||||
};
|
||||
private:
|
||||
void ReleaseReference();
|
||||
bool IsSameHandle(napi_env env, napi_value handle, napi_ref ref);
|
||||
void EmitStartThumbnailDraw(int32_t pixmap, int32_t errCode);
|
||||
void EmitNoticeThumbnailDraw(int32_t dragStates, int32_t errCode);
|
||||
void EmitEndThumbnailDraw(int32_t errCode);
|
||||
void EmitUnregisterThumbnailDraw(int32_t errCode);
|
||||
void EmitUnregisterThumbnailDraw(sptr<CallbackInfo> callbackInfo, int32_t errCode);
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
bool hasRegistered_ { false };
|
||||
inline static std::map<std::string, std::vector<std::unique_ptr<CallbackInfo>>> listeners_ {};
|
||||
inline static std::vector<sptr<CallbackInfo>> thumbnailDrawCb_;
|
||||
sptr<ThumbnailDrawCb> thumbnailDrawCb_;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
|
@ -187,21 +187,21 @@ napi_value JsDragContext::RegisterThumbnailDraw(napi_env env, napi_callback_info
|
||||
size_t argc = 3;
|
||||
napi_value argv[3] = { nullptr };
|
||||
CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO);
|
||||
if (argc < 3) {
|
||||
THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Wrong number of parameters");
|
||||
return nullptr;
|
||||
}
|
||||
for (auto item : argv) {
|
||||
if (!UtilNapi::TypeOf(env, item, napi_function)) {
|
||||
THROWERR(env, COMMON_PARAMETER_ERROR, "callback", "function");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
if (argc < 3) {
|
||||
THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Wrong number of parameters");
|
||||
return nullptr;
|
||||
}
|
||||
JsDragContext *jsDev = JsDragContext::GetInstance(env);
|
||||
CHKPP(jsDev);
|
||||
auto jsDragMgr = jsDev->GetJsDragMgr();
|
||||
CHKPP(jsDragMgr);
|
||||
jsDragMgr->RegisterThumbnailDraw(env, argc, argv);
|
||||
jsDragMgr->RegisterThumbnailDraw(env, argv);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -223,7 +223,7 @@ napi_value JsDragContext::UnregisterThumbnailDraw(napi_env env, napi_callback_in
|
||||
CHKPP(jsDev);
|
||||
auto jsDragMgr = jsDev->GetJsDragMgr();
|
||||
CHKPP(jsDragMgr);
|
||||
jsDragMgr->UnregisterThumbnailDraw(env);
|
||||
jsDragMgr->UnregisterThumbnailDraw(env, argv[0]);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -90,56 +90,58 @@ monitorLabel:
|
||||
|
||||
void JsDragManager::EmitStartThumbnailDraw(int32_t pixmap, int32_t errCode)
|
||||
{
|
||||
(void)pixmap;
|
||||
(void)errCode;
|
||||
CALL_INFO_TRACE;
|
||||
}
|
||||
|
||||
void JsDragManager::EmitNoticeThumbnailDraw(int32_t dragStates, int32_t errCode)
|
||||
{
|
||||
(void)dragStates;
|
||||
(void)errCode;
|
||||
CALL_INFO_TRACE;
|
||||
}
|
||||
|
||||
void JsDragManager::EmitEndThumbnailDraw(int32_t errCode)
|
||||
{
|
||||
(void)errCode;
|
||||
CALL_INFO_TRACE;
|
||||
}
|
||||
|
||||
void JsDragManager::ReleaseReference()
|
||||
{
|
||||
for (auto item : thumbnailDrawCb_) {
|
||||
CHKPV(thumbnailDrawCb_);
|
||||
CHKPV(thumbnailDrawCb_->env);
|
||||
for (auto item : thumbnailDrawCb_->ref) {
|
||||
if (item != nullptr) {
|
||||
if (item->env != nullptr && item->ref != nullptr) {
|
||||
napi_delete_reference(item->env, item->ref);
|
||||
item->env = nullptr;
|
||||
item->ref = nullptr;
|
||||
if (napi_delete_reference(thumbnailDrawCb_->env, item) != napi_ok) {
|
||||
FI_HILOGE("Create reference failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
thumbnailDrawCb_->env = nullptr;
|
||||
thumbnailDrawCb_ = nullptr;
|
||||
}
|
||||
|
||||
void JsDragManager::RegisterThumbnailDraw(napi_env env, size_t argc, napi_value* argv)
|
||||
void JsDragManager::RegisterThumbnailDraw(napi_env env, napi_value* argv)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
if (thumbnailDrawCb_.empty()) {
|
||||
for (size_t i = 0; i < argc; ++i) {
|
||||
auto cb = new (std::nothrow) CallbackInfo();
|
||||
thumbnailDrawCb_.push_back(cb);
|
||||
}
|
||||
if (thumbnailDrawCb_ == nullptr) {
|
||||
thumbnailDrawCb_ = new (std::nothrow) ThumbnailDrawCb();
|
||||
CHKPV(thumbnailDrawCb_);
|
||||
}
|
||||
for (size_t i = 0; i < argc; ++i) {
|
||||
if (thumbnailDrawCb_[i] == nullptr) {
|
||||
thumbnailDrawCb_[i] = new (std::nothrow) CallbackInfo();
|
||||
thumbnailDrawCb_->env = env;
|
||||
for (size_t i = 0; i < 3; ++i) {
|
||||
if (thumbnailDrawCb_->ref[i] != nullptr) {
|
||||
if (napi_delete_reference(thumbnailDrawCb_->env, thumbnailDrawCb_->ref[i]) != napi_ok) {
|
||||
FI_HILOGE("Create reference failed");
|
||||
return;
|
||||
}
|
||||
thumbnailDrawCb_->ref[i] = nullptr;
|
||||
}
|
||||
CHKPV(thumbnailDrawCb_[i]);
|
||||
napi_ref ref = nullptr;
|
||||
if (napi_create_reference(env, argv[i], 1, &ref) != napi_ok) {
|
||||
ReleaseReference();
|
||||
FI_HILOGE("Create reference failed");
|
||||
return;
|
||||
}
|
||||
thumbnailDrawCb_[i]->env = env;
|
||||
thumbnailDrawCb_[i]->ref = ref;
|
||||
thumbnailDrawCb_->ref[i] = ref;
|
||||
}
|
||||
auto startCallback = std::bind(&JsDragManager::EmitStartThumbnailDraw, this,
|
||||
std::placeholders::_1, std::placeholders::_2);
|
||||
@ -152,17 +154,28 @@ void JsDragManager::RegisterThumbnailDraw(napi_env env, size_t argc, napi_value*
|
||||
}
|
||||
}
|
||||
|
||||
void JsDragManager::EmitUnregisterThumbnailDraw(int32_t errCode)
|
||||
{
|
||||
(void)errCode;
|
||||
}
|
||||
|
||||
void JsDragManager::UnregisterThumbnailDraw(napi_env env)
|
||||
void JsDragManager::EmitUnregisterThumbnailDraw(sptr<CallbackInfo> callbackInfo, int32_t errCode)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
}
|
||||
|
||||
void JsDragManager::UnregisterThumbnailDraw(napi_env env, napi_value argv)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
auto callback = std::bind(&JsDragManager::EmitUnregisterThumbnailDraw, this, std::placeholders::_1);
|
||||
InteractionMgr->UnregisterThumbnailDraw(callback);
|
||||
ReleaseReference();
|
||||
napi_ref ref = nullptr;
|
||||
if (napi_create_reference(env, argv, 1, &ref) != napi_ok) {
|
||||
FI_HILOGE("Create reference failed");
|
||||
return;
|
||||
}
|
||||
sptr<CallbackInfo> callbackInfo = new (std::nothrow) CallbackInfo();
|
||||
CHKPV(callbackInfo);
|
||||
callbackInfo->env = env;
|
||||
callbackInfo->ref = ref;
|
||||
auto callback = std::bind(&JsDragManager::EmitUnregisterThumbnailDraw, this, callbackInfo, std::placeholders::_1);
|
||||
if (InteractionMgr->UnregisterThumbnailDraw(callback) != RET_OK) {
|
||||
FI_HILOGE("Call Unregister thumbnail draw failed");
|
||||
}
|
||||
}
|
||||
|
||||
void JsDragManager::ResetEnv()
|
||||
|
@ -74,6 +74,7 @@ int32_t DragManagerImpl::RegisterThumbnailDraw(std::function<void(int32_t, int32
|
||||
std::function<void(int32_t, int32_t)> noticeCallback, std::function<void(int32_t)> endCallback)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
auto ret = DeviceStatusClient::GetInstance().RegisterThumbnailDraw();
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Register thumbnail draw failed");
|
||||
@ -89,14 +90,12 @@ int32_t DragManagerImpl::RegisterThumbnailDraw(std::function<void(int32_t, int32
|
||||
int32_t DragManagerImpl::UnregisterThumbnailDraw(std::function<void(int32_t)> callback)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
int32_t ret;
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
if (!hasRegisterThumbnailDraw_) {
|
||||
FI_HILOGE("Have not registered thumbnail draw");
|
||||
ret = RET_ERR;
|
||||
callback(ret);
|
||||
return RET_ERR;
|
||||
FI_HILOGI("have not registered");
|
||||
return RET_OK;
|
||||
}
|
||||
ret = DeviceStatusClient::GetInstance().UnregisterThumbnailDraw();
|
||||
auto ret = DeviceStatusClient::GetInstance().UnregisterThumbnailDraw();
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Unregister thumbnail draw failed");
|
||||
return ret;
|
||||
|
@ -129,9 +129,9 @@ public:
|
||||
|
||||
/**
|
||||
* @brief 注册阴影缩略图托管
|
||||
* @param startCallback 回调函数,用于在启动拖拽是调用
|
||||
* @param noticeCallback 回调函数,用于通知拖拽状态
|
||||
* @param endCallback 回调函数,用于就结束拖拽时调用
|
||||
* @param startCallback 回调函数,在启动拖拽时调用
|
||||
* @param noticeCallback 回调函数,拖拽状态变化时调用
|
||||
* @param endCallback 回调函数,结束拖拽时调用
|
||||
* @return 返回值如果是0表示接口调用成功,返回其他值表示接口调用失败。
|
||||
* @since 10
|
||||
*/
|
||||
|
@ -376,7 +376,6 @@ int32_t DeviceStatusSrvProxy::RegisterThumbnailDraw()
|
||||
int32_t ret = remote->SendRequest(REGISTER_THUMBNAIL_DRAW, data, reply, option);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Send request fail, ret:%{public}d", ret);
|
||||
return RET_ERR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-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
|
||||
|
Loading…
x
Reference in New Issue
Block a user