1 /*
2 * Copyright (c) 2022 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 "clip/clip_plugin.h"
17
18 #include "default_clip.h"
19 namespace OHOS::MiscServices {
20 std::map<std::string, ClipPlugin::Factory *> ClipPlugin::factories_;
21 DefaultClip g_defaultClip;
RegCreator(const std::string & name,Factory * factory)22 bool ClipPlugin::RegCreator(const std::string &name, Factory *factory)
23 {
24 auto it = factories_.find(name);
25 if (it != factories_.end()) {
26 return false;
27 }
28 factories_[name] = factory;
29 return true;
30 }
31
CreatePlugin(const std::string & name)32 ClipPlugin *ClipPlugin::CreatePlugin(const std::string &name)
33 {
34 auto it = factories_.find(name);
35 if (it == factories_.end() || it->second == nullptr) {
36 return &g_defaultClip;
37 }
38 return it->second->Create();
39 }
40
DestroyPlugin(const std::string & name,ClipPlugin * plugin)41 bool ClipPlugin::DestroyPlugin(const std::string &name, ClipPlugin *plugin)
42 {
43 if (plugin == &g_defaultClip) {
44 return true;
45 }
46
47 auto it = factories_.find(name);
48 if (it == factories_.end() || it->second == nullptr) {
49 return false;
50 }
51 return it->second->Destroy(plugin);
52 }
53
~ClipPlugin()54 ClipPlugin::~ClipPlugin()
55 {
56 }
57
GetTopEvents(uint32_t topN)58 std::vector<ClipPlugin::GlobalEvent> ClipPlugin::GetTopEvents(uint32_t topN)
59 {
60 (void)topN;
61 return std::vector<GlobalEvent>();
62 }
63
GetTopEvents(uint32_t topN,int32_t user)64 std::vector<ClipPlugin::GlobalEvent> ClipPlugin::GetTopEvents(uint32_t topN, int32_t user)
65 {
66 (void)user;
67 (void)topN;
68 return std::vector<GlobalEvent>();
69 }
70
Clear()71 void ClipPlugin::Clear()
72 {
73 }
74
Clear(int32_t user)75 void ClipPlugin::Clear(int32_t user)
76 {
77 (void)user;
78 }
79 } // namespace OHOS::MiscServices
80