From e3ddaa285e389baf3f26cfb6964919718a8f6a00 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Cr=C3=AAte?= Date: Wed, 21 Jun 2017 16:55:32 -0400 Subject: [PATCH] agent: Adjust the nice_agent_new_full() to use flags This makes it easier to read and more extensible. --- agent/agent.c | 9 +++++---- agent/agent.h | 27 ++++++++++++++++++++++----- tests/test-nomination.c | 8 ++++---- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/agent/agent.c b/agent/agent.c index 27e6193..8fd8ead 100644 --- a/agent/agent.c +++ b/agent/agent.c @@ -1168,14 +1168,15 @@ nice_agent_new_reliable (GMainContext *ctx, NiceCompatibility compat) NICEAPI_EXPORT NiceAgent * nice_agent_new_full (GMainContext *ctx, NiceCompatibility compat, - gboolean reliable, - NiceNominationMode nomination) + NiceAgentOption flags) { NiceAgent *agent = g_object_new (NICE_TYPE_AGENT, "compatibility", compat, "main-context", ctx, - "reliable", reliable, - "nomination-mode", nomination, + "reliable", (flags & NICE_AGENT_OPTION_RELIABLE) ? TRUE : FALSE, + "nomination-mode", (flags & NICE_AGENT_OPTION_REGULAR_NOMINATION) ? + NICE_NOMINATION_MODE_REGULAR : NICE_NOMINATION_MODE_AGGRESSIVE, + "full-mode", (flags & NICE_AGENT_OPTION_LITE_MODE) ? FALSE : TRUE, NULL); return agent; diff --git a/agent/agent.h b/agent/agent.h index 6e233c6..ed6f6e4 100644 --- a/agent/agent.h +++ b/agent/agent.h @@ -399,6 +399,25 @@ typedef enum } NiceNominationMode; /** + * NiceAgentOption: + * @NICE_AGENT_OPTION_REGULAR_NOMINATION: Enables regular nomination, default + * is aggrssive mode (see #NiceNominationMode). + * @NICE_AGENT_OPTION_RELIABLE: Enables reliable mode, possibly using PseudoTCP, * see nice_agent_new_reliable(). + * @NICE_AGENT_OPTION_LITE_MODE: Enable lite mode + * + * These are options that can be passed to nice_agent_new_full(). They set + * various properties on the agent. Not including them sets the property to + * the other value. + * + * Since: UNRELEASED + */ +typedef enum { + NICE_AGENT_OPTION_REGULAR_NOMINATION = 1 << 0, + NICE_AGENT_OPTION_RELIABLE = 1 << 1, + NICE_AGENT_OPTION_LITE_MODE = 1 << 2, +} NiceAgentOption; + +/** * NiceAgentRecvFunc: * @agent: The #NiceAgent Object * @stream_id: The id of the stream @@ -452,13 +471,12 @@ nice_agent_new_reliable (GMainContext *ctx, NiceCompatibility compat); * nice_agent_new_full: * @ctx: The Glib Mainloop Context to use for timers * @compat: The compatibility mode of the agent - * @reliable: The reliability mode of the agent - * @nomination: The nomination mode of the agent + * @flags: Flags to set the properties * * Create a new #NiceAgent with parameters that must be be defined at * construction time. * The returned object must be freed with g_object_unref() - * See also: #NiceNominationMode + * See also: #NiceNominationMode and #NiceAgentOption * * Since: UNRELEASED * @@ -467,8 +485,7 @@ nice_agent_new_reliable (GMainContext *ctx, NiceCompatibility compat); NiceAgent * nice_agent_new_full (GMainContext *ctx, NiceCompatibility compat, - gboolean reliable, - NiceNominationMode nomination); + NiceAgentOption flags); /** * nice_agent_add_local_address: diff --git a/tests/test-nomination.c b/tests/test-nomination.c index b5a5e5f..bf21557 100644 --- a/tests/test-nomination.c +++ b/tests/test-nomination.c @@ -140,13 +140,13 @@ run_test(NiceNominationMode l_nomination_mode, lagent = nice_agent_new_full (NULL, NICE_COMPATIBILITY_RFC5245, - FALSE, /* reliable */ - l_nomination_mode); + l_nomination_mode == NICE_NOMINATION_MODE_REGULAR ? + NICE_AGENT_OPTION_REGULAR_NOMINATION : 0); ragent = nice_agent_new_full (NULL, NICE_COMPATIBILITY_RFC5245, - FALSE, /* reliable */ - r_nomination_mode); + r_nomination_mode == NICE_NOMINATION_MODE_REGULAR ? + NICE_AGENT_OPTION_REGULAR_NOMINATION : 0); g_object_set (G_OBJECT (lagent), "ice-tcp", FALSE, NULL); g_object_set (G_OBJECT (ragent), "ice-tcp", FALSE, NULL); -- 2.7.4