From 86dccc318096b7cd35253e47354fdd2267f5168c Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Tue, 5 Jan 2010 07:42:11 +0000 Subject: [PATCH] Add uk.me.doof.Cowsay.Dream method to implement `dream' mode --- ChangeLog | 9 ++++++++- src/Cowsay_glue.h | 5 +++-- src/cowsay.xml | 6 +++++- src/xcowsay.c | 26 +++++++++++++++++++++++--- src/xcowsayd.c | 13 ++++++++++++- 5 files changed, 51 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2e42e5e..9fa63c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-01-05 Nick Gasson + + * src/cowsayd.c (cowsay_dream): New DBus method to implement + uk.me.doof.Cowsay.Dream + * src/xcowsay.c (main): Make dream path absolute for daemon and + check file exists before going further. + 2010-01-04 Nick Gasson * src/xcowsay.c (main): Add --bubble-at option to change @@ -26,7 +33,7 @@ the daemon. (cowsay_think): New DBus method to implement uk.me.doof.Cowsay.Think - + 2010-01-03 Nick Gasson * src/xcowsay.c (main): Add --at option to specify cow location diff --git a/src/Cowsay_glue.h b/src/Cowsay_glue.h index 1602af5..b18eb8d 100644 --- a/src/Cowsay_glue.h +++ b/src/Cowsay_glue.h @@ -108,13 +108,14 @@ G_END_DECLS static const DBusGMethodInfo dbus_glib_cowsay_methods[] = { { (GCallback) cowsay_show_cow, dbus_glib_marshal_cowsay_BOOLEAN__STRING_POINTER, 0 }, { (GCallback) cowsay_think, dbus_glib_marshal_cowsay_BOOLEAN__STRING_POINTER, 38 }, + { (GCallback) cowsay_dream, dbus_glib_marshal_cowsay_BOOLEAN__STRING_POINTER, 74 }, }; const DBusGObjectInfo dbus_glib_cowsay_object_info = { 0, dbus_glib_cowsay_methods, - 2, -"uk.me.doof.Cowsay\0ShowCow\0S\0mess\0I\0s\0\0uk.me.doof.Cowsay\0Think\0S\0mess\0I\0s\0\0\0", + 3, +"uk.me.doof.Cowsay\0ShowCow\0S\0mess\0I\0s\0\0uk.me.doof.Cowsay\0Think\0S\0mess\0I\0s\0\0uk.me.doof.Cowsay\0Dream\0S\0file\0I\0s\0\0\0", "\0", "\0" }; diff --git a/src/cowsay.xml b/src/cowsay.xml index 9b221e2..d11c2eb 100644 --- a/src/cowsay.xml +++ b/src/cowsay.xml @@ -16,6 +16,10 @@ - + + + + + diff --git a/src/xcowsay.c b/src/xcowsay.c index 7d57425..648b48c 100644 --- a/src/xcowsay.c +++ b/src/xcowsay.c @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +#define _GNU_SOURCE #include #include #include @@ -22,6 +23,11 @@ #include #include +#include +#include +#include +#include + #include "display_cow.h" #include "settings.h" #include "xcowsayd.h" @@ -314,9 +320,23 @@ int main(int argc, char **argv) cowsay_init(&argc, &argv); if (dream_file != NULL) { - // COWMODE_DREAM not in daemon yet - // TODO: need to make path absolute - display_cow_or_invoke_daemon(debug, dream_file, COWMODE_DREAM); + // Make path absolute + char *wd = getcwd(NULL, 0); + char *abs_path; + + asprintf(&abs_path, "%s/%s", wd, dream_file); + free(wd); + + struct stat dummy; + if (stat(abs_path, &dummy) != 0) { + fprintf(stderr, "Error: %s: %s\n", abs_path, + strerror(errno)); + free(abs_path); + exit(EXIT_FAILURE); + } + + display_cow_or_invoke_daemon(debug, abs_path, COWMODE_DREAM); + free(abs_path); } else if (optind == argc) { read_from_stdin(mode); diff --git a/src/xcowsayd.c b/src/xcowsayd.c index 3d67c71..82ca3b5 100644 --- a/src/xcowsayd.c +++ b/src/xcowsayd.c @@ -44,6 +44,7 @@ static void cowsayd_class_init(CowsayClass *class); static gboolean cowsay_show_cow(Cowsay *obj, const gchar *mess, GError **error); static gboolean cowsay_think(Cowsay *obj, const gchar *mess, GError **error); +static gboolean cowsay_dream(Cowsay *obj, const gchar *file, GError **error); G_DEFINE_TYPE(Cowsay, cowsayd, G_TYPE_OBJECT); @@ -202,6 +203,13 @@ static gboolean cowsay_think(Cowsay *obj, const gchar *mess, GError **error) return true; } +static gboolean cowsay_dream(Cowsay *obj, const gchar *file, GError **error) +{ + printf("cowsay_dream file=%s\n", file); + enqueue_request(file, COWMODE_DREAM); + return true; +} + void run_cowsay_daemon(bool debug, int argc, char **argv) { if (!debug) { @@ -247,7 +255,8 @@ void run_cowsay_daemon(bool debug, int argc, char **argv) cowsay_init(&argc, &argv); g_type_init(); - + Cowsay *server = g_object_new(cowsayd_get_type(), NULL); + GThread *displ = g_thread_create(cow_display_thread, (gpointer)&debug, FALSE, NULL); g_assert(displ); @@ -257,6 +266,8 @@ void run_cowsay_daemon(bool debug, int argc, char **argv) g_cond_signal(display_complete); } + g_object_unref(server); + exit(EXIT_SUCCESS); } -- 2.39.2