• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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_export.h"
17 #include "hilog/log.h"
18 #include "log_tags.h"
19 #include "plugin_utils.h"
20 #include "raw_decoder.h"
21 
22 // plugin package name same as metadata.
23 namespace {
24     const std::string PACKAGE_NAME = ("LibRawPlugin");
25 }
26 
27 // register implement classes of this plugin.
28 PLUGIN_EXPORT_REGISTER_CLASS_BEGIN
29 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::RawDecoder)
30 PLUGIN_EXPORT_REGISTER_CLASS_END
31 
32 using std::string;
33 using namespace OHOS::HiviewDFX;
34 
35 static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibRawPlugin" };
36 
37 #define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__)
38 #define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__)
39 
40 // define the external interface of this plugin.
41 PLUGIN_EXPORT_DEFAULT_EXTERNAL_START()
PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP()42 PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP()
43 OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className)
44 {
45     HiLog::Debug(LABEL, "PluginExternalCreate: create object for package: %{public}s, class: %{public}s.",
46                  PACKAGE_NAME.c_str(), className.c_str());
47 
48     auto iter = implClassMap.find(className);
49     if (iter == implClassMap.end()) {
50         HiLog::Error(LABEL, "PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.",
51                      className.c_str(), PACKAGE_NAME.c_str());
52         return nullptr;
53     }
54 
55     auto creator = iter->second;
56     if (creator == nullptr) {
57         HiLog::Error(LABEL, "PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.",
58                      className.c_str(), PACKAGE_NAME.c_str());
59         return nullptr;
60     }
61 
62     return creator();
63 }
64