libmbca r36 - trunk/src
- From: kaijanma svn gnome org
- To: svn-commits-list gnome org
- Subject: libmbca r36 - trunk/src
- Date: Thu, 21 Aug 2008 10:29:03 +0000 (UTC)
Author: kaijanma
Date: Thu Aug 21 10:29:03 2008
New Revision: 36
URL: http://svn.gnome.org/viewvc/libmbca?rev=36&view=rev
Log:
move everything from MBCAAssistantClassPrivate to MBCAAssistantPrivate
Modified:
trunk/src/common.h
trunk/src/mbca_assistant.c
trunk/src/provider_page.c
trunk/src/provider_thread.c
trunk/src/provider_thread.h
Modified: trunk/src/common.h
==============================================================================
--- trunk/src/common.h (original)
+++ trunk/src/common.h Thu Aug 21 10:29:03 2008
@@ -138,47 +138,10 @@
*
* Private members of the assistant class.
* All databases and models are shared between instances.
- *
- * @note instances <b>must not</b> alter any model. They are strictly readers!
*/
struct _MBCAAssistantClassPrivate
{
- DBusConnection* halconn; /**< connection to HAL */
- LibHalContext* halctx; /**< HAL context for halconn */
-
- GtkListStore* serial_store;
- GtkListStore* baud_store;
- GtkListStore* hal_store; /**< constains available HAL devices */
-
- /* Provider page resource loading thread
- * - these members should be accessed with great care to avoid any nasty
- * race or other concurrency issues
- */
- GThread* provider_thread; /**< thread for loading provider page data
- * in the background */
-
- GtkTreeModel* gweather_database; /**< database containing country
- * information from libgweather */
-
- GtkListStore* country_store; /**< contains available countries */
-
- gchar* country_code; /**< ISO 3166-1 alpha-2 code of systems country */
-
- volatile gboolean abort_provider_thread; /**< if TRUE interrupts loading
- */
- volatile gboolean provider_thread_ready; /**< TRUE if loading is done */
-
- GMutex* instances_mutex; /**< mutex for waiting_instances */
- GSList* waiting_instances; /**< instances waiting for resources, see
- * comments at the end of assistant_init()
- */
-
- GMutex* trigger_mutex; /**< this is only a workaround of a thread problem
- */
-
-
- GSList* database; /**< service provider database */
};
/**
@@ -233,12 +196,46 @@
gboolean country_list_sorted; /**< TRUE is country list is initially
* sorted. */
-
- MBCAAssistantClassPrivate* kpriv; /**< this is only a workaround of a
- * thread problem */
- /** @todo fixme */
gboolean resources_attached; /**< part of the workaround... */
/** @todo fixme */
+
+
+ /* Resources */
+ DBusConnection* halconn; /**< connection to HAL */
+ LibHalContext* halctx; /**< HAL context for halconn */
+
+ GtkListStore* serial_store;
+ GtkListStore* baud_store;
+ GtkListStore* hal_store; /**< constains available HAL devices */
+
+
+ /* Provider page resource loading thread
+ * - these members should be accessed with great care to avoid any nasty
+ * race or other concurrency issues
+ */
+ GThread* provider_thread; /**< thread for loading provider page data
+ * in the background */
+
+ GtkTreeModel* gweather_database; /**< database containing country
+ * information from libgweather */
+
+ GtkListStore* country_store; /**< contains available countries */
+
+ gchar* country_code; /**< ISO 3166-1 alpha-2 code of systems country */
+
+ volatile gboolean abort_provider_thread; /**< if TRUE interrupts loading
+ */
+ volatile gboolean provider_thread_ready; /**< TRUE if loading is done */
+
+ GMutex* instances_mutex; /**< mutex for waiting_instances */
+ GSList* waiting_instances; /**< instances waiting for resources, see
+ * comments at the end of assistant_init()
+ */
+
+ GMutex* trigger_mutex; /**< this is only a workaround of a thread problem
+ */
+
+ GSList* database; /**< service provider database */
};
Modified: trunk/src/mbca_assistant.c
==============================================================================
--- trunk/src/mbca_assistant.c (original)
+++ trunk/src/mbca_assistant.c Thu Aug 21 10:29:03 2008
@@ -557,7 +557,7 @@
static void
hal_device_added_cb (LibHalContext *ctx, const char *udi)
{
- MBCAAssistantClassPrivate* priv;
+ MBCAAssistantPrivate* priv;
GtkTreeIter iter;
gchar* product;
gchar* vendor;
@@ -568,7 +568,7 @@
{
return;
}
- priv = (MBCAAssistantClassPrivate*)libhal_ctx_get_user_data (ctx);
+ priv = (MBCAAssistantPrivate*)libhal_ctx_get_user_data (ctx);
/* check that device is not already in the list */
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->hal_store), &iter))
@@ -618,7 +618,7 @@
static void
hal_device_removed_cb (LibHalContext *ctx, const char *udi)
{
- MBCAAssistantClassPrivate* priv;
+ MBCAAssistantPrivate* priv;
GtkTreeIter iter;
/**
@@ -627,7 +627,7 @@
* priv->hal_strore, but it's propably not a problem.
*/
- priv = (MBCAAssistantClassPrivate*)libhal_ctx_get_user_data (ctx);
+ priv = (MBCAAssistantPrivate*)libhal_ctx_get_user_data (ctx);
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->hal_store), &iter))
{
do
@@ -663,64 +663,6 @@
* GObject *
***********/
-__attribute__ ((unused)) /** @todo use me, see mbca_assistant_get_type() */
-static void
-assistant_class_finalize (gpointer g_class,
- gpointer class_data __attribute__((unused)))
-{
- MBCAAssistantClassPrivate* priv;
- GtkTreeModel* country_store;
- GtkTreeIter iter;
-
- g_debug ("assistant_class_finalize");
- priv = ((MBCAAssistantClass*)g_class)->priv;
-
-
- priv->abort_provider_thread = TRUE;
- g_thread_join (priv->provider_thread);
- g_mutex_free (priv->instances_mutex);
-
- /* Service provider page */
- if (priv->gweather_database)
- {
- g_object_unref (priv->gweather_database);
- }
-
- country_store = GTK_TREE_MODEL (priv->country_store);
- if (country_store)
- {
- if (gtk_tree_model_get_iter_first (country_store, &iter))
- {
- do
- {
- GtkTreeModel* provider_store;
- gtk_tree_model_get (country_store, &iter,
- COUNTRY_PROVIDERS_COLUMN,
- &provider_store,
- -1);
- gtk_list_store_clear (GTK_LIST_STORE (provider_store));
- g_object_unref (provider_store);
- }
- while (gtk_tree_model_iter_next (country_store, &iter));
- }
- gtk_list_store_clear (GTK_LIST_STORE (country_store));
- }
-
- free_service_provider_database (&(priv->database));
-
- if (priv->halctx)
- {
- libhal_ctx_shutdown (priv->halctx, NULL);
- libhal_ctx_free (priv->halctx);
- }
- if (priv->halconn)
- {
- dbus_connection_unref(priv->halconn);
- }
-
- g_free (priv->country_code);
- g_free (priv);
-}
static void
assistant_dispose (GObject *obj __attribute__((unused)))
@@ -753,10 +695,12 @@
{
MBCAAssistant* self = (MBCAAssistant*)obj;
MBCAAssistantPrivate* priv;
+ GtkTreeModel* country_store;
+ GtkTreeIter iter;
g_debug ("assistant_finalize");
priv = self->priv;
-
+
/* Everything was set to zero in new() by g_malloc0 so any pointer that
* is not NULL must be freed
*/
@@ -764,29 +708,59 @@
if (!self->priv)
{
return;
- }
-
- priv->exit_btrescan = TRUE;
- g_thread_join (priv->btrescan_thread);
-
- mbca_free_configuration (priv->conf);
+ }
- /* USB page */
+ priv->abort_provider_thread = TRUE;
+ g_thread_join (priv->provider_thread);
+ g_mutex_free (priv->instances_mutex);
+ priv->exit_btrescan = TRUE;
+ g_thread_join (priv->btrescan_thread);
- /* Serial page */
+
+ if (priv->gweather_database)
+ {
+ g_object_unref (priv->gweather_database);
+ }
+ country_store = GTK_TREE_MODEL (priv->country_store);
+ if (country_store)
+ {
+ if (gtk_tree_model_get_iter_first (country_store, &iter))
+ {
+ do
+ {
+ GtkTreeModel* provider_store;
+ gtk_tree_model_get (country_store, &iter,
+ COUNTRY_PROVIDERS_COLUMN,
+ &provider_store,
+ -1);
+ gtk_list_store_clear (GTK_LIST_STORE (provider_store));
+ g_object_unref (provider_store);
+ }
+ while (gtk_tree_model_iter_next (country_store, &iter));
+ }
+ gtk_list_store_clear (GTK_LIST_STORE (country_store));
+ }
- /* Bluetooth page */
+ free_service_provider_database (&(priv->database));
+ if (priv->halctx)
+ {
+ libhal_ctx_shutdown (priv->halctx, NULL);
+ libhal_ctx_free (priv->halctx);
+ }
+ if (priv->halconn)
+ {
+ dbus_connection_unref(priv->halconn);
+ }
- /* Generic */
+ mbca_free_configuration (priv->conf);
+
g_free (priv->nice_device_name);
g_free (priv->country_name);
g_free (priv->provider_name);
-
- /* conf is given to the caller so it must not be freed
- */
+ g_free (priv->country_code);
if (priv->assistant)
{
@@ -803,20 +777,8 @@
assistant_class_init (gpointer g_class,
gpointer g_class_data __attribute__((unused)))
{
- MBCAAssistantClassPrivate* priv;
- GObjectClass* gobject_class;
MBCAAssistantClass *klass;
- GtkTreeIter iter;
- gint ret;
-
- /* HAL */
- DBusError halerr;
- int num_devices;
- char** devices;
- char** udi;
- int num;
-
- g_debug ("assistant_class_init");
+ GObjectClass* gobject_class;
/* translation domain */
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
@@ -833,8 +795,49 @@
/* private structure */
- priv = g_malloc0 (sizeof (MBCAAssistantClass));
- klass->priv = priv;
+ klass->priv = g_malloc0 (sizeof (MBCAAssistantClassPrivate));
+
+ klass->state_changed_signal_id =
+ g_signal_new ("state-changed",
+ G_TYPE_FROM_CLASS (g_class),
+ G_SIGNAL_RUN_LAST |
+ G_SIGNAL_NO_RECURSE |
+ G_SIGNAL_NO_HOOKS,
+ 0, /* class_offset */
+ NULL, /* accumulator */
+ NULL, /* accu_data */
+ g_cclosure_marshal_VOID__ENUM,
+ G_TYPE_NONE, /* return_type */
+ 1, /* n_params */
+ MBCA_TYPE_ASSISTANT_STATE); /* param_types */
+}
+
+static void
+assistant_init (GTypeInstance* instance, gpointer g_class __attribute__ ((unused)))
+{
+ MBCAAssistant* self = (MBCAAssistant*)instance;
+ MBCAAssistantPrivate* priv;
+ GError* error = NULL;
+ GtkTreeIter iter;
+ gint ret;
+
+ /* HAL */
+ DBusError halerr;
+ int num_devices;
+ char** devices;
+ char** udi;
+ int num;
+
+
+ g_debug ("assistant_init");
+ if (!g_thread_supported ())
+ {
+ g_error ("gthreads are not supported. did you forget to call "
+ "g_thread_init()?"
+ /* "please, RTFM!" */);
+ }
+ self->priv = g_malloc0 (sizeof (MBCAAssistantPrivate));
+ priv = self->priv;
/* create list stores */
@@ -1005,42 +1008,7 @@
if (!priv->provider_thread)
{
g_error ("g_thread_create failed");
- }
-
- klass->state_changed_signal_id =
- g_signal_new ("state-changed",
- G_TYPE_FROM_CLASS (g_class),
- G_SIGNAL_RUN_LAST |
- G_SIGNAL_NO_RECURSE |
- G_SIGNAL_NO_HOOKS,
- 0, /* class_offset */
- NULL, /* accumulator */
- NULL, /* accu_data */
- g_cclosure_marshal_VOID__ENUM,
- G_TYPE_NONE, /* return_type */
- 1, /* n_params */
- MBCA_TYPE_ASSISTANT_STATE); /* param_types */
-}
-
-static void
-assistant_init (GTypeInstance* instance, gpointer g_class)
-{
- MBCAAssistantClass *klass = (MBCAAssistantClass*)g_class;
- MBCAAssistant* self = (MBCAAssistant*)instance;
- MBCAAssistantPrivate* priv;
- GError* error = NULL;
- gint ret;
-
- g_debug ("assistant_init");
- if (!g_thread_supported ())
- {
- g_error ("gthreads are not supported. did you forget to call "
- "g_thread_init()?"
- /* "please, RTFM!" */);
- }
- self->priv = g_malloc0 (sizeof (MBCAAssistantPrivate));
- priv = self->priv;
-
+ }
priv->builder = gtk_builder_new ();
ret = gtk_builder_add_from_file (priv->builder,
@@ -1069,9 +1037,9 @@
*/
setup_bluetooth_page (priv);
setup_serial_page (priv,
- klass->priv->serial_store,
- klass->priv->baud_store);
- setup_hal_page (priv, klass->priv->hal_store);
+ priv->serial_store,
+ priv->baud_store);
+ setup_hal_page (priv, priv->hal_store);
setup_provider_page (priv);
gtk_assistant_set_forward_page_func (priv->assistant,
@@ -1079,9 +1047,6 @@
priv,
NULL);
connect_signals (self);
-
-
- priv->kpriv = klass->priv; /** @todo fixme */
/** @todo fixme
*
@@ -1150,7 +1115,6 @@
static GType type = 0;
if (type == 0) {
- /** @todo assistant should be static so that resources are freed */
static const GTypeInfo info = {
sizeof (MBCAAssistantClass),
NULL, /* base_init */
Modified: trunk/src/provider_page.c
==============================================================================
--- trunk/src/provider_page.c (original)
+++ trunk/src/provider_page.c Thu Aug 21 10:29:03 2008
@@ -44,9 +44,9 @@
*//** @todo fixme */
if (!priv->resources_attached)
{
- g_mutex_lock (priv->kpriv->trigger_mutex);
- mbca_provider_attach_resources (priv->kpriv, priv);
- g_mutex_unlock (priv->kpriv->trigger_mutex);
+ g_mutex_lock (priv->trigger_mutex);
+ mbca_provider_attach_resources (priv);
+ g_mutex_unlock (priv->trigger_mutex);
priv->resources_attached = TRUE;
}
}
Modified: trunk/src/provider_thread.c
==============================================================================
--- trunk/src/provider_thread.c (original)
+++ trunk/src/provider_thread.c Thu Aug 21 10:29:03 2008
@@ -338,7 +338,7 @@
static void
mbca_country_foreach (gpointer data, gpointer user_data)
{
- MBCAAssistantClassPrivate* priv = user_data;
+ MBCAAssistantPrivate* priv = user_data;
ServiceProviderCountry* country = data;
GtkListStore* provider_store;
GtkTreeIter iter;
@@ -597,7 +597,7 @@
gpointer
mbca_load_provider_page_resources_thread_func (gpointer data)
{
- MBCAAssistantClassPrivate* priv = data;
+ MBCAAssistantPrivate* priv = data;
const gchar* code;
gint ret;
@@ -671,8 +671,7 @@
}
void
-mbca_provider_attach_resources (MBCAAssistantClassPrivate* kpriv,
- MBCAAssistantPrivate* ipriv)
+mbca_provider_attach_resources (MBCAAssistantPrivate* priv)
{
GtkTreeViewColumn* column;
GtkWidget* country_list;
@@ -682,12 +681,12 @@
g_debug ("attaching resources");
- country_list = GTK_WIDGET (gtk_builder_get_object (ipriv->builder,
+ country_list = GTK_WIDGET (gtk_builder_get_object (priv->builder,
"country_treeview"));
g_return_if_fail (country_list);
gtk_tree_view_set_model (GTK_TREE_VIEW (country_list),
- GTK_TREE_MODEL (kpriv->country_store));
+ GTK_TREE_MODEL (priv->country_store));
/* sort the country list */
column = gtk_tree_view_get_column (GTK_TREE_VIEW (country_list),
@@ -697,20 +696,20 @@
gtk_tree_view_column_clicked (column);
found = FALSE;
- if (kpriv->country_code)
+ if (priv->country_code)
{
/* set country list to correct row */
GtkTreeIter iter;
- gtk_tree_model_get_iter_first (GTK_TREE_MODEL (kpriv->country_store),
+ gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->country_store),
&iter);
do
{
gchar* modelcode;
- gtk_tree_model_get (GTK_TREE_MODEL (kpriv->country_store), &iter,
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->country_store), &iter,
COUNTRY_CODE_COLUMN, &modelcode,
-1);
- if (g_ascii_strcasecmp (kpriv->country_code, modelcode) == 0)
+ if (g_ascii_strcasecmp (priv->country_code, modelcode) == 0)
{
found = TRUE;
g_free (modelcode);
@@ -718,7 +717,7 @@
}
g_free (modelcode);
}
- while (gtk_tree_model_iter_next (GTK_TREE_MODEL (kpriv->country_store),
+ while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->country_store),
&iter));
if (found)
{
@@ -727,7 +726,7 @@
GtkTreeView* view = GTK_TREE_VIEW (country_list);
selection = gtk_tree_view_get_selection (view);
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (kpriv->country_store),
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->country_store),
&iter);
gtk_tree_selection_select_path (selection,
path);
@@ -738,12 +737,12 @@
}
if (!found){
/* expand country list */
- expander = GTK_EXPANDER (gtk_builder_get_object (ipriv->builder,
+ expander = GTK_EXPANDER (gtk_builder_get_object (priv->builder,
"country_expander"));
g_return_if_fail (expander);
gtk_expander_set_expanded (expander, TRUE);
}
- page = gtk_assistant_get_nth_page (ipriv->assistant, PAGE_PROVIDER);
+ page = gtk_assistant_get_nth_page (priv->assistant, PAGE_PROVIDER);
gtk_widget_set_sensitive (page, TRUE);
}
Modified: trunk/src/provider_thread.h
==============================================================================
--- trunk/src/provider_thread.h (original)
+++ trunk/src/provider_thread.h Thu Aug 21 10:29:03 2008
@@ -39,8 +39,7 @@
mbca_load_provider_page_resources_thread_func (gpointer data);
void
-mbca_provider_attach_resources (MBCAAssistantClassPrivate* kpriv,
- MBCAAssistantPrivate* ipriv);
+mbca_provider_attach_resources (MBCAAssistantPrivate* priv);
G_END_DECLS
#endif /* RESOURCE_THREAD_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]