Systemd/src/libudev/libudev-queue.c

225 lines
5.5 KiB
C
Raw Normal View History

2012-11-12 17:50:33 +01:00
/***
This file is part of systemd.
Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
Copyright 2009 Alan Jenkins <alan-jenkins@tuffmail.co.uk>
systemd 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.
systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
***/
2008-10-01 09:34:07 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
2008-10-01 09:34:07 +02:00
#include <sys/stat.h>
#include "libudev.h"
#include "libudev-private.h"
2009-06-15 17:09:43 +02:00
/**
* SECTION:libudev-queue
* @short_description: access to currently active events
*
* This exports the current state of the udev processing queue.
2009-06-15 17:09:43 +02:00
*/
/**
* udev_queue:
*
* Opaque object representing the current event queue in the udev daemon.
*/
2008-10-01 09:34:07 +02:00
struct udev_queue {
struct udev *udev;
int refcount;
2008-10-01 09:34:07 +02:00
};
2009-06-15 20:28:28 +02:00
/**
* udev_queue_new:
* @udev: udev library context
*
* The initial refcount is 1, and needs to be decremented to
* release the resources of the udev queue context.
*
* Returns: the udev queue context, or #NULL on error.
**/
_public_ struct udev_queue *udev_queue_new(struct udev *udev)
2008-10-01 09:34:07 +02:00
{
struct udev_queue *udev_queue;
if (udev == NULL)
return NULL;
udev_queue = new0(struct udev_queue, 1);
if (udev_queue == NULL)
return NULL;
udev_queue->refcount = 1;
udev_queue->udev = udev;
return udev_queue;
2008-10-01 09:34:07 +02:00
}
2009-06-15 20:28:28 +02:00
/**
* udev_queue_ref:
* @udev_queue: udev queue context
*
* Take a reference of a udev queue context.
*
* Returns: the same udev queue context.
**/
_public_ struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue)
2008-10-01 09:34:07 +02:00
{
if (udev_queue == NULL)
return NULL;
udev_queue->refcount++;
return udev_queue;
2008-10-01 09:34:07 +02:00
}
2009-06-15 20:28:28 +02:00
/**
* udev_queue_unref:
* @udev_queue: udev queue context
*
* Drop a reference of a udev queue context. If the refcount reaches zero,
* the resources of the queue context will be released.
2012-05-15 23:44:28 +02:00
*
* Returns: #NULL
2009-06-15 20:28:28 +02:00
**/
_public_ struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue)
2008-10-01 09:34:07 +02:00
{
if (udev_queue == NULL)
return NULL;
udev_queue->refcount--;
if (udev_queue->refcount > 0)
return NULL;
free(udev_queue);
return NULL;
2008-10-01 09:34:07 +02:00
}
2009-06-15 20:28:28 +02:00
/**
* udev_queue_get_udev:
* @udev_queue: udev queue context
*
* Retrieve the udev library context the queue context was created with.
*
* Returns: the udev library context.
**/
_public_ struct udev *udev_queue_get_udev(struct udev_queue *udev_queue)
2008-10-01 09:34:07 +02:00
{
if (udev_queue == NULL)
return NULL;
return udev_queue->udev;
2008-10-01 09:34:07 +02:00
}
2009-06-15 20:28:28 +02:00
/**
* udev_queue_get_kernel_seqnum:
* @udev_queue: udev queue context
*
* This function is deprecated.
2012-04-20 03:25:36 +02:00
*
* Returns: 0.
2009-06-15 20:28:28 +02:00
**/
_public_ unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue)
2008-10-01 09:34:07 +02:00
{
return 0;
}
2009-06-15 20:28:28 +02:00
/**
* udev_queue_get_udev_seqnum:
* @udev_queue: udev queue context
*
* This function is deprecated.
2012-04-20 03:25:36 +02:00
*
* Returns: 0.
2009-06-15 20:28:28 +02:00
**/
_public_ unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue)
{
return 0;
}
2009-06-15 20:28:28 +02:00
/**
* udev_queue_get_udev_is_active:
* @udev_queue: udev queue context
*
2012-04-20 03:25:36 +02:00
* Check if udev is active on the system.
*
2009-06-15 20:28:28 +02:00
* Returns: a flag indicating if udev is active.
**/
_public_ int udev_queue_get_udev_is_active(struct udev_queue *udev_queue)
{
return access("/run/udev/control", F_OK) >= 0;
2008-11-06 19:41:58 +01:00
}
2009-06-15 20:28:28 +02:00
/**
* udev_queue_get_queue_is_empty:
* @udev_queue: udev queue context
*
2012-04-20 03:25:36 +02:00
* Check if udev is currently processing any events.
*
2009-06-15 20:28:28 +02:00
* Returns: a flag indicating if udev is currently handling events.
**/
_public_ int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue)
2008-10-01 09:34:07 +02:00
{
return access("/run/udev/queue", F_OK) < 0;
2008-10-01 09:34:07 +02:00
}
2009-06-15 20:28:28 +02:00
/**
* udev_queue_get_seqnum_sequence_is_finished:
* @udev_queue: udev queue context
* @start: first event sequence number
* @end: last event sequence number
*
* This function is deprecated, it just returns the result of
* udev_queue_get_queue_is_empty().
2012-04-20 03:25:36 +02:00
*
* Returns: a flag indicating if udev is currently handling events.
2009-06-15 20:28:28 +02:00
**/
_public_ int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue,
unsigned long long int start, unsigned long long int end)
2008-10-01 09:34:07 +02:00
{
return udev_queue_get_queue_is_empty(udev_queue);
}
2009-06-15 20:28:28 +02:00
/**
* udev_queue_get_seqnum_is_finished:
* @udev_queue: udev queue context
* @seqnum: sequence number
*
* This function is deprecated, it just returns the result of
* udev_queue_get_queue_is_empty().
2012-04-20 03:25:36 +02:00
*
* Returns: a flag indicating if udev is currently handling events.
2009-06-15 20:28:28 +02:00
**/
_public_ int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum)
{
return udev_queue_get_queue_is_empty(udev_queue);
2008-10-01 09:34:07 +02:00
}
2009-06-15 20:28:28 +02:00
/**
* udev_queue_get_queued_list_entry:
* @udev_queue: udev queue context
*
* This function is deprecated.
2012-04-20 03:25:36 +02:00
*
* Returns: NULL.
2009-06-15 20:28:28 +02:00
**/
_public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue)
2008-10-01 09:34:07 +02:00
{
return NULL;
2008-10-01 09:34:07 +02:00
}