Ejemplo n.º 1
0
void _marpaXmlLog_defaultCallback(void *userDatavp, marpaXmlLogLevel_t logLeveli, const char *msgs) {
  /* We are NOT going to do a general log4c mechanism (this can come later), using marpaXml in fact */
  /* I.e. we are fixing the default output to be: DD/MM/YYYY hh::mm::ss PREFIX MESSAGE */
  const char   *prefixs =
    (logLeveli == MARPAXML_LOGLEVEL_TRACE    ) ? "TRACE"     :
    (logLeveli == MARPAXML_LOGLEVEL_DEBUG    ) ? "DEBUG"     :
    (logLeveli == MARPAXML_LOGLEVEL_INFO     ) ? "INFO"      :
    (logLeveli == MARPAXML_LOGLEVEL_NOTICE   ) ? "NOTICE"    :
    (logLeveli == MARPAXML_LOGLEVEL_WARNING  ) ? "WARNING"   :
    (logLeveli == MARPAXML_LOGLEVEL_ERROR    ) ? "ERROR"     :
    (logLeveli == MARPAXML_LOGLEVEL_CRITICAL ) ? "CRITICAL"  :
    (logLeveli == MARPAXML_LOGLEVEL_ALERT    ) ? "ALERT"     :
    (logLeveli == MARPAXML_LOGLEVEL_EMERGENCY) ? "EMERGENCY" :
    "UNKOWN";
  char   *dates = dateBuilder("%d/%m/%Y %H:%M:%S");
  char   *localMsgs = messageBuilder("%s %9s %s\n", dates, prefixs, (msgs != NULL) ? (char *) msgs : (char *) MARPAXML_LOG_NO_MESSAGE);
#if (defined(_WIN32) || (_POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE))
#ifdef _WIN32
  int filenoStderr = _fileno(stderr);
  size_t bytesWriten = 0;
#else
  int filenoStderr = fileno(stderr);
  ssize_t bytesWriten = 0;
#endif
  char *p = localMsgs;
  size_t  count;
#endif

#if (defined(_WIN32) || (_POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE))
  count = strlen(p);
  while (bytesWriten < count) {
#if defined(_WIN32)
    bytesWriten += _write(filenoStderr, p+bytesWriten, count-bytesWriten);
#else
    bytesWriten += write(filenoStderr, p+bytesWriten, count-bytesWriten);
#endif
  }
#else
  /* Note: this is not asynchroneous safe */
  fprintf(stderr, "%s", p);
#endif

  if (dates != dateBuilder_internalErrors()) {
    free(dates);
  }
  if (localMsgs != messageBuilder_internalErrors()) {
    free(localMsgs);
  }
}
Ejemplo n.º 2
0
MARPAWRAPPER_EXPORT void _genericLogger_defaultCallback(const void *userDatavp, const genericLoggerLevel_t leveli, const char *msgs) {
  /* We are NOT going to do a general log4c mechanism (this can come later) */
  /* I.e. we are fixing the default output to be: DD/MM/YYYY hh::mm::ss PREFIX MESSAGE */
  const char *prefixs =
    (leveli == GENERICLOGGER_LOGLEVEL_TRACE    ) ? "TRACE"     :
    (leveli == GENERICLOGGER_LOGLEVEL_DEBUG    ) ? "DEBUG"     :
    (leveli == GENERICLOGGER_LOGLEVEL_INFO     ) ? "INFO"      :
    (leveli == GENERICLOGGER_LOGLEVEL_NOTICE   ) ? "NOTICE"    :
    (leveli == GENERICLOGGER_LOGLEVEL_WARNING  ) ? "WARNING"   :
    (leveli == GENERICLOGGER_LOGLEVEL_ERROR    ) ? "ERROR"     :
    (leveli == GENERICLOGGER_LOGLEVEL_CRITICAL ) ? "CRITICAL"  :
    (leveli == GENERICLOGGER_LOGLEVEL_ALERT    ) ? "ALERT"     :
    (leveli == GENERICLOGGER_LOGLEVEL_EMERGENCY) ? "EMERGENCY" :
    "UNKOWN";
  char *dates = dateBuilder("%d/%m/%Y %H:%M:%S");
  char *localMsgs = messageBuilder("%s %9s %s\n", dates, prefixs, (msgs != NULL) ? (char *) msgs : (char *) GENERICLOGGER_LOG_NO_MESSAGE);
  char *p = localMsgs;
#ifdef FILENO
  int filenoStderr = FILENO(stderr);
#ifdef SYS_FILENO_IS_FILENO
  ssize_t bytesWriten = 0;
#else
  size_t bytesWriten = 0;
#endif
  size_t  count;
#endif

#ifdef FILENO
  count = strlen(p);
  while (bytesWriten < count) {
    bytesWriten += SYS_WRITE(filenoStderr, p+bytesWriten, count-bytesWriten);
  }
#else
  /* Note: this is not asynchroneous safe */
  fprintf(stderr, "%s", p);
#endif

  if (dates != dateBuilder_internalErrors()) {
    free(dates);
  }
  if (localMsgs != messageBuilder_internalErrors()) {
    free(localMsgs);
  }
}
Ejemplo n.º 3
0
void HostLocator::tryLocate()
{
  if ( ticker.isItTime() )
  {
    MessageBuilder messageBuilder(lemmaId);
    udp.broadcast(messageBuilder.buildMarco(roomName));
  }

  if(udp.attemptRead())
  {
    Polo* polo = MessageParser::parsePolo(udp.message);
    if (polo)
    {
      found = true;
      strncpy(hostIpAddress, udp.lastAddress(), 24);
      hostPort = polo->port;
      delete polo;
    }
  }
}
Ejemplo n.º 4
0
static marpaWrapperBool_t myValueRuleCallback(const marpaWrapperUserData_t    *marpaWrapperUserDatap,
					      const marpaWrapperRecognizer_t  *marpaWrapperRecognizerp,
					      const marpaWrapperRule_t        *marpaWrapperRulep,
					      const size_t                     nValuepInputi,
					      const marpaWrapperValuepArrayp_t valuepArrayInputp,
					      marpaWrapperValuep_t            *valuepOutputp) {
  int rulei;
  myStack_t *outputp = malloc(sizeof(myStack_t));
  myStack_t **stackpp = (myStack_t **) valuepArrayInputp;

  if (outputp == NULL) {
    return MARPAWRAPPER_BOOL_FALSE;
  }

  rulei = (int) marpaWrapperRule_datavp_get(marpaWrapperRulep);

  switch (rulei) {
  case START_RULE:
    /* S ::= E */
    outputp->string = messageBuilder("%s == %d", stackpp[0]->string, stackpp[0]->value);
    if (outputp->string == messageBuilder_internalErrors()) {
      free(outputp);
      return MARPAWRAPPER_BOOL_FALSE;
    }
    outputp->value = stackpp[0]->value;
    break;

  case NUMBER_RULE:
    /* E ::= number */
    outputp->string = messageBuilder("%d", stackpp[0]->value);
    if (outputp->string == messageBuilder_internalErrors()) {
      free(outputp);
      return MARPAWRAPPER_BOOL_FALSE;
    }
    outputp->value = stackpp[0]->value;
    break;

  case OP_RULE:
    /* E ::= E op E */
    outputp->string = messageBuilder("(%s%s%s)", stackpp[0]->string, stackpp[1]->string, stackpp[2]->string);
    if (outputp->string == messageBuilder_internalErrors()) {
      free(outputp);
      return MARPAWRAPPER_BOOL_FALSE;
    }
    switch (stackpp[1]->string[0]) {
    case '+':
      outputp->value = stackpp[0]->value + stackpp[2]->value;
      break;
    case '-':
      outputp->value = stackpp[0]->value - stackpp[2]->value;
      break;
    case '*':
      outputp->value = stackpp[0]->value * stackpp[2]->value;
      break;
    default:
      free(outputp);
      return MARPAWRAPPER_BOOL_FALSE;
    }
    break;

  default:
    free(outputp);
    return MARPAWRAPPER_BOOL_FALSE;
  }

  *valuepOutputp = outputp;

  return MARPAWRAPPER_BOOL_TRUE;
}