Beispiel #1
0
void ui_input_manager::push_mouse_leave_event(render_target* target)
{
	ui_event event = { UI_EVENT_NONE };
	event.event_type = UI_EVENT_MOUSE_LEAVE;
	event.target = target;
	push_event(event);
}
Beispiel #2
0
void MyClass::read_attr(Tango::Attribute &attr)
{
    ...
    ...
    
    
    if (attr_name == "Sinusoide")
    {
        struct timeval tv;
        gettimeofday(&tv, NULL);
        sinusoide = 100 * sin( 2 * 3.14 * frequency * tv.tv_sec);
        attr.set_value(&sinusoide);
	
	if (sinusoide >= 0)              
        {
            vector<string> filterable_names;
            vector<double> filterable_value;
   
            filterable_names.push_back("value");
            filterable_value.push_back((double)sinusoide);
           
            push_event( filterable_names,
                        filterable_value,
                        attr);
			
            attr.set_value(&sinusoide);
	    
        }
      
    }
    
    ....
    ....
    
}
void RedClient::set_mouse_mode(uint32_t supported_modes, uint32_t current_mode)
{
    if (current_mode != _mouse_mode) {
        _mouse_mode = current_mode;
        Lock lock(_channels_lock);
        Channels::iterator iter = _channels.begin();
        for (; iter != _channels.end(); ++iter) {
            if ((*iter)->get_type() == SPICE_CHANNEL_CURSOR) {
                ((CursorChannel *)(*iter))->on_mouse_mode_change();
            }
        }
        AutoRef<MouseModeEvent> event(new MouseModeEvent(*this));
        push_event(*event);
    }
    // FIXME: use configured mouse mode (currently, use client mouse mode if supported by server)
    if ((supported_modes & SPICE_MOUSE_MODE_CLIENT) && (current_mode != SPICE_MOUSE_MODE_CLIENT)) {
        Message* message = new Message(SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST);
        SpiceMsgcMainMouseModeRequest mouse_mode_request;
        mouse_mode_request.mode = SPICE_MOUSE_MODE_CLIENT;
	_marshallers->msgc_main_mouse_mode_request(message->marshaller(),
						    &mouse_mode_request);

        post_message(message);
    }
}
Beispiel #4
0
static void set_input_ui_object_state (ui_object *obj, int flag)
{
	
	input_ui_object
		*input;

	input = obj->data;

	if (input->area.state != flag)
	{
							
		input->area.state = flag;

		if (flag)
		{

			set_alpha_event_functions (input_entry, input_end, input_abort);
		
	  		input_object = obj;

			push_event (set_input_events, "input events");
		}
		else
		{

			set_ui_object_text (obj, "");
		}

		set_ui_object_redraw (obj, TRUE);
	}
}
Beispiel #5
0
void check_circle_event(arc_t *i, double x0){

    if((i->e != NULL) && (i->e->x != x0)){

        i->e->valid = FALSE;    }

    i->e = NULL;

    if((i->prev == NULL)||(i->next == NULL)){
        return;
    }

    double x;
    point_t o;

    BOOL rst_circle = circle(i->prev->p, i->p, i->next->p, &x,&o);
    if(rst_circle == TRUE && x > x0){
        i->e = dispatch_event();
        i->e->x = x;
        i->e->p = o;
        i->e->a = i;
        i->e->valid = TRUE;

        push_event(i->e);
    }
}
void RedClient::on_connect()
{
    AutoRef<ConnectedEvent> event(new ConnectedEvent());
    push_event(*event);
    _migrate.add_channel(new MigChannel(SPICE_CHANNEL_MAIN, 0, get_common_caps(),
                                        get_caps()));
}
Beispiel #7
0
/*-------------------------------------------------
    push_char_event - pushes a char event
    to the specified render_target
-------------------------------------------------*/
void ui_input_manager::push_char_event(render_target* target, char32_t ch)
{
	ui_event event = { UI_EVENT_NONE };
	event.event_type = UI_EVENT_CHAR;
	event.target = target;
	event.ch = ch;
	push_event(event);
}
Beispiel #8
0
void setup_free_flight_quit_campaign_dialog (void)
{
	set_ui_object_drawable (free_flight_dialog_area, TRUE);

	set_ui_object_drawable (free_flight_quit_campaign_area, TRUE);

	push_event (quit_free_flight_set_events, "quit free flight events");
}
Beispiel #9
0
void ui_input_manager::push_mouse_rup_event(render_target* target, s32 x, s32 y)
{
	ui_event event = { UI_EVENT_NONE };
	event.event_type = UI_EVENT_MOUSE_RUP;
	event.target = target;
	event.mouse_x = x;
	event.mouse_y = y;
	push_event(event);
}
Beispiel #10
0
/*-------------------------------------------------
    push_mouse_double_click_event - pushes
    a mouse double-click event to the specified
    render_target
-------------------------------------------------*/
void ui_input_manager::push_mouse_double_click_event(render_target* target, s32 x, s32 y)
{
	ui_event event = { UI_EVENT_NONE };
	event.event_type = UI_EVENT_MOUSE_DOUBLE_CLICK;
	event.target = target;
	event.mouse_x = x;
	event.mouse_y = y;
	push_event(event);
}
Beispiel #11
0
void ui_input_manager::push_mouse_down_event(render_target* target, INT32 x, INT32 y)
{
	ui_event event = { UI_EVENT_NONE };
	event.event_type = UI_EVENT_MOUSE_DOWN;
	event.target = target;
	event.mouse_x = x;
	event.mouse_y = y;
	push_event(event);
}
Beispiel #12
0
/*
 *
 * ===  FUNCTION  ======================================================================
 *         Name:  stim_delay
 *  Description:  wait some milliseconds.It will blocking process until time out.
 * =====================================================================================
 */
void stim_delay ( uint16_t delayms)
{

  struct stim_event *event;
  __ASM("CPSID  I");  
  event = push_event(delayms,NULL,1);
  __ASM("CPSIE  I"); 
  while(event->now < event->interval);
}		/* -----  end of function stim_delay  ----- */
Beispiel #13
0
void RedClient::send_agent_monitors_config()
{
    AutoRef<MonitorsQuery > qury(new MonitorsQuery());
    push_event(*qury);
    (*qury)->wait();
    if (!(*qury)->success()) {
        THROW(" monitors query failed");
    }

    double min_distance = INFINITY;
    int dx = 0;
    int dy = 0;
    int i;

    std::vector<MonitorInfo>& monitors = (*qury)->get_monitors();
    std::vector<MonitorInfo>::iterator iter = monitors.begin();
    for (; iter != monitors.end(); iter++) {
        double distance = sqrt(pow((double)(*iter).position.x, 2) + pow((double)(*iter).position.y,
                                                                        2));
        if (distance < min_distance) {
            min_distance = distance;
            dx = -(*iter).position.x;
            dy = -(*iter).position.y;
        }
    }

    Message* message = new Message(SPICE_MSGC_MAIN_AGENT_DATA);
    VDAgentMessage* msg = (VDAgentMessage*)
      spice_marshaller_reserve_space(message->marshaller(), sizeof(VDAgentMessage));
    msg->protocol = VD_AGENT_PROTOCOL;
    msg->type = VD_AGENT_MONITORS_CONFIG;
    msg->opaque = 0;
    msg->size = sizeof(VDAgentMonitorsConfig) + monitors.size() * sizeof(VDAgentMonConfig);

    VDAgentMonitorsConfig* mon_config = (VDAgentMonitorsConfig*)
      spice_marshaller_reserve_space(message->marshaller(),
				     sizeof(VDAgentMonitorsConfig) + monitors.size() * sizeof(VDAgentMonConfig));
    mon_config->num_of_monitors = monitors.size();
    mon_config->flags = 0;
    if (Platform::is_monitors_pos_valid()) {
        mon_config->flags = VD_AGENT_CONFIG_MONITORS_FLAG_USE_POS;
    }
    for (iter = monitors.begin(), i = 0; iter != monitors.end(); iter++, i++) {
        mon_config->monitors[i].depth = (*iter).depth;
        mon_config->monitors[i].width = (*iter).size.x;
        mon_config->monitors[i].height = (*iter).size.y;
        mon_config->monitors[i].x = (*iter).position.x + dx;
        mon_config->monitors[i].y = (*iter).position.y + dy;
    }
    ASSERT(_agent_tokens)
    _agent_tokens--;
    post_message(message);
    _agent_mon_config_sent = true;
    _agent_reply_wait_type = VD_AGENT_MONITORS_CONFIG;
}
Beispiel #14
0
void ui_input_manager::push_mouse_wheel_event(render_target *target, s32 x, s32 y, short delta, int ucNumLines)
{
	ui_event event = { UI_EVENT_NONE };
	event.event_type = UI_EVENT_MOUSE_WHEEL;
	event.target = target;
	event.mouse_x = x;
	event.mouse_y = y;
	event.zdelta = delta;
	event.num_lines = ucNumLines;
	push_event(event);
}
Beispiel #15
0
void RedClient::on_channel_disconnected(RedChannel& channel)
{
    Lock lock(_notify_lock);
    if (_notify_disconnect) {
        _notify_disconnect = false;
        int connection_error = channel.get_connection_error();
        AutoRef<DisconnectedEvent> disconn_event(new DisconnectedEvent(connection_error));
        push_event(*disconn_event);
    }
    disconnect_channels();
    RedPeer::disconnect();
}
void throw_event( void* _event_handler_p, event_t _func, event_arg_t _arg )
{
    if ( !_func )
        return;

    event_handler_t* _event_handler = _event_handler_p;

    pthread_mutex_lock(&_event_handler->_mutex);

    push_event(&_event_handler->_events, &_event_handler->_events_count, _func, _arg);

    pthread_mutex_unlock(&_event_handler->_mutex);
}
Beispiel #17
0
static int window_poll(lua_State *L) 
{
	sf::RenderWindow *window = luaW_check<sf::RenderWindow>(L, 1);
	sf::Event event;
	if (window->pollEvent(event)) {
		push_event(L, event);
	} else {
		lua_pushboolean(L, 0 );
	}
	if (lua_istable(L, -1) || lua_isboolean(L, -1)) {
		return 1;
	}
	return luaL_error(L, "could not poll RenderWindow");
}
Beispiel #18
0
void push_timeout(Queue *queue, int time_ms, int type)
{
  struct timeval timeout, now;

  TimeoutEvent *event = (TimeoutEvent *)malloc(sizeof(TimeoutEvent));

  CHECK((gettimeofday(&now, NULL)) == 0);
  timeout.tv_sec = now.tv_sec + (time_ms / 1000);
  timeout.tv_usec = now.tv_usec + (time_ms % 1000) * 1000;

  event->time = timeout;
  event->next = event->prev = NULL;
  event->type = type;
  event->frame = NULL;

  push_event(event, queue);
}
Beispiel #19
0
/* Place and order array of timers */
int throw_timer_event ( void *(func)(void *), void *arg, unsigned timeout)
{
    static int _unique_id = 1;

    push_event(&event_handler.timed_events, &(event_handler.timed_events_count), func, arg );

    size_t _counter = event_handler.timed_events_count;

    event_handler.timed_events[_counter - 1].timeout = timeout + ((uint32_t)current_time_monotonic());
    event_handler.timed_events[_counter - 1].id = _unique_id;
    ++_unique_id;


    /* reorder */

    reorder_events(_counter, event_handler.timed_events, timeout );

    return _unique_id - 1;
}
Beispiel #20
0
void RedClient::handle_migrate_switch_host(RedPeer::InMessage* message)
{
    SpiceMsgMainMigrationSwitchHost* migrate = (SpiceMsgMainMigrationSwitchHost*)message->data();
    char* host = (char *)migrate->host_data;
    char* subject = NULL;

    if (host[migrate->host_size - 1] != '\0') {
        THROW("host is not a null-terminated string");
    }

    if (migrate->cert_subject_size) {
        subject = (char *)migrate->cert_subject_data;
        if (subject[migrate->cert_subject_size - 1] != '\0') {
            THROW("cert subject is not a null-terminated string");
        }
    }

    AutoRef<SwitchHostEvent> switch_event(new SwitchHostEvent(host,
                                                              migrate->port,
                                                              migrate->sport,
                                                              subject));
    push_event(*switch_event);
}
int throw_timer_event ( void* _event_handler_p, event_t _func, event_arg_t _arg, uint32_t _timeout)
{
    if ( !_func )
        return FAILURE;

    event_handler_t* _event_handler = _event_handler_p;

    pthread_mutex_lock(&_event_handler->_mutex);

    push_event(&_event_handler->_timed_events, &_event_handler->_timed_events_count, _func, _arg);
    size_t _counter = _event_handler->_timed_events_count;
    _event_handler->_timed_events[_counter - 1]._timeout = _timeout + t_time();
    _event_handler->_timed_events[_counter - 1]._id = _unique_id; ++_unique_id;


    /* reorder */
    if ( _counter > 1 ) {

        int i = _counter - 1;
        /* start from behind excluding last added member */
        event_container_t* _it = &_event_handler->_timed_events[i - 1];

        event_container_t _last_added = _event_handler->_timed_events[i];

        for ( ; i > 0; --i ) {
            if ( _it->_timeout > _timeout ){
                *(_it + 1) = *_it;
                *_it = _last_added; -- _it;
            }
        }

    }

    pthread_mutex_unlock(&_event_handler->_mutex);

    return _event_handler->_timed_events[_counter - 1]._id;
}
Beispiel #22
0
Uint32 ticker(Uint32 interval, void *p)
{
    push_event(EVENT_TICKER);
    return interval;
}
Beispiel #23
0
void comms_process_data (void)
{

	session_list_data_type
		*current_session;

	connection_list_type
		*this_connection,
		*connection;

	char
		*received_data;

	int
		planner_event,
		frame_id,
		packet_id,
		receive_flag,
		received_size;

	GUID
		received_id = 0;

	entity
		*member;

	send_types
		send_type;

	packet_types
		type;

	// receive all packets in queue

	current_session = get_current_game_session ();

	received_size = MAX_RECEIVE_SIZE;

	connection = get_connection_list_head ();

	while (connection)
	{

		this_connection = connection;

		connection = connection->next;

		send_type = SEND_TYPE_GROUP;

		while (send_type >= SEND_TYPE_PERSONAL)
		{

			receive_flag = TRUE;

			while (receive_flag)
			{

				type = process_packet_list (send_type, this_connection, &received_id, &received_data, &received_size);

				switch (type)
				{

					///////////////////////////////////////////////////////////////////////////////////////////////
					//
					// System packets, used internally
					//
					///////////////////////////////////////////////////////////////////////////////////////////////

					case PACKET_TYPE_INVALID:
					{

						receive_flag = FALSE;

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

							if (this_connection->packet_rerequested > command_line_comms_packet_rerequest_limit)
							{

								debug_log ("COMM_MAN: REJECTING CONNECTION. CONNECTION TOO BAD (re-request limit %d reached)", command_line_comms_packet_rerequest_limit);

								send_packet (this_connection->connection_id, PACKET_TYPE_SERVER_REJECTED, NULL, 0, SEND_TYPE_PERSONAL);
							}
						}

						break;
					}

					case PACKET_TYPE_RESEND_PACKET:
					{

						send_types
							resend_send_type;

						frame_id = get_list_item (received_data, int);

						packet_id = get_list_item (received_data, int);

						resend_send_type = get_list_item (received_data, send_types);

						#if DEBUG_MODULE

						if (this_connection->pilot_entity)
						{

							debug_log ("COMMS MAN: received RESEND PACKET for frame %d packet %d from %s (dpid %d)",
											frame_id, packet_id,
											get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
											received_id);
						}
						else
						{

							debug_log ("COMMS MAN: received RESEND PACKET by unknown (pdid %d)",
											received_id);
						}

						#endif

						resend_packet (received_id, frame_id, packet_id, resend_send_type);

						break;
					}

					///////////////////////////////////////////////////////////////////////////////////////////////
					//
					// Packets for initialisation and joining
					//
					///////////////////////////////////////////////////////////////////////////////////////////////

					case PACKET_TYPE_SESSION_QUERY:
					{

						char
							*ptr;

						int
							server_version_number,
							player_count,
							size;

						connection_list_type
							*new_connection;

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

							#if DEBUG_MODULE

							if (this_connection->pilot_entity)
							{

								debug_log ("COMMS MAN: RECEIVED SESSION QUERY from %s (dpid %d)",
												get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
												received_id);
							}
							else
							{

								debug_log ("COMMS MAN: RECEIVED SESSION QUERY from %d", received_id);
							}

							#endif

							new_connection = get_connection_list_item (received_id);

							if (!new_connection->already_sent_query_data)
							{

								new_connection->already_sent_query_data = TRUE;

								while (TRUE)
								{

									ptr = new_connection->connection_receive_buffer;

									size = 0;

									/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
									//
									// Check both client and server are running same campaign data
									//
									server_version_number = get_local_entity_int_value (get_session_entity (), INT_TYPE_VERSION_NUMBER);

									quick_set_list_item (ptr, int, server_version_number);

									size += sizeof (int);
									//
									/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

									// map details

									quick_set_list_item (ptr, int, NUM_MAP_X_SECTORS);

									quick_set_list_item (ptr, int, NUM_MAP_Z_SECTORS);

									quick_set_list_item (ptr, int, SECTOR_SIDE_LENGTH);

									size += sizeof (int) * 3;

									// data path

									strcpy (ptr, current_session->data_path);

									ptr += strlen (current_session->data_path) + 1;

									size += strlen (current_session->data_path) + 1;

									// population_placement filename

									if (population_placement_filename)
									{

										strcpy (ptr, population_placement_filename);

										ptr += strlen (population_placement_filename) + 1;

										size += strlen (population_placement_filename) + 1;
									}
									else
									{

										strcpy (ptr, "\0");

										ptr += strlen ("\0") + 1;

										size += strlen ("\0") + 1;
									}

									//

									// side_data filename

									if (side_data_filename)
									{

										strcpy (ptr, side_data_filename);

										ptr += strlen (side_data_filename) + 1;

										size += strlen (side_data_filename) + 1;
									}
									else
									{

										strcpy (ptr, "\0");

										ptr += strlen ("\0") + 1;

										size += strlen ("\0") + 1;
									}

									// campaign_population filename

									if (campaign_population_filename)
									{

										strcpy (ptr, campaign_population_filename);

										ptr += strlen (campaign_population_filename) + 1;

										size += strlen (campaign_population_filename) + 1;
									}
									else
									{

										strcpy (ptr, "\0");

										ptr += strlen ("\0") + 1;

										size += strlen ("\0") + 1;
									}

									//
									// planner position and zoom
									//

//									quick_set_list_item (ptr, float, planner_map_data.centre_map_x);

//									quick_set_list_item (ptr, float, planner_map_data.centre_map_z);

//									size += sizeof (float) * 2;

//									quick_set_list_item (ptr, int, planner_map_data.map_zoom);

//									size += sizeof (int);

									//
									// Pilots
									//

									player_count = get_number_of_connected_players ();

									quick_set_list_item (ptr, int, player_count);

									size += sizeof (int);

									//
									//
									//

									#if DEBUG_MODULE

									debug_log ("COMM_MAN: sending data path %s, population placement %s, side data %s, campaign_pop file %s",
													current_session->data_path, population_placement_filename, side_data_filename, campaign_population_filename);

									#endif

									new_connection->connection_receive_buffer_size -= size;

									if (!pack_session (ptr, &new_connection->connection_receive_buffer_size, PACK_MODE_BROWSE_SESSION))
									{

										break;
									}

									new_connection->connection_receive_buffer_size *= 2;

									#if DEBUG_MODULE

									debug_log ("COMMS MAN: Browse: connection_receive_buffer too small, mallocing to %d", new_connection->connection_receive_buffer_size);

									#endif

									free_mem (new_connection->connection_receive_buffer);

									new_connection->connection_receive_buffer = malloc_heap_mem (new_connection->connection_receive_buffer_size);
								}

								//
								//
								//

								send_packet (received_id, PACKET_TYPE_SESSION_INFO, new_connection->connection_receive_buffer, new_connection->connection_receive_buffer_size + size, SEND_TYPE_PERSONAL);

								/*
								{

									FILE
										*test_ptr;

									test_ptr = fopen ("out.txt", "wb");

									fwrite (new_connection->connection_receive_buffer, 1, new_connection->connection_receive_buffer_size + size, test_ptr);

									fclose (test_ptr);
								}
								*/
							}
							else
							{

								debug_log ("COMM_MAN: not resending query data");
							}
						}

						break;
					}

					case PACKET_TYPE_CONNECTION_VALIDATION:
					{

						debug_log ("COMM_MAN: received CONNECTION_VALIDATION, sending RESPONSE");

						send_packet (received_id, PACKET_TYPE_CONNECTION_RESPONSE, NULL, 0, SEND_TYPE_PERSONAL);

						break;
					}

					case PACKET_TYPE_CONNECTION_RESPONSE:
					{

						connection_list_type
							*connection;

						connection = get_connection_list_item (received_id);

						connection->validation_count = 0;

						debug_log ("COMM_MAN: received CONNECTION_RESPONSE, connection still alive");

						break;
					}

					case PACKET_TYPE_SESSION_INFO:
					{

						entity
							*force,
							*pilot;

						int
							client_version_number,
							server_version_number;

						int
							size,
							x_size,
							z_size,
							sector_size,
							player_count,
							loop;

						char
							*ptr,
							warzone_ffp_filename [256],
							temp_campaign_population_filename [256],
							temp_population_placement_filename [256],
							temp_side_data_filename [256],
							buffer [128];

						session_data = FALSE;

						reinitialise_entity_system ();

						ptr = received_data;

						size = 0;

						set_ui_object_redraw (gunships_screen, TRUE);

						ui_force_update ();

						/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
						//
						// Check both client and server are running same campaign data
						//
						client_version_number = get_global_version_number ();

						server_version_number = get_list_item (ptr, int);

						size += sizeof (int);

						if (client_version_number != server_version_number)
						{

							debug_fatal ("COMM_MAN: Incorrect version. Server Version No. %d, Client Version No. %d", server_version_number, client_version_number);
						}
						//
						/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

						// map details

						x_size = get_list_item (ptr, int);

						z_size = get_list_item (ptr, int);

						sector_size = get_list_item (ptr, int);

						size += (sizeof (int) * 3);

						set_entity_world_map_size (x_size, z_size, sector_size);

						// data path

						strncpy (current_session->data_path, ptr, sizeof (current_session->data_path));

						ptr += strlen (current_session->data_path) + 1;

						size += strlen (current_session->data_path) + 1;

						// population_placement_filename

						strncpy (temp_population_placement_filename, ptr, sizeof (temp_population_placement_filename));

						ptr += strlen (temp_population_placement_filename) + 1;

						size += strlen (temp_population_placement_filename) + 1;

						if (population_placement_filename)
						{

							free_mem (population_placement_filename);
						}

						if (strlen (temp_population_placement_filename) > 0)
						{

							population_placement_filename = (char *) malloc_heap_mem (strlen (temp_population_placement_filename) + 1);

							sprintf (population_placement_filename, "%s", temp_population_placement_filename);
						}
						else
						{

							population_placement_filename = NULL;
						}

						// side_data filename

						strncpy (temp_side_data_filename, ptr, sizeof (temp_side_data_filename));

						ptr += strlen (temp_side_data_filename) + 1;

						size += strlen (temp_side_data_filename) + 1;

						if (side_data_filename)
						{

							free_mem (side_data_filename);
						}

						if (strlen (temp_side_data_filename) > 0)
						{

							side_data_filename = (char *) malloc_heap_mem (strlen (temp_side_data_filename) + 1);

							sprintf (side_data_filename, "%s", temp_side_data_filename);
						}
						else
						{

							side_data_filename = NULL;
						}

						// campaign_population_filename

						strncpy (temp_campaign_population_filename, ptr, sizeof (temp_campaign_population_filename));

						ptr += strlen (temp_campaign_population_filename) + 1;

						size += strlen (temp_campaign_population_filename) + 1;

						if (campaign_population_filename)
						{

							free_mem (campaign_population_filename);
						}

						if (strlen (temp_campaign_population_filename) > 0)
						{

							campaign_population_filename = (char *) malloc_heap_mem (strlen (temp_campaign_population_filename) + 1);

							sprintf (campaign_population_filename, "%s", temp_campaign_population_filename);
						}
						else
						{

							campaign_population_filename = NULL;
						}

						//
						//
						//

						player_count = get_list_item (ptr, int);

						size += sizeof (int);

						//
						//
						//

						received_size -= size;

						#if DEBUG_MODULE

						debug_log ("COMM_MAN: data path %s population placement filename %s, side data filename %s", current_session->data_path, population_placement_filename, side_data_filename);

						debug_log ("COMM_MAN: campaign data path = %s", current_session->data_path);

						#endif

						//
						// check we have the correct warzone locally
						//

						sprintf (warzone_ffp_filename, "%s\\terrain\\terrain.ffp", current_session->data_path);

						if (!file_exist (warzone_ffp_filename))
						{

							add_to_pop_up_list_with_word_wrap (get_trans ("UNRECOGNISED_WARZONE"), session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);
							//add_to_pop_up_list (get_trans ("Server using unrecognised warzone"), session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);

							break;
						}

						//
						//
						//

						create_local_only_entities (PACK_MODE_BROWSE_SESSION);

						if (unpack_session (ptr, received_size, PACK_MODE_BROWSE_SESSION))
						{

							debug_fatal ("COMMS MAN: browse: received size overflow");
						}

						#if DEBUG_MODULE

						if (this_connection->pilot_entity)
						{

							debug_log ("COMMS MAN: received SESSION INFO from %s (dpid %d) (setting server id)",
											get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
											received_id);
						}
						else
						{

							debug_log ("COMMS MAN: RECEIVED SESSION INFO from %d", received_id);
						}

						debug_log ("COMMS MAN: session info: time of day = %f",
										get_local_entity_float_value (get_session_entity (), FLOAT_TYPE_TIME_OF_DAY));

						debug_log ("COMMS MAN: map dimensions %d, %d, sector size %d", x_size, z_size, sector_size);

						#endif

						set_ui_object_drawable (session_screen_next_button, TRUE);

						//
						// Display game info
						//

						ui_object_destroy_list_items (session_info_list);

						if (get_local_entity_int_value (get_session_entity (), INT_TYPE_CAMPAIGN_REQUIRES_APACHE_HAVOC))
						{

							// campaign requires apache havoc to be installed
							// check it is...

							if (!get_global_apache_havoc_installed ())
							{

								add_to_pop_up_list_with_word_wrap (get_trans ("REQUIRES_APACHE_HAVOC"), session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);

								set_ui_object_drawable (session_screen_next_button, FALSE);

								break;
							}
						}

						loop = 3;

						sprintf (buffer, "%s : %d", get_trans ("Players"), player_count);

						add_to_pop_up_list_with_word_wrap (buffer, session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);

						force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

						while (force)
						{

							pilot = get_local_entity_first_child (force, LIST_TYPE_PILOT);

							while (pilot)
							{
								{
									rgb_colour
										col;

									sprintf (buffer, "%2d  ", loop - 2);

									strncat (buffer, get_local_entity_string (pilot, STRING_TYPE_PILOTS_NAME), 64);

									switch (get_local_entity_int_value (pilot, INT_TYPE_SIDE))
									{
										case ENTITY_SIDE_BLUE_FORCE:
										{
											col.r = 120;
											col.g = 158;
											col.b = 255;
											col.a = 255;

											break;
										}
										case ENTITY_SIDE_RED_FORCE:
										{
											col.r = 255;
											col.g = 120;
											col.b = 80;
											col.a = 255;

											break;
										}
										default:
										{
									      col = ui_colour_white;

											break;
										}
									}

									add_to_pop_up_list_with_word_wrap (buffer, session_info_list, NULL, 0, UI_FONT_ARIAL_10, col);

									loop ++;
								}

								pilot = get_local_entity_child_succ (pilot, LIST_TYPE_PILOT);
							}

							force = get_local_entity_child_succ (force, LIST_TYPE_FORCE);
						}

						set_server_id (received_id);

						//
						// destroy all entities created by browse info
						//

						reinitialise_entity_system ();

						break;
					}

					case PACKET_TYPE_CLIENT_PILOT_REQUEST:
					{

						connection_list_type
							*new_connection;

						client_pilot_request_data
							pilot_data;

						entity
							*new_pilot;

						int
							index;

						ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: RECEIVED PILOT REQUEST from %d", received_id);

//						#endif

						//
						// unpack name
						//

						memcpy (&pilot_data, (client_pilot_request_data *) received_data, sizeof (client_pilot_request_data));

						new_pilot = create_new_pilot_entity
										(
											pilot_data.name,
											pilot_data.side,
											pilot_data.rank,
											pilot_data.sub_type,
											pilot_data.unique_id,
											pilot_data.difficulty
										);

						ASSERT (new_pilot);

						index = get_local_entity_safe_index (new_pilot);

						new_connection = get_connection_list_item (received_id);

						transmit_entity_comms_message (ENTITY_COMMS_PILOT_REQUEST_ACCEPTED, NULL, received_id, index);

						new_connection->pilot_entity = new_pilot;

						break;
					}

					case PACKET_TYPE_CLIENT_GUNSHIP_REQUEST:
					{

						connection_list_type
							*new_connection;

						client_gunship_request_data
							pilot_data;

						int
							index_number,
							buffer [2];

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

//							#if DEBUG_MODULE

							if (this_connection->pilot_entity)
							{

								debug_log ("COMMS MAN: RECEIVED GUNSHIP REQUEST from %s (dpid %d)",
												get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
												received_id);
							}
							else
							{

								debug_log ("COMMS MAN: RECEIVED GUNSHIP REQUEST from %d", received_id);
							}

//							#endif

							memcpy (&pilot_data, (client_gunship_request_data *) received_data, sizeof (client_gunship_request_data));

							index_number = pilot_data.gunship_index;

							ASSERT (index_number != ENTITY_INDEX_DONT_CARE);

							member = get_local_entity_safe_ptr (index_number);

							if (!member)
							{
//								#if DEBUG_MODULE

								if (this_connection->pilot_entity)
								{

									debug_log ("COMMS MAN: REFUSING GUNSHIP FOR PLAYER %s (dpid %d) for helicopter %d",
													get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
													received_id, pilot_data.gunship_index);
								}
								else
								{

									debug_log ("COMMS MAN: Refusing gunship for player %d to helicopter %d", received_id, pilot_data.gunship_index);
								}

//								#endif

								send_packet (received_id, PACKET_TYPE_GUNSHIP_REQUEST_REFUSED, NULL, 0, SEND_TYPE_PERSONAL);

								break;
							}

							new_connection = get_connection_list_item (received_id);

							//
							// send acceptance
							//

							buffer [0] = index_number;

//							#if DEBUG_MODULE

							debug_log ("COMMS MAN: sending gunship request accepted for gunship %d pilot id %d", index_number, received_id);

//							#endif

							send_packet (received_id, PACKET_TYPE_GUNSHIP_REQUEST_ACCEPTED, (void *) &buffer, 4, SEND_TYPE_PERSONAL);

							new_connection->gunship_number = pilot_data.gunship_index;

							new_connection->gunship_entity = member;
						}

						break;
					}

					case PACKET_TYPE_CLIENT_CAMPAIGN_DATA_REQUEST:
					{

						connection_list_type
							*new_connection;

						int
							index_number;

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

							#if DEBUG_MODULE

							if (this_connection->pilot_entity)
							{

								debug_log ("COMMS MAN: RECEIVED JOIN REQUEST by %s (dpid %d)",
												get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
												received_id);
							}
							else
							{

								debug_log ("COMMS MAN: received JOIN REQUEST by %d", received_id);
							}

							#endif

							//
							// flush group send buffer
							//

							send_comms_data ();

							//
							// pack mission data into packet
							//

							new_connection = get_connection_list_item (received_id);

							//
							// Store entity data
							//

							while (pack_session (new_connection->connection_receive_buffer, &new_connection->connection_receive_buffer_size, PACK_MODE_CLIENT_SESSION))
							{

								new_connection->connection_receive_buffer_size *= 2;

								#if DEBUG_MODULE

								debug_log ("COMMS MAN: Mission data: connection_receive_buffer too small, mallocing to %d", new_connection->connection_receive_buffer_size);

								#endif

								free_mem (new_connection->connection_receive_buffer);

								new_connection->connection_receive_buffer = malloc_heap_mem (new_connection->connection_receive_buffer_size);

								memset (new_connection->connection_receive_buffer, 0, new_connection->connection_receive_buffer_size);
							}

							// add frame id
							index_number = get_group_frame_id ();
							memcpy (&new_connection->connection_receive_buffer [new_connection->connection_receive_buffer_size], (void *) &index_number, sizeof (int));
							new_connection->connection_receive_buffer_size += sizeof (int);

							send_packet (received_id, PACKET_TYPE_MISSION_DATA, new_connection->connection_receive_buffer, new_connection->connection_receive_buffer_size, SEND_TYPE_PERSONAL);

							memset (new_connection->connection_receive_buffer, 0, new_connection->connection_receive_buffer_size);

							//
							// send group frame id
							//

							SDL_Delay (100);

							index_number = get_group_frame_id ();

							//send_packet (received_id, PACKET_TYPE_FRAME_ID, (void *) &index_number, 4, SEND_TYPE_PERSONAL);

							zero_average_pack_size ();
						}

						break;
					}

					case PACKET_TYPE_CLIENT_FRAME_ID:
					{

						int
							loop1,
							loop2,
							index_number;

						stub_packet_type
							*stub_packet;

						connection_list_type
							*new_connection;

						index_number = get_list_item (received_data, int);

						new_connection = get_connection_list_item (received_id);

						//#if DEBUG_MODULE

						if (new_connection)
						{

							debug_log ("COMMS MAN: received CLIENT FRAME ID (%d) by %d %s", index_number, received_id, direct_play_get_player_name (received_id));
						}

						//#endif

						//
						// send all packets between when the client started to join and when it actually joined.
						//

						for (loop1 = index_number; loop1 < get_group_frame_id () - 1; loop1 ++)
						{

							//#if DEBUG_MODULE

							debug_log ("COMMS MAN: sending packet %d frame %d to recently joined client", loop1, 0);

							//#endif

							stub_packet = resend_packet (received_id, loop1, 1, SEND_TYPE_GROUP);

							ASSERT (stub_packet);

							for (loop2 = 2; loop2 <= stub_packet->packet->number_of_packets; loop2 ++)
							{

								//#if DEBUG_MODULE

								debug_log ("COMMS MAN: sending packet %d frame %d to recently joined client", loop1, loop2);

								//#endif

								stub_packet = resend_packet (received_id, loop1, loop2, SEND_TYPE_GROUP);
							}
						}

						break;
					}

					case PACKET_TYPE_GUNSHIP_REQUEST_REFUSED:
					{

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: Gunship refused");

//						#endif

						set_server_response (SERVER_RESPONSE_REFUSE);

						break;
					}

					case PACKET_TYPE_GUNSHIP_REQUEST_ACCEPTED:
					{

						entity
							*gunship;

						int
							index_number;

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received GUNSHIP ACCEPTED by %d", received_id);

//						#endif

						//
						// set gunship
						//

						index_number = get_list_item (received_data, int);

						ASSERT (get_pilot_entity ());

						gunship = get_local_entity_safe_ptr (index_number);

						debug_filtered_log ("COMM_MAN: setting gunship");

						planner_event = FALSE;

						if (get_event_stack_head_function() == ingame_screen_set_events)
						{

							pop_event (ingame_screen_set_events);

							planner_event = TRUE;
						}

						assign_entity_to_user (gunship);

						if (planner_event)
						{

							push_event (ingame_screen_set_events, "ingame screen events");
						}

						debug_filtered_log ("COMM_MAN: gunship set");

						////////////////////////////////////////////////////////////////////////

						break;
					}

					case PACKET_TYPE_PILOT_REQUEST_ACCEPTED:
					{

						int
							index_number;

						ASSERT (get_comms_model () == COMMS_MODEL_CLIENT);

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received PILOT ACCEPTED by %d", received_id);

//						#endif

						index_number = get_list_item (received_data, int);

						set_pilot_entity (get_local_entity_safe_ptr (index_number));

						break;
					}

					case PACKET_TYPE_MISSION_DATA:
					{

						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received MISSION DATA by %d", received_id);

						#endif

						set_mouse_graphic_off ();

						//
						// LOAD TERRAIN DATA
						//

						load_3d_terrain_game_data ();

						initialise_population_name_database ();

						load_route_data (); // might need to send what route filename to load...

						//
						// Initialise stuff
						//

						create_local_only_entities (PACK_MODE_CLIENT_SESSION);

						/////////////////////////////////////////////////////////////////
						if (strstr ((char*) stoupper (side_data_filename), "SID"))
						{

							read_sector_side_file (side_data_filename);
						}
						else if (strstr ((char*) stoupper (side_data_filename), "DAT"))
						{

							load_ai_sector_data (side_data_filename);
						}
						/////////////////////////////////////////////////////////////////

						deinitialise_formation_database ();

						initialise_formation_database ();

						deinitialise_formation_component_database ();

						initialise_formation_component_database ();

						if (unpack_session (received_data, received_size - 4, PACK_MODE_CLIENT_SESSION))
						{

							debug_fatal ("COMMS MAN: received size overflow");
						}
/*
						force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

						while (force)
						{

							create_frontline (force);

							force = get_local_entity_child_succ (force, LIST_TYPE_FORCE);
						}

*/
						{
							int
								index_number;

							connection_list_type
								*new_connection;

							received_data += received_size - 4;
							index_number = get_list_item (received_data, int);

							new_connection = get_connection_list_item (received_id);

							new_connection->receive_group_frame_id = index_number;

							send_packet (get_server_id (), PACKET_TYPE_CLIENT_FRAME_ID, (void *) &index_number, 4, SEND_TYPE_PERSONAL);
						}

						session_data = TRUE;

						//direct_play_join_group ();

						set_gunship_waiting_for_connection ( FALSE );

						zero_average_pack_size ();

						set_mouse_graphic_on ();

						break;
					}

					case PACKET_TYPE_FRAME_ID:
					{

						int
							index_number;

						connection_list_type
							*new_connection;

						index_number = get_list_item (received_data, int);

						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received FRAME ID (%d) by %d", index_number, received_id);

						#endif

						new_connection = get_connection_list_item (received_id);

						new_connection->receive_group_frame_id = index_number;

						send_packet (get_server_id (), PACKET_TYPE_CLIENT_FRAME_ID, (void *) &index_number, 4, SEND_TYPE_PERSONAL);

						break;
					}

					///////////////////////////////////////////////////////////////////////////////////////////////
					//
					// In game packets
					//
					///////////////////////////////////////////////////////////////////////////////////////////////

					case PACKET_TYPE_AI_DATA:
					{

						int
							//padding,
							data_size;

						#if DEBUG_MODULE >= 2

						debug_log ("COMMS MAN: received AI DATA by %d", received_id);

						#endif

						if (get_comms_model () == COMMS_MODEL_CLIENT)
						{

							ASSERT (session_data);
						}

						data_size = get_list_item (received_data, int);

						//debug
						//padding = get_list_item (received_data, int);
						//end

						open_unpack_buffer (received_data, received_size);

						process_received_entity_comms_messages ();

						ASSERT (!get_unpack_buffer_overflow ());

						close_unpack_buffer ();

						//debug
						//padding = get_list_item (received_data, int);
						//end

						memset (received_data, 0, this_connection->connection_receive_buffer_size);

						break;
					}

					case PACKET_TYPE_END_GAME:
					{

						debug_log ("COMMS MAN: received END GAME from %d", received_id);

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{
							if (this_connection->gunship_entity)
							{

								set_client_server_entity_int_value (this_connection->gunship_entity, INT_TYPE_PLAYER, ENTITY_PLAYER_AI);
							}

							if (this_connection->pilot_entity)
							{

								debug_log ("	from %s ", get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME));
							}

							unregister_connection (received_id);
						}
						else
						{

							if (received_id == get_server_id ())
							{

								//setup_campaign_over_screen (get_local_force_entity (get_global_gunship_side ()), CAMPAIGN_RESULT_STALEMATE);

								start_game_exit (GAME_EXIT_KICKOUT, FALSE);
							}
						}

						receive_flag = FALSE;

						break;
					}

					case PACKET_TYPE_SERVER_REJECTED:
					{

						debug_log ("COMMS MAN: received SERVER REJECTED (server id %d)", received_id);

						//setup_campaign_over_screen (get_local_force_entity (get_global_gunship_side ()), CAMPAIGN_RESULT_SERVER_REJECTED);

						start_game_exit (GAME_EXIT_KICKOUT, FALSE);

						break;
					}

					default:
					{

						debug_fatal ("ERROR: Data Exchange, unknown packet type %d", type);

						break;
					}
				}
			}

			send_type --;
		}
	}
}
Beispiel #24
0
/** Get data and parse scancodes.
 *
 * @param arg Pointer to xt_kbd_t structure.
 *
 * @return EIO on error.
 *
 */
static int polling(void *arg)
{
	const xt_kbd_t *kbd = arg;
	
	assert(kbd);
	assert(kbd->parent_sess);
	
	async_exch_t *parent_exch = async_exchange_begin(kbd->parent_sess);
	
	while (true) {
		if (!parent_exch)
			parent_exch = async_exchange_begin(kbd->parent_sess);
		
		const unsigned int *map = scanmap_simple;
		size_t map_size = sizeof(scanmap_simple) / sizeof(unsigned int);
		
		uint8_t code = 0;
		ssize_t size = chardev_read(parent_exch, &code, 1);
		if (size != 1)
			return EIO;
		
		/* Ignore AT command reply */
		if ((code == KBD_ACK) || (code == KBD_RESEND))
			continue;
		
		/* Extended set */
		if (code == KBD_SCANCODE_SET_EXTENDED) {
			map = scanmap_e0;
			map_size = sizeof(scanmap_e0) / sizeof(unsigned int);
			
			size = chardev_read(parent_exch, &code, 1);
			if (size != 1)
				return EIO;
			
			/* Handle really special keys */
			
			if (code == 0x2a) {  /* Print Screen */
				size = chardev_read(parent_exch, &code, 1);
				if (size != 1)
					return EIO;
				
				if (code != 0xe0)
					continue;
				
				size = chardev_read(parent_exch, &code, 1);
				if (size != 1)
					return EIO;
				
				if (code == 0x37)
					push_event(kbd->client_sess, KEY_PRESS, KC_PRTSCR);
				
				continue;
			}
			
			if (code == 0x46) {  /* Break */
				size = chardev_read(parent_exch, &code, 1);
				if (size != 1)
					return EIO;
				
				if (code != 0xe0)
					continue;
				
				size = chardev_read(parent_exch, &code, 1);
				if (size != 1)
					return EIO;
				
				if (code == 0xc6)
					push_event(kbd->client_sess, KEY_PRESS, KC_BREAK);
				
				continue;
			}
		}
		
		/* Extended special set */
		if (code == KBD_SCANCODE_SET_EXTENDED_SPECIAL) {
			size = chardev_read(parent_exch, &code, 1);
			if (size != 1)
				return EIO;
			
			if (code != 0x1d)
				continue;
			
			size = chardev_read(parent_exch, &code, 1);
			if (size != 1)
				return EIO;
			
			if (code != 0x45)
				continue;
			
			size = chardev_read(parent_exch, &code, 1);
			if (size != 1)
				return EIO;
			
			if (code != 0xe1)
				continue;
			
			size = chardev_read(parent_exch, &code, 1);
			if (size != 1)
				return EIO;
			
			if (code != 0x9d)
				continue;
			
			size = chardev_read(parent_exch, &code, 1);
			if (size != 1)
				return EIO;
			
			if (code == 0xc5)
				push_event(kbd->client_sess, KEY_PRESS, KC_PAUSE);
			
			continue;
		}
		
		/* Bit 7 indicates press/release */
		const kbd_event_type_t type =
		    (code & 0x80) ? KEY_RELEASE : KEY_PRESS;
		code &= ~0x80;
		
		const unsigned int key = (code < map_size) ? map[code] : 0;
		
		if (key != 0)
			push_event(kbd->client_sess, type, key);
		else
			ddf_msg(LVL_WARN, "Unknown scancode: %hhx", code);
	}
}
Beispiel #25
0
//-----------------------------------------------------------------------------
void event_loop()
{
	XEvent event;

	OSEventParameter data_button[4] = {0, 0, 0, 0};
	OSEventParameter data_key[4] = {0, 0, 0, 0};

	while (XPending(display))
	{
		XNextEvent(display, &event);

		switch (event.type)
		{
			case ConfigureNotify:
			{
				window_x = event.xconfigure.x;
				window_y = event.xconfigure.y;
				window_width = event.xconfigure.width;
				window_height = event.xconfigure.height;

				break;
			}
			case ButtonPress:
			case ButtonRelease:
			{
				OSEventType oset_type = event.type == ButtonPress ? OSET_BUTTON_PRESS : OSET_BUTTON_RELEASE;

				data_button[0].int_value = event.xbutton.x;
				data_button[1].int_value = event.xbutton.y;

				switch (event.xbutton.button)
				{
					case Button1:
					{
						data_button[2].int_value = 0;
						push_event(oset_type, data_button[0], data_button[1], data_button[2], data_button[3]);
						break;
					}
					case Button2:
					{
						data_button[2].int_value = 1;
						push_event(oset_type, data_button[0], data_button[1], data_button[2], data_button[3]);
						break;
					}
					case Button3:
					{
						data_button[2].int_value = 2;
						push_event(oset_type, data_button[0], data_button[1], data_button[2], data_button[3]);
						break;
					}
				}

				break;
			}
			case MotionNotify:
			{
				push_event(OSET_MOTION_NOTIFY, data_button[0], data_button[1], data_button[2], data_button[3]);
				break;
			}
			case KeyPress:
			case KeyRelease:
			{
				char string[4] = {0, 0, 0, 0};
				int32_t len = -1;
				KeySym key;

				len = XLookupString(&event.xkey, string, 4, &key, NULL);

				Key kc = x11_translate_key(key);

				// Check if any modifier key is pressed or released
				int32_t modifier_mask = 0;

				if (kc == KC_LSHIFT || kc == KC_RSHIFT)
				{
					(event.type == KeyPress) ? modifier_mask |= MK_SHIFT : modifier_mask &= ~MK_SHIFT;
				}
				else if (kc == KC_LCONTROL || kc == KC_RCONTROL)
				{
					(event.type == KeyPress) ? modifier_mask |= MK_CTRL : modifier_mask &= ~MK_CTRL;
				}
				else if (kc == KC_LALT || kc == KC_RALT)
				{
					(event.type == KeyPress) ? modifier_mask |= MK_ALT : modifier_mask &= ~MK_ALT;
				}

				OSEventType oset_type = event.type == KeyPress ? OSET_KEY_PRESS : OSET_KEY_RELEASE;

				data_key[0].int_value = ((int32_t)kc);
				data_key[1].int_value = modifier_mask;

				push_event(oset_type, data_key[0], data_key[1], data_key[2], data_key[3]);

//				// Text input part
//				if (event.type == KeyPress && len > 0)
//				{
//					//crownEvent.event_type = ET_TEXT;
//					//crownEvent.text.type = TET_TEXT_INPUT;
//					strncpy(keyboardEvent.text, string, 4);

//					if (mListener)
//					{
//						mListener->TextInput(keyboardEvent);
//					}
//				}

				break;
			}
			case KeymapNotify:
			{
				XRefreshKeyboardMapping(&event.xmapping);
				break;
			}
			default:
			{
				break;
			}
		}
	}
}
Beispiel #26
0
void qd_entity_cache_add(const char *type, void *object) { push_event(ADD, type, object); }
Beispiel #27
0
void qd_entity_cache_remove(const char *type, void *object) { push_event(REMOVE, type, object); }
void ProcessLoop::quit(int error_code)
{
    AutoRef<QuitEvent> quit_event(new QuitEvent(error_code));
    push_event(*quit_event);
}
Beispiel #29
0
/** Get data and parse scancodes.
 *
 * @param arg Pointer to at_kbd_t structure.
 *
 * @return EIO on error.
 *
 */
static int polling(void *arg)
{
    const at_kbd_t *kbd = arg;

    assert(kbd);
    assert(kbd->parent_sess);

    async_exch_t *parent_exch = async_exchange_begin(kbd->parent_sess);

    while (true) {
        if (!parent_exch)
            parent_exch = async_exchange_begin(kbd->parent_sess);

        uint8_t code = 0;
        ssize_t size = chardev_read(parent_exch, &code, 1);
        if (size != 1)
            return EIO;

        const unsigned int *map;
        size_t map_size;

        if (code == KBD_SCANCODE_SET_EXTENDED) {
            map = scanmap_e0;
            map_size = sizeof(scanmap_e0) / sizeof(unsigned int);

            size = chardev_read(parent_exch, &code, 1);
            if (size != 1)
                return EIO;
        } else if (code == KBD_SCANCODE_SET_EXTENDED_SPECIAL) {
            size = chardev_read(parent_exch, &code, 1);
            if (size != 1)
                return EIO;
            if (code != 0x14)
                continue;

            size = chardev_read(parent_exch, &code, 1);
            if (size != 1)
                return EIO;
            if (code != 0x77)
                continue;

            size = chardev_read(parent_exch, &code, 1);
            if (size != 1)
                return EIO;
            if (code != 0xe1)
                continue;

            size = chardev_read(parent_exch, &code, 1);
            if (size != 1)
                return EIO;
            if (code != 0xf0)
                continue;

            size = chardev_read(parent_exch, &code, 1);
            if (size != 1)
                return EIO;
            if (code != 0x14)
                continue;

            size = chardev_read(parent_exch, &code, 1);
            if (size != 1)
                return EIO;
            if (code != 0xf0)
                continue;

            size = chardev_read(parent_exch, &code, 1);
            if (size != 1)
                return EIO;
            if (code == 0x77)
                push_event(kbd->client_sess, KEY_PRESS, KC_BREAK);

            continue;
        } else {
            map = scanmap_simple;
            map_size = sizeof(scanmap_simple) / sizeof(unsigned int);
        }

        kbd_event_type_t type;
        if (code == KBD_SCANCODE_KEY_RELEASE) {
            type = KEY_RELEASE;
            size = chardev_read(parent_exch, &code, 1);
            if (size != 1)
                return EIO;
        } else {
            type = KEY_PRESS;
        }

        const unsigned int key = (code < map_size) ? map[code] : 0;

        if (key != 0)
            push_event(kbd->client_sess, type, key);
        else
            ddf_msg(LVL_WARN, "Unknown scancode: %hhx", code);
    }
}
Beispiel #30
0
/* The following is called from the serial driver when bytes/breaks
 * are received on the Mouse line.
 */
void
sun_mouse_inbyte(unsigned char byte, int is_break)
{
	signed char mvalue;
	int d, pushed = 0;
	Firm_event ev;

	add_mouse_randomness (byte);
#if 0
	{
		static int xxx = 0;
		printk("mouse(%02x:%d) ",
		       byte, is_break);
		if (byte == 0x87) {
			xxx = 0;
			printk("\n");
		}
	}
#endif
	if (mouse_baud_detection(byte, is_break))
		return;

	if(!sunmouse.active)
		return;

	/* Ignore this if it is garbage. */
	if (sunmouse.byte == 69) {
		if (byte != 0x87)
			return;

		/* Ok, we've begun the state machine. */
		sunmouse.byte = 0;
	}
#if 0
	/* If the mouse sends us a byte from 0x80 to 0x87
	 * we are starting at byte zero in the transaction
	 * protocol.
	 */
	if(byte >= 0x80 && byte <= 0x87)
		sunmouse.byte = 0;
#endif

	mvalue = (signed char) byte;
	switch(sunmouse.byte) {
	case 0:
		/* If we get a bogus button byte, just skip it.
		 * When we get here the baud detection code has
		 * passed, so the only other things which can
		 * cause this are dropped serial characters and
		 * confused mouse.  We check this because otherwise
		 * begin posting erroneous mouse events.
		 */
		if ((byte & 0xf0) != 0x80)
			return;

		/* Button state */
		sunmouse.button_state = (~byte) & 0x7;
#ifdef SMOUSE_DEBUG
		printk("B<Left %s, Middle %s, Right %s>",
		       ((sunmouse.button_state & 0x4) ? "DOWN" : "UP"),
		       ((sunmouse.button_state & 0x2) ? "DOWN" : "UP"),
		       ((sunmouse.button_state & 0x1) ? "DOWN" : "UP"));
#endif
		sunmouse.byte++;
		return;
	case 1:
		/* Delta-x 1 */
#ifdef SMOUSE_DEBUG
		printk("DX1<%d>", mvalue);
#endif
		sunmouse.delta_x = mvalue;
		sunmouse.byte++;
		return;
	case 2:
		/* Delta-y 1 */
#ifdef SMOUSE_DEBUG
		printk("DY1<%d>", mvalue);
#endif
		sunmouse.delta_y = mvalue;
		sunmouse.byte++;
		return;
	case 3:
		/* Delta-x 2 */
#ifdef SMOUSE_DEBUG
		printk("DX2<%d>", mvalue);
#endif
		sunmouse.delta_x += mvalue;
		sunmouse.delta_x = CLIP(sunmouse.delta_x);
		sunmouse.byte++;
		return;
	case 4:
		/* Last byte, Delta-y 2 */
#ifdef SMOUSE_DEBUG
		printk("DY2<%d>", mvalue);
#endif
		sunmouse.delta_y += mvalue;
		sunmouse.delta_y = CLIP(sunmouse.delta_y);
		sunmouse.byte = 0;  /* Back to button state */
		break;
	case 69:
		/* Until we get the (0x80 -> 0x87) value we aren't
		 * in the middle of a real transaction, so just
		 * return.
		 */
		return;
	default:
		printk("sunmouse: bogon transaction state\n");
		sunmouse.byte = 69;  /* What could cause this? */
		return;
	};
	if (!gen_events){
		push_char (~sunmouse.button_state & 0x87);
		push_char (sunmouse.delta_x);
		push_char (sunmouse.delta_y);
		return;
	}
	d = bstate ^ pstate;
	pstate = bstate;
	if (d){
		if (d & BUTTON_LEFT){
			ev.id = MS_LEFT;
			ev.value = bstate & BUTTON_LEFT;
		}
		if (d & BUTTON_RIGHT){
			ev.id = MS_RIGHT;
			ev.value = bstate & BUTTON_RIGHT;
		}
		if (d & BUTTON_MIDDLE){
			ev.id = MS_MIDDLE;
			ev.value = bstate & BUTTON_MIDDLE;
		}
		ev.time = xtime;
		ev.value = ev.value ? VKEY_DOWN : VKEY_UP;
		pushed += push_event (&ev);
	}
	if (sunmouse.delta_x){
		ev.id = LOC_X_DELTA;
		ev.time = xtime;
		ev.value = sunmouse.delta_x;
		pushed += push_event (&ev);
		sunmouse.delta_x = 0;
	}
	if (sunmouse.delta_y){
		ev.id = LOC_Y_DELTA;
		ev.time = xtime;
		ev.value = sunmouse.delta_y;
		pushed += push_event (&ev);
	}
	
	if(pushed != 0) {
		/* We just completed a transaction, wake up whoever is awaiting
		 * this event.
		 */
		sunmouse.ready = 1;
		if (sunmouse.fasync)
			kill_fasync (sunmouse.fasync, SIGIO);
		wake_up_interruptible(&sunmouse.proc_list);
	}
	return;
}