From 427b802ac362471a417810ee8bd520e51b9a0ae4 Mon Sep 17 00:00:00 2001 From: pwx1285814 Date: Sat, 29 Jun 2024 17:50:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E6=94=B9=E7=BB=95=E8=BF=87CFI?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: pwx1285814 --- .../callback/dscreen_source_callback_stub.h | 6 +-- .../callback/dscreen_source_callback_stub.cpp | 22 +++++----- .../include/dscreen_sink_stub.h | 6 +-- .../dscreenservice/src/dscreen_sink_stub.cpp | 36 ++++++++--------- .../dscreenmgr/1.0/src/dscreen.cpp | 4 +- .../dscreenmgr/2.0/src/dscreen.cpp | 2 +- .../include/dscreen_source_stub.h | 5 +-- .../src/dscreen_source_stub.cpp | 40 +++++++++---------- .../decoder/src/image_sink_decoder.cpp | 2 +- .../src/screen_source_trans.cpp | 4 +- 10 files changed, 53 insertions(+), 74 deletions(-) diff --git a/interfaces/innerkits/native_cpp/screen_source/include/callback/dscreen_source_callback_stub.h b/interfaces/innerkits/native_cpp/screen_source/include/callback/dscreen_source_callback_stub.h index 434ad916..8f140590 100644 --- a/interfaces/innerkits/native_cpp/screen_source/include/callback/dscreen_source_callback_stub.h +++ b/interfaces/innerkits/native_cpp/screen_source/include/callback/dscreen_source_callback_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -35,10 +35,6 @@ public: int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; private: - using DScreenFunc = int32_t (DScreenSourceCallbackStub::*)(MessageParcel &data, MessageParcel &reply, - MessageOption &option); - std::map memberFuncMap_; - int32_t OnNotifyRegResultInner(MessageParcel &data, MessageParcel &reply, MessageOption &option); int32_t OnNotifyUnregResultInner(MessageParcel &data, MessageParcel &reply, diff --git a/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback_stub.cpp b/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback_stub.cpp index 8d75dca8..3b581a94 100644 --- a/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback_stub.cpp +++ b/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -28,11 +28,7 @@ namespace OHOS { class MessageOption; } namespace OHOS { namespace DistributedHardware { -DScreenSourceCallbackStub::DScreenSourceCallbackStub() -{ - memberFuncMap_[NOTIFY_REG_RESULT] = &DScreenSourceCallbackStub::OnNotifyRegResultInner; - memberFuncMap_[NOTIFY_UNREG_RESULT] = &DScreenSourceCallbackStub::OnNotifyUnregResultInner; -} +DScreenSourceCallbackStub::DScreenSourceCallbackStub() {} int32_t DScreenSourceCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -44,13 +40,15 @@ int32_t DScreenSourceCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel return ERR_INVALID_DATA; } - std::map::iterator iter = memberFuncMap_.find(code); - if (iter == memberFuncMap_.end()) { - DHLOGE("invalid request code."); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + switch (code) { + case NOTIFY_REG_RESULT: + return OnNotifyRegResultInner(data, reply, option); + case NOTIFY_UNREG_RESULT: + return OnNotifyUnregResultInner(data, reply, option); + default: + DHLOGE("invalid request code."); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } - DScreenFunc &func = iter->second; - return (this->*func)(data, reply, option); } int32_t DScreenSourceCallbackStub::OnNotifyRegResultInner(MessageParcel &data, MessageParcel &reply, diff --git a/services/screenservice/sinkservice/dscreenservice/include/dscreen_sink_stub.h b/services/screenservice/sinkservice/dscreenservice/include/dscreen_sink_stub.h index 0259ebd8..076ca346 100644 --- a/services/screenservice/sinkservice/dscreenservice/include/dscreen_sink_stub.h +++ b/services/screenservice/sinkservice/dscreenservice/include/dscreen_sink_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -31,10 +31,6 @@ public: int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; private: - using DScreenSinkFunc = int32_t (DScreenSinkStub::*)(MessageParcel &data, MessageParcel &reply, - MessageOption &option); - std::map memberFuncMap_; - int32_t InitSinkInner(MessageParcel &data, MessageParcel &reply, MessageOption &option); int32_t ReleaseSinkInner(MessageParcel &data, MessageParcel &reply, diff --git a/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_stub.cpp b/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_stub.cpp index d71c57f4..9b3875c2 100644 --- a/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_stub.cpp +++ b/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -24,19 +24,7 @@ namespace OHOS { namespace DistributedHardware { -DScreenSinkStub::DScreenSinkStub() -{ - memberFuncMap_[static_cast(IDScreenSinkInterfaceCode::INIT_SINK)] = - &DScreenSinkStub::InitSinkInner; - memberFuncMap_[static_cast(IDScreenSinkInterfaceCode::RELEASE_SINK)] = - &DScreenSinkStub::ReleaseSinkInner; - memberFuncMap_[static_cast(IDScreenSinkInterfaceCode::SUBSCRIBE_DISTRIBUTED_HARDWARE)] = - &DScreenSinkStub::SubscribeDistributedHardwareInner; - memberFuncMap_[static_cast(IDScreenSinkInterfaceCode::UNSUBSCRIBE_DISTRIBUTED_HARDWARE)] = - &DScreenSinkStub::UnsubscribeDistributedHardwareInner; - memberFuncMap_[static_cast(IDScreenSinkInterfaceCode::DSCREEN_NOTIFY)] = - &DScreenSinkStub::DScreenNotifyInner; -} +DScreenSinkStub::DScreenSinkStub() {} bool DScreenSinkStub::HasEnableDHPermission() { @@ -57,13 +45,21 @@ int32_t DScreenSinkStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mes return ERR_INVALID_DATA; } - const auto &iter = memberFuncMap_.find(code); - if (iter == memberFuncMap_.end()) { - DHLOGE("invalid request code."); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + switch (static_cast(code)) { + case IDScreenSinkInterfaceCode::INIT_SINK: + return InitSinkInner(data, reply, option); + case IDScreenSinkInterfaceCode::RELEASE_SINK: + return ReleaseSinkInner(data, reply, option); + case IDScreenSinkInterfaceCode::SUBSCRIBE_DISTRIBUTED_HARDWARE: + return SubscribeDistributedHardwareInner(data, reply, option); + case IDScreenSinkInterfaceCode::UNSUBSCRIBE_DISTRIBUTED_HARDWARE: + return UnsubscribeDistributedHardwareInner(data, reply, option); + case IDScreenSinkInterfaceCode::DSCREEN_NOTIFY: + return DScreenNotifyInner(data, reply, option); + default: + DHLOGE("invalid request code."); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } - DScreenSinkFunc &func = iter->second; - return (this->*func)(data, reply, option); } int32_t DScreenSinkStub::InitSinkInner(MessageParcel &data, MessageParcel &reply, diff --git a/services/screenservice/sourceservice/dscreenmgr/1.0/src/dscreen.cpp b/services/screenservice/sourceservice/dscreenmgr/1.0/src/dscreen.cpp index 1d60a789..e8e054ea 100644 --- a/services/screenservice/sourceservice/dscreenmgr/1.0/src/dscreen.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/1.0/src/dscreen.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -42,7 +42,7 @@ DScreen::DScreen(const std::string &devId, const std::string &dhId, dscreenCallback_ = dscreenCallback; SetState(DISABLED); taskThreadRunning_ = true; - taskQueueThread_ = std::thread(&DScreen::TaskThreadLoop, this); + taskQueueThread_ = std::thread([this] { this->TaskThreadLoop(); }); } DScreen::~DScreen() diff --git a/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen.cpp b/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen.cpp index 75ca33a0..72f3ef05 100644 --- a/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen.cpp @@ -55,7 +55,7 @@ DScreen::DScreen(const std::string &devId, const std::string &dhId, SetState(DISABLED); taskThreadRunning_ = true; watchdogFlag_ = false; - taskQueueThread_ = std::thread(&DScreen::TaskThreadLoop, this); + taskQueueThread_ = std::thread([this] { this->TaskThreadLoop(); }); auto taskFunc = [this]() { if (watchdogFlag_) { watchdogFlag_ = false; diff --git a/services/screenservice/sourceservice/dscreenservice/include/dscreen_source_stub.h b/services/screenservice/sourceservice/dscreenservice/include/dscreen_source_stub.h index 2c0f1ebb..ee868a3d 100644 --- a/services/screenservice/sourceservice/dscreenservice/include/dscreen_source_stub.h +++ b/services/screenservice/sourceservice/dscreenservice/include/dscreen_source_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -48,9 +48,6 @@ private: bool CheckConfigParams(const std::string &devId, const std::string &dhId, const std::string &key, const std::string &value) const; bool HasEnableDHPermission(); - using DScreenSourceFunc = int32_t (DScreenSourceStub::*)(MessageParcel &data, MessageParcel &reply, - MessageOption &option); - std::map memberFuncMap_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_stub.cpp b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_stub.cpp index dc37785b..06558a15 100644 --- a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_stub.cpp +++ b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -27,21 +27,7 @@ namespace OHOS { namespace DistributedHardware { -DScreenSourceStub::DScreenSourceStub() -{ - memberFuncMap_[static_cast(IDScreenSourceInterfaceCode::INIT_SOURCE)] = - &DScreenSourceStub::InitSourceInner; - memberFuncMap_[static_cast(IDScreenSourceInterfaceCode::RELEASE_SOURCE)] = - &DScreenSourceStub::ReleaseSourceInner; - memberFuncMap_[static_cast(IDScreenSourceInterfaceCode::REGISTER_DISTRIBUTED_HARDWARE)] = - &DScreenSourceStub::RegisterDistributedHardwareInner; - memberFuncMap_[static_cast(IDScreenSourceInterfaceCode::UNREGISTER_DISTRIBUTED_HARDWARE)] = - &DScreenSourceStub::UnregisterDistributedHardwareInner; - memberFuncMap_[static_cast(IDScreenSourceInterfaceCode::CONFIG_DISTRIBUTED_HARDWARE)] = - &DScreenSourceStub::ConfigDistributedHardwareInner; - memberFuncMap_[static_cast(IDScreenSourceInterfaceCode::DSCREEN_NOTIFY)] = - &DScreenSourceStub::DScreenNotifyInner; -} +DScreenSourceStub::DScreenSourceStub() {} bool DScreenSourceStub::HasEnableDHPermission() { @@ -62,13 +48,23 @@ int32_t DScreenSourceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M return ERR_INVALID_DATA; } - std::map::iterator iter = memberFuncMap_.find(code); - if (iter == memberFuncMap_.end()) { - DHLOGE("invalid request code."); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + switch (static_cast(code)) { + case IDScreenSourceInterfaceCode::INIT_SOURCE: + return InitSourceInner(data, reply, option); + case IDScreenSourceInterfaceCode::RELEASE_SOURCE: + return ReleaseSourceInner(data, reply, option); + case IDScreenSourceInterfaceCode::REGISTER_DISTRIBUTED_HARDWARE: + return RegisterDistributedHardwareInner(data, reply, option); + case IDScreenSourceInterfaceCode::UNREGISTER_DISTRIBUTED_HARDWARE: + return UnregisterDistributedHardwareInner(data, reply, option); + case IDScreenSourceInterfaceCode::CONFIG_DISTRIBUTED_HARDWARE: + return ConfigDistributedHardwareInner(data, reply, option); + case IDScreenSourceInterfaceCode::DSCREEN_NOTIFY: + return DScreenNotifyInner(data, reply, option); + default: + DHLOGE("invalid request code."); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } - DScreenSourceFunc &func = iter->second; - return (this->*func)(data, reply, option); } int32_t DScreenSourceStub::InitSourceInner(MessageParcel &data, MessageParcel &reply, diff --git a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp index 1f15ec41..88213a5e 100644 --- a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp +++ b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp @@ -448,7 +448,7 @@ int32_t ImageSinkDecoder::StartInputThread() { DHLOGI("%{public}s: StartInputThread.", DSCREEN_LOG_TAG); isDecoderReady_ = true; - decodeThread_ = std::thread(&ImageSinkDecoder::DecodeScreenData, this); + decodeThread_ = std::thread([this] { this->DecodeScreenData(); }); return DH_SUCCESS; } diff --git a/services/screentransport/screensourcetrans/src/screen_source_trans.cpp b/services/screentransport/screensourcetrans/src/screen_source_trans.cpp index 566d7852..5fe9e2a5 100644 --- a/services/screentransport/screensourcetrans/src/screen_source_trans.cpp +++ b/services/screentransport/screensourcetrans/src/screen_source_trans.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -342,7 +342,7 @@ void ScreenSourceTrans::OnSessionOpened() isChannelReady_ = true; DHLOGI("%{public}s: Start thread.", DSCREEN_LOG_TAG); - std::thread(&ScreenSourceTrans::FeedChannelData, this).detach(); + std::thread([this] { this->FeedChannelData(); }).detach(); std::unique_lock lck(sessionMtx_); sessionCond_.notify_all(); } -- Gitee