libpolkit-seat.c 3.57 KB
Newer Older
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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/***************************************************************************
 *
 * libpolkit-seat.c : seat
 *
 * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
 *
 * Licensed under the Academic Free License version 2.1
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307	 USA
 *
 **************************************************************************/

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
#include <unistd.h>
#include <errno.h>

#include <glib.h>
#include "libpolkit-seat.h"

David Zeuthen's avatar
David Zeuthen committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55
/**
 * SECTION:libpolkit-seat
 * @short_description: Seats.
 *
 * This class is used to represent a seat. TODO: describe seat.
 **/

/**
 * PolKitSeat:
 *
 * Objects of this class are used to record information about a
 * seat.
 **/
struct PolKitSeat
56
{
57 58
        int refcount;
        char *ck_objref;
59 60
};

David Zeuthen's avatar
David Zeuthen committed
61 62 63 64 65 66 67
/**
 * libpolkit_seat_new:
 * 
 * Creates a new #PolKitSeat object.
 * 
 * Returns: the new object
 **/
68 69 70
PolKitSeat *
libpolkit_seat_new (void)
{
71 72 73 74
        PolKitSeat *seat;
        seat = g_new0 (PolKitSeat, 1);
        seat->refcount = 1;
        return seat;
75 76
}

David Zeuthen's avatar
David Zeuthen committed
77 78 79 80 81 82 83 84
/**
 * libpolkit_seat_ref:
 * @seat: the seat object
 * 
 * Increase reference count.
 * 
 * Returns: the object
 **/
85 86 87
PolKitSeat *
libpolkit_seat_ref (PolKitSeat *seat)
{
88 89
        g_return_val_if_fail (seat != NULL, seat);
        seat->refcount++;
90 91 92
        return seat;
}

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
/**
 * libpolkit_seat_unref:
 * @seat: the seat object
 * 
 * Decreases the reference count of the object. If it becomes zero,
 * the object is freed. Before freeing, reference counts on embedded
 * objects are decresed by one.
 **/
void
libpolkit_seat_unref (PolKitSeat *seat)
{
        g_return_if_fail (seat != NULL);
        seat->refcount--;
        if (seat->refcount > 0) 
                return;
        g_free (seat->ck_objref);
        g_free (seat);
}

David Zeuthen's avatar
David Zeuthen committed
112 113 114 115 116 117 118
/**
 * libpolkit_seat_set_ck_objref:
 * @seat: the seat object
 * @ck_objref: the D-Bus object path to the ConsoleKit seat object
 * 
 * Set the D-Bus object path to the ConsoleKit seat object.
 **/
119 120 121
void 
libpolkit_seat_set_ck_objref (PolKitSeat *seat, const char *ck_objref)
{
122
        g_return_if_fail (seat != NULL);
123
        if (seat->ck_objref != NULL)
124 125
                g_free (seat->ck_objref);
        seat->ck_objref = g_strdup (ck_objref);
126 127
}

David Zeuthen's avatar
David Zeuthen committed
128 129 130 131 132 133 134 135 136
/**
 * libpolkit_seat_get_ck_objref:
 * @seat: the seat object
 * @out_ck_objref: Returns the D-Bus object path to the ConsoleKit seat object. The caller shall not free this string.
 * 
 * Get the D-Bus object path to the ConsoleKit seat object.
 * 
 * Returns: TRUE iff the value is returned
 **/
137 138 139
gboolean
libpolkit_seat_get_ck_objref (PolKitSeat *seat, char **out_ck_objref)
{
140 141 142 143
        g_return_val_if_fail (seat != NULL, FALSE);
        g_return_val_if_fail (out_ck_objref != NULL, FALSE);
        *out_ck_objref = seat->ck_objref;
        return TRUE;
144
}