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