\hypertarget{group__modules}{}\section{Modules}
\label{group__modules}\index{Modules@{Modules}}


Loading Modules for Elektra.  


\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
int \mbox{\hyperlink{group__modules_gaa40915e67f973ccd5258aa450bd03585}{elektra\+Modules\+Init}} (Key\+Set $\ast$modules, Key $\ast$error)
\begin{DoxyCompactList}\small\item\em Initialises the module loading system. \end{DoxyCompactList}\item 
elektra\+Plugin\+Factory \mbox{\hyperlink{group__modules_ga09300fbf0e0cfc9dc80bb877b00117c0}{elektra\+Modules\+Load}} (Key\+Set $\ast$modules, const char $\ast$name, Key $\ast$error)
\begin{DoxyCompactList}\small\item\em Load a library with the given name. \end{DoxyCompactList}\item 
int \mbox{\hyperlink{group__modules_ga5646d92ffe3e1e04c4586d9c910ba6bd}{elektra\+Modules\+Close}} (Key\+Set $\ast$modules, Key $\ast$error)
\begin{DoxyCompactList}\small\item\em Close all modules. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Loading Modules for Elektra. 

Unfortunately there is no portable way to load modules, plugins or libraries. So Elektra needed a framework which abstracts the loading of modules. Depending of the operating system the build system chooses different source files which actually implement the loading of a module.

The goals are\+:
\begin{DoxyItemize}
\item to have a list of all loaded modules
\item writing module loaders should be easy
\item handle and report errors well
\item avoid loading of modules multiple times (maybe OS can\textquotesingle{}t handle that well)
\item hide the OS dependent handle inside a Key (handle is needed to close module afterwards) 
\end{DoxyItemize}

\subsection{Function Documentation}
\mbox{\Hypertarget{group__modules_ga5646d92ffe3e1e04c4586d9c910ba6bd}\label{group__modules_ga5646d92ffe3e1e04c4586d9c910ba6bd}} 
\index{Modules@{Modules}!elektraModulesClose@{elektraModulesClose}}
\index{elektraModulesClose@{elektraModulesClose}!Modules@{Modules}}
\subsubsection{\texorpdfstring{elektraModulesClose()}{elektraModulesClose()}}
{\footnotesize\ttfamily int elektra\+Modules\+Close (\begin{DoxyParamCaption}\item[{Key\+Set $\ast$}]{modules,  }\item[{Key $\ast$}]{error }\end{DoxyParamCaption})}



Close all modules. 

Iterates over all modules and closes each of them.

Finish all affairs with the modules. Delete all keys where the appropriate module could be closed.

If it is not possible to close a module, still try to close all other modules, but report the error with the error key.


\begin{DoxyParams}{Parameters}
{\em modules} & all modules in this keyset will be closed \\
\hline
{\em error} & a key to append the error information if it is not null \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
-\/1 on error 

$>$=0 otherwise 
\end{DoxyReturn}
\mbox{\Hypertarget{group__modules_gaa40915e67f973ccd5258aa450bd03585}\label{group__modules_gaa40915e67f973ccd5258aa450bd03585}} 
\index{Modules@{Modules}!elektraModulesInit@{elektraModulesInit}}
\index{elektraModulesInit@{elektraModulesInit}!Modules@{Modules}}
\subsubsection{\texorpdfstring{elektraModulesInit()}{elektraModulesInit()}}
{\footnotesize\ttfamily int elektra\+Modules\+Init (\begin{DoxyParamCaption}\item[{Key\+Set $\ast$}]{modules,  }\item[{Key $\ast$}]{error }\end{DoxyParamCaption})}



Initialises the module loading system. 

Most operating systems will have to do nothing here. Anyway you are required to add the key system/elektra/modules if it was successful.

On error -\/1 is returned and if error != 0 error information is added to it.


\begin{DoxyParams}{Parameters}
{\em modules} & an empty keyset \\
\hline
{\em error} & a key to append the error information if it is not null \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
-\/1 on error 

$>$=0 otherwise 
\end{DoxyReturn}
\mbox{\Hypertarget{group__modules_ga09300fbf0e0cfc9dc80bb877b00117c0}\label{group__modules_ga09300fbf0e0cfc9dc80bb877b00117c0}} 
\index{Modules@{Modules}!elektraModulesLoad@{elektraModulesLoad}}
\index{elektraModulesLoad@{elektraModulesLoad}!Modules@{Modules}}
\subsubsection{\texorpdfstring{elektraModulesLoad()}{elektraModulesLoad()}}
{\footnotesize\ttfamily elektra\+Plugin\+Factory elektra\+Modules\+Load (\begin{DoxyParamCaption}\item[{Key\+Set $\ast$}]{modules,  }\item[{const char $\ast$}]{name,  }\item[{Key $\ast$}]{error }\end{DoxyParamCaption})}



Load a library with the given name. 

\begin{DoxyReturn}{Returns}
a pointer to the factory which can create the plugin.
\end{DoxyReturn}
Make sure that you first lookup if this module was already loaded. If it was, just return the pointer and you are done.

Otherwise load the module/library given by name. You need to take care that a proper name is used. The name does not have any path, pre-\/ or postfixes.

The next step is to fetch the symbol elektra\+Plugin\+Factory.

If everything was successful append all information to the keyset modules and return the pointer. Take care that you can close the module with that information. All information needs to be stored within system/elektra/modules/name You might want to use an struct and store it there as binary key.

If anything goes wrong don\textquotesingle{}t append anything to modules. Instead report the error to the error key and return with 0.

\begin{DoxyPrecond}{Precondition}
the name is not null, empty and has at least one character different to /. It is suitable to be used as key\+Add\+Base\+Name without any further error checking.
\end{DoxyPrecond}

\begin{DoxyParams}{Parameters}
{\em modules} & where to get existing modules from a new module will be added there \\
\hline
{\em name} & the name for the plugin to load. Note that it does not have any prefixes or postfixes, you need to add them yourself. \\
\hline
{\em error} & the key to add warnings or report errors \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
a pointer which can create a Plugin 

0 on error 
\end{DoxyReturn}
