diff options
author | David Zeuthen <davidz@redhat.com> | 2010-10-09 09:05:19 -0400 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2010-10-09 09:05:19 -0400 |
commit | 7cb53e7dbbb420fb69e74944b701a40fc2cb411a (patch) | |
tree | 1f502e2bdf4c33c400e51d0e0fb6a0f2c496f872 | |
parent | 3c11729c2bb78ed9de9883b17a01f35bafd31632 (diff) |
Nuke stc_monitor_new_with_config_dir() - use STC_CONFIG_DIR envvar instead
Signed-off-by: David Zeuthen <davidz@redhat.com>
-rw-r--r-- | doc/stc-docs.xml | 18 | ||||
-rw-r--r-- | doc/stc-sections.txt | 2 | ||||
-rw-r--r-- | stc/stcmonitor.c | 80 | ||||
-rw-r--r-- | stc/stcmonitor.h | 4 | ||||
-rw-r--r-- | stc/test.c | 18 |
5 files changed, 33 insertions, 89 deletions
diff --git a/doc/stc-docs.xml b/doc/stc-docs.xml index e90fea8..cd6addb 100644 --- a/doc/stc-docs.xml +++ b/doc/stc-docs.xml @@ -12,6 +12,24 @@ <part> <title>Introduction</title> + + <chapter> + <title>Running stc applications</title> + <para> + Applications using <literal>libstc-1</literal> is influenced + by the following environment variables: + </para> + + <formalpara> + <title><envar>STC_CONFIG_DIR</envar></title> + <para> + This is used to load the <filename>stc.conf</filename> and + <filename>stc.conf.d/*.conf</filename> configuration files. If + not set, the path <filename>/etc</filename> is used. + </para> + </formalpara> + </chapter> + </part> <part> diff --git a/doc/stc-sections.txt b/doc/stc-sections.txt index db7c608..685f97f 100644 --- a/doc/stc-sections.txt +++ b/doc/stc-sections.txt @@ -4,8 +4,6 @@ StcMonitor StcErrorHandlerFunc stc_monitor_new -stc_monitor_new_for_config_dir -stc_monitor_get_config_dir stc_monitor_get_items stc_monitor_get_item_by_id <SUBSECTION Standard> diff --git a/stc/stcmonitor.c b/stc/stcmonitor.c index 4877957..db17251 100644 --- a/stc/stcmonitor.c +++ b/stc/stcmonitor.c @@ -51,6 +51,8 @@ struct _StcMonitor { GObject parent_instance; + gchar *config_dir; + GUdevClient *gudev_client; _StcMountMonitor *mount_monitor; @@ -59,8 +61,6 @@ struct _StcMonitor StcErrorHandlerFunc error_handler_func; gpointer error_handler_user_data; - gchar *config_dir; - GList *items; GHashTable *map_id_to_item; @@ -85,7 +85,6 @@ struct _StcMonitorClass enum { PROP_0, - PROP_CONFIG_DIR, PROP_ERROR_HANDLER_FUNC, PROP_ERROR_HANDLER_USER_DATA }; @@ -172,11 +171,12 @@ stc_monitor_finalize (GObject *object) g_signal_handlers_disconnect_by_func (monitor->conf_dir_monitor, G_CALLBACK (on_conf_dir_monitor_changed), monitor); g_object_unref (monitor->conf_dir_monitor); } - g_free (monitor->config_dir); g_list_foreach (monitor->items, (GFunc) g_object_unref, NULL); g_list_free (monitor->items); g_hash_table_unref (monitor->map_id_to_item); + g_free (monitor->config_dir); + if (G_OBJECT_CLASS (stc_monitor_parent_class)->finalize) G_OBJECT_CLASS (stc_monitor_parent_class)->finalize (object); } @@ -191,10 +191,6 @@ stc_monitor_get_property (GObject *object, switch (prop_id) { - case PROP_CONFIG_DIR: - g_value_set_string (value, stc_monitor_get_config_dir (monitor)); - break; - case PROP_ERROR_HANDLER_FUNC: g_value_set_pointer (value, monitor->error_handler_func); break; @@ -219,12 +215,6 @@ stc_monitor_set_property (GObject *object, switch (prop_id) { - case PROP_CONFIG_DIR: - g_assert (monitor->config_dir == NULL); - monitor->config_dir = g_value_dup_string (value); - g_assert (monitor->config_dir != NULL); - break; - case PROP_ERROR_HANDLER_FUNC: monitor->error_handler_func = g_value_get_pointer (value); break; @@ -260,6 +250,10 @@ stc_monitor_constructed (GObject *object) g_return_if_fail (STC_IS_MONITOR (monitor)); + monitor->config_dir = g_strdup (g_getenv ("STC_CONFIG_DIR")); + if (monitor->config_dir == NULL) + monitor->config_dir = g_strdup (PACKAGE_SYSCONF_DIR); + path = g_strdup_printf ("%s/stc.conf", monitor->config_dir); file = g_file_new_for_path (path); error = NULL; @@ -334,22 +328,6 @@ stc_monitor_class_init (StcMonitorClass *klass) gobject_class->set_property = stc_monitor_set_property; /** - * StcMonitor:config-dir: - * - * The path for the configuration directory. - */ - g_object_class_install_property (gobject_class, - PROP_CONFIG_DIR, - g_param_spec_string ("config-dir", - "Configuration Directory", - "The configuration directory", - PACKAGE_SYSCONF_DIR, - G_PARAM_READABLE | - G_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - /** * StcMonitor:error-handler-func: * * Pointer to a #StcErrorHandlerFunc to call on error, or %NULL. @@ -459,48 +437,6 @@ stc_monitor_new (StcErrorHandlerFunc error_handler_func, } /** - * stc_monitor_new_for_config_dir: - * @config_dir: A path to where the <filename>stc.conf</filename> is stored. - * @error_handler_func: A function to handle errors or %NULL. - * @error_handler_user_data: The @user_data #gpointer to pass to @error_handler_func. - * - * Creates a new #StcMonitor. - * - * Returns: A #StcMonitor. Free with g_object_unref(). - */ -StcMonitor * -stc_monitor_new_for_config_dir (const gchar *config_dir, - StcErrorHandlerFunc error_handler_func, - gpointer error_handler_user_data) -{ - StcMonitor *monitor; - - g_return_val_if_fail (config_dir != NULL, NULL); - - monitor = STC_MONITOR (g_object_new (STC_TYPE_MONITOR, - "config-dir", config_dir, - "error-handler-func", error_handler_func, - "error-handler-user-data", error_handler_user_data, - NULL)); - return monitor; -} - -/** - * stc_monitor_get_config_dir: - * @monitor: A #StcMonitor. - * - * Gets the configuration directory used by @monitor. - * - * Returns: A directory name. Do not free, the string is owned by @monitor. - */ -const gchar * -stc_monitor_get_config_dir (StcMonitor *monitor) -{ - g_return_val_if_fail (STC_IS_MONITOR (monitor), NULL); - return monitor->config_dir; -} - -/** * stc_monitor_get_items: * @monitor: An active #StcMonitor. * diff --git a/stc/stcmonitor.h b/stc/stcmonitor.h index 66057d0..69be93e 100644 --- a/stc/stcmonitor.h +++ b/stc/stcmonitor.h @@ -59,10 +59,6 @@ typedef void (*StcErrorHandlerFunc) (StcMonitor *monitor, GType stc_monitor_get_type (void) G_GNUC_CONST; StcMonitor *stc_monitor_new (StcErrorHandlerFunc error_handler_func, gpointer error_handler_user_data); -StcMonitor *stc_monitor_new_for_config_dir (const gchar *config_dir, - StcErrorHandlerFunc error_handler_func, - gpointer error_handler_user_data); -const gchar *stc_monitor_get_config_dir (StcMonitor *monitor); GList *stc_monitor_get_items (StcMonitor *monitor); StcItem *stc_monitor_get_item_by_id (StcMonitor *monitor, const gchar *item_id); @@ -144,11 +144,6 @@ test_stc_basic (void) StcMonitor *monitor; monitor = stc_monitor_new (NULL, NULL); - g_assert_cmpstr (stc_monitor_get_config_dir (monitor), ==, PACKAGE_SYSCONF_DIR); - g_object_unref (monitor); - - monitor = stc_monitor_new_for_config_dir (SRCDIR, NULL, NULL); - g_assert_cmpstr (stc_monitor_get_config_dir (monitor), ==, SRCDIR); g_object_unref (monitor); } @@ -158,9 +153,10 @@ test_stc_no_conf (void) StcMonitor *monitor; GString *str; + str = g_string_new (NULL); - monitor = stc_monitor_new_for_config_dir (SRCDIR "/nonexistant", on_error_append_str, str); - g_assert_cmpstr (stc_monitor_get_config_dir (monitor), ==, SRCDIR "/nonexistant"); + g_setenv ("STC_CONFIG_DIR", SRCDIR "/nonexistant", TRUE); + monitor = stc_monitor_new (on_error_append_str, str); g_object_unref (monitor); g_assert_cmpstr (str->str, ==, @@ -180,8 +176,8 @@ test_stc_semi_valid_conf (void) GList *l; str = g_string_new (NULL); - monitor = stc_monitor_new_for_config_dir (SRCDIR "/testdata/semi_valid_conf", on_error_append_str, str); - g_assert_cmpstr (stc_monitor_get_config_dir (monitor), ==, SRCDIR "/testdata/semi_valid_conf"); + g_setenv ("STC_CONFIG_DIR", SRCDIR "/testdata/semi_valid_conf", TRUE); + monitor = stc_monitor_new (on_error_append_str, str); g_assert_cmpstr (str->str, ==, SRCDIR "/testdata/semi_valid_conf/stc.conf: Error parsing key Auto for item BigStorage of type Filesystem: Key file contains key 'Auto' which has value that cannot be interpreted. (stc-error-quark, 1)\n" SRCDIR "/testdata/semi_valid_conf/stc.conf: Error parsing group name `Blah' (stc-error-quark, 1)\n" @@ -415,8 +411,8 @@ test_stc_monitoring (void) g_assert_not_reached (); } - monitor = stc_monitor_new_for_config_dir (dirname, NULL, NULL); - g_assert_cmpstr (stc_monitor_get_config_dir (monitor), ==, dirname); + g_setenv ("STC_CONFIG_DIR", dirname, TRUE); + monitor = stc_monitor_new (NULL, NULL); /* main timeout */ timeout_id = g_timeout_add_seconds (30, on_timeout, NULL); |