Exemplo n.º 1
0
static void
test_foreach_message_queue() {
  message_queue *queue = create_message_queue();
  assert_true( queue != NULL );

  buffer *first_buf = alloc_buffer();
  append_string( first_buf, "first_buffer" );
  assert_true( enqueue_message( queue, first_buf ) );
  assert_int_equal( queue->length, 1 );
  buffer *second_buf = alloc_buffer();
  append_string( second_buf, "second_buffer" );
  assert_true( enqueue_message( queue, second_buf ) );
  assert_int_equal( queue->length, 2 );
  buffer *third_buf = alloc_buffer();
  append_string( third_buf, "third_buffer" );
  assert_true( enqueue_message( queue, third_buf ) );
  assert_int_equal( queue->length, 3 );

  buffer *deq_buf = dequeue_message( queue );
  assert_true( deq_buf == first_buf );

  char *user_data = xstrdup( "user_data" );
  count = 0;

  foreach_message_queue( queue, test_foreach_message_queue_helper, user_data );

  assert_int_equal( count, 2 );

  xfree( user_data );
  assert_true( delete_message_queue( queue ) );
}
Exemplo n.º 2
0
/* create message queue and prepare timer callbacks */
static void
split_and_send(message_to_conv *msg_to_conv, const char **message) {
	gint message_delay_ms;

	g_return_if_fail( msg_to_conv != NULL );
	g_return_if_fail( message     != NULL );
	g_return_if_fail( *message    != NULL );

	/* read and validate preferences */
	current_split_size = purple_prefs_get_int("/plugins/core/splitter/split_size");
	if( current_split_size > MAX_SPLIT_SIZE ) current_split_size = MAX_SPLIT_SIZE;
	if( current_split_size < MIN_SPLIT_SIZE ) current_split_size = MIN_SPLIT_SIZE;

	message_delay_ms = purple_prefs_get_int("/plugins/core/splitter/delay_ms");
	if( message_delay_ms > MAX_DELAY_MS ) message_delay_ms = MAX_DELAY_MS;
	if( message_delay_ms < MIN_DELAY_MS ) message_delay_ms = MIN_DELAY_MS;

	/* prepare message queue */
	msg_to_conv->messages = create_message_queue(*message);
	g_return_if_fail( msg_to_conv->messages != NULL );

	/* initialize message send timer */
	purple_timeout_add( (g_queue_get_length(msg_to_conv->messages) > 1) ? message_delay_ms : 0,
			  (GSourceFunc)send_message_timer_cb,
			  msg_to_conv);

	/* free the original message and ensure it does not get sent */
	g_free((char*)*message);
	*message = NULL;
}
JNIEXPORT jboolean JNICALL Java_ism_monagent_EMListener_create_1message_1queue
  (JNIEnv *env, jobject obj, jboolean isblocking)
{
    string s = isblocking? "true":"false";
    TRACE("create_message_queue(" << s << ")");
    return create_message_queue(isblocking);
}
Exemplo n.º 4
0
static void
test_create_and_delete_message_queue() {
  message_queue *queue = create_message_queue();
  assert_true( queue != NULL );
  assert_int_equal( queue->length, 0 );

  assert_true( delete_message_queue( queue ) );
}
Exemplo n.º 5
0
static void
test_enqueue_message_if_message_is_NULL() {
  message_queue *queue = create_message_queue();
  assert_true( queue != NULL );
  assert_int_equal( queue->length, 0 );

  expect_assert_failure( enqueue_message( queue, NULL ) );

  assert_true( delete_message_queue( queue ) );
}
void
cc_init_sw_info(sw_info* cc_sw_info)
{
	//sw_info* cc_sw_info;
	//cc_sw_info = (sw_info*)malloc(sizeof(cc_sw_info));
	cc_sw_info->xid_latest= 0;
	cc_sw_info->recv_queue = create_message_queue();
	cc_sw_info->send_queue = create_message_queue();
	pool_init(&(cc_sw_info->cc_recv_thread_pool), 1);
	cc_sw_info->xid_table = cc_init_xid_table();
	cc_sw_info->xid_latest = 0;
	cc_sw_info->config_flags = CC_MAX_THREAD_NUM;
	cc_sw_info->miss_send_len = OFP_DEFAULT_MISS_SEND_LEN;
	cc_sw_info->cookie = 0;
    /*add default handler*/
    cc_sw_info->recv_handler = cc_recv_handle_register(CC_OFP_VER_1_0);
    cc_sw_info->send_handler = NULL;//cc_send_handle_register(CC_OFP_VER_1_0);
    
	return;
}
Exemplo n.º 7
0
static void
test_enqueue_and_delete_message_queue() {
  message_queue *queue = create_message_queue();
  assert_true( queue != NULL );
  assert_int_equal( queue->length, 0 );

  buffer *buf = alloc_buffer();
  assert_true( enqueue_message( queue, buf ) );
  assert_int_equal( queue->length, 1 );

  assert_true( delete_message_queue( queue ) );
}
Exemplo n.º 8
0
static int start_mq(void)
{
	struct mq_attr attr;
	attr.mq_flags = 0;
	attr.mq_maxmsg = MAX_MESSAGES;
	attr.mq_msgsize = MAX_MESSAGES_SIZE;
	attr.mq_curmsgs = 0;
	if (create_message_queue( &attr) < 0) {
		APP_ERROR("Failed to create mq.");
		return -1;
	}
	return 0;
}
Exemplo n.º 9
0
static void
test_foreach_message_queue_if_queue_is_empty() {
  message_queue *queue = create_message_queue();
  assert_true( queue != NULL );

  char *user_data = xstrdup( "user_data" );
  foreach_message_queue( queue, test_foreach_message_queue_if_queue_is_empty_helper, user_data );

  assert_int_equal( count, 2 );

  xfree( user_data );
  assert_true( delete_message_queue( queue ) );
}
Exemplo n.º 10
0
bool
init_secure_channel( uint32_t ip, uint16_t port, connected_handler connected_callback, disconnected_handler disconnected_callback ) {
  assert( !secure_channel_initialized );

  connection.ip = ip;
  connection.port = port;
  connection.fd = -1;
  connection.connected_callback = connected_callback;
  connection.disconnected_callback = disconnected_callback;

  bool ret = try_connect();
  if ( ret == false ) {
    clear_connection();
    return false;
  }

  send_queue = create_message_queue();
  recv_queue = create_message_queue();

  secure_channel_initialized = true;

  return true;
}
Exemplo n.º 11
0
static void
test_multiple_queueing() {
  message_queue *queue = create_message_queue();
  assert_true( queue != NULL );

  buffer *first_buf = alloc_buffer();
  assert_true( enqueue_message( queue, first_buf ) );
  assert_int_equal( queue->length, 1 );

  buffer *deq_buf = dequeue_message( queue );
  assert_true( deq_buf == first_buf );
  free_buffer( deq_buf );
  assert_int_equal( queue->length, 0 );


  first_buf = alloc_buffer();
  assert_true( enqueue_message( queue, first_buf ) );
  assert_int_equal( queue->length, 1 );
  buffer *second_buf = alloc_buffer();
  assert_true( enqueue_message( queue, second_buf ) );
  assert_int_equal( queue->length, 2 );

  deq_buf = dequeue_message( queue );
  assert_true( deq_buf == first_buf );
  free_buffer( deq_buf );
  assert_int_equal( queue->length, 1 );

  buffer *third_buf = alloc_buffer();
  assert_true( enqueue_message( queue, third_buf ) );
  assert_int_equal( queue->length, 2 );
  buffer *fourth_buf = alloc_buffer();
  assert_true( enqueue_message( queue, fourth_buf ) );
  assert_int_equal( queue->length, 3 );

  deq_buf = dequeue_message( queue );
  assert_true( deq_buf == second_buf );
  free_buffer( deq_buf );
  assert_int_equal( queue->length, 2 );
  deq_buf = dequeue_message( queue );
  assert_true( deq_buf == third_buf );
  free_buffer( deq_buf );
  assert_int_equal( queue->length, 1 );
  deq_buf = dequeue_message( queue );
  assert_true( deq_buf == fourth_buf );
  free_buffer( deq_buf );
  assert_int_equal( queue->length, 0 );


  assert_true( delete_message_queue( queue ) );
}
Exemplo n.º 12
0
struct switch_arguments *
init_parse_args( int argc, char **argv ) {
  struct switch_arguments *args = xmalloc( sizeof( struct switch_arguments ) );

  parse_options( args, argc, argv );
  int efd[ 2 ];
  uint32_t i;

  for ( i = 0; i < sizeof( efd ) / sizeof( efd[ 0 ] ); i++ ) {
    efd[ i ] = create_event_fd();
    if ( efd[ i ] == -1 ) {
      error( "failed to create_event_fd %d", errno );
      xfree( args );
      return NULL;
    }
  }
  memcpy( args->efd, &efd, sizeof( efd ) );
  args->to_protocol_queue = create_message_queue();
  assert( args->to_protocol_queue != NULL );
  char *switch_log = get_switch_log();
  logging_type log_output_type = LOGGING_TYPE_FILE;
  if ( args->run_as_daemon == false ) {
    log_output_type |= LOGGING_TYPE_STDOUT;
  }
  char name[ PATH_MAX ];
  snprintf( name, PATH_MAX, "%s.%#" PRIx64, args->progname, args->datapath_id );
  init_log( name, switch_log, log_output_type );
  xfree( switch_log );

  char *switch_pid_dir = get_switch_pid_dir();
  write_pid( switch_pid_dir, name );
  char cmd[ PATH_MAX ];
  /*
   * change the pid file permissions to allow deletion since switch is started
   * as sudo. This would become obsolete if sudo is removed.
   */
  snprintf( cmd, PATH_MAX, "chmod 0666 %s/%s.pid", switch_pid_dir, name );
  system( cmd );
  xfree( switch_pid_dir );

  ignore_sigpipe();
#ifdef NOT_TESTED
  if ( args->run_as_daemon == true ) {
    daemonize( get_switch_home() );
  }
#endif

  return args;
}
Exemplo n.º 13
0
	app::app(const std::string& aName)
		try :
		iName(aName),
		iQuitWhenLastWindowClosed(true),
		neolib::io_thread("neogfx::app", true),
		iBasicServices(new neogfx::sdl_basic_services(*this)),
		iKeyboard(new neogfx::sdl_keyboard()),
		iClipboard(new neogfx::clipboard(basic_services().clipboard())),
		iRenderingEngine(new neogfx::sdl_renderer(*iBasicServices, *iKeyboard)),
		iSurfaceManager(new neogfx::surface_manager(*iBasicServices, *iRenderingEngine)),
		iCurrentStyle(iStyles.begin())
	{
		app* np = nullptr;
		sFirstInstance.compare_exchange_strong(np, this);
		create_message_queue([this]() -> bool 
		{ 
			return process_events(*iContext); 
		});
		iContext = std::make_unique<event_processing_context>(*this, "neogfx::app");
		iKeyboard->grab_keyboard(*this);
		style whiteStyle("Default");
		register_style(whiteStyle);
		style slateStyle("Slate");
		slateStyle.set_colour(colour(0x35, 0x35, 0x35));
		register_style(slateStyle);
		iSystemCache.reset(new window{ point{}, size{}, "neogfx::system_cache", window::InitiallyHidden | window::Weak });
	}
	catch (std::exception& e)
	{
		std::cerr << "neogfx::app::app: terminating with exception: " << e.what() << std::endl;
		sdl_basic_services(*this).display_error_dialog(aName.empty() ? "Abnormal Program Termination" : "Abnormal Program Termination - " + aName, std::string("main: terminating with exception: ") + e.what());
		throw;
	}
	catch (...)
	{
		std::cerr << "neogfx::app::app: terminating with unknown exception" << std::endl;
		sdl_basic_services(*this).display_error_dialog(aName.empty() ? "Abnormal Program Termination" : "Abnormal Program Termination - " + aName, "main: terminating with unknown exception");
		throw;
	}
Exemplo n.º 14
0
int main(int argc, char** argv) {
    my_msg the_msg;
    int retval;

    if (!strcmp(argv[1], "-d")) {
        destroy_message_queue(KEY);
    } else if (!strcmp(argv[1], "-c")) {
        create_message_queue(KEY);
    } else if (!strcmp(argv[1], "-rw")) {
        retval = receive_message(KEY, &the_msg, sizeof(my_msg),true);
        printf("Received message: %s\n", the_msg.msg_text);
    } else if (!strcmp(argv[1], "-r")) {
        retval = receive_message(KEY, &the_msg, sizeof(my_msg),false);
        if (!retval) printf("Received message: %s\n", the_msg.msg_text);
    } else if (!strcmp(argv[1], "-s")) {
        the_msg.msg_type = 1;
        strcpy(the_msg.msg_text, argv[2]);
        send_message(KEY, &the_msg, sizeof(my_msg),true);
    }

    return 0;
}
Exemplo n.º 15
0
int
main( int argc, char *argv[] ) {
  int ret;
  int i;
  char *service_name;

  init_trema( &argc, &argv );
  option_parser( argc, argv );

  create_list( &switch_info.vendor_service_name_list );
  create_list( &switch_info.packetin_service_name_list );
  create_list( &switch_info.portstatus_service_name_list );
  create_list( &switch_info.state_service_name_list );

  for ( i = optind; i < argc; i++ ) {
    if ( strncmp( argv[ i ], VENDOR_PREFIX, strlen( VENDOR_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[ i ] + strlen( VENDOR_PREFIX ) );
      append_to_tail( &switch_info.vendor_service_name_list, service_name );
    }
    else if ( strncmp( argv[ i ], PACKET_IN_PREFIX, strlen( PACKET_IN_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[ i ] + strlen( PACKET_IN_PREFIX ) );
      append_to_tail( &switch_info.packetin_service_name_list, service_name );
    }
    else if ( strncmp( argv[ i ], PORTSTATUS_PREFIX, strlen( PORTSTATUS_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[ i ] + strlen( PORTSTATUS_PREFIX ) );
      append_to_tail( &switch_info.portstatus_service_name_list, service_name );
    }
    else if ( strncmp( argv[ i ], STATE_PREFIX, strlen( STATE_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[ i ] + strlen( STATE_PREFIX ) );
      append_to_tail( &switch_info.state_service_name_list, service_name );
    }
  }

  struct sigaction signal_exit;
  memset( &signal_exit, 0, sizeof( struct sigaction ) );
  signal_exit.sa_handler = handle_sigterm;
  sigaction( SIGINT, &signal_exit, NULL );
  sigaction( SIGTERM, &signal_exit, NULL );

  fcntl( switch_info.secure_channel_fd, F_SETFL, O_NONBLOCK );

  set_fd_handler( switch_info.secure_channel_fd, secure_channel_read, NULL, secure_channel_write, NULL );
  set_readable( switch_info.secure_channel_fd, true );
  set_writable( switch_info.secure_channel_fd, false );

  // default switch configuration
  switch_info.config_flags = OFPC_FRAG_NORMAL;
  switch_info.miss_send_len = UINT16_MAX;

  switch_info.fragment_buf = NULL;
  switch_info.send_queue = create_message_queue();
  switch_info.recv_queue = create_message_queue();
  switch_info.running_timer = false;
  switch_info.echo_request_xid = 0;

  init_xid_table();
  if ( switch_info.cookie_translation ) {
    init_cookie_table();
  }

  add_message_received_callback( get_trema_name(), service_recv );
  set_management_application_request_handler( management_recv, NULL );

  ret = switch_event_connected( &switch_info );
  if ( ret < 0 ) {
    error( "Failed to set connected state." );
    return -1;
  }
  ret = flush_secure_channel( &switch_info );
  if ( ret < 0 ) {
    error( "Failed to flush secure channel. Terminating %s.", argv[ 0 ] );
    return -1;
  }

  start_trema();

  // Note: init_event_forward_interface will be called on feature_reply.
  finalize_event_forward_interface();

  finalize_xid_table();
  if ( switch_info.cookie_translation ) {
    finalize_cookie_table();
  }

  if ( switch_info.secure_channel_fd >= 0 ) {
    delete_fd_handler( switch_info.secure_channel_fd );
  }

  return 0;
}
Exemplo n.º 16
0
int
main(int argc, char **argv)
{
/*****************test 1********************************/
	message_queue *tmp_queue;
	if((tmp_queue = create_message_queue()) == NULL)
	{
		printf("create queue error!\n");
    	return -1;
    }

    int i = 1;
    buffer *tmp_buf;
    char *tmp_char;

	tmp_char = *sample_string;
    while( tmp_char != NULL )
    {
       	tmp_buf = alloc_buffer_with_length(10);
        strcpy(tmp_buf->data, tmp_char);
        printf("the insert is %s, and %d\n",(char*)tmp_buf->data,sizeof(*(tmp_buf->data)));
        enqueue_message(tmp_queue, tmp_buf);
		tmp_char = sample_string[i];
        if(tmp_char == NULL)
            break;
        i++;
    }  

    int len;
    buffer *out;
    for( len = tmp_queue->length; len > 0; len-- )
    {
    	out = dequeue_message(tmp_queue);
        if(out->data == NULL)
            break;
        printf("%s\n", out->data);
        free_buffer(out);
  	}

    delete_message_queue(tmp_queue);
/*****************test 2********************************/

	message_queue *tmp_queue_;
   	if((tmp_queue_ = create_message_queue()) == NULL)
	{
		printf("create queue error!\n");
    	return -1;
    }
    int j = 1;
    buffer *tmp_buf_;
    char *tmp_char_;    
    
	tmp_char_ = *sample_string;
    while( tmp_char_ != NULL )
    {
       	tmp_buf_ = alloc_buffer_with_length(10);
        strcpy(tmp_buf_->data, tmp_char_);
        printf("the insert is %s, and %d\n",(char*)tmp_buf_->data,sizeof(*(tmp_buf_->data)));
        enqueue_message(tmp_queue_, tmp_buf_);
		tmp_char_ = sample_string[j];
        if(tmp_char_ == NULL)
            break;
        j++;
    }  

    delete_message_queue(tmp_queue_);
/*****************end of test********************************/


    return 0;
}
Exemplo n.º 17
0
Arquivo: switch.c Projeto: Darma/trema
int
main( int argc, char *argv[] ) {
  int ret;
  int i;
  char *service_name;
  char management_service_name[ MESSENGER_SERVICE_NAME_LENGTH ];

  init_trema( &argc, &argv );
  option_parser( argc, argv );

  create_list( &switch_info.vendor_service_name_list );
  create_list( &switch_info.packetin_service_name_list );
  create_list( &switch_info.portstatus_service_name_list );
  create_list( &switch_info.state_service_name_list );

  // FIXME
#define VENDER_PREFIX "vendor::"
#define PACKET_IN_PREFIX "packet_in::"
#define PORTSTATUS_PREFIX "port_status::"
#define STATE_PREFIX "state_notify::"
  for ( i = optind; i < argc; i++ ) {
    if ( strncmp( argv[i], VENDER_PREFIX, strlen( VENDER_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( VENDER_PREFIX ) );
      insert_in_front( &switch_info.vendor_service_name_list, service_name );
    }
    else if ( strncmp( argv[i], PACKET_IN_PREFIX, strlen( PACKET_IN_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( PACKET_IN_PREFIX ) );
      insert_in_front( &switch_info.packetin_service_name_list, service_name );
    }
    else if ( strncmp( argv[i], PORTSTATUS_PREFIX, strlen( PORTSTATUS_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( PORTSTATUS_PREFIX ) );
      insert_in_front( &switch_info.portstatus_service_name_list, service_name );
    }
    else if ( strncmp( argv[i], STATE_PREFIX, strlen( STATE_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( STATE_PREFIX ) );
      insert_in_front( &switch_info.state_service_name_list, service_name );
    }
  }

  struct sigaction signal_exit;
  memset( &signal_exit, 0, sizeof( struct sigaction ) );
  signal_exit.sa_handler = handle_sigterm;
  sigaction( SIGINT, &signal_exit, NULL );
  sigaction( SIGTERM, &signal_exit, NULL );

  fcntl( switch_info.secure_channel_fd, F_SETFL, O_NONBLOCK );

  set_fd_handler( switch_info.secure_channel_fd, secure_channel_read, NULL, secure_channel_write, NULL );
  set_readable( switch_info.secure_channel_fd, true );
  set_writable( switch_info.secure_channel_fd, false );

  // default switch configuration
  switch_info.config_flags = OFPC_FRAG_NORMAL;
  switch_info.miss_send_len = UINT16_MAX;

  switch_info.fragment_buf = NULL;
  switch_info.send_queue = create_message_queue();
  switch_info.recv_queue = create_message_queue();
  switch_info.running_timer = false;
  switch_info.echo_request_xid = 0;

  init_xid_table();
  if ( switch_info.cookie_translation ) {
    init_cookie_table();
  }

  add_message_received_callback( get_trema_name(), service_recv );

  snprintf( management_service_name , MESSENGER_SERVICE_NAME_LENGTH,
            "%s.m", get_trema_name() );
  management_service_name[ MESSENGER_SERVICE_NAME_LENGTH - 1 ] = '\0';
  add_message_received_callback( management_service_name, management_recv );

  ret = switch_event_connected( &switch_info );
  if ( ret < 0 ) {
    error( "Failed to set connected state." );
    return -1;
  }
  flush_secure_channel( &switch_info );

  start_trema();

  finalize_xid_table();
  if ( switch_info.cookie_translation ) {
    finalize_cookie_table();
  }

  if ( switch_info.secure_channel_fd >= 0 ) {
    delete_fd_handler( switch_info.secure_channel_fd );
  }

  return 0;
}
Exemplo n.º 18
0
/* loop inspired by yay
 * http://freecode.com/projects/yay
 */
Uint32 event_loop(void)
{
    char caption[256];
    Uint16 quit = 0;
    Uint32 frame = 0;
    int play_yuv = 0;
    unsigned int start_ticks = 0;

    while (!quit) {

        set_caption(caption, frame, 256);
        SDL_WM_SetCaption(caption, NULL);

        /* wait for SDL event */
        if (P.mode == NONE || P.mode == MASTER) {
            SDL_WaitEvent(&event);
        } else if (P.mode == SLAVE) {
            if (!event_dispatcher()) {
                SDL_WaitEvent(&event);
            }
        }

        switch (event.type)
        {
            case SDL_KEYDOWN:
                switch (event.key.keysym.sym)
                {
                    case SDLK_SPACE:
                        play_yuv = 1; /* play it, sam! */
                        while (play_yuv) {
                            start_ticks = SDL_GetTicks();
                            set_caption(caption, frame, 256);
                            SDL_WM_SetCaption( caption, NULL );

                            /* check for next frame existing */
                            if (read_frame()) {
                                draw_frame();
                                /* insert delay for real time viewing */
                                if (SDL_GetTicks() - start_ticks < 40)
                                    SDL_Delay(40 - (SDL_GetTicks() - start_ticks));
                                frame++;
                                send_message(NEXT);
                            } else {
                                play_yuv = 0;
                            }
                            /* check for any key event */
                            if (SDL_PollEvent(&event)) {
                                if (event.type == SDL_KEYDOWN) {
                                    /* stop playing */
                                    play_yuv = 0;
                                }
                            }
                        }
                        break;
                    case SDLK_RIGHT: /* next frame */
                        /* check for next frame existing */
                        if (read_frame()) {
                            draw_frame();
                            frame++;
                            send_message(NEXT);
                        }
                        break;
                    case SDLK_LEFT: /* previous frame */
                        if (frame > 1) {
                            frame--;
                            fseek(fd, ((frame-1) * P.frame_size), SEEK_SET);
                            if (P.diff) {
                                fseek(P.fd2, ((frame-1) * P.frame_size), SEEK_SET);
                            }
                            read_frame();
                            draw_frame();
                            send_message(PREV);
                        }
                        break;
                    case SDLK_UP: /* zoom in */
                        P.zoom++;
                        set_zoom_rect();
                        screen = SDL_SetVideoMode(P.zoom_width,
                                                  P.zoom_height,
                                                  P.bpp, P.vflags);
                        video_rect.w = P.zoom_width;
                        video_rect.h = P.zoom_height;
                        SDL_DisplayYUVOverlay(my_overlay, &video_rect);
                        send_message(ZOOM_IN);
                        break;
                    case SDLK_DOWN: /* zoom out */
                        P.zoom--;
                        set_zoom_rect();
                        screen = SDL_SetVideoMode(P.zoom_width,
                                                  P.zoom_height,
                                                  P.bpp, P.vflags);
                        video_rect.w = P.zoom_width;
                        video_rect.h = P.zoom_height;
                        SDL_DisplayYUVOverlay(my_overlay, &video_rect);
                        send_message(ZOOM_OUT);
                        break;
                    case SDLK_r: /* rewind */
                        if (frame > 1) {
                            frame = 1;
                            fseek(fd, 0, SEEK_SET);
                            if (P.diff) {
                                fseek(P.fd2, 0, SEEK_SET);
                            }
                            read_frame();
                            draw_frame();
                            send_message(REW);
                        }
                        break;
                    case SDLK_g: /* display grid */
                        P.grid = ~P.grid;
                        if (P.zoom < 1)
                            P.grid = 0;
                        draw_frame();
                        break;
                    case SDLK_m: /* show mb-data on stdout */
                        P.mb = ~P.mb;
                        if (P.zoom < 1)
                            P.mb = 0;
                        draw_frame();
                        break;
                    case SDLK_F5: /* Luma data only */
                        P.y_only = ~P.y_only;
                        P.cb_only = 0;
                        P.cr_only = 0;
                        draw_frame();
                        send_message(Y_ONLY);
                        break;
                    case SDLK_F6: /* Cb data only */
                        P.cb_only = ~P.cb_only;
                        P.y_only = 0;
                        P.cr_only = 0;
                        draw_frame();
                        send_message(CB_ONLY);
                        break;
                    case SDLK_F7: /* Cr data only */
                        P.cr_only = ~P.cr_only;
                        P.y_only = 0;
                        P.cb_only = 0;
                        send_message(CR_ONLY);
                        draw_frame();
                        break;
                    case SDLK_F8: /* display all color planes */
                        P.y_only = 0;
                        P.cb_only = 0;
                        P.cr_only = 0;
                        draw_frame();
                        send_message(ALL_PLANES);
                        break;
                    case SDLK_h: /* histogram */
                        P.hist = ~P.hist;
                        draw_frame();
                        break;
                    case SDLK_F1: /* MASTER-mode */
                        if (create_message_queue()) {
                            P.mode = MASTER;
                        }
                        break;
                    case SDLK_F2: /* SLAVE-mode */
                        if (P.mode == MASTER) {
                            destroy_message_queue();
                        }
                        if (connect_message_queue()) {
                            P.mode = SLAVE;
                        }
                        break;
                    case SDLK_F3: /* NONE-mode */
                        destroy_message_queue();
                        P.mode = NONE;
                        break;
                    case SDLK_q: /* quit */
                        quit = 1;
                        send_message(QUIT);
                        break;
                    default:
                        break;
                } /* switch key */
                break;
            case SDL_QUIT:
                quit = 1;
                break;
            case SDL_VIDEOEXPOSE:
                SDL_DisplayYUVOverlay(my_overlay, &video_rect);
                break;
            case SDL_MOUSEBUTTONDOWN:
                /* If the left mouse button was pressed */
                if (event.button.button == SDL_BUTTON_LEFT ) {
                    show_mb(event.button.x, event.button.y);
                }
                break;

            default:
                break;

        } /* switch event type */

    } /* while */

    return quit;
}
Exemplo n.º 19
0
int
main( int argc, char *argv[] ) {
  int ret;
  int i;
  char *service_name;
  char management_service_name[ MESSENGER_SERVICE_NAME_LENGTH ];

  init_trema( &argc, &argv );
  option_parser( argc, argv );

  create_list( &switch_info.vendor_service_name_list );
  create_list( &switch_info.packetin_service_name_list );
  create_list( &switch_info.portstatus_service_name_list );
  create_list( &switch_info.state_service_name_list );

  // FIXME
#define VENDER_PREFIX "vendor::"
#define PACKET_IN_PREFIX "packet_in::"
#define PORTSTATUS_PREFIX "port_status::"
#define STATE_PREFIX "state_notify::"
  for ( i = optind; i < argc; i++ ) {
    if ( strncmp( argv[i], VENDER_PREFIX, strlen( VENDER_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( VENDER_PREFIX ) );
      insert_in_front( &switch_info.vendor_service_name_list, service_name );
    }
    else if ( strncmp( argv[i], PACKET_IN_PREFIX, strlen( PACKET_IN_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( PACKET_IN_PREFIX ) );
      insert_in_front( &switch_info.packetin_service_name_list, service_name );
    }
    else if ( strncmp( argv[i], PORTSTATUS_PREFIX, strlen( PORTSTATUS_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( PORTSTATUS_PREFIX ) );
      insert_in_front( &switch_info.portstatus_service_name_list, service_name );
    }
    else if ( strncmp( argv[i], STATE_PREFIX, strlen( STATE_PREFIX ) ) == 0 ) {
      service_name = xstrdup( argv[i] + strlen( STATE_PREFIX ) );
      insert_in_front( &switch_info.state_service_name_list, service_name );
    }
  }

  fcntl( switch_info.secure_channel_fd, F_SETFL, O_NONBLOCK );
  // default switch configuration
  switch_info.config_flags = OFPC_FRAG_NORMAL;
  switch_info.miss_send_len = UINT16_MAX;

  switch_info.fragment_buf = NULL;
  switch_info.send_queue = create_message_queue();
  switch_info.recv_queue = create_message_queue();

  init_xid_table();
  init_cookie_table();

  set_fd_set_callback( secure_channel_fd_set );
  set_check_fd_isset_callback( secure_channel_fd_isset );
  add_message_received_callback( get_trema_name(), service_recv );

  snprintf( management_service_name , MESSENGER_SERVICE_NAME_LENGTH,
            "%s.m", get_trema_name() );
  management_service_name[ MESSENGER_SERVICE_NAME_LENGTH - 1 ] = '\0';
  add_message_received_callback( management_service_name, management_recv );

  ret = switch_event_connected( &switch_info );
  if ( ret < 0 ) {
    error( "Failed to set connected state." );
    return -1;
  }

  start_trema();

  finalize_xid_table();
  finalize_cookie_table();

  return 0;
}