예제 #1
0
파일: getopt.hpp 프로젝트: mbits-os/libbase
		inline void copy_strtrans(std::basic_string<CharOut, std::char_traits<CharOut>, std::allocator<CharOut>>& out, const Char* in)
		{
			if (!in)
			{
				out.clear();
				return;
			}
			out.assign(_begin(in), _end(in));
		}
예제 #2
0
static void loop_wrapper() {
	static bool setup_done = false;
	preloop_update_frequency();
	if (!setup_done) {
		_begin();		// Startup MySensors library
		setup_done = true;
	}
	_process();			// Process incoming data
	loop();
	run_scheduled_functions();
	esp_schedule();
}
예제 #3
0
int main(int argc, char *argv[])
{
	int opt, log_opts, debug = 0, foreground = 1;

	/* register the signal handler */
	signal(SIGINT, handle_sigint);
	signal(SIGTERM, handle_sigint);

	while ((opt = getopt(argc, argv, "hdb")) != -1) {
		switch (opt) {
			case 'h':
				print_usage();
				exit(0);
			case 'd':
				debug = 1;
				break;
			case 'b':
				foreground = 0;
				break;
			default:
				print_usage();
				exit(0);
		}
	}

	log_opts = LOG_CONS;
	if (foreground && isatty(STDIN_FILENO)) {
		// Also print syslog to stderror
		log_opts |= LOG_PERROR;
	}
	if (!debug) {
		setlogmask(LOG_UPTO (LOG_INFO));
	}
	openlog(NULL, log_opts, LOG_USER);

	if (!foreground && !debug) {
		if (daemonize() != 0) {
			exit(EXIT_FAILURE);
		}
	}

	mys_log(LOG_INFO, "Starting gateway...\n");
	mys_log(LOG_INFO, "Protocol version - %s\n", MYSENSORS_LIBRARY_VERSION);

	_begin(); // Startup MySensors library

	for (;;) {
		_process();  // Process incoming data
		if (loop) loop(); // Call sketch loop
	}
	return 0;
}
예제 #4
0
파일: kvdb.c 프로젝트: fingon/kvdb
bool kvdb_commit(kvdb k)
{
  /* Give import/export module chance to do 'stuff' */
  _kvdb_io_pre_commit(k);

  /* Push current ops to disk. */
  _commit(k);

  /* Start transaction - commit call commits changes. */
  _begin(k);

  return true;
}
예제 #5
0
// The method begin_BCU() is renamed during compilation to indicate the BCU type.
// If you get a link error then the library's BCU_TYPE is different from your application's BCU_TYPE.
void BcuBase::begin_BCU(int manufacturer, int deviceType, int version)
{
	_begin();
#ifdef DUMP_TELEGRAMS
    serial.begin(115200);
    serial.println("Telegram dump enabled");
#endif

    sendTelegram[0] = 0;
    sendCtrlTelegram[0] = 0;

    connectedSeqNo = 0;
    incConnectedSeqNo = false;
    lastAckSeqNo = -1;

    connectedAddr = 0;

    userRam.status = BCU_STATUS_LL | BCU_STATUS_TL | BCU_STATUS_AL | BCU_STATUS_USR;
    userRam.deviceControl = 0;
    userRam.runState = 1;

    userEeprom.runError = 0xff;
    userEeprom.portADDR = 0;

    userEeprom.manufacturerH = manufacturer >> 8;
    userEeprom.manufacturerL = manufacturer;

    userEeprom.deviceTypeH = deviceType >> 8;
    userEeprom.deviceTypeL = deviceType;

    userEeprom.version = version;

#if BCU_TYPE != BCU1_TYPE
    unsigned int serial;
    iapReadPartID(& serial);
    memcpy (userEeprom.serial, &serial, 4);
    userEeprom.serial[4] = SBLIB_VERSION >> 8;
    userEeprom.serial[5] = SBLIB_VERSION;

    userRam.peiType = 0;     // PEI type: 0=no adapter connected to PEI.
    userEeprom.appType = 0;  // Set to BCU2 application. ETS reads this when programming.
#endif

    writeUserEepromTime = 0;
    enabled = true;
    bus.begin();
    progButtonDebouncer.init(1);
}
void CBCGPScanliner::Attach
(
	LPBYTE data,
	const CRect& rect,
	size_t height/* = 0*/,
	size_t pitch/*  = 0*/,
	BYTE channels/* = 1*/,
	BOOL invert/*   = FALSE*/
)
{
	Empty();

	ASSERT(data != NULL);

	CPoint point(rect.TopLeft());
	CSize size(rect.Size());
	if(pitch == 0)
	{
		pitch = size.cx;
	}
	if(height == 0)
	{
		height = point.y + size.cy;
	}

	ASSERT((size_t)size.cx <= pitch);
	ASSERT((size_t)(point.y + size.cy) <= height);

	m_rows	   = size.cy;
	m_cols	   = size.cx * channels;
	m_pitch    = (DWORD)pitch;
	m_offset   = (int)m_pitch;
	if (invert)
	{
		m_offset = -m_offset;
	}
	m_channels = channels;
	m_height   = (DWORD)height;

	m_start_row = point.y;
	m_start_col = point.x;

	m_line_begin = _begin(data);
	m_line_end	 = _end(data);
	m_line		 = m_line_begin;
}
예제 #7
0
void STDRenderer::begin(STDRenderer* prev)
{
    OX_ASSERT(_vertices.empty() == true);
    _previous = prev;
    if (_previous)
    {
        _previous->end();
        _vp = _previous->_vp;
    }

    _program = 0;
    _vertices.clear();
    _transform.identity();
    resetSettings();

    _begin();
}
예제 #8
0
파일: kvdb.c 프로젝트: fingon/kvdb
static bool _kvdb_upgrade(kvdb k)
{
  /* Start transaction */
  _begin(k);
  int schema = _kvdb_get_schema(k);
  if (schema < 0 || schema >= LATEST_SCHEMA)
    {
      KVDEBUG("schema out of range: %d/%d", schema, (int) LATEST_SCHEMA);
      _rollback(k);
      return false;
    }
  sqlite3_stmt *stmt;
  const char *left = _schema_upgrades[schema];
  while (left && strlen(left)>0)
    {
      KVDEBUG("preparing %s", left);

      int rc =
        sqlite3_prepare_v2(k->db,
                           left, -1,
                           &stmt, &left);
      if (rc)
        {
          KVDEBUG("prepare failed");
          _rollback(k);
          return false;
        }
      /* Ok, we've got prepared stmt. Let her rip. */
      if (!_kvdb_run_stmt(k, stmt))
        {
          _rollback(k);
          return false;
        }
    }
  KVDEBUG("upgrade succeeded");
  stmt = _prep_stmt(k, "UPDATE db_state SET value=?1 WHERE key='version'");
  schema++;
  KVDEBUG("setting schema to %d", schema);
  (void)sqlite3_bind_int(stmt, 1, schema);
  bool rv = _kvdb_run_stmt(k, stmt);
  if (rv)
    _commit(k);
  else
    _rollback(k);
  return rv;
}
예제 #9
0
int main(void)
{
	init();
#if defined(USBCON)
	USBDevice.attach();
#endif
	_begin(); // Startup MySensors library
	for(;;) {
		_process();  // Process incoming data
		if (loop) {
			loop(); // Call sketch loop
		}
		if (serialEventRun) {
			serialEventRun();
		}
	}
	return 0;
}
 void VideoDriverGLES20::begin(const Rect& viewport, const Color* clearColor)
 {
     _begin(viewport, clearColor);
 }
예제 #11
0
파일: avl_tree.hpp 프로젝트: jashook/ev6
 iterator begin() { return iterator(_begin()); }
예제 #12
0
bool windows_opengl_init()
{
	if(oglAlreadyInit) return true;

	if(!makeBootstrapContext())
	{
		printf("GL bootstrap context failed\n");
		return false;
	}

	//thx will perone

	PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
	PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
	PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB");
	PFNWGLGETPBUFFERDCARBPROC wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB");
	PFNWGLQUERYPBUFFERARBPROC wglQueryPbufferARB = (PFNWGLQUERYPBUFFERARBPROC)wglGetProcAddress("wglQueryPbufferARB");
	PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC)wglGetProcAddress("wglDestroyPbufferARB");
	PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB");
	PFNWGLBINDTEXIMAGEARBPROC wglBindTexImageARB = (PFNWGLBINDTEXIMAGEARBPROC)wglGetProcAddress("wglBindTexImageARB");
	PFNWGLRELEASETEXIMAGEARBPROC wglReleaseTexImageARB = (PFNWGLRELEASETEXIMAGEARBPROC)wglGetProcAddress("wglReleaseTexImageARB");
  PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB");

	if(!wglCreatePbufferARB)
	{
		printf("no PBuffer support on this video driver. sorry!");
		return false;
	}

	int intAttrs[32] ={
		WGL_COLOR_BITS_ARB,24,
		WGL_RED_BITS_ARB,8,
		WGL_GREEN_BITS_ARB,8,
		WGL_BLUE_BITS_ARB,8,
		WGL_ALPHA_BITS_ARB,8,
		WGL_DEPTH_BITS_ARB,24,
		WGL_STENCIL_BITS_ARB,8,
		WGL_DRAW_TO_PBUFFER_ARB, GL_TRUE,
		WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
		WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
		WGL_DOUBLE_BUFFER_ARB,GL_FALSE,
		0};

	//setup pixel format
	UINT numFormats;
	int pixelFormat;
	if(!wglChoosePixelFormatARB(main_hDC, intAttrs, NULL, 1, &pixelFormat, &numFormats) || numFormats == 0)
	{
		printf("problem finding pixel format in wglChoosePixelFormatARB\n");
		return false;
	}

	//pbuf attributes
	int pbuf_width = 256;  //try 192 later, but i think it has to be square
	int pbuf_height = 256;
	static const int pbuf_attributes[]= {0};

	HPBUFFERARB pbuffer = wglCreatePbufferARB(main_hDC, pixelFormat, pbuf_width, pbuf_height, pbuf_attributes);
	HDC hdc = wglGetPbufferDCARB(pbuffer);
	HGLRC hGlRc = wglCreateContext(hdc);		

	//doublecheck dimensions
	int width, height;
	wglQueryPbufferARB(pbuffer, WGL_PBUFFER_WIDTH_ARB, &width);
	wglQueryPbufferARB(pbuffer, WGL_PBUFFER_HEIGHT_ARB, &height);
	if(width != pbuf_height || height != pbuf_height)
	{
		printf("wglCreatePbufferARB created some wrongly sized nonsense\n");
		return false;
	}

	//cleanup the bootstrap context
	wglDeleteContext(main_hRC);
	DeleteObject(main_hDC);
	DestroyWindow(main_hWND);

	main_hDC = hdc;
	main_hRC = hGlRc;
	oglAlreadyInit = true;
	oglrender_beginOpenGL = _begin;
	
	//use the new pbuffer context for further extension interrogation in shared opengl init
	_begin();

	return true;
}
예제 #13
0
파일: kvdb.c 프로젝트: fingon/kvdb
bool kvdb_create(const char *path, kvdb *r_k)
{
  int i;
  int rc;
  kvdb_init_s *is;

  KVASSERT(path, "no path to kvdb_create");
  KVASSERT(r_k, "no return value to kvdb_create");

  kvdb k = calloc(1, sizeof(*k));
  *r_k = k;
  if (!k)
    return false;
  rc = sqlite3_open(path, &k->db);
  if (rc)
    {
      _kvdb_set_err_from_sqlite(k);
fail:
      kvdb_destroy(k);
      return false;
    }
  int schema;
  while ((schema = _kvdb_get_schema(k)) < LATEST_SCHEMA)
    {
      if (!_kvdb_upgrade(k))
        {
          _kvdb_set_err(k, "_kvdb_upgrade failed");
           goto fail;
        }
      int new_schema = _kvdb_get_schema(k);
      if (new_schema <= schema)
        {
          _kvdb_set_err(k, "upgrade step did not upgrade schema#");
          goto fail;
        }
      schema = new_schema;
    }
  if (schema != LATEST_SCHEMA)
    {
      _kvdb_set_err(k, "unable to upgrade to latest");
      goto fail;
    }
  k->oidbase.boot =
    _kvdb_get_int(k, "SELECT value FROM db_state WHERE key='boot'", -1);
  KVASSERT(k->oidbase.boot >= 0, "no boot key in db_state");
  SQLITE_EXEC2("UPDATE db_state SET value=value+1 WHERE key='boot'", goto fail);
  FILE *f = popen("hostname -s", "r");
  if (!f)
    {
      _kvdb_set_err(k, "hostname callf ailed)");
      goto fail;
    }
  char *hname = k->oidbase.name;
  fgets(hname, KVDB_HOSTNAME_SIZE, f);
  hname[KVDB_HOSTNAME_SIZE-1] = 0;
  if (*hname && hname[strlen(hname)-1] == '\n')
    hname[strlen(hname)-1] = 0;
  if (*hname && hname[strlen(hname)-1] == '\r')
    hname[strlen(hname)-1] = 0;
  if (*hname && hname[strlen(hname)-1] == '\n')
    hname[strlen(hname)-1] = 0;
  KVDEBUG("got name %s", hname);
  k->ss_app = stringset_create(sizeof(struct kvdb_app_struct), NULL, NULL);
  if (!k->ss_app)
    {
      _kvdb_set_err(k, "stringset_create failed");
      goto fail;
    }
  k->ss_class = stringset_create(sizeof(struct kvdb_class_struct), NULL, NULL);
  if (!k->ss_class)
    {
      _kvdb_set_err(k, "stringset_create failed");
      goto fail;
    }
  k->ss_key = stringset_create(sizeof(struct kvdb_key_struct), NULL, NULL);
  if (!k->ss_key)
    {
      _kvdb_set_err(k, "stringset_create failed");
      goto fail;
    }

  k->oid_ih = ihash_create(_kvdb_o_hash_value, _kvdb_o_compare, NULL);
  if (!k->oid_ih)
    {
      _kvdb_set_err(k, "oid_ih create failed");
      goto fail;
    }

  /* Initialize the pointer structures from local data */

  for (is = &_stmt_init[0] ; is->n >= 0 ; is++)
    {
      if (!(k->stmts[is->n] = _prep_stmt(k, is->s)))
        {
          _kvdb_set_err_from_sqlite2(k, "unable to prepare stmt");
          goto fail;
        }
    }

  for (is = &_app_init[0] ; is->n >= 0 ; is++)
    k->apps[is->n] = kvdb_define_app(k, is->s);

  for (is = &_key_init[0] ; is->n >= 0 ; is++)
    k->keys[is->n] = kvdb_define_key(k, is->s, KVDB_STRING);

  /* Make sure we actually have all pointers we wanted */

  for (i = 0 ; i < NUM_STMTS ; i++)
    KVASSERT(k->stmts[i], "missing stmt %d", i);

  for (i = 0 ; i < NUM_KEYS ; i++)
    KVASSERT(k->keys[i], "missing key %d", i);

  for (i = 0 ; i < NUM_APPS ; i++)
    KVASSERT(k->apps[i], "missing app %d", i);

  /* Init submodules */
  if (!_kvdb_index_init(k))
    goto fail;

  if (!_kvdb_io_init(k))
    goto fail;

  /* Start transaction - commit call commits changes. */
  _begin(k);
  return true;
}