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