]> git.ozlabs.org Git - petitboot/commitdiff
Move waiter to library
authorGeoff Levand <geoffrey.levand@am.sony.com>
Thu, 22 Jan 2009 00:26:54 +0000 (16:26 -0800)
committerJeremy Kerr <jk@ozlabs.org>
Sun, 1 Feb 2009 00:41:41 +0000 (11:41 +1100)
Move the waiter routines into the petitboot library.  The waiter
routines are generic enough to be used for both server and
client.  Does not change the waiter source.

jk: move to lib/waiter/ instead of lib/

Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
configure.ac
discover/discover-server.c
discover/pb-discover.c
discover/udev.c
discover/waiter.c [deleted file]
discover/waiter.h [deleted file]
lib/waiter/waiter.c [new file with mode: 0644]
lib/waiter/waiter.h [new file with mode: 0644]
rules.mk

index 650d60b2fe2194dd81b90a79ccdfba5811624bd6..f06ac80112e895b15fb4ce72f413ea9bc8a00bcc 100644 (file)
@@ -31,6 +31,7 @@ AC_PROG_INSTALL
 
 PKG_CHECK_MODULES([twin], [libtwin])
 
-mkdir -p discover ui/test ui/common lib/talloc lib/pb-protocol lib/list
+mkdir -p discover ui/test ui/common lib/talloc lib/pb-protocol lib/list \
+             lib/waiter
 
 AC_OUTPUT
index b2025cce5e233e4f1232bba021303bb9733b5abe..1fab3036e9b05aa493357bfc4ba2dc08636388f1 100644 (file)
 #include <asm/byteorder.h>
 
 #include <talloc/talloc.h>
+#include <waiter/waiter.h>
 
 #include "pb-protocol/pb-protocol.h"
 #include "list/list.h"
 
 #include "log.h"
-#include "waiter.h"
 #include "device-handler.h"
 #include "discover-server.h"
 
index 56602d95d015b24b74c6976b60099993823ef745..d11ab648b745fa2a20ab6b96b92e16988de82594 100644 (file)
@@ -2,10 +2,11 @@
 #include <stdlib.h>
 #include <signal.h>
 
+#include <waiter/waiter.h>
+
 #include "udev.h"
 #include "discover-server.h"
 #include "device-handler.h"
-#include "waiter.h"
 #include "log.h"
 
 static int running;
index 6747e78a8064f7a04a5b377b3535a6a412658a71..66d9544ad81dfe21c914b5505315ac556998a650 100644 (file)
 #include <sys/un.h>
 
 #include <talloc/talloc.h>
+#include <waiter/waiter.h>
 
 #include "udev.h"
 #include "log.h"
-#include "waiter.h"
 #include "pb-discover.h"
 #include "device-handler.h"
 
diff --git a/discover/waiter.c b/discover/waiter.c
deleted file mode 100644 (file)
index 21dd4a5..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-
-#include <poll.h>
-#include <string.h>
-#include <assert.h>
-
-#include <talloc/talloc.h>
-
-#include "waiter.h"
-
-struct waiter {
-       int             fd;
-       int             events;
-       waiter_cb       callback;
-       void            *arg;
-};
-
-static struct waiter *waiters;
-static int n_waiters;
-
-struct waiter *waiter_register(int fd, int events,
-               waiter_cb callback, void *arg)
-{
-       struct waiter *waiter;
-
-       n_waiters++;
-
-       waiters = talloc_realloc(NULL, waiters, struct waiter, n_waiters);
-       waiter = &waiters[n_waiters - 1];
-
-       waiter->fd = fd;
-       waiter->events = events;
-       waiter->callback = callback;
-       waiter->arg = arg;
-
-       return 0;
-}
-
-void waiter_remove(struct waiter *waiter)
-{
-       int i;
-
-       i = waiter - waiters;
-       assert(i >= 0 && i < n_waiters);
-
-       n_waiters--;
-       memmove(&waiters[i], &waiters[i+1], n_waiters - i);
-
-       waiters = talloc_realloc(NULL, waiters, struct waiter, n_waiters);
-}
-
-int waiter_poll(void)
-{
-       static struct pollfd *pollfds;
-       static int n_pollfds;
-       int i, rc;
-
-       if (n_waiters > n_pollfds) {
-               pollfds = talloc_realloc(NULL, pollfds,
-                               struct pollfd, n_waiters);
-       }
-
-       for (i = 0; i < n_waiters; i++) {
-               pollfds[i].fd = waiters[i].fd;
-               pollfds[i].events = waiters[i].events;
-               pollfds[i].revents = 0;
-       }
-
-       rc = poll(pollfds, n_waiters, -1);
-
-       if (rc <= 0)
-               return rc;
-
-       for (i = 0; i < n_waiters; i++) {
-               if (pollfds[i].revents) {
-                       rc = waiters[i].callback(waiters[i].arg);
-
-                       if (rc)
-                               waiter_remove(&waiters[i]);
-               }
-       }
-
-       return 0;
-}
diff --git a/discover/waiter.h b/discover/waiter.h
deleted file mode 100644 (file)
index ff8a5ff..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef _WAITER_H
-#define _WAITER_H
-
-#include <poll.h>
-
-struct waiter;
-
-enum events {
-       WAIT_IN  = POLLIN,
-       WAIT_OUT = POLLOUT,
-};
-
-typedef int (*waiter_cb)(void *);
-
-struct waiter *waiter_register(int fd, int events,
-               waiter_cb callback, void *arg);
-
-void waiter_remove(struct waiter *waiter);
-
-int waiter_poll(void);
-#endif /* _WAITER_H */
-
-
diff --git a/lib/waiter/waiter.c b/lib/waiter/waiter.c
new file mode 100644 (file)
index 0000000..21dd4a5
--- /dev/null
@@ -0,0 +1,83 @@
+
+#include <poll.h>
+#include <string.h>
+#include <assert.h>
+
+#include <talloc/talloc.h>
+
+#include "waiter.h"
+
+struct waiter {
+       int             fd;
+       int             events;
+       waiter_cb       callback;
+       void            *arg;
+};
+
+static struct waiter *waiters;
+static int n_waiters;
+
+struct waiter *waiter_register(int fd, int events,
+               waiter_cb callback, void *arg)
+{
+       struct waiter *waiter;
+
+       n_waiters++;
+
+       waiters = talloc_realloc(NULL, waiters, struct waiter, n_waiters);
+       waiter = &waiters[n_waiters - 1];
+
+       waiter->fd = fd;
+       waiter->events = events;
+       waiter->callback = callback;
+       waiter->arg = arg;
+
+       return 0;
+}
+
+void waiter_remove(struct waiter *waiter)
+{
+       int i;
+
+       i = waiter - waiters;
+       assert(i >= 0 && i < n_waiters);
+
+       n_waiters--;
+       memmove(&waiters[i], &waiters[i+1], n_waiters - i);
+
+       waiters = talloc_realloc(NULL, waiters, struct waiter, n_waiters);
+}
+
+int waiter_poll(void)
+{
+       static struct pollfd *pollfds;
+       static int n_pollfds;
+       int i, rc;
+
+       if (n_waiters > n_pollfds) {
+               pollfds = talloc_realloc(NULL, pollfds,
+                               struct pollfd, n_waiters);
+       }
+
+       for (i = 0; i < n_waiters; i++) {
+               pollfds[i].fd = waiters[i].fd;
+               pollfds[i].events = waiters[i].events;
+               pollfds[i].revents = 0;
+       }
+
+       rc = poll(pollfds, n_waiters, -1);
+
+       if (rc <= 0)
+               return rc;
+
+       for (i = 0; i < n_waiters; i++) {
+               if (pollfds[i].revents) {
+                       rc = waiters[i].callback(waiters[i].arg);
+
+                       if (rc)
+                               waiter_remove(&waiters[i]);
+               }
+       }
+
+       return 0;
+}
diff --git a/lib/waiter/waiter.h b/lib/waiter/waiter.h
new file mode 100644 (file)
index 0000000..ff8a5ff
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef _WAITER_H
+#define _WAITER_H
+
+#include <poll.h>
+
+struct waiter;
+
+enum events {
+       WAIT_IN  = POLLIN,
+       WAIT_OUT = POLLOUT,
+};
+
+typedef int (*waiter_cb)(void *);
+
+struct waiter *waiter_register(int fd, int events,
+               waiter_cb callback, void *arg);
+
+void waiter_remove(struct waiter *waiter);
+
+int waiter_poll(void);
+#endif /* _WAITER_H */
+
+
index af6223beb45f8bc8117b7903d90b5bf57c5ed193..607a25ee451b2e20523c3e829aab064c6c1924de 100644 (file)
--- a/rules.mk
+++ b/rules.mk
@@ -16,6 +16,7 @@ artwork = background.jpg cdrom.png hdd.png usbpen.png tux.png cursor.gz
 
 talloc_objs = lib/talloc/talloc.o
 list_objs = lib/list/list.o
+waiter_objs = lib/waiter/waiter.o
 server_objs = lib/pb-protocol/pb-protocol.o
 parser_objs = discover/parser.o discover/parser-utils.o \
              $(foreach p, $(parsers), discover/$(p)-parser.o)
@@ -46,9 +47,9 @@ ui/test/pb-test: $(pb_test_objs)
 #            $(foreach p,$(parsers),discover/$(p)-parser.o)
 
 pb_discover_objs = discover/pb-discover.o discover/udev.o discover/log.o \
-                  discover/waiter.o discover/discover-server.o \
-                  discover/device-handler.o discover/paths.o \
-                  $(talloc_objs) $(server_objs) $(parser_objs) $(list_objs)
+                  discover/discover-server.o discover/device-handler.o \
+                  discover/paths.o $(talloc_objs) $(server_objs) \
+                  $(parser_objs) $(list_objs) $(waiter_objs)
 
 discover/pb-discover: $(pb_discover_objs)
        $(LINK.o) -o $@ $^