multihandle: rename num-fds/-sockets to num-handles

This commit is contained in:
Thomas Vander Stichele 2012-01-28 18:06:02 +01:00
parent fa14beb88b
commit 029b9b49de
8 changed files with 35 additions and 76 deletions

View file

@ -160,8 +160,6 @@ enum
PROP_HANDLE_READ,
PROP_NUM_FDS,
PROP_LAST
};
@ -185,8 +183,6 @@ gst_fdset_mode_get_type (void)
return fdset_mode_type;
}
static void gst_multi_fd_sink_finalize (GObject * object);
static void gst_multi_fd_sink_clear_post (GstMultiHandleSink * mhsink);
static void gst_multi_fd_sink_stop_pre (GstMultiHandleSink * mhsink);
static void gst_multi_fd_sink_stop_post (GstMultiHandleSink * mhsink);
@ -226,7 +222,6 @@ gst_multi_fd_sink_class_init (GstMultiFdSinkClass * klass)
gobject_class->set_property = gst_multi_fd_sink_set_property;
gobject_class->get_property = gst_multi_fd_sink_get_property;
gobject_class->finalize = gst_multi_fd_sink_finalize;
/**
* GstMultiFdSink::mode
@ -254,11 +249,6 @@ gst_multi_fd_sink_class_init (GstMultiFdSinkClass * klass)
"Handle client reads and discard the data",
DEFAULT_HANDLE_READ, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_NUM_FDS,
g_param_spec_uint ("num-fds", "Number of fds",
"The current number of client file descriptors.",
0, G_MAXUINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GstMultiFdSink::add:
* @gstmultifdsink: the multifdsink element to emit this signal on
@ -423,7 +413,6 @@ gst_multi_fd_sink_class_init (GstMultiFdSinkClass * klass)
gstmultihandlesink_class->remove_client_link =
GST_DEBUG_FUNCPTR (gst_multi_fd_sink_remove_client_link);
klass->add = GST_DEBUG_FUNCPTR (gst_multi_fd_sink_add);
klass->add_full = GST_DEBUG_FUNCPTR (gst_multi_fd_sink_add_full);
klass->remove = GST_DEBUG_FUNCPTR (gst_multi_fd_sink_remove);
@ -436,23 +425,15 @@ gst_multi_fd_sink_class_init (GstMultiFdSinkClass * klass)
static void
gst_multi_fd_sink_init (GstMultiFdSink * this)
{
GstMultiHandleSink *mhsink = GST_MULTI_HANDLE_SINK (this);
this->mode = DEFAULT_MODE;
this->handle_hash = g_hash_table_new (g_int_hash, g_int_equal);
mhsink->handle_hash = g_hash_table_new (g_int_hash, g_int_equal);
this->handle_read = DEFAULT_HANDLE_READ;
}
static void
gst_multi_fd_sink_finalize (GObject * object)
{
GstMultiFdSink *this = GST_MULTI_FD_SINK (object);
g_hash_table_destroy (this->handle_hash);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static int
gst_multi_fd_sink_client_get_fd (GstMultiHandleClient * client)
{
@ -514,13 +495,13 @@ gst_multi_fd_sink_add_full (GstMultiFdSink * sink, GstMultiSinkHandle handle,
CLIENTS_LOCK (sink);
/* check the hash to find a duplicate fd */
clink = g_hash_table_lookup (sink->handle_hash, &client->gfd.fd);
clink = g_hash_table_lookup (mhsink->handle_hash, &client->gfd.fd);
if (clink != NULL)
goto duplicate;
/* we can add the fd now */
clink = mhsink->clients = g_list_prepend (mhsink->clients, client);
g_hash_table_insert (sink->handle_hash, &client->gfd.fd, clink);
g_hash_table_insert (mhsink->handle_hash, &client->gfd.fd, clink);
mhsink->clients_cookie++;
/* set the socket to non blocking */
@ -603,7 +584,7 @@ gst_multi_fd_sink_remove (GstMultiFdSink * sink, GstMultiSinkHandle handle)
GST_DEBUG_OBJECT (sink, "%s removing client", debug);
CLIENTS_LOCK (sink);
clink = g_hash_table_lookup (sink->handle_hash, &fd);
clink = g_hash_table_lookup (mhsink->handle_hash, &fd);
if (clink != NULL) {
GstTCPClient *client = (GstTCPClient *) clink->data;
GstMultiHandleClient *mhclient = (GstMultiHandleClient *) client;
@ -645,7 +626,7 @@ gst_multi_fd_sink_remove_flush (GstMultiFdSink * sink,
GST_DEBUG_OBJECT (sink, "%s flushing client", debug);
CLIENTS_LOCK (sink);
clink = g_hash_table_lookup (sink->handle_hash, &fd);
clink = g_hash_table_lookup (mhsink->handle_hash, &fd);
if (clink != NULL) {
GstTCPClient *client = (GstTCPClient *) clink->data;
GstMultiHandleClient *mhclient = (GstMultiHandleClient *) client;
@ -708,7 +689,7 @@ gst_multi_fd_sink_get_stats (GstMultiFdSink * sink, GstMultiSinkHandle handle)
mhsinkclass->handle_debug (handle, debug);
CLIENTS_LOCK (sink);
clink = g_hash_table_lookup (sink->handle_hash, &fd);
clink = g_hash_table_lookup (mhsink->handle_hash, &fd);
if (clink == NULL)
goto noclient;
@ -856,7 +837,7 @@ gst_multi_fd_sink_remove_client_link (GstMultiHandleSink * sink, GList * link)
/* fd cannot be reused in the above signal callback so we can safely
* remove it from the hashtable here */
if (!g_hash_table_remove (mfsink->handle_hash, &client->gfd.fd)) {
if (!g_hash_table_remove (sink->handle_hash, &client->gfd.fd)) {
GST_WARNING_OBJECT (sink,
"%s error removing client %p from hash", mhclient->debug, client);
}
@ -1692,9 +1673,6 @@ gst_multi_fd_sink_get_property (GObject * object, guint prop_id, GValue * value,
case PROP_HANDLE_READ:
g_value_set_boolean (value, multifdsink->handle_read);
break;
case PROP_NUM_FDS:
g_value_set_uint (value, g_hash_table_size (multifdsink->handle_hash));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -1746,6 +1724,6 @@ gst_multi_fd_sink_stop_post (GstMultiHandleSink * mhsink)
gst_poll_free (mfsink->fdset);
mfsink->fdset = NULL;
}
g_hash_table_foreach_remove (mfsink->handle_hash, multifdsink_hash_remove,
g_hash_table_foreach_remove (mhsink->handle_hash, multifdsink_hash_remove,
mfsink);
}

View file

@ -66,8 +66,6 @@ struct _GstMultiFdSink {
GstMultiHandleSink element;
/*< private >*/
GHashTable *handle_hash; /* index on fd to client */
gint mode;
GstPoll *fdset;

View file

@ -194,9 +194,7 @@ enum
PROP_RESEND_STREAMHEADER,
#if 0
PROP_NUM_SOCKETS,
#endif
PROP_NUM_HANDLES,
PROP_LAST
};
@ -458,12 +456,12 @@ gst_multi_handle_sink_class_init (GstMultiHandleSinkClass * klass)
DEFAULT_RESEND_STREAMHEADER,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
#if 0
g_object_class_install_property (gobject_class, PROP_NUM_SOCKETS,
g_param_spec_uint ("num-sockets", "Number of sockets",
"The current number of client sockets",
g_object_class_install_property (gobject_class, PROP_NUM_HANDLES,
g_param_spec_uint ("num-handles", "Number of handles",
"The current number of client handles",
0, G_MAXUINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
#if 0
/**
* GstMultiHandleSink::add:
* @gstmultihandlesink: the multihandlesink element to emit this signal on
@ -689,6 +687,7 @@ gst_multi_handle_sink_finalize (GObject * object)
CLIENTS_LOCK_CLEAR (this);
g_array_free (this->bufqueue, TRUE);
g_hash_table_destroy (this->handle_hash);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -2620,12 +2619,10 @@ gst_multi_handle_sink_get_property (GObject * object, guint prop_id,
case PROP_RESEND_STREAMHEADER:
g_value_set_boolean (value, multihandlesink->resend_streamheader);
break;
#if 0
case PROP_NUM_SOCKETS:
case PROP_NUM_HANDLES:
g_value_set_uint (value,
g_hash_table_size (multihandlesink->socket_hash));
g_hash_table_size (multihandlesink->handle_hash));
break;
#endif
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;

View file

@ -214,6 +214,8 @@ struct _GstMultiHandleSink {
GList *clients; /* list of clients we are serving */
guint clients_cookie; /* Cookie to detect changes to the clients list */
GHashTable *handle_hash; /* index of handle -> GstMultiHandleClient */
GMainContext *main_context;
GCancellable *cancellable;
@ -286,6 +288,7 @@ struct _GstMultiHandleSinkClass {
GstStructure* (*get_stats) (GstMultiHandleSink *sink, GstMultiSinkHandle handle);
void (*remove_client_link) (GstMultiHandleSink * sink, GList * link);
/* vtable */
gboolean (*init) (GstMultiHandleSink *sink);
gboolean (*close) (GstMultiHandleSink *sink);

View file

@ -142,8 +142,6 @@ enum
{
PROP_0,
PROP_NUM_SOCKETS,
PROP_LAST
};
@ -198,11 +196,6 @@ gst_multi_socket_sink_class_init (GstMultiSocketSinkClass * klass)
gobject_class->get_property = gst_multi_socket_sink_get_property;
gobject_class->finalize = gst_multi_socket_sink_finalize;
g_object_class_install_property (gobject_class, PROP_NUM_SOCKETS,
g_param_spec_uint ("num-sockets", "Number of sockets",
"The current number of client sockets",
0, G_MAXUINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GstMultiSocketSink::add:
* @gstmultisocketsink: the multisocketsink element to emit this signal on
@ -381,7 +374,9 @@ gst_multi_socket_sink_class_init (GstMultiSocketSinkClass * klass)
static void
gst_multi_socket_sink_init (GstMultiSocketSink * this)
{
this->handle_hash = g_hash_table_new (g_direct_hash, g_int_equal);
GstMultiHandleSink *mhsink = GST_MULTI_HANDLE_SINK (this);
mhsink->handle_hash = g_hash_table_new (g_direct_hash, g_int_equal);
this->cancellable = g_cancellable_new ();
}
@ -391,7 +386,6 @@ gst_multi_socket_sink_finalize (GObject * object)
{
GstMultiSocketSink *this = GST_MULTI_SOCKET_SINK (object);
g_hash_table_destroy (this->handle_hash);
if (this->cancellable) {
g_object_unref (this->cancellable);
this->cancellable = NULL;
@ -457,13 +451,13 @@ gst_multi_socket_sink_add_full (GstMultiSocketSink * sink,
CLIENTS_LOCK (sink);
/* check the hash to find a duplicate fd */
clink = g_hash_table_lookup (sink->handle_hash, handle.socket);
clink = g_hash_table_lookup (mhsink->handle_hash, handle.socket);
if (clink != NULL)
goto duplicate;
/* we can add the fd now */
clink = mhsink->clients = g_list_prepend (mhsink->clients, client);
g_hash_table_insert (sink->handle_hash, handle.socket, clink);
g_hash_table_insert (mhsink->handle_hash, handle.socket, clink);
mhsink->clients_cookie++;
/* set the socket to non blocking */
@ -540,7 +534,7 @@ gst_multi_socket_sink_remove (GstMultiSocketSink * sink,
GST_DEBUG_OBJECT (sink, "%s removing client", debug);
CLIENTS_LOCK (sink);
clink = g_hash_table_lookup (sink->handle_hash, handle.socket);
clink = g_hash_table_lookup (mhsink->handle_hash, handle.socket);
if (clink != NULL) {
GstSocketClient *client = clink->data;
GstMultiHandleClient *mhclient = (GstMultiHandleClient *) client;
@ -578,7 +572,7 @@ gst_multi_socket_sink_remove_flush (GstMultiSocketSink * sink,
GST_DEBUG_OBJECT (sink, "%s flushing client", debug);
CLIENTS_LOCK (sink);
clink = g_hash_table_lookup (sink->handle_hash, handle.socket);
clink = g_hash_table_lookup (mhsink->handle_hash, handle.socket);
if (clink != NULL) {
GstSocketClient *client = clink->data;
GstMultiHandleClient *mhclient = (GstMultiHandleClient *) client;
@ -621,7 +615,7 @@ gst_multi_socket_sink_get_stats (GstMultiSocketSink * sink,
mhsinkclass->handle_debug (handle, debug);
CLIENTS_LOCK (sink);
clink = g_hash_table_lookup (sink->handle_hash, handle.socket);
clink = g_hash_table_lookup (mhsink->handle_hash, handle.socket);
if (clink == NULL)
goto noclient;
@ -677,7 +671,6 @@ gst_multi_socket_sink_remove_client_link (GstMultiHandleSink * sink,
GTimeVal now;
GstSocketClient *client = link->data;
GstMultiHandleClient *mhclient = (GstMultiHandleClient *) client;
GstMultiSocketSink *mssink = GST_MULTI_SOCKET_SINK (sink);
GstMultiSocketSinkClass *fclass;
fclass = GST_MULTI_SOCKET_SINK_GET_CLASS (sink);
@ -753,7 +746,7 @@ gst_multi_socket_sink_remove_client_link (GstMultiHandleSink * sink,
/* fd cannot be reused in the above signal callback so we can safely
* remove it from the hashtable here */
if (!g_hash_table_remove (mssink->handle_hash, mhclient->handle.socket)) {
if (!g_hash_table_remove (sink->handle_hash, mhclient->handle.socket)) {
GST_WARNING_OBJECT (sink,
"%s error removing client %p from hash", mhclient->debug, client);
}
@ -1366,7 +1359,7 @@ gst_multi_socket_sink_socket_condition (GstMultiSinkHandle handle,
GST_MULTI_HANDLE_SINK_GET_CLASS (mhsink);
CLIENTS_LOCK (sink);
clink = g_hash_table_lookup (sink->handle_hash, handle.socket);
clink = g_hash_table_lookup (mhsink->handle_hash, handle.socket);
if (clink == NULL) {
ret = FALSE;
goto done;
@ -1491,20 +1484,12 @@ gst_multi_socket_sink_set_property (GObject * object, guint prop_id,
}
}
// FIXME: remove ?
static void
gst_multi_socket_sink_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstMultiSocketSink *multisocketsink;
multisocketsink = GST_MULTI_SOCKET_SINK (object);
switch (prop_id) {
case PROP_NUM_SOCKETS:
g_value_set_uint (value,
g_hash_table_size (multisocketsink->handle_hash));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1568,7 +1553,7 @@ gst_multi_socket_sink_stop_post (GstMultiHandleSink * mhsink)
mssink->main_context = NULL;
}
g_hash_table_foreach_remove (mssink->handle_hash, multisocketsink_hash_remove,
g_hash_table_foreach_remove (mhsink->handle_hash, multisocketsink_hash_remove,
mssink);
}

View file

@ -67,8 +67,6 @@ struct _GstMultiSocketSink {
GstMultiHandleSink element;
/*< private >*/
GHashTable *handle_hash; /* index on socket to client */
GMainContext *main_context;
GCancellable *cancellable;

View file

@ -161,7 +161,7 @@ G_STMT_START { \
#define fail_unless_num_handles(sink,num) \
G_STMT_START { \
gint handles; \
g_object_get (sink, "num-fds", &handles, NULL); \
g_object_get (sink, "num-handles", &handles, NULL); \
fail_unless (handles == num, \
"sink has %d handles instead of expected %d", handles, num); \
} G_STMT_END;

View file

@ -153,7 +153,7 @@ G_STMT_START { \
#define fail_unless_num_handles(sink,num) \
G_STMT_START { \
gint handles; \
g_object_get (sink, "num-sockets", &handles, NULL); \
g_object_get (sink, "num-handles", &handles, NULL); \
fail_unless (handles == num, \
"sink has %d handles instead of expected %d", handles, num); \
} G_STMT_END;