~azzar1/snapd-glib-fork/glib-2-40

1
2
3
4
5
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * Copyright (C) 2016 Canonical Ltd.
 *
 * 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 or version 3 of the License.
 * See http://www.gnu.org/copyleft/lgpl.html the full text of the license.
 */

#include "config.h"

#include <string.h>

#include "snapd-connection.h"

struct _SnapdConnection
{
    GObject parent_instance;

    gchar *name;
    gchar *snap;
};

enum 
{
    PROP_NAME = 1,
    PROP_SNAP,
    PROP_LAST
};
 
G_DEFINE_TYPE (SnapdConnection, snapd_connection, G_TYPE_OBJECT)

/**
 * snapd_connection_get_name:
 * @connection: a #SnapdConnection.
 *
 * Returns: the name of this connection (i.e. a slot or plug name).
 */
const gchar *
snapd_connection_get_name (SnapdConnection *connection)
{
    g_return_val_if_fail (SNAPD_IS_CONNECTION (connection), NULL);
    return connection->name;
}

/**
 * snapd_connection_get_snap:
 * @connection: a #SnapdConnection.
 *
 * Returns: the snap this connection is on.
 */
const gchar *
snapd_connection_get_snap (SnapdConnection *connection)
{
    g_return_val_if_fail (SNAPD_IS_CONNECTION (connection), NULL);
    return connection->snap;
}

static void
snapd_connection_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
    SnapdConnection *connection = SNAPD_CONNECTION (object);

    switch (prop_id) {
    case PROP_NAME:
        g_free (connection->name);
        connection->name = g_strdup (g_value_get_string (value));
        break;
    case PROP_SNAP:
        g_free (connection->snap);
        connection->snap = g_strdup (g_value_get_string (value));
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        break;
    }
}

static void
snapd_connection_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
    SnapdConnection *connection = SNAPD_CONNECTION (object);

    switch (prop_id) {
    case PROP_NAME:
        g_value_set_string (value, connection->name);
        break;
    case PROP_SNAP:
        g_value_set_string (value, connection->snap);
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        break;
    }
}

static void
snapd_connection_finalize (GObject *object)
{
    SnapdConnection *connection = SNAPD_CONNECTION (object);

    g_clear_pointer (&connection->name, g_free);
    g_clear_pointer (&connection->snap, g_free);
}

static void
snapd_connection_class_init (SnapdConnectionClass *klass)
{
    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

    gobject_class->set_property = snapd_connection_set_property;
    gobject_class->get_property = snapd_connection_get_property; 
    gobject_class->finalize = snapd_connection_finalize;

    g_object_class_install_property (gobject_class,
                                     PROP_NAME,
                                     g_param_spec_string ("name",
                                                          "name",
                                                          "Name of connection/plug on snap",
                                                          NULL,
                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
    g_object_class_install_property (gobject_class,
                                     PROP_SNAP,
                                     g_param_spec_string ("snap",
                                                          "snap",
                                                          "Snap this connection is made to",
                                                          NULL,
                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}

static void
snapd_connection_init (SnapdConnection *connection)
{
}