From 325adc1d9cd625107e59e00d46569200b0019647 Mon Sep 17 00:00:00 2001 From: AOL Date: Thu, 16 Sep 2021 13:12:09 +0000 Subject: [PATCH 1/8] fix image load library error Signed-off-by: magekkkk --- frameworks/innerkitsimpl/pixelconverter/BUILD.gn | 3 ++- plugins/manager/BUILD.gn | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frameworks/innerkitsimpl/pixelconverter/BUILD.gn b/frameworks/innerkitsimpl/pixelconverter/BUILD.gn index 2389606bb..9f5bf5b23 100644 --- a/frameworks/innerkitsimpl/pixelconverter/BUILD.gn +++ b/frameworks/innerkitsimpl/pixelconverter/BUILD.gn @@ -146,7 +146,8 @@ ohos_shared_library("pixelconvertadapter") { external_deps = [ "hiviewdfx_hilog_native:libhilog" ] } - relative_install_dir = "module/multimedia" + + #relative_install_dir = "module/multimedia" subsystem_name = "multimedia" part_name = "multimedia_image_standard" } diff --git a/plugins/manager/BUILD.gn b/plugins/manager/BUILD.gn index b5b004090..11223d876 100644 --- a/plugins/manager/BUILD.gn +++ b/plugins/manager/BUILD.gn @@ -76,7 +76,8 @@ ohos_shared_library("pluginmanager") { external_deps = [ "hiviewdfx_hilog_native:libhilog" ] } - relative_install_dir = "module/multimedia" + + #relative_install_dir = "module/multimedia" subsystem_name = "multimedia" part_name = "multimedia_image_standard" } -- Gitee From 401ace08a7fef4e230f85d38612ded2ef1960a61 Mon Sep 17 00:00:00 2001 From: caochuan Date: Thu, 23 Sep 2021 14:33:00 +0800 Subject: [PATCH 2/8] Fix validation issues Signed-off-by: caochuan --- .../innerkitsimpl/converter/include/matrix.h | 2 +- .../kits/js/common/include/image_napi_utils.h | 9 ++++--- interfaces/innerkits/include/media_errors.h | 1 - .../js/common/include/image_source_napi.h | 7 +++--- .../kits/js/common/include/pixel_map_napi.h | 8 +++---- .../kits/native/include/image_pixel_map.h | 9 ------- mock/native/include/nocopyable.h | 17 +++++++++---- mock/native/include/refbase.h | 2 +- mock/native/include/rwlock.h | 4 ++-- mock/native/include/singleton.h | 17 +++++++++---- .../formatagentplugin/src/plugin_export.cpp | 2 +- .../image/libgifplugin/src/plugin_export.cpp | 2 +- .../image/libheifplugin/src/plugin_export.cpp | 2 +- .../image/libjpegplugin/src/plugin_export.cpp | 2 +- .../image/libpngplugin/src/plugin_export.cpp | 2 +- .../image/libwebpplugin/src/plugin_export.cpp | 2 +- .../manager/include/image/input_data_stream.h | 18 ++++++++++---- plugins/manager/include/plugin_service.h | 8 ++----- .../manager/include/pluginbase/plugin_utils.h | 24 ------------------- .../plugin_example2/plugin_export.cpp | 2 +- .../plugin_example3/plugin_export.cpp | 2 +- 21 files changed, 62 insertions(+), 80 deletions(-) diff --git a/frameworks/innerkitsimpl/converter/include/matrix.h b/frameworks/innerkitsimpl/converter/include/matrix.h index 7545c4c4c..f06b60835 100644 --- a/frameworks/innerkitsimpl/converter/include/matrix.h +++ b/frameworks/innerkitsimpl/converter/include/matrix.h @@ -108,7 +108,7 @@ public: constexpr Matrix(float sx, float kx, float tx, float ky, float sy, float ty, float p0, float p1, float p2, uint32_t operType) - : fMat_{ sx, kx, tx, ky, sy, ty, p0, p1, p2 }, operType_(operType){}; + : fMat_ { sx, kx, tx, ky, sy, ty, p0, p1, p2 }, operType_(operType){}; ~Matrix() = default; diff --git a/frameworks/kits/js/common/include/image_napi_utils.h b/frameworks/kits/js/common/include/image_napi_utils.h index f5d8e062f..f692d8d5a 100644 --- a/frameworks/kits/js/common/include/image_napi_utils.h +++ b/frameworks/kits/js/common/include/image_napi_utils.h @@ -26,7 +26,7 @@ #define IMG_NAPI_CHECK_RET_D(x, res, msg) \ do \ { \ - if(!(x)) \ + if (!(x)) \ { \ msg; \ return (res); \ @@ -36,7 +36,7 @@ do \ #define IMG_NAPI_CHECK_RET(x, res) \ do \ { \ - if(!(x)) \ + if (!(x)) \ { \ return (res); \ } \ @@ -69,7 +69,7 @@ do \ } \ } while (0) -#define IMG_ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0])) +#define IMG_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) #define GET_BUFFER_BY_NAME(root, name, res, len) ImageNapiUtils::GetBufferByName(env, (root), (name), &(res), &(len)) #define GET_UINT32_BY_NAME(root, name, res) ImageNapiUtils::GetUint32ByName(env, (root), (name), &(res)) @@ -82,7 +82,6 @@ do \ namespace OHOS { namespace Media { - class ImageNapiUtils { public: static bool GetBufferByName(napi_env env, napi_value root, const char* name, void **res, size_t* len); @@ -94,4 +93,4 @@ public: }; } // namespace Media } // namespace OHOS -#endif // IMAGE_NAPI_UTILS_H \ No newline at end of file +#endif // IMAGE_NAPI_UTILS_H diff --git a/interfaces/innerkits/include/media_errors.h b/interfaces/innerkits/include/media_errors.h index 1699dc731..6cb2a1eeb 100644 --- a/interfaces/innerkits/include/media_errors.h +++ b/interfaces/innerkits/include/media_errors.h @@ -109,7 +109,6 @@ const int32_t ERR_MEDIA_NUMBER_OVERFLOW = BASE_MEDIA_ERR_OFFSET + 73; const int32_t ERR_MEDIA_DIS_PLAYER_UNSUPPORTED = BASE_MEDIA_ERR_OFFSET + 74; // media distribute player unsupporteded const int32_t ERR_MEDIA_UNKNOWN = BASE_MEDIA_ERR_OFFSET + 200; // media unknown error - } // namespace Media } // namespace OHOS #endif // MEDIA_ERRORS_H diff --git a/interfaces/kits/js/common/include/image_source_napi.h b/interfaces/kits/js/common/include/image_source_napi.h index 561ea5143..8f522dad4 100644 --- a/interfaces/kits/js/common/include/image_source_napi.h +++ b/interfaces/kits/js/common/include/image_source_napi.h @@ -35,14 +35,14 @@ private: static napi_value Constructor(napi_env env, napi_callback_info info); static void Destructor(napi_env env, void *nativeObject, void *finalize); - //readonly property + // readonly property static napi_value GetSupportedFormats(napi_env env, napi_callback_info info); - //static methods + // static methods static napi_value CreateImageSource(napi_env env, napi_callback_info info); static napi_value CreateIncrementalSource(napi_env env, napi_callback_info info); - //methods + // methods static napi_value GetImageInfo(napi_env env, napi_callback_info info); static napi_value CreatePixelMap(napi_env env, napi_callback_info info); static napi_value GetImagePropertyInt(napi_env env, napi_callback_info info); @@ -58,7 +58,6 @@ private: std::shared_ptr nativeImgSrc = nullptr; bool isRelease = false; }; - } // namespace Media } // namespace OHOS #endif /* PIXEL_MAP_NAPI_H_ */ diff --git a/interfaces/kits/js/common/include/pixel_map_napi.h b/interfaces/kits/js/common/include/pixel_map_napi.h index 065fe38ea..3764f4b54 100644 --- a/interfaces/kits/js/common/include/pixel_map_napi.h +++ b/interfaces/kits/js/common/include/pixel_map_napi.h @@ -38,14 +38,14 @@ private: static napi_value Constructor(napi_env env, napi_callback_info info); static void Destructor(napi_env env, void *nativeObject, void *finalize); - //readonly property + // readonly property static napi_value GetIsEditable(napi_env env, napi_callback_info info); - //static mothod + // static mothod static napi_value CreatePixelMap(napi_env env, napi_callback_info info); static void CreatePixelMapComplete(napi_env env, napi_status status, void *data); - //methods + // methods static napi_value ReadPixelsToBuffer(napi_env env, napi_callback_info info); static napi_value ReadPixels(napi_env env, napi_callback_info info); static napi_value WritePixels(napi_env env, napi_callback_info info); @@ -56,7 +56,6 @@ private: static napi_value getPixelBytesCount(napi_env env, napi_callback_info info); static napi_value Release(napi_env env, napi_callback_info info); - static napi_ref sConstructor_; static std::shared_ptr sPixelMap_; @@ -65,7 +64,6 @@ private: std::shared_ptr nativePixelMap_; bool isRelease = false; }; - } // namespace Media } // namespace OHOS #endif /* PIXEL_MAP_NAPI_H_ */ diff --git a/interfaces/kits/native/include/image_pixel_map.h b/interfaces/kits/native/include/image_pixel_map.h index 9dd564c6a..2b2b50277 100644 --- a/interfaces/kits/native/include/image_pixel_map.h +++ b/interfaces/kits/native/include/image_pixel_map.h @@ -117,9 +117,6 @@ struct OhosPixelMapInfo { * @since 3 * @version 1.0 */ -/* -int32_t GetImageInfo(JNIEnv *env, jobject pixelMapObject, OhosPixelMapInfo &info); -*/ /** * @brief Obtains the memory address of a given PixelMap object and locks the memory. * @@ -136,9 +133,6 @@ int32_t GetImageInfo(JNIEnv *env, jobject pixelMapObject, OhosPixelMapInfo &info * @since 3 * @version 1.0 */ -/* -int32_t AccessPixels(JNIEnv *env, jobject pixelMapObject, void **addrPtr); -*/ /** * @brief Unlocks the memory storing the pixel data of a given PixelMap to balance a successful call to {@link * AccessPixels}. @@ -151,9 +145,6 @@ int32_t AccessPixels(JNIEnv *env, jobject pixelMapObject, void **addrPtr); * @since 3 * @version 1.0 */ -/* -int32_t UnAccessPixels(JNIEnv *env, jobject pixelMapObject); -*/ #ifdef __cplusplus }; diff --git a/mock/native/include/nocopyable.h b/mock/native/include/nocopyable.h index 383f8199b..2b046ab45 100644 --- a/mock/native/include/nocopyable.h +++ b/mock/native/include/nocopyable.h @@ -17,16 +17,25 @@ #define UTILS_BASE_NOCOPYABLE_H namespace OHOS { #define DISALLOW_COPY_AND_MOVE(className) \ +do \ +{ \ DISALLOW_COPY(className); \ - DISALLOW_MOVE(className) + DISALLOW_MOVE(className); \ +} while (0) #define DISALLOW_COPY(className) \ +do \ +{ \ className(const className&) = delete; \ - className& operator= (const className&) = delete + className& operator= (const className&) = delete; \ +} while (0) #define DISALLOW_MOVE(className) \ +do \ +{ \ className(className&&) = delete; \ - className& operator= (className&&) = delete + className& operator= (className&&) = delete; \ +} while (0) class NoCopyable { protected: NoCopyable() {}; @@ -36,4 +45,4 @@ private: DISALLOW_COPY_AND_MOVE(NoCopyable); }; } // namespace OHOS -#endif \ No newline at end of file +#endif diff --git a/mock/native/include/refbase.h b/mock/native/include/refbase.h index 69426221a..57e1b0d54 100644 --- a/mock/native/include/refbase.h +++ b/mock/native/include/refbase.h @@ -389,7 +389,7 @@ inline sptr::~sptr() } template -inline sptr::sptr(WeakRefCounter *p, bool /* force */) +inline sptr::sptr(WeakRefCounter *p, bool/* force */) { if ((p != nullptr) && p->AttemptIncStrongRef(this)) { refs_ = reinterpret_cast(p->GetRefPtr()); diff --git a/mock/native/include/rwlock.h b/mock/native/include/rwlock.h index 3a9f1f9af..21e6cc3bd 100644 --- a/mock/native/include/rwlock.h +++ b/mock/native/include/rwlock.h @@ -52,7 +52,7 @@ private: std::atomic_uint writeWaitCount_; }; -template +template class UniqueWriteGuard : NoCopyable { public: explicit UniqueWriteGuard(RWLockable &rwLockable) @@ -74,7 +74,7 @@ private: }; -template +template class UniqueReadGuard : NoCopyable { public: explicit UniqueReadGuard(RWLockable &rwLockable) diff --git a/mock/native/include/singleton.h b/mock/native/include/singleton.h index 5662fcfdc..4d35a997d 100644 --- a/mock/native/include/singleton.h +++ b/mock/native/include/singleton.h @@ -22,27 +22,34 @@ namespace OHOS { #define DECLARE_DELAYED_SINGLETON(MyClass) \ +do \ +{ \ public: \ ~MyClass(); \ private: \ friend DelayedSingleton; \ - MyClass(); + MyClass(); \ +} while (0) #define DECLARE_DELAYED_REF_SINGLETON(MyClass) \ +do \ +{ \ private: \ friend DelayedRefSingleton; \ ~MyClass(); \ - MyClass(); - + MyClass(); \ +} while (0) #define DECLARE_SINGLETON(MyClass) \ +do \ +{ \ private: \ friend Singleton; \ MyClass& operator=(const MyClass&) = delete; \ MyClass(const MyClass&) = delete; \ MyClass(); \ - ~MyClass(); - + ~MyClass(); \ +} while (0) template class DelayedSingleton : public NoCopyable { diff --git a/plugins/common/libs/image/formatagentplugin/src/plugin_export.cpp b/plugins/common/libs/image/formatagentplugin/src/plugin_export.cpp index 63d32f2e6..9b8071909 100644 --- a/plugins/common/libs/image/formatagentplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/formatagentplugin/src/plugin_export.cpp @@ -51,4 +51,4 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibIm // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() diff --git a/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp b/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp index a34d5407c..549b117b5 100644 --- a/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp @@ -37,4 +37,4 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibGi // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() diff --git a/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp b/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp index 7173d27ab..9e32a2164 100644 --- a/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp @@ -37,4 +37,4 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibHe // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() diff --git a/plugins/common/libs/image/libjpegplugin/src/plugin_export.cpp b/plugins/common/libs/image/libjpegplugin/src/plugin_export.cpp index 9677c35b7..bac59e55e 100644 --- a/plugins/common/libs/image/libjpegplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libjpegplugin/src/plugin_export.cpp @@ -41,4 +41,4 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibJp // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() diff --git a/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp b/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp index ed1f7697e..d9409b280 100644 --- a/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp @@ -37,4 +37,4 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibPn // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() diff --git a/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp b/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp index d1b81c859..571590925 100644 --- a/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp @@ -37,4 +37,4 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibWe // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() diff --git a/plugins/manager/include/image/input_data_stream.h b/plugins/manager/include/image/input_data_stream.h index a2f6f514e..398d48a3e 100644 --- a/plugins/manager/include/image/input_data_stream.h +++ b/plugins/manager/include/image/input_data_stream.h @@ -59,20 +59,28 @@ public: virtual bool Seek(uint32_t position) = 0; // get inherited class type - virtual uint32_t GetStreamType() { return -1; } + virtual uint32_t GetStreamType() { + return -1; + } // get raw pointer for BUFFER TYPE - virtual uint8_t *GetDataPtr() { return nullptr; } + virtual uint8_t *GetDataPtr() { + return nullptr; + } // whether the stream data is completed or not. - virtual bool IsStreamCompleted() { return true; } + virtual bool IsStreamCompleted() { + return true; + } // get stream size - virtual size_t GetStreamSize() { return 0; } + virtual size_t GetStreamSize() { + return 0; + } virtual ~InputDataStream() {} }; } // namespace ImagePlugin } // namespace OHOS -#endif // INPUT_DATA_STREAM_H \ No newline at end of file +#endif // INPUT_DATA_STREAM_H diff --git a/plugins/manager/include/plugin_service.h b/plugins/manager/include/plugin_service.h index d17422738..ea6113cb0 100644 --- a/plugins/manager/include/plugin_service.h +++ b/plugins/manager/include/plugin_service.h @@ -46,12 +46,8 @@ template inline uint16_t GetInterfaceId() return INVALID_IID; } -#define DECLARE_INTERFACE(InterfaceType, interfaceID) \ - template <> \ - inline uint16_t OHOS::MultimediaPlugin::GetInterfaceId() \ - { \ - return interfaceID; \ - } +#define DECLARE_INTERFACE(InterfaceType, interfaceID) template <> inline uint16_t OHOS::MultimediaPlugin::GetInterfaceId() { return interfaceID; } + } // namespace MultimediaPlugin } // namespace OHOS diff --git a/plugins/manager/include/pluginbase/plugin_utils.h b/plugins/manager/include/pluginbase/plugin_utils.h index 75cd73114..790d3bcb1 100644 --- a/plugins/manager/include/pluginbase/plugin_utils.h +++ b/plugins/manager/include/pluginbase/plugin_utils.h @@ -63,28 +63,4 @@ void PluginExternalStop() \ PLUGIN_LOG_D("call PluginExternalStop() in package: %{public}s.", PACKAGE_NAME.c_str()); \ return; \ } - -#define PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() \ -OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const std::string &className) \ -{ \ - PLUGIN_LOG_D("PluginExternalCreate: create object for package: %{public}s, class: %{public}s.", \ - PACKAGE_NAME.c_str(), className.c_str()); \ - \ - auto iter = implClassMap.find(className); \ - if (iter == implClassMap.end()) { \ - PLUGIN_LOG_E("PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.", \ - className.c_str(), PACKAGE_NAME.c_str()); \ - return nullptr; \ - } \ - \ - auto creator = iter->second; \ - if (creator == nullptr) { \ - PLUGIN_LOG_E("PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.", \ - className.c_str(), PACKAGE_NAME.c_str()); \ - return nullptr; \ - } \ - \ - return creator(); \ -} - #endif // PLUGIN_UTILS_H diff --git a/plugins/manager/test/unittest/common/plugin_example/plugin_example2/plugin_export.cpp b/plugins/manager/test/unittest/common/plugin_example/plugin_example2/plugin_export.cpp index 2e6110112..761ae7c4d 100644 --- a/plugins/manager/test/unittest/common/plugin_example/plugin_example2/plugin_export.cpp +++ b/plugins/manager/test/unittest/common/plugin_example/plugin_example2/plugin_export.cpp @@ -40,5 +40,5 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "plugi // define the external interface of this plugin PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() diff --git a/plugins/manager/test/unittest/common/plugin_example/plugin_example3/plugin_export.cpp b/plugins/manager/test/unittest/common/plugin_example/plugin_example3/plugin_export.cpp index db149a35b..0205a53f3 100644 --- a/plugins/manager/test/unittest/common/plugin_example/plugin_example3/plugin_export.cpp +++ b/plugins/manager/test/unittest/common/plugin_example/plugin_example3/plugin_export.cpp @@ -40,5 +40,5 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "plugi // define the external interface of this plugin PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() -- Gitee From 3a94b3617bfb7b967bdbcd159b5db57869753d07 Mon Sep 17 00:00:00 2001 From: caochuan Date: Fri, 24 Sep 2021 09:17:59 +0800 Subject: [PATCH 3/8] Fix code check issue Signed-off-by: caochuan --- mock/native/include/refbase.h | 2 +- plugins/manager/include/image/input_data_stream.h | 8 ++++---- plugins/manager/include/plugin_service.h | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/mock/native/include/refbase.h b/mock/native/include/refbase.h index 57e1b0d54..ea1a03235 100644 --- a/mock/native/include/refbase.h +++ b/mock/native/include/refbase.h @@ -389,7 +389,7 @@ inline sptr::~sptr() } template -inline sptr::sptr(WeakRefCounter *p, bool/* force */) +inline sptr::sptr(WeakRefCounter *p, bool) { if ((p != nullptr) && p->AttemptIncStrongRef(this)) { refs_ = reinterpret_cast(p->GetRefPtr()); diff --git a/plugins/manager/include/image/input_data_stream.h b/plugins/manager/include/image/input_data_stream.h index 398d48a3e..0a1bccd40 100644 --- a/plugins/manager/include/image/input_data_stream.h +++ b/plugins/manager/include/image/input_data_stream.h @@ -60,22 +60,22 @@ public: // get inherited class type virtual uint32_t GetStreamType() { - return -1; + return -1; } // get raw pointer for BUFFER TYPE virtual uint8_t *GetDataPtr() { - return nullptr; + return nullptr; } // whether the stream data is completed or not. virtual bool IsStreamCompleted() { - return true; + return true; } // get stream size virtual size_t GetStreamSize() { - return 0; + return 0; } virtual ~InputDataStream() {} diff --git a/plugins/manager/include/plugin_service.h b/plugins/manager/include/plugin_service.h index ea6113cb0..1ac4cf5ba 100644 --- a/plugins/manager/include/plugin_service.h +++ b/plugins/manager/include/plugin_service.h @@ -46,8 +46,7 @@ template inline uint16_t GetInterfaceId() return INVALID_IID; } -#define DECLARE_INTERFACE(InterfaceType, interfaceID) template <> inline uint16_t OHOS::MultimediaPlugin::GetInterfaceId() { return interfaceID; } - +#define DECLARE_INTERFACE(InterfaceType, interfaceID) template<> inline uint16_t OHOS::MultimediaPlugin::GetInterfaceId() { return interfaceID; } } // namespace MultimediaPlugin } // namespace OHOS -- Gitee From 947133b03e82d1326b07be3265e4a922e0410c00 Mon Sep 17 00:00:00 2001 From: caochuan Date: Fri, 24 Sep 2021 11:08:25 +0800 Subject: [PATCH 4/8] Fix code validation issues Signed-off-by: caochuan --- .../manager/include/image/input_data_stream.h | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/plugins/manager/include/image/input_data_stream.h b/plugins/manager/include/image/input_data_stream.h index 0a1bccd40..6e4cc61b1 100644 --- a/plugins/manager/include/image/input_data_stream.h +++ b/plugins/manager/include/image/input_data_stream.h @@ -59,23 +59,27 @@ public: virtual bool Seek(uint32_t position) = 0; // get inherited class type - virtual uint32_t GetStreamType() { - return -1; + virtual uint32_t GetStreamType() + { + return -1; } // get raw pointer for BUFFER TYPE - virtual uint8_t *GetDataPtr() { - return nullptr; + virtual uint8_t *GetDataPtr() + { + return nullptr; } // whether the stream data is completed or not. - virtual bool IsStreamCompleted() { - return true; + virtual bool IsStreamCompleted() + { + return true; } // get stream size - virtual size_t GetStreamSize() { - return 0; + virtual size_t GetStreamSize() + { + return 0; } virtual ~InputDataStream() {} -- Gitee From 1016c51c562e2029112adda91e9bce3311c2ee60 Mon Sep 17 00:00:00 2001 From: caochuan Date: Fri, 24 Sep 2021 13:38:22 +0800 Subject: [PATCH 5/8] Fix code validation issues Signed-off-by: caochuan --- mock/native/include/nocopyable.h | 4 ++-- plugins/manager/include/plugin_service.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mock/native/include/nocopyable.h b/mock/native/include/nocopyable.h index 2b046ab45..060a872d2 100644 --- a/mock/native/include/nocopyable.h +++ b/mock/native/include/nocopyable.h @@ -27,14 +27,14 @@ do \ do \ { \ className(const className&) = delete; \ - className& operator= (const className&) = delete; \ + (className)& operator= (const className&) = delete; \ } while (0) #define DISALLOW_MOVE(className) \ do \ { \ className(className&&) = delete; \ - className& operator= (className&&) = delete; \ + (className)& operator= (className&&) = delete; \ } while (0) class NoCopyable { protected: diff --git a/plugins/manager/include/plugin_service.h b/plugins/manager/include/plugin_service.h index 1ac4cf5ba..768c80d4f 100644 --- a/plugins/manager/include/plugin_service.h +++ b/plugins/manager/include/plugin_service.h @@ -46,7 +46,7 @@ template inline uint16_t GetInterfaceId() return INVALID_IID; } -#define DECLARE_INTERFACE(InterfaceType, interfaceID) template<> inline uint16_t OHOS::MultimediaPlugin::GetInterfaceId() { return interfaceID; } +#define DECLARE_INTERFACE(InterfaceType, interfaceID) template<> inline uint16_t OHOS::MultimediaPlugin::GetInterfaceId() { return interfaceID; } } // namespace MultimediaPlugin } // namespace OHOS -- Gitee From 52557729e3dcd7867822a6e9ace7756f4694d2b4 Mon Sep 17 00:00:00 2001 From: caochuan Date: Fri, 24 Sep 2021 14:25:22 +0800 Subject: [PATCH 6/8] Fix code check issue Signed-off-by: caochuan --- mock/native/include/nocopyable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mock/native/include/nocopyable.h b/mock/native/include/nocopyable.h index 060a872d2..e5203d024 100644 --- a/mock/native/include/nocopyable.h +++ b/mock/native/include/nocopyable.h @@ -34,7 +34,7 @@ do \ do \ { \ className(className&&) = delete; \ - (className)& operator= (className&&) = delete; \ + (className)& operator= ((className)&&) = delete; \ } while (0) class NoCopyable { protected: -- Gitee From 2f843feafa3c3c39dcd25ba0666dcccf5cb121e3 Mon Sep 17 00:00:00 2001 From: caochuan Date: Fri, 24 Sep 2021 14:33:12 +0800 Subject: [PATCH 7/8] Fix loading issue Signed-off-by: caochuan --- frameworks/kits/js/common/native_module_ohos_image.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/kits/js/common/native_module_ohos_image.cpp b/frameworks/kits/js/common/native_module_ohos_image.cpp index 3e62211be..bd70d78e6 100644 --- a/frameworks/kits/js/common/native_module_ohos_image.cpp +++ b/frameworks/kits/js/common/native_module_ohos_image.cpp @@ -43,7 +43,7 @@ static napi_module g_module = { /* * module register */ -extern "C" __attribute__((constructor)) void RegisterModule(void) +extern "C" __attribute__((constructor)) void ImageRegisterModule(void) { napi_module_register(&g_module); } -- Gitee From 68b3e0185f5240543468491b159254030a5ce3dd Mon Sep 17 00:00:00 2001 From: caochuan Date: Sun, 26 Sep 2021 12:43:15 +0800 Subject: [PATCH 8/8] Delete refbase.h in mock folder and update plugin_service. Signed-off-by: caochuan --- interfaces/innerkits/include/pixel_map.h | 1 - mock/native/include/refbase.h | 679 ----------------------- plugins/manager/include/plugin_service.h | 4 +- 3 files changed, 2 insertions(+), 682 deletions(-) delete mode 100644 mock/native/include/refbase.h diff --git a/interfaces/innerkits/include/pixel_map.h b/interfaces/innerkits/include/pixel_map.h index 687a4e7bf..68a5a44b8 100644 --- a/interfaces/innerkits/include/pixel_map.h +++ b/interfaces/innerkits/include/pixel_map.h @@ -18,7 +18,6 @@ #include #include "image_type.h" -#include "refbase.h" #include "parcel.h" namespace OHOS { diff --git a/mock/native/include/refbase.h b/mock/native/include/refbase.h deleted file mode 100644 index ea1a03235..000000000 --- a/mock/native/include/refbase.h +++ /dev/null @@ -1,679 +0,0 @@ -/* - * Copyright (C) 2021 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 UTILS_BASE_REFBASE_H -#define UTILS_BASE_REFBASE_H - -#include -#include - -namespace OHOS { -#define INITIAL_PRIMARY_VALUE (1 << 28) - -class RefBase; - -class RefCounter { -public: - using RefPtrCallback = std::function; - - RefCounter(); - - explicit RefCounter(RefCounter *counter); - - RefCounter &operator=(const RefCounter &counter); - - virtual ~RefCounter(); - - void SetCallback(const RefPtrCallback& callback); - - void RemoveCallback(); - - int GetRefCount(); - - void IncRefCount(); - - void DecRefCount(); - - bool IsRefPtrValid(); - - int IncStrongRefCount(const void *objectId); - - int DecStrongRefCount(const void *objectId); - - int GetStrongRefCount(); - - int IncWeakRefCount(const void *objectId); - - int DecWeakRefCount(const void *objectId); - - int GetWeakRefCount(); - - void SetAttemptAcquire(); - - bool IsAttemptAcquireSet(); - - void ClearAttemptAcquire(); - - bool AttemptIncStrongRef(const void *objectId, int &outCount); - - bool IsLifeTimeExtended(); - - void ExtendObjectLifetime(); - -private: - std::atomic atomicStrong_; - std::atomic atomicWeak_; - std::atomic atomicRefCount_; - std::atomic atomicFlags_; - std::atomic atomicAttempt_; - RefPtrCallback callback_ = nullptr; - static constexpr unsigned int FLAG_EXTEND_LIFE_TIME = 0x00000002; -}; - -class WeakRefCounter { -public: - WeakRefCounter(RefCounter *base, void *cookie); - - virtual ~WeakRefCounter(); - - void *GetRefPtr(); - - void IncWeakRefCount(const void *objectId); - - void DecWeakRefCount(const void *objectId); - - bool AttemptIncStrongRef(const void *objectId); - -private: - std::atomic atomicWeak_; - RefCounter *refCounter_ = nullptr; - void *cookie_ = nullptr; -}; - -class RefBase { -public: - RefBase(); - - RefBase(const RefBase &refbase); - - RefBase &operator=(const RefBase &refbase); - - RefBase(RefBase &&refbase) noexcept; - - RefBase &operator=(RefBase &&refbase) noexcept; - - virtual ~RefBase(); - - void RefPtrCallback(); - - void ExtendObjectLifetime(); - - void IncStrongRef(const void *objectId); - - void DecStrongRef(const void *objectId); - - int GetSptrRefCount(); - - WeakRefCounter *CreateWeakRef(void *cookie); - - void IncWeakRef(const void *objectId); - - void DecWeakRef(const void *objectId); - - int GetWptrRefCount(); - - bool AttemptAcquire(const void *objectId); - - bool AttemptIncStrongRef(const void *objectId); - - bool IsAttemptAcquireSet(); - - bool IsExtendLifeTimeSet(); - - virtual void OnFirstStrongRef(const void *objectId); - - virtual void OnLastStrongRef(const void *objectId); - - virtual void OnLastWeakRef(const void *objectId); - - virtual bool OnAttemptPromoted(const void *objectId); - -private: - RefCounter *refs_ = nullptr; -}; - -template -class wptr; - -template -class sptr { - friend class wptr; - -public: - sptr(); - - ~sptr(); - - sptr(T *other); - - sptr(const sptr &other); - - sptr(sptr &&other); - - sptr &operator=(sptr &&other); - - template - sptr(const sptr &other); - - inline sptr(WeakRefCounter *p, bool force); - - inline T *GetRefPtr() const - { - return refs_; - } - - inline void ForceSetRefPtr(T *other); - - void clear(); - - inline operator T *() const - { - return refs_; - } - - inline T &operator*() const - { - return *refs_; - } - - inline T *operator->() const - { - return refs_; - } - - inline bool operator!() const - { - return refs_ == nullptr; - } - - sptr &operator=(T *other); - - sptr &operator=(const sptr &other); - - sptr &operator=(const wptr &other); - - template - sptr &operator=(const sptr &other); - - bool operator==(const T *other) const; - - inline bool operator!=(const T *other) const - { - return !operator==(other); - } - - bool operator==(const wptr &other) const; - - inline bool operator!=(const wptr &other) const - { - return !operator==(other); - } - - bool operator==(const sptr &other) const; - - inline bool operator!=(const sptr &other) const - { - return !operator==(other); - } - -private: - T *refs_ = nullptr; -}; - -template -inline void sptr::ForceSetRefPtr(T *other) -{ - refs_ = other; -} - -template -inline sptr::sptr() -{ - refs_ = nullptr; -} - -template -inline sptr::sptr(T *other) -{ - refs_ = other; - if (refs_ != nullptr) { - refs_->IncStrongRef(this); - } -} - -template -inline sptr::sptr(const sptr &other) -{ - refs_ = other.GetRefPtr(); - if (refs_ != nullptr) { - refs_->IncStrongRef(this); - } -} - -template -sptr::sptr(sptr &&other) -{ - refs_ = other.GetRefPtr(); - other.ForceSetRefPtr(nullptr); -} - -template -sptr &sptr::operator=(sptr &&other) -{ - if (refs_ != nullptr) { - refs_->DecStrongRef(this); - } - refs_ = other.GetRefPtr(); - other.ForceSetRefPtr(nullptr); - return *this; -} - -template -template -sptr::sptr(const sptr &other) : refs_(other.GetRefPtr()) -{ - if (refs_ != nullptr) { - refs_->IncStrongRef(this); - } -} - -template -inline sptr &sptr::operator=(T *other) -{ - if (other != nullptr) { - other->IncStrongRef(this); - } - if (refs_ != nullptr) { - refs_->DecStrongRef(this); - } - refs_ = other; - return *this; -} - -template -inline sptr &sptr::operator=(const sptr &other) -{ - T *otherRef(other.GetRefPtr()); - if (otherRef != nullptr) { - otherRef->IncStrongRef(this); - } - if (refs_ != nullptr) { - refs_->DecStrongRef(this); - } - refs_ = otherRef; - return *this; -} - -template -inline sptr &sptr::operator=(const wptr &other) -{ - if ((other != nullptr) && other.AttemptIncStrongRef(this)) { - refs_ = other.GetRefPtr(); - } else { - refs_ = nullptr; - } - return *this; -} - -template -template -sptr &sptr::operator=(const sptr &other) -{ - T *otherRef(other.GetRefPtr()); - if (otherRef != nullptr) { - otherRef->IncStrongRef(this); - } - if (refs_ != nullptr) { - refs_->DecStrongRef(this); - } - refs_ = otherRef; - return *this; -} - -template -inline bool sptr::operator==(const T *other) const -{ - return other == refs_; -} - -template -inline bool sptr::operator==(const wptr &other) const -{ - return refs_ == other.GetRefPtr(); -} - -template -inline bool sptr::operator==(const sptr &other) const -{ - return refs_ == other.GetRefPtr(); -} - -template -void sptr::clear() -{ - if (refs_) { - refs_->DecStrongRef(this); - refs_ = 0; - } -} - -template -inline sptr::~sptr() -{ - if (refs_ != nullptr) { - refs_->DecStrongRef(this); - } -} - -template -inline sptr::sptr(WeakRefCounter *p, bool) -{ - if ((p != nullptr) && p->AttemptIncStrongRef(this)) { - refs_ = reinterpret_cast(p->GetRefPtr()); - } else { - refs_ = nullptr; - } -} - -template -class wptr { - template - friend class wptr; - -public: - wptr(); - - wptr(T *other); - - wptr(const wptr &other); - - wptr(const sptr &other); - - template - wptr(const wptr &other); - - template - wptr(const sptr &other); - - wptr &operator=(T *other); - - template - wptr &operator=(O *other); - - wptr &operator=(const wptr &other); - - wptr &operator=(const sptr &other); - - template - wptr &operator=(const wptr &other); - - template - wptr &operator=(const sptr &other); - - inline T *operator*() const - { - return *refs_; - } - inline T *operator->() const - { - return reinterpret_cast(refs_->GetRefPtr()); - } - - bool operator==(const T *other) const; - - inline bool operator!=(const T *other) const - { - return !operator==(other); - }; - - bool operator==(const wptr &other) const; - - inline bool operator!=(const wptr &other) const - { - return !operator==(other); - } - - bool operator==(const sptr &other) const; - - inline bool operator!=(const sptr &other) const - { - return !operator==(other); - } - - T *GetRefPtr() const; - - inline bool AttemptIncStrongRef(const void *objectId) const - { - return refs_->AttemptIncStrongRef(objectId); - } - - const sptr promote() const; - - ~wptr(); - -private: - WeakRefCounter *refs_ = nullptr; -}; - -template -inline T *wptr::GetRefPtr() const -{ - return (refs_ != nullptr) ? reinterpret_cast(refs_->GetRefPtr()) : nullptr; -} - -template -wptr::wptr() -{ - refs_ = nullptr; -} - -template -wptr::wptr(T *other) -{ - if (other != nullptr) { - refs_ = other->CreateWeakRef(other); - if (refs_ != nullptr) { - refs_->IncWeakRefCount(this); - } - } else { - refs_ = nullptr; - } -} - -template -wptr::wptr(const wptr &other) -{ - refs_ = other.refs_; - if (refs_ != nullptr) { - refs_->IncWeakRefCount(this); - } -} - -template -wptr::wptr(const sptr &other) -{ - if (other.GetRefPtr() != nullptr) { - refs_ = other->CreateWeakRef(other.GetRefPtr()); - if (refs_ != nullptr) { - refs_->IncWeakRefCount(this); - } - } -} - -template -template -wptr::wptr(const wptr &other) -{ - refs_ = other.refs_; - if (refs_ != nullptr) { - refs_->IncWeakRefCount(this); - } -} - -template -template -wptr::wptr(const sptr &other) -{ - if (other.GetRefPtr() != nullptr) { - refs_ = other->CreateWeakRef(other.GetRefPtr()); - if (refs_ != nullptr) { - refs_->IncWeakRefCount(this); - } - } -} - -template -wptr &wptr::operator=(T *other) -{ - WeakRefCounter *newWeakRef = nullptr; - if (other != nullptr) { - newWeakRef = other->CreateWeakRef(other); - if (newWeakRef != nullptr) { - newWeakRef->IncWeakRefCount(this); - } - } - if (refs_ != nullptr) { - refs_->DecWeakRefCount(this); - } - refs_ = newWeakRef; - return *this; -} - -template -template -wptr &wptr::operator=(O *other) -{ - T *object = reinterpret_cast(other); - WeakRefCounter *newWeakRef = nullptr; - if (object != nullptr) { - newWeakRef = object->CreateWeakRef(object); - if (newWeakRef != nullptr) { - newWeakRef->IncWeakRefCount(this); - } - } - if (refs_ != nullptr) { - refs_->DecWeakRefCount(this); - } - - refs_ = newWeakRef; - return *this; -} - -template -inline wptr &wptr::operator=(const wptr &other) -{ - if (other.refs_ != nullptr) { - other.refs_->IncWeakRefCount(this); - } - if (refs_ != nullptr) { - refs_->DecWeakRefCount(this); - } - refs_ = other.refs_; - return *this; -} - -template -inline wptr &wptr::operator=(const sptr &other) -{ - WeakRefCounter *newWeakRef = nullptr; - if (other.GetRefPtr() != nullptr) { - newWeakRef = other->CreateWeakRef(other.GetRefPtr()); - if (newWeakRef != nullptr) { - newWeakRef->IncWeakRefCount(this); - } - } - if (refs_ != nullptr) { - refs_->DecWeakRefCount(this); - } - refs_ = newWeakRef; - return *this; -} - -template -template -wptr &wptr::operator=(const wptr &other) -{ - if (other.refs_ != nullptr) { - other.refs_->IncWeakRefCount(this); - } - if (refs_ != nullptr) { - refs_->DecWeakRefCount(this); - } - refs_ = other.refs_; - return *this; -} - -template -template -wptr &wptr::operator=(const sptr &other) -{ - WeakRefCounter *newWeakRef = nullptr; - if (other.GetRefPtr() != nullptr) { - newWeakRef = other->CreateWeakRef(other->GetRefPtr()); - if (newWeakRef != nullptr) { - newWeakRef->IncWeakRefCount(this); - } - } - if (refs_ != nullptr) { - refs_->DecWeakRefCount(this); - } - refs_ = newWeakRef; - return *this; -} - -template -inline bool wptr::operator==(const T *other) const -{ - return GetRefPtr() == other; -} - -template -inline bool wptr::operator==(const wptr &other) const -{ - return GetRefPtr() == other.GetRefPtr(); -} - -template -inline bool wptr::operator==(const sptr &other) const -{ - return GetRefPtr() == other.GetRefPtr(); -} - -template -inline const sptr wptr::promote() const -{ - return sptr(refs_, true); -} - -template -inline wptr::~wptr() -{ - if (refs_ != nullptr) { - refs_->DecWeakRefCount(this); - } -} -} // namespace OHOS -#endif diff --git a/plugins/manager/include/plugin_service.h b/plugins/manager/include/plugin_service.h index 768c80d4f..79425417e 100644 --- a/plugins/manager/include/plugin_service.h +++ b/plugins/manager/include/plugin_service.h @@ -45,8 +45,8 @@ template inline uint16_t GetInterfaceId() { return INVALID_IID; } - -#define DECLARE_INTERFACE(InterfaceType, interfaceID) template<> inline uint16_t OHOS::MultimediaPlugin::GetInterfaceId() { return interfaceID; } +#define GET_INTERFACE_ID OHOS::MultimediaPlugin::GetInterfaceId +#define DECLARE_INTERFACE(Type, ID) template<> inline uint16_t GET_INTERFACE_ID() { return ID; } } // namespace MultimediaPlugin } // namespace OHOS -- Gitee