static void setup_io() { int result; channel = g_io_channel_unix_new(STDIN_FILENO); g_io_channel_set_close_on_unref(channel, TRUE); #if 0 g_io_channel_set_encoding(channel, NULL, NULL); g_io_channel_set_buffered(channel, FALSE); g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL ); #endif channel_read_callback = result = g_io_add_watch_full(channel, G_PRIORITY_HIGH, (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI), io_invoke, NULL, NULL); channel_error_callback = g_io_add_watch_full(channel, G_PRIORITY_HIGH, (G_IO_NVAL), io_invoke_error, GINT_TO_POINTER(result), NULL); g_io_channel_unref(channel); /* Apparently this caused crashes for some people. But irssi does this, so I am going to assume the crashes were caused by some other stuff. */ gnt_warning("setting up IO (%d)", channel_read_callback); }
void CoreManager::InputInit() { // init libtermkey TERMKEY_CHECK_VERSION; if (!(tk = termkey_new(STDIN_FILENO, TERMKEY_FLAG_NOTERMIOS))) { g_critical(_("Libtermkey initialization failed.")); exit(1); } utf8 = g_get_charset(NULL); io_input_channel = g_io_channel_unix_new(STDIN_FILENO); // set channel encoding to NULL so it can be unbuffered g_io_channel_set_encoding(io_input_channel, NULL, NULL); g_io_channel_set_buffered(io_input_channel, FALSE); g_io_channel_set_close_on_unref(io_input_channel, TRUE); io_input_channel_id = g_io_add_watch_full(io_input_channel, G_PRIORITY_HIGH, static_cast<GIOCondition>(G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI), io_input_, this, NULL); g_io_add_watch_full(io_input_channel, G_PRIORITY_HIGH, G_IO_NVAL, io_input_error_, this, NULL); g_io_channel_unref(io_input_channel); // screen resizing if (!pipe(pipefd)) { pipe_valid = true; resize_channel = g_io_channel_unix_new(pipefd[0]); g_io_channel_set_encoding(resize_channel, NULL, NULL); g_io_channel_set_buffered(resize_channel, FALSE); g_io_channel_set_close_on_unref(resize_channel, TRUE); resize_channel_id = g_io_add_watch_full(resize_channel, G_PRIORITY_HIGH, G_IO_IN, resize_input_, this, NULL); } }
static int telit_sap_enable(struct ofono_modem *modem, struct ofono_modem *sap_modem, int bt_fd) { struct telit_data *data = ofono_modem_get_data(modem); int fd; DBG("%p", modem); fd = telit_sap_open(); if (fd < 0) goto error; data->hw_io = g_io_channel_unix_new(fd); if (data->hw_io == NULL) { close(fd); goto error; } g_io_channel_set_encoding(data->hw_io, NULL, NULL); g_io_channel_set_buffered(data->hw_io, FALSE); g_io_channel_set_close_on_unref(data->hw_io, TRUE); data->bt_io = g_io_channel_unix_new(bt_fd); if (data->bt_io == NULL) goto error; g_io_channel_set_encoding(data->bt_io, NULL, NULL); g_io_channel_set_buffered(data->bt_io, FALSE); g_io_channel_set_close_on_unref(data->bt_io, TRUE); data->hw_watch = g_io_add_watch_full(data->hw_io, G_PRIORITY_DEFAULT, G_IO_HUP | G_IO_ERR | G_IO_NVAL | G_IO_IN, hw_event_cb, modem, hw_watch_remove); data->bt_watch = g_io_add_watch_full(data->bt_io, G_PRIORITY_DEFAULT, G_IO_HUP | G_IO_ERR | G_IO_NVAL | G_IO_IN, bt_event_cb, modem, bt_watch_remove); data->sap_modem = sap_modem; g_at_chat_register(data->chat, "#RSEN:", telit_rsen_notify, FALSE, modem, NULL); g_at_chat_send(data->chat, "AT#NOPT=0", NULL, NULL, NULL, NULL); /* Set SAP functionality */ g_at_chat_send(data->chat, "AT#RSEN=1,1,0,2,0", rsen_prefix, rsen_enable_cb, modem, NULL); return -EINPROGRESS; error: shutdown(bt_fd, SHUT_RDWR); close(bt_fd); sap_close_io(modem); return -EINVAL; }
static struct io_watch *watch_new(struct io *io, GIOCondition cond, io_callback_func_t callback, void *user_data, io_destroy_func_t destroy) { struct io_watch *watch; watch = g_try_new0(struct io_watch, 1); if (!watch) return NULL; watch->io = io_ref(io); watch->callback = callback; watch->destroy = destroy; watch->user_data = user_data; watch->id = g_io_add_watch_full(io->channel, G_PRIORITY_DEFAULT, cond | G_IO_ERR | G_IO_NVAL, watch_callback, watch, watch_destroy); if (watch->id == 0) { watch_destroy(watch); return NULL; } return watch; }
static guint input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, gpointer data) { PurpleIOClosure *closure = g_new0(PurpleIOClosure, 1); GIOChannel *channel; GIOCondition cond = (GIOCondition)0; closure->function = function; closure->data = data; int tmp = 0; if (condition & PURPLE_INPUT_READ) { tmp |= READ_COND; cond = (GIOCondition)tmp; } if (condition & PURPLE_INPUT_WRITE) { tmp |= WRITE_COND; cond = (GIOCondition)tmp; } #ifdef WIN32 channel = wpurple_g_io_channel_win32_new_socket(fd); #else channel = g_io_channel_unix_new(fd); #endif closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, io_invoke, closure, io_destroy); g_io_channel_unref(channel); return closure->result; }
uxsel_id *uxsel_input_add(int fd, int rwx) { uxsel_id *id = snew(uxsel_id); #if GTK_CHECK_VERSION(2, 0, 0) int flags = 0; if (rwx & 1) flags |= G_IO_IN; if (rwx & 2) flags |= G_IO_OUT; if (rwx & 4) flags |= G_IO_PRI; id->chan = g_io_channel_unix_new(fd); g_io_channel_set_encoding(id->chan, NULL, NULL); id->watch_id = g_io_add_watch_full( id->chan, GDK_PRIORITY_REDRAW + 1, flags, fd_input_func, NULL, NULL); #else int flags = 0; if (rwx & 1) flags |= GDK_INPUT_READ; if (rwx & 2) flags |= GDK_INPUT_WRITE; if (rwx & 4) flags |= GDK_INPUT_EXCEPTION; assert(flags); id->id = gdk_input_add(fd, flags, fd_input_func, NULL); #endif return id; }
int rfs_manager_start(struct rfs_manager *mgr) { int fd; if (!mgr) return -1; g_message("Starting up RFS manager ..."); ipc_client_create_handlers_common_data(mgr->client); ipc_client_open(mgr->client); ipc_client_set_log_handler(mgr->client, log_handler, NULL); fd = ipc_client_get_handlers_common_data_fd(mgr->client); if (fd < 0) return -1; mgr->io = g_io_channel_unix_new(fd); g_io_channel_set_encoding(mgr->io, NULL, NULL); g_io_channel_set_buffered(mgr->io, FALSE); mgr->read_watch = g_io_add_watch_full(mgr->io, G_PRIORITY_DEFAULT, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, received_data, mgr, read_watch_destroy); g_io_channel_unref(mgr->io); return 0; }
struct mgmt *mgmt_new(int fd) { struct mgmt *mgmt; if (fd < 0) return NULL; mgmt = g_try_new0(struct mgmt, 1); if (!mgmt) return NULL; mgmt->fd = fd; mgmt->close_on_unref = false; mgmt->len = 512; mgmt->buf = g_try_malloc(mgmt->len); if (!mgmt->buf) { g_free(mgmt); return NULL; } mgmt->io = g_io_channel_unix_new(mgmt->fd); g_io_channel_set_encoding(mgmt->io, NULL, NULL); g_io_channel_set_buffered(mgmt->io, FALSE); mgmt->request_queue = g_queue_new(); mgmt->reply_queue = g_queue_new(); mgmt->read_watch = g_io_add_watch_full(mgmt->io, G_PRIORITY_DEFAULT, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, received_data, mgmt, read_watch_destroy); return mgmt_ref(mgmt); }
gboolean server_handle_c(GIOChannel *source, GIOCondition cond, gpointer user) { int sock; int client; struct layout *l = (void *)user; struct sockaddr sa; unsigned int sa_len; GIOChannel *channel; sock = g_io_channel_unix_get_fd(source); sa_len = sizeof(sa); client = accept(sock, &sa, &sa_len); if (client < 0) { perror("accept"); return TRUE; } channel = g_io_channel_unix_new(client); g_io_channel_set_encoding(channel, NULL, NULL); g_io_add_watch_full(channel, 0, G_IO_IN, server_handle, l, NULL); l->state.last_ui_fd = client; printf("Added client\n"); return TRUE; }
static void tcl_create_file_handler(int fd, int mask, Tcl_FileProc *proc, ClientData data) { struct tcl_file_handler *tfh = g_new0(struct tcl_file_handler, 1); GIOChannel *channel; GIOCondition cond = 0; if (g_hash_table_lookup(tcl_file_handlers, GINT_TO_POINTER(fd))) tcl_delete_file_handler(fd); if (mask & TCL_READABLE) cond |= G_IO_IN; if (mask & TCL_WRITABLE) cond |= G_IO_OUT; if (mask & TCL_EXCEPTION) cond |= G_IO_ERR|G_IO_HUP|G_IO_NVAL; tfh->fd = fd; tfh->mask = mask; tfh->proc = proc; tfh->data = data; channel = g_io_channel_unix_new(fd); tfh->source = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, tcl_file_callback, tfh, g_free); g_io_channel_unref(channel); g_hash_table_insert(tcl_file_handlers, GINT_TO_POINTER(fd), tfh); Tcl_ServiceAll(); }
static guint eventloop_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, gpointer data) { AndroidIOClosure *closure = g_new0(AndroidIOClosure, 1); GIOChannel *channel; GIOCondition cond = 0; closure->function = function; closure->data = data; if (condition & PURPLE_INPUT_READ) cond |= ANDROID_READ_COND; if (condition & PURPLE_INPUT_WRITE) cond |= ANDROID_WRITE_COND; channel = g_io_channel_unix_new(fd); closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, android_io_invoke, closure, g_free); g_io_channel_unref(channel); purple_debug_info("eventloop", "called input add for %d, result: %d", fd, closure->result); return closure->result; }
mainloop_io_t * mainloop_add_fd( const char *name, int priority, int fd, void *userdata, struct mainloop_fd_callbacks *callbacks) { mainloop_io_t *client = NULL; if(fd > 0) { client = calloc(1, sizeof(mainloop_io_t)); client->name = strdup(name); client->userdata = userdata; if(callbacks) { client->destroy_fn = callbacks->destroy; client->dispatch_fn_io = callbacks->dispatch; } client->channel = g_io_channel_unix_new(fd); client->source = g_io_add_watch_full( client->channel, priority, (G_IO_IN|G_IO_HUP|G_IO_NVAL|G_IO_ERR), mainloop_gio_callback, client, mainloop_gio_destroy); /* Now that mainloop now holds a reference to adaptor->channel, * thanks to g_io_add_watch_full(), drop ours from g_io_channel_unix_new(). * * This means that adaptor->channel will be free'd by: * g_main_context_dispatch() or g_source_remove() * -> g_source_destroy_internal() * -> g_source_callback_unref() * shortly after mainloop_gio_destroy() completes */ g_io_channel_unref(client->channel); crm_trace("Added connection %d for %s[%p].%d %d", client->source, client->name, client, fd, mainloop_gio_refcount(client)); } return client; }
static guint glib_input_add( gint fd, PurpleInputCondition condition, PurpleInputFunction function, gpointer data) { PurpleGLibIOClosure *closure = g_new0(PurpleGLibIOClosure, 1); GIOChannel *channel; GIOCondition cond = 0; closure->function = function; closure->data = data; if (condition & PURPLE_INPUT_READ) { cond |= PURPLE_GLIB_READ_COND; } if (condition & PURPLE_INPUT_WRITE) { cond |= PURPLE_GLIB_WRITE_COND; } channel = g_io_channel_unix_new(fd); closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, purple_glib_io_invoke, closure, purple_glib_io_destroy); g_io_channel_unref(channel); return closure->result; }
static gboolean btic_midi_device_start (gconstpointer _self) { BtIcMidiDevice *self = BTIC_MIDI_DEVICE (_self); GError *error = NULL; GST_INFO ("starting the midi device"); // start the io-loop self->priv->io_channel = g_io_channel_new_file (self->priv->devnode, "r", &error); if (error) { GST_WARNING ("iochannel error for open(%s): %s", self->priv->devnode, error->message); g_error_free (error); return FALSE; } g_io_channel_set_encoding (self->priv->io_channel, NULL, &error); if (error) { GST_WARNING ("iochannel error for setting encoding to NULL: %s", error->message); g_error_free (error); g_io_channel_unref (self->priv->io_channel); self->priv->io_channel = NULL; return FALSE; } self->priv->io_source = g_io_add_watch_full (self->priv->io_channel, G_PRIORITY_LOW, G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL, io_handler, (gpointer) self, NULL); return TRUE; }
gboolean g_ril_io_set_write_handler(GRilIO *io, GRilIOWriteFunc write_handler, gpointer user_data) { if (io == NULL) return FALSE; if (io->write_watch > 0) { if (write_handler == NULL) { g_source_remove(io->write_watch); return TRUE; } return FALSE; } if (write_handler == NULL) return FALSE; io->write_handler = write_handler; io->write_data = user_data; if (io->use_write_watch == TRUE) io->write_watch = g_io_add_watch_full(io->channel, G_PRIORITY_HIGH, G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL, can_write_data, io, write_watcher_destroy_notify); else io->write_watch = g_idle_add(call_blocking_read, io); return TRUE; }
guint gnt_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, gpointer data) { PurpleGntIOClosure *closure = g_new0(PurpleGntIOClosure, 1); GIOChannel *channel; GIOCondition cond = 0; #ifdef _WIN32 static int use_glib_io_channel = -1; if (use_glib_io_channel == -1) use_glib_io_channel = (g_getenv("PIDGIN_GLIB_IO_CHANNEL") != NULL) ? 1 : 0; #endif closure->function = function; closure->data = data; if (condition & PURPLE_INPUT_READ) cond |= FINCH_READ_COND; if (condition & PURPLE_INPUT_WRITE) cond |= FINCH_WRITE_COND; #ifdef _WIN32 if (use_glib_io_channel == 0) channel = (GIOChannel *) wpurple_g_io_channel_win32_new_socket(fd); else #endif channel = g_io_channel_unix_new(fd); closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, purple_gnt_io_invoke, closure, purple_gnt_io_destroy); g_io_channel_unref(channel); return closure->result; }
gint gdk_input_add_full(gint source, GdkInputCondition condition, GdkInputFunction function, gpointer data, GdkDestroyNotify destroy) { guint result; GdkIOClosure *closure = g_new(GdkIOClosure, 1); GIOChannel *channel; GIOCondition cond = 0; closure->function = function; closure->condition = condition; closure->notify = destroy; closure->data = data; if (condition & GDK_INPUT_READ) cond |= READ_CONDITION; if (condition & GDK_INPUT_WRITE) cond |= WRITE_CONDITION; if (condition & GDK_INPUT_EXCEPTION) cond |= EXCEPTION_CONDITION; channel = g_io_channel_unix_new(source); result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, gdk_io_invoke, closure, gdk_io_destroy); g_io_channel_unref(channel); return result; }
int ui_pipe_new ( int pipe_fd[2], pipe_input_cb_t input_cb, gpointer user_data) { static pipe_input_t pipe_input; g_assert (pipe_fd != NULL); /* * Create a pipe between GUI and a thread or a process */ if (socketpair (AF_UNIX, SOCK_DGRAM, 0, pipe_fd) < 0) { g_warning ("Failed to create socketpair %s", g_strerror (errno)); return RC_FAIL; } /* * Source taken from wireshark SVN repository */ pipe_input.source_fd = pipe_fd[0]; pipe_input.input_cb = input_cb; pipe_input.user_data = user_data; pipe_input.pipe_channel = g_io_channel_unix_new (pipe_fd[0]); g_io_channel_set_encoding (pipe_input.pipe_channel, NULL, NULL); pipe_input.pipe_input_id = g_io_add_watch_full (pipe_input.pipe_channel, G_PRIORITY_HIGH, G_IO_IN | G_IO_ERR | G_IO_HUP, ui_callback_on_pipe_notification, &pipe_input, NULL); return RC_OK; }
/* Caller need to load leases before call it */ int g_dhcp_server_start(GDHCPServer *dhcp_server) { GIOChannel *listener_channel; int listener_sockfd; if (dhcp_server->started) return 0; listener_sockfd = dhcp_l3_socket(SERVER_PORT, dhcp_server->interface, AF_INET); if (listener_sockfd < 0) return -EIO; listener_channel = g_io_channel_unix_new(listener_sockfd); if (!listener_channel) { close(listener_sockfd); return -EIO; } dhcp_server->listener_sockfd = listener_sockfd; dhcp_server->listener_channel = listener_channel; g_io_channel_set_close_on_unref(listener_channel, TRUE); dhcp_server->listener_watch = g_io_add_watch_full(listener_channel, G_PRIORITY_HIGH, G_IO_IN | G_IO_NVAL | G_IO_ERR | G_IO_HUP, listener_event, dhcp_server, NULL); g_io_channel_unref(dhcp_server->listener_channel); dhcp_server->started = TRUE; return 0; }
static void wake_up_sender(struct _GAttrib *attrib) { if (attrib->write_watch == 0) attrib->write_watch = g_io_add_watch_full(attrib->io, G_PRIORITY_DEFAULT, G_IO_OUT, can_write_data, attrib, destroy_sender); }
static gboolean master_socket_io_handler (GIOChannel * channel, GIOCondition condition, gpointer user_data) { BtPlaybackControllerSocket *self = BT_PLAYBACK_CONTROLLER_SOCKET (user_data); struct sockaddr addr = { 0, }; socklen_t addrlen = sizeof (struct sockaddr); GST_INFO ("master io handler : %d", condition); if (condition & (G_IO_IN | G_IO_PRI)) { if ((self->priv->client_socket = accept (self->priv->master_socket, &addr, &addrlen)) < 0) { GST_WARNING ("accept error: %s", g_strerror (errno)); } else { self->priv->client_channel = g_io_channel_unix_new (self->priv->client_socket); //self->priv->client_source=g_io_add_watch(self->priv->client_channel,G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,client_socket_io_handler,(gpointer)self); self->priv->client_source = g_io_add_watch_full (self->priv->client_channel, G_PRIORITY_LOW, G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL, client_socket_io_handler, (gpointer) self, NULL); GST_INFO ("playback controller client connected"); } } if (condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) { client_connection_close (self); GST_INFO ("playback controller client disconnected"); } return TRUE; }
static guint input_add ( int fd , PurpleInputCondition cond , PurpleInputFunction func , gpointer user_data ) { purple_glib_ioclosure *closure = g_new0( purple_glib_ioclosure, 1 ); GIOCondition gio_cond = 0; GIOChannel *channel; if( cond & PURPLE_INPUT_READ ) gio_cond |= PURPLE_GLIB_READ_COND ; if( cond & PURPLE_INPUT_WRITE ) gio_cond |= PURPLE_GLIB_WRITE_COND; closure->function = func; closure->data = user_data; channel = g_io_channel_unix_new( fd ); closure->result = g_io_add_watch_full( channel , G_PRIORITY_DEFAULT , gio_cond , __elim_io_invoke , closure , __elim_io_destroy ); g_io_channel_unref( channel ); return closure->result; }
guint g_io_add_watch (GIOChannel *channel, GIOCondition condition, GIOFunc func, gpointer user_data) { return g_io_add_watch_full (channel, 0, condition, func, user_data, NULL); }
static int32_t gio_poll_dispatch_add(enum qb_loop_priority p, int32_t fd, int32_t evts, void *data, qb_ipcs_dispatch_fn_t fn) { struct gio_to_qb_poll *adaptor; GIOChannel *channel; int32_t res = 0; res = qb_array_index(gio_map, fd, (void **)&adaptor); if (res < 0) { crm_err("Array lookup failed for fd=%d: %d", fd, res); return res; } crm_trace("Adding fd=%d to mainloop as adapater %p", fd, adaptor); if (adaptor->is_used) { crm_err("Adapter for descriptor %d is still in-use", fd); return -EEXIST; } /* channel is created with ref_count = 1 */ channel = g_io_channel_unix_new(fd); if (!channel) { crm_err("No memory left to add fd=%d", fd); return -ENOMEM; } /* Because unlike the poll() API, glib doesn't tell us about HUPs by default */ evts |= (G_IO_HUP | G_IO_NVAL | G_IO_ERR); adaptor->fn = fn; adaptor->events = evts; adaptor->data = data; adaptor->p = p; adaptor->is_used = QB_TRUE; adaptor->source = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, evts, gio_read_socket, adaptor, gio_poll_destroy); /* Now that mainloop now holds a reference to channel, * thanks to g_io_add_watch_full(), drop ours from g_io_channel_unix_new(). * * This means that channel will be free'd by: * g_main_context_dispatch() * -> g_source_destroy_internal() * -> g_source_callback_unref() * shortly after gio_poll_destroy() completes */ g_io_channel_unref(channel); crm_trace("Added to mainloop with gsource id=%d", adaptor->source); if (adaptor->source > 0) { return 0; } return -EINVAL; }
nsresult nsAppShell::Init() { #ifdef PR_LOGGING if (!gWidgetLog) gWidgetLog = PR_NewLogModule("Widget"); if (!gWidgetFocusLog) gWidgetFocusLog = PR_NewLogModule("WidgetFocus"); if (!gWidgetDragLog) gWidgetDragLog = PR_NewLogModule("WidgetDrag"); if (!gWidgetDrawLog) gWidgetDrawLog = PR_NewLogModule("WidgetDraw"); #endif if (!sPollFunc) { sPollFunc = g_main_context_get_poll_func(NULL); g_main_context_set_poll_func(NULL, &PollWrapper); } GIOChannel *ioc; if (PR_GetEnv("MOZ_DEBUG_PAINTS")) gdk_window_set_debug_updates(TRUE); int err = pipe(mPipeFDs); if (err) return NS_ERROR_OUT_OF_MEMORY; // make the pipe nonblocking int flags = fcntl(mPipeFDs[0], F_GETFL, 0); if (flags == -1) goto failed; err = fcntl(mPipeFDs[0], F_SETFL, flags | O_NONBLOCK); if (err == -1) goto failed; flags = fcntl(mPipeFDs[1], F_GETFL, 0); if (flags == -1) goto failed; err = fcntl(mPipeFDs[1], F_SETFL, flags | O_NONBLOCK); if (err == -1) goto failed; ioc = g_io_channel_unix_new(mPipeFDs[0]); mTag = g_io_add_watch_full(ioc, G_PRIORITY_DEFAULT, G_IO_IN, EventProcessorCallback, this, nsnull); g_io_channel_unref(ioc); return nsBaseAppShell::Init(); failed: close(mPipeFDs[0]); close(mPipeFDs[1]); mPipeFDs[0] = mPipeFDs[1] = 0; return NS_ERROR_FAILURE; }
WebosSurfaceManagerRemoteClient::WebosSurfaceManagerRemoteClient(WebosSurfaceManager *parent, int socketFd) : m_parent(parent), m_socketFd(socketFd), m_channel(0), m_socketWatch(0), m_winId(-1) { m_channel = g_io_channel_unix_new(m_socketFd); m_socketWatch = g_io_add_watch_full(m_channel, G_PRIORITY_DEFAULT, G_IO_IN, onIncomingDataCb, this, NULL); }
void asound_setup(const gchar * card, const gchar * channel, void (*volume_changed)(int,gboolean)) { // Make sure (for now) that the setup function only gets called once static int asound_setup_called = 0; assert(asound_setup_called == 0); asound_setup_called++; // Save card, volume_changed strcpy(m_card, card); m_volume_changed = volume_changed; // Load the mixer for the provided cardname snd_mixer_open(&m_mixer, 0); snd_mixer_attach(m_mixer, m_card); snd_mixer_selem_register(m_mixer, NULL, NULL); snd_mixer_load(m_mixer); // Setup g_io_watch for the mixer int count = snd_mixer_poll_descriptors_count(m_mixer); if(count >= 1) { struct pollfd pfd; count = snd_mixer_poll_descriptors(m_mixer, &pfd, 1); if(count == 1) { GIOChannel * giochannel = g_io_channel_unix_new(pfd.fd); g_io_add_watch_full(giochannel, G_PRIORITY_DEFAULT, G_IO_IN, asound_poll_cb, NULL, NULL); } } // Iterate over the elements in the mixer and store them in m_channel_names int elemcount = snd_mixer_get_count(m_mixer); snd_mixer_elem_t * elem = snd_mixer_first_elem(m_mixer); int loop; for(loop = 0; loop < elemcount; loop++) { const char * elemname = snd_mixer_selem_get_name(elem); if(snd_mixer_selem_has_playback_volume(elem)) { m_channel_names = g_list_append(m_channel_names, (gpointer)g_strdup(elemname)); } elem = snd_mixer_elem_next(elem); } // Setup m_elem using the provided channelname if(channel != NULL && asound_channel_exists(channel)) asound_set_channel(channel); else if(m_channel_names != NULL) asound_set_channel((const gchar*)m_channel_names->data); }
static void master_connection_open (BtPlaybackControllerSocket * self) { BtSettings *settings; gboolean active; guint port; static struct sockaddr_in serv_addr; g_object_get (self->priv->app, "settings", &settings, NULL); g_object_get (settings, "coherence-upnp-active", &active, "coherence-upnp-port", &port, NULL); g_object_unref (settings); if (!active) return; /* new socket: internet address family, stream socket */ if ((self->priv->master_socket = socket (AF_INET, SOCK_STREAM, 0)) < 0) { goto socket_error; } memset (&serv_addr, 0, sizeof (serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = htonl (INADDR_ANY); // my address serv_addr.sin_port = htons (port); if (bind (self->priv->master_socket, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) { goto bind_error; } if (listen (self->priv->master_socket, 64) < 0) { goto listen_error; } self->priv->master_channel = g_io_channel_unix_new (self->priv->master_socket); //self->priv->master_source=g_io_add_watch(self->priv->master_channel,G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,master_socket_io_handler,(gpointer)self); self->priv->master_source = g_io_add_watch_full (self->priv->master_channel, G_PRIORITY_LOW, G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL, master_socket_io_handler, (gpointer) self, NULL); GST_INFO ("playback controller running"); return; socket_error: GST_WARNING ("socket allocation failed: %s", g_strerror (errno)); return; bind_error: GST_WARNING ("binding the socket failed: %s", g_strerror (errno)); return; listen_error: GST_WARNING ("listen failed: %s", g_strerror (errno)); return; }
static void wakeup_writer(GAtMux *mux) { if (mux->write_watch != 0) return; debug(mux, "waking up writer"); mux->write_watch = g_io_add_watch_full(mux->channel, G_PRIORITY_DEFAULT, G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL, can_write_data, mux, write_watcher_destroy_notify); }
void add_input(void) { if(input_running == FALSE) { input_running = TRUE; callback_handler = g_io_add_watch_full(g_io_channel_unix_new(serial_port_fd), 10, G_IO_OUT, (GIOFunc)ecriture, NULL, NULL); } }