//============================================================================= void tracker::start_logging(char* filename) { if (get_logging()) return; char logfilename[128]; FILE* file; timer t; unsigned long time; double x,y,z,ya,pi,ro; if (filename == NULL) if (get_default_log_filename(logfilename, 128) == -1) { #if TraceErrors printf("tracker: start_logging: could not get default log filename\n"); #endif return; } child_pid_ = fork(); if (child_pid_ == -1) { #if TraceErrors printf("tracker: start_logging: error creating child process\n"); #endif return; } set_logging(1); if (child_pid_ == 0) { file = fopen(logfilename, "a+"); if (file == NULL) { #if TraceErrors printf("tracker: start_logging: error opening file\n"); #endif } t.timer_reset(); while(get_logging()) { get_pose(&x,&y,&z,&ya,&pi,&ro); time = t.timer_read(); fprintf(file, "%lu %.2lf %.2lf %.2lf %.2lf %.2lf %.2lf\n", time, x, y, z, ya, pi, ro); } fclose(file); exit(0); } }
//============================================================================= void tracker::stop_logging(void) { //Parent process gets this call if (!get_logging()) return; set_logging(0); //Send interrupt to child kill(child_pid_, SIGALRM); }
//============================================================================= void tracker::tracker_(int num, unsigned long baud, int stopbits, int databits) { //This is an encapsulated constructor //Creates and opens comport with given settings, sets defaults //for units and hemisphere double yaw, pitch, roll; port = new comport; if (port->open_comport(num, baud, stopbits, databits) == -1) { #if TraceErrors printf("tracker: couldn't open comport\n"); return; #endif } //Always use inches from tracker since this is the system default //Conversion is done upon reading port->send_comport("U"); //On startup, read system stored boresight and set our boresight to this set_angle_units(ANGLE_UNIT_DEG); get_system_boresight(&yaw, &pitch, &roll); //always in degrees set_boresight(yaw, pitch, roll); //Set defaults set_default_units(); set_default_hemisphere(); //FOR LOGGING: //Logging flag set_logging(0); //Child process stuff signal(SIGCHLD, catch_child); signal(SIGALRM, catch_interrupt); child_pid_ = -1; }
static int transmit_audio(fax_session *s) { int res = -1; struct ast_format original_read_fmt; struct ast_format original_write_fmt; fax_state_t fax; t30_state_t *t30state; struct ast_frame *inf = NULL; int last_state = 0; struct timeval now, start, state_change; enum ast_t38_state t38_state; struct ast_control_t38_parameters t38_parameters = { .version = 0, .max_ifp = 800, .rate = AST_T38_RATE_14400, .rate_management = AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF, .fill_bit_removal = 1, /* * spandsp has API calls to support MMR and JBIG transcoding, but they aren't * implemented quite yet... so don't offer them to the remote endpoint * .transcoding_mmr = 1, * .transcoding_jbig = 1, */ }; ast_format_clear(&original_read_fmt); ast_format_clear(&original_write_fmt); /* if in called party mode, try to use T.38 */ if (s->caller_mode == FALSE) { /* check if we are already in T.38 mode (unlikely), or if we can request * a switch... if so, request it now and wait for the result, rather * than starting an audio FAX session that will have to be cancelled */ if ((t38_state = ast_channel_get_t38_state(s->chan)) == T38_STATE_NEGOTIATED) { return 1; } else if ((t38_state != T38_STATE_UNAVAILABLE) && (t38_parameters.request_response = AST_T38_REQUEST_NEGOTIATE, (ast_indicate_data(s->chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters)) == 0))) { /* wait up to five seconds for negotiation to complete */ unsigned int timeout = 5000; int ms; ast_debug(1, "Negotiating T.38 for receive on %s\n", ast_channel_name(s->chan)); while (timeout > 0) { ms = ast_waitfor(s->chan, 1000); if (ms < 0) { ast_log(LOG_WARNING, "something bad happened while channel '%s' was polling.\n", ast_channel_name(s->chan)); return -1; } if (!ms) { /* nothing happened */ if (timeout > 0) { timeout -= 1000; continue; } else { ast_log(LOG_WARNING, "channel '%s' timed-out during the T.38 negotiation.\n", ast_channel_name(s->chan)); break; } } if (!(inf = ast_read(s->chan))) { return -1; } if ((inf->frametype == AST_FRAME_CONTROL) && (inf->subclass.integer == AST_CONTROL_T38_PARAMETERS) && (inf->datalen == sizeof(t38_parameters))) { struct ast_control_t38_parameters *parameters = inf->data.ptr; switch (parameters->request_response) { case AST_T38_NEGOTIATED: ast_debug(1, "Negotiated T.38 for receive on %s\n", ast_channel_name(s->chan)); res = 1; break; case AST_T38_REFUSED: ast_log(LOG_WARNING, "channel '%s' refused to negotiate T.38\n", ast_channel_name(s->chan)); break; default: ast_log(LOG_ERROR, "channel '%s' failed to negotiate T.38\n", ast_channel_name(s->chan)); break; } ast_frfree(inf); if (res == 1) { return 1; } else { break; } } ast_frfree(inf); } } } #if SPANDSP_RELEASE_DATE >= 20080725 /* for spandsp shaphots 0.0.6 and higher */ t30state = &fax.t30; #else /* for spandsp release 0.0.5 */ t30state = &fax.t30_state; #endif ast_format_copy(&original_read_fmt, ast_channel_readformat(s->chan)); if (original_read_fmt.id != AST_FORMAT_SLINEAR) { res = ast_set_read_format_by_id(s->chan, AST_FORMAT_SLINEAR); if (res < 0) { ast_log(LOG_WARNING, "Unable to set to linear read mode, giving up\n"); goto done; } } ast_format_copy(&original_write_fmt, ast_channel_writeformat(s->chan)); if (original_write_fmt.id != AST_FORMAT_SLINEAR) { res = ast_set_write_format_by_id(s->chan, AST_FORMAT_SLINEAR); if (res < 0) { ast_log(LOG_WARNING, "Unable to set to linear write mode, giving up\n"); goto done; } } /* Initialize T30 terminal */ fax_init(&fax, s->caller_mode); /* Setup logging */ set_logging(&fax.logging); set_logging(&t30state->logging); /* Configure terminal */ set_local_info(t30state, s); set_file(t30state, s); set_ecm(t30state, TRUE); fax_set_transmit_on_idle(&fax, TRUE); t30_set_phase_e_handler(t30state, phase_e_handler, s); start = state_change = ast_tvnow(); ast_activate_generator(s->chan, &generator, &fax); while (!s->finished) { inf = NULL; if ((res = ast_waitfor(s->chan, 25)) < 0) { ast_debug(1, "Error waiting for a frame\n"); break; } /* Watchdog */ now = ast_tvnow(); if (ast_tvdiff_sec(now, start) > WATCHDOG_TOTAL_TIMEOUT || ast_tvdiff_sec(now, state_change) > WATCHDOG_STATE_TIMEOUT) { ast_log(LOG_WARNING, "It looks like we hung. Aborting.\n"); res = -1; break; } if (!res) { /* There was timeout waiting for a frame. Loop around and wait again */ continue; } /* There is a frame available. Get it */ res = 0; if (!(inf = ast_read(s->chan))) { ast_debug(1, "Channel hangup\n"); res = -1; break; } ast_debug(10, "frame %d/%u, len=%d\n", inf->frametype, (unsigned int) inf->subclass.format.id, inf->datalen); /* Check the frame type. Format also must be checked because there is a chance that a frame in old format was already queued before we set channel format to slinear so it will still be received by ast_read */ if (inf->frametype == AST_FRAME_VOICE && inf->subclass.format.id == AST_FORMAT_SLINEAR) { if (fax_rx(&fax, inf->data.ptr, inf->samples) < 0) { /* I know fax_rx never returns errors. The check here is for good style only */ ast_log(LOG_WARNING, "fax_rx returned error\n"); res = -1; break; } if (last_state != t30state->state) { state_change = ast_tvnow(); last_state = t30state->state; } } else if ((inf->frametype == AST_FRAME_CONTROL) && (inf->subclass.integer == AST_CONTROL_T38_PARAMETERS)) { struct ast_control_t38_parameters *parameters = inf->data.ptr; if (parameters->request_response == AST_T38_NEGOTIATED) { /* T38 switchover completed */ s->t38parameters = *parameters; ast_debug(1, "T38 negotiated, finishing audio loop\n"); res = 1; break; } else if (parameters->request_response == AST_T38_REQUEST_NEGOTIATE) { t38_parameters.request_response = AST_T38_NEGOTIATED; ast_debug(1, "T38 request received, accepting\n"); /* Complete T38 switchover */ ast_indicate_data(s->chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters)); /* Do not break audio loop, wait until channel driver finally acks switchover * with AST_T38_NEGOTIATED */ } } ast_frfree(inf); inf = NULL; } ast_debug(1, "Loop finished, res=%d\n", res); if (inf) ast_frfree(inf); ast_deactivate_generator(s->chan); /* If we are switching to T38, remove phase E handler. Otherwise it will be executed by t30_terminate, display diagnostics and set status variables although no transmittion has taken place yet. */ if (res > 0) { t30_set_phase_e_handler(t30state, NULL, NULL); } t30_terminate(t30state); fax_release(&fax); done: if (original_write_fmt.id != AST_FORMAT_SLINEAR) { if (ast_set_write_format(s->chan, &original_write_fmt) < 0) ast_log(LOG_WARNING, "Unable to restore write format on '%s'\n", ast_channel_name(s->chan)); } if (original_read_fmt.id != AST_FORMAT_SLINEAR) { if (ast_set_read_format(s->chan, &original_read_fmt) < 0) ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", ast_channel_name(s->chan)); } return res; } static int transmit_t38(fax_session *s) { int res = 0; t38_terminal_state_t t38; struct ast_frame *inf = NULL; int last_state = 0; struct timeval now, start, state_change, last_frame; t30_state_t *t30state; t38_core_state_t *t38state; #if SPANDSP_RELEASE_DATE >= 20080725 /* for spandsp shaphots 0.0.6 and higher */ t30state = &t38.t30; t38state = &t38.t38_fe.t38; #else /* for spandsp releases 0.0.5 */ t30state = &t38.t30_state; t38state = &t38.t38; #endif /* Initialize terminal */ memset(&t38, 0, sizeof(t38)); if (t38_terminal_init(&t38, s->caller_mode, t38_tx_packet_handler, s->chan) == NULL) { ast_log(LOG_WARNING, "Unable to start T.38 termination.\n"); res = -1; goto disable_t38; } t38_set_max_datagram_size(t38state, s->t38parameters.max_ifp); if (s->t38parameters.fill_bit_removal) { t38_set_fill_bit_removal(t38state, TRUE); } if (s->t38parameters.transcoding_mmr) { t38_set_mmr_transcoding(t38state, TRUE); } if (s->t38parameters.transcoding_jbig) { t38_set_jbig_transcoding(t38state, TRUE); } /* Setup logging */ set_logging(&t38.logging); set_logging(&t30state->logging); set_logging(&t38state->logging); /* Configure terminal */ set_local_info(t30state, s); set_file(t30state, s); set_ecm(t30state, TRUE); t30_set_phase_e_handler(t30state, phase_e_handler, s); now = start = state_change = ast_tvnow(); while (!s->finished) { inf = NULL; if ((res = ast_waitfor(s->chan, 25)) < 0) { ast_debug(1, "Error waiting for a frame\n"); break; } last_frame = now; /* Watchdog */ now = ast_tvnow(); if (ast_tvdiff_sec(now, start) > WATCHDOG_TOTAL_TIMEOUT || ast_tvdiff_sec(now, state_change) > WATCHDOG_STATE_TIMEOUT) { ast_log(LOG_WARNING, "It looks like we hung. Aborting.\n"); res = -1; break; } t38_terminal_send_timeout(&t38, ast_tvdiff_us(now, last_frame) / (1000000 / 8000)); if (!res) { /* There was timeout waiting for a frame. Loop around and wait again */ continue; } /* There is a frame available. Get it */ res = 0; if (!(inf = ast_read(s->chan))) { ast_debug(1, "Channel hangup\n"); res = -1; break; } ast_debug(10, "frame %d/%d, len=%d\n", inf->frametype, inf->subclass.integer, inf->datalen); if (inf->frametype == AST_FRAME_MODEM && inf->subclass.integer == AST_MODEM_T38) { t38_core_rx_ifp_packet(t38state, inf->data.ptr, inf->datalen, inf->seqno); if (last_state != t30state->state) { state_change = ast_tvnow(); last_state = t30state->state; } } else if (inf->frametype == AST_FRAME_CONTROL && inf->subclass.integer == AST_CONTROL_T38_PARAMETERS) { struct ast_control_t38_parameters *parameters = inf->data.ptr; if (parameters->request_response == AST_T38_TERMINATED) { ast_debug(1, "T38 down, finishing\n"); break; } } ast_frfree(inf); inf = NULL; } ast_debug(1, "Loop finished, res=%d\n", res); if (inf) ast_frfree(inf); t30_terminate(t30state); t38_terminal_release(&t38); disable_t38: /* if we are not the caller, it's our job to shut down the T.38 * session when the FAX transmisson is complete. */ if ((s->caller_mode == FALSE) && (ast_channel_get_t38_state(s->chan) == T38_STATE_NEGOTIATED)) { struct ast_control_t38_parameters t38_parameters = { .request_response = AST_T38_REQUEST_TERMINATE, }; if (ast_indicate_data(s->chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters)) == 0) { /* wait up to five seconds for negotiation to complete */ unsigned int timeout = 5000; int ms; ast_debug(1, "Shutting down T.38 on %s\n", ast_channel_name(s->chan)); while (timeout > 0) { ms = ast_waitfor(s->chan, 1000); if (ms < 0) { ast_log(LOG_WARNING, "something bad happened while channel '%s' was polling.\n", ast_channel_name(s->chan)); return -1; } if (!ms) { /* nothing happened */ if (timeout > 0) { timeout -= 1000; continue; } else { ast_log(LOG_WARNING, "channel '%s' timed-out during the T.38 shutdown.\n", ast_channel_name(s->chan)); break; } } if (!(inf = ast_read(s->chan))) { return -1; } if ((inf->frametype == AST_FRAME_CONTROL) && (inf->subclass.integer == AST_CONTROL_T38_PARAMETERS) && (inf->datalen == sizeof(t38_parameters))) { struct ast_control_t38_parameters *parameters = inf->data.ptr; switch (parameters->request_response) { case AST_T38_TERMINATED: ast_debug(1, "Shut down T.38 on %s\n", ast_channel_name(s->chan)); break; case AST_T38_REFUSED: ast_log(LOG_WARNING, "channel '%s' refused to disable T.38\n", ast_channel_name(s->chan)); break; default: ast_log(LOG_ERROR, "channel '%s' failed to disable T.38\n", ast_channel_name(s->chan)); break; } ast_frfree(inf); break; } ast_frfree(inf); } } } return res; }
DatabaseIO::DatabaseIO(Region *region, std::string filename, DatabaseUsage db_usage, MPI_Comm communicator, const PropertyManager &props) : properties(props), commonSideTopology(nullptr), DBFilename(std::move(filename)), dbState(STATE_INVALID), isParallel(false), myProcessor(0), cycleCount(0), overlayCount(0), timeScaleFactor(1.0), splitType(SPLIT_BY_TOPOLOGIES), dbUsage(db_usage), dbIntSizeAPI(USE_INT32_API), lowerCaseVariableNames(true), util_(communicator), region_(region), isInput(is_input_event(db_usage)), isParallelConsistent(true), singleProcOnly(db_usage == WRITE_HISTORY || db_usage == WRITE_HEARTBEAT || SerializeIO::isEnabled()), doLogging(false), useGenericCanonicalName(false) { isParallel = util_.parallel_size() > 1; myProcessor = util_.parallel_rank(); // Check environment variable IOSS_PROPERTIES. If it exists, parse // the contents and add to the 'properties' map. std::string env_props; if (util_.get_environment("IOSS_PROPERTIES", env_props, isParallel)) { // env_props string should be of the form // "PROP1=VALUE1:PROP2=VALUE2:..." std::vector<std::string> prop_val = tokenize(env_props, ":"); for (auto &elem : prop_val) { std::vector<std::string> property = tokenize(elem, "="); if (property.size() != 2) { std::ostringstream errmsg; errmsg << "ERROR: Invalid property specification found in " "IOSS_PROPERTIES environment variable\n" << " Found '" << elem << "' which is not of the correct PROPERTY=VALUE form"; IOSS_ERROR(errmsg); } std::string prop = Utils::uppercase(property[0]); std::string value = property[1]; std::string up_value = Utils::uppercase(value); bool all_digit = value.find_first_not_of("0123456789") == std::string::npos; if (myProcessor == 0) { std::cerr << "IOSS: Adding property '" << prop << "' with value '" << value << "'\n"; } if (all_digit) { int int_value = std::strtol(value.c_str(), nullptr, 10); properties.add(Property(prop, int_value)); } else if (up_value == "TRUE" || up_value == "YES") { properties.add(Property(prop, 1)); } else if (up_value == "FALSE" || up_value == "NO") { properties.add(Property(prop, 0)); } else { properties.add(Property(prop, value)); } } } if (properties.exists("INTEGER_SIZE_API")) { int isize = properties.get("INTEGER_SIZE_API").get_int(); if (isize == 8) { set_int_byte_size_api(Ioss::USE_INT64_API); } } { bool logging; if (Utils::check_set_bool_property(properties, "LOGGING", logging)) { set_logging(logging); } } Utils::check_set_bool_property(properties, "LOWER_CASE_VARIABLE_NAMES", lowerCaseVariableNames); Utils::check_set_bool_property(properties, "USE_GENERIC_CANONICAL_NAMES", useGenericCanonicalName); { bool consistent; if (Utils::check_set_bool_property(properties, "PARALLEL_CONSISTENCY", consistent)) { set_parallel_consistency(consistent); } } if (!is_input()) { // Create full path to the output file at this point if it doesn't // exist... create_path(DBFilename); } }
static int transmit_t38(fax_session *s) { int res = 0; t38_terminal_state_t t38; struct ast_frame *inf = NULL; int last_state = 0; struct timeval now, start, state_change, last_frame; enum ast_control_t38 t38control; /* Initialize terminal */ memset(&t38, 0, sizeof(t38)); if (t38_terminal_init(&t38, s->caller_mode, t38_tx_packet_handler, s->chan) == NULL) { ast_log(LOG_WARNING, "Unable to start T.38 termination.\n"); return -1; } /* Setup logging */ set_logging(&t38.logging); set_logging(&t38.t30_state.logging); set_logging(&t38.t38.logging); /* Configure terminal */ set_local_info(&t38.t30_state, s); set_file(&t38.t30_state, s); set_ecm(&t38.t30_state, TRUE); t30_set_phase_e_handler(&t38.t30_state, phase_e_handler, s); now = start = state_change = ast_tvnow(); while (!s->finished) { res = ast_waitfor(s->chan, 20); if (res < 0) break; else if (res > 0) res = 0; last_frame = now; now = ast_tvnow(); t38_terminal_send_timeout(&t38, ast_tvdiff_us(now, last_frame) / (1000000 / 8000)); inf = ast_read(s->chan); if (inf == NULL) { ast_debug(1, "Channel hangup\n"); res = -1; break; } ast_debug(10, "frame %d/%d, len=%d\n", inf->frametype, inf->subclass, inf->datalen); if (inf->frametype == AST_FRAME_MODEM && inf->subclass == AST_MODEM_T38) { t38_core_rx_ifp_packet(&t38.t38, inf->data, inf->datalen, inf->seqno); /* Watchdog */ if (last_state != t38.t30_state.state) { state_change = ast_tvnow(); last_state = t38.t30_state.state; } } else if (inf->frametype == AST_FRAME_CONTROL && inf->subclass == AST_CONTROL_T38 && inf->datalen == sizeof(enum ast_control_t38)) { t38control = *((enum ast_control_t38 *) inf->data); if (t38control == AST_T38_TERMINATED || t38control == AST_T38_REFUSED) { ast_debug(1, "T38 down, terminating\n"); res = -1; break; } } ast_frfree(inf); inf = NULL; /* Watchdog */ if (ast_tvdiff_sec(now, start) > WATCHDOG_TOTAL_TIMEOUT || ast_tvdiff_sec(now, state_change) > WATCHDOG_STATE_TIMEOUT) { ast_log(LOG_WARNING, "It looks like we hung. Aborting.\n"); res = -1; break; } } ast_debug(1, "Loop finished, res=%d\n", res); if (inf) ast_frfree(inf); t30_terminate(&t38.t30_state); t38_terminal_release(&t38); return res; }
static int transmit_audio(fax_session *s) { int res = -1; int original_read_fmt = AST_FORMAT_SLINEAR; int original_write_fmt = AST_FORMAT_SLINEAR; fax_state_t fax; struct ast_dsp *dsp = NULL; int detect_tone = 0; struct ast_frame *inf = NULL; struct ast_frame *fr; int last_state = 0; struct timeval now, start, state_change; enum ast_control_t38 t38control; original_read_fmt = s->chan->readformat; if (original_read_fmt != AST_FORMAT_SLINEAR) { res = ast_set_read_format(s->chan, AST_FORMAT_SLINEAR); if (res < 0) { ast_log(LOG_WARNING, "Unable to set to linear read mode, giving up\n"); goto done; } } original_write_fmt = s->chan->writeformat; if (original_write_fmt != AST_FORMAT_SLINEAR) { res = ast_set_write_format(s->chan, AST_FORMAT_SLINEAR); if (res < 0) { ast_log(LOG_WARNING, "Unable to set to linear write mode, giving up\n"); goto done; } } /* Initialize T30 terminal */ fax_init(&fax, s->caller_mode); /* Setup logging */ set_logging(&fax.logging); set_logging(&fax.t30_state.logging); /* Configure terminal */ set_local_info(&fax.t30_state, s); set_file(&fax.t30_state, s); set_ecm(&fax.t30_state, TRUE); fax_set_transmit_on_idle(&fax, TRUE); t30_set_phase_e_handler(&fax.t30_state, phase_e_handler, s); if (s->t38state == T38_STATE_UNAVAILABLE) { ast_debug(1, "T38 is unavailable on %s\n", s->chan->name); } else if (!s->direction) { /* We are receiving side and this means we are the side which should request T38 when the fax is detected. Use DSP to detect fax tone */ ast_debug(1, "Setting up CNG detection on %s\n", s->chan->name); dsp = ast_dsp_new(); ast_dsp_set_features(dsp, DSP_FEATURE_FAX_DETECT); ast_dsp_set_faxmode(dsp, DSP_FAXMODE_DETECT_CNG); detect_tone = 1; } start = state_change = ast_tvnow(); ast_activate_generator(s->chan, &generator, &fax); while (!s->finished) { res = ast_waitfor(s->chan, 20); if (res < 0) break; else if (res > 0) res = 0; inf = ast_read(s->chan); if (inf == NULL) { ast_debug(1, "Channel hangup\n"); res = -1; break; } ast_debug(10, "frame %d/%d, len=%d\n", inf->frametype, inf->subclass, inf->datalen); /* Detect fax tone */ if (detect_tone && inf->frametype == AST_FRAME_VOICE) { /* Duplicate frame because ast_dsp_process may free the frame passed */ fr = ast_frdup(inf); /* Do not pass channel to ast_dsp_process otherwise it may queue modified audio frame back */ fr = ast_dsp_process(NULL, dsp, fr); if (fr && fr->frametype == AST_FRAME_DTMF && fr->subclass == 'f') { ast_debug(1, "Fax tone detected. Requesting T38\n"); t38control = AST_T38_REQUEST_NEGOTIATE; ast_indicate_data(s->chan, AST_CONTROL_T38, &t38control, sizeof(t38control)); detect_tone = 0; } ast_frfree(fr); } /* Check the frame type. Format also must be checked because there is a chance that a frame in old format was already queued before we set chanel format to slinear so it will still be received by ast_read */ if (inf->frametype == AST_FRAME_VOICE && inf->subclass == AST_FORMAT_SLINEAR) { if (fax_rx(&fax, inf->data, inf->samples) < 0) { /* I know fax_rx never returns errors. The check here is for good style only */ ast_log(LOG_WARNING, "fax_rx returned error\n"); res = -1; break; } /* Watchdog */ if (last_state != fax.t30_state.state) { state_change = ast_tvnow(); last_state = fax.t30_state.state; } } else if (inf->frametype == AST_FRAME_CONTROL && inf->subclass == AST_CONTROL_T38 && inf->datalen == sizeof(enum ast_control_t38)) { t38control =*((enum ast_control_t38 *) inf->data); if (t38control == AST_T38_NEGOTIATED) { /* T38 switchover completed */ ast_debug(1, "T38 negotiated, finishing audio loop\n"); res = 1; break; } } ast_frfree(inf); inf = NULL; /* Watchdog */ now = ast_tvnow(); if (ast_tvdiff_sec(now, start) > WATCHDOG_TOTAL_TIMEOUT || ast_tvdiff_sec(now, state_change) > WATCHDOG_STATE_TIMEOUT) { ast_log(LOG_WARNING, "It looks like we hung. Aborting.\n"); res = -1; break; } } ast_debug(1, "Loop finished, res=%d\n", res); if (inf) ast_frfree(inf); if (dsp) ast_dsp_free(dsp); ast_deactivate_generator(s->chan); /* If we are switching to T38, remove phase E handler. Otherwise it will be executed by t30_terminate, display diagnostics and set status variables although no transmittion has taken place yet. */ if (res > 0) { t30_set_phase_e_handler(&fax.t30_state, NULL, NULL); } t30_terminate(&fax.t30_state); fax_release(&fax); done: if (original_write_fmt != AST_FORMAT_SLINEAR) { if (ast_set_write_format(s->chan, original_write_fmt) < 0) ast_log(LOG_WARNING, "Unable to restore write format on '%s'\n", s->chan->name); } if (original_read_fmt != AST_FORMAT_SLINEAR) { if (ast_set_read_format(s->chan, original_read_fmt) < 0) ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", s->chan->name); } return res; }
//============================================================================= void tracker::start_logging_xml(char* filename) { if (get_logging()) return; char logfilename[128]; FILE* file; timer t; unsigned long time; double x,y,z,ya,pi,ro; //double *x, *y, *z, *ya, *pi, *ro; //int num = 2; if (filename == NULL) if (get_default_xml_filename(logfilename, 128) == -1) { #if TraceErrors printf("tracker: start_logging: could not get default log filename\n"); #endif return; } child_pid_ = fork(); if (child_pid_ == -1) { #if TraceErrors printf("tracker: start_logging: error creating child process\n"); #endif return; } set_logging(1); if (child_pid_ == 0) { file = fopen(logfilename, "a+"); if (file == NULL) { #if TraceErrors printf("tracker: start_logging: error opening file\n"); #endif } t.timer_reset(); fprintf(file,"<demo>\n"); while(get_logging()) { get_pose(&x,&y,&z,&ya,&pi,&ro); //get_multi_pose(num,&x,&y,&z,&ya,&pi,&ro); time = t.timer_read(); fprintf(file,"<point>\n"); fprintf(file,"<time>%.3lf</time>\n",((double)time) /1000 ); fprintf(file,"<end-effector>"); fprintf(file, "<position>%.2lf;%.2lf;%.2lf</position><YPR>%.2lf;%.2lf;%.2lf</YPR>", x, y, z, ya, pi, ro); //fprintf(file, "<position>%.2lf;%.2lf;%.2lf</position><YPR>%.2lf;%.2lf;%.2lf</YPR>", x, y, z, ya, pi, ro); printf("%lu %.2lf %.2lf %.2lf %.2lf %.2lf %.2lf\n",time, x, y, z, ya, pi, ro); /*for(int i=0;i<num;i++){ printf("%lu %.2lf %.2lf %.2lf %.2lf %.2lf %.2lf\n",time, x[i], y[i], z[i], ya[i], pi[i], ro[i]); }*/ fprintf(file,"</end-effector>\n"); fprintf(file,"</point>\n"); } fprintf(file,"</demo>\n"); fclose(file); exit(0); } }
int main(int argc, char *argv[]) { signal(SIGCHLD, signal_sigchld); signal(SIGINT, signal_sigint); signal(SIGPIPE, signal_sigint); signal(SIGTERM, signal_sigint); signal(SIGTSTP, signal_sigint); signal(SIGHUP, signal_sigint); log_level(_LOG_DEBUG); log_msg("Start zoodis."); zoodis.keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL; zoodis.zoo_stat = ZOO_STAT_NOT_CONNECTED; zoodis.zoo_timeout = DEFAULT_ZOO_TIMEOUT; zoodis.zoo_connect_wait_interval = DEFAULT_ZOO_CONNECT_WAIT_INTERVAL; zoodis.redis_port = DEFAULT_REDIS_PORT; zoodis.redis_ping_interval = DEFAULT_REDIS_PING_INTERVAL; zoodis.redis_pong_timeout_sec = DEFAULT_REDIS_PONG_TIMEOUT_SEC; zoodis.redis_pong_timeout_usec = DEFAULT_REDIS_PONG_TIMEOUT_USEC; zoodis.redis_max_fail_count = DEFAULT_REDIS_MAX_FAIL_COUNT; zoodis.pid_file = NULL; zoodis.redis_stat = REDIS_STAT_NONE; static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'v'}, {"log-level", required_argument, 0, 'l'}, {"pid-file", required_argument, 0, 'f'}, {"keepalive", no_argument, 0, 'k'}, {"keepalive-interval", required_argument, 0, 'i'}, {"redis-bin", required_argument, 0, 'b'}, {"redis-conf", required_argument, 0, 'c'}, {"redis-port", required_argument, 0, 'r'}, {"redis-ping-interval", required_argument, 0, 's'}, {"zoo-host", required_argument, 0, 'z'}, {"zoo-path", required_argument, 0, 'p'}, {"zoo-nodename", required_argument, 0, 'n'}, {"zoo-nodedata", required_argument, 0, 'd'}, {"zoo-timeout", required_argument, 0, 't'}, {0, 0, 0, 0} }; enum zoo_res zres; if(argc < 3) print_help(argv); while (1) { /* getopt_long stores the option index here. */ int option_index = 0; int opt; opt = getopt_long_only(argc, argv, "", long_options, &option_index); /* Detect the end of the options. */ if (opt == -1) break; switch (opt) { case 'h': print_help(argv); break; case 'v': print_version(argv); break; case 'l': set_logging(optarg); break; case 'k': zoodis.keepalive = 1; break; case 'f': zoodis.pid_file = check_pid_file(optarg); case 'i': zoodis.keepalive_interval = check_option_int(optarg, DEFAULT_KEEPALIVE_INTERVAL); break; case 'b': zoodis.redis_bin = check_redis_bin(optarg); break; case 'c': zoodis.redis_conf = check_redis_conf(optarg); break; case 'r': zoodis.redis_port = check_option_int(optarg, DEFAULT_REDIS_PORT); break; case 's': zoodis.redis_ping_interval = check_option_int(optarg, DEFAULT_REDIS_PING_INTERVAL); break; case 'z': zoodis.zoo_host = check_zoo_host(optarg); break; case 'p': zoodis.zoo_path = check_zoo_path(optarg); break; case 'n': zoodis.zoo_nodename = check_zoo_nodename(optarg); break; case 'd': zoodis.zoo_nodedata = check_zoo_nodedata(optarg); break; case 't': zoodis.zoo_timeout = check_option_int(optarg, DEFAULT_ZOO_TIMEOUT); break; default: exit_proc(-1); } } zoodis.zookeeper = check_zoo_options(&zoodis); if(zoodis.zoo_nodedata == NULL) zoodis.zoo_nodedata = mstr_alloc_dup(DEFAULT_ZOO_NODEDATA, strlen(DEFAULT_ZOO_NODEDATA)); check_redis_options(&zoodis); if(zoodis.zookeeper) { zoodis.zoo_nodepath = mstr_concat(3, zoodis.zoo_path->data, "/", zoodis.zoo_nodename->data); zu_set_log_level(log_level(0)); zu_set_log_stream(log_fd(stdout)); zres = zu_connect(&zoodis); if(zres != ZOO_RES_OK) { exit_proc(-1); } } // sleep(1); // while(zoodis.zoo_stat != ZOO_STAT_CONNECTED) // if(zoodis.zoo_stat != ZOO_STAT_CONNECTED) // { // log_warn("Zookeeper: is not connected yet."); // sleep(zoodis.zoo_connect_wait_interval); // } exec_redis(); redis_health(); return 0; }
int dna_helper_start() { const char *command = confValueGet("dna.helper.executable", NULL); const char *arg = confValueGet("dna.helper.argv.1", NULL); if (!command || !command[0]) { /* Check if we have a helper configured. If not, then set dna_helper_pid to magic value of 0 so that we don't waste time in future looking up the dna helper configuration value. */ INFO("DNAHELPER none configured"); dna_helper_pid = 0; return 0; } if (!my_subscriber) return WHY("Unable to lookup my SID"); const char *mysid = alloca_tohex_sid(my_subscriber->sid); dna_helper_close_pipes(); int stdin_fds[2], stdout_fds[2], stderr_fds[2]; if (pipe(stdin_fds) == -1) return WHY_perror("pipe"); if (pipe(stdout_fds) == -1) { WHY_perror("pipe"); close(stdin_fds[0]); close(stdin_fds[1]); return -1; } if (pipe(stderr_fds) == -1) { WHY_perror("pipe"); close(stdin_fds[0]); close(stdin_fds[1]); close(stdout_fds[0]); close(stdout_fds[1]); return -1; } switch (dna_helper_pid = fork()) { case 0: /* Child, should exec() to become helper after installing file descriptors. */ setenv("MYSID", mysid, 1); set_logging(stderr); signal(SIGTERM, SIG_DFL); close(stdin_fds[1]); close(stdout_fds[0]); close(stderr_fds[0]); if (dup2(stderr_fds[1], 2) == -1 || dup2(stdout_fds[1], 1) == -1 || dup2(stdin_fds[0], 0) == -1) { LOG_perror(LOG_LEVEL_FATAL, "dup2"); fflush(stderr); _exit(-1); } /* XXX: Need the cast on Solaris because it defins NULL as 0L and gcc doesn't * see it as a sentinal */ execl(command, command, arg, (void *)NULL); LOGF_perror(LOG_LEVEL_FATAL, "execl(%s, %s, %s, NULL)", command, command, arg ? arg : "NULL"); fflush(stderr); do { _exit(-1); } while (1); break; case -1: /* fork failed */ WHY_perror("fork"); close(stdin_fds[0]); close(stdin_fds[1]); close(stdout_fds[0]); close(stdout_fds[1]); close(stderr_fds[0]); close(stderr_fds[1]); return -1; default: /* Parent, should put file descriptors into place for use */ close(stdin_fds[0]); close(stdout_fds[1]); close(stderr_fds[1]); dna_helper_started = 0; dna_helper_stdin = stdin_fds[1]; dna_helper_stdout = stdout_fds[0]; dna_helper_stderr = stderr_fds[0]; INFOF("STARTED DNA HELPER pid=%u stdin=%d stdout=%d stderr=%d executable=%s arg=%s", dna_helper_pid, dna_helper_stdin, dna_helper_stdout, dna_helper_stderr, command, arg ? arg : "NULL" ); sched_requests.function = monitor_requests; sched_requests.context = NULL; sched_requests.poll.fd = -1; sched_requests.poll.events = POLLOUT; sched_requests.stats = NULL; sched_timeout.function = reply_timeout; sched_timeout.context = NULL; sched_timeout.stats = NULL; sched_replies.function = monitor_replies; sched_replies.context = NULL; sched_replies.poll.fd = dna_helper_stdout; sched_replies.poll.events = POLLIN; sched_replies.stats = NULL; sched_errors.function = monitor_errors; sched_errors.context = NULL; sched_errors.poll.fd = dna_helper_stderr; sched_errors.poll.events = POLLIN; sched_errors.stats = NULL; sched_harvester.function = harvester; sched_harvester.stats = NULL; sched_harvester.alarm = gettime_ms() + 1000; sched_harvester.deadline = sched_harvester.alarm + 1000; reply_bufend = reply_buffer; discarding_until_nl = 0; awaiting_reply = 0; watch(&sched_replies); watch(&sched_errors); schedule(&sched_harvester); return 0; } return -1; }