LCOV - code coverage report
Current view: top level - src/plugins/ccode - ccode.cpp (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 27 27 100.0 %
Date: 2019-09-12 12:28:41 Functions: 6 7 85.7 %

          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             : #include "ccode.hpp"
      10             : #include "coder.hpp"
      11             : 
      12             : #include <kdberrors.h>
      13             : #include <kdbplugin.hpp>
      14             : 
      15             : using elektra::Coder;
      16             : 
      17             : using CppKeySet = kdb::KeySet;
      18             : 
      19             : namespace
      20             : {
      21             : typedef Delegator<Coder> coderDelegator;
      22             : 
      23             : /**
      24             :  * @brief This function returns a key set containing the contract of this plugin.
      25             :  *
      26             :  * @return A contract describing the functionality of this plugin.
      27             :  */
      28         157 : inline KeySet * contract (void)
      29             : {
      30         157 :         return ksNew (30, keyNew ("system/elektra/modules/ccode", KEY_VALUE, "ccode plugin waits for your orders", KEY_END),
      31             :                       keyNew ("system/elektra/modules/ccode/exports", KEY_END),
      32             :                       keyNew ("system/elektra/modules/ccode/exports/open", KEY_FUNC, elektraCcodeOpen, KEY_END),
      33             :                       keyNew ("system/elektra/modules/ccode/exports/close", KEY_FUNC, elektraCcodeClose, KEY_END),
      34             :                       keyNew ("system/elektra/modules/ccode/exports/get", KEY_FUNC, elektraCcodeGet, KEY_END),
      35             :                       keyNew ("system/elektra/modules/ccode/exports/set", KEY_FUNC, elektraCcodeSet, KEY_END),
      36             : #include "readme_ccode.c"
      37         157 :                       keyNew ("system/elektra/modules/ccode/infos/version", KEY_VALUE, PLUGINVERSION, KEY_END), KS_END);
      38             : }
      39             : 
      40             : } // end namespace
      41             : 
      42             : extern "C" {
      43             : 
      44             : // ====================
      45             : // = Plugin Interface =
      46             : // ====================
      47             : 
      48             : /** @see elektraDocOpen */
      49         813 : int elektraCcodeOpen (Plugin * handle, Key * key)
      50             : {
      51         813 :         return coderDelegator::open (handle, key);
      52             : }
      53             : 
      54             : /** @see elektraDocClose */
      55         813 : int elektraCcodeClose (Plugin * handle ELEKTRA_UNUSED, Key * key)
      56             : {
      57         813 :         return coderDelegator::close (handle, key);
      58             : }
      59             : 
      60             : /** @see elektraDocGet */
      61         246 : int elektraCcodeGet (Plugin * handle, KeySet * returned, Key * parentKey)
      62             : {
      63         246 :         if (!strcmp (keyName (parentKey), "system/elektra/modules/ccode"))
      64             :         {
      65         157 :                 KeySet * const pluginConfig = contract ();
      66         157 :                 ksAppend (returned, pluginConfig);
      67         157 :                 ksDel (pluginConfig);
      68             :                 return ELEKTRA_PLUGIN_STATUS_SUCCESS;
      69             :         }
      70             : 
      71          89 :         CppKeySet keys{ returned };
      72         178 :         CppKeySet decoded = coderDelegator::get (handle)->decodeKeySet (keys);
      73          89 :         keys.release ();
      74          89 :         ksCopy (returned, decoded.getKeySet ());
      75          89 :         ksDel (decoded.release ());
      76             : 
      77          89 :         return ELEKTRA_PLUGIN_STATUS_SUCCESS;
      78             : }
      79             : 
      80             : /** @see elektraDocSet */
      81          46 : int elektraCcodeSet (Plugin * handle, KeySet * returned, Key * parentKey ELEKTRA_UNUSED)
      82             : {
      83          92 :         CppKeySet keys{ returned };
      84             : 
      85          92 :         CppKeySet encoded = coderDelegator::get (handle)->encodeKeySet (keys);
      86          46 :         keys.release ();
      87          46 :         ksCopy (returned, encoded.getKeySet ());
      88          46 :         ksDel (encoded.release ());
      89             : 
      90          92 :         return ELEKTRA_PLUGIN_STATUS_SUCCESS;
      91             : }
      92             : 
      93         813 : Plugin * ELEKTRA_PLUGIN_EXPORT
      94             : {
      95             :         // clang-format off
      96             :         return elektraPluginExport("ccode",
      97             :                 ELEKTRA_PLUGIN_OPEN,    &elektraCcodeOpen,
      98             :                 ELEKTRA_PLUGIN_CLOSE,   &elektraCcodeClose,
      99             :                 ELEKTRA_PLUGIN_GET,     &elektraCcodeGet,
     100             :                 ELEKTRA_PLUGIN_SET,     &elektraCcodeSet,
     101         813 :                 ELEKTRA_PLUGIN_END);
     102             : }
     103             : 
     104             : } // end extern "C"

Generated by: LCOV version 1.13