SIGNAL_NEW_SELECTED_PAIR_FULL,
SIGNAL_NEW_CANDIDATE_FULL,
SIGNAL_NEW_REMOTE_CANDIDATE_FULL,
- SIGNAL_CLOSED,
N_SIGNALS,
};
NICE_TYPE_CANDIDATE,
G_TYPE_INVALID);
- /**
- * NiceAgent::closed
- * @agent: The #NiceAgent object
- *
- * This signal is fired when the agent finishes freeing resources it
- * previously allocated on remote servers (e.g. relay ports) and is ready
- * to be disposed.
- *
- * Since: 0.1.16
- */
- signals[SIGNAL_CLOSED] =
- g_signal_new (
- "closed",
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL,
- NULL,
- NULL,
- G_TYPE_NONE,
- 0);
-
/* Init debug options depending on env variables */
nice_debug_init ();
}
static gboolean
on_agent_refreshes_pruned (NiceAgent *agent, gpointer user_data)
{
- // This is called from a timeout cb with agent lock held
+ GTask *task = user_data;
+
+ /* This is called from a timeout cb with agent lock held */
- agent_queue_signal (agent, signals[SIGNAL_CLOSED]);
+ agent_unlock (agent);
+
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
+
+ agent_lock (agent);
return G_SOURCE_REMOVE;
}
void
-nice_agent_close_async (NiceAgent *agent)
+nice_agent_close_async (NiceAgent *agent, GAsyncReadyCallback callback,
+ gpointer callback_data)
{
+ GTask *task;
+
+ task = g_task_new (agent, NULL, callback, callback_data);
+ g_task_set_source_tag (task, nice_agent_close_async);
+
agent_lock (agent);
- refresh_prune_agent_async (agent, on_agent_refreshes_pruned);
+ refresh_prune_agent_async (agent, on_agent_refreshes_pruned, task);
agent_unlock (agent);
}
/**
* nice_agent_close_async:
* @agent: The #NiceAgent object
+ * @callback: (nullable): A callback that will be called when the closing is
+ * complete
+ * @callback_data: (nullable): A pointer that will be passed to the callback
*
* Asynchronously closes resources the agent has allocated on remote servers.
- * The agent will emit "closed" signal when the operation finishes.
+ *
+ * The agent will call the callback in the current #GMainContext in
+ * which this function is called. The #GAsyncResult in the callback
+ * can be ignored as this operation never fails.
*
* Calling this function before freeing the agent makes sure the allocated relay
* ports aren't left behind on TURN server but properly removed.
* Since: 0.1.16
*/
void
-nice_agent_close_async (NiceAgent *agent);
+nice_agent_close_async (NiceAgent *agent, GAsyncReadyCallback callback,
+ gpointer callback_data);
G_END_DECLS
}
void refresh_prune_agent_async (NiceAgent *agent,
- NiceTimeoutLockedCallback function)
+ NiceTimeoutLockedCallback function, gpointer user_data)
{
- refresh_prune_async (agent, agent->refresh_list, function, NULL);
+ refresh_prune_async (agent, agent->refresh_list, function, user_data);
}
/*
void refresh_free (NiceAgent *agent, CandidateRefresh *refresh);
void refresh_prune_agent_async (NiceAgent *agent,
- NiceTimeoutLockedCallback function);
+ NiceTimeoutLockedCallback function, gpointer user_data);
void refresh_prune_stream_async (NiceAgent *agent, NiceStream *stream,
NiceTimeoutLockedCallback function);
void refresh_prune_candidate (NiceAgent *agent, NiceCandidate *candidate);
static gboolean global_ragent_gathering_done = FALSE;
static gboolean global_lagent_ibr_received = FALSE;
static gboolean global_ragent_ibr_received = FALSE;
-static gboolean global_lagent_closed = FALSE;
-static gboolean global_ragent_closed = FALSE;
static int global_lagent_cands = 0;
static int global_ragent_cands = 0;
static gint global_ragent_read = 0;
(void)agent; (void)stream_id; (void)data;
}
-static void cb_closed (NiceAgent *agent, gpointer data)
+static void cb_closed (GObject *src, GAsyncResult *result, gpointer data)
{
+ NiceAgent *agent = NICE_AGENT (src);
+
g_debug ("test-fullmode:%s: %p", G_STRFUNC, agent);
*((gboolean *)data) = TRUE;
int result;
guint timer_id;
const char *stun_server = NULL, *stun_server_port = NULL;
+ gboolean lagent_closed = FALSE;
+ gboolean ragent_closed = FALSE;
#ifdef G_OS_WIN32
WSADATA w;
g_signal_connect (G_OBJECT (ragent), "initial-binding-request-received",
G_CALLBACK (cb_initial_binding_request_received),
GUINT_TO_POINTER (2));
- g_signal_connect (G_OBJECT (lagent), "closed",
- G_CALLBACK (cb_closed), &global_lagent_closed);
- g_signal_connect (G_OBJECT (ragent), "closed",
- G_CALLBACK (cb_closed), &global_ragent_closed);
stun_server = getenv ("NICE_STUN_SERVER");
stun_server_port = getenv ("NICE_STUN_SERVER_PORT");
g_assert (global_ragent_state[0] == NICE_COMPONENT_STATE_READY);
g_assert (global_ragent_state[1] == NICE_COMPONENT_STATE_READY);
- nice_agent_close_async (lagent);
- nice_agent_close_async (ragent);
+ nice_agent_close_async (lagent, cb_closed, &lagent_closed);
+ nice_agent_close_async (ragent, cb_closed, &ragent_closed);
+ g_object_unref (lagent);
+ g_object_unref (ragent);
- while (!global_lagent_closed || !global_ragent_closed) {
+ while (!ragent_closed || !ragent_closed) {
g_main_context_iteration (NULL, TRUE);
}
- g_object_unref (lagent);
- g_object_unref (ragent);
g_main_loop_unref (global_mainloop);
global_mainloop = NULL;
static guint global_components_ready = 0;
static gboolean global_lagent_gathering_done = FALSE;
static gboolean global_ragent_gathering_done = FALSE;
-static gboolean global_lagent_closed = FALSE;
-static gboolean global_ragent_closed = FALSE;
static int global_lagent_cands = 0;
static int global_ragent_cands = 0;
++global_ragent_cands;
}
-static void cb_closed (NiceAgent *agent, gpointer data)
+static void cb_closed (GObject *src, GAsyncResult *res, gpointer data)
{
+ NiceAgent *agent = NICE_AGENT (src);
g_debug ("test-turn:%s: %p", G_STRFUNC, agent);
*((gboolean *)data) = TRUE;
NiceAddress localaddr;
guint ls_id, rs_id;
gulong timer_id;
+ gboolean lagent_closed = FALSE;
+ gboolean ragent_closed = FALSE;
if (is_ipv6)
localhost = "::1";
global_components_ready = 0;
global_lagent_gathering_done = FALSE;
global_ragent_gathering_done = FALSE;
- global_lagent_closed = FALSE;
- global_ragent_closed = FALSE;
global_lagent_cands = global_ragent_cands = 0;
lagent = nice_agent_new (NULL, NICE_COMPATIBILITY_RFC5245);
G_CALLBACK (cb_new_selected_pair), GUINT_TO_POINTER(1));
g_signal_connect (G_OBJECT (ragent), "new-selected-pair",
G_CALLBACK (cb_new_selected_pair), GUINT_TO_POINTER (2));
- g_signal_connect (G_OBJECT (lagent), "closed",
- G_CALLBACK (cb_closed), &global_lagent_closed);
- g_signal_connect (G_OBJECT (ragent), "closed",
- G_CALLBACK (cb_closed), &global_ragent_closed);
g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL);
g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL);
nice_agent_remove_stream (lagent, ls_id);
nice_agent_remove_stream (ragent, rs_id);
- nice_agent_close_async (lagent);
- nice_agent_close_async (ragent);
+ nice_agent_close_async (lagent, cb_closed, &lagent_closed);
+ nice_agent_close_async (ragent, cb_closed, &ragent_closed);
- while (!global_lagent_closed || !global_ragent_closed) {
+ g_clear_object(&lagent);
+ g_clear_object(&ragent);
+
+ while (!lagent_closed || !ragent_closed) {
g_main_context_iteration (NULL, TRUE);
}
g_source_remove (timer_id);
- g_clear_object(&lagent);
- g_clear_object(&ragent);
}
guint global_turn_port;