Commit b500e48a authored by Dafydd Harries's avatar Dafydd Harries

make NiceAgent a GObject

darcs-hash:20070213142624-c9803-936a3813421658d2fd71e793073a20f7028c2516.gz
parent a5398e4e
......@@ -141,6 +141,59 @@ candidate_pair_priority (
/*** agent ***/
G_DEFINE_TYPE (NiceAgent, nice_agent, G_TYPE_OBJECT);
enum
{
PROP_SOCKET_FACTORY = 1,
};
static void
nice_agent_dispose (GObject *object);
static void
nice_agent_get_property (
GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void
nice_agent_set_property (
GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void
nice_agent_class_init (NiceAgentClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->get_property = nice_agent_get_property;
gobject_class->set_property = nice_agent_set_property;
gobject_class->dispose = nice_agent_dispose;
g_object_class_install_property (gobject_class, PROP_SOCKET_FACTORY,
g_param_spec_pointer (
"socket-factory",
"UDP socket factory",
"The socket factory used to create new UDP sockets",
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
static void
nice_agent_init (NiceAgent *agent)
{
agent->next_candidate_id = 1;
agent->next_stream_id = 1;
}
/**
* nice_agent_new:
* @factory: a NiceUDPSocketFactory used for allocating sockets
......@@ -152,13 +205,51 @@ candidate_pair_priority (
NiceAgent *
nice_agent_new (NiceUDPSocketFactory *factory)
{
NiceAgent *agent;
return g_object_new (NICE_TYPE_AGENT,
"socket-factory", factory,
NULL);
}
static void
nice_agent_get_property (
GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
NiceAgent *agent = NICE_AGENT (object);
agent = g_slice_new0 (NiceAgent);
agent->socket_factory = factory;
agent->next_candidate_id = 1;
agent->next_stream_id = 1;
return agent;
switch (property_id)
{
case PROP_SOCKET_FACTORY:
g_value_set_pointer (value, agent->socket_factory);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
nice_agent_set_property (
GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
NiceAgent *agent = NICE_AGENT (object);
switch (property_id)
{
case PROP_SOCKET_FACTORY:
agent->socket_factory = g_value_get_pointer (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
......@@ -930,8 +1021,15 @@ nice_agent_get_local_candidates (
**/
void
nice_agent_free (NiceAgent *agent)
{
g_object_unref (agent);
}
static void
nice_agent_dispose (GObject *object)
{
GSList *i;
NiceAgent *agent = NICE_AGENT (object);
for (i = agent->local_addresses; i; i = i->next)
{
......@@ -973,7 +1071,8 @@ nice_agent_free (NiceAgent *agent)
g_slist_free (agent->streams);
agent->streams = NULL;
g_slice_free (NiceAgent, agent);
if (G_OBJECT_CLASS (nice_agent_parent_class)->dispose)
G_OBJECT_CLASS (nice_agent_parent_class)->dispose (object);
}
......
......@@ -2,7 +2,7 @@
#ifndef _AGENT_H
#define _AGENT_H
#include <glib.h>
#include <glib-object.h>
#include "udp.h"
#include "address.h"
......@@ -10,6 +10,28 @@
G_BEGIN_DECLS
#define NICE_TYPE_AGENT nice_agent_get_type()
#define NICE_AGENT(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
NICE_TYPE_AGENT, NiceAgent))
#define NICE_AGENT_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), \
NICE_TYPE_AGENT, NiceAgentClass))
#define NICE_IS_AGENT(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
NICE_TYPE_AGENT))
#define NICE_IS_AGENT_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
NICE_TYPE_AGENT))
#define NICE_AGENT_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
NICE_TYPE_AGENT, NiceAgentClass))
typedef struct _NiceAgent NiceAgent;
typedef void (*NiceAgentRecvFunc) (
......@@ -18,6 +40,7 @@ typedef void (*NiceAgentRecvFunc) (
struct _NiceAgent
{
GObject parent;
guint next_candidate_id;
guint next_stream_id;
NiceUDPSocketFactory *socket_factory;
......@@ -31,6 +54,15 @@ struct _NiceAgent
gpointer read_func_data;
};
typedef struct _NiceAgentClass NiceAgentClass;
struct _NiceAgentClass
{
GObjectClass parent_class;
};
GType nice_agent_get_type (void);
NiceAgent *
nice_agent_new (NiceUDPSocketFactory *factory);
......
......@@ -9,6 +9,8 @@ main (void)
NiceAddress addr = {0,};
NiceUDPSocketFactory factory;
g_type_init ();
nice_udp_fake_socket_factory_init (&factory);
if (!nice_address_set_ipv4_from_string (&addr, "127.0.0.1"))
......
......@@ -30,6 +30,8 @@ main (void)
NiceAddress addr = {0,};
NiceUDPSocketFactory factory;
g_type_init ();
nice_udp_fake_socket_factory_init (&factory);
agent = nice_agent_new (&factory);
nice_address_set_ipv4 (&addr, 0x7f000001);
......
......@@ -38,6 +38,8 @@ main (void)
GSList *fds = NULL;
GSList *readable;
g_type_init ();
/* set up agent */
if (!nice_address_set_ipv4_from_string (&addr, "127.0.0.1"))
......
......@@ -11,6 +11,8 @@ main (void)
NiceAddress addr = {0,};
NiceUDPSocketFactory factory;
g_type_init ();
nice_udp_fake_socket_factory_init (&factory);
/* set up agent */
......
......@@ -92,6 +92,8 @@ main (void)
NiceAddress local_addr = {0,};
NiceAddress remote_addr = {0,};
g_type_init ();
/* set up */
nice_rng_set_new_func (nice_rng_glib_new_predictable);
......
......@@ -191,6 +191,8 @@ main (void)
NiceUDPSocketFactory factory;
NiceUDPSocket *sock;
g_type_init ();
nice_udp_fake_socket_factory_init (&factory);
g_assert (nice_address_set_ipv4_from_string (&local_addr, "192.168.0.1"));
......
......@@ -12,6 +12,8 @@ main (void)
NiceCandidate *candidate;
NiceUDPSocketFactory factory;
g_type_init ();
nice_udp_fake_socket_factory_init (&factory);
g_assert (nice_address_set_ipv4_from_string (&addr_local, "192.168.0.1"));
......
......@@ -13,6 +13,7 @@ T nice_agent_add_remote_candidate
T nice_agent_add_stream
T nice_agent_free
T nice_agent_get_local_candidates
T nice_agent_get_type
T nice_agent_main_context_attach
T nice_agent_new
T nice_agent_poll_read
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment