static void alsa_release (void *dp) { alsa_driver * const d = dp; free(d->sndbuf); d->sndbuf = NULL; /* audio_poll_remove(d->polltag); */ gdk_input_remove(d->polltag); d->polltag = 0; if(d->soundfd != 0) { /* snd_pcm_drain_capture(d->soundfd); */ snd_pcm_close(d->soundfd); d->soundfd = 0; } }
static void shutdown(void *arg) { /* Close remote command handling */ if ( command_id >= 0 ) gdk_input_remove(command_id); command_id = -1; if ( timeout_tag >= 0 ) g_source_remove(timeout_tag); timeout_tag = -1; if ( viewer != NULL ) viewer_done(viewer); viewer = NULL; exit(EXIT_SUCCESS); /*gtk_main_quit();*/ }
static void updatewrite(struct conduit *conduit) { struct data *data; data = conduit->cdata; if(data->fd < 0) return; if(dc_wantwrite()) { if(data->gdkwrite == -1) data->gdkwrite = gdk_input_add(data->fd, GDK_INPUT_WRITE, (void (*)(gpointer, int, GdkInputCondition))dcfdcb, conduit); } else { if(data->gdkwrite != -1) { gdk_input_remove(data->gdkwrite); data->gdkwrite = -1; } } }
PRIVATE void clock_handler(AClock *clock, AClockReason reason) { Data *data = clock->gen->data; switch (reason) { case CLOCK_DISABLE: gdk_input_remove(data->input_tag); data->input_tag = -1; break; case CLOCK_ENABLE: if (data->input_tag == -1) data->input_tag = gdk_input_add(data->audiofd, GDK_INPUT_WRITE, (GdkInputFunction) gen_clock_mainloop, NULL); break; default: g_message("Unreachable code reached (esd_output)... reason = %d", reason); break; } }
void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event) { gint *m_id = (gint *)(socket->m_gui_dependent); int c; assert( m_id != NULL ); switch (event) { case GSOCK_LOST: /* fall-through */ case GSOCK_INPUT: c = 0; break; case GSOCK_OUTPUT: c = 1; break; case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break; default: return; } if (m_id[c] != -1) gdk_input_remove(m_id[c]); m_id[c] = -1; }
/** c2_imap_reconnect * * @imap: A locked imap object * * This function attempts to reconnect and restore * proper state of an imap object. * * Return Value: * 0 on success, -1 otherwise **/ static gint c2_imap_reconnect(C2IMAP *imap) { C2NetObjectByte *byte; c2_net_object_disconnect(C2_NET_OBJECT(imap)); c2_net_object_destroy_byte(C2_NET_OBJECT(imap)); gdk_input_remove(imap->input_tag); imap->input_tag = -1; if(!(byte = c2_net_object_run(C2_NET_OBJECT(imap)))) { imap->state = C2IMAPDisconnected; gtk_signal_emit(GTK_OBJECT(imap), signals[NET_ERROR]); c2_imap_set_error(imap, _("Error connecting to IMAP server.")); return -1; } imap->input_tag = gdk_input_add(byte->sock, GDK_INPUT_READ, (GdkInputFunction)c2_imap_on_net_traffic, imap); imap->input_tag = gdk_input_add(byte->sock, GDK_INPUT_READ, (GdkInputFunction)c2_imap_on_net_traffic, imap); imap->login(imap); if(imap->state == C2IMAPSelected) if(c2_imap_select_mailbox(imap, imap->selected_mailbox) < 0) { c2_net_object_disconnect(C2_NET_OBJECT(imap)); gtk_signal_emit(GTK_OBJECT(imap), signals[LOGOUT]); return -1; } return 0; }
virtual void RemoveInput(wxFDIOHandler* WXUNUSED(handler), int fd, Direction WXUNUSED(d)) { gdk_input_remove(fd); }
int main(int argc, char *argv[]) { char *host, *port, *path, *tmp_url; lo_server osc_server; gint osc_server_socket_tag; Y_DEBUG_INIT("WhySynth_gtk"); #ifdef Y_DEBUG GDB_MESSAGE(GDB_MAIN, " starting (pid %d)...\n", getpid()); #else fprintf(stderr, "WhySynth_gtk starting (pid %d)...\n", getpid()); #endif /* { int i; fprintf(stderr, "args:\n"); for(i=0; i<argc; i++) printf("%d: %s\n", i, argv[i]); } // debug */ gtk_init(&argc, &argv); if (argc > 1 && !strcmp(argv[1], "-test")) { gui_test_mode = 1; test_argv[0] = argv[0]; test_argv[1] = "osc.udp://localhost:9/test/mode"; if (argc >= 5) test_argv[4] = argv[4]; argc = 5; argv = test_argv; } else if (argc != 5) { fprintf(stderr, "usage: %s <osc url> <plugin dllname> <plugin label> <user-friendly id>\n" " or: %s -test\n", argv[0], argv[0]); exit(1); } /* set up OSC support */ osc_host_url = argv[1]; host = lo_url_get_hostname(osc_host_url); port = lo_url_get_port(osc_host_url); path = lo_url_get_path(osc_host_url); osc_host_address = lo_address_new(host, port); osc_configure_path = osc_build_path(path, "/configure"); osc_control_path = osc_build_path(path, "/control"); osc_exiting_path = osc_build_path(path, "/exiting"); osc_hide_path = osc_build_path(path, "/hide"); osc_midi_path = osc_build_path(path, "/midi"); osc_program_path = osc_build_path(path, "/program"); osc_quit_path = osc_build_path(path, "/quit"); osc_rate_path = osc_build_path(path, "/sample-rate"); osc_show_path = osc_build_path(path, "/show"); osc_update_path = osc_build_path(path, "/update"); osc_server = lo_server_new(NULL, osc_error); lo_server_add_method(osc_server, osc_configure_path, "ss", osc_configure_handler, NULL); lo_server_add_method(osc_server, osc_control_path, "if", osc_control_handler, NULL); lo_server_add_method(osc_server, osc_hide_path, "", osc_action_handler, "hide"); lo_server_add_method(osc_server, osc_program_path, "ii", osc_program_handler, NULL); lo_server_add_method(osc_server, osc_quit_path, "", osc_action_handler, "quit"); lo_server_add_method(osc_server, osc_rate_path, "i", osc_action_handler, "sample-rate"); lo_server_add_method(osc_server, osc_show_path, "", osc_action_handler, "show"); lo_server_add_method(osc_server, NULL, NULL, osc_debug_handler, NULL); tmp_url = lo_server_get_url(osc_server); osc_self_url = osc_build_path(tmp_url, (strlen(path) > 1 ? path + 1 : path)); free(tmp_url); GDB_MESSAGE(GDB_OSC, ": listening at %s\n", osc_self_url); /* set up GTK+ */ update_port_wavetable_counts(); create_windows(argv[4]); /* add OSC server socket to GTK+'s watched I/O */ if (lo_server_get_socket_fd(osc_server) < 0) { fprintf(stderr, "WhySynth_gtk fatal: OSC transport does not support exposing socket fd\n"); exit(1); } osc_server_socket_tag = gdk_input_add(lo_server_get_socket_fd(osc_server), GDK_INPUT_READ, osc_data_on_socket_callback, osc_server); /* default patches, temporary patchfile support */ gui_data_friendly_patches(); rebuild_patches_list(); patches_dirty = 0; last_configure_load_was_from_tmp = 0; create_patches_tmp_filename(path); /* schedule our update request */ update_request_timeout_tag = g_timeout_add(50, update_request_timeout_callback, NULL); /* let GTK+ take it from here */ gtk_main(); /* clean up and exit */ GDB_MESSAGE(GDB_MAIN, ": yep, we got to the cleanup!\n"); /* release test note, if playing */ release_test_note(); /* GTK+ cleanup */ if (update_request_timeout_tag != 0) gtk_timeout_remove(update_request_timeout_tag); gdk_input_remove(osc_server_socket_tag); /* say bye-bye */ if (!host_requested_quit) { lo_send(osc_host_address, osc_exiting_path, ""); } /* clean up patches */ if (patches) free(patches); if (project_directory) free(project_directory); /* clean up OSC support */ lo_server_free(osc_server); free(host); free(port); free(path); free(osc_configure_path); free(osc_control_path); free(osc_exiting_path); free(osc_hide_path); free(osc_midi_path); free(osc_program_path); free(osc_quit_path); free(osc_rate_path); free(osc_show_path); free(osc_update_path); free(osc_self_url); return 0; }
//attention feinte: on read, on lcose et re read bien sur // on enleve l'ancien message et on remet le nouvo void input_callback(gpointer data,gint source,GdkInputCondition condition ){ //GtkWidget *pDialog; //gchar *sDialogText; message_t *m; caract_t *r; gint nbytes; int tmp; int nb_packet = 10; printf("On a appele le callback de fifo\n"); char buf[BUFSIZE]; printf("On lit sur %s\n",FIFO_CORE_TO_IHM); nbytes=read(source,buf,BUFSIZE); printf("On a lu sur le pipe\n"); close(source); printf("On ferme le fichier\n"); //on vire l'ancien callback gdk_input_remove(pipe_tag); printf("On a retire le callback\n"); // on remet le meme... ihm_p->core_to_ihm_fd = open(FIFO_CORE_TO_IHM, O_RDONLY| O_NDELAY); printf("On a reouvert le pipe\n"); // fd = open("./fifo_test", O_RDONLY|O_NONBLOCK); pipe_tag = gdk_input_add( ihm_p->core_to_ihm_fd,GDK_INPUT_READ,input_callback,NULL); printf("On a remi le callback\n"); printf("On a recu:%d\n", nbytes); //Partie recopiee: //on a le buffer, on peut faire le traitement // nbytes = read(ihm_p->core_to_ihm_fd, buf, BUFSIZE); if(nbytes < 0){ printf("Problemes dans la lecture de %s car %i\n",FIFO_CORE_TO_IHM,nbytes); }else{ tmp = (nbytes<BUFSIZE?nbytes:BUFSIZE); //on met un 0 ds le dernier caract // buf[tmp] = '\0'; printf("On a receptionne un message de taille %d\n",tmp); m=(message_t*)buf; printf("Get Type:%d Len:%d\n",m->type,m->len); if(m->type == TYPE_CARACT){ printf("On a receptionne un caract\n"); r = (struct caract*)(&(m->payload)); caract_t r2 = *r; print_caract(r2); ihm_p->wai_caract = caract_list_add(ihm_p->wai_caract,r2); } if(m->type == TYPE_LISTE_RULE){ //on recoi la liste des rules printf("On recoi la liste des rules\n"); struct rule * rule_tab = (struct rule *)(&(m->payload)); int nbRule = (m->len - 2*sizeof(u16))/sizeof(struct rule); if((m->len - 2*sizeof(u16)) > 0){ struct rule * rule_tab_ihm = (struct rule *)malloc((m->len - 2*sizeof(u16))*sizeof(struct rule)); printf("Taille: %d\n",(m->len - 2*sizeof(u16))); printf("Nombre Rule: %d\n",nbRule); memcpy(rule_tab_ihm,rule_tab,(m->len - 2*sizeof(u16))); printf("Apres memcpy\n"); if(ihm_p->rule_tab != NULL) free(ihm_p->rule_tab); printf("apres free\n"); ihm_p->rule_tab = rule_tab_ihm; ihm_p->rule_tab_size = nbRule; printf("On a %d rules\n",nbRule); //maintenant on parcoure les rule :) int i=0; for(i=0;i<nbRule;i++) print_rule( *(rule_tab_ihm+i) ); recreate_show_rule_page(); } } /* printf("On renvoi TO_ACCEPT au packet:\n"); message_t m_choix; u8* packet_choix; //pareil on envoi un choix choix_t c = creer_choix(r2.id,TO_ACCEPT); m_choix=creer_message_choix(c); packet_choix=creer_packet(m_choix); printf("Envois de Choix taille: %d\n",sizeof(struct choix)+2*sizeof(u16)); print_choix(c); write(ihm_to_core_fd, packet_choix,sizeof(struct choix)+2*sizeof(u16)); */ //printf("Policy a jour:\n"); //close(ihm_p->core_to_ihm_fd); plus besoin, fait au dessus } //test recreate_front_page(); }
static void pipefdcb(struct conduit *conduit, int fd, GdkInputCondition condition) { struct data *data; int ret; char *p, *p2, *cmd; char **args; size_t argssize, argsdata; struct transfer *transfer; data = (struct data *)conduit->cdata; if(conduit->state == CNDS_SYN) condconnected(conduit); sizebuf2(data->inbuf, data->inbufdata + 80, 1); ret = read(data->fd, data->inbuf + data->inbufdata, data->inbufsize - data->inbufdata); if(ret < 0) { if((errno == EINTR) || (errno == EAGAIN)) /* Shouldn't happen, but, oh well... */ return; perror("conduit-pipe: read"); gdk_input_remove(data->gdktag); close(data->fd); kill(-data->subproc, SIGHUP); data->gdktag = -1; data->fd = -1; data->subproc = 0; conddisconn(conduit); } if(ret == 0) { gdk_input_remove(data->gdktag); close(data->fd); kill(-data->subproc, SIGHUP); data->gdktag = -1; data->fd = -1; data->subproc = 0; conddisconn(conduit); } data->inbufdata += ret; while((p = memchr(data->inbuf, '\n', data->inbufdata)) != NULL) { *p = 0; cmd = sstrdup(data->inbuf); memmove(data->inbuf, p + 1, data->inbufdata -= (p - data->inbuf) + 1); args = NULL; argssize = argsdata = 0; p = cmd; do { if((p2 = strchr(p, '\t')) != NULL) *(p2++) = 0; addtobuf(args, p); p = p2; } while(p2 != NULL); if(!strcmp(args[0], "N") && (argsdata >= 4)) { transfer = newtransfer(conduit, args[1], atoi(args[2]), atoi(args[3])); } if(!strcmp(args[0], "D") && (argsdata >= 2)) { if((transfer = findtransferbytag(conduit, args[1])) != NULL) freetransfer(transfer); } if(!strcmp(args[0], "S") && (argsdata >= 3)) { if((transfer = findtransferbytag(conduit, args[1])) != NULL) transfersetsize(transfer, atoi(args[2])); } if(!strcmp(args[0], "P") && (argsdata >= 3)) { if((transfer = findtransferbytag(conduit, args[1])) != NULL) transfersetpos(transfer, atoi(args[2])); } free(args); free(cmd); } }
void midi_init() { int rc; snd_seq_port_info_t port; snd_seq_port_subscribe_t sub; int client; if (midi_handle != NULL ) { if (IS_MIDI_DEBUG_ON) { g_print( "Reinitializing MIDI input\n"); } if (midi_file_tag >= 0) { gdk_input_remove( midi_file_tag); midi_file_tag = -1; } close_handle( midi_handle); midi_handle = NULL; } /* Open the sequencer device, in non-block mode. Don't use O_NONBLOCK here, it crashes the application as for ALSA 0.5.5. (LT 15-mar-2000) */ rc = snd_seq_open( &midi_handle, SND_SEQ_OPEN_IN); if (rc < 0) { g_warning( "error opening ALSA MIDI input stream (%s)\n", snd_strerror(rc)); return; } /* Set nonblock mode i.e. enable==0. */ rc = snd_seq_block_mode( midi_handle, 0); if (rc < 0) { close_handle( midi_handle); midi_handle = NULL; g_warning( "error disabling sequencer block mode (%s)\n", snd_strerror(rc)); return; } /* Get client id. Needed to subscribe to the kernel-level client. */ client = snd_seq_client_id( midi_handle); if (client < 0) { close_handle( midi_handle); midi_handle = NULL; g_warning( "error naming sequencer client (%s)\n", snd_strerror(client)); return; } /* Set client name. Visible with 'cat /proc/asound/seq/clients'. */ rc = set_seq_name( midi_handle); if (rc < 0) { close_handle( midi_handle); midi_handle = NULL; g_warning( "error naming sequencer client (%s)\n",snd_strerror(rc)); return; } /* Create a port for our user-level client. */ memset( &port, 0, sizeof(port)); strcpy( port.name, "tracker"); port.capability = SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_WRITE; port.capability |= SND_SEQ_PORT_CAP_SUBS_WRITE; /* necessary??? */ port.type = SND_SEQ_PORT_TYPE_APPLICATION; rc = snd_seq_create_port( midi_handle, &port); if (rc < 0) { close_handle( midi_handle); midi_handle = NULL; g_warning( "error creating sequencer port (%s)\n", snd_strerror(rc)); return; } /* Subscribe to the kernel client. */ memset( &sub, 0, sizeof(sub)); sub.sender.client = midi_settings.input.client; sub.sender.port = midi_settings.input.port; sub.dest.client = client; sub.dest.port = port.port; rc = snd_seq_subscribe_port( midi_handle, &sub); if (rc < 0) { close_handle( midi_handle); midi_handle = NULL; g_warning( "error subscribing to client %d port %d (%s)\n", sub.sender.client, sub.sender.port, snd_strerror(rc)); return; } /* Install callback to process MIDI input. */ midi_file_tag = gdk_input_add( snd_seq_file_descriptor( midi_handle), GDK_INPUT_READ, (GdkInputFunction)midi_in_cb, midi_handle); if (midi_file_tag < 0) { close_handle( midi_handle); midi_handle = NULL; g_warning( "error installing MIDI input callback (%s)\n", g_strerror(midi_file_tag)); return; } if (IS_MIDI_DEBUG_ON) { g_print( "MIDI input initialized\n"); } return; } /* midi_init() */
static void callback_pipes(gpointer data, gint source, GdkInputCondition condition) { char input[4096]; int n, i, number; char *app; number = (int)data; app = app_name(number); n = read(source, input, 4095); if (n<=0) { gdk_input_remove(reader[number]); } if (n==0) { extern int use_yuvdenoise_pipe; extern int use_yuvscaler_pipe; extern int use_yuvplay_pipe; extern int preview_or_render; /* program finished */ if (verbose) printf("%s finished\n", app); /* close pipes/app */ close(pipe_in[number]); if (number != MP2ENC && number != MPEG2ENC && number != YUVSCALER && number != YUVPLAY && number != YUVPLAY_E && number != YUV2LAV && number != YUVDENOISE && number != YUV2DIVX && number != YUV2LAV_E) { close(pipe_out[number]); } close_pipe(number); if (number == LAV2WAV) { close(pipe_out[MP2ENC]); } if (number == LAV2YUV) { if (use_yuvdenoise_pipe) close(pipe_out[YUVDENOISE]); else if (use_yuvscaler_pipe) close(pipe_out[YUVSCALER]); else { extern int studio_enc_format; switch (studio_enc_format) { case STUDIO_ENC_FORMAT_MPEG: close(pipe_out[MPEG2ENC]); break; case STUDIO_ENC_FORMAT_DIVX: close(pipe_out[YUV2DIVX]); break; case STUDIO_ENC_FORMAT_MJPEG: close(pipe_out[YUV2LAV_E]); break; } } if (use_yuvplay_pipe) close(pipe_out[YUVPLAY]); } if (number == YUVDENOISE) { if (use_yuvscaler_pipe) close(pipe_out[YUVSCALER]); else { extern int studio_enc_format; switch (studio_enc_format) { case STUDIO_ENC_FORMAT_MPEG: close(pipe_out[MPEG2ENC]); break; case STUDIO_ENC_FORMAT_DIVX: close(pipe_out[YUV2DIVX]); break; case STUDIO_ENC_FORMAT_MJPEG: close(pipe_out[YUV2LAV_E]); break; } } } if (number == YUVSCALER) { extern int studio_enc_format; switch (studio_enc_format) { case STUDIO_ENC_FORMAT_MPEG: close(pipe_out[MPEG2ENC]); break; case STUDIO_ENC_FORMAT_DIVX: close(pipe_out[YUV2DIVX]); break; case STUDIO_ENC_FORMAT_MJPEG: close(pipe_out[YUV2LAV_E]); break; } } if (number == LAVPIPE) { if (preview_or_render) close(pipe_out[YUV2LAV]); else close(pipe_out[YUVPLAY_E]); } /* trigger callback function for each specific app */ if (number == MPEG2ENC || number == MP2ENC || number == MPLEX || number == YUV2DIVX || number == YUV2LAV_E) { continue_encoding(); } else if (number == LAV2YUV_S) { scene_detection_finished(); } else if (number == LAVPLAY_E) { lavplay_edit_stopped(); } else if (number == LAVPLAY_T) { quit_trimming(NULL,NULL); } else if (number == LAVREC) { lavrec_quit(); } else if (number == LAVPLAY) { lavplay_stopped(); } else if (number == YUV2LAV || number == YUVPLAY_E) { effects_finished(); } /* officially, we should detach the gdk_input here */ gdk_input_remove(reader[number]); } else { int x = 0; char temp[256], endsign; for(i=0;i<n;i++) { if(input[i]=='\n' || input[i]=='\r' || i==n-1) { strncpy(temp, input+x, i-x); if (i-x<255) { if (i==n-1 && input[i]!='\r' && input[i]!='\n') { temp[i-x] = input[i]; if (i-x<254) temp[i-x+1] = '\0'; } else temp[i-x] = '\0'; } endsign = '\n'; if (input[i] == '\n' || input[i] == '\r') endsign = input[i]; if (input[x] == '@') endsign = '\r'; if (number == LAV2YUV_S && strncmp(temp, "--DEBUG: frame", 14)==0) endsign = '\r'; if (number == MPEG2ENC && strncmp(temp, " INFO: Frame", 14)==0) endsign = '\r'; if (number == MP2ENC && strncmp(temp, "--DEBUG: ", 9)==0) endsign = '\r'; if(!(number == LAVPLAY && strncmp(temp, "--DEBUG: frame=", 15)==0)) { if (verbose) { fprintf(stdout, "FROM %10.10s: %s%c", app, temp, endsign); fflush(stdout); } } switch(number) { case MPEG2ENC: case LAV2YUV: case LAV2WAV: case MP2ENC: case MPLEX: case YUVSCALER: case YUVPLAY: case YUV2DIVX: case YUV2LAV_E: lavencode_callback(number, temp); break; case LAV2YUV_S: scene_detection_input_cb(temp); break; case LAVPLAY_E: process_lavplay_edit_input(temp); break; case LAVPLAY: process_lavplay_input(temp); break; case LAVPLAY_T: lavplay_trimming_callback(temp); break; case LAVREC: dispatch_input(temp); break; case YUV2LAV: case YUVPLAY_E: case LAVPIPE: effects_callback(number, temp); break; } x = i+1; } } } }