]> git.pld-linux.org Git - packages/cups.git/blame - cups-avahi-3-timeouts.patch
- use new functions
[packages/cups.git] / cups-avahi-3-timeouts.patch
CommitLineData
d07e62b1
ER
1diff -up cups-1.5.0/scheduler/cupsd.h.avahi-3-timeouts cups-1.5.0/scheduler/cupsd.h
2--- cups-1.5.0/scheduler/cupsd.h.avahi-3-timeouts 2011-05-11 23:17:34.000000000 +0100
3+++ cups-1.5.0/scheduler/cupsd.h 2011-08-05 15:06:13.570811440 +0100
4@@ -140,6 +140,15 @@ extern const char *cups_hstrerror(int);
5
6 typedef void (*cupsd_selfunc_t)(void *data);
7
8+#ifdef HAVE_AVAHI
9+/*
10+ * Timeout callback function type...
11+ */
12+
13+typedef struct _cupsd_timeout_s cupsd_timeout_t;
14+typedef void (*cupsd_timeoutfunc_t)(cupsd_timeout_t *timeout, void *data);
15+#endif /* HAVE_AVAHI */
16+
17
18 /*
19 * Globals...
20@@ -173,6 +182,11 @@ VAR int Launchd VALUE(0);
21 /* Running from launchd */
22 #endif /* HAVE_LAUNCH_H */
23
24+#ifdef HAVE_AVAHI
25+VAR cups_array_t *Timeouts; /* Timed callbacks for main loop */
26+#endif /* HAVE_AVAHI */
27+
28+
29
30 /*
31 * Prototypes...
32@@ -242,6 +256,20 @@ extern void cupsdStopSelect(void);
33 extern void cupsdStartServer(void);
34 extern void cupsdStopServer(void);
35
36+#ifdef HAVE_AVAHI
37+extern void cupsdInitTimeouts(void);
38+extern cupsd_timeout_t *cupsdAddTimeout (const struct timeval *tv,
39+ cupsd_timeoutfunc_t cb,
40+ void *data);
41+extern cupsd_timeout_t *cupsdNextTimeout (long *delay);
42+extern void cupsdRunTimeout (cupsd_timeout_t *timeout);
43+extern void cupsdUpdateTimeout (cupsd_timeout_t *timeout,
44+ const struct timeval *tv);
45+extern void cupsdRemoveTimeout (cupsd_timeout_t *timeout);
46+#endif /* HAVE_AVAHI */
47+
48+extern int cupsdRemoveFile(const char *filename);
49+
50
51 /*
52 * End of "$Id$".
53diff -up cups-1.5.0/scheduler/main.c.avahi-3-timeouts cups-1.5.0/scheduler/main.c
54--- cups-1.5.0/scheduler/main.c.avahi-3-timeouts 2011-08-05 15:05:45.590700888 +0100
55+++ cups-1.5.0/scheduler/main.c 2011-08-05 15:06:13.572811372 +0100
56@@ -146,6 +146,10 @@ main(int argc, /* I - Number of comm
57 int launchd_idle_exit;
58 /* Idle exit on select timeout? */
59 #endif /* HAVE_LAUNCHD */
60+#ifdef HAVE_AVAHI
61+ cupsd_timeout_t *tmo; /* Next scheduled timed callback */
62+ long tmo_delay; /* Time before it must be called */
63+#endif /* HAVE_AVAHI */
64
65
66 #ifdef HAVE_GETEUID
67@@ -535,6 +539,14 @@ main(int argc, /* I - Number of comm
68
69 httpInitialize();
70
71+#ifdef HAVE_AVAHI
72+ /*
73+ * Initialize timed callback structures.
74+ */
75+
76+ cupsdInitTimeouts();
77+#endif /* HAVE_AVAHI */
78+
79 cupsdStartServer();
80
81 /*
82@@ -874,6 +886,16 @@ main(int argc, /* I - Number of comm
83 }
84 #endif /* __APPLE__ */
85
86+#ifdef HAVE_AVAHI
87+ /*
88+ * If a timed callback is due, run it.
89+ */
90+
91+ tmo = cupsdNextTimeout (&tmo_delay);
92+ if (tmo && tmo_delay == 0)
93+ cupsdRunTimeout (tmo);
94+#endif /* HAVE_AVAHI */
95+
96 #ifndef __APPLE__
97 /*
98 * Update the network interfaces once a minute...
99@@ -1787,6 +1809,10 @@ select_timeout(int fds) /* I - Number
100 cupsd_job_t *job; /* Job information */
101 cupsd_subscription_t *sub; /* Subscription information */
102 const char *why; /* Debugging aid */
103+#ifdef HAVE_AVAHI
104+ cupsd_timeout_t *tmo; /* Timed callback */
105+ long tmo_delay; /* Seconds before calling it */
106+#endif /* HAVE_AVAHI */
107
108
109 /*
110@@ -1829,6 +1855,19 @@ select_timeout(int fds) /* I - Number
111 }
112 #endif /* __APPLE__ */
113
114+#ifdef HAVE_AVAHI
115+ /*
116+ * See if there are any scheduled timed callbacks to run.
117+ */
118+
119+ tmo = cupsdNextTimeout (&tmo_delay);
120+ if (tmo)
121+ {
122+ timeout = tmo_delay;
123+ why = "run a timed callback";
124+ }
125+#endif /* HAVE_AVAHI */
126+
127 /*
128 * Check whether we are accepting new connections...
129 */
130diff -up cups-1.5.0/scheduler/Makefile.avahi-3-timeouts cups-1.5.0/scheduler/Makefile
131--- cups-1.5.0/scheduler/Makefile.avahi-3-timeouts 2011-08-05 15:05:45.673698248 +0100
132+++ cups-1.5.0/scheduler/Makefile 2011-08-05 15:06:13.569811476 +0100
133@@ -39,7 +39,8 @@ CUPSDOBJS = \
134 server.o \
135 statbuf.o \
136 subscriptions.o \
137- sysman.o
138+ sysman.o \
139+ timeout.o
140 LIBOBJS = \
141 filter.o \
142 mime.o \
143diff -up cups-1.5.0/scheduler/timeout.c.avahi-3-timeouts cups-1.5.0/scheduler/timeout.c
144--- cups-1.5.0/scheduler/timeout.c.avahi-3-timeouts 2011-08-05 15:06:13.573811341 +0100
145+++ cups-1.5.0/scheduler/timeout.c 2011-08-05 15:06:13.573811341 +0100
146@@ -0,0 +1,195 @@
147+/*
148+ * "$Id$"
149+ *
150+ * Timeout functions for the Common UNIX Printing System (CUPS).
151+ *
152+ * Copyright (C) 2010 Red Hat, Inc.
153+ * Authors:
154+ * Tim Waugh <twaugh@redhat.com>
155+ *
156+ * Distribution and use rights are outlined in the file "LICENSE.txt"
157+ * which should have been included with this file. If this file is
158+ * file is missing or damaged, see the license at "http://www.cups.org/".
159+ *
160+ * Contents:
161+ *
162+ * cupsdInitTimeouts() - Initialise timeout structure.
163+ * cupsdAddTimeout() - Add a timed callback.
164+ * cupsdNextTimeout() - Find the next enabled timed callback.
165+ * cupsdUpdateTimeout() - Adjust the time of a timed callback or disable it.
166+ * cupsdRemoveTimeout() - Discard a timed callback.
167+ * compare_timeouts() - Compare timed callbacks for array sorting.
168+ */
169+
170+#include <config.h>
171+
172+#ifdef HAVE_AVAHI /* Applies to entire file... */
173+
174+/*
175+ * Include necessary headers...
176+ */
177+
178+#include "cupsd.h"
179+
180+#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
181+# include <malloc.h>
182+#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
183+
184+#ifdef HAVE_AVAHI
185+# include <avahi-common/timeval.h>
186+#endif /* HAVE_AVAHI */
187+
188+
189+struct _cupsd_timeout_s
190+{
191+ struct timeval when;
192+ int enabled;
193+ cupsd_timeoutfunc_t callback;
194+ void *data;
195+};
196+
197+/*
198+ * Local functions...
199+ */
200+
201+/*
202+ * 'compare_timeouts()' - Compare timed callbacks for array sorting.
203+ */
204+
205+static int
206+compare_timeouts (cupsd_timeout_t *p0, cupsd_timeout_t *p1)
207+{
208+ if (!p0->enabled || !p1->enabled)
209+ {
210+ if (!p0->enabled && !p1->enabled)
211+ return (0);
212+
213+ return (p0->enabled ? -1 : 1);
214+ }
215+
216+ return (avahi_timeval_compare (&p0->when, &p1->when));
217+}
218+
219+
220+/*
221+ * 'cupsdInitTimeouts()' - Initialise timeout structures.
222+ */
223+
224+void
225+cupsdInitTimeouts(void)
226+{
227+ Timeouts = cupsArrayNew ((cups_array_func_t)compare_timeouts, NULL);
228+}
229+
230+
231+/*
232+ * 'cupsdAddTimeout()' - Add a timed callback.
233+ */
234+
235+cupsd_timeout_t * /* O - Timeout handle */
236+cupsdAddTimeout(const struct timeval *tv, /* I - Absolute time */
237+ cupsd_timeoutfunc_t cb, /* I - Callback function */
238+ void *data) /* I - User data */
239+{
240+ cupsd_timeout_t *timeout;
241+
242+ timeout = malloc (sizeof(cupsd_timeout_t));
243+ if (timeout != NULL)
244+ {
245+ timeout->enabled = (tv != NULL);
246+ if (tv)
247+ {
248+ timeout->when.tv_sec = tv->tv_sec;
249+ timeout->when.tv_usec = tv->tv_usec;
250+ }
251+
252+ timeout->callback = cb;
253+ timeout->data = data;
254+ cupsArrayAdd (Timeouts, timeout);
255+ }
256+
257+ return timeout;
258+}
259+
260+
261+/*
262+ * 'cupsdNextTimeout()' - Find the next enabled timed callback.
263+ */
264+
265+cupsd_timeout_t * /* O - Next enabled timeout or NULL */
266+cupsdNextTimeout(long *delay) /* O - Seconds before scheduled */
267+{
268+ cupsd_timeout_t *first = cupsArrayFirst (Timeouts);
269+ struct timeval curtime;
270+
271+ if (first && !first->enabled)
272+ first = NULL;
273+
274+ if (first && delay)
275+ {
276+ gettimeofday (&curtime, NULL);
277+ if (avahi_timeval_compare (&curtime, &first->when) > 0)
278+ {
279+ *delay = 0;
280+ } else {
281+ *delay = 1 + first->when.tv_sec - curtime.tv_sec;
282+ if (first->when.tv_usec < curtime.tv_usec)
283+ (*delay)--;
284+ }
285+ }
286+
287+ return (first);
288+}
289+
290+
291+/*
292+ * 'cupsdRunTimeout()' - Run a timed callback.
293+ */
294+
295+void
296+cupsdRunTimeout(cupsd_timeout_t *timeout) /* I - Timeout */
297+{
298+ if (!timeout)
299+ return;
300+ timeout->enabled = 0;
301+ if (!timeout->callback)
302+ return;
303+ timeout->callback (timeout, timeout->data);
304+}
305+
306+/*
307+ * 'cupsdUpdateTimeout()' - Adjust the time of a timed callback or disable it.
308+ */
309+
310+void
311+cupsdUpdateTimeout(cupsd_timeout_t *timeout, /* I - Timeout */
312+ const struct timeval *tv) /* I - Absolute time or NULL */
313+{
314+ cupsArrayRemove (Timeouts, timeout);
315+ timeout->enabled = (tv != NULL);
316+ if (tv)
317+ {
318+ timeout->when.tv_sec = tv->tv_sec;
319+ timeout->when.tv_usec = tv->tv_usec;
320+ }
321+ cupsArrayAdd (Timeouts, timeout);
322+}
323+
324+
325+/*
326+ * 'cupsdRemoveTimeout()' - Discard a timed callback.
327+ */
328+
329+void
330+cupsdRemoveTimeout(cupsd_timeout_t *timeout) /* I - Timeout */
331+{
332+ cupsArrayRemove (Timeouts, timeout);
333+ free (timeout);
334+}
335+
336+
337+#endif /* HAVE_AVAHI ... from top of file */
338+
339+/*
340+ * End of "$Id$".
341+ */
This page took 0.060678 seconds and 4 git commands to generate.