Fcitx
Public Member Functions | Protected Member Functions | Friends | List of all members
fcitx::AddonInstance Class Reference

Base class for any addon in fcitx. More...

#include <fcitx/addoninstance.h>

Inheritance diagram for fcitx::AddonInstance:
Inheritance graph
[legend]

Public Member Functions

virtual void reloadConfig ()
 Reload configuration from disk.
 
virtual void save ()
 Save any relevant data. Usually, it will be invoked when fcitx exits.
 
virtual const ConfigurationgetConfig () const
 Get the configuration.
 
virtual void setConfig (const RawConfig &)
 Set configuration from Raw Config.
 
virtual const ConfigurationgetSubConfig (const std::string &) const
 
virtual void setSubConfig (const std::string &, const RawConfig &)
 
template<typename Signature , typename... Args>
std::function< Signature >::result_type callWithSignature (const std::string &name, Args &&...args)
 
template<typename MetaSignatureString , typename... Args>
AddonFunctionSignatureReturnType< MetaSignatureString > callWithMetaString (Args &&...args)
 
template<typename MetaType , typename... Args>
AddonFunctionSignatureReturnType< typename MetaType::Name > call (Args &&...args)
 Call an exported function for this addon.
 
void registerCallback (const std::string &name, AddonFunctionAdaptorBase *adaptor)
 
const AddonInfoaddonInfo () const
 
bool canRestart () const
 Check if this addon can safely restart. More...
 

Protected Member Functions

void setCanRestart (bool canRestart)
 Set if this addon can safely restart. More...
 

Friends

class AddonManagerPrivate
 

Detailed Description

Base class for any addon in fcitx.

To implement addon in fcitx, you will need to create a sub class for this class.

To make an SharedLibrary Addon, you will also need to use FCITX_ADDON_FACTORY to export the factory for addon.

An addon can export several function to be invoked by other addons. When you need to do so, you will need some extra command in your CMakeLists.txt, and using FCITX_ADDON_DECLARE_FUNCTION and FCITX_ADDON_EXPORT_FUNCTION.

fcitx5_export_module(XCB
TARGET xcb
BUILD_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}"
HEADERS xcb_public.h INSTALL)

First you will need to create a header file with exported addon function. E.g. dummyaddon_public.h

FCITX_ADDON_DECLARE_FUNCTION(DummyAddon, addOne, int(int));

This file declares a function addOne for DummyAddon, with function signature int(int).

Then, when you implement the class, add using the macro FCITX_ADDON_EXPORT_FUNCTION to the addon class.

class DummyAddon : public fcitx::AddonInstance {
public:
int addOne(int a) { return a + 1; }
FCITX_ADDON_EXPORT_FUNCTION(DummyAddon, addOne);
};

This macro will register the function and check the signature against the actual function to make sure they have the same signature.

In order to invoke the function in other code, you will need to first obtain the pointer to the addon via AddonManager. Then invoke it by

addon->call<fcitx::IDummyAddon::addOne>(7);

Definition at line 71 of file addoninstance.h.


The documentation for this class was generated from the following files: