nwfilter.c 4.15 KB
Newer Older
1 2 3 4
/*
 * nwfilter.c: virNWFilter methods
 *
 * Copyright (C) 2010 Red Hat Inc.
Chris Lalancette's avatar
Chris Lalancette committed
5
 * Copyright (C) 2013-2016 Chris Lalancette <[email protected]>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 */

#include <ruby.h>
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include "common.h"
#include "connect.h"
#include "extconf.h"

#if HAVE_TYPE_VIRNWFILTERPTR
static VALUE c_nwfilter;

Chris Lalancette's avatar
Chris Lalancette committed
32
static void nwfilter_free(void *n)
33
{
34
    ruby_libvirt_free_struct(NWFilter, n);
35 36
}

Chris Lalancette's avatar
Chris Lalancette committed
37
static virNWFilterPtr nwfilter_get(VALUE n)
38
{
39
    ruby_libvirt_get_struct(NWFilter, n);
40 41
}

42
VALUE ruby_libvirt_nwfilter_new(virNWFilterPtr n, VALUE conn)
43
{
44
    return ruby_libvirt_new_class(c_nwfilter, n, conn, nwfilter_free);
45 46 47 48 49 50
}

/*
 * call-seq:
 *   nwfilter.undefine -> nil
 *
51
 * Call virNWFilterUndefine[http://www.libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterUndefine]
52
 * to undefine the network filter.
53
 */
Chris Lalancette's avatar
Chris Lalancette committed
54
static VALUE libvirt_nwfilter_undefine(VALUE n)
55
{
56 57 58
    ruby_libvirt_generate_call_nil(virNWFilterUndefine,
                                   ruby_libvirt_connect_get(n),
                                   nwfilter_get(n));
59 60 61 62
}

/*
 * call-seq:
63
 *   nwfilter.name -> String
64
 *
65
 * Call virNWFilterGetName[http://www.libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterGetName]
66
 * to retrieve the network filter name.
67
 */
Chris Lalancette's avatar
Chris Lalancette committed
68
static VALUE libvirt_nwfilter_name(VALUE n)
69
{
70 71 72
    ruby_libvirt_generate_call_string(virNWFilterGetName,
                                      ruby_libvirt_connect_get(n), 0,
                                      nwfilter_get(n));
73 74 75 76
}

/*
 * call-seq:
77
 *   nwfilter.uuid -> String
78
 *
79
 * Call virNWFilterGetUUIDString[http://www.libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterGetUUIDString]
80
 * to retrieve the network filter UUID.
81
 */
Chris Lalancette's avatar
Chris Lalancette committed
82
static VALUE libvirt_nwfilter_uuid(VALUE n)
83
{
84 85
    ruby_libvirt_generate_uuid(virNWFilterGetUUIDString,
                               ruby_libvirt_connect_get(n), nwfilter_get(n));
86 87 88 89
}

/*
 * call-seq:
90
 *   nwfilter.xml_desc(flags=0) -> String
91
 *
92
 * Call virNWFilterGetXMLDesc[http://www.libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterGetXMLDesc]
93
 * to retrieve the XML for this network filter.
94
 */
Chris Lalancette's avatar
Chris Lalancette committed
95
static VALUE libvirt_nwfilter_xml_desc(int argc, VALUE *argv, VALUE n)
96
{
97 98 99 100
    VALUE flags;

    rb_scan_args(argc, argv, "01", &flags);

101 102
    ruby_libvirt_generate_call_string(virNWFilterGetXMLDesc,
                                      ruby_libvirt_connect_get(n), 1,
103
                                      nwfilter_get(n),
104
                                      ruby_libvirt_value_to_uint(flags));
105 106 107 108 109 110
}

/*
 * call-seq:
 *   nwfilter.free -> nil
 *
111
 * Call virNWFilterFree[http://www.libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterFree]
112 113
 * to free this network filter.  After this call the network filter object is
 * no longer valid.
114
 */
Chris Lalancette's avatar
Chris Lalancette committed
115
static VALUE libvirt_nwfilter_free(VALUE n)
116
{
117
    ruby_libvirt_generate_call_free(NWFilter, n);
118 119 120 121 122 123 124
}

#endif

/*
 * Class Libvirt::NWFilter
 */
125
void ruby_libvirt_nwfilter_init(void)
126 127 128 129 130 131 132 133 134 135 136 137 138
{
#if HAVE_TYPE_VIRNWFILTERPTR
    c_nwfilter = rb_define_class_under(m_libvirt, "NWFilter", rb_cObject);
    rb_define_attr(c_nwfilter, "connection", 1, 0);

    /* NWFilter object methods */
    rb_define_method(c_nwfilter, "undefine", libvirt_nwfilter_undefine, 0);
    rb_define_method(c_nwfilter, "name", libvirt_nwfilter_name, 0);
    rb_define_method(c_nwfilter, "uuid", libvirt_nwfilter_uuid, 0);
    rb_define_method(c_nwfilter, "xml_desc", libvirt_nwfilter_xml_desc, -1);
    rb_define_method(c_nwfilter, "free", libvirt_nwfilter_free, 0);
#endif
}