Fcitx
addonloader.cpp
1 /*
2  * SPDX-FileCopyrightText: 2016-2016 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 
8 #include "addonloader.h"
9 #include <exception>
10 #include <string>
11 #include "fcitx-utils/log.h"
12 #include "addonfactory.h"
13 #include "addoninfo.h"
14 #include "addonloader_p.h"
15 
16 namespace fcitx {
17 
18 AddonLoader::~AddonLoader() {}
19 
20 StaticLibraryLoader::StaticLibraryLoader(StaticAddonRegistry *registry_)
21  : registry(registry_) {}
22 
23 AddonInstance *StaticLibraryLoader::load(const AddonInfo &info,
24  AddonManager *manager) {
25  auto iter = registry->find(info.uniqueName());
26  if (iter == registry->end()) {
27  return nullptr;
28  }
29  try {
30  return iter->second->create(manager);
31  } catch (const std::exception &e) {
32  FCITX_ERROR() << "Failed to create addon: " << info.uniqueName() << " "
33  << e.what();
34  } catch (...) {
35  FCITX_ERROR() << "Failed to create addon: " << info.uniqueName();
36  }
37  return nullptr;
38 }
39 } // namespace fcitx
Addon Factory class.
Definition: action.cpp:17
Log utilities.