Beispiel #1
0
gint
gdk_input_add(gint source,
              GdkInputCondition condition,
              GdkInputFunction function, gpointer data)
{
   return gdk_input_add_full(source, condition, function, data, NULL);
}
void
GtkTCPConnectionHandler::handleWriteSlot(TCPClientConnection* conn,
                                         bool connect)
{
   connStorage_t::iterator it = m_connections.find(conn);
   if ( connect ) {
      // Disconnect...
      // note: old code here, not sure if we should disconnect or not...?
      // handleWriteSlot(conn, false);

      // create connection data that we
      // pass to callback function
      ConnData *data = new ConnData;
      data->handler = this;
      data->client = conn; 

      //
      // Note: gdk_input_add_full is deprecated
      // but currently the g_io_* functions are 
      // too ....painfull
      guint event_id = gdk_input_add_full( 
                it->second.m_fd,                                     
                GDK_INPUT_WRITE,
                GtkTCPConnectionHandler::gdkWriteCallback,
                data,
                destroyCallbackData);


      it->second.m_outSignal = event_id;
   } else {
      gdk_input_remove( it->second.m_outSignal );
   }
}
void
GtkTCPConnectionHandler::handleReadSlot(TCPClientConnection* conn,
                                        bool connect)
{
   connStorage_t::iterator it = m_connections.find(conn);
   if ( connect ) {
      // Disconnect.
      handleReadSlot(conn, false);
      
      // create connection data that we
      // pass to callback function
      ConnData *data = new ConnData;
      data->handler = this;
      data->client = conn;

      //
      // Note: gdk_input_add_full is deprecated
      // but currently the g_io_* functions are 
      // too ....painfull
      guint event_id = gdk_input_add_full(
               it->second.m_fd,
               (GdkInputCondition)(GDK_INPUT_READ | GDK_INPUT_EXCEPTION),
               GtkTCPConnectionHandler::gdkReadCallback,
               data,
               destroyCallbackData);

      it->second.m_inSignal = event_id;
   } else {
      gdk_input_remove( it->second.m_inSignal );
   }
}
Beispiel #4
0
gint c_gdk_input_add_full (gint s_fd, 
						   GdkInputCondition condition,
						   EIF_OBJ object, 
						   EIF_PROC func, 
						   EIF_PROC destruct,
						   callback_data **p)

{
  callback_data *cbd;


  eif_freeze (object);

  /* Allocate data for two callback blocks */
  cbd = (callback_data *)g_malloc (2 * sizeof (callback_data));
  *p = cbd;
  cbd->rtn = func;
  cbd->obj = eif_access (object);

  /* descriptor destruction callback */
  cbd++;
  cbd->rtn = destruct;
  cbd->obj = eif_access (object);

  return (gdk_input_add_full (s_fd, condition, 
							  c_gdk_input_function,
							  cbd,
							  c_gdk_destroy_notify));

}
void CFDMonitor::connectFD(int fd, void (*f)(void *), void * data) {

    cbdata * foo = new cbdata(fd,f,data);
    gint m_ID = gdk_input_add_full(fd,
                                   GDK_INPUT_READ,
                                   fdInputHandler,
                                   foo,
                                   NULL);
}
Beispiel #6
0
/* Run the program as '<path> -', piping the data to it via stdin.
 * You can g_free() the data as soon as this returns.
 */
void run_with_data(const char *path, gpointer data, gulong length)
{
	const char	*argv[] = {NULL, "-", NULL};
	struct stat 	info;
	int		fds[2];
	PipedData	*pd;

	if (stat(path, &info))
	{
		delayed_error(_("Program %s not found - deleted?"), path);
		return;
	}

	if (S_ISDIR(info.st_mode))
		argv[0] = make_path(path, "AppRun");
	else
		argv[0] = path;
	
	if (pipe(fds))
	{
		delayed_error("pipe: %s", g_strerror(errno));
		return;
	}
	close_on_exec(fds[1], TRUE);
	close_on_exec(fds[0], TRUE);

	switch (fork())
	{
		case -1:
			delayed_error("fork: %s", g_strerror(errno));
			close(fds[1]);
			break;
		case 0:
			/* We are the child */
			chdir(home_dir);
			if (dup2(fds[0], 0) == -1)
				g_warning("dup2() failed: %s\n",
						g_strerror(errno));
			else
			{
				close_on_exec(0, FALSE);
				if (execv(argv[0], (char **) argv))
					g_warning("execv(%s) failed: %s\n",
						argv[0], g_strerror(errno));
			}
			_exit(1);
		default:
			/* We are the parent */
			set_blocking(fds[1], FALSE);
			pd = g_new(PipedData, 1);
			pd->data = g_malloc(length);
			memcpy(pd->data, data, length);
			pd->length = length;
			pd->sent = 0;
			pd->tag = gdk_input_add_full(fds[1], GDK_INPUT_WRITE,
						write_data, pd, NULL);
			break;
	}

	close(fds[0]);
}