Example #1
0
void
Exceptions::error (const char *message, error_type_t error_type)
{
  static char buffer[3][100];
  static char *lines[3] = { buffer[0], buffer[1], buffer[2] };
  int count = 0;

  if (error_type == INTERNAL_ERROR)
    strcpy (buffer[count++], f_msg_internal_error);
  else if (error_type == APPLICATION_ERROR)
    strcpy (buffer[count++], f_msg_application_error);
  else
    strcpy (buffer[count++], f_msg_throw_message);
      
  // Don't use fprintf because it may try to allocate memory.
  if (Exception::g_current_exception != NULL)
    {
      sprintf (buffer[count++],
	       "   In exception thrown in file \"%s\", line %d,",
	       Exception::g_current_exception->f_file,
	       Exception::g_current_exception->f_line);
    }

  if (message != NULL)
    sprintf (buffer[count++], "   %s", message);

  // Call user print function if set, otherwise just dump lines.
  if (g_error_handler != NULL)
    {
      try
	{
	  // Reset global variable to NULL before calling to prevent
	  // the possibility of recursive calls. 
	  Exceptions::error_handler_t current = set_error_handler (NULL);
	  (*current) ((const char**)lines, count);
	  set_error_handler (current);
	}
      catch_any()
	{
	  // Error handler will be NULL at this point. 
	  Exceptions::error (Exceptions::f_msg_throw_from_error_handler,
			     Exceptions::APPLICATION_ERROR);
	  terminate();

	}
      end_try;
    }
  else
    {
      for (int i = 0; i < count; i++)
Example #2
0
 Listener::Listener(Scheduler &scheduler)
     : m_scheduler(&scheduler)
     , m_acceptor(scheduler.asio())
     , m_next_connection(scheduler)
 {
     set_connection_handler(nullptr);
     set_error_handler(nullptr);
 }
bool
init_transaction_manager() {
  debug( "Initializing transaction manager." );

  create_transaction_db();
  set_barrier_reply_handler( handle_barrier_reply, NULL );
  set_error_handler( handle_error, NULL );

  struct itimerspec interval;
  interval.it_interval = TRANSACTION_AGING_INTERVAL;
  interval.it_value = TRANSACTION_AGING_INTERVAL;
  add_timer_event_callback( &interval, age_transaction_entries, NULL );

  debug( "Initialization completed." );

  return true;
}
bool
set_other_error_handler( error_handler callback, void *user_data ) {
  if ( callback == NULL ) {
    error( "Callback function ( error_handler ) must not be NULL." );
    return false;
  }

  debug( "Setting an other error handler ( callback = %p, user_data = %p ).",
         callback, user_data );

  set_error_handler( handle_error, NULL );

  event_handlers.other_error_callback = callback;
  event_handlers.other_error_user_data = user_data;

  return true;
}
Example #5
0
/*
 * Starts this controller. Usually you do not need to invoke
 * explicitly, because this is called implicitly by "trema run"
 * command.
 */
static VALUE
controller_run( VALUE self ) {
  setenv( "TREMA_HOME", STR2CSTR( rb_funcall( mTrema, rb_intern( "home" ), 0 ) ), 1 );

  VALUE name = rb_funcall( self, rb_intern( "name" ), 0 );
  rb_gv_set( "$PROGRAM_NAME", name );

  int argc = 3;
  char **argv = xmalloc( sizeof( char * ) * ( uint32_t ) ( argc + 1 ) );
  argv[ 0 ] = STR2CSTR( name );
  argv[ 1 ] = ( char * ) ( uintptr_t ) "--name";
  argv[ 2 ] = STR2CSTR( name );
  argv[ 3 ] = NULL;
  init_trema( &argc, &argv );
  xfree( argv );

  set_switch_ready_handler( handle_switch_ready, ( void * ) self );
  set_features_reply_handler( handle_features_reply, ( void * ) self );
  set_packet_in_handler( handle_packet_in, ( void * ) self );
  set_flow_removed_handler( handle_flow_removed, ( void * ) self );
  set_switch_disconnected_handler( handle_switch_disconnected, ( void * ) self );
  set_port_status_handler( handle_port_status, ( void * ) self );
  set_stats_reply_handler( handle_stats_reply, ( void * ) self );
  set_error_handler( handle_openflow_error, ( void * ) self );
  set_get_config_reply_handler( handle_get_config_reply, ( void * ) self );
  set_barrier_reply_handler( handle_barrier_reply, ( void * ) self );
  set_vendor_handler( handle_vendor, ( void * ) self );
  set_queue_get_config_reply_handler( handle_queue_get_config_reply, ( void * ) self );
  set_list_switches_reply_handler( handle_list_switches_reply );

  struct itimerspec interval;
  interval.it_interval.tv_sec = 1;
  interval.it_interval.tv_nsec = 0;
  interval.it_value.tv_sec = 0;
  interval.it_value.tv_nsec = 0;
  add_timer_event_callback( &interval, handle_timer_event, ( void * ) self );

  if ( rb_respond_to( self, rb_intern( "start" ) ) == Qtrue ) {
    rb_funcall( self, rb_intern( "start" ), 0 );
  }

  rb_funcall( self, rb_intern( "start_trema" ), 0 );

  return self;
}
Example #6
0
static int do_register(psys_pkg_t pkg, psys_err_t *err, jmp_buf *buf)
{
	int ret;
	char *dpkgname = NULL;
	const char *dpkgarch;
	struct pkginfo *dpkg;
	psys_flist_t flist = NULL;
	char *filelist_path = NULL;
	char *md5list_path = NULL;

	set_error_handler(err, *buf, out);

	dpkgname = dpkg_name(psys_pkg_vendor(pkg), psys_pkg_name(pkg));
	dpkg = findpackage(dpkgname);
	if (ensure_not_installed(dpkg, err)) {
		ret = -1;
		goto out;
	}

	if (ensure_dependencies_met(pkg, err)) {
		ret = -1;
		goto out;
	}

	blankpackage(dpkg);
	blankpackageperfile(&dpkg->installed);

	/* Name, Version */
	dpkg->name = dpkgname;
	parseversion(&dpkg->installed.version, psys_pkg_version(pkg));

	/* Architecture */
	dpkgarch = dpkg_arch(psys_pkg_arch(pkg), err);
	if (!dpkgarch) {
		ret = -1;
		goto out;
	}
	dpkg->installed.architecture = dpkgarch;

	/* Description */
	set_description(dpkg, pkg);

	/* 
	 * Maintainer
	 *
	 * FIXME: Our Maintainer value does not conform to the format
	 * mandated by the Debian Policy Manual (which is "Name <E-Mail>"),
	 * but this is better than not specifying a Maintainer at all
	 * (which is a mandatory field)
	 */
	dpkg->installed.maintainer = nfstrsave(psys_pkg_vendor(pkg));

	/* Priority */
	dpkg->priority = pri_optional;

	/* Dependencies */
	add_dependencies(dpkg, pkg);

	flist = psys_pkg_flist(pkg, err);
	if (!flist) {
		ret = -1;
		goto out;
	}

	/* Installed Size */
	set_installed_size(dpkg, flist);

	/* File List */
	filelist_path = create_file_list(dpkg, flist, err);
	if (!filelist_path) {
		ret = -1;
		goto out;
	}

	/* MD5SUMS List */
	md5list_path = create_md5sums_list(dpkg, flist, err);
	if (!md5list_path) {
		ret = -1;
		goto out;
	}

	dpkg->want = want_install;
	dpkg->status = stat_installed;
	modstatdb_note(dpkg);

	ret = 0;
out:
	if (md5list_path) {
		if (ret == -1)
			remove(md5list_path);
		free(md5list_path);
	}
	if (filelist_path) {
		if (ret == -1)
			remove(filelist_path);
		free(filelist_path);
	}
	if (flist)
		psys_flist_free(flist);
	return ret;
}
Example #7
0
JNIEXPORT void JNICALL Java_com_example_hellohalide_CameraPreview_processFrame(JNIEnv * env, jobject obj, jbyteArray jSrc, jobject surf) {

    set_error_handler(handler);

    unsigned char *src = (unsigned char *)env->GetByteArrayElements(jSrc, NULL);

    ANativeWindow *win = ANativeWindow_fromSurface(env, surf);
    ANativeWindow_acquire(win);

    static bool first_call = true;
    static unsigned counter = 0;
    static unsigned times[16];
    if (first_call) {
      LOGD("Resetting buffer format");
      ANativeWindow_setBuffersGeometry(win, 640, 360, 0); 
      first_call = false;
      for (int t = 0; t < 16; t++) times[t] = 0;
    }

    ANativeWindow_Buffer buf;
    ARect rect = {0, 0, 640, 360};
    ANativeWindow_lock(win, &buf, &rect);

    uint8_t *dst = (uint8_t *)buf.bits;
    buffer_t srcBuf = {0}, dstBuf = {0};
    srcBuf.host = (uint8_t *)src;
    srcBuf.extent[0] = 642;
    srcBuf.extent[1] = 362;
    srcBuf.extent[2] = 1;
    srcBuf.extent[3] = 1;
    srcBuf.stride[0] = 1;    
    srcBuf.stride[1] = 640;
    srcBuf.min[0] = -1;
    srcBuf.min[1] = -1;
    srcBuf.elem_size = 1;

    dstBuf.host = dst;
    dstBuf.extent[0] = 640;
    dstBuf.extent[1] = 360;
    dstBuf.extent[2] = 1;
    dstBuf.extent[3] = 1;
    dstBuf.stride[0] = 1;
    dstBuf.stride[1] = 640;
    dstBuf.min[0] = 0;
    dstBuf.min[1] = 0;
    dstBuf.elem_size = 1;

    timeval t1, t2;
    gettimeofday(&t1, NULL);
    halide(&srcBuf, &dstBuf);
    gettimeofday(&t2, NULL);
    unsigned elapsed = (t2.tv_sec - t1.tv_sec)*1000000 + (t2.tv_usec - t1.tv_usec);

    times[counter & 15] = elapsed;
    counter++;
    unsigned min = times[0];
    for (int i = 1; i < 16; i++) {
        if (times[i] < min) min = times[i];
    }    
    LOGD("Time taken: %d (%d)", elapsed, min);

    // Just copy over chrominance untouched
    memcpy(dst + 640*360, src + 640*480, 320*180);
    memcpy(dst + 640*360 + 320*180, src + 640*480 + 320*240, 320*180);

    ANativeWindow_unlockAndPost(win);
    ANativeWindow_release(win);

    env->ReleaseByteArrayElements(jSrc, (jbyte *)src, 0);        
}