int test12 (void) { g_print ("%s started, main thread is %p\n", __FUNCTION__, g_thread_self ()); GdaWorker *worker; gint nfailed = 0; worker = gda_worker_new (); GError *error = NULL; g_print ("Waiting for test12_func() to execute\n"); gpointer result; if (!gda_worker_do_job (worker, NULL, 0, &result, NULL, (GdaWorkerFunc) test12_func, NULL, NULL, NULL, &error) || (result != (gpointer) 0x02)) { g_print ("gda_worker_do_job() failed: %s\n", error && error->message ? error->message : "No detail"); g_clear_error (&error); nfailed ++; } g_print ("Unref worker...\n"); gda_worker_unref (worker); g_print ("%s done\n", __FUNCTION__); return nfailed; }
int test13 (void) { g_print ("%s started, main thread is %p\n", __FUNCTION__, g_thread_self ()); GdaWorker *worker; gint nfailed = 0; worker = gda_worker_new (); GError *error = NULL; g_timeout_add (200, (GSourceFunc) test13_time_func, gda_worker_ref (worker)); g_print ("Sumbitting job for test13_func()\n"); gpointer result; if (!gda_worker_do_job (worker, NULL, 0, &result, NULL, (GdaWorkerFunc) test13_func, "1st", NULL, NULL, &error)) { g_print ("gda_worker_do_job() failed: %s\n", error && error->message ? error->message : "No detail"); g_clear_error (&error); nfailed ++; } else if (GPOINTER_TO_UINT (result) != 2) { g_print ("In %s(): expected 2 and got %u\n", __FUNCTION__, GPOINTER_TO_UINT (result)); nfailed ++; } else if (test13_sub_failed) nfailed ++; g_print ("Unref worker...\n"); gda_worker_unref (worker); g_print ("%s done\n", __FUNCTION__); return nfailed; }
/* * Reopens a connection after the server has closed it (possibly because of a timeout) */ gboolean gda_ldap_rebind (GdaLdapConnection *cnc, GError **error) { g_return_val_if_fail (GDA_IS_LDAP_CONNECTION (cnc), FALSE); gda_lockable_lock ((GdaLockable*) cnc); /* CNC LOCK */ LdapConnectionData *cdata; cdata = (LdapConnectionData*) gda_virtual_connection_internal_get_provider_data (GDA_VIRTUAL_CONNECTION (cnc)); if (!cdata) { gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */ g_warning ("cdata != NULL failed"); return FALSE; } GdaServerProviderConnectionData *pcdata; pcdata = gda_connection_internal_get_provider_data_error ((GdaConnection*) cnc, NULL); GdaWorker *worker; worker = gda_worker_ref (gda_connection_internal_get_worker (pcdata)); GMainContext *context; context = gda_server_provider_get_real_main_context ((GdaConnection *) cnc); gpointer retval; gda_worker_do_job (worker, context, 0, &retval, NULL, (GdaWorkerFunc) worker_gda_ldap_rebind, (gpointer) cdata, NULL, NULL, error); if (context) g_main_context_unref (context); gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */ gda_worker_unref (worker); return retval ? TRUE : FALSE; }
/* * Unbinds the connection if possible (i.e. if cdata->keep_bound_count is 0) * This allows to avoid keeping the connection to the LDAP server if unused */ void gda_ldap_may_unbind (GdaLdapConnection *cnc) { gda_lockable_lock ((GdaLockable*) cnc); /* CNC LOCK */ LdapConnectionData *cdata; cdata = (LdapConnectionData*) gda_virtual_connection_internal_get_provider_data (GDA_VIRTUAL_CONNECTION (cnc)); if (!cdata || (cdata->keep_bound_count > 0)) { gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */ return; } GdaServerProviderConnectionData *pcdata; pcdata = gda_connection_internal_get_provider_data_error ((GdaConnection*) cnc, NULL); GdaWorker *worker; worker = gda_worker_ref (gda_connection_internal_get_worker (pcdata)); GMainContext *context; context = gda_server_provider_get_real_main_context ((GdaConnection *) cnc); gpointer retval; gda_worker_do_job (worker, context, 0, &retval, NULL, (GdaWorkerFunc) worker_gda_ldap_may_unbind, (gpointer) cdata, NULL, NULL, NULL); if (context) g_main_context_unref (context); gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */ gda_worker_unref (worker); }
int test11 (void) { g_print ("%s started, main thread is %p\n", __FUNCTION__, g_thread_self ()); GdaWorker *worker; gint nfailed = 0; worker = gda_worker_new (); GError *error = NULL; g_print ("Waiting for test11_func() to execute\n"); gpointer result; if (!gda_worker_do_job (worker, NULL, 0, &result, NULL, (GdaWorkerFunc) test11_func, NULL, NULL, NULL, &error) || (result != (gpointer) 0x01)) { g_print ("gda_worker_do_job() failed: %s\n", error && error->message ? error->message : "No detail"); g_clear_error (&error); nfailed ++; } if (!gda_worker_do_job (worker, NULL, 0, &result, NULL, (GdaWorkerFunc) test11_func_e, NULL, NULL, NULL, &error) || result) { g_print ("gda_worker_do_job() failed: %s\n", error && error->message ? error->message : "No detail"); g_clear_error (&error); nfailed ++; } else if (!error || (error->domain != 1) || (error->code != 1)) { g_print ("gda_worker_do_job() failed: unexpected empty error, or wrong error domain or code%s\n", error && error->message ? error->message : "No detail"); g_clear_error (&error); nfailed ++; } g_print ("Unref worker...\n"); gda_worker_unref (worker); g_print ("%s done\n", __FUNCTION__); return nfailed; }
int test6 (void) { g_print ("%s started, main thread is %p\n", __FUNCTION__, g_thread_self ()); GdaWorker *worker; gint nfailed = 0; worker = gda_worker_new (); GError *error = NULL; guint nticks = 0; guint timer; timer = g_timeout_add (10, (GSourceFunc) test6_timer_cb, &nticks); guint jid; gpointer out; gint wait; wait = 50; if (gda_worker_do_job (worker, NULL, 100, &out, &jid, (GdaWorkerFunc) test6_worker_func, (gpointer) &wait, NULL, (GDestroyNotify) test6_string_free, &error)) { if (!out || strcmp (out, "Test6Done")) { g_print ("Expected out to be [Test6Done] and got [%s]\n", (gchar*) out); nfailed++; } g_free (out); if (jid != 0) { g_print ("Expected JID to be 0 and got %u\n", jid); nfailed++; } } else { g_print ("gda_worker_do_job() failed: %s\n", error && error->message ? error->message : "No detail"); g_clear_error (&error); nfailed ++; } g_source_remove (timer); if (nticks < 3) { g_print ("Tick timer was not called while in gda_worker_do_job()\n"); nfailed++; } g_print ("Unref worker...\n"); gda_worker_unref (worker); g_print ("%s done\n", __FUNCTION__); return nfailed; }
/** * gdaprov_ldap_get_class_info: * @cnc: a #GdaLdapConnection (not %NULL) * @classname: the class name (not %NULL) * * Returns: the #GdaLdapClass for @classname, or %NULL */ GdaLdapClass * gdaprov_ldap_get_class_info (GdaLdapConnection *cnc, const gchar *classname) { g_return_val_if_fail (GDA_IS_LDAP_CONNECTION (cnc), NULL); g_return_val_if_fail (classname, NULL); gda_lockable_lock ((GdaLockable*) cnc); /* CNC LOCK */ LdapConnectionData *cdata; cdata = (LdapConnectionData*) gda_virtual_connection_internal_get_provider_data (GDA_VIRTUAL_CONNECTION (cnc)); if (!cdata) { gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */ return NULL; } if (cdata->classes_hash) { gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */ return g_hash_table_lookup (cdata->classes_hash, classname); } GdaServerProviderConnectionData *pcdata; pcdata = gda_connection_internal_get_provider_data_error ((GdaConnection*) cnc, NULL); GdaWorker *worker; worker = gda_worker_ref (gda_connection_internal_get_worker (pcdata)); GMainContext *context; context = gda_server_provider_get_real_main_context ((GdaConnection *) cnc); WorkerLdapClassInfoData data; data.cnc = cnc; data.cdata = cdata; data.classname = classname; gda_connection_increase_usage ((GdaConnection*) cnc); /* USAGE ++ */ gpointer retval; gda_worker_do_job (worker, context, 0, &retval, NULL, (GdaWorkerFunc) worker_gdaprov_ldap_get_class_info, (gpointer) &data, NULL, NULL, NULL); if (context) g_main_context_unref (context); gda_connection_decrease_usage ((GdaConnection*) cnc); /* USAGE -- */ gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */ gda_worker_unref (worker); return (GdaLdapClass*) retval; }
GdaLdapEntry * gdaprov_ldap_describe_entry (GdaLdapConnection *cnc, const gchar *dn, GError **error) { g_return_val_if_fail (GDA_IS_LDAP_CONNECTION (cnc), NULL); g_return_val_if_fail (!dn || (dn && *dn), NULL); gda_lockable_lock ((GdaLockable*) cnc); /* CNC LOCK */ LdapConnectionData *cdata; cdata = (LdapConnectionData*) gda_virtual_connection_internal_get_provider_data (GDA_VIRTUAL_CONNECTION (cnc)); if (!cdata) { gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */ return NULL; } GdaServerProviderConnectionData *pcdata; pcdata = gda_connection_internal_get_provider_data_error ((GdaConnection*) cnc, NULL); GdaWorker *worker; worker = gda_worker_ref (gda_connection_internal_get_worker (pcdata)); GMainContext *context; context = gda_server_provider_get_real_main_context ((GdaConnection *) cnc); WorkerLdapDescrEntryData data; data.cnc = cnc; data.cdata = cdata; data.dn = dn; gda_connection_increase_usage ((GdaConnection*) cnc); /* USAGE ++ */ gpointer retval; gda_worker_do_job (worker, context, 0, &retval, NULL, (GdaWorkerFunc) worker_gdaprov_ldap_describe_entry, (gpointer) &data, NULL, NULL, error); if (context) g_main_context_unref (context); gda_connection_decrease_usage ((GdaConnection*) cnc); /* USAGE -- */ gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */ gda_worker_unref (worker); return (GdaLdapEntry*) retval; }
gboolean test13_time_func (GdaWorker *worker) { /* this time we should get 3, because the previous call to test13_func() should have returned 2 */ g_print ("Sumbitting another job for test13_func()\n"); gpointer result; GError *error = NULL; if (!gda_worker_do_job (worker, NULL, 0, &result, NULL, (GdaWorkerFunc) test13_func, "2nd", NULL, NULL, &error)) { g_print ("gda_worker_do_job() failed: %s\n", error && error->message ? error->message : "No detail"); g_clear_error (&error); test13_sub_failed = TRUE; } else if (GPOINTER_TO_UINT (result) != 3) { g_print ("In %s(): expected 3 and got %u\n", __FUNCTION__, GPOINTER_TO_UINT (result)); test13_sub_failed = TRUE; } gda_worker_unref (worker); return G_SOURCE_REMOVE; }
/** * gda_ldap_get_attr_info: * @cnc: a #GdaLdapConnection * @cdata: * @attribute: * * Returns: (transfer none): the #LdapAttribute for @attribute, or %NULL */ LdapAttribute * gda_ldap_get_attr_info (GdaLdapConnection *cnc, LdapConnectionData *cdata, const gchar *attribute) { g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL); if (! attribute || !cdata) return NULL; gda_lockable_lock ((GdaLockable*) cnc); /* CNC LOCK */ GdaServerProviderConnectionData *pcdata; pcdata = gda_connection_internal_get_provider_data_error ((GdaConnection*) cnc, NULL); GdaWorker *worker; worker = gda_worker_ref (gda_connection_internal_get_worker (pcdata)); GMainContext *context; context = gda_server_provider_get_real_main_context ((GdaConnection *) cnc); WorkerLdapAttrInfoData data; data.cnc = cnc; data.cdata = cdata; data.attribute = attribute; gda_connection_increase_usage ((GdaConnection*) cnc); /* USAGE ++ */ gpointer retval; gda_worker_do_job (worker, context, 0, &retval, NULL, (GdaWorkerFunc) worker_gda_ldap_get_attr_info, (gpointer) &data, NULL, NULL, NULL); if (context) g_main_context_unref (context); gda_connection_decrease_usage ((GdaConnection*) cnc); /* USAGE -- */ gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */ gda_worker_unref (worker); return (LdapAttribute*) retval; }