LCOV - code coverage report
Current view: top level - src/plugins/iterate - iterate.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 25 25 100.0 %
Date: 2019-09-12 12:28:41 Functions: 7 8 87.5 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief Source for iterate plugin
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  *
       8             :  */
       9             : 
      10             : #include "iterate.h"
      11             : 
      12             : #include <kdbhelper.h>
      13             : 
      14             : 
      15          24 : int elektraIterateOpen (Plugin * handle ELEKTRA_UNUSED, Key * errorKey ELEKTRA_UNUSED)
      16             : {
      17             :         // plugin initialization logic
      18             : 
      19          24 :         return 1; // success
      20             : }
      21             : 
      22          24 : int elektraIterateClose (Plugin * handle ELEKTRA_UNUSED, Key * errorKey ELEKTRA_UNUSED)
      23             : {
      24             :         // free all plugin resources and shut it down
      25             : 
      26          24 :         return 1; // success
      27             : }
      28             : 
      29           8 : static int doIterate (KeySet * returned)
      30             : {
      31           8 :         int ret = 0;
      32             :         Key * k;
      33          20 :         while ((k = ksNext (returned)))
      34             :         {
      35           4 :                 const Key * m = keyGetMeta (k, "iterate");
      36           4 :                 if (m)
      37             :                 {
      38           4 :                         ret = 1;
      39             :                 }
      40             :         }
      41             : 
      42           8 :         return ret;
      43             : }
      44             : 
      45          24 : int elektraIterateGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey ELEKTRA_UNUSED)
      46             : {
      47          24 :         if (!elektraStrCmp (keyName (parentKey), "system/elektra/modules/iterate"))
      48             :         {
      49          20 :                 KeySet * contract =
      50          20 :                         ksNew (30, keyNew ("system/elektra/modules/iterate", KEY_VALUE, "iterate plugin waits for your orders", KEY_END),
      51             :                                keyNew ("system/elektra/modules/iterate/exports", KEY_END),
      52             :                                keyNew ("system/elektra/modules/iterate/exports/open", KEY_FUNC, elektraIterateOpen, KEY_END),
      53             :                                keyNew ("system/elektra/modules/iterate/exports/close", KEY_FUNC, elektraIterateClose, KEY_END),
      54             :                                keyNew ("system/elektra/modules/iterate/exports/get", KEY_FUNC, elektraIterateGet, KEY_END),
      55             :                                keyNew ("system/elektra/modules/iterate/exports/set", KEY_FUNC, elektraIterateSet, KEY_END),
      56             :                                keyNew ("system/elektra/modules/iterate/exports/error", KEY_FUNC, elektraIterateError, KEY_END),
      57             : #include ELEKTRA_README
      58             :                                keyNew ("system/elektra/modules/iterate/infos/version", KEY_VALUE, PLUGINVERSION, KEY_END), KS_END);
      59          20 :                 ksAppend (returned, contract);
      60          20 :                 ksDel (contract);
      61             : 
      62          20 :                 return 1; // success
      63             :         }
      64             : 
      65           4 :         return doIterate (returned);
      66             : }
      67             : 
      68           4 : int elektraIterateSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey ELEKTRA_UNUSED)
      69             : {
      70           4 :         return doIterate (returned);
      71             : }
      72             : 
      73           2 : int elektraIterateError (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey ELEKTRA_UNUSED)
      74             : {
      75             :         // set all keys
      76             : 
      77           2 :         return 1; // success
      78             : }
      79             : 
      80          22 : Plugin * ELEKTRA_PLUGIN_EXPORT
      81             : {
      82             :         // clang-format off
      83          22 :         return elektraPluginExport ("iterate",
      84             :                 ELEKTRA_PLUGIN_OPEN,    &elektraIterateOpen,
      85             :                 ELEKTRA_PLUGIN_CLOSE,   &elektraIterateClose,
      86             :                 ELEKTRA_PLUGIN_GET,     &elektraIterateGet,
      87             :                 ELEKTRA_PLUGIN_SET,     &elektraIterateSet,
      88             :                 ELEKTRA_PLUGIN_ERROR,   &elektraIterateError,
      89             :                 ELEKTRA_PLUGIN_END);
      90             : }
      91             : 

Generated by: LCOV version 1.13