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_export.h"
17 #include "image_log.h"
18 #include "plugin_utils.h"
19 #include "png_decoder.h"
20
21 #undef LOG_DOMAIN
22 #define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
23
24 #undef LOG_TAG
25 #define LOG_TAG "LibPngPlugin"
26
27 // plugin package name same as metadata.
28 namespace {
29 const std::string PACKAGE_NAME = ("LibPngPlugin");
30 }
31
32 // register implement classes of this plugin.
33 PLUGIN_EXPORT_REGISTER_CLASS_BEGIN
34 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::PngDecoder)
35 PLUGIN_EXPORT_REGISTER_CLASS_END
36
37 using std::string;
38
39 // define the external interface of this plugin.
40 PLUGIN_EXPORT_DEFAULT_EXTERNAL_START()
PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP()41 PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP()
42 OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className)
43 {
44 IMAGE_LOGD("PluginExternalCreate: create object for package: %{public}s, class: %{public}s.",
45 PACKAGE_NAME.c_str(), className.c_str());
46
47 auto iter = implClassMap.find(className);
48 if (iter == implClassMap.end()) {
49 IMAGE_LOGE("PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.",
50 className.c_str(), PACKAGE_NAME.c_str());
51 return nullptr;
52 }
53
54 auto creator = iter->second;
55 if (creator == nullptr) {
56 IMAGE_LOGE("PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.",
57 className.c_str(), PACKAGE_NAME.c_str());
58 return nullptr;
59 }
60
61 return creator();
62 }
63