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 <map>
18 #include "image_log.h"
19 #include "plugin_class_base.h"
20 #include "plugin_utils.h"
21 #include "cloud_label_detector.h"
22 #include "label_detector.h"
23
24 #undef LOG_DOMAIN
25 #define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN
26
27 #undef LOG_TAG
28 #define LOG_TAG "plugin_example1"
29
30 // this file shows how to write plugin_export.cpp file directly.
31 // but this file can also be simplified using the code elements provided by plugin_utils.h,
32 // see plugin_example2 and plugin_example3.
33 using std::map;
34 using std::string;
35
36 static const string PACKAGE_NAME = "plugin_example1";
37 using ImplClassMap = map<const string, PluginObjectCreatorFunc>;
38
39 static ImplClassMap implClassMap = {
40 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::PluginExample::LabelDetector)
41 PLUGIN_EXPORT_REGISTER_CLASS(OHOS::PluginExample::CloudLabelDetector)
42 };
43
PluginExternalStart()44 bool PluginExternalStart()
45 {
46 IMAGE_LOGD("call PluginExternalStart() in package: %{public}s.", PACKAGE_NAME.c_str());
47 // in this example we don't have to do anything,
48 // but you may need to do some preparations below for your plugin...
49 return true;
50 }
51
PluginExternalStop()52 void PluginExternalStop()
53 {
54 IMAGE_LOGD("call PluginExternalStop() in package: %{public}s.", PACKAGE_NAME.c_str());
55 // in this example we don't have to do anything,
56 // but you may need to do some cleaning work below for your plugin...
57 return;
58 }
59
PluginExternalCreate(const string & className)60 OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className)
61 {
62 IMAGE_LOGD("PluginExternalCreate: create object for package: %{public}s, class: %{public}s.",
63 PACKAGE_NAME.c_str(), className.c_str());
64
65 auto iter = implClassMap.find(className);
66 if (iter == implClassMap.end()) {
67 IMAGE_LOGE("PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.",
68 className.c_str(), PACKAGE_NAME.c_str());
69 return nullptr;
70 }
71
72 auto creator = iter->second;
73 if (creator == nullptr) {
74 IMAGE_LOGE("PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.",
75 className.c_str(), PACKAGE_NAME.c_str());
76 return nullptr;
77 }
78
79 return creator();
80 }
81