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