LCOV - code coverage report
Current view: top level - network - networkd-link-bus.c (source / functions) Hit Total Coverage
Test: systemd test coverage Lines: 6 60 10.0 %
Date: 2015-07-29 18:47:03 Functions: 1 6 16.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 2015 Tom Gundersen
       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-util.h"
      23             : #include "strv.h"
      24             : 
      25             : #include "networkd.h"
      26             : #include "networkd-link.h"
      27             : 
      28           0 : static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_operational_state, link_operstate, LinkOperationalState);
      29           0 : static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_administrative_state, link_state, LinkState);
      30             : 
      31             : const sd_bus_vtable link_vtable[] = {
      32             :         SD_BUS_VTABLE_START(0),
      33             : 
      34             :         SD_BUS_PROPERTY("OperationalState", "s", property_get_operational_state, offsetof(Link, operstate), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
      35             :         SD_BUS_PROPERTY("AdministrativeState", "s", property_get_administrative_state, offsetof(Link, state), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
      36             : 
      37             :         SD_BUS_VTABLE_END
      38             : };
      39             : 
      40           0 : static char *link_bus_path(Link *link) {
      41           0 :         _cleanup_free_ char *ifindex = NULL;
      42             :         char *p;
      43             :         int r;
      44             : 
      45           0 :         assert(link);
      46           0 :         assert(link->ifindex > 0);
      47             : 
      48           0 :         if (asprintf(&ifindex, "%d", link->ifindex) < 0)
      49           0 :                 return NULL;
      50             : 
      51           0 :         r = sd_bus_path_encode("/org/freedesktop/network1/link", ifindex, &p);
      52           0 :         if (r < 0)
      53           0 :                 return NULL;
      54             : 
      55           0 :         return p;
      56             : }
      57             : 
      58           0 : int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
      59           0 :         _cleanup_strv_free_ char **l = NULL;
      60           0 :         Manager *m = userdata;
      61             :         Link *link;
      62             :         Iterator i;
      63             :         int r;
      64             : 
      65           0 :         assert(bus);
      66           0 :         assert(path);
      67           0 :         assert(m);
      68           0 :         assert(nodes);
      69             : 
      70           0 :         HASHMAP_FOREACH(link, m->links, i) {
      71             :                 char *p;
      72             : 
      73           0 :                 p = link_bus_path(link);
      74           0 :                 if (!p)
      75           0 :                         return -ENOMEM;
      76             : 
      77           0 :                 r = strv_consume(&l, p);
      78           0 :                 if (r < 0)
      79           0 :                         return r;
      80             :         }
      81             : 
      82           0 :         *nodes = l;
      83           0 :         l = NULL;
      84             : 
      85           0 :         return 1;
      86             : }
      87             : 
      88           0 : int link_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
      89           0 :         _cleanup_free_ char *identifier = NULL;
      90           0 :         Manager *m = userdata;
      91             :         Link *link;
      92             :         int ifindex, r;
      93             : 
      94           0 :         assert(bus);
      95           0 :         assert(path);
      96           0 :         assert(interface);
      97           0 :         assert(m);
      98           0 :         assert(found);
      99             : 
     100           0 :         r = sd_bus_path_decode(path, "/org/freedesktop/network1/link", &identifier);
     101           0 :         if (r < 0)
     102           0 :                 return 0;
     103             : 
     104           0 :         r = safe_atoi(identifier, &ifindex);
     105           0 :         if (r < 0)
     106           0 :                 return 0;
     107             : 
     108           0 :         r = link_get(m, ifindex, &link);
     109           0 :         if (r < 0)
     110           0 :                 return 0;
     111             : 
     112           0 :         *found = link;
     113             : 
     114           0 :         return 1;
     115             : }
     116             : 
     117           4 : int link_send_changed(Link *link, const char *property, ...) {
     118           8 :         _cleanup_free_ char *p = NULL;
     119             :         char **l;
     120             : 
     121           4 :         assert(link);
     122           4 :         assert(link->manager);
     123             : 
     124           4 :         if (!link->manager->bus)
     125           4 :                 return 0; /* replace with assert when we have kdbus */
     126             : 
     127           0 :         l = strv_from_stdarg_alloca(property);
     128             : 
     129           0 :         p = link_bus_path(link);
     130           0 :         if (!p)
     131           0 :                 return -ENOMEM;
     132             : 
     133           0 :         return sd_bus_emit_properties_changed_strv(
     134           0 :                         link->manager->bus,
     135             :                         p,
     136             :                         "org.freedesktop.network1.Link",
     137             :                         l);
     138             : }

Generated by: LCOV version 1.11