summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier CrĂȘte <olivier.crete@collabora.com>2019-05-08 16:40:10 -0400
committerOlivier CrĂȘte <olivier.crete@ocrete.ca>2019-05-09 01:14:37 +0000
commit6171f2507992792fcee739f751fe469322e5a621 (patch)
treeb9a66d88cfb43faf72695e1e36c73d2ab547c9ca
parente78a492314e4577d33966434708e17eb9e2e52a2 (diff)
downloadlibnice-6171f2507992792fcee739f751fe469322e5a621.tar.gz
agent: Replace closed signal with GASyncResult type function
This makes the API more GIO style
-rw-r--r--agent/agent.c44
-rw-r--r--agent/agent.h11
-rw-r--r--agent/discovery.c4
-rw-r--r--agent/discovery.h2
-rw-r--r--tests/test-fullmode.c22
-rw-r--r--tests/test-turn.c24
6 files changed, 49 insertions, 58 deletions
diff --git a/agent/agent.c b/agent/agent.c
index dc47ba0..e653d02 100644
--- a/agent/agent.c
+++ b/agent/agent.c
@@ -136,7 +136,6 @@ enum
SIGNAL_NEW_SELECTED_PAIR_FULL,
SIGNAL_NEW_CANDIDATE_FULL,
SIGNAL_NEW_REMOTE_CANDIDATE_FULL,
- SIGNAL_CLOSED,
N_SIGNALS,
};
@@ -1141,28 +1140,6 @@ nice_agent_class_init (NiceAgentClass *klass)
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 ();
}
@@ -6688,19 +6665,32 @@ nice_agent_peer_candidate_gathering_done (NiceAgent *agent, guint stream_id)
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);
}
diff --git a/agent/agent.h b/agent/agent.h
index c85ee5e..c3b77a3 100644
--- a/agent/agent.h
+++ b/agent/agent.h
@@ -1662,9 +1662,15 @@ nice_agent_peer_candidate_gathering_done (
/**
* 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.
@@ -1672,7 +1678,8 @@ nice_agent_peer_candidate_gathering_done (
* 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
diff --git a/agent/discovery.c b/agent/discovery.c
index 189baf4..7155dc3 100644
--- a/agent/discovery.c
+++ b/agent/discovery.c
@@ -326,9 +326,9 @@ static void refresh_prune_async (NiceAgent *agent, GSList *refreshes,
}
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);
}
/*
diff --git a/agent/discovery.h b/agent/discovery.h
index 3e41e52..976118b 100644
--- a/agent/discovery.h
+++ b/agent/discovery.h
@@ -86,7 +86,7 @@ typedef struct
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);
diff --git a/tests/test-fullmode.c b/tests/test-fullmode.c
index d5aedb5..7c38330 100644
--- a/tests/test-fullmode.c
+++ b/tests/test-fullmode.c
@@ -130,8 +130,6 @@ static gboolean global_lagent_gathering_done = FALSE;
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;
@@ -298,8 +296,10 @@ static void cb_initial_binding_request_received(NiceAgent *agent, guint stream_i
(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;
@@ -862,6 +862,8 @@ int main (void)
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;
@@ -933,10 +935,6 @@ int main (void)
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");
@@ -1112,15 +1110,15 @@ int main (void)
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;
diff --git a/tests/test-turn.c b/tests/test-turn.c
index 9a1e63f..8122d8e 100644
--- a/tests/test-turn.c
+++ b/tests/test-turn.c
@@ -10,8 +10,6 @@ static NiceComponentState global_ragent_state[2] = { NICE_COMPONENT_STATE_LAST,
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;
@@ -103,8 +101,9 @@ static void cb_new_selected_pair(NiceAgent *agent, guint stream_id,
++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;
@@ -163,6 +162,8 @@ run_test(guint turn_port, gboolean is_ipv6,
NiceAddress localaddr;
guint ls_id, rs_id;
gulong timer_id;
+ gboolean lagent_closed = FALSE;
+ gboolean ragent_closed = FALSE;
if (is_ipv6)
localhost = "::1";
@@ -173,8 +174,6 @@ run_test(guint turn_port, gboolean is_ipv6,
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);
@@ -210,10 +209,6 @@ run_test(guint turn_port, gboolean is_ipv6,
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);
@@ -262,17 +257,18 @@ run_test(guint turn_port, gboolean is_ipv6,
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;