void JVlibForm::getActivePatchNames() { // get just the associated Part Patch names to match the Part_common headers int err; int Stop=0; unsigned char buf[8]; char name_size[] = { 0x0,0x0,0x0,0x0C }; memset(buf,0,sizeof(buf)); buf[0] = 0x2; buf[7] = 0xC; // just enough space for the name, ignore the rest of patch common for now. // open the selected midi port if (open_ports() == EXIT_FAILURE) return; for (int x=0;x<16;x++) { // get patch common usleep(200000); buf[1] = x; // Patch number RetryC: if (sysex_request(buf) == EXIT_FAILURE) { close_ports(); return; } err = sysex_get((unsigned char *)&active_area->active_perf_patch[x].patch_common.name[0], (char *)name_size); if (err == EXIT_FAILURE) { close_ports(); return; } if (err==2 && Stop<MAX_RETRIES) { Stop++; sleep(1*Stop); goto RetryC; } if (err==3 && Stop<MAX_RETRIES) { Stop++; sleep(1*Stop); goto RetryC; } if (err != EXIT_SUCCESS) { close_ports(); return; } Stop=0; } close_ports(); } // end getActivePatchNames
int main(int argc, char *argv[]) { int rv, len, nblocks, done = 0; char * data = NULL; if ( (rv = get_opts(&gopts, argc, argv)) != 0 ) return rv; /* register interrupt trap */ signal(SIGTERM, cleanup); /* so need global variables */ signal(SIGINT, cleanup); /* open or set input file */ if( gopts.in_fname ) { gcontr.infd = open(gopts.in_fname, O_RDONLY); if( gcontr.infd < 0 ) { fprintf(stderr,"** failed to open infile '%s'\n",gopts.in_fname); return 1; } } else gcontr.infd = 0; /* stdin */ /* allocate data block */ data = (char *)malloc(gopts.block_len * sizeof(char)); if( !data ) { fprintf(stderr,"** failed to alloc %d bytes for block\n", gopts.block_len); return 1; } if( gopts.swap == 2 ) swap_2(data, gopts.block_len/2); else if( gopts.swap == 4 ) swap_4(data, gopts.block_len/4); if( (rv = open_serial(&gopts, &gcontr)) != 0 ) return rv; nblocks = 0; while(! done && (gopts.nblocks <= 0 || nblocks < gopts.nblocks) ) { len = set_data(&gopts, &gcontr, data); if( len > 0 ) done = send_serial(&gopts, &gcontr, data, len); else done = 1; nblocks++; if( gopts.ms_sleep ) ms_sleep(gopts.ms_sleep); } free(data); close_ports(); if(gopts.debug) fprintf(stderr,"-d wrote %d blocks of data\n",nblocks); return 0; }
/* close any open ports (to possibly catch an interrupt) */ void cleanup(int sig_num) { if ( gopts.debug > 0 ) { fprintf(stderr, "-- received signal %d: closing ports\n", sig_num); if ( gopts.debug > 1 ) fprintf(stderr," descriptors: ser = %d, file = %d\n", gcontr.spfd, gcontr.infd); } close_ports(); exit(0); }
/* * Postmaster subroutine to start a syslogger subprocess. */ int syslog_start(void) { pid_t pid; char *filename; if (!log_collector) return 0; /* * If first time through, create the pipe which will receive stderr * output. If syslog crashes and needs to be restarted, we continue to * use the same pipe. Indeed must do so, since extant backends will be * writing into that pipe. * * This means the postmaster must continue to hold the read end of the * pipe open, so we can pass it down to the reincarnated syslogger. This * is a bit klugy but we have little choice. */ #ifndef WIN32 if (syslog_pipe[0] < 0) { if (pgpipe(syslog_pipe) < 0) ereport(FATAL, ( errcode_sock_access(), errmsg("could not create pipe for syslog: %m"))); } #else if (!syslog_pipe[0]) { SECURITY_ATTRIBUTES sa; memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES)); sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.bInheritHandle = TRUE; if (!CreatePipe(&syslog_pipe[0], &syslog_pipe[1], &sa, 32768)) ereport(FATAL, ( errcode_file_access(), errmsg("could not create pipe for syslog: %m"))); } #endif /* * Create log directory if not present; ignore errors */ mkdir(log_directory, S_IRWXU); /* * The initial logfile is created right in the postmaster, to verify i * that the log_directory is writable. */ filename = logfile_getname(time(NULL), NULL); syslog_file = logfile_open(filename, "a", false); pfree(filename); #ifdef EXEC_BACKEND switch ((pid = syslog_forkexec())) { #else switch ((pid = fork_process())) { #endif case -1: ereport(LOG, (errmsg("could not fork system logger: %m"))); return 0; #ifndef EXEC_BACKEND case 0: /* in postmaster child ... */ /* Close the postmaster's sockets */ close_ports(true); /* Lose the postmaster's on-exit routines */ on_exit_reset(); /* Drop our connection to postmaster's shared memory */ shm_child_detach(); /* do the work */ syslog_main(0, NULL); break; #endif default: /* success, in postmaster */ /* now we redirect stderr, if not done already */ if (!redirection_done) { #ifndef WIN32 fflush(stdout); if (dup2(syslog_pipe[1], fileno(stdout)) < 0) { ereport(FATAL, ( errcode_file_access(), errmsg("could not redirect stdout: %m"))); } fflush(stderr); if (dup2(syslog_pipe[1], fileno(stderr)) < 0) { ereport(FATAL, ( errcode_file_access(), errmsg("could not redirect stderr: %m"))); } /* Now we are done with the write end of pipe */ close(syslog_pipe[1]); syslog_pipe[1] = -1; #else int fd; /* * open the pipe in binary mode and make sure stderr is binary * after it's been dup'ed into, to avoid disturbing the pipe * chunking protocol. */ fflush(stderr); fd = _open_osfhandle((intptr_t) syslog_pipe[1], _O_APPEND | _O_BINARY); if (dup2(fd, _fileno(stderr)) < 0) ereport(FATAL, ( errcode_file_access(), errmsg("could not redirect stderr: %m"))); close(fd); _setmode(_fileno(stderr), _O_BINARY); /* Now we are done with the write end of the pipe. */ CloseHandle(syslog_pipe[1]); syslog_pipe[1] = 0; #endif redirection_done = true; } /* postmaster will never write the file; close it */ fclose(syslog_file); syslog_file = NULL; return (int) pid; } /* we should never reach here */ return 0; } #ifdef EXEC_BACKEND /* * syslog_forkexec() - * * Format up the arglist for, then fork and exec, a syslogger process */ static pid_t syslog_forkexec(void) { char *av[10]; int ac = 0; char filenobuf[32]; av[ac++] = "postgres"; av[ac++] = "--forklog"; av[ac++] = NULL; /* filled in by master_forkexec */ /* static variables (those not passed by write_backend_variables) */ #ifndef WIN32 if (syslog_file != NULL) snprintf(filenobuf, sizeof(filenobuf), "%d", fileno(syslog_file)); else strcpy(filenobuf, "-1"); #else /* WIN32 */ if (syslog_file != NULL) snprintf(filenobuf, sizeof(filenobuf), "%ld", (long) _get_osfhandle(_fileno(syslog_file))); else strcpy(filenobuf, "0"); #endif /* WIN32 */ av[ac++] = filenobuf; av[ac] = NULL; ASSERT(ac < lengthof(av)); return master_forkexec(ac, av); }
void JVlibForm::getActivePerfCommon() { // download from the synth: Performance Common, Part Common (15 total) // called from on_PerfSync_button_clicked when Performance Sync button is clicked. int err; int Stop=0; unsigned char buf[8]; char active_perf_common[]={ 0x1,0x0,0x0,0x0 }; char perf_common_size[] = { 0x0,0x0,0x0,0x40 }; char perf_part_size[] = { 0x0,0x0,0x0,0x13 }; char name_size[] = { 0x0,0x0,0x0,0x0C }; // get active_area perf_common memset(buf,0,sizeof(buf)); memcpy(buf+0,active_perf_common,4); memcpy(buf+4,perf_common_size,4); // open the selected midi port if (open_ports() == EXIT_FAILURE) return; QProgressDialog progress("Getting Performance data...", "Abort Download", 0, 32, this); progress.setWindowModality(Qt::WindowModal); progress.setMinimumDuration(0); progress.setValue(0); RetryA: if (sysex_request(buf) == EXIT_FAILURE) { close_ports(); return; } err = sysex_get((unsigned char *)&active_area->active_performance.perf_common.name[0], (char *)perf_common_size); if (err == EXIT_FAILURE) { close_ports(); return; } if (err==2 && Stop<MAX_RETRIES) { if (debug) puts("Retrying"); Stop++; sleep(1*Stop); goto RetryA; } if (err==3 && Stop<MAX_RETRIES) { if (debug) puts("Retrying"); Stop++; sleep(1*Stop); goto RetryA; } if (err != EXIT_SUCCESS) { close_ports(); return; } // get Performance Part_common headers for 16 parts memcpy(buf+4,perf_part_size,4); for (int x=0;x<16;x++) { progress.setValue(x); if (progress.wasCanceled()) goto breakout; printf("part %d\n",x+1); usleep(200000); buf[2] = 0x10+x; RetryB: if (sysex_request(buf) == EXIT_FAILURE) { close_ports(); return; } err = sysex_get((unsigned char *)&active_area->active_performance.perf_part[x].MIDI_receive, (char *)perf_part_size); if (err == EXIT_FAILURE) { close_ports(); return; } if (err==2 && Stop<MAX_RETRIES) { Stop++; sleep(1*Stop); goto RetryB; } if (err==3 && Stop<MAX_RETRIES) { Stop++; sleep(1*Stop); goto RetryB; } if (err != EXIT_SUCCESS) { close_ports(); return; } Stop=0; } // end FOR // get just the associated Part Patch names to match the Part_common headers memset(buf,0,sizeof(buf)); buf[0] = 0x2; buf[7] = 0xC; // just enough space for the name, ignore the rest of patch common for now. for (int x=0;x<16;x++) { // get patch common progress.setValue(x+16); if (progress.wasCanceled()) goto breakout; printf("patch name %d\n",x+1); usleep(200000); buf[1] = x; // Patch number RetryC: if (sysex_request(buf) == EXIT_FAILURE) { close_ports(); return; } err = sysex_get((unsigned char *)&active_area->active_perf_patch[x].patch_common.name[0], (char *)name_size); if (err == EXIT_FAILURE) { close_ports(); return; } if (err==2 && Stop<MAX_RETRIES) { Stop++; sleep(1*Stop); goto RetryC; } if (err==3 && Stop<MAX_RETRIES) { Stop++; sleep(1*Stop); goto RetryC; } if (err != EXIT_SUCCESS) { close_ports(); return; } Stop=0; } breakout: close_ports(); progress.setValue(32); progress.reset(); EnableParts(true); } // end getActivePerfCommon