summaryrefslogtreecommitdiff
path: root/libohm
diff options
context:
space:
mode:
Diffstat (limited to 'libohm')
-rw-r--r--libohm/Makefile.am50
-rw-r--r--libohm/libohm-marshal.c87
-rw-r--r--libohm/libohm-marshal.h21
-rw-r--r--libohm/libohm-marshal.list1
-rw-r--r--libohm/libohm-test.c51
-rw-r--r--libohm/libohm.c249
-rw-r--r--libohm/libohm.h77
7 files changed, 536 insertions, 0 deletions
diff --git a/libohm/Makefile.am b/libohm/Makefile.am
new file mode 100644
index 0000000..12ca745
--- /dev/null
+++ b/libohm/Makefile.am
@@ -0,0 +1,50 @@
+INCLUDES = \
+ $(GLIB_CFLAGS) \
+ $(DBUS_CFLAGS) \
+ -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
+
+EXTRA_DIST = \
+ libohm-marshal.list
+
+lib_LTLIBRARIES=libohm.la
+
+libohmincludedir=$(includedir)/ohm
+
+libohminclude_HEADERS = \
+ libohm.h
+
+libohm_la_SOURCES = \
+ libohm-marshal.h \
+ libohm-marshal.c \
+ libohm.c \
+ libohm.h
+
+libohm_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS)
+
+libohm_la_LDFLAGS = -module -avoid-version
+#-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
+
+noinst_PROGRAMS = libohm-test
+
+libohm_test_SOURCES = \
+ libohm-test.c
+
+libohm_test_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(top_builddir)/libohm/libohm.la
+
+BUILT_SOURCES = \
+ libohm-marshal.c \
+ libohm-marshal.h
+
+libohm-marshal.c: libohm-marshal.list
+ echo "#include \"libohm-marshal.h\"" > $@ && \
+ @GLIB_GENMARSHAL@ $< --prefix=libohm_marshal --body >> $@
+
+libohm-marshal.h: libohm-marshal.list
+ @GLIB_GENMARSHAL@ $< --prefix=libohm_marshal --header > $@
+
+clean-local:
+ rm -f *~
+ rm -f libohm-marshal.c libohm-marshal.h
+
+CLEANFILES = $(BUILT_SOURCES)
diff --git a/libohm/libohm-marshal.c b/libohm/libohm-marshal.c
new file mode 100644
index 0000000..e4ef82c
--- /dev/null
+++ b/libohm/libohm-marshal.c
@@ -0,0 +1,87 @@
+#include "libohm-marshal.h"
+
+#include <glib-object.h>
+
+
+#ifdef G_ENABLE_DEBUG
+#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)
+#define g_marshal_value_peek_char(v) g_value_get_char (v)
+#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v)
+#define g_marshal_value_peek_int(v) g_value_get_int (v)
+#define g_marshal_value_peek_uint(v) g_value_get_uint (v)
+#define g_marshal_value_peek_long(v) g_value_get_long (v)
+#define g_marshal_value_peek_ulong(v) g_value_get_ulong (v)
+#define g_marshal_value_peek_int64(v) g_value_get_int64 (v)
+#define g_marshal_value_peek_uint64(v) g_value_get_uint64 (v)
+#define g_marshal_value_peek_enum(v) g_value_get_enum (v)
+#define g_marshal_value_peek_flags(v) g_value_get_flags (v)
+#define g_marshal_value_peek_float(v) g_value_get_float (v)
+#define g_marshal_value_peek_double(v) g_value_get_double (v)
+#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v)
+#define g_marshal_value_peek_param(v) g_value_get_param (v)
+#define g_marshal_value_peek_boxed(v) g_value_get_boxed (v)
+#define g_marshal_value_peek_pointer(v) g_value_get_pointer (v)
+#define g_marshal_value_peek_object(v) g_value_get_object (v)
+#else /* !G_ENABLE_DEBUG */
+/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
+ * Do not access GValues directly in your code. Instead, use the
+ * g_value_get_*() functions
+ */
+#define g_marshal_value_peek_boolean(v) (v)->data[0].v_int
+#define g_marshal_value_peek_char(v) (v)->data[0].v_int
+#define g_marshal_value_peek_uchar(v) (v)->data[0].v_uint
+#define g_marshal_value_peek_int(v) (v)->data[0].v_int
+#define g_marshal_value_peek_uint(v) (v)->data[0].v_uint
+#define g_marshal_value_peek_long(v) (v)->data[0].v_long
+#define g_marshal_value_peek_ulong(v) (v)->data[0].v_ulong
+#define g_marshal_value_peek_int64(v) (v)->data[0].v_int64
+#define g_marshal_value_peek_uint64(v) (v)->data[0].v_uint64
+#define g_marshal_value_peek_enum(v) (v)->data[0].v_long
+#define g_marshal_value_peek_flags(v) (v)->data[0].v_ulong
+#define g_marshal_value_peek_float(v) (v)->data[0].v_float
+#define g_marshal_value_peek_double(v) (v)->data[0].v_double
+#define g_marshal_value_peek_string(v) (v)->data[0].v_pointer
+#define g_marshal_value_peek_param(v) (v)->data[0].v_pointer
+#define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer
+#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer
+#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer
+#endif /* !G_ENABLE_DEBUG */
+
+
+/* NONE:STRING,INT (libohm-marshal.list:1) */
+void
+libohm_marshal_VOID__STRING_INT (GClosure *closure,
+ GValue *return_value,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint,
+ gpointer marshal_data)
+{
+ typedef void (*GMarshalFunc_VOID__STRING_INT) (gpointer data1,
+ gpointer arg_1,
+ gint arg_2,
+ gpointer data2);
+ register GMarshalFunc_VOID__STRING_INT callback;
+ register GCClosure *cc = (GCClosure*) closure;
+ register gpointer data1, data2;
+
+ g_return_if_fail (n_param_values == 3);
+
+ if (G_CCLOSURE_SWAP_DATA (closure))
+ {
+ data1 = closure->data;
+ data2 = g_value_peek_pointer (param_values + 0);
+ }
+ else
+ {
+ data1 = g_value_peek_pointer (param_values + 0);
+ data2 = closure->data;
+ }
+ callback = (GMarshalFunc_VOID__STRING_INT) (marshal_data ? marshal_data : cc->callback);
+
+ callback (data1,
+ g_marshal_value_peek_string (param_values + 1),
+ g_marshal_value_peek_int (param_values + 2),
+ data2);
+}
+
diff --git a/libohm/libohm-marshal.h b/libohm/libohm-marshal.h
new file mode 100644
index 0000000..b31e1f7
--- /dev/null
+++ b/libohm/libohm-marshal.h
@@ -0,0 +1,21 @@
+
+#ifndef __libohm_marshal_MARSHAL_H__
+#define __libohm_marshal_MARSHAL_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/* NONE:STRING,INT (libohm-marshal.list:1) */
+extern void libohm_marshal_VOID__STRING_INT (GClosure *closure,
+ GValue *return_value,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint,
+ gpointer marshal_data);
+#define libohm_marshal_NONE__STRING_INT libohm_marshal_VOID__STRING_INT
+
+G_END_DECLS
+
+#endif /* __libohm_marshal_MARSHAL_H__ */
+
diff --git a/libohm/libohm-marshal.list b/libohm/libohm-marshal.list
new file mode 100644
index 0000000..6880221
--- /dev/null
+++ b/libohm/libohm-marshal.list
@@ -0,0 +1 @@
+NONE:STRING,INT
diff --git a/libohm/libohm-test.c b/libohm/libohm-test.c
new file mode 100644
index 0000000..cffab89
--- /dev/null
+++ b/libohm/libohm-test.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2007 Richard Hughes <richard@hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <string.h>
+#include <unistd.h>
+#include <glib.h>
+
+#include "libohm.h"
+
+/**
+ * main:
+ **/
+int
+main (int argc, char *argv[])
+{
+ LibOhm *ctx;
+ gboolean ret;
+ gint value;
+
+ g_type_init ();
+
+ g_debug ("Creating ctx");
+ ctx = libohm_new ();
+
+ ret = libohm_keystore_set_key (ctx, "backlight.value_idle", 999, NULL);
+ g_debug ("ret=%i", ret);
+
+ ret = libohm_keystore_get_key (ctx, "backlight.value_idle", &value, NULL);
+ g_debug ("ret=%i, value=%i", ret, value);
+
+ g_object_unref (ctx);
+
+ return 0;
+}
diff --git a/libohm/libohm.c b/libohm/libohm.c
new file mode 100644
index 0000000..81e2040
--- /dev/null
+++ b/libohm/libohm.c
@@ -0,0 +1,249 @@
+/*
+ * Copyright (C) 2007 Richard Hughes <richard@hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <dbus/dbus-glib.h>
+
+#include "libohm.h"
+#include "libohm-marshal.h"
+#include "../ohmd/ohm-common.h"
+
+static gboolean do_trace = FALSE;
+
+static void trace (const char *format, ...)
+{
+ va_list args;
+ gchar *str;
+ FILE *out;
+
+ if (!do_trace)
+ return;
+
+ g_return_if_fail (format != NULL);
+
+ va_start(args, format);
+ str = g_strdup_vprintf(format, args);
+ va_end(args);
+
+ out = stderr;
+
+ fputs("libohm trace: ", out);
+ fputs(str, out);
+
+ g_free(str);
+}
+
+enum {
+ VALUE_CHANGED,
+ LAST_SIGNAL
+};
+
+static void libohm_class_init (LibOhmClass * klass);
+static void libohm_init (LibOhm *ctx);
+static void libohm_finalize (GObject *object);
+
+static gpointer parent_class = NULL;
+static guint signals[LAST_SIGNAL] = { 0 };
+
+GType
+libohm_get_type (void)
+{
+ static GType ctx_type = 0;
+
+ if (!ctx_type) {
+ static const GTypeInfo ctx_info = {
+ sizeof(LibOhmClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) libohm_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof(LibOhm),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) libohm_init
+ };
+
+ ctx_type = g_type_register_static(G_TYPE_OBJECT, "LibOhm", &ctx_info, 0);
+ }
+
+ return ctx_type;
+}
+
+static void
+libohm_class_init (LibOhmClass * class)
+{
+ GObjectClass *object_class;
+
+ object_class = (GObjectClass *) class;
+
+ parent_class = g_type_class_peek_parent(class);
+
+ signals[VALUE_CHANGED] =
+ g_signal_new ("value_changed",
+ G_TYPE_FROM_CLASS(object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(LibOhmClass, value_changed),
+ NULL, NULL,
+ libohm_marshal_VOID__STRING_INT,
+ G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_INT);
+
+ class->value_changed = NULL;
+
+ object_class->finalize = libohm_finalize;
+
+ if (g_getenv("LIBOHM_DEBUG_TRACE_CTX") != NULL)
+ do_trace = TRUE;
+}
+
+static void
+libohm_init (LibOhm *ctx)
+{
+ GError *error = NULL;
+
+ ctx->is_initialized = TRUE;
+ ctx->is_direct = FALSE;
+
+ gchar *direct_addr;
+ direct_addr = getenv ("OHMD_DIRECT_ADDR");
+ if (direct_addr != NULL) {
+ g_error ("got direct address of %s", direct_addr);
+// DBusGConnection * dbus_g_connection_open (const gchar *address, GError **error)
+ // Returns a connection to the given address.
+//dbus_g_proxy_new_for_peer (DBusGConnection *connection, const char *path_name, const char *interface_name)
+// Creates a proxy for an object in peer application (one we're directly connected to).
+ }
+
+ /* get the DBUS session connection */
+ ctx->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (error != NULL) {
+ g_warning ("Unable to get connection : %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ /* get the proxy with g-p-m */
+ ctx->proxy = dbus_g_proxy_new_for_name (ctx->connection,
+ OHM_DBUS_SERVICE,
+ OHM_DBUS_PATH_KEYSTORE,
+ OHM_DBUS_INTERFACE_KEYSTORE);
+ if (ctx->proxy == NULL) {
+ g_warning ("Unable to get proxy : %s", OHM_DBUS_INTERFACE_KEYSTORE);
+ return;
+ }
+ trace ("ctx created okay");
+}
+
+static void
+libohm_finalize (GObject *object)
+{
+ LibOhm *ctx = LIBOHM_CTX (object);
+
+ g_object_unref (G_OBJECT (ctx->proxy));
+ ctx->is_initialized = FALSE;
+
+ if (G_OBJECT_CLASS(parent_class)->finalize)
+ (*G_OBJECT_CLASS(parent_class)->finalize) (object);
+}
+
+LibOhm *
+libohm_new (void)
+{
+ LibOhm *ctx;
+
+ ctx = g_object_new (libohm_get_type(), NULL);
+ g_object_ref (G_OBJECT(ctx));
+
+ return ctx;
+}
+
+gboolean
+libohm_keystore_get_key (LibOhm *ctx,
+ const gchar *key,
+ gint *value,
+ GError **error)
+{
+ gboolean ret;
+
+ g_return_val_if_fail (ctx != NULL, FALSE);
+ g_return_val_if_fail (ctx->is_initialized, FALSE);
+
+ ret = dbus_g_proxy_call (ctx->proxy,
+ "GetKey", error,
+ G_TYPE_STRING, key,
+ G_TYPE_INVALID,
+ G_TYPE_INT, value,
+ G_TYPE_INVALID);
+ if (ret == FALSE) {
+ *value = 0;
+ }
+ return ret;
+}
+
+gboolean
+libohm_keystore_set_key (LibOhm *ctx,
+ const gchar *key,
+ gint value,
+ GError **error)
+{
+ gboolean ret;
+
+ g_return_val_if_fail (ctx != NULL, FALSE);
+ g_return_val_if_fail (ctx->is_initialized, FALSE);
+
+ ret = dbus_g_proxy_call (ctx->proxy,
+ "SetKey", error,
+ G_TYPE_STRING, key,
+ G_TYPE_INT, value,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ return ret;
+}
+
+gboolean
+libohm_keystore_add_notify_key (LibOhm *ctx,
+ const gchar *key,
+ GError **error)
+{
+ gboolean ret;
+
+ g_return_val_if_fail (ctx != NULL, FALSE);
+ g_return_val_if_fail (ctx->is_initialized, FALSE);
+
+ ret = dbus_g_proxy_call (ctx->proxy,
+ "AddNotifyKey", error,
+ G_TYPE_STRING, key,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ return ret;
+}
+
+#if 0
+void
+libohm_value_changed (LibOhm *ctx, const gchar *key, gint value)
+{
+ g_return_if_fail (ctx != NULL);
+ g_return_if_fail (LIBOHM_IS_CTX(ctx));
+ g_return_if_fail (key != NULL);
+
+ g_signal_emit (G_OBJECT(ctx), signals[VALUE_CHANGED], 0, key, value);
+}
+#endif
diff --git a/libohm/libohm.h b/libohm/libohm.h
new file mode 100644
index 0000000..abf03fb
--- /dev/null
+++ b/libohm/libohm.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2007 Richard Hughes <richard@hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef LIBOHM_H
+#define LIBOHM_H
+
+#include <glib-object.h>
+#include <dbus/dbus-glib.h>
+
+typedef struct _LibOhm LibOhm;
+typedef struct _LibOhmClass LibOhmClass;
+
+#define LIBOHM_GET_TYPE (libohm_get_type ())
+#define LIBOHM_CTX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LIBOHM_GET_TYPE, LibOhm))
+#define LIBOHM_CTX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LIBOHM_GET_TYPE, LibOhmClass))
+#define LIBOHM_IS_CTX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LIBOHM_GET_TYPE))
+#define LIBOHM_IS_CTX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LIBOHM_GET_TYPE))
+#define LIBOHM_CTX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LIBOHM_GET_TYPE, LibOhmClass))
+
+struct _LibOhm {
+ GObject object;
+
+ /*< private > */
+
+ gboolean is_initialized;
+ gboolean is_direct;
+ DBusGProxy *proxy;
+ DBusGConnection *connection;
+
+ gpointer pad1;
+ guint pad2;
+};
+
+struct _LibOhmClass {
+ GObjectClass parent_class;
+
+ void (*value_changed) (LibOhm *ctx, const gchar *key, gint value);
+
+ GFunc pad1;
+ GFunc pad2;
+ GFunc pad3;
+};
+
+GType libohm_get_type(void);
+
+LibOhm *libohm_new (void);
+
+gboolean libohm_keystore_get_key (LibOhm *ctx,
+ const gchar *key,
+ gint *value,
+ GError **error);
+gboolean libohm_keystore_set_key (LibOhm *ctx,
+ const gchar *key,
+ gint value,
+ GError **error);
+gboolean libohm_keystore_add_notify_key (LibOhm *ctx,
+ const gchar *key,
+ GError **error);
+
+#endif /* LIBOHM_H */