Example #1
0
static void start_gtk(int argc, char **argv, int ErlFd){
  GIOChannel *channel;
  GIOCondition condition = G_IO_IN;
  GIOFunc func = gn_handle_read;
  gpointer user_data = NULL;

  /* exit on g_critical */
  g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL);


  /* initialise libraries */
  gtk_init(&argc, &argv);
  glade_xml_get_type();

  /* watch the erlang distribution file descriptor */
  channel = g_io_channel_unix_new(ErlFd);
  g_io_add_watch(channel, condition, func, user_data);

  gtk_main();                   /* start the event loop */
}
Example #2
0
void
fe_main (void)
{
	GIOChannel *keyboard_input;

	main_loop = g_main_loop_new(NULL, FALSE);

	/* Keyboard Entry Setup */
#ifdef G_OS_WIN32
	keyboard_input = g_io_channel_win32_new_fd(STDIN_FILENO);
#else
	keyboard_input = g_io_channel_unix_new(STDIN_FILENO);
#endif

	g_io_add_watch(keyboard_input, G_IO_IN, handle_line, NULL);

	g_main_loop_run(main_loop);

	return;
}
Example #3
0
static void
watch_for_term_signal (GnomeSettingsManager *manager)
{
        GIOChannel *channel;

        if (-1 == pipe (term_signal_pipe_fds) ||
            -1 == fcntl (term_signal_pipe_fds[0], F_SETFD, FD_CLOEXEC) ||
            -1 == fcntl (term_signal_pipe_fds[1], F_SETFD, FD_CLOEXEC)) {
                g_error ("Could not create pipe: %s", g_strerror (errno));
                exit (EXIT_FAILURE);
        }

        channel = g_io_channel_unix_new (term_signal_pipe_fds[0]);
        g_io_channel_set_encoding (channel, NULL, NULL);
        g_io_channel_set_buffered (channel, FALSE);
        g_io_add_watch (channel, G_IO_HUP, on_term_signal_pipe_closed, manager);
        g_io_channel_unref (channel);

        signal (SIGTERM, on_term_signal);
}
Example #4
0
static struct event_watch *
event_glib_add_watch(void *fd, enum event_watch_cond cond, struct callback *cb)
{
	struct event_watch *ret=g_new0(struct event_watch, 1);
	int flags=0;
	ret->iochan = g_io_channel_unix_new(GPOINTER_TO_INT(fd));
	switch (cond) {
	case event_watch_cond_read:
		flags=G_IO_IN;
		break;
	case event_watch_cond_write:
		flags=G_IO_OUT;
		break;
	case event_watch_cond_except:
		flags=G_IO_ERR|G_IO_HUP;
		break;
	}	
	ret->source = g_io_add_watch(ret->iochan, flags, event_glib_call_watch, (gpointer)cb);
	return ret;
}
static gboolean
generic_set_reader (modem_instance_t instance, GIOFunc reader, gpointer data)
{
  struct generic_modem_t *modem = (struct generic_modem_t *) instance;

  /*modem->reader = reader;
     modem->reader_pvt = data;

     DEBUG("Data set to %p", data );
   */

  if (modem->reader >= 0)
    {
      g_source_remove (modem->reader);
    }

  modem->reader = g_io_add_watch (modem->channel, G_IO_IN, reader, data);

  return TRUE;
}
int avctp_connect_browsing(struct avctp *session, int fd, size_t imtu,
								size_t omtu)
{
	struct avctp_channel *browsing;
	GIOCondition cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;

	if (session->browsing)
		return -EISCONN;

	browsing = avctp_channel_create(session, fd, imtu, omtu,
						avctp_destroy_browsing);
	if (!browsing)
		return -EINVAL;

	session->browsing = browsing;
	browsing->watch = g_io_add_watch(session->browsing->io, cond,
					(GIOFunc) session_browsing_cb, session);

	return 0;
}
Example #7
0
/*
 * _kh_startup_impl:
 * @unused: unused
 *
 * Kqueue backend startup code. Should be called only once.
 *
 * Returns: %TRUE on success, %FALSE otherwise.
 **/
static gpointer
_kh_startup_impl (gpointer unused)
{
  GIOChannel *channel = NULL;
  gboolean result = FALSE;

  kqueue_descriptor = kqueue ();
  result = (kqueue_descriptor != -1);
  if (!result)
    {
      KH_W ("Failed to initialize kqueue\n!");
      return GINT_TO_POINTER (FALSE);
    }

  result = socketpair (AF_UNIX, SOCK_STREAM, 0, kqueue_socket_pair);
  if (result != 0)
    {
      KH_W ("Failed to create socket pair\n!");
      return GINT_TO_POINTER (FALSE) ;
    }

  result = pthread_create (&kqueue_thread,
                           NULL,
                           _kqueue_thread_func,
                           &kqueue_socket_pair[1]);
  if (result != 0)
    {
      KH_W ("Failed to run kqueue thread\n!");
      return GINT_TO_POINTER (FALSE);
    }

  _km_init (_kh_file_appeared_cb);

  channel = g_io_channel_unix_new (kqueue_socket_pair[0]);
  g_io_add_watch (channel, G_IO_IN, process_kqueue_notifications, NULL);

  subs_hash_table = g_hash_table_new (g_direct_hash, g_direct_equal);

  KH_W ("started gio kqueue backend\n");
  return GINT_TO_POINTER (TRUE);
}
Example #8
0
static void start_http_request(struct http_fetch_buf *hfb)
{
  int i;
  char hostname[512];
  const char *hostn;
  const char *slash;
  int sock;
  int port;
  hostn=hfb->url+sizeof("http://")-1;
  for(i=0;(i<511)&&(hostn[i]!=':')&&(hostn[i]!='/');i++)
    hostname[i]=hostn[i];
  hostname[i]=0;
  hostn=hostn+i;
  slash=strchr(hostn,'/');
  if (!slash) 
    slash="/"; 
  if (hostn[0]==':') {
    port=atoi(hostn+1);
  } else {
    port=80;
  }
  sock=my_connectto(hostname,port);
  if (sock<0) {
    if (hfb->fail_cb)
      hfb->fail_cb(hfb->url,hfb->filename,hfb->data);
    cleanup_http_buf(hfb);
    return;
  }
  running_requests++;
  hfb->fd=sock;
  hfb->request=g_strdup_printf("%s %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: %s %s\r\n\r\n",
			       "GET",slash,hostname,PACKAGE,VERSION);
#ifdef _WIN32
  hfb->ioc=g_io_channel_win32_new_stream_socket(hfb->fd);
#else
  hfb->ioc=g_io_channel_unix_new(hfb->fd);
#endif
  g_io_add_watch(hfb->ioc,
		 G_IO_OUT|G_IO_HUP,
		 do_http_send,hfb);
}
int
main (int    argc,
      char **argv)
{
        GIOChannel *io_channel;

        setlocale (LC_ALL, "");

        g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, on_debug_message, NULL);

        event_loop = g_main_loop_new (NULL, FALSE);

        watch_for_smartcards ();

        if (pipe (signal_pipe_fds) != 0) {
                return 1;
        }
        fcntl (signal_pipe_fds[0], F_SETFD, FD_CLOEXEC);
        fcntl (signal_pipe_fds[1], F_SETFD, FD_CLOEXEC);

        io_channel = g_io_channel_unix_new (signal_pipe_fds[0]);
        g_io_channel_set_flags (io_channel, G_IO_FLAG_NONBLOCK, NULL);
        g_io_channel_set_encoding (io_channel, NULL, NULL);
        g_io_channel_set_buffered (io_channel, FALSE);
        g_io_add_watch (io_channel, G_IO_HUP, after_term_signal, NULL);
        g_io_channel_set_close_on_unref (io_channel, TRUE);
        g_io_channel_unref (io_channel);

        signal (SIGTERM, on_term_signal);
        signal (SIGPIPE, on_term_signal);

#ifdef HAVE_SYS_PRCTL_H
        prctl (PR_SET_PDEATHSIG, SIGKILL);
#endif

        g_main_loop_run (event_loop);

        stop_watching_for_smartcards ();

        return 0;
}
Example #10
0
int main (int argc, char **argv) {
    GMainLoop  *loop;
    GIOChannel *sock;

    /* read nocat.conf */
    read_conf_file( NC_CONF_PATH "/nocat.conf" );

    if (argc < 2 || strncmp(argv[1], "-D", 2) != 0)
        daemonize();

    /* initalize the log */
    initialize_log();

    /* set network parameters */
    set_network_defaults( nocat_conf );

    /* initialize the gateway type driver */
    initialize_driver();

    /* initialize the firewall */
    fw_init( nocat_conf );

    /* initialize the peer table */
    peer_tab = g_hash_new();

    /* initialize the listen socket */
    sock = http_bind_socket(
               CONF("GatewayAddr"), CONFd("GatewayPort"), CONFd("ListenQueue") );

    /* initialize the main loop and handlers */
    loop = g_main_new(FALSE);
    g_io_add_watch( sock, G_IO_IN,  (GIOFunc) handle_accept, NULL );
    g_timeout_add( 30000, (GSourceFunc) check_peers, NULL );
    g_timeout_add( 1000, (GSourceFunc) check_exit_signal, loop );

    /* Go! */
    g_message("starting main loop");
    g_main_run( loop );
    g_message("exiting main loop");
    return 0;
}
Example #11
0
static gboolean gst_avdtp_sink_start(GstBaseSink *basesink)
{
	GstAvdtpSink *self = GST_AVDTP_SINK(basesink);
	gint sk;
	gint err;

	GST_INFO_OBJECT(self, "start");

	self->watch_id = 0;

	sk = bt_audio_service_open();
	if (sk <= 0) {
		err = errno;
		GST_ERROR_OBJECT(self, "Cannot open connection to bt "
			"audio service: %s %d", strerror(err), err);
		goto failed;
	}

	self->server = g_io_channel_unix_new(sk);
	self->watch_id = g_io_add_watch(self->server, G_IO_HUP | G_IO_ERR |
					G_IO_NVAL, server_callback, self);

	self->data = g_new0(struct bluetooth_data, 1);

	self->stream = NULL;
	self->stream_caps = NULL;
	self->mp3_using_crc = -1;
	self->channel_mode = -1;

	if (!gst_avdtp_sink_get_capabilities(self)) {
		GST_ERROR_OBJECT(self, "failed to get capabilities "
				"from device");
		goto failed;
	}

	return TRUE;

failed:
	bt_audio_service_close(sk);
	return FALSE;
}
Example #12
0
/**
 * gfuse_loop_run:
 * @loop: the #GFuseLoop to run
 *
 * Runs a #GFuseLoop, mounting it and adding polling of the FUSE channel in
 * the mainloop. If multi-thread is required, also allocates all working
 * threads
 */
void gfuse_loop_run (GFuseLoop *loop)
{
    int thread;
    struct fuse_session *se;
    struct fuse_chan *ch;
    struct fuse *fuse_session;

    if (loop->priv->real_ops == NULL) {
        g_warning ("Invalid initialization of GFuseLoop, no operations loaded");
        return;
    }

    loop->priv->runtime_data = g_new0 (PrivateDataBlock, 1);
    loop->priv->runtime_data->loop = loop;

    loop->priv->shadow_ops = g_new0 (struct fuse_operations, 1);
    memcpy (loop->priv->shadow_ops, loop->priv->real_ops, sizeof (struct fuse_operations));
    loop->priv->shadow_ops->init = internal_init_wrapper;

    fuse_session = fuse_setup (loop->priv->startup_argc, loop->priv->startup_argv,
                               loop->priv->shadow_ops, sizeof (struct fuse_operations),
                               &loop->priv->mountpoint, &thread, loop->priv->runtime_data);

    loop->priv->threads = (thread != 0);
    se = fuse_get_session (fuse_session);
    ch = fuse_session_next_chan (se, NULL);
    loop->priv->fuse_fd = g_io_channel_unix_new (fuse_chan_fd (ch));

    /**
        TODO    Provide implementation also for multi-threads
    */

    /*
    if (thread)
        g_io_add_watch (loop->priv->fuse_fd, G_IO_IN, manage_fuse_mt, fuse_session);
    else
        g_io_add_watch (loop->priv->fuse_fd, G_IO_IN, manage_fuse_st, fuse_session);
    */

    g_io_add_watch (loop->priv->fuse_fd, G_IO_IN, manage_fuse_st, fuse_session);
}
Example #13
0
static gboolean server_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
{
	struct sockaddr_un addr;
	socklen_t addrlen;
	int sk, cli_sk;
	struct unix_client *client;
	GIOChannel *io;

	if (cond & G_IO_NVAL)
		return FALSE;

	if (cond & (G_IO_HUP | G_IO_ERR)) {
		g_io_channel_close(chan);
		return FALSE;
	}

	sk = g_io_channel_unix_get_fd(chan);

	memset(&addr, 0, sizeof(addr));
	addrlen = sizeof(addr);

	cli_sk = accept(sk, (struct sockaddr *) &addr, &addrlen);
	if (cli_sk < 0) {
		error("accept: %s (%d)", strerror(errno), errno);
		return TRUE;
	}

	DBG("Accepted new client connection on unix socket (fd=%d)", cli_sk);
	set_nonblocking(cli_sk);

	client = g_new0(struct unix_client, 1);
	client->sock = cli_sk;
	clients = g_slist_append(clients, client);

	io = g_io_channel_unix_new(cli_sk);
	g_io_add_watch(io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
							client_cb, client);
	g_io_channel_unref(io);

	return TRUE;
}
static int init (ServerData *app)
{
  int error_flag = 0;
  gst_init (NULL, NULL);

  app->loop         = g_main_loop_new (NULL, FALSE);
  app->pipeline     = gst_pipeline_new ("server");
  app->source       = gst_element_factory_make ("uridecodebin", "decoder");
  app->a_filter     = gst_element_factory_make ("audioconvert","audio filter");
  app->a_enc_buffer = gst_element_factory_make ("queue", "audio enc buffer");
  app->a_encoder    = gst_element_factory_make ("vorbisenc", "audio enconder");
  app->v_enc_buffer = gst_element_factory_make ("queue", "video enc buffer");
  app->v_encoder    = gst_element_factory_make ("jpegenc", "video encoder");
  app->muxer        = gst_element_factory_make ("matroskamux", "muxer");
  app->sink_buffer  = gst_element_factory_make ("queue", "sink buffer");
  app->sink         = gst_element_factory_make ("tcpserversink", "sink");

  if (app->pipeline == NULL || app->source == NULL || app->a_filter == NULL ||
      app->a_enc_buffer == NULL || app->a_encoder == NULL || 
      app->v_enc_buffer == NULL || app->v_encoder == NULL || 
      app->muxer == NULL ||  app->sink_buffer == NULL  || app->sink == NULL)
  {
    fprintf (stderr, "Error while instantiating elements\n");
    error_flag = 1;
  }
  else
  {
    GIOChannel *io = NULL;

    io = g_io_channel_unix_new (STDIN_FILENO);
    g_io_add_watch (io, G_IO_IN, handle_input, app);
    g_io_channel_unref (io);

    gst_bin_add_many (GST_BIN (app->pipeline), app->source, app->a_filter, 
        app->a_enc_buffer, app->a_encoder, app->v_enc_buffer, app->v_encoder, 
        app->muxer, app->sink_buffer, app->sink, 
        NULL);
  }

  return error_flag;
}
Example #15
0
static const char *
apm_readinfo (BatteryStatus *status)
{
  /* Code for Linux by Thomas Hood <*****@*****.**>. apm_read() will
     read from /proc/... instead and we do not need to open the device
     ourselves.
  */
  if (DEBUG) g_print("apm_readinfo() (Linux)\n");

  /* ACPI support added by Lennart Poettering <*****@*****.**> 10/27/2001
   * Updated by David Moore <*****@*****.**> 5/29/2003 to poll less and
   *   use ACPI events. */
  if (using_acpi && acpiinfo.event_fd >= 0) {
    if (acpi_count <= 0) {
      /* Only call this one out of 30 calls to apm_readinfo() (every 30 seconds)
       * since reading the ACPI system takes CPU cycles. */
      acpi_count=30;
      acpi_linux_read(&apminfo, &acpiinfo);
    }
    acpi_count--;
  }
  /* If we lost the file descriptor with ACPI events, try to get it back. */
  else if (using_acpi) {
      if (acpi_linux_init(&acpiinfo)) {
          acpiwatch = g_io_add_watch (acpiinfo.channel,
              G_IO_IN | G_IO_ERR | G_IO_HUP,
              acpi_callback, NULL);
          acpi_linux_read(&apminfo, &acpiinfo);
      }
  }
  else
    apm_read(&apminfo);

  status->present = TRUE;
  status->on_ac_power = apminfo.ac_line_status ? 1 : 0;
  status->percent = (guint) apminfo.battery_percentage;
  status->charging = (apminfo.battery_flags & 0x8) ? TRUE : FALSE;
  status->minutes = apminfo.battery_time;

  return NULL;
}
Example #16
0
static void interrupt_connect_cb(GIOChannel *chan, GError *conn_err,
							gpointer user_data)
{
	struct input_device *idev = user_data;
	GIOCondition cond = G_IO_HUP | G_IO_ERR | G_IO_NVAL;
	int err;

	if (conn_err) {
		err = -EIO;
		goto failed;
	}

	err = input_device_connected(idev);
	if (err < 0)
		goto failed;

	if (idev->uhid)
		cond |= G_IO_IN;

	idev->intr_watch = g_io_add_watch(idev->intr_io, cond, intr_watch_cb,
									idev);

	return;

failed:
	btd_service_connecting_complete(idev->service, err);

	/* So we guarantee the interrupt channel is closed before the
	 * control channel (if we only do unref GLib will close it only
	 * after returning control to the mainloop */
	if (!conn_err)
		g_io_channel_shutdown(idev->intr_io, FALSE, NULL);

	g_io_channel_unref(idev->intr_io);
	idev->intr_io = NULL;

	if (idev->ctrl_io) {
		g_io_channel_unref(idev->ctrl_io);
		idev->ctrl_io = NULL;
	}
}
Example #17
0
void StarDictClient::on_connected(gpointer data, bool succeeded)
{
    StarDictClient *oStarDictClient = (StarDictClient *)data;
    if (!succeeded) {
	static bool showed_once = false;
	if (!showed_once) {
		showed_once = true;
	        gchar *mes = g_strdup_printf(_("Can not connect to %s: %s\n"), oStarDictClient->host_.c_str(), Socket::get_error_msg().c_str());
        	on_error_.emit(mes);
	        g_free(mes);
	}
        return;
    }
#ifdef _WIN32
    oStarDictClient->channel_ = g_io_channel_win32_new_socket(oStarDictClient->sd_);
#else
    oStarDictClient->channel_ = g_io_channel_unix_new(oStarDictClient->sd_);
#endif

    g_io_channel_set_encoding(oStarDictClient->channel_, NULL, NULL);

    /* make sure that the channel is non-blocking */
    int flags = g_io_channel_get_flags(oStarDictClient->channel_);
    flags |= G_IO_FLAG_NONBLOCK;
    GError *err = NULL;
    g_io_channel_set_flags(oStarDictClient->channel_, GIOFlags(flags), &err);
    if (err) {
        g_io_channel_unref(oStarDictClient->channel_);
        oStarDictClient->channel_ = NULL;
        gchar *str = g_strdup_printf(_("Unable to set the channel as non-blocking: %s"), err->message);
        on_error_.emit(str);
        g_free(str);
        g_error_free(err);
        return;
    }

    oStarDictClient->is_connected_ = true;
    oStarDictClient->waiting_banner_ = true;
    oStarDictClient->reading_type_ = READ_LINE;
    oStarDictClient->in_source_id_ = g_io_add_watch(oStarDictClient->channel_, GIOCondition(G_IO_IN | G_IO_ERR), on_io_in_event, oStarDictClient);
}
Example #18
0
GAttrib *g_attrib_new(GIOChannel *io)
{
	struct _GAttrib *attrib;
	uint16_t imtu;
	uint16_t att_mtu;
	uint16_t cid;
	GError *gerr = NULL;

	g_io_channel_set_encoding(io, NULL, NULL);
	g_io_channel_set_buffered(io, FALSE);

	bt_io_get(io, BT_IO_L2CAP, &gerr,
			BT_IO_OPT_IMTU, &imtu,
			BT_IO_OPT_CID, &cid,
			BT_IO_OPT_INVALID);

	if (gerr) {
		error("%s", gerr->message);
		g_error_free(gerr);
		return NULL;
	}

	attrib = g_try_new0(struct _GAttrib, 1);
	if (attrib == NULL)
		return NULL;

	att_mtu = (cid == ATT_CID) ? ATT_DEFAULT_LE_MTU : imtu;

	attrib->buf = g_malloc0(att_mtu);
	attrib->buflen = att_mtu;

	attrib->io = g_io_channel_ref(io);
	attrib->requests = g_queue_new();
	attrib->responses = g_queue_new();

	attrib->read_watch = g_io_add_watch(attrib->io,
			G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
			received_data, attrib);

	return g_attrib_ref(attrib);
}
Example #19
0
guint sock_add_watch(SockInfo *sock, GIOCondition condition, SockFunc func,
		     gpointer data)
{
	sock->callback = func;
	sock->condition = condition;
	sock->data = data;

#if USE_SSL
	if (sock->ssl) {
		GSource *source;

		source = g_source_new(&sock_watch_funcs, sizeof(SockSource));
		((SockSource *)source)->sock = sock;
		g_source_set_priority(source, G_PRIORITY_DEFAULT);
		g_source_set_can_recurse(source, FALSE);
		return g_source_attach(source, NULL);
	}
#endif

	return g_io_add_watch(sock->sock_ch, condition, sock_watch_cb, sock);
}
Example #20
0
File: mce.c Project: ClementFan/mce
/** Create a pipe and io watch for handling signal from glib mainloop
 */
static gboolean mce_init_signal_pipe(void)
{
	int         result  = FALSE;
	GIOChannel *channel = 0;

	if( pipe(signal_pipe) == -1 )
		goto EXIT;

	if( (channel = g_io_channel_unix_new(signal_pipe[0])) == 0 )
		goto EXIT;

	if( !g_io_add_watch(channel, G_IO_IN, mce_rx_signal_cb, 0) )
		goto EXIT;

	result = TRUE;

EXIT:
	if( channel != 0 ) g_io_channel_unref(channel);

	return result;
}
Example #21
0
static gboolean ril_mtu_watch_start(struct ril_mtu_watch *self)
{
	if (self->fd >= 0) {
		return TRUE;
	} else if (ril_mtu_watch_open_socket(self)) {
		GASSERT(!self->channel);
		GASSERT(!self->io_watch);
		self->channel = g_io_channel_unix_new(self->fd);
		if (self->channel) {
			g_io_channel_set_encoding(self->channel, NULL, NULL);
			g_io_channel_set_buffered(self->channel, FALSE);
			self->io_watch = g_io_add_watch(self->channel,
					G_IO_IN | G_IO_NVAL | G_IO_HUP,
					ril_mtu_watch_event, self);
			return TRUE;
		}
		close(self->fd);
		self->fd = -1;
	}
	return FALSE;
}
Example #22
0
static void sco_connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
{
	struct audio_device *dev = (struct audio_device *) user_data;
	struct gateway *gw = dev->gateway;

	DBG("at the begin of sco_connect_cb() in gateway.c");

	gw->sco = g_io_channel_ref(chan);

	if (gw->sco_start_cb)
		gw->sco_start_cb(dev, err, gw->sco_start_cb_data);

	if (err) {
		error("sco_connect_cb(): %s", err->message);
		gateway_close(dev);
		return;
	}

	g_io_add_watch(gw->sco, G_IO_ERR | G_IO_HUP | G_IO_NVAL,
				(GIOFunc) sco_io_cb, dev);
}
Example #23
0
void StarDictClient::write_str(const char *str, GError **err)
{
    int len = strlen(str);
    int left_byte = len;
    GIOStatus res;
    gsize bytes_written;
    while (left_byte) {
        res = g_io_channel_write_chars(channel_, str+(len - left_byte), left_byte, &bytes_written, err);
        if (res == G_IO_STATUS_ERROR) {
            disconnect();
            return;
        }
        left_byte -= bytes_written;
    }
    res = g_io_channel_flush(channel_, err);
    if (res == G_IO_STATUS_ERROR) {
        disconnect();
    }
	if (out_source_id_ == 0)
		out_source_id_ = g_io_add_watch(channel_, GIOCondition(G_IO_OUT), on_io_out_event, this);
}
static void
setup_connection (GsmXSMPClient *client)
{
        GIOChannel    *channel;
        int            fd;

        g_debug ("GsmXSMPClient: Setting up new connection");

        fd = IceConnectionNumber (client->priv->ice_connection);
        fcntl (fd, F_SETFD, fcntl (fd, F_GETFD, 0) | FD_CLOEXEC);
        channel = g_io_channel_unix_new (fd);
        client->priv->watch_id = g_io_add_watch (channel,
                                                 G_IO_IN | G_IO_ERR,
                                                 (GIOFunc)client_iochannel_watch,
                                                 client);
        g_io_channel_unref (channel);

        set_description (client);

        g_debug ("GsmXSMPClient: New client '%s'", client->priv->description);
}
Example #25
0
static void sco_connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
{
	struct audio_device *dev = (struct audio_device *) user_data;
	struct gateway *gw = dev->gateway;

	DBG("at the begin of sco_connect_cb() in gateway.c");

	gw->sco = g_io_channel_ref(chan);

	gw->sco_id = g_io_add_watch(gw->sco, G_IO_ERR | G_IO_HUP | G_IO_NVAL,
						(GIOFunc) sco_io_cb, dev);

	if (err) {
		error("sco_connect_cb(): %s", err->message);
		gateway_suspend_stream(dev);
		return;
	}

	change_state(dev, GATEWAY_STATE_PLAYING);
	run_connect_cb(dev, NULL);
}
Example #26
0
File: io.c Project: TaylanUB/uzbl
gboolean
control_socket(GIOChannel *chan) {
    struct sockaddr_un remote;
    unsigned int t = sizeof(remote);
    GIOChannel *iochan;
    int clientsock;

    clientsock = accept (g_io_channel_unix_get_fd(chan),
                         (struct sockaddr *) &remote, &t);

    if(!uzbl.comm.client_chan)
        uzbl.comm.client_chan = g_ptr_array_new();

    if ((iochan = g_io_channel_unix_new(clientsock))) {
        g_io_channel_set_encoding(iochan, NULL, NULL);
        g_io_add_watch(iochan, G_IO_IN|G_IO_HUP,
                       (GIOFunc) control_client_socket, iochan);
        g_ptr_array_add(uzbl.comm.client_chan, (gpointer)iochan);
    }
    return TRUE;
}
Example #27
0
File: io.c Project: TaylanUB/uzbl
gboolean
attach_fifo(gchar *path) {
    GError *error = NULL;
    /* we don't really need to write to the file, but if we open the
     * file as 'r' we will block here, waiting for a writer to open
     * the file. */
    GIOChannel *chan = g_io_channel_new_file(path, "r+", &error);
    if (chan) {
        if (g_io_add_watch(chan, G_IO_IN|G_IO_HUP, (GIOFunc) control_fifo, NULL)) {
            if (uzbl.state.verbose)
                printf ("attach_fifo: created successfully as %s\n", path);
            send_event(FIFO_SET, NULL, TYPE_STR, path, NULL);
            uzbl.comm.fifo_path = path;
            g_setenv("UZBL_FIFO", uzbl.comm.fifo_path, TRUE);
            return TRUE;
        } else g_warning ("attach_fifo: could not add watch on %s\n", path);
    } else g_warning ("attach_fifo: can't open: %s\n", error->message);

    if (error) g_error_free (error);
    return FALSE;
}
Example #28
0
static void start_aprsis_thread(void *ptr) {
    GError *error = NULL;
	aprsis_ctx *ctx = ptr;
	
	g_message("connecting to %s", ctx->host);
	if (aprsis_connect(ctx)) {
		g_error("failed to connect");
	}

	g_message("logging in...");
	aprsis_login(ctx);

	aprsis_set_filter(ctx, DEF_HOME_LAT, DEF_HOME_LON, DEF_RAD);
	//aprsis_set_filter_string(ctx, "p/M/G/2"); // callsigns beginning with G, M or 2 - UK callsigns, normally
	//aprsis_set_filter_string(ctx, "p/HB9"); // Swiss callsigns

	aprsis_io = g_io_channel_unix_new (ctx->sockfd);
    g_io_channel_set_encoding(aprsis_io, NULL, &error);
    if (!g_io_add_watch (aprsis_io, G_IO_IN | G_IO_ERR | G_IO_HUP, aprsis_got_packet, ctx))
        g_error ("Cannot add watch on GIOChannel!");
}
Example #29
0
static gboolean
do_start (GPPWorker *self)
{
  GPPWorkerPrivate *priv = GET_PRIV (self);
  priv->frontend = zsocket_new (priv->ctx, ZMQ_DEALER);
  zsocket_connect (priv->frontend, "tcp://localhost:5556");
  priv->frontend_channel = g_io_channel_from_zmq_socket (priv->frontend);
  priv->liveness = HEARTBEAT_LIVENESS;
  priv->frontend_source = g_io_add_watch (priv->frontend_channel,
      G_IO_IN, (GIOFunc) check_socket_activity, self);

  g_timeout_add (HEARTBEAT_INTERVAL / 1000, (GSourceFunc) do_heartbeat, self);

  zframe_t *frame = zframe_new (PPP_READY, 1);
  zframe_send (&frame, priv->frontend, 0);

  /* We need to do that for some reason ... */
  check_socket_activity (priv->frontend_channel, G_IO_IN, self);

  return FALSE;
}
Example #30
0
void pipeTest() {
	GIOChannel *channel, *channel2;
	pid_t childPid;
	
	printf("Pipe test\n");

	mLoop1 = g_main_loop_new(NULL, FALSE);
	timer = g_timer_new();
	g_timer_start(timer);
	
//	g_timeout_add_seconds(5, timeout_1, "Pipe timeout");

	channel = g_io_channel_unix_new (STDIN_FILENO);
	if (!channel)
		g_error ("Cannot create new GIOChannel!\n");
	
	if (!g_io_add_watch (channel, G_IO_IN | G_IO_HUP, gio_in, NULL))
		g_error ("Cannot add watch on GIOChannel!\n");
	
	g_main_loop_run(mLoop1);
}