Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Source for template plugin
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 :
10 : #include "template.h"
11 :
12 : #include <kdbhelper.h>
13 :
14 :
15 24 : int elektraTemplateOpen (Plugin * handle ELEKTRA_UNUSED, Key * errorKey ELEKTRA_UNUSED)
16 : {
17 : // plugin initialization logic
18 : // this function is optional
19 :
20 24 : return ELEKTRA_PLUGIN_STATUS_SUCCESS;
21 : }
22 :
23 24 : int elektraTemplateClose (Plugin * handle ELEKTRA_UNUSED, Key * errorKey ELEKTRA_UNUSED)
24 : {
25 : // free all plugin resources and shut it down
26 : // this function is optional
27 :
28 24 : return ELEKTRA_PLUGIN_STATUS_SUCCESS;
29 : }
30 :
31 22 : int elektraTemplateGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey)
32 : {
33 22 : if (!elektraStrCmp (keyName (parentKey), "system/elektra/modules/template"))
34 : {
35 20 : KeySet * contract =
36 20 : ksNew (30, keyNew ("system/elektra/modules/template", KEY_VALUE, "template plugin waits for your orders", KEY_END),
37 : keyNew ("system/elektra/modules/template/exports", KEY_END),
38 : keyNew ("system/elektra/modules/template/exports/open", KEY_FUNC, elektraTemplateOpen, KEY_END),
39 : keyNew ("system/elektra/modules/template/exports/close", KEY_FUNC, elektraTemplateClose, KEY_END),
40 : keyNew ("system/elektra/modules/template/exports/get", KEY_FUNC, elektraTemplateGet, KEY_END),
41 : keyNew ("system/elektra/modules/template/exports/set", KEY_FUNC, elektraTemplateSet, KEY_END),
42 : keyNew ("system/elektra/modules/template/exports/commit", KEY_FUNC, elektraTemplateCommit, KEY_END),
43 : keyNew ("system/elektra/modules/template/exports/error", KEY_FUNC, elektraTemplateError, KEY_END),
44 : keyNew ("system/elektra/modules/template/exports/checkconf", KEY_FUNC, elektraTemplateCheckConfig, KEY_END),
45 : #include ELEKTRA_README
46 : keyNew ("system/elektra/modules/template/infos/version", KEY_VALUE, PLUGINVERSION, KEY_END), KS_END);
47 20 : ksAppend (returned, contract);
48 20 : ksDel (contract);
49 :
50 20 : return ELEKTRA_PLUGIN_STATUS_SUCCESS;
51 : }
52 : // get all keys
53 :
54 : return ELEKTRA_PLUGIN_STATUS_NO_UPDATE;
55 : }
56 :
57 2 : int elektraTemplateSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey ELEKTRA_UNUSED)
58 : {
59 : // set all keys
60 : // this function is optional
61 :
62 2 : return ELEKTRA_PLUGIN_STATUS_NO_UPDATE;
63 : }
64 :
65 2 : int elektraTemplateError (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey ELEKTRA_UNUSED)
66 : {
67 : // handle errors (commit failed)
68 : // this function is optional
69 :
70 2 : return ELEKTRA_PLUGIN_STATUS_SUCCESS;
71 : }
72 :
73 2 : int elektraTemplateCommit (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey ELEKTRA_UNUSED)
74 : {
75 : // commit changes
76 : // this function is optional
77 :
78 2 : return ELEKTRA_PLUGIN_STATUS_SUCCESS;
79 : }
80 :
81 0 : int elektraTemplateCheckConfig (Key * errorKey ELEKTRA_UNUSED, KeySet * conf ELEKTRA_UNUSED)
82 : {
83 : // validate plugin configuration
84 : // this function is optional
85 :
86 0 : return ELEKTRA_PLUGIN_STATUS_NO_UPDATE;
87 : }
88 :
89 22 : Plugin * ELEKTRA_PLUGIN_EXPORT
90 : {
91 : // clang-format off
92 22 : return elektraPluginExport ("template",
93 : ELEKTRA_PLUGIN_OPEN, &elektraTemplateOpen,
94 : ELEKTRA_PLUGIN_CLOSE, &elektraTemplateClose,
95 : ELEKTRA_PLUGIN_GET, &elektraTemplateGet,
96 : ELEKTRA_PLUGIN_SET, &elektraTemplateSet,
97 : ELEKTRA_PLUGIN_COMMIT, &elektraTemplateCommit,
98 : ELEKTRA_PLUGIN_ERROR, &elektraTemplateError,
99 : ELEKTRA_PLUGIN_END);
100 : }
|