1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef UIEFFECT_EFFECT_VISUAL_EFFECT_UNMARSHALLING_SINGLETON_H 17 #define UIEFFECT_EFFECT_VISUAL_EFFECT_UNMARSHALLING_SINGLETON_H 18 19 #include <unordered_map> 20 #include <functional> 21 #include <mutex> 22 #include <memory> 23 24 #include <parcel.h> 25 26 #include "common/rs_macros.h" 27 28 namespace OHOS { 29 namespace Rosen { 30 31 class VisualEffectPara; 32 33 class RSC_EXPORT VisualEffectUnmarshallingSingleton final { 34 public: 35 using UnmarshallingFunc = std::function<bool (Parcel&, std::shared_ptr<VisualEffectPara>&)>; 36 37 static VisualEffectUnmarshallingSingleton& GetInstance(); 38 39 VisualEffectUnmarshallingSingleton(const VisualEffectUnmarshallingSingleton&) = delete; 40 VisualEffectUnmarshallingSingleton& operator=(const VisualEffectUnmarshallingSingleton&) = delete; 41 VisualEffectUnmarshallingSingleton(VisualEffectUnmarshallingSingleton&&) = delete; 42 VisualEffectUnmarshallingSingleton& operator=(VisualEffectUnmarshallingSingleton&&) = delete; 43 44 void RegisterCallback(uint16_t type, UnmarshallingFunc func); 45 void UnregisterCallback(uint16_t type); 46 [[nodiscard]] UnmarshallingFunc GetCallback(uint16_t type); 47 48 private: 49 VisualEffectUnmarshallingSingleton() = default; 50 ~VisualEffectUnmarshallingSingleton() = default; 51 52 private: 53 std::unordered_map<uint16_t, UnmarshallingFunc> unmarshallingFuncs_; 54 std::mutex mutex_; 55 }; 56 57 } // namespace Rosen 58 } // namespace OHOS 59 60 #endif // UIEFFECT_EFFECT_VISUAL_EFFECT_UNMARSHALLING_SINGLETON_H