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 #include "plugin_fw.h"
17 #include "hilog/log.h"
18 #include "singleton.h"
19 #include "log_tags.h"
20 #include "impl_class_mgr.h"
21 #include "plugin_info_lock.h"
22 #include "plugin_mgr.h"
23
24 namespace OHOS {
25 namespace MultimediaPlugin {
26 using std::map;
27 using std::string;
28 using std::vector;
29 using OHOS::Utils::RWLock;
30 using OHOS::Utils::UniqueReadGuard;
31 using OHOS::Utils::UniqueWriteGuard;
32 using namespace OHOS::HiviewDFX;
33
34 static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "PluginFw" };
35
Register(const vector<string> & canonicalPaths)36 uint32_t PluginFw::Register(const vector<string> &canonicalPaths)
37 {
38 HiLog::Debug(LABEL, "plugin register.");
39 // Use the read-write lock to mutually exclusive write plugin information and read plugin information operations,
40 // where Register() plays the write role.
41 UniqueWriteGuard<RWLock> lk(DelayedRefSingleton<PluginInfoLock>::GetInstance().rwLock_);
42 return pluginMgr_.Register(canonicalPaths);
43 }
44
CreateObject(uint16_t interfaceID,const string & className,uint32_t & errorCode)45 PluginClassBase *PluginFw::CreateObject(uint16_t interfaceID, const string &className, uint32_t &errorCode)
46 {
47 // Use the read-write lock to mutually exclusive write plugin information and read plugin information operations,
48 // where CreateObject() plays the read role.
49 UniqueReadGuard<RWLock> lk(DelayedRefSingleton<PluginInfoLock>::GetInstance().rwLock_);
50 return implClassMgr_.CreateObject(interfaceID, className, errorCode);
51 }
52
CreateObject(uint16_t interfaceID,uint16_t serviceType,const map<string,AttrData> & capabilities,const PriorityScheme & priorityScheme,uint32_t & errorCode)53 PluginClassBase *PluginFw::CreateObject(uint16_t interfaceID, uint16_t serviceType,
54 const map<string, AttrData> &capabilities,
55 const PriorityScheme &priorityScheme, uint32_t &errorCode)
56 {
57 // Use the read-write lock to mutually exclusive write plugin information and read plugin information operations,
58 // where CreateObject() plays the read role.
59 UniqueReadGuard<RWLock> lk(DelayedRefSingleton<PluginInfoLock>::GetInstance().rwLock_);
60 return implClassMgr_.CreateObject(interfaceID, serviceType, capabilities, priorityScheme, errorCode);
61 }
62
PluginFwGetClassInfo(uint16_t interfaceID,uint16_t serviceType,const map<std::string,AttrData> & capabilities,vector<ClassInfo> & classesInfo)63 uint32_t PluginFw::PluginFwGetClassInfo(uint16_t interfaceID, uint16_t serviceType,
64 const map<std::string, AttrData> &capabilities,
65 vector<ClassInfo> &classesInfo)
66 {
67 // Use the read-write lock to mutually exclusive write plugin information and read plugin information operations,
68 // where GetClassInfo() plays the read role.
69 UniqueReadGuard<RWLock> lk(DelayedRefSingleton<PluginInfoLock>::GetInstance().rwLock_);
70 return implClassMgr_.ImplClassMgrGetClassInfo(interfaceID, serviceType, capabilities, classesInfo);
71 }
72
73 // ------------------------------- private method -------------------------------
PluginFw()74 PluginFw::PluginFw()
75 : pluginMgr_(DelayedRefSingleton<PluginMgr>::GetInstance()),
76 implClassMgr_(DelayedRefSingleton<ImplClassMgr>::GetInstance()) {}
77
~PluginFw()78 PluginFw::~PluginFw() {}
79 } // namespace MultimediaPlugin
80 } // namespace OHOS
81