LCOV - code coverage report
Current view: top level - libsystemd/sd-bus - bus-type.c (source / functions) Hit Total Coverage
Test: systemd test coverage Lines: 17 24 70.8 %
Date: 2015-07-29 18:47:03 Functions: 6 7 85.7 %

          Line data    Source code
       1             : /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
       2             : 
       3             : /***
       4             :   This file is part of systemd.
       5             : 
       6             :   Copyright 2013 Lennart Poettering
       7             : 
       8             :   systemd is free software; you can redistribute it and/or modify it
       9             :   under the terms of the GNU Lesser General Public License as published by
      10             :   the Free Software Foundation; either version 2.1 of the License, or
      11             :   (at your option) any later version.
      12             : 
      13             :   systemd is distributed in the hope that it will be useful, but
      14             :   WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      16             :   Lesser General Public License for more details.
      17             : 
      18             :   You should have received a copy of the GNU Lesser General Public License
      19             :   along with systemd; If not, see <http://www.gnu.org/licenses/>.
      20             : ***/
      21             : 
      22             : #include "bus-type.h"
      23             : 
      24           5 : bool bus_type_is_valid(char c) {
      25             :         static const char valid[] = {
      26             :                 SD_BUS_TYPE_BYTE,
      27             :                 SD_BUS_TYPE_BOOLEAN,
      28             :                 SD_BUS_TYPE_INT16,
      29             :                 SD_BUS_TYPE_UINT16,
      30             :                 SD_BUS_TYPE_INT32,
      31             :                 SD_BUS_TYPE_UINT32,
      32             :                 SD_BUS_TYPE_INT64,
      33             :                 SD_BUS_TYPE_UINT64,
      34             :                 SD_BUS_TYPE_DOUBLE,
      35             :                 SD_BUS_TYPE_STRING,
      36             :                 SD_BUS_TYPE_OBJECT_PATH,
      37             :                 SD_BUS_TYPE_SIGNATURE,
      38             :                 SD_BUS_TYPE_ARRAY,
      39             :                 SD_BUS_TYPE_VARIANT,
      40             :                 SD_BUS_TYPE_STRUCT,
      41             :                 SD_BUS_TYPE_DICT_ENTRY,
      42             :                 SD_BUS_TYPE_UNIX_FD
      43             :         };
      44             : 
      45           5 :         return !!memchr(valid, c, sizeof(valid));
      46             : }
      47             : 
      48           0 : bool bus_type_is_valid_in_signature(char c) {
      49             :         static const char valid[] = {
      50             :                 SD_BUS_TYPE_BYTE,
      51             :                 SD_BUS_TYPE_BOOLEAN,
      52             :                 SD_BUS_TYPE_INT16,
      53             :                 SD_BUS_TYPE_UINT16,
      54             :                 SD_BUS_TYPE_INT32,
      55             :                 SD_BUS_TYPE_UINT32,
      56             :                 SD_BUS_TYPE_INT64,
      57             :                 SD_BUS_TYPE_UINT64,
      58             :                 SD_BUS_TYPE_DOUBLE,
      59             :                 SD_BUS_TYPE_STRING,
      60             :                 SD_BUS_TYPE_OBJECT_PATH,
      61             :                 SD_BUS_TYPE_SIGNATURE,
      62             :                 SD_BUS_TYPE_ARRAY,
      63             :                 SD_BUS_TYPE_VARIANT,
      64             :                 SD_BUS_TYPE_STRUCT_BEGIN,
      65             :                 SD_BUS_TYPE_STRUCT_END,
      66             :                 SD_BUS_TYPE_DICT_ENTRY_BEGIN,
      67             :                 SD_BUS_TYPE_DICT_ENTRY_END,
      68             :                 SD_BUS_TYPE_UNIX_FD
      69             :         };
      70             : 
      71           0 :         return !!memchr(valid, c, sizeof(valid));
      72             : }
      73             : 
      74      276055 : bool bus_type_is_basic(char c) {
      75             :         static const char valid[] = {
      76             :                 SD_BUS_TYPE_BYTE,
      77             :                 SD_BUS_TYPE_BOOLEAN,
      78             :                 SD_BUS_TYPE_INT16,
      79             :                 SD_BUS_TYPE_UINT16,
      80             :                 SD_BUS_TYPE_INT32,
      81             :                 SD_BUS_TYPE_UINT32,
      82             :                 SD_BUS_TYPE_INT64,
      83             :                 SD_BUS_TYPE_UINT64,
      84             :                 SD_BUS_TYPE_DOUBLE,
      85             :                 SD_BUS_TYPE_STRING,
      86             :                 SD_BUS_TYPE_OBJECT_PATH,
      87             :                 SD_BUS_TYPE_SIGNATURE,
      88             :                 SD_BUS_TYPE_UNIX_FD
      89             :         };
      90             : 
      91      276055 :         return !!memchr(valid, c, sizeof(valid));
      92             : }
      93             : 
      94       15491 : bool bus_type_is_trivial(char c) {
      95             :         static const char valid[] = {
      96             :                 SD_BUS_TYPE_BYTE,
      97             :                 SD_BUS_TYPE_BOOLEAN,
      98             :                 SD_BUS_TYPE_INT16,
      99             :                 SD_BUS_TYPE_UINT16,
     100             :                 SD_BUS_TYPE_INT32,
     101             :                 SD_BUS_TYPE_UINT32,
     102             :                 SD_BUS_TYPE_INT64,
     103             :                 SD_BUS_TYPE_UINT64,
     104             :                 SD_BUS_TYPE_DOUBLE
     105             :         };
     106             : 
     107       15491 :         return !!memchr(valid, c, sizeof(valid));
     108             : }
     109             : 
     110         732 : bool bus_type_is_container(char c) {
     111             :         static const char valid[] = {
     112             :                 SD_BUS_TYPE_ARRAY,
     113             :                 SD_BUS_TYPE_VARIANT,
     114             :                 SD_BUS_TYPE_STRUCT,
     115             :                 SD_BUS_TYPE_DICT_ENTRY
     116             :         };
     117             : 
     118         732 :         return !!memchr(valid, c, sizeof(valid));
     119             : }
     120             : 
     121          63 : int bus_type_get_alignment(char c) {
     122             : 
     123          63 :         switch (c) {
     124             :         case SD_BUS_TYPE_BYTE:
     125             :         case SD_BUS_TYPE_SIGNATURE:
     126             :         case SD_BUS_TYPE_VARIANT:
     127           2 :                 return 1;
     128             : 
     129             :         case SD_BUS_TYPE_INT16:
     130             :         case SD_BUS_TYPE_UINT16:
     131           0 :                 return 2;
     132             : 
     133             :         case SD_BUS_TYPE_BOOLEAN:
     134             :         case SD_BUS_TYPE_INT32:
     135             :         case SD_BUS_TYPE_UINT32:
     136             :         case SD_BUS_TYPE_STRING:
     137             :         case SD_BUS_TYPE_OBJECT_PATH:
     138             :         case SD_BUS_TYPE_ARRAY:
     139             :         case SD_BUS_TYPE_UNIX_FD:
     140          18 :                 return 4;
     141             : 
     142             :         case SD_BUS_TYPE_INT64:
     143             :         case SD_BUS_TYPE_UINT64:
     144             :         case SD_BUS_TYPE_DOUBLE:
     145             :         case SD_BUS_TYPE_STRUCT:
     146             :         case SD_BUS_TYPE_STRUCT_BEGIN:
     147             :         case SD_BUS_TYPE_DICT_ENTRY:
     148             :         case SD_BUS_TYPE_DICT_ENTRY_BEGIN:
     149          43 :                 return 8;
     150             :         }
     151             : 
     152           0 :         return -EINVAL;
     153             : }
     154             : 
     155          11 : int bus_type_get_size(char c) {
     156             : 
     157          11 :         switch (c) {
     158             :         case SD_BUS_TYPE_BYTE:
     159           2 :                 return 1;
     160             : 
     161             :         case SD_BUS_TYPE_INT16:
     162             :         case SD_BUS_TYPE_UINT16:
     163           0 :                 return 2;
     164             : 
     165             :         case SD_BUS_TYPE_BOOLEAN:
     166             :         case SD_BUS_TYPE_INT32:
     167             :         case SD_BUS_TYPE_UINT32:
     168             :         case SD_BUS_TYPE_UNIX_FD:
     169           9 :                 return 4;
     170             : 
     171             :         case SD_BUS_TYPE_INT64:
     172             :         case SD_BUS_TYPE_UINT64:
     173             :         case SD_BUS_TYPE_DOUBLE:
     174           0 :                 return 8;
     175             :         }
     176             : 
     177           0 :         return -EINVAL;
     178             : }

Generated by: LCOV version 1.11