From de306cee23d086947bf4720cee517cc3e1713591 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Tue, 18 Sep 2012 10:36:37 +0200 Subject: [PATCH] shl: move kmscon_hook_* to shl This is the last static helper that is moved so as a next step we should get rid of the "static" library entirely. Signed-off-by: David Herrmann --- Makefile.am | 9 +++-- src/eloop.c | 64 +++++++++++++++---------------- src/{static_hook.h => shl_hook.h} | 54 +++++++++++++------------- src/uterm_input.c | 16 ++++---- src/uterm_video.c | 12 +++--- src/uterm_video.h | 6 +-- 6 files changed, 82 insertions(+), 79 deletions(-) rename src/{static_hook.h => shl_hook.h} (70%) diff --git a/Makefile.am b/Makefile.am index b4bee74..446afae 100644 --- a/Makefile.am +++ b/Makefile.am @@ -93,6 +93,8 @@ SHL_TIMER = \ src/shl_timer.h SHL_LLOG = \ src/shl_llog.h +SHL_HOOK = \ + src/shl_hook.h # # libeloop @@ -106,6 +108,7 @@ lib_LTLIBRARIES += \ libeloop_la_SOURCES = \ $(SHL_DLIST) \ $(SHL_LLOG) \ + $(SHL_HOOK) \ src/static_llog.h \ src/static_hook.h \ src/eloop.h \ @@ -144,6 +147,7 @@ lib_LTLIBRARIES += \ libuterm_la_SOURCES = \ $(SHL_DLIST) \ + $(SHL_HOOK) \ src/uterm.h \ src/uterm_keysyms.h \ src/uterm_input.h \ @@ -266,6 +270,7 @@ libkmscon_core_la_SOURCES = \ $(SHL_HASHTABLE) \ $(SHL_RING) \ $(SHL_TIMER) \ + $(SHL_HOOK) \ src/main.h \ src/conf.c src/conf.h \ src/ui.c src/ui.h \ @@ -339,9 +344,7 @@ libkmscon_core_la_LIBADD = \ # simply link them statically into all other libraries/programs. # -libkmscon_static_la_SOURCES = \ - src/static_llog.h \ - src/static_hook.h +libkmscon_static_la_SOURCES = nodist_libkmscon_static_la_SOURCES = libkmscon_static_la_CPPFLAGS = \ diff --git a/src/eloop.c b/src/eloop.c index 76c7bd9..daf24b6 100644 --- a/src/eloop.c +++ b/src/eloop.c @@ -173,8 +173,8 @@ #include #include "eloop.h" #include "shl_dlist.h" +#include "shl_hook.h" #include "shl_llog.h" -#include "static_hook.h" #define LLOG_SUBSYSTEM "eloop" @@ -204,9 +204,9 @@ struct ev_eloop { int idle_fd; struct shl_dlist sig_list; - struct kmscon_hook *idlers; - struct kmscon_hook *pres; - struct kmscon_hook *posts; + struct shl_hook *idlers; + struct shl_hook *pres; + struct shl_hook *posts; bool dispatching; struct epoll_event *cur_fds; @@ -299,7 +299,7 @@ struct ev_signal_shared { struct ev_fd *fd; int signum; - struct kmscon_hook *hook; + struct shl_hook *hook; }; /* @@ -360,7 +360,7 @@ static void shared_signal_cb(struct ev_fd *fd, int mask, void *data) if (len != sizeof(info)) llog_warn(fd, "cannot read signalfd (%d): %m", errno); else - kmscon_hook_call(sig->hook, sig->fd->loop, &info); + shl_hook_call(sig->hook, sig->fd->loop, &info); if (info.ssi_signo == SIGCHLD) sig_child(fd); @@ -397,7 +397,7 @@ static int signal_new(struct ev_signal_shared **out, struct ev_eloop *loop, memset(sig, 0, sizeof(*sig)); sig->signum = signum; - ret = kmscon_hook_new(&sig->hook); + ret = shl_hook_new(&sig->hook); if (ret) goto err_free; @@ -425,7 +425,7 @@ static int signal_new(struct ev_signal_shared **out, struct ev_eloop *loop, err_sig: close(fd); err_hook: - kmscon_hook_free(sig->hook); + shl_hook_free(sig->hook); err_free: free(sig); return ret; @@ -451,7 +451,7 @@ static void signal_free(struct ev_signal_shared *sig) fd = sig->fd->fd; ev_eloop_rm_fd(sig->fd); close(fd); - kmscon_hook_free(sig->hook); + shl_hook_free(sig->hook); free(sig); /* * We do not unblock the signal here as there may be other subsystems @@ -552,8 +552,8 @@ static void eloop_idle_event(struct ev_eloop *loop, unsigned int mask) ret); goto err_out; } else if (val > 0) { - kmscon_hook_call(loop->idlers, loop, NULL); - if (kmscon_hook_num(loop->idlers) > 0) + shl_hook_call(loop->idlers, loop, NULL); + if (shl_hook_num(loop->idlers) > 0) write_eventfd(loop->llog, loop->idle_fd, 1); } @@ -602,15 +602,15 @@ int ev_eloop_new(struct ev_eloop **out, ev_log_t log) goto err_free; } - ret = kmscon_hook_new(&loop->idlers); + ret = shl_hook_new(&loop->idlers); if (ret) goto err_fds; - ret = kmscon_hook_new(&loop->pres); + ret = shl_hook_new(&loop->pres); if (ret) goto err_idlers; - ret = kmscon_hook_new(&loop->posts); + ret = shl_hook_new(&loop->posts); if (ret) goto err_pres; @@ -656,11 +656,11 @@ err_fd: err_close: close(loop->efd); err_posts: - kmscon_hook_free(loop->posts); + shl_hook_free(loop->posts); err_pres: - kmscon_hook_free(loop->pres); + shl_hook_free(loop->pres); err_idlers: - kmscon_hook_free(loop->idlers); + shl_hook_free(loop->idlers); err_fds: free(loop->cur_fds); err_free: @@ -720,9 +720,9 @@ void ev_eloop_unref(struct ev_eloop *loop) ev_fd_unref(loop->fd); close(loop->efd); - kmscon_hook_free(loop->posts); - kmscon_hook_free(loop->pres); - kmscon_hook_free(loop->idlers); + shl_hook_free(loop->posts); + shl_hook_free(loop->pres); + shl_hook_free(loop->idlers); free(loop->cur_fds); free(loop); } @@ -803,7 +803,7 @@ int ev_eloop_dispatch(struct ev_eloop *loop, int timeout) loop->dispatching = true; - kmscon_hook_call(loop->pres, loop, NULL); + shl_hook_call(loop->pres, loop, NULL); count = epoll_wait(loop->efd, loop->cur_fds, @@ -857,7 +857,7 @@ int ev_eloop_dispatch(struct ev_eloop *loop, int timeout) ret = 0; out_dispatch: - kmscon_hook_call(loop->posts, loop, NULL); + shl_hook_call(loop->posts, loop, NULL); loop->dispatching = false; return ret; } @@ -2136,7 +2136,7 @@ int ev_eloop_register_signal_cb(struct ev_eloop *loop, int signum, return ret; } - return kmscon_hook_add_cast(sig->hook, cb, data); + return shl_hook_add_cast(sig->hook, cb, data); } /** @@ -2163,8 +2163,8 @@ void ev_eloop_unregister_signal_cb(struct ev_eloop *loop, int signum, shl_dlist_for_each(iter, &loop->sig_list) { sig = shl_dlist_entry(iter, struct ev_signal_shared, list); if (sig->signum == signum) { - kmscon_hook_rm_cast(sig->hook, cb, data); - if (!kmscon_hook_num(sig->hook)) + shl_hook_rm_cast(sig->hook, cb, data); + if (!shl_hook_num(sig->hook)) signal_free(sig); return; } @@ -2198,14 +2198,14 @@ int ev_eloop_register_idle_cb(struct ev_eloop *eloop, ev_idle_cb cb, if (!eloop) return -EINVAL; - ret = kmscon_hook_add_cast(eloop->idlers, cb, data); + ret = shl_hook_add_cast(eloop->idlers, cb, data); if (ret) return ret; ret = write_eventfd(eloop->llog, eloop->idle_fd, 1); if (ret) { llog_warning(eloop, "cannot increase eloop idle-counter"); - kmscon_hook_rm_cast(eloop->idlers, cb, data); + shl_hook_rm_cast(eloop->idlers, cb, data); return ret; } @@ -2229,7 +2229,7 @@ void ev_eloop_unregister_idle_cb(struct ev_eloop *eloop, ev_idle_cb cb, if (!eloop) return; - kmscon_hook_rm_cast(eloop->idlers, cb, data); + shl_hook_rm_cast(eloop->idlers, cb, data); } /* @@ -2258,7 +2258,7 @@ int ev_eloop_register_pre_cb(struct ev_eloop *eloop, ev_idle_cb cb, if (!eloop) return -EINVAL; - return kmscon_hook_add_cast(eloop->pres, cb, data); + return shl_hook_add_cast(eloop->pres, cb, data); } /** @@ -2278,7 +2278,7 @@ void ev_eloop_unregister_pre_cb(struct ev_eloop *eloop, ev_idle_cb cb, if (!eloop) return; - kmscon_hook_rm_cast(eloop->pres, cb, data); + shl_hook_rm_cast(eloop->pres, cb, data); } /* @@ -2307,7 +2307,7 @@ int ev_eloop_register_post_cb(struct ev_eloop *eloop, ev_idle_cb cb, if (!eloop) return -EINVAL; - return kmscon_hook_add_cast(eloop->posts, cb, data); + return shl_hook_add_cast(eloop->posts, cb, data); } /** @@ -2327,5 +2327,5 @@ void ev_eloop_unregister_post_cb(struct ev_eloop *eloop, ev_idle_cb cb, if (!eloop) return; - kmscon_hook_rm_cast(eloop->posts, cb, data); + shl_hook_rm_cast(eloop->posts, cb, data); } diff --git a/src/static_hook.h b/src/shl_hook.h similarity index 70% rename from src/static_hook.h rename to src/shl_hook.h index 07c5bf1..b49668f 100644 --- a/src/static_hook.h +++ b/src/shl_hook.h @@ -1,5 +1,5 @@ /* - * kmscon - Hook Handling + * shl - Hook Handling * * Copyright (c) 2011-2012 David Herrmann * Copyright (c) 2011 University of Tuebingen @@ -28,8 +28,8 @@ * Simply hook-implementation */ -#ifndef KMSCON_STATIC_HOOK_H -#define KMSCON_STATIC_HOOK_H +#ifndef SHL_HOOK_H +#define SHL_HOOK_H #include #include @@ -38,30 +38,30 @@ #include #include -struct kmscon_hook; -struct kmscon_hook_entry; -typedef void (*kmscon_hook_cb) (void *parent, void *arg, void *data); +struct shl_hook; +struct shl_hook_entry; +typedef void (*shl_hook_cb) (void *parent, void *arg, void *data); -#define kmscon_hook_add_cast(hook, cb, data) \ - kmscon_hook_add((hook), (kmscon_hook_cb)(cb), (data)) -#define kmscon_hook_rm_cast(hook, cb, data) \ - kmscon_hook_rm((hook), (kmscon_hook_cb)(cb), (data)) +#define shl_hook_add_cast(hook, cb, data) \ + shl_hook_add((hook), (shl_hook_cb)(cb), (data)) +#define shl_hook_rm_cast(hook, cb, data) \ + shl_hook_rm((hook), (shl_hook_cb)(cb), (data)) -struct kmscon_hook_entry { - struct kmscon_hook_entry *next; - kmscon_hook_cb cb; +struct shl_hook_entry { + struct shl_hook_entry *next; + shl_hook_cb cb; void *data; }; -struct kmscon_hook { +struct shl_hook { unsigned int num; - struct kmscon_hook_entry *entries; - struct kmscon_hook_entry *cur_entry; + struct shl_hook_entry *entries; + struct shl_hook_entry *cur_entry; }; -static inline int kmscon_hook_new(struct kmscon_hook **out) +static inline int shl_hook_new(struct shl_hook **out) { - struct kmscon_hook *hook; + struct shl_hook *hook; if (!out) return -EINVAL; @@ -75,9 +75,9 @@ static inline int kmscon_hook_new(struct kmscon_hook **out) return 0; } -static inline void kmscon_hook_free(struct kmscon_hook *hook) +static inline void shl_hook_free(struct shl_hook *hook) { - struct kmscon_hook_entry *entry; + struct shl_hook_entry *entry; if (!hook) return; @@ -90,7 +90,7 @@ static inline void kmscon_hook_free(struct kmscon_hook *hook) free(hook); } -static inline unsigned int kmscon_hook_num(struct kmscon_hook *hook) +static inline unsigned int shl_hook_num(struct shl_hook *hook) { if (!hook) return 0; @@ -98,10 +98,10 @@ static inline unsigned int kmscon_hook_num(struct kmscon_hook *hook) return hook->num; } -static inline int kmscon_hook_add(struct kmscon_hook *hook, kmscon_hook_cb cb, +static inline int shl_hook_add(struct shl_hook *hook, shl_hook_cb cb, void *data) { - struct kmscon_hook_entry *entry; + struct shl_hook_entry *entry; if (!hook || !cb) return -EINVAL; @@ -119,10 +119,10 @@ static inline int kmscon_hook_add(struct kmscon_hook *hook, kmscon_hook_cb cb, return 0; } -static inline void kmscon_hook_rm(struct kmscon_hook *hook, kmscon_hook_cb cb, +static inline void shl_hook_rm(struct shl_hook *hook, shl_hook_cb cb, void *data) { - struct kmscon_hook_entry *entry, *tmp; + struct shl_hook_entry *entry, *tmp; if (!hook || !cb || !hook->entries) return; @@ -148,7 +148,7 @@ static inline void kmscon_hook_rm(struct kmscon_hook *hook, kmscon_hook_cb cb, } } -static inline void kmscon_hook_call(struct kmscon_hook *hook, void *parent, +static inline void shl_hook_call(struct shl_hook *hook, void *parent, void *arg) { if (!hook) @@ -162,4 +162,4 @@ static inline void kmscon_hook_call(struct kmscon_hook *hook, void *parent, } } -#endif /* KMSCON_STATIC_HOOK_H */ +#endif /* SHL_HOOK_H */ diff --git a/src/uterm_input.c b/src/uterm_input.c index c5e6f1e..9f1499c 100644 --- a/src/uterm_input.c +++ b/src/uterm_input.c @@ -39,7 +39,7 @@ #include "eloop.h" #include "log.h" #include "shl_dlist.h" -#include "static_hook.h" +#include "shl_hook.h" #include "uterm.h" #include "uterm_input.h" @@ -69,7 +69,7 @@ struct uterm_input { struct ev_eloop *eloop; int awake; - struct kmscon_hook *hook; + struct shl_hook *hook; struct kbd_desc *desc; struct shl_dlist devices; @@ -92,7 +92,7 @@ static void notify_key(struct uterm_input_dev *dev, if (ret) return; - kmscon_hook_call(dev->input->hook, dev->input, &ev); + shl_hook_call(dev->input->hook, dev->input, &ev); } static void input_data_dev(struct ev_fd *fd, int mask, void *data) @@ -252,7 +252,7 @@ int uterm_input_new(struct uterm_input **out, input->eloop = eloop; shl_dlist_init(&input->devices); - ret = kmscon_hook_new(&input->hook); + ret = shl_hook_new(&input->hook); if (ret) goto err_free; @@ -280,7 +280,7 @@ int uterm_input_new(struct uterm_input **out, return 0; err_hook: - kmscon_hook_free(input->hook); + shl_hook_free(input->hook); err_free: free(input); return ret; @@ -311,7 +311,7 @@ void uterm_input_unref(struct uterm_input *input) } kbd_desc_unref(input->desc); - kmscon_hook_free(input->hook); + shl_hook_free(input->hook); ev_eloop_unref(input->eloop); free(input); } @@ -409,7 +409,7 @@ int uterm_input_register_cb(struct uterm_input *input, if (!input || !cb) return -EINVAL; - return kmscon_hook_add_cast(input->hook, cb, data); + return shl_hook_add_cast(input->hook, cb, data); } void uterm_input_unregister_cb(struct uterm_input *input, @@ -419,7 +419,7 @@ void uterm_input_unregister_cb(struct uterm_input *input, if (!input || !cb) return; - kmscon_hook_rm_cast(input->hook, cb, data); + shl_hook_rm_cast(input->hook, cb, data); } void uterm_input_sleep(struct uterm_input *input) diff --git a/src/uterm_video.c b/src/uterm_video.c index 33c32c6..7d90a9e 100644 --- a/src/uterm_video.c +++ b/src/uterm_video.c @@ -37,7 +37,7 @@ #include #include "eloop.h" #include "log.h" -#include "static_hook.h" +#include "shl_hook.h" #include "uterm.h" #include "uterm_video.h" @@ -494,7 +494,7 @@ int uterm_video_new(struct uterm_video **out, video->ops = ops; video->eloop = eloop; - ret = kmscon_hook_new(&video->hook); + ret = shl_hook_new(&video->hook); if (ret) goto err_free; @@ -508,7 +508,7 @@ int uterm_video_new(struct uterm_video **out, return 0; err_hook: - kmscon_hook_free(video->hook); + shl_hook_free(video->hook); err_free: free(video); return ret; @@ -539,7 +539,7 @@ void uterm_video_unref(struct uterm_video *video) uterm_display_unref(disp); } - kmscon_hook_free(video->hook); + shl_hook_free(video->hook); ev_eloop_unref(video->eloop); free(video); } @@ -574,7 +574,7 @@ int uterm_video_register_cb(struct uterm_video *video, uterm_video_cb cb, if (!video || !cb) return -EINVAL; - return kmscon_hook_add_cast(video->hook, cb, data); + return shl_hook_add_cast(video->hook, cb, data); } void uterm_video_unregister_cb(struct uterm_video *video, uterm_video_cb cb, @@ -583,7 +583,7 @@ void uterm_video_unregister_cb(struct uterm_video *video, uterm_video_cb cb, if (!video || !cb) return; - kmscon_hook_rm_cast(video->hook, cb, data); + shl_hook_rm_cast(video->hook, cb, data); } void uterm_video_sleep(struct uterm_video *video) diff --git a/src/uterm_video.h b/src/uterm_video.h index e666852..cadfcbb 100644 --- a/src/uterm_video.h +++ b/src/uterm_video.h @@ -33,7 +33,7 @@ #include #include #include "eloop.h" -#include "static_hook.h" +#include "shl_hook.h" #include "uterm.h" /* backend-operations */ @@ -372,7 +372,7 @@ struct uterm_video { struct ev_eloop *eloop; struct uterm_display *displays; - struct kmscon_hook *hook; + struct shl_hook *hook; const struct video_ops *ops; union { @@ -392,7 +392,7 @@ static inline bool video_need_hotplug(const struct uterm_video *video) return video->flags & VIDEO_HOTPLUG; } -#define VIDEO_CB(vid, disp, act) kmscon_hook_call((vid)->hook, (vid), \ +#define VIDEO_CB(vid, disp, act) shl_hook_call((vid)->hook, (vid), \ &(struct uterm_video_hotplug){ \ .display = (disp), \ .action = (act), \