Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : */
8 :
9 : #ifndef HAVE_KDBCONFIG
10 : #include "kdbconfig.h"
11 : #endif
12 :
13 : #include <stdio.h>
14 : #include <string.h>
15 :
16 : #include "counter.h"
17 :
18 : typedef int Counter;
19 : #define COUNTER_FMT "%d"
20 :
21 : static Counter elektraCountOpen = 0;
22 :
23 19 : int elektraCounterOpen (Plugin * handle, Key * errorKey ELEKTRA_UNUSED)
24 : {
25 19 : elektraCountOpen += 1;
26 19 : KeySet * config = elektraPluginGetConfig (handle);
27 19 : if (ksLookupByName (config, "/module", 0))
28 : {
29 17 : if (ksLookupByName (config, "/logmodule", 0))
30 : {
31 0 : printf ("%p elektraCounterOpen (module) called " COUNTER_FMT " times\n", (void *) handle, elektraCountOpen);
32 : }
33 : }
34 : else
35 : {
36 2 : printf ("%p elektraCounterOpen called " COUNTER_FMT " times\n", (void *) handle, elektraCountOpen);
37 : }
38 :
39 19 : return 1; /* success */
40 : }
41 :
42 : static Counter elektraCountClose = 0;
43 :
44 19 : int elektraCounterClose (Plugin * handle, Key * errorKey ELEKTRA_UNUSED)
45 : {
46 19 : elektraCountClose += 1;
47 19 : KeySet * config = elektraPluginGetConfig (handle);
48 19 : if (ksLookupByName (config, "/module", 0))
49 : {
50 17 : if (ksLookupByName (config, "/logmodule", 0))
51 : {
52 0 : printf ("%p elektraCounterClose (module) called " COUNTER_FMT " times\n", (void *) handle, elektraCountClose);
53 : }
54 : }
55 : else
56 : {
57 2 : printf ("%p elektraCounterClose called " COUNTER_FMT " times\n", (void *) handle, elektraCountClose);
58 : }
59 :
60 19 : return 1; /* success */
61 : }
62 :
63 19 : int elektraCounterGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey ELEKTRA_UNUSED)
64 : {
65 19 : if (!strcmp (keyName (parentKey), "system/elektra/modules/counter"))
66 : {
67 19 : KeySet * contract =
68 19 : ksNew (30, keyNew ("system/elektra/modules/counter", KEY_VALUE, "counter plugin waits for your orders", KEY_END),
69 : keyNew ("system/elektra/modules/counter/exports", KEY_END),
70 : keyNew ("system/elektra/modules/counter/exports/open", KEY_FUNC, elektraCounterOpen, KEY_END),
71 : keyNew ("system/elektra/modules/counter/exports/close", KEY_FUNC, elektraCounterClose, KEY_END),
72 : keyNew ("system/elektra/modules/counter/exports/get", KEY_FUNC, elektraCounterGet, KEY_END),
73 : keyNew ("system/elektra/modules/counter/exports/set", KEY_FUNC, elektraCounterSet, KEY_END),
74 : keyNew ("system/elektra/modules/counter/exports/error", KEY_FUNC, elektraCounterError, KEY_END),
75 : #include ELEKTRA_README
76 : keyNew ("system/elektra/modules/counter/infos/version", KEY_VALUE, PLUGINVERSION, KEY_END), KS_END);
77 19 : ksAppend (returned, contract);
78 19 : ksDel (contract);
79 :
80 19 : return 1; /* success */
81 : }
82 : /* get all keys */
83 :
84 : return 1; /* success */
85 : }
86 :
87 0 : int elektraCounterSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey ELEKTRA_UNUSED)
88 : {
89 : /* set all keys */
90 :
91 0 : return 1; /* success */
92 : }
93 :
94 0 : int elektraCounterError (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey ELEKTRA_UNUSED)
95 : {
96 : /* set all keys */
97 :
98 0 : return 1; /* success */
99 : }
100 :
101 19 : Plugin * ELEKTRA_PLUGIN_EXPORT
102 : {
103 : // clang-format off
104 19 : return elektraPluginExport("counter",
105 : ELEKTRA_PLUGIN_OPEN, &elektraCounterOpen,
106 : ELEKTRA_PLUGIN_CLOSE, &elektraCounterClose,
107 : ELEKTRA_PLUGIN_GET, &elektraCounterGet,
108 : ELEKTRA_PLUGIN_SET, &elektraCounterSet,
109 : ELEKTRA_PLUGIN_ERROR, &elektraCounterError,
110 : ELEKTRA_PLUGIN_END);
111 : }
112 :
|