Commit f136ef1b authored by Dafydd Harries's avatar Dafydd Harries

emit signal when component becomes connected

darcs-hash:20070213164350-c9803-c86275d76f9ccffc8dc22beccc57e6783da7cf4d.gz
parent 0445310e
...@@ -81,6 +81,8 @@ ...@@ -81,6 +81,8 @@
^agent/test-send$ ^agent/test-send$
^agent/test-poll$ ^agent/test-poll$
^agent/test-mainloop$ ^agent/test-mainloop$
^agent/agent-signals-marshal.h$
^agent/agent-signals-marshal.c$
# stun/ stuff # stun/ stuff
^stun/libstun.la$ ^stun/libstun.la$
......
...@@ -14,11 +14,25 @@ COMMON_LDADD = libagent.la $(GLIB_LIBS) ...@@ -14,11 +14,25 @@ COMMON_LDADD = libagent.la $(GLIB_LIBS)
noinst_LTLIBRARIES = libagent.la noinst_LTLIBRARIES = libagent.la
%-signals-marshal.h: %-signals-marshal.list
glib-genmarshal --header --prefix=$(subst -,_,$*)_marshal $< > $*-signals-marshal.h
%-signals-marshal.c: %-signals-marshal.list
glib-genmarshal --body --prefix=$(subst -,_,$*)_marshal $< > $*-signals-marshal.c
sed -i "1i#include \"$*-signals-marshal.h\"" $*-signals-marshal.c
BUILT_SOURCES = \
agent-signals-marshal.h \
agent-signals-marshal.c
CLEANFILES += $(BUILT_SOURCES)
libagent_la_SOURCES = \ libagent_la_SOURCES = \
candidate.h \ candidate.h \
candidate.c \ candidate.c \
agent.h \ agent.h \
agent.c agent.c \
$(BUILT_SOURCES)
libagent_la_LIBADD = \ libagent_la_LIBADD = \
$(top_builddir)/address/libaddress.la \ $(top_builddir)/address/libaddress.la \
......
# component-status-changed
VOID:UINT,UINT,UINT
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "udp.h" #include "udp.h"
#include "random.h" #include "random.h"
#include "agent.h" #include "agent.h"
#include "agent-signals-marshal.h"
/*** component ***/ /*** component ***/
...@@ -37,6 +38,7 @@ struct _Component ...@@ -37,6 +38,7 @@ struct _Component
/* the remote address that the last connectivity check came from */ /* the remote address that the last connectivity check came from */
NiceAddress *peer_addr; NiceAddress *peer_addr;
guint id; guint id;
NiceComponentState state;
}; };
...@@ -149,6 +151,16 @@ enum ...@@ -149,6 +151,16 @@ enum
}; };
enum
{
SIGNAL_COMPONENT_STATE_CHANGED,
N_SIGNALS,
};
static guint signals[N_SIGNALS];
static void static void
nice_agent_dispose (GObject *object); nice_agent_dispose (GObject *object);
...@@ -176,12 +188,30 @@ nice_agent_class_init (NiceAgentClass *klass) ...@@ -176,12 +188,30 @@ nice_agent_class_init (NiceAgentClass *klass)
gobject_class->set_property = nice_agent_set_property; gobject_class->set_property = nice_agent_set_property;
gobject_class->dispose = nice_agent_dispose; gobject_class->dispose = nice_agent_dispose;
/* install properties */
g_object_class_install_property (gobject_class, PROP_SOCKET_FACTORY, g_object_class_install_property (gobject_class, PROP_SOCKET_FACTORY,
g_param_spec_pointer ( g_param_spec_pointer (
"socket-factory", "socket-factory",
"UDP socket factory", "UDP socket factory",
"The socket factory used to create new UDP sockets", "The socket factory used to create new UDP sockets",
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/* install signals */
signals[SIGNAL_COMPONENT_STATE_CHANGED] =
g_signal_new (
"component-state-changed",
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
0,
NULL,
NULL,
agent_marshal_VOID__UINT_UINT_UINT,
G_TYPE_NONE,
3,
G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT,
G_TYPE_INVALID);
} }
...@@ -739,6 +769,7 @@ static guint ...@@ -739,6 +769,7 @@ static guint
_nice_agent_recv ( _nice_agent_recv (
NiceAgent *agent, NiceAgent *agent,
Stream *stream, Stream *stream,
Component *component,
NiceCandidate *candidate, NiceCandidate *candidate,
guint buf_len, guint buf_len,
gchar *buf) gchar *buf)
...@@ -779,6 +810,14 @@ _nice_agent_recv ( ...@@ -779,6 +810,14 @@ _nice_agent_recv (
if ((buf[0] & 0xc0) == 0x80) if ((buf[0] & 0xc0) == 0x80)
{ {
/* looks like RTP */ /* looks like RTP */
if (component->state != NICE_COMPONENT_STATE_CONNECTED)
{
component->state = NICE_COMPONENT_STATE_CONNECTED;
g_signal_emit (agent, signals[SIGNAL_COMPONENT_STATE_CHANGED], 0,
stream->id, component->id, component->state);
}
return len; return len;
} }
else if ((buf[0] & 0xc0) == 0) else if ((buf[0] & 0xc0) == 0)
...@@ -865,8 +904,9 @@ nice_agent_recv ( ...@@ -865,8 +904,9 @@ nice_agent_recv (
candidate = _local_candidate_lookup_by_fd (agent, j); candidate = _local_candidate_lookup_by_fd (agent, j);
g_assert (candidate); g_assert (candidate);
stream = _stream_lookup (agent, candidate->stream_id); stream = _stream_lookup (agent, candidate->stream_id);
len = _nice_agent_recv (agent, stream, candidate, buf_len, g_assert (stream);
buf); len = _nice_agent_recv (agent, stream, stream->component,
candidate, buf_len, buf);
if (len > 0) if (len > 0)
return len; return len;
...@@ -953,7 +993,8 @@ nice_agent_poll_read ( ...@@ -953,7 +993,8 @@ nice_agent_poll_read (
if (stream == NULL) if (stream == NULL)
break; break;
len = _nice_agent_recv (agent, stream, candidate, 1024, buf); len = _nice_agent_recv (agent, stream, stream->component,
candidate, 1024, buf);
if (len && func != NULL) if (len && func != NULL)
func (agent, stream->id, candidate->component_id, len, buf, func (agent, stream->id, candidate->component_id, len, buf,
...@@ -1102,7 +1143,8 @@ nice_agent_g_source_cb ( ...@@ -1102,7 +1143,8 @@ nice_agent_g_source_cb (
if (stream == NULL) if (stream == NULL)
return TRUE; return TRUE;
len = _nice_agent_recv (agent, stream, candidate, 1024, buf); len = _nice_agent_recv (agent, stream, stream->component, candidate, 1024,
buf);
if (len > 0) if (len > 0)
agent->read_func (agent, candidate->stream_id, candidate->component_id, agent->read_func (agent, candidate->stream_id, candidate->component_id,
......
...@@ -32,6 +32,13 @@ G_BEGIN_DECLS ...@@ -32,6 +32,13 @@ G_BEGIN_DECLS
(G_TYPE_INSTANCE_GET_CLASS ((obj), \ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
NICE_TYPE_AGENT, NiceAgentClass)) NICE_TYPE_AGENT, NiceAgentClass))
typedef enum
{
NICE_COMPONENT_STATE_DISCONNECTED,
NICE_COMPONENT_STATE_CONNECTING,
NICE_COMPONENT_STATE_CONNECTED,
} NiceComponentState;
typedef struct _NiceAgent NiceAgent; typedef struct _NiceAgent NiceAgent;
typedef void (*NiceAgentRecvFunc) ( typedef void (*NiceAgentRecvFunc) (
......
...@@ -4,6 +4,23 @@ ...@@ -4,6 +4,23 @@
#include "udp-fake.h" #include "udp-fake.h"
#include "agent.h" #include "agent.h"
static gboolean cb_called = FALSE;
static void
cb_component_state_changed (
NiceAgent *agent,
guint stream_id,
guint component_id,
guint state)
{
g_assert (agent != NULL);
g_assert (stream_id == 1);
g_assert (component_id == 1);
g_assert (state == NICE_COMPONENT_STATE_CONNECTED);
g_assert (cb_called == FALSE);
cb_called = TRUE;
}
int int
main (void) main (void)
{ {
...@@ -21,6 +38,8 @@ main (void) ...@@ -21,6 +38,8 @@ main (void)
nice_agent_add_local_address (agent, &addr); nice_agent_add_local_address (agent, &addr);
nice_agent_add_stream (agent, 1); nice_agent_add_stream (agent, 1);
g_assert (agent->local_candidates != NULL); g_assert (agent->local_candidates != NULL);
g_signal_connect (agent, "component-state-changed",
(GCallback) cb_component_state_changed, NULL);
/* recieve an RTP packet */ /* recieve an RTP packet */
...@@ -39,6 +58,8 @@ main (void) ...@@ -39,6 +58,8 @@ main (void)
g_assert (0 == strncmp (buf, "\x80lalala", 7)); g_assert (0 == strncmp (buf, "\x80lalala", 7));
} }
g_assert (cb_called);
/* clean up */ /* clean up */
g_object_unref (agent); g_object_unref (agent);
nice_udp_socket_factory_close (&factory); nice_udp_socket_factory_close (&factory);
......
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