chiark / gitweb /
eb0e096f843f44cc0f57ef012bfe83aa35fbab95
[elogind.git] / src / libudev / libudev-queue.c
1 /***
2   This file is part of systemd.
3
4   Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
5   Copyright 2009 Alan Jenkins <alan-jenkins@tuffmail.co.uk>
6
7   systemd is free software; you can redistribute it and/or modify it
8   under the terms of the GNU Lesser General Public License as published by
9   the Free Software Foundation; either version 2.1 of the License, or
10   (at your option) any later version.
11
12   systemd is distributed in the hope that it will be useful, but
13   WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   Lesser General Public License for more details.
16
17   You should have received a copy of the GNU Lesser General Public License
18   along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stddef.h>
24 #include <unistd.h>
25 #include <errno.h>
26 #include <string.h>
27 #include <limits.h>
28 #include <sys/stat.h>
29
30 #include "libudev.h"
31 #include "libudev-private.h"
32
33 /**
34  * SECTION:libudev-queue
35  * @short_description: access to currently active events
36  *
37  * This exports the current state of the udev processing queue.
38  */
39
40 /**
41  * udev_queue:
42  *
43  * Opaque object representing the current event queue in the udev daemon.
44  */
45 struct udev_queue {
46         struct udev *udev;
47         int refcount;
48 };
49
50 /**
51  * udev_queue_new:
52  * @udev: udev library context
53  *
54  * The initial refcount is 1, and needs to be decremented to
55  * release the resources of the udev queue context.
56  *
57  * Returns: the udev queue context, or #NULL on error.
58  **/
59 _public_ struct udev_queue *udev_queue_new(struct udev *udev)
60 {
61         struct udev_queue *udev_queue;
62
63         if (udev == NULL)
64                 return NULL;
65
66         udev_queue = new0(struct udev_queue, 1);
67         if (udev_queue == NULL)
68                 return NULL;
69
70         udev_queue->refcount = 1;
71         udev_queue->udev = udev;
72         return udev_queue;
73 }
74
75 /**
76  * udev_queue_ref:
77  * @udev_queue: udev queue context
78  *
79  * Take a reference of a udev queue context.
80  *
81  * Returns: the same udev queue context.
82  **/
83 _public_ struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue)
84 {
85         if (udev_queue == NULL)
86                 return NULL;
87
88         udev_queue->refcount++;
89         return udev_queue;
90 }
91
92 /**
93  * udev_queue_unref:
94  * @udev_queue: udev queue context
95  *
96  * Drop a reference of a udev queue context. If the refcount reaches zero,
97  * the resources of the queue context will be released.
98  *
99  * Returns: #NULL
100  **/
101 _public_ struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue)
102 {
103         if (udev_queue == NULL)
104                 return NULL;
105
106         udev_queue->refcount--;
107         if (udev_queue->refcount > 0)
108                 return NULL;
109
110         free(udev_queue);
111         return NULL;
112 }
113
114 /**
115  * udev_queue_get_udev:
116  * @udev_queue: udev queue context
117  *
118  * Retrieve the udev library context the queue context was created with.
119  *
120  * Returns: the udev library context.
121  **/
122 _public_ struct udev *udev_queue_get_udev(struct udev_queue *udev_queue)
123 {
124         if (udev_queue == NULL)
125                 return NULL;
126         return udev_queue->udev;
127 }
128
129 /**
130  * udev_queue_get_kernel_seqnum:
131  * @udev_queue: udev queue context
132  *
133  * This function is deprecated.
134  *
135  * Returns: 0.
136  **/
137 _public_ unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue)
138 {
139         return 0;
140 }
141
142 /**
143  * udev_queue_get_udev_seqnum:
144  * @udev_queue: udev queue context
145  *
146  * This function is deprecated.
147  *
148  * Returns: 0.
149  **/
150 _public_ unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue)
151 {
152         return 0;
153 }
154
155 /**
156  * udev_queue_get_udev_is_active:
157  * @udev_queue: udev queue context
158  *
159  * Check if udev is active on the system.
160  *
161  * Returns: a flag indicating if udev is active.
162  **/
163 _public_ int udev_queue_get_udev_is_active(struct udev_queue *udev_queue)
164 {
165         return access("/run/udev/control", F_OK) >= 0;
166 }
167
168 /**
169  * udev_queue_get_queue_is_empty:
170  * @udev_queue: udev queue context
171  *
172  * Check if udev is currently processing any events.
173  *
174  * Returns: a flag indicating if udev is currently handling events.
175  **/
176 _public_ int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue)
177 {
178         return access("/run/udev/queue", F_OK) >= 0;
179 }
180
181 /**
182  * udev_queue_get_seqnum_sequence_is_finished:
183  * @udev_queue: udev queue context
184  * @start: first event sequence number
185  * @end: last event sequence number
186  *
187  * This function is deprecated, it just returns the result of
188  * udev_queue_get_queue_is_empty().
189  *
190  * Returns: a flag indicating if udev is currently handling events.
191  **/
192 _public_ int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue,
193                                                unsigned long long int start, unsigned long long int end)
194 {
195         return udev_queue_get_queue_is_empty(udev_queue);
196 }
197
198 /**
199  * udev_queue_get_seqnum_is_finished:
200  * @udev_queue: udev queue context
201  * @seqnum: sequence number
202  *
203  * This function is deprecated, it just returns the result of
204  * udev_queue_get_queue_is_empty().
205  *
206  * Returns: a flag indicating if udev is currently handling events.
207  **/
208 _public_ int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum)
209 {
210         return udev_queue_get_queue_is_empty(udev_queue);
211 }
212
213 /**
214  * udev_queue_get_queued_list_entry:
215  * @udev_queue: udev queue context
216  *
217  * This function is deprecated.
218  *
219  * Returns: NULL.
220  **/
221 _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue)
222 {
223         return NULL;
224 }