grim/guifications3

Parents 78c35facb162
Children f7ab774df309
Implemented listening. Doesn't do anything except actually create the socket in ~/.guifications/gflib-unix, lots more work to go
--- a/gflib-unix/configure.ac Sun Jul 26 19:47:28 2009 -0500
+++ b/gflib-unix/configure.ac Sun Jul 26 23:11:55 2009 -0500
@@ -103,6 +103,14 @@
AC_SUBST(GFLIB_CFLAGS)
AC_SUBST(GFLIB_LIBS)
+if test x"${prefix}" = x"NONE" ; then
+ GFLIB_PLUGIN_DIR=`pkg-config --variable=plugin_dir gflib`
+else
+ GFLIB_PLUGIN_DIR="${prefix}/lib/guifications/"
+fi
+
+AC_SUBST(GFLIB_PLUGIN_DIR)
+
dnl #######################################################################
dnl # Finish up
dnl #######################################################################
@@ -120,5 +128,7 @@
echo;
echo Debugging enabled................: $enable_debug
echo;
+echo gflib plugin directory...........: $GFLIB_PLUGIN_DIR
+echo;
echo Type make to compile
echo;
--- a/gflib-unix/gflib-unix/Makefile.am Sun Jul 26 19:47:28 2009 -0500
+++ b/gflib-unix/gflib-unix/Makefile.am Sun Jul 26 23:11:55 2009 -0500
@@ -1,9 +1,17 @@
-EXTRA_DIST=
+EXTRA_DIST = \
+ gf_unix_errors.h \
+ gf_unix_server_connection.h \
+ gf_unix_utils.h
-lib_LTLIBRARIES = gflib-unix.la
+gflib_unixdir = $(GFLIB_PLUGIN_DIR)
+
+gflib_unix_LTLIBRARIES = gflib-unix.la
gflib_unix_la_SOURCES = \
- gf_unix_core.c
+ gf_unix_core.c \
+ gf_unix_errors.c \
+ gf_unix_server_connection.c \
+ gf_unix_utils.c
gflib_unix_la_LIBADD = \
$(GFLIB_LIBS) \
--- a/gflib-unix/gflib-unix/gf_unix_core.c Sun Jul 26 19:47:28 2009 -0500
+++ b/gflib-unix/gflib-unix/gf_unix_core.c Sun Jul 26 23:11:55 2009 -0500
@@ -22,6 +22,8 @@
#include <gflib/gf_intl.h>
#include <gflib/gf_native_plugin.h>
+#include "gf_unix_server_connection.h"
+
static gboolean initialized = FALSE;
G_MODULE_EXPORT gboolean
@@ -36,6 +38,8 @@
# endif /* HAVE_BIND_TEXTDOMAIN_CODESET */
#endif /* ENABLE_NLS */
+ gf_unix_server_connection_register_type(plugin);
+
/* and we're done... */
initialized = TRUE;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gflib-unix/gflib-unix/gf_unix_errors.c Sun Jul 26 23:11:55 2009 -0500
@@ -0,0 +1,28 @@
+/*
+ * Guifications - The end-all, be-all notification framework
+ * Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "gf_unix_errors.h"
+
+GQuark
+gf_unix_errors_quark(void) {
+ static GQuark quark = 0;
+
+ if(quark == 0)
+ quark = g_quark_from_static_string("gflib-unix-errors");
+
+ return quark;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gflib-unix/gflib-unix/gf_unix_errors.h Sun Jul 26 23:11:55 2009 -0500
@@ -0,0 +1,37 @@
+/*
+ * Guifications - The end-all, be-all notification framework
+ * Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef GF_UNIX_UTIL_H
+#define GF_UNIX_UTIL_H
+
+#include <glib.h>
+
+typedef enum {
+ FailedToCreateSocket,
+ SocketInUse,
+ FailedToBindToSocket,
+ FailedToMakeNonBlocking,
+ NoFeedsRegistered,
+ NoEventsRegistered,
+ RegistrationFailed,
+} GfUnixErrors;
+
+GQuark gf_unix_errors_quark(void);
+
+#define GF_UNIX_ERRORS (gf_unix_errors_quark())
+
+#endif /* GF_UNIX_UTIL_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gflib-unix/gflib-unix/gf_unix_server_connection.c Sun Jul 26 23:11:55 2009 -0500
@@ -0,0 +1,204 @@
+/*
+ * Guifications - The end-all, be-all notification framework
+ * Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <gflib/gf_intl.h>
+#include <gflib/gf_log.h>
+
+#include "gf_unix_errors.h"
+#include "gf_unix_server_connection.h"
+#include "gf_unix_utils.h"
+
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+#define GF_UNIX_SERVER_CONNECTION_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GF_TYPE_UNIX_SERVER_CONNECTION, GfUnixServerConnectionPrivate))
+
+/******************************************************************************
+ * Structs
+ *****************************************************************************/
+typedef struct {
+ gint fd;
+ gchar *path;
+} GfUnixServerConnectionPrivate;
+
+/******************************************************************************
+ * Globals
+ *****************************************************************************/
+static GfServerConnectionClass *parent_class = NULL;
+static GType type = 0;
+
+/******************************************************************************
+ * Connection Stuff
+ *****************************************************************************/
+static gboolean
+gf_unix_server_connection_listen(GfServerConnection *connection,
+ GError **error)
+{
+ struct sockaddr_un saddr;
+
+ GfUnixServerConnectionPrivate *priv =
+ GF_UNIX_SERVER_CONNECTION_GET_PRIVATE(connection);
+
+ gf_connection_set_state(GF_CONNECTION(connection),
+ GF_CONNECTION_STATE_CONNECTING);
+
+ priv->fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if(priv->fd == -1) {
+ *error = g_error_new(GF_UNIX_ERRORS, FailedToCreateSocket,
+ "Failed to create socket");
+
+ return FALSE;
+ }
+
+ saddr.sun_family = AF_UNIX;
+
+ priv->path = gf_unix_get_socket_path();
+ g_snprintf(saddr.sun_path, 108, "%s", priv->path);
+
+ if(access(saddr.sun_path, F_OK) == 0) {
+ if(connect(priv->fd, (struct sockaddr *)&saddr, sizeof(saddr)) != -1) {
+ /* the socket is already in use */
+ close(priv->fd);
+ priv->fd = -1;
+
+ gf_connection_set_state(GF_CONNECTION(connection),
+ GF_CONNECTION_STATE_DISCONNECTED);
+
+ *error = g_error_new(GF_UNIX_ERRORS, SocketInUse,
+ "Socket is already in use!");
+
+ return FALSE;
+ }
+
+ unlink(saddr.sun_path);
+ }
+
+ if(bind(priv->fd, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) {
+ close(priv->fd);
+ priv->fd = -1;
+
+ gf_connection_set_state(GF_CONNECTION(connection),
+ GF_CONNECTION_STATE_DISCONNECTED);
+
+ *error = g_error_new(GF_UNIX_ERRORS, FailedToBindToSocket,
+ "Failed to bind to the socket");
+
+ return FALSE;
+ }
+
+ listen(priv->fd, 5);
+
+ if(!gf_unix_fd_make_nonblocking(priv->fd)) {
+ close(priv->fd);
+ priv->fd = -1;
+
+ gf_connection_set_state(GF_CONNECTION(connection),
+ GF_CONNECTION_STATE_DISCONNECTED);
+
+ *error = g_error_new(GF_UNIX_ERRORS, FailedToMakeNonBlocking,
+ "Failed to make the socket nonblocking");
+
+ return FALSE;
+ }
+
+ gf_connection_set_state(GF_CONNECTION(connection),
+ GF_CONNECTION_STATE_CONNECTED);
+
+ return TRUE;
+}
+
+static gboolean
+gf_unix_server_connection_disconnect(GfConnection *connection, GError **error)
+{
+ return FALSE;
+}
+
+/******************************************************************************
+ * Object Stuff
+ *****************************************************************************/
+static void
+gf_unix_server_connection_finalize(GObject *obj) {
+ GfUnixServerConnectionPrivate *priv = NULL;
+
+ priv = GF_UNIX_SERVER_CONNECTION_GET_PRIVATE(obj);
+
+ G_OBJECT_CLASS(parent_class)->finalize(obj);
+}
+
+static void
+gf_unix_server_connection_class_init(GfUnixServerConnectionClass *klass) {
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+ GfNamedObjectClass *gfno_class = GF_NAMED_OBJECT_CLASS(klass);
+ GfConnectionClass *conn_class = GF_CONNECTION_CLASS(klass);
+ GfServerConnectionClass *server_class = GF_SERVER_CONNECTION_CLASS(klass);
+
+ parent_class = g_type_class_peek_parent(klass);
+
+ obj_class->finalize = gf_unix_server_connection_finalize;
+
+ g_type_class_add_private(klass, sizeof(GfUnixServerConnectionPrivate));
+
+ gfno_class->name = _("UNIX");
+
+ server_class->listen = gf_unix_server_connection_listen;
+ conn_class->disconnect = gf_unix_server_connection_disconnect;
+}
+
+/******************************************************************************
+ * Connection API
+ *****************************************************************************/
+void
+gf_unix_server_connection_register_type(GfNativePlugin *plugin) {
+ if(type == 0) {
+ static const GTypeInfo info = {
+ sizeof(GfUnixServerConnectionClass),
+ NULL,
+ NULL,
+ (GClassInitFunc)gf_unix_server_connection_class_init,
+ NULL,
+ NULL,
+ sizeof(GfUnixServerConnection),
+ 0,
+ NULL,
+ };
+
+ type = gf_native_plugin_register_type(plugin,
+ GF_TYPE_SERVER_CONNECTION,
+ "GfUnixServerConnection",
+ &info,
+ 0);
+ }
+}
+
+GType
+gf_unix_server_connection_get_type(void) {
+ if(type == 0) {
+ gf_log_warning("GfUnixServerConnection",
+ "gf_unix_server_connection_get_type called before the "
+ "type was registered!\n");
+ }
+
+ return type;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gflib-unix/gflib-unix/gf_unix_server_connection.h Sun Jul 26 23:11:55 2009 -0500
@@ -0,0 +1,60 @@
+/*
+ * Guifications - The end-all, be-all notification framework
+ * Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef GF_UNIX_SERVER_CONNECTION_H
+#define GF_UNIX_SERVER_CONNECTION_H
+
+#define GF_TYPE_UNIX_SERVER_CONNECTION (gf_unix_server_connection_get_type())
+#define GF_UNIX_SERVER_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GF_TYPE_UNIX_SERVER_CONNECTION, GfUnixServerConnection))
+#define GF_UNIX_SERVER_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GF_TYPE_UNIX_SERVER_CONNECTION, GfUnixServerConnectionClass))
+#define GF_IS_UNIX_SERVER_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GF_TYPE_UNIX_SERVER_CONNECTION))
+#define GF_IS_UNIX_SERVER_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GF_TYPE_UNIX_SERVER_CONNECTION))
+#define GF_UNIX_SERVER_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GF_TYPE_UNIX_SERVER_CONNECTION, GfUnixServerConnectionClass))
+
+typedef struct _GfUnixServerConnection GfUnixServerConnection;
+typedef struct _GfUnixServerConnectionClass GfUnixServerConnectionClass;
+
+#include <gflib/gf_server_connection.h>
+#include <gflib/gf_native_plugin.h>
+
+struct _GfUnixServerConnection {
+ GfServerConnection parent;
+
+ void (*_gf_reserved1)(void);
+ void (*_gf_reserved2)(void);
+ void (*_gf_reserved3)(void);
+ void (*_gf_reserved4)(void);
+};
+
+struct _GfUnixServerConnectionClass {
+ GfServerConnectionClass parent;
+
+ void (*_gf_reserved1)(void);
+ void (*_gf_reserved2)(void);
+ void (*_gf_reserved3)(void);
+ void (*_gf_reserved4)(void);
+};
+
+G_BEGIN_DECLS
+
+GType gf_unix_server_connection_get_type(void);
+
+void gf_unix_server_connection_register_type(GfNativePlugin *plugin);
+
+G_END_DECLS
+
+#endif /* GF_UNIX_SERVER_CONNECTION_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gflib-unix/gflib-unix/gf_unix_utils.c Sun Jul 26 23:11:55 2009 -0500
@@ -0,0 +1,52 @@
+/*
+ * Guifications - The end-all, be-all notification framework
+ * Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "gf_unix_utils.h"
+
+#include <gflib/gf_filesystem.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+gchar *
+gf_unix_get_socket_path(void) {
+ gchar *dir = NULL, *path = NULL;
+
+ dir = gf_fs_user_settings_dir();
+ path = g_build_filename(dir, "gflib-unix", NULL);
+ g_free(dir);
+
+ return path;
+}
+
+gboolean
+gf_unix_fd_make_nonblocking(gint fd) {
+ gint flags = 0;
+
+ flags = fcntl(fd, F_GETFL, 0);
+ if(flags == -1)
+ return FALSE;
+
+ flags |= O_NONBLOCK;
+
+ flags = fcntl(fd, F_SETFL, flags);
+ if(flags == -1)
+ return FALSE;
+
+ return TRUE;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gflib-unix/gflib-unix/gf_unix_utils.h Sun Jul 26 23:11:55 2009 -0500
@@ -0,0 +1,31 @@
+/*
+ * Guifications - The end-all, be-all notification framework
+ * Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef GF_UNIX_UTILS_H
+#define GF_UNIX_UTILS_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gchar *gf_unix_get_socket_path(void);
+
+gboolean gf_unix_fd_make_nonblocking(gint fd);
+
+G_END_DECLS
+
+#endif /* GF_UNIX_UTILS_H */