Getting pointer to ui elements from callback functions
- From: Jacques Fortier <jfortier seul org>
- To: gnome-devel-list gnome org
- Subject: Getting pointer to ui elements from callback functions
- Date: Mon, 24 Jan 2000 13:33:49 -0500 (EST)
Hi,
I'm doing some weird stuff where I'm registering a callback and
passing a pointer to another callback function in the userdata field, and
then registering the second callback function from within the first. My
problem is that the first callback function is responding to glib
iochannel events, and I want the second callback function to report on the
status of the first one via the gui. But, with all this calling and
passing of callbacks, there's no way to pass a pointer to a widget to the
second callback, and therefore no way to allow it to do anything to the
gui. This is all complicated by the fact that I'm trying to keep the io
and gui parts of the program separate so that I can slap on a non-gnome
frontend later.
So, is there a way, without using global variables, of getting the
toplevel widget (in this case a GnomeApp) -- or any widget for that
matter? I looked at using glib's datasets to associate a piece of data
with a pointer to a function, but I'm not sure if this is safe and it
seems pretty kludgy to me? Will this idea work, or is there a better or
more elegant method of doing this?
Thanks,
Jacques Fortier
here's some of my code. Currently, the status_cb can't do anything
because it has no way of communicating with the user
/*
* net_listen: start the process of listening for connections
* from clients
*/
void net_listen(gint port, gchar *pw, gint numplayers,
void (*status_cb)(NetResult, gchar *))
{
GIOChannel *servchan = NULL;
GTcpSocket *server = NULL;
g_assert(physics != NULL);
physics->password = g_strdup(pw);
physics->num_players = numplayers;
server = gnet_tcp_socket_server_new(port);
g_assert(server != NULL);
servchan = gnet_tcp_socket_get_iochannel(server);
g_assert(servchan != NULL);
g_io_add_watch(servchan, G_IO_IN, net_listen_cb,
(gpointer)server);
g_io_add_watch(servchan, G_IO_ERR | G_IO_HUP | G_IO_NVAL,
net_listen_error_cb, status_cb);
status_cb(NET_WORKING, NULL);
}
gboolean net_listen_error_cb(GIOChannel *con_socket, GIOCondition cond,
void (*status_cb)(NetResult, gchar *))
{
// {TODO} Improve the status messages
switch(cond)
{
case G_IO_ERR:
status_cb(NET_FAILURE, "There was an error");
break;
case G_IO_NVAL:
status_cb(NET_FAILURE, "There was an error");
break;
case G_IO_HUP:
status_cb(NET_FAILURE, "There was an error");
break;
}
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]