示例#1
0
int file_validate_buffer(char  *buf, unsigned int len, size_t offset)
{
  unsigned int checksum;
  unsigned int cs_offset;

  cs_offset = len - (FILE_CHECKSUM_LENGTH + FILE_OFFSET_LENGTH);
  
  checksum = (unsigned int)crc32(0, buf, cs_offset);

  if (checksum != *(unsigned int *)(buf + cs_offset))
  {
    log_text(LOG_FATAL, "Checksum mismatch in block: ", offset);
    log_text(LOG_FATAL, "    Calculated value: 0x%x    Stored value: 0x%x",
             checksum, *(unsigned int *)(buf + cs_offset));
    return 1;
  }

  if (offset != *(size_t *)(buf + cs_offset + FILE_CHECKSUM_LENGTH))
  {
    log_text(LOG_FATAL, "Offset mismatch in block:");
    log_text(LOG_FATAL, "   Actual offset: %ld    Stored offset: %ld",
             offset, *(size_t *)(buf + cs_offset + FILE_CHECKSUM_LENGTH));
    return 1;
  }

  return 0;
}
示例#2
0
int file_wait(int thread_id, long nreq)
{ 
  long            i;
  long            nr;
  struct io_event *event;
  sb_aio_oper_t   *oper;
  struct iocb     *iocbp;

  /* Try to read some events */
#ifdef HAVE_OLD_GETEVENTS
  (void)nreq; /* unused */
  nr = io_getevents(aio_ctxts[thread_id].io_ctxt, file_async_backlog,
                    aio_ctxts[thread_id].events, NULL);
#else
  nr = io_getevents(aio_ctxts[thread_id].io_ctxt, nreq, file_async_backlog,
                    aio_ctxts[thread_id].events, NULL);
#endif
  if (nr < 1)
  {
    log_errno(LOG_FATAL, "io_getevents() failed!");
    return 1;
  }

  /* Verify results */
  for (i = 0; i < nr; i++)
  {
    event = (struct io_event *)aio_ctxts[thread_id].events + i;
    iocbp = (struct iocb *)(unsigned long)event->obj;
    oper = (sb_aio_oper_t *)iocbp;
    switch (oper->type) {
      case FILE_OP_TYPE_FSYNC:
        if (event->res != 0)
        {
          log_text(LOG_FATAL, "Asynchronous fsync failed!\n");
          return 1;
        }
        break;
      case FILE_OP_TYPE_READ:
        if ((ssize_t)event->res != oper->len)
        {
          log_text(LOG_FATAL, "Asynchronous read failed!\n");
          return 1;
        }
        break;
      case FILE_OP_TYPE_WRITE:
        if ((ssize_t)event->res != oper->len)
        {
          log_text(LOG_FATAL, "Asynchronous write failed!\n");
          return 1;
        }
        break;
      default:
        break;
    }
    free(oper);
    aio_ctxts[thread_id].nrequests--;
  }
  
  return 0;
}
示例#3
0
static void dump_config_string(
	PConfigRef config)
{
	struct endpoint_data *endpoint_data;

	endpoint_data= get_current_endpoint_data();
	if (endpoint_data && endpoint_data->endpoint)
	{
		NMErr err;
		char default_config_string[1024];
	
		/* Echo the default config string. */
		err= ProtocolGetConfigString(config, default_config_string, sizeof(default_config_string));
		if (!err)
		{
			short function_length;
			
			log_text("Created endpoint has configuration: **%s**", default_config_string);
			err= ProtocolGetConfigStringLen(config, &function_length);
			if (!err)
			{
				log_text("Actual Length: %d", strlen(default_config_string));
				log_text("ProtocolGetConfigStringLen: %d",function_length);
			} else {
				log_text("Err: %d in ProtocolGetConfigStringLen", err);
			}
		} else {
			log_text("Err %d on ProtocolGetConfigString", err);
		}
	}
	
	return;
}
示例#4
0
unsigned long long sb_timer_split_tmc(sb_timer_t *t)
{
  struct timespec    tmp;
  unsigned long long res;

  switch (t->state) {
    case TIMER_INITIALIZED:
      log_text(LOG_WARNING, "timer was never started");
      return 0;
    case TIMER_STOPPED:
      res = TIMESPEC_DIFF(t->time_end, t->time_split);
      t->time_split = t->time_end;
      if (res)
        return res;
      else
      {
        log_text(LOG_WARNING, "timer was already stopped");
        return 0;
      }
    case TIMER_RUNNING:
      break;
    default:
      log_text(LOG_FATAL, "uninitialized timer queried");
      abort();
  }

  SB_GETTIME(&tmp);
  t->elapsed = TIMESPEC_DIFF(tmp, t->time_start);
  res = TIMESPEC_DIFF(tmp, t->time_split);

  return res;
}
示例#5
0
void sb_timer_stop(sb_timer_t *t)
{
  switch (t->state) {
    case TIMER_INITIALIZED:
      log_text(LOG_WARNING, "timer was never started");
      break;
    case TIMER_STOPPED:
      log_text(LOG_WARNING, "timer was already stopped");
      break;
    case TIMER_RUNNING:
      break;
    default:
      log_text(LOG_FATAL, "uninitialized timer stopped");
      abort();
  }

  sb_timer_update(t);
  t->events++;
  t->sum_time += t->elapsed;
  if (t->elapsed < t->min_time)
    t->min_time = t->elapsed;
  if (t->elapsed > t->max_time)
    t->max_time = t->elapsed;

  t->state = TIMER_STOPPED;
}
示例#6
0
static int sql_init(dbref player) {
  MYSQL *result;
  
  /* If we are already connected, drop and retry the connection, in
   * case for some reason the server went away.
   */
  
  if (mysql_struct)
    sql_shutdown(player);
  
  /* Try to connect to the database host. If we have specified
   * localhost, use the Unix domain socket instead.
   */
  
  mysql_init(mysql_struct);
  
  result = mysql_real_connect(mysql_struct, DB_HOST, DB_USER, DB_PASS, DB_BASE,
 			      3306, DB_SOCKET, 0);
  
  if (!result) {
    STARTLOG(LOG_PROBLEMS, "SQL", "ERR");
    log_text(unsafe_tprintf("DB connect by %s : ", player < 0 ? "SYSTEM" : Name(player)));
    log_text("Failed to connect to SQL database.");
    ENDLOG
    return -1;
  } else {
示例#7
0
int mysql_drv_prepare(db_stmt_t *stmt, const char *query)
{
#ifdef HAVE_PS
  MYSQL      *con = (MYSQL *)stmt->connection->ptr;
  MYSQL_STMT *mystmt;
  unsigned int rc;

  if (con == NULL)
    return 1;

  if (use_ps)
  {
    mystmt = mysql_stmt_init(con);
    DEBUG("mysql_stmt_init(%p) = %p", con, mystmt);
    if (mystmt == NULL)
    {
      log_text(LOG_FATAL, "mysql_stmt_init() failed");
      return 1;
    }
    stmt->ptr = (void *)mystmt;
    DEBUG("mysql_stmt_prepare(%p, \"%s\", %d) = %p", mystmt, query, strlen(query), stmt->ptr);
    if (mysql_stmt_prepare(mystmt, query, strlen(query)))
    {
      /* Check if this statement in not supported */
      rc = mysql_errno(con);
      DEBUG("mysql_errno(%p) = %u", con, rc);
      if (rc == ER_UNSUPPORTED_PS)
      {
        log_text(LOG_DEBUG,
                 "Failed to prepare query \"%s\", using emulation",
                 query);
        goto emulate;
      }
      else
      {
        log_text(LOG_FATAL, "mysql_stmt_prepare() failed");
        log_text(LOG_FATAL, "MySQL error: %d \"%s\"", rc,
                 mysql_error(con));
        DEBUG("mysql_stmt_close(%p)", mystmt);
        mysql_stmt_close(mystmt);
        return 1;
      }
    }

    return 0;
  }

 emulate:
#endif /* HAVE_PS */

  /* Use client-side PS */
  stmt->emulated = 1;
  stmt->query = strdup(query);

  return 0;
}
示例#8
0
static void time_greyscale(void)
{
    char str[32];     /* text buffer */
    long time_start;  /* start tickcount */
    long time_end;    /* end tickcount */
    long time_1, time_2;
    int frames_1, frames_2;
    int fps, load;

    gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
    if (!grey_init(gbuf, gbuf_size, GREY_ON_COP,
                   LCD_WIDTH, LCD_HEIGHT, NULL))
    {
        log_text("greylib: out of memory.");
        return;
    }
    make_grey_rect(LCD_WIDTH, LCD_HEIGHT);

    /* Test 1 - greyscale overlay not yet enabled */
    frames_1 = 0;
    rb->sleep(0); /* sync to tick */
    time_start = *rb->current_tick;
    while((time_end = *rb->current_tick) - time_start < DURATION)
    {
        grey_ub_gray_bitmap(greydata[0], 0, 0, LCD_WIDTH, LCD_HEIGHT);
        frames_1++;
    }
    time_1 = time_end - time_start;
    
    /* Test 2 - greyscale overlay enabled */
    grey_show(true);
    frames_2 = 0;
    rb->sleep(0); /* sync to tick */
    time_start = *rb->current_tick;
    while((time_end = *rb->current_tick) - time_start < DURATION)
    {
        grey_ub_gray_bitmap(greydata[0], 0, 0, LCD_WIDTH, LCD_HEIGHT);
        frames_2++;
    }
    time_2 = time_end - time_start;

    grey_release();
    fps = calc_tenth_fps(frames_2, time_2);
    load = 100 - (100 * frames_2 * time_1) / (frames_1 * time_2);
    rb->snprintf(str, sizeof(str), "1/1: %d.%d fps", fps / 10, fps % 10);
    log_text(str);

    if (load > 0 && load < 100)
    {
        rb->snprintf(str, sizeof(str), "CPU load: %d%%", load);
        log_text(str);
    }
    else
        log_text("CPU load err (boost?)");
}
示例#9
0
int mysql_drv_init(void)
{
  char *s;
  
  args.hosts = sb_get_value_list("mysql-host");
  if (SB_LIST_IS_EMPTY(args.hosts))
  {
    log_text(LOG_FATAL, "No MySQL hosts specified, aborting");
    return 1;
  }
  hosts_pos = args.hosts;
  pthread_mutex_init(&hosts_mutex, NULL);
  
  args.port = sb_get_value_int("mysql-port");
  args.socket = sb_get_value_string("mysql-socket");
  args.user = sb_get_value_string("mysql-user");
  args.password = sb_get_value_string("mysql-password");
  args.db = sb_get_value_string("mysql-db");
  args.myisam_max_rows = sb_get_value_int("myisam-max-rows");
  args.use_ssl = sb_get_value_flag("mysql-ssl");
  args.create_options = sb_get_value_string("mysql-create-options");
  if (args.create_options == NULL)
    args.create_options = "";
  
  use_ps = 0;
#ifdef HAVE_PS
  mysql_drv_caps.prepared_statements = 1;
  if (db_globals.ps_mode != DB_PS_MODE_DISABLE)
    use_ps = 1;
#endif

  s = sb_get_value_string("mysql-engine-trx");
  if (s == NULL)
  {
    log_text(LOG_FATAL, "--mysql-engine-trx requires an argument");
    return 1;
  }
  if (!strcasecmp(s, "yes"))
    args.engine_trx = ENGINE_TRX_YES;
  else if (!strcasecmp(s, "no"))
    args.engine_trx = ENGINE_TRX_NO;
  else if (!strcasecmp(s, "auto"))
    args.engine_trx = ENGINE_TRX_AUTO;
  else
  {
    log_text(LOG_FATAL, "Invalid value for mysql-engine-trx: %s", s);
    return 1;
  }
  
  s = sb_get_value_string("mysql-table-engine");

  mysql_library_init(0, NULL, NULL);
  
  return parse_table_engine(s);
}
示例#10
0
static char* get_line(const char* prompt, char* buf, int size)
{
#ifdef WIN32
	int n,c;

	//fflush(stdin);

	MSG_OUT("%s", prompt);


	for(n = 0; n < size-1; n++)
	{
		c = getchar();
		if(c == EOF)
		{
			if(n == 0)
				return NULL;
			break;
		}
		else if(c=='\n')
		{
			break;
		}
		else
		{
			buf[n] = (char)c;
		}
	}
	buf[n] = 0;

#elif defined(LINUX)
	char    utf8[1024];
	char*   sl;


	A2UTF8( prompt, utf8, sizeof(utf8));

	log_text(utf8);
	sl = readline(utf8);

	if(strlen(sl) > 0)
		add_history(sl);

	strncpy(buf, sl, size);

	free(sl);

#endif

	log_text("%s\n", buf);

	return buf;
}
示例#11
0
int parse_table_engine(const char *type)
{
  /* Determine if the engine supports transactions */
  if (args.engine_trx == ENGINE_TRX_AUTO)
  {
    if (!strcasecmp(type, "myisam") || !strcasecmp(type, "heap") ||
        !strcasecmp(type, "maria"))
      mysql_drv_caps.transactions = 0;
    else if (!strcasecmp(type, "innodb") ||
             !strcasecmp(type, "bdb") || !strcasecmp(type, "berkeleydb") ||
             !strcasecmp(type, "ndbcluster") ||
             !strcasecmp(type, "federated") ||
             !strcasecmp(type, "pbxt") ||
             !strcasecmp(type, "falcon"))
      mysql_drv_caps.transactions = 1;
    else
    {
      log_text(LOG_FATAL, "Failed to determine transactions support for "
               "unknown storage engine '%s'", type);
      log_text(LOG_FATAL, "Specify explicitly with --mysql-engine-trx option");
      return 1;
    }
  }
  else
    mysql_drv_caps.transactions = (args.engine_trx == ENGINE_TRX_YES);

  /* Get engine-specific options string */
  if (!strcasecmp(type, "myisam"))
  {
    if (args.myisam_max_rows > 0)
      snprintf(table_options_str, sizeof(table_options_str),
               "%s /*! "ENGINE_CLAUSE"=MyISAM MAX_ROWS=%u */",
               args.create_options,
               args.myisam_max_rows);
    else
      snprintf(table_options_str, sizeof(table_options_str),
               "%s /*! "ENGINE_CLAUSE"=MyISAM */", args.create_options);
  }
  else if (!strcasecmp(type, "bdb") || !strcasecmp(type, "berkeleydb"))
    snprintf(table_options_str, sizeof(table_options_str),
             "%s /*! "ENGINE_CLAUSE"=BerkeleyDB */", args.create_options);
  else if (!strcasecmp(type, "ndbcluster"))
    snprintf(table_options_str, sizeof(table_options_str),
             "%s /*! "ENGINE_CLAUSE"=NDB */", args.create_options);
  else
    snprintf(table_options_str, sizeof(table_options_str),
             "%s /*! "ENGINE_CLAUSE"=%s */", args.create_options, type);

  mysql_drv_caps.table_options_str = table_options_str;
  
  return 0;
}
示例#12
0
void memory_print_stats(void)
{
  double total_time;

  total_time = NS2SEC(sb_timer_value(&sb_globals.exec_timer));
  
  log_text(LOG_NOTICE, "Operations performed: %d (%8.2f ops/sec)\n", total_ops,
           total_ops / total_time);
  if (memory_oper != SB_MEM_OP_NONE)
    log_text(LOG_NOTICE, "%4.2f MB transferred (%4.2f MB/sec)\n",
             (double)total_bytes / (1024 * 1024),
             (double)total_bytes / (1024 * 1024) / total_time);
}
示例#13
0
int create_files(void)
{
  unsigned int       i;
  int                fd;
  char               file_name[512];
  long long          offset;

  log_text(LOG_INFO, "%d files, %ldKb each, %ldMb total", num_files,
           (long)(file_size / 1024),
           (long)((file_size * num_files) / (1024 * 1024)));
  log_text(LOG_INFO, "Creating files for the test...");
  for (i=0; i < num_files; i++) {
    snprintf(file_name, sizeof(file_name), "test_file.%d",i);
    unlink(file_name);

    fd = open(file_name, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
    if (fd < 0)
    {
      log_errno(LOG_FATAL, "Can't open file");
      return 1; 
    }

    for (offset = 0; offset < file_size; offset += file_block_size)
    {
      /* If in validation mode, fill buffer with random values
         and write checksum
      */
      if (sb_globals.validate)
        file_fill_buffer(buffer, file_block_size, offset);
                         
      if (write(fd, buffer, file_block_size) < 0)
        goto error;
    }
    
    /* fsync files to prevent cache flush from affecting test results */
#ifndef _WIN32
    fsync(fd);
#else
    _commit(fd);
#endif
    close(fd);
  }
  return 0; 

 error:
  log_errno(LOG_FATAL, "Failed to write file!");
  close(fd);
  return 1;
}
示例#14
0
文件: test_fps.c 项目: 4nykey/rockbox
static void time_main_yuv(void)
{
    char str[32];     /* text buffer */
    long time_start;  /* start tickcount */
    long time_end;    /* end tickcount */
    int frame_count;
    int fps;

    const int part14_x = YUV_WIDTH/4;   /* x-offset for 1/4 update test */
    const int part14_w = YUV_WIDTH/2;   /* x-size for 1/4 update test */
    const int part14_y = YUV_HEIGHT/4;  /* y-offset for 1/4 update test */
    const int part14_h = YUV_HEIGHT/2;  /* y-size for 1/4 update test */
    
    log_text("Main LCD YUV");

    rb->memset(ydata, 128, sizeof(ydata)); /* medium grey */

    /* Test 1: full LCD update */
    make_gradient_rect(YUV_WIDTH, YUV_HEIGHT);

    frame_count = 0;
    rb->sleep(0); /* sync to tick */
    time_start = *rb->current_tick;
    while((time_end = *rb->current_tick) - time_start < DURATION)
    {
        rb->lcd_blit_yuv(yuvbuf, 0, 0, YUV_WIDTH,
                         0, 0, YUV_WIDTH, YUV_HEIGHT);
        frame_count++;
    }
    fps = calc_tenth_fps(frame_count, time_end - time_start);
    rb->snprintf(str, sizeof(str), "1/1: %d.%d fps", fps / 10, fps % 10);
    log_text(str);

    /* Test 2: quarter LCD update */
    make_gradient_rect(YUV_WIDTH/2, YUV_HEIGHT/2);

    frame_count = 0;
    rb->sleep(0); /* sync to tick */
    time_start = *rb->current_tick;
    while((time_end = *rb->current_tick) - time_start < DURATION)
    {
        rb->lcd_blit_yuv(yuvbuf, 0, 0, YUV_WIDTH,
                         part14_x, part14_y, part14_w, part14_h);
        frame_count++;
    }
    fps = calc_tenth_fps(frame_count, time_end - time_start);
    rb->snprintf(str, sizeof(str), "1/4: %d.%d fps", fps / 10, fps % 10);
    log_text(str);
}
示例#15
0
void *sb_memalign(size_t size)
{
  unsigned long page_size;
  void *buffer;
  
#ifdef HAVE_POSIX_MEMALIGN
  page_size = sb_getpagesize();
  posix_memalign((void **)&buffer, page_size, size);
#elif defined(HAVE_MEMALIGN)
  page_size = sb_getpagesize();
  buffer = memalign(page_size, size);
#elif defined(HAVE_VALLOC)
  (void)page_size; /* unused */
  buffer = valloc(size);
#elif defined (_WIN32)
  (void)page_size; /* unused */
  buffer = VirtualAlloc(NULL, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
#else
  (void)page_size; /* unused */
  log_text(LOG_WARNING, "None of valloc(), memalign and posix_memalign() is available, doing unaligned IO!");
  buffer = malloc(size);
#endif

  return buffer;
}
示例#16
0
	bool GLShader::ValidateCompile(GLuint shader)
	{
		GLint compiled;
		glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
		if (!compiled) {
			GLsizei length;
			glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length);

			/*output shader log info*/
			GLchar* log = new GLchar[length + 1];
			glGetShaderInfoLog(shader, length, &length, log);
#ifdef UNICODE
			std::string log_text(log);
			UConverter converter;
			UString log_string = converter.from_bytes(log_text);
			DebugPrintF(log_string.c_str());
			std::cout << log << std::endl;
#else
			DebugPrintF(VTEXT("Shader Log: %s\n"),
				    log);
#endif
			delete[] log;

			return false;
		}


		return true;
	}
示例#17
0
void log_text(const char* fmt, ...)
{
	static char path [MAX_PATH];
	static int  init = 0;
	static int  sz;
	FILE* f;
	va_list vl;

	if(init == 0)
	{
		time_t  t = time(NULL);
		get_app_path(path, sizeof(path));
		sz = strlen(path);
		sz+=snprintf(path+sz, sizeof(path)-sz, "/../log");
		mkdir(path, 0755);
		struct tm*  lt = localtime(&t);
		sz+=snprintf(path+sz, sizeof(path)-sz, "/logic_%04d%02d%02d_%02d%02d%02d.log", 
			lt->tm_year+1900,lt->tm_mon+1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec);
		init = 1;

		log_text("=========================== LOG START  ======================\n%s", ctime(&t));
	}

	f = fopen(path, "a+");

	if(f)
	{
		va_start(vl, fmt);
		vfprintf(f, fmt, vl);
		va_end(vl);

		fclose(f);
	}
}
示例#18
0
static void voice_handle_touchtone_dle(int byte)
{
	switch (byte)
	{
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
		case '*':
		case '#':
		case 'A':
		case 'B':
		case 'C':
		case 'D':
			voice_handle_touchtone(byte);
			break;

		default:
			log_line(L_ERROR, "Illeagal \"<DLE>\" shielded code \"");
			log_char(L_ERROR, byte);
			log_text(L_ERROR, "\" (ignored)...\n");
			break;
	}
}
示例#19
0
int file_submit_or_wait(struct iocb *iocb, sb_file_op_t type, ssize_t len,
                        int thread_id)
{
  sb_aio_oper_t   *oper;
  struct iocb     *iocbp;

  oper = (sb_aio_oper_t *)malloc(sizeof(sb_aio_oper_t));
  if (oper == NULL)
  {
    log_text(LOG_FATAL, "Failed to allocate AIO operation!");
    return 1;
  }

  memcpy(&oper->iocb, iocb, sizeof(*iocb));
  oper->type = type;
  oper->len = len;
  iocbp = &oper->iocb;

  if (io_submit(aio_ctxts[thread_id].io_ctxt, 1, &iocbp) < 1)
  {
    log_errno(LOG_FATAL, "io_submit() failed!");
    return 1;
  }
  
  aio_ctxts[thread_id].nrequests++;
  if (aio_ctxts[thread_id].nrequests < file_async_backlog)
    return 0;
  
  return file_wait(thread_id, 1);
}
示例#20
0
文件: cmd.cpp 项目: voidpaper/sgs2010
void cmd_output(const char* fmt, ...)
{
	char text[4096];
	char utf8[4096*2];


	va_list vl;
	size_t sz;

	va_start(vl, fmt);
	sz = vsnprintf(text, sizeof(text), fmt, vl);
	va_end(vl);

	if(is_test_mode() && s_test_input == 0)
	{
		if(sz + s_out_len >= sizeof(s_out_messages))
		{
			sz = sizeof(s_out_messages)/sizeof(s_out_messages[0]) - s_out_len - 1;
		}
		memcpy(s_out_messages + s_out_len, text, sz);
		s_out_len += sz;
		s_out_messages[s_out_len] = 0;
	}	

	A2UTF8(text, utf8, sizeof(utf8));

	log_text("%s", utf8);

	printf("%s", utf8);
}
void hs_log(char *str)
{
  time_t  tt;
  struct tm *ttm;
  char    timebuf[256];
  char    tbuf[512];

#ifdef TM3
  char    *text, *newstr;

  /* We make a lot of modifications in this one function, so we don't have
   * to change all of the hs_log calls. Otherwise, future mainline patches
   * would be harder to apply.
   */

  newstr = strdup(str);
  text = strchr(newstr, ':');
  if (text) {
  	*text = '\0';

	/* Skip over the colon and space */
	text += 2;

	STARTLOG(LOG_ALWAYS, "HSPACE", newstr)
		log_text(text);
	ENDLOG 
  } else {
示例#22
0
void QFExtensionB040SPADMeasurement::connectMeasurementDevice(unsigned int measuremenDevice)
{
    if ( measuremenDevice>=getMeasurementDeviceCount()) return;
    QFSerialConnection* com=ports.getCOMPort(devices[measuremenDevice].port);
    if (!com) return;
    QMutex* mutex=ports.getMutex(devices[measuremenDevice].port);
    QMutexLocker locker(mutex);
    com->open();
    if (com->isConnectionOpen()) {
        QTime t;
        t.start();
        // wait CONNECTION_DELAY_MS ms for connection!
        while (t.elapsed()<CONNECTION_DELAY_MS)  {
            QApplication::processEvents();
        }
        devices[measuremenDevice].infoMessage=devices[measuremenDevice].serial->queryCommand("?");
        //qDebug()<<"infoMessage '"<<infoMessage<<"'";
        if (!(devices[measuremenDevice].infoMessage.toLower().contains("spadarray controller") && devices[measuremenDevice].infoMessage.toLower().contains("jan krieger"))) {
            com->close();
            log_error(tr("%1 Could not connect to SPADArray Controller [port=%1  baud=%2]!!!\n").arg(com->get_port().c_str()).arg(com->get_baudrate()));
            log_error(tr("%1 reason: received wrong ID string from SPADArray Controller: string was '%2'\n").arg(LOG_PREFIX).arg(devices[measuremenDevice].infoMessage));
        } else {
            log_text(tr("%1 Connected to SPADArray Controller [port=%2  baud=%3] \n%1 welcome message:'%4'\n").arg(LOG_PREFIX).arg(com->get_port().c_str()).arg(com->get_baudrate()).arg(devices[measuremenDevice].infoMessage));
        }
    } else {
        log_error(tr("%1 Could not connect to SPADArray Controller [port=%1  baud=%2]!!!\n").arg(com->get_port().c_str()).arg(com->get_baudrate()));
        log_error(tr("%1 reason: %2\n").arg(LOG_PREFIX).arg(devices[measuremenDevice].serial->getLastError()));
    }
}
示例#23
0
static void MainL()
{
  log_clear(PRIMARY_LOG_FILENAME);
  log_text(PRIMARY_LOG_FILENAME, "initializing");
  logg("value is %d", 555);
  log_ctx(PRIMARY_LOG_FILENAME, "context test");

  // Note that if our program does not run for at least five seconds
  // or so, the S60 auto launch mechanism will consider that an error,
  // and this may result in some error dialog popping up. We use
  // WaitWhile() to avoid that sort of thing where an intrusive error
  // report is not called for. Calling WaitWhile will hopefully also
  // ensure that the system is somewhat up and running even right after
  // boot, so that there are no problems with querying the installed
  // apps information or anything like that.
  WaitWhile();

  RFs fs;
  User::LeaveIfError(fs.Connect());
  CleanupClosePushL(fs);

  TBool magicFileExists = MagicFileExists(fs);
  if (!magicFileExists) {
    TBool isAppInstalled = IsAppInstalledL();
    if (isAppInstalled) {
      MainLoopL();
    } else {
      logt("program to launch not installed");
    }
  } else {
    logt("magic file exists");
  }

  CleanupStack::PopAndDestroy(); // fs
}
示例#24
0
int attachsql_drv_fetch_row(db_result_set_t *rs, db_row_t *row)
{
  attachsql_error_t *error= NULL;
  attachsql_return_t aret= ATTACHSQL_RETURN_NONE;

  /* NYI */

  attachsql_connect_t *con = rs->connection->ptr;

  while((aret != ATTACHSQL_RETURN_EOF) && (aret != ATTACHSQL_RETURN_ROW_READY))
  {
    aret= attachsql_connect_poll(con, &error);

    if (error)
    {
      log_text(LOG_ALERT, "libAttachSQL Query Failed: %u:%s", attachsql_error_code(error), attachsql_error_message(error));
      attachsql_error_free(error);
      return 1;
    }
  }
  if (aret == ATTACHSQL_RETURN_EOF)
  {
    return 1;
  }
  row->ptr= attachsql_query_row_get(con, NULL);
  attachsql_query_row_next(con);

  return 0;
}
示例#25
0
int file_async_init(void)
{
  unsigned int i;

  if (file_io_mode != FILE_IO_MODE_ASYNC)
    return 0;
  
  file_async_backlog = sb_get_value_int("file-async-backlog");
  if (file_async_backlog <= 0) {
    log_text(LOG_FATAL, "Invalid value of file-async-backlog: %d",
             file_async_backlog);
    return 1;
  }

  aio_ctxts = (sb_aio_context_t *)calloc(sb_globals.num_threads,
                                         sizeof(sb_aio_context_t));
  for (i = 0; i < sb_globals.num_threads; i++)
  {
    if (io_queue_init(file_async_backlog, &aio_ctxts[i].io_ctxt))
    {
      log_errno(LOG_FATAL, "io_queue_init() failed!");
      return 1;
    }
      
    aio_ctxts[i].events = (struct io_event *)malloc(file_async_backlog *
                                                    sizeof(struct io_event));
    if (aio_ctxts[i].events == NULL)
    {
      log_errno(LOG_FATAL, "Failed to allocate async I/O context!");
      return 1;
    }
  }

  return 0;
}
示例#26
0
/* plugin entry point */
enum plugin_status plugin_start(const void* parameter)
{
#ifndef SIMULATOR
    char str[32];
    int cpu_freq;
#endif

    /* standard stuff */
    PLUGIN_IRAM_INIT(rb)
    (void)parameter;
    
    log_init();
#ifndef SIMULATOR
    cpu_freq = *rb->cpu_frequency; /* remember CPU frequency */
#endif
    backlight_force_on(); /* backlight control in lib/helper.c */

    log_text("Main LCD Update");
    time_main_update();
#if defined(HAVE_LCD_COLOR) && (MEMORYSIZE > 2)
    log_text("Main LCD YUV");
    time_main_yuv();
#endif
#if LCD_DEPTH < 4
    log_text("Greyscale library");
    time_greyscale();
#endif
#ifdef HAVE_REMOTE_LCD
    log_text("Remote LCD Update");
    time_remote_update();
#endif

#ifndef SIMULATOR
    if (*rb->cpu_frequency != cpu_freq)
        rb->snprintf(str, sizeof(str), "CPU clock changed!");
    else
        rb->snprintf(str, sizeof(str), "CPU: %d MHz",
                     (cpu_freq + 500000) / 1000000);
    log_text(str);
#endif
    backlight_use_settings(); /* backlight control in lib/helper.c */

    /* wait until user closes plugin */
    while (rb->button_get(true) != FPS_QUIT);

    return PLUGIN_OK;
}
示例#27
0
文件: log.c 项目: jes/serve
/* check if pidfile exists, check if the process is running, save pid */
void save_pid(int pid) {
  int n;
  FILE *file;
  struct stat stat_buf;

  /* if pidfile exists, check if the process is running */
  if(stat(pidfile, &stat_buf) == 0) {
    file = fopen(pidfile, "r");
    if(!file) {
      log_text(err, "'%s' already exists, but can not be read. "
               "Execution shall continue, but with no logging of the pid (%d).",
               pidfile, pid);
      pidfile = NULL;
      fclose(file);
      return;
    } else {
      fscanf(file, "%d", &n);
      fclose(file);
      if(kill(n, 0) == -1) {
        log_text(err, "'%s' already exists, but no process with pid %d is "
                 "running. Perhaps serve crashed or was forcibly killed. "
                 "Execution shall continue, but with no logging of the pid "
                 "(%d).",
                 pidfile, n, pid);
      } else {
        log_text(err, "'%s' already exists, and a process with pid %d is "
                 "running. Execution shall not continue.", pidfile, n);
        pidfile = NULL;
        exit(1);
      }
    }
  }

  /* now write the pid */
  file = fopen(pidfile, "w");
  if(file) {
    fprintf(file, "%d\n", pid);
    fclose(file);
    log_text(err, "Wrote pid %d to '%s'.", pid, pidfile);
  } else {
    log_text(err, "Unable to open '%s' for writing. Execution shall continue, "
             "but with no logging of the pid (%d).", pidfile, pid);
    pidfile = NULL;
  }
}
示例#28
0
void sb_timer_start(sb_timer_t *t)
{
  switch (t->state) {
    case TIMER_INITIALIZED:
    case TIMER_STOPPED:
      break;
    case TIMER_RUNNING:
      log_text(LOG_WARNING, "timer was already started");
      break;
    default:
      log_text(LOG_FATAL, "uninitialized timer started");
      abort();
  }
  
  SB_GETTIME(&t->time_start);
  t->time_split = t->time_start;
  t->state = TIMER_RUNNING;
}
示例#29
0
unsigned long long  sb_timer_value(sb_timer_t *t)
{
  switch (t->state) {
    case TIMER_INITIALIZED:
      log_text(LOG_WARNING, "timer was never started");
      return 0;
    case TIMER_STOPPED:
      return t->elapsed;
    case TIMER_RUNNING:
      break;
    default:
      log_text(LOG_FATAL, "uninitialized timer queried");
      abort();
  }

  sb_timer_update(t);

  return t->elapsed;
}
示例#30
0
void NDECL(init_version)
{
#ifdef BETA
#define INDEVEL_TAG "Beta"
#endif
#ifdef ALPHA
#define INDEVEL_TAG "Alpha"
#endif

#ifdef INDEVEL_TAG
#if PATCHLEVEL > 0
	sprintf(mudstate.version, "RhostMUSH %s version %.30s%.10s patchlevel %d%s #%.10s",
		INDEVEL_TAG, MUSH_VERSION, EXT_MUSH_VER, PATCHLEVEL, PATCHLEVELEXT, MUSH_BUILD_NUM);
	sprintf(mudstate.short_ver, "RhostMUSH %s %.30s%.10s.p%d%s",
		INDEVEL_TAG, MUSH_VERSION, EXT_MUSH_VER, PATCHLEVEL, PATCHLEVELEXT);
#else
	sprintf(mudstate.version, "RhostMUSH %s version %.30s%.10s #%.10s",
		INDEVEL_TAG, MUSH_VERSION, EXT_MUSH_VER, MUSH_BUILD_NUM);
	sprintf(mudstate.short_ver, "RhostMUSH %s %.30s%.10s", INDEVEL_TAG,
		MUSH_VERSION, EXT_MUSH_VER);
#endif	/* PATCHLEVEL */
#else	/* not BETA or ALPHA */
#if PATCHLEVEL > 0
	sprintf(mudstate.version, "RhostMUSH version %.30s%.10s patchlevel %d%s #%.10s [%.30s]",
		MUSH_VERSION, EXT_MUSH_VER, PATCHLEVEL, PATCHLEVELEXT, MUSH_BUILD_NUM, MUSH_RELEASE_DATE);
	sprintf(mudstate.short_ver, "RhostMUSH %.30s%.10s.p%d%s",
		MUSH_VERSION, EXT_MUSH_VER, PATCHLEVEL, PATCHLEVELEXT);
#else
	sprintf(mudstate.version, "RhostMUSH version %.30s%.10s #%.10s [%.30s]",
		MUSH_VERSION, EXT_MUSH_VER, MUSH_BUILD_NUM, MUSH_RELEASE_DATE);
	sprintf(mudstate.short_ver, "RhostMUSH %.30s%.10s",
		MUSH_VERSION, EXT_MUSH_VER);
#endif	/* PATCHLEVEL */
#endif	/* BETA */
	STARTLOG(LOG_ALWAYS,"INI","START")
		log_text((char *)"Starting: ");
		log_text(mudstate.version);
	ENDLOG
	STARTLOG(LOG_ALWAYS,"INI","START")
		log_text((char *)"Build date: ");
		log_text((char *)MUSH_BUILD_DATE);
	ENDLOG	
}