Exemple #1
0
/**
 * output RAW format log
 *
 * @param format output format
 * @param ... args
 */
void elog_raw(const char *format, ...) {
    va_list args;
    int fmt_result;

    /* check output enabled */
    if (!elog.output_enabled) {
        return;
    }

    /* args point to the first variable parameter */
    va_start(args, format);

    /* lock output */
    output_lock();

    /* package log data to buffer */
    fmt_result = vsnprintf(log_buf, ELOG_BUF_SIZE, format, args);

    /* output converted log */
    if ((fmt_result > -1) && (fmt_result <= ELOG_BUF_SIZE)) {
        /* output log */
        elog_port_output(log_buf, fmt_result);
    } else {
        /* output log */
        elog_port_output(log_buf, ELOG_BUF_SIZE);
    }

    /* unlock output */
    elog_port_output_unlock();

    va_end(args);
}
Exemple #2
0
int
output_send_debug(OutputModule *output, int flag, char* log_path)
{
    char *cmd_str;
    int err;

    MSG(4, "Module sending debug flag %d with file %s", flag, log_path);
    
    output_lock();
    if (flag){
      cmd_str = g_strdup_printf("DEBUG ON %s \n", log_path);
      err = output_send_data(cmd_str, output, 1);
      spd_free(cmd_str);
      if (err){
	MSG(3, "ERROR: Can't set debugging on for output module %s", output->name);
	OL_RET(-1);
      }      
    }else{
      err = output_send_data("DEBUG OFF \n", output, 1);
      if (err){
	MSG(3, "ERROR: Can't switch debugging off for output module %s", output->name);
	OL_RET(-1);
      }
      
    }
   
    OL_RET(0);
}
Exemple #3
0
int
output_speak(TSpeechDMessage *msg)
{
    OutputModule *output;
    int err;
    int ret;

    if(msg == NULL) return -1;

    output_lock();


    /* Determine which output module should be used */
    output = get_output_module(msg);
    if (output == NULL){
        MSG(3, "Output module doesn't work...");
        OL_RET(-1)
    }                    
Exemple #4
0
/**
 * output the log
 *
 * @param level level
 * @param tag tag
 * @param file file name
 * @param func function name
 * @param line line number
 * @param format output format
 * @param ... args
 *
 */
void elog_output(uint8_t level, const char *tag, const char *file, const char *func,
        const long line, const char *format, ...) {
	size_t tag_len = strlen(tag), log_len = 0, newline_len = strlen(ELOG_NEWLINE_SIGN), slog_len = 0;
    char line_num[ELOG_LINE_NUM_MAX_LEN + 1] = { 0 };
    char tag_sapce[ELOG_FILTER_TAG_MAX_LEN / 2 + 1] = { 0 };
    va_list args;
    int fmt_result;

    ELOG_ASSERT(level <= ELOG_LVL_VERBOSE);

    /* check output enabled */
    if (!elog.output_enabled) {
        return;
    }

    /* level filter */
    if (level > elog.filter.level) {
        return;
    } else if (!strstr(tag, elog.filter.tag)) { /* tag filter */
        //TODO 可以考虑采用KMP及朴素模式匹配字符串,提升性能
        return;
    }
	slog.level = level;
	strncpy(slog.tag, tag, sizeof(tag) - 1);
    /* args point to the first variable parameter */
    va_start(args, format);

    /* lock output */
    output_lock();
    /* package level info */
    if (get_fmt_enabled(level, ELOG_FMT_LVL)) {
        log_len += elog_strcpy(log_len, log_buf + log_len, level_output_info[level]);
    }
    /* package tag info */
    if (get_fmt_enabled(level, ELOG_FMT_TAG)) {
        log_len += elog_strcpy(log_len, log_buf + log_len, tag);
        /* if the tag length is less than 50% ELOG_FILTER_TAG_MAX_LEN, then fill space */
        if (tag_len <= ELOG_FILTER_TAG_MAX_LEN / 2) {
            memset(tag_sapce, ' ', ELOG_FILTER_TAG_MAX_LEN / 2 - tag_len);
            log_len += elog_strcpy(log_len, log_buf + log_len, tag_sapce);
        }
        log_len += elog_strcpy(log_len, log_buf + log_len, " ");
    }
    /* package time, process and thread info */
    if (get_fmt_enabled(level, ELOG_FMT_TIME | ELOG_FMT_P_INFO | ELOG_FMT_T_INFO)) {
        log_len += elog_strcpy(log_len, log_buf + log_len, "[");
        /* package time info */
        if (get_fmt_enabled(level, ELOG_FMT_TIME)) {
			strncpy(slog.time, elog_port_get_time(), sizeof(slog.time) - 1);
			log_len += elog_strcpy(log_len, log_buf + log_len, slog.time);
            if (get_fmt_enabled(level, ELOG_FMT_P_INFO | ELOG_FMT_T_INFO)) {
                log_len += elog_strcpy(log_len, log_buf + log_len, " ");
            }
        }
        /* package process info */
        if (get_fmt_enabled(level, ELOG_FMT_P_INFO)) {
            log_len += elog_strcpy(log_len, log_buf + log_len, elog_port_get_p_info());
            if (get_fmt_enabled(level, ELOG_FMT_T_INFO)) {
                log_len += elog_strcpy(log_len, log_buf + log_len, " ");
            }
        }
        /* package thread info */
        if (get_fmt_enabled(level, ELOG_FMT_T_INFO)) {
            log_len += elog_strcpy(log_len, log_buf + log_len, elog_port_get_t_info());
        }
        log_len += elog_strcpy(log_len, log_buf + log_len, "] ");
    }
    /* package file directory and name, function name and line number info */
    if (get_fmt_enabled(level, ELOG_FMT_DIR | ELOG_FMT_FUNC | ELOG_FMT_LINE)) {
        log_len += elog_strcpy(log_len, log_buf + log_len, "(");
        /* package time info */
        if (get_fmt_enabled(level, ELOG_FMT_DIR)) {
            log_len += elog_strcpy(log_len, log_buf + log_len, file);
            if (get_fmt_enabled(level, ELOG_FMT_FUNC)) {
                log_len += elog_strcpy(log_len, log_buf + log_len, " ");
            } else if (get_fmt_enabled(level, ELOG_FMT_LINE)) {
                log_len += elog_strcpy(log_len, log_buf + log_len, ":");
            }
        }
        /* package process info */
        if (get_fmt_enabled(level, ELOG_FMT_FUNC)) {
            log_len += elog_strcpy(log_len, log_buf + log_len, func);
            if (get_fmt_enabled(level, ELOG_FMT_LINE)) {
                log_len += elog_strcpy(log_len, log_buf + log_len, ":");
            }
        }
        /* package thread info */
        if (get_fmt_enabled(level, ELOG_FMT_LINE)) {
            //TODO snprintf资源占用可能较高,待优化
            snprintf(line_num, ELOG_LINE_NUM_MAX_LEN, "%ld", line);
            log_len += elog_strcpy(log_len, log_buf + log_len, line_num);
        }
        log_len += elog_strcpy(log_len, log_buf + log_len, ")");
    }

    /* add space and colon sign */
    if (log_len != 0) {
        log_len += elog_strcpy(log_len, log_buf + log_len, ": ");
    }

    /* package other log data to buffer. '\0' must be added in the end by vsnprintf. */
    fmt_result = vsnprintf(log_buf + log_len, ELOG_BUF_SIZE - log_len - newline_len + 1, format, args);
	slog_len += strlen(format);
	vsnprintf(slog.lograw, sizeof(slog.lograw) - slog_len - 1, format, args);

    va_end(args);

    /* keyword filter */
    if (!strstr(log_buf, elog.filter.keyword)) {
        //TODO 可以考虑采用KMP及朴素模式匹配字符串,提升性能
        /* unlock output */
        output_unlock();
        return;
    }

    /* package newline sign */
    if ((fmt_result > -1) && (fmt_result + log_len + newline_len <= ELOG_BUF_SIZE)) {
        log_len += fmt_result;
        log_len += elog_strcpy(log_len, log_buf + log_len, ELOG_NEWLINE_SIGN);

    } else {
        /* copy newline sign */
        strcpy(log_buf - newline_len, ELOG_NEWLINE_SIGN);
    }

    /* output log */
    elog_port_output(log_buf, log_len);

    /* unlock output */
    output_unlock();
}
Exemple #5
0
int
_output_get_voices(OutputModule *module)
{
  VoiceDescription** voice_dscr;
  GString *reply;
  gchar **lines;
  gchar **atoms;
  int i;
  int ret = 0;
  gboolean errors = FALSE;

  output_lock();

  if (module == NULL){
    MSG(1, "ERROR: Can't list voices for broken output module");
    OL_RET(-1);
  }
  output_send_data("LIST VOICES\n", module, 0);
  reply = output_read_reply(module);

  if (reply == NULL){
      output_unlock();
      voice_dscr = NULL;
      return -1;
  }

  //TODO: only 256 voices supported here
  lines = g_strsplit(reply->str, "\n", 256);
  g_string_free(reply, TRUE);
  voice_dscr = malloc(256*sizeof(VoiceDescription*));
  for (i = 0; !errors && (lines[i] != NULL); i++) {
    MSG(1, "LINE here:|%s|", lines[i]);
    if (strlen(lines[i])<=4){
      MSG(1, "ERROR: Bad communication from driver in synth_voices");
      ret = -1;
      errors = TRUE;
    }
    else if (lines[i][3] == ' ')
      break;
    else if (lines[i][3] == '-'){
      atoms = g_strsplit(&lines[i][4]," ", 0);
      // Name, language, dialect
      if ((atoms[0] == NULL) || (atoms[1] == NULL) || (atoms[2] == NULL)){
	ret = -1;
      errors = TRUE;
      } else {
        //Fill in VoiceDescription
        voice_dscr[i] = (VoiceDescription*) malloc(sizeof(VoiceDescription));
        voice_dscr[i]->name=strdup(atoms[0]);
        voice_dscr[i]->language=strdup(atoms[1]);
        voice_dscr[i]->dialect=strdup(atoms[2]);
      }
    if (atoms != NULL)
      g_strfreev(atoms);
    }
    /* Should we do something in a final "else" branch? */

  }
  voice_dscr[i] = NULL;
  g_strfreev(lines);

  module->voices=voice_dscr;

  output_unlock();
  return ret;
}