diff options
author | Richard Hughes <richard@hughsie.com> | 2007-07-13 10:31:14 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2007-07-13 10:31:14 +0100 |
commit | b919445b8c34172ab015913de2d121596908d699 (patch) | |
tree | f6c70d60ed6284a22c5e158dbc07932e62050255 | |
parent | b0fbca5136d391e191739331ef9381ba20786e20 (diff) |
add a session setter for testing
-rw-r--r-- | tools/.gitignore | 1 | ||||
-rw-r--r-- | tools/Makefile.am | 6 | ||||
-rw-r--r-- | tools/ohm-set-key.c | 82 |
3 files changed, 88 insertions, 1 deletions
diff --git a/tools/.gitignore b/tools/.gitignore index 0000bcd..845d628 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -4,6 +4,7 @@ Makefile Makefile.in libohm-test lsohm +ohm-set-key *.la *.lo *.o diff --git a/tools/Makefile.am b/tools/Makefile.am index 46fe7f5..246f012 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -6,12 +6,16 @@ INCLUDES = \ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" noinst_PROGRAMS = libohm-test -bin_PROGRAMS = lsohm +bin_PROGRAMS = lsohm ohm-set-key libohm_test_SOURCES = \ libohm-test.c libohm_test_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(top_builddir)/libohm/libohm.la +ohm_set_key_SOURCES = \ + ohm-set-key.c +ohm_set_key_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(top_builddir)/libohm/libohm.la + lsohm_SOURCES = \ lsohm.c lsohm_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(top_builddir)/libohm/libohm.la diff --git a/tools/ohm-set-key.c b/tools/ohm-set-key.c new file mode 100644 index 0000000..ccc40a5 --- /dev/null +++ b/tools/ohm-set-key.c @@ -0,0 +1,82 @@ +/* + * 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 + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <string.h> +#include <unistd.h> +#include <glib.h> + +#include <libohm.h> + +/** + * main: + **/ +int +main (int argc, char *argv[]) +{ + GError *error; + GOptionContext *context; + gboolean ret; + LibOhm *ctx; + gchar *key = NULL; + gint value = 0; + + const GOptionEntry options[] = { + { "key", '\0', 0, G_OPTION_ARG_STRING, &key, + "The public key, e.g. idle.timer_powerdown", NULL }, + { "value", '\0', 0, G_OPTION_ARG_INT, &value, + "The value of the key, e.g. 1000", NULL }, + { NULL} + }; + + context = g_option_context_new ("lsohm"); + g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); + g_option_context_parse (context, &argc, &argv, NULL); + + /* do nothing */ + if (key == NULL) + goto unref; + + g_type_init (); + ctx = libohm_new (); + error = NULL; + ret = libohm_connect (ctx, &error); + if (ret == FALSE) { + g_warning ("cannot connect to ohmd: %s", error->message); + g_error_free (error); + goto unref; + } + + /* returns list of all the LibOhmKeyValue on the system */ + error = NULL; + ret = libohm_keystore_set_key (ctx, key, value, &error); + if (ret == FALSE) { + g_warning ("cannot set key: %s", error->message); + g_error_free (error); + goto unref; + } + +unref: + g_object_unref (ctx); + return 0; +} |