1 /* 2 * Copyright (C) 2021 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 IMPL_CLASS_MGR_H 17 #define IMPL_CLASS_MGR_H 18 19 #include <list> 20 #include <string> 21 #include "json.hpp" 22 #include "nocopyable.h" 23 #include "plugin_common_type.h" 24 #include "plugin_errors.h" 25 #include "pointer_key_map.h" 26 #include "priority_scheme.h" 27 #include "singleton.h" 28 29 namespace OHOS { 30 namespace MultimediaPlugin { 31 class ImplClass; 32 class Plugin; 33 class PluginClassBase; 34 35 class ImplClassMgr final : public NoCopyable { 36 public: 37 uint32_t AddClass(std::weak_ptr<Plugin> &plugin, const nlohmann::json &classInfo); 38 void DeleteClass(const std::weak_ptr<Plugin> &plugin); 39 PluginClassBase *CreateObject(uint16_t interfaceID, const std::string &className, uint32_t &errorCode); 40 PluginClassBase *CreateObject(uint16_t interfaceID, uint16_t serviceType, 41 const std::map<std::string, AttrData> &capabilities, 42 const PriorityScheme &priorityScheme, uint32_t &errorCode); 43 uint32_t ImplClassMgrGetClassInfo(uint16_t interfaceID, uint16_t serviceType, 44 const std::map<std::string, AttrData> &capabilities, std::vector<ClassInfo> &classesInfo); 45 std::shared_ptr<ImplClass> GetImplClass(const std::string &packageName, const std::string &className); 46 DECLARE_DELAYED_REF_SINGLETON(ImplClassMgr); 47 48 private: 49 std::shared_ptr<ImplClass> SearchByPriority(const std::list<std::shared_ptr<ImplClass>> &candidates, 50 const PriorityScheme &priorityScheme); 51 std::shared_ptr<ImplClass> SearchSimplePriority(const std::list<std::shared_ptr<ImplClass>> &candidates); 52 uint32_t ComparePriority(const AttrData &lhs, const AttrData &rhs, PriorityType type); 53 uint32_t CompareBoolPriority(const AttrData &lhs, const AttrData &rhs, PriorityType type); 54 uint32_t CompareUint32Priority(const AttrData &lhs, const AttrData &rhs, PriorityType type); 55 uint32_t CompareStringPriority(const AttrData &lhs, const AttrData &rhs, PriorityType type); 56 57 using NameClassMultimap = PointerKeyMultimap<const std::string, std::shared_ptr<ImplClass>>; 58 using ServiceClassMultimap = std::multimap<uint32_t, std::shared_ptr<ImplClass>>; 59 NameClassMultimap classMultimap_; 60 ServiceClassMultimap srvSearchMultimap_; 61 }; 62 } // namespace MultimediaPlugin 63 } // namespace OHOS 64 65 #endif // IMPL_CLASS_MGR_H 66