2000-05-30 19:48:18 +00:00
|
|
|
/*
|
|
|
|
* Server-side message queues
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000 Alexandre Julliard
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-05-30 19:48:18 +00:00
|
|
|
*/
|
|
|
|
|
2002-04-26 19:05:15 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2000-05-30 19:48:18 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2001-05-18 22:51:56 +00:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
|
2000-05-30 19:48:18 +00:00
|
|
|
#include "handle.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "process.h"
|
|
|
|
#include "request.h"
|
2001-08-28 18:44:52 +00:00
|
|
|
#include "user.h"
|
2000-05-30 19:48:18 +00:00
|
|
|
|
2001-08-07 19:19:08 +00:00
|
|
|
enum message_kind { SEND_MESSAGE, POST_MESSAGE, COOKED_HW_MESSAGE, RAW_HW_MESSAGE };
|
|
|
|
#define NB_MSG_KINDS (RAW_HW_MESSAGE+1)
|
|
|
|
|
|
|
|
|
2001-05-18 22:51:56 +00:00
|
|
|
struct message_result
|
|
|
|
{
|
|
|
|
struct message_result *send_next; /* next in sender list */
|
|
|
|
struct message_result *recv_next; /* next in receiver list */
|
|
|
|
struct msg_queue *sender; /* sender queue */
|
|
|
|
struct msg_queue *receiver; /* receiver queue */
|
|
|
|
int replied; /* has it been replied to? */
|
|
|
|
unsigned int result; /* reply result */
|
|
|
|
unsigned int error; /* error code to pass back to sender */
|
2001-08-07 19:19:08 +00:00
|
|
|
void *data; /* message reply data */
|
|
|
|
unsigned int data_size; /* size of message reply data */
|
|
|
|
struct timeout_user *timeout; /* result timeout */
|
2001-05-18 22:51:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct message
|
|
|
|
{
|
|
|
|
struct message *next; /* next message in list */
|
|
|
|
struct message *prev; /* prev message in list */
|
2001-08-07 19:19:08 +00:00
|
|
|
enum message_type type; /* message type */
|
2001-08-28 18:44:52 +00:00
|
|
|
user_handle_t win; /* window handle */
|
2001-05-18 22:51:56 +00:00
|
|
|
unsigned int msg; /* message code */
|
|
|
|
unsigned int wparam; /* parameters */
|
|
|
|
unsigned int lparam; /* parameters */
|
2001-08-07 19:19:08 +00:00
|
|
|
int x; /* x position */
|
|
|
|
int y; /* y position */
|
2001-06-19 19:16:41 +00:00
|
|
|
unsigned int time; /* message time */
|
2001-05-18 22:51:56 +00:00
|
|
|
unsigned int info; /* extra info */
|
2001-08-07 19:19:08 +00:00
|
|
|
void *data; /* message data for sent messages */
|
|
|
|
unsigned int data_size; /* size of message data */
|
2001-05-18 22:51:56 +00:00
|
|
|
struct message_result *result; /* result in sender queue */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct message_list
|
|
|
|
{
|
|
|
|
struct message *first; /* head of list */
|
|
|
|
struct message *last; /* tail of list */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct timer
|
|
|
|
{
|
|
|
|
struct timer *next; /* next timer in list */
|
|
|
|
struct timer *prev; /* prev timer in list */
|
|
|
|
struct timeval when; /* next expiration */
|
|
|
|
unsigned int rate; /* timer rate in ms */
|
2001-08-28 18:44:52 +00:00
|
|
|
user_handle_t win; /* window handle */
|
2001-05-18 22:51:56 +00:00
|
|
|
unsigned int msg; /* message to post */
|
|
|
|
unsigned int id; /* timer id */
|
|
|
|
unsigned int lparam; /* lparam for message */
|
|
|
|
};
|
|
|
|
|
2002-10-11 18:50:15 +00:00
|
|
|
struct thread_input
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
user_handle_t focus; /* focus window */
|
|
|
|
user_handle_t capture; /* capture window */
|
|
|
|
user_handle_t active; /* active window */
|
|
|
|
user_handle_t menu_owner; /* current menu owner window */
|
|
|
|
user_handle_t move_size; /* current moving/resizing window */
|
|
|
|
user_handle_t caret; /* caret window */
|
|
|
|
rectangle_t rect; /* caret rectangle */
|
|
|
|
unsigned char keystate[256]; /* state of each key */
|
|
|
|
};
|
|
|
|
|
2000-05-30 19:48:18 +00:00
|
|
|
struct msg_queue
|
|
|
|
{
|
2001-05-18 22:51:56 +00:00
|
|
|
struct object obj; /* object header */
|
|
|
|
unsigned int wake_bits; /* wakeup bits */
|
|
|
|
unsigned int wake_mask; /* wakeup mask */
|
|
|
|
unsigned int changed_bits; /* changed wakeup bits */
|
|
|
|
unsigned int changed_mask; /* changed wakeup mask */
|
2001-06-20 22:55:31 +00:00
|
|
|
int paint_count; /* pending paint messages count */
|
2001-06-19 19:16:41 +00:00
|
|
|
struct message_list msg_list[NB_MSG_KINDS]; /* lists of messages */
|
2001-05-18 22:51:56 +00:00
|
|
|
struct message_result *send_result; /* stack of sent messages waiting for result */
|
|
|
|
struct message_result *recv_result; /* stack of received messages waiting for result */
|
2001-06-28 04:37:22 +00:00
|
|
|
struct message *last_msg; /* last msg returned to the app and not removed */
|
|
|
|
enum message_kind last_msg_kind; /* message kind of last_msg */
|
2001-05-18 22:51:56 +00:00
|
|
|
struct timer *first_timer; /* head of timer list */
|
|
|
|
struct timer *last_timer; /* tail of timer list */
|
|
|
|
struct timer *next_timer; /* next timer to expire */
|
|
|
|
struct timeout_user *timeout; /* timeout for next timer to expire */
|
2002-10-11 18:50:15 +00:00
|
|
|
struct thread_input *input; /* thread input descriptor */
|
2000-05-30 19:48:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void msg_queue_dump( struct object *obj, int verbose );
|
|
|
|
static int msg_queue_add_queue( struct object *obj, struct wait_queue_entry *entry );
|
|
|
|
static void msg_queue_remove_queue( struct object *obj, struct wait_queue_entry *entry );
|
|
|
|
static int msg_queue_signaled( struct object *obj, struct thread *thread );
|
|
|
|
static int msg_queue_satisfied( struct object *obj, struct thread *thread );
|
2001-05-18 22:51:56 +00:00
|
|
|
static void msg_queue_destroy( struct object *obj );
|
2002-10-11 18:50:15 +00:00
|
|
|
static void thread_input_dump( struct object *obj, int verbose );
|
|
|
|
static void thread_input_destroy( struct object *obj );
|
2001-05-18 22:51:56 +00:00
|
|
|
static void timer_callback( void *private );
|
2000-05-30 19:48:18 +00:00
|
|
|
|
|
|
|
static const struct object_ops msg_queue_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct msg_queue), /* size */
|
|
|
|
msg_queue_dump, /* dump */
|
|
|
|
msg_queue_add_queue, /* add_queue */
|
|
|
|
msg_queue_remove_queue, /* remove_queue */
|
|
|
|
msg_queue_signaled, /* signaled */
|
|
|
|
msg_queue_satisfied, /* satisfied */
|
|
|
|
NULL, /* get_poll_events */
|
|
|
|
NULL, /* poll_event */
|
2000-12-19 02:12:45 +00:00
|
|
|
no_get_fd, /* get_fd */
|
2000-05-30 19:48:18 +00:00
|
|
|
no_flush, /* flush */
|
|
|
|
no_get_file_info, /* get_file_info */
|
2001-12-20 00:07:05 +00:00
|
|
|
NULL, /* queue_async */
|
2001-05-18 22:51:56 +00:00
|
|
|
msg_queue_destroy /* destroy */
|
2000-05-30 19:48:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-10-11 18:50:15 +00:00
|
|
|
static const struct object_ops thread_input_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct thread_input), /* size */
|
|
|
|
thread_input_dump, /* dump */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
|
|
|
NULL, /* get_poll_events */
|
|
|
|
NULL, /* poll_event */
|
|
|
|
no_get_fd, /* get_fd */
|
|
|
|
no_flush, /* flush */
|
|
|
|
no_get_file_info, /* get_file_info */
|
|
|
|
NULL, /* queue_async */
|
|
|
|
thread_input_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* create a thread input object */
|
|
|
|
static struct thread_input *create_thread_input(void)
|
|
|
|
{
|
|
|
|
struct thread_input *input;
|
|
|
|
|
|
|
|
if ((input = alloc_object( &thread_input_ops, -1 )))
|
|
|
|
{
|
|
|
|
input->focus = 0;
|
|
|
|
input->capture = 0;
|
|
|
|
input->active = 0;
|
|
|
|
input->menu_owner = 0;
|
|
|
|
input->move_size = 0;
|
|
|
|
input->caret = 0;
|
|
|
|
input->rect.left = 0;
|
|
|
|
input->rect.top = 0;
|
|
|
|
input->rect.right = 0;
|
|
|
|
input->rect.bottom = 0;
|
|
|
|
memset( input->keystate, 0, sizeof(input->keystate) );
|
|
|
|
}
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pointer to input structure of foreground thread */
|
|
|
|
static struct thread_input *foreground_input;
|
|
|
|
|
|
|
|
/* create a message queue object */
|
|
|
|
static struct msg_queue *create_msg_queue( struct thread *thread, struct thread_input *input )
|
2000-05-30 19:48:18 +00:00
|
|
|
{
|
|
|
|
struct msg_queue *queue;
|
2001-06-19 19:16:41 +00:00
|
|
|
int i;
|
2000-05-30 19:48:18 +00:00
|
|
|
|
2002-10-11 18:50:15 +00:00
|
|
|
if (!input && !(input = create_thread_input())) return NULL;
|
2000-05-30 19:48:18 +00:00
|
|
|
if ((queue = alloc_object( &msg_queue_ops, -1 )))
|
|
|
|
{
|
2001-05-18 22:51:56 +00:00
|
|
|
queue->wake_bits = 0;
|
|
|
|
queue->wake_mask = 0;
|
|
|
|
queue->changed_bits = 0;
|
|
|
|
queue->changed_mask = 0;
|
2001-06-20 22:55:31 +00:00
|
|
|
queue->paint_count = 0;
|
2001-05-18 22:51:56 +00:00
|
|
|
queue->send_result = NULL;
|
|
|
|
queue->recv_result = NULL;
|
2001-06-28 04:37:22 +00:00
|
|
|
queue->last_msg = NULL;
|
2001-05-18 22:51:56 +00:00
|
|
|
queue->first_timer = NULL;
|
|
|
|
queue->last_timer = NULL;
|
|
|
|
queue->next_timer = NULL;
|
|
|
|
queue->timeout = NULL;
|
2002-10-11 18:50:15 +00:00
|
|
|
queue->input = (struct thread_input *)grab_object( input );
|
2001-06-19 19:16:41 +00:00
|
|
|
for (i = 0; i < NB_MSG_KINDS; i++)
|
|
|
|
queue->msg_list[i].first = queue->msg_list[i].last = NULL;
|
|
|
|
|
2000-05-30 19:48:18 +00:00
|
|
|
thread->queue = queue;
|
|
|
|
if (!thread->process->queue)
|
|
|
|
thread->process->queue = (struct msg_queue *)grab_object( queue );
|
|
|
|
}
|
2002-10-11 18:50:15 +00:00
|
|
|
release_object( input );
|
2000-05-30 19:48:18 +00:00
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
|
2002-08-16 23:30:41 +00:00
|
|
|
/* free the message queue of a thread at thread exit */
|
|
|
|
void free_msg_queue( struct thread *thread )
|
|
|
|
{
|
|
|
|
struct process *process = thread->process;
|
|
|
|
|
|
|
|
if (!thread->queue) return;
|
|
|
|
if (process->queue == thread->queue) /* is it the process main queue? */
|
|
|
|
{
|
|
|
|
release_object( process->queue );
|
|
|
|
process->queue = NULL;
|
|
|
|
if (process->idle_event)
|
|
|
|
{
|
|
|
|
set_event( process->idle_event );
|
|
|
|
release_object( process->idle_event );
|
|
|
|
process->idle_event = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
release_object( thread->queue );
|
|
|
|
thread->queue = NULL;
|
|
|
|
}
|
|
|
|
|
2001-05-18 22:51:56 +00:00
|
|
|
/* check the queue status */
|
|
|
|
inline static int is_signaled( struct msg_queue *queue )
|
|
|
|
{
|
|
|
|
return ((queue->wake_bits & queue->wake_mask) || (queue->changed_bits & queue->changed_mask));
|
|
|
|
}
|
|
|
|
|
2001-08-07 19:19:08 +00:00
|
|
|
/* set some queue bits */
|
|
|
|
inline static void set_queue_bits( struct msg_queue *queue, unsigned int bits )
|
2001-05-18 22:51:56 +00:00
|
|
|
{
|
2001-08-07 19:19:08 +00:00
|
|
|
queue->wake_bits |= bits;
|
|
|
|
queue->changed_bits |= bits;
|
2001-05-18 22:51:56 +00:00
|
|
|
if (is_signaled( queue )) wake_up( &queue->obj, 0 );
|
|
|
|
}
|
|
|
|
|
2001-08-07 19:19:08 +00:00
|
|
|
/* clear some queue bits */
|
|
|
|
inline static void clear_queue_bits( struct msg_queue *queue, unsigned int bits )
|
|
|
|
{
|
|
|
|
queue->wake_bits &= ~bits;
|
|
|
|
queue->changed_bits &= ~bits;
|
|
|
|
}
|
|
|
|
|
2001-06-19 19:16:41 +00:00
|
|
|
/* get the QS_* bit corresponding to a given hardware message */
|
|
|
|
inline static int get_hardware_msg_bit( struct message *msg )
|
|
|
|
{
|
|
|
|
if (msg->msg == WM_MOUSEMOVE || msg->msg == WM_NCMOUSEMOVE) return QS_MOUSEMOVE;
|
|
|
|
if (msg->msg >= WM_KEYFIRST && msg->msg <= WM_KEYLAST) return QS_KEY;
|
|
|
|
return QS_MOUSEBUTTON;
|
|
|
|
}
|
|
|
|
|
2001-05-18 22:51:56 +00:00
|
|
|
/* get the current thread queue, creating it if needed */
|
2001-11-13 22:23:48 +00:00
|
|
|
inline static struct msg_queue *get_current_queue(void)
|
2001-05-18 22:51:56 +00:00
|
|
|
{
|
|
|
|
struct msg_queue *queue = current->queue;
|
2002-10-11 18:50:15 +00:00
|
|
|
if (!queue) queue = create_msg_queue( current, NULL );
|
2001-05-18 22:51:56 +00:00
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* append a message to the end of a list */
|
|
|
|
inline static void append_message( struct message_list *list, struct message *msg )
|
|
|
|
{
|
|
|
|
msg->next = NULL;
|
|
|
|
if ((msg->prev = list->last)) msg->prev->next = msg;
|
|
|
|
else list->first = msg;
|
|
|
|
list->last = msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unlink a message from a list it */
|
|
|
|
inline static void unlink_message( struct message_list *list, struct message *msg )
|
|
|
|
{
|
|
|
|
if (msg->next) msg->next->prev = msg->prev;
|
|
|
|
else list->last = msg->prev;
|
|
|
|
if (msg->prev) msg->prev->next = msg->next;
|
|
|
|
else list->first = msg->next;
|
|
|
|
}
|
|
|
|
|
2001-07-11 17:29:01 +00:00
|
|
|
/* try to merge a message with the last in the list; return 1 if successful */
|
|
|
|
static int merge_message( struct message_list *list, const struct message *msg )
|
|
|
|
{
|
|
|
|
struct message *prev = list->last;
|
|
|
|
|
|
|
|
if (!prev) return 0;
|
|
|
|
if (prev->result) return 0;
|
|
|
|
if (prev->win != msg->win) return 0;
|
|
|
|
if (prev->msg != msg->msg) return 0;
|
|
|
|
if (prev->type != msg->type) return 0;
|
|
|
|
/* now we can merge it */
|
|
|
|
prev->wparam = msg->wparam;
|
|
|
|
prev->lparam = msg->lparam;
|
|
|
|
prev->x = msg->x;
|
|
|
|
prev->y = msg->y;
|
|
|
|
prev->time = msg->time;
|
|
|
|
prev->info = msg->info;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-08-07 19:19:08 +00:00
|
|
|
/* free a result structure */
|
|
|
|
static void free_result( struct message_result *result )
|
|
|
|
{
|
|
|
|
if (result->timeout) remove_timeout_user( result->timeout );
|
|
|
|
if (result->data) free( result->data );
|
|
|
|
free( result );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* store the message result in the appropriate structure */
|
|
|
|
static void store_message_result( struct message_result *res, unsigned int result,
|
|
|
|
unsigned int error )
|
|
|
|
{
|
|
|
|
res->result = result;
|
|
|
|
res->error = error;
|
|
|
|
res->replied = 1;
|
|
|
|
if (res->timeout)
|
|
|
|
{
|
|
|
|
remove_timeout_user( res->timeout );
|
|
|
|
res->timeout = NULL;
|
|
|
|
}
|
|
|
|
/* wake sender queue if waiting on this result */
|
|
|
|
if (res->sender && res->sender->send_result == res)
|
|
|
|
set_queue_bits( res->sender, QS_SMRESULT );
|
|
|
|
}
|
|
|
|
|
2001-05-18 22:51:56 +00:00
|
|
|
/* free a message when deleting a queue or window */
|
|
|
|
static void free_message( struct message *msg )
|
|
|
|
{
|
|
|
|
struct message_result *result = msg->result;
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
if (result->sender)
|
|
|
|
{
|
|
|
|
result->receiver = NULL;
|
2001-08-07 19:19:08 +00:00
|
|
|
store_message_result( result, 0, STATUS_ACCESS_DENIED /*FIXME*/ );
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
2001-08-07 19:19:08 +00:00
|
|
|
else free_result( result );
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
2001-08-07 19:19:08 +00:00
|
|
|
if (msg->data) free( msg->data );
|
2001-05-18 22:51:56 +00:00
|
|
|
free( msg );
|
|
|
|
}
|
|
|
|
|
2001-06-19 19:16:41 +00:00
|
|
|
/* remove (and free) a message from a message list */
|
|
|
|
static void remove_queue_message( struct msg_queue *queue, struct message *msg,
|
|
|
|
enum message_kind kind )
|
2001-05-18 22:51:56 +00:00
|
|
|
{
|
2001-06-19 19:16:41 +00:00
|
|
|
int clr_bit;
|
|
|
|
struct message *other;
|
2001-05-18 22:51:56 +00:00
|
|
|
|
2001-06-28 04:37:22 +00:00
|
|
|
if (queue->last_msg == msg) queue->last_msg = NULL;
|
2001-06-19 19:16:41 +00:00
|
|
|
unlink_message( &queue->msg_list[kind], msg );
|
|
|
|
switch(kind)
|
|
|
|
{
|
|
|
|
case SEND_MESSAGE:
|
2001-08-07 19:19:08 +00:00
|
|
|
if (!queue->msg_list[kind].first) clear_queue_bits( queue, QS_SENDMESSAGE );
|
2001-06-19 19:16:41 +00:00
|
|
|
break;
|
|
|
|
case POST_MESSAGE:
|
2001-08-07 19:19:08 +00:00
|
|
|
if (!queue->msg_list[kind].first) clear_queue_bits( queue, QS_POSTMESSAGE );
|
2001-06-19 19:16:41 +00:00
|
|
|
break;
|
|
|
|
case COOKED_HW_MESSAGE:
|
|
|
|
case RAW_HW_MESSAGE:
|
|
|
|
clr_bit = get_hardware_msg_bit( msg );
|
|
|
|
for (other = queue->msg_list[kind].first; other; other = other->next)
|
|
|
|
if (get_hardware_msg_bit( other ) == clr_bit) break;
|
2001-08-07 19:19:08 +00:00
|
|
|
if (!other) clear_queue_bits( queue, clr_bit );
|
2001-06-19 19:16:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-05-18 22:51:56 +00:00
|
|
|
free_message( msg );
|
|
|
|
}
|
|
|
|
|
2001-08-07 19:19:08 +00:00
|
|
|
/* message timed out without getting a reply */
|
|
|
|
static void result_timeout( void *private )
|
|
|
|
{
|
|
|
|
struct message_result *result = private;
|
|
|
|
|
|
|
|
assert( !result->replied );
|
|
|
|
|
|
|
|
result->timeout = NULL;
|
|
|
|
store_message_result( result, 0, STATUS_TIMEOUT );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate and fill a message result structure */
|
|
|
|
static struct message_result *alloc_message_result( struct msg_queue *send_queue,
|
|
|
|
struct msg_queue *recv_queue,
|
|
|
|
unsigned int timeout )
|
2001-05-18 22:51:56 +00:00
|
|
|
{
|
|
|
|
struct message_result *result = mem_alloc( sizeof(*result) );
|
2001-08-07 19:19:08 +00:00
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
/* put the result on the sender result stack */
|
|
|
|
result->sender = send_queue;
|
|
|
|
result->receiver = recv_queue;
|
|
|
|
result->replied = 0;
|
|
|
|
result->data = NULL;
|
|
|
|
result->data_size = 0;
|
|
|
|
result->timeout = NULL;
|
|
|
|
result->send_next = send_queue->send_result;
|
|
|
|
send_queue->send_result = result;
|
|
|
|
if (timeout != -1)
|
|
|
|
{
|
|
|
|
struct timeval when;
|
|
|
|
gettimeofday( &when, 0 );
|
|
|
|
add_timeout( &when, timeout );
|
|
|
|
result->timeout = add_timeout_user( &when, result_timeout, result );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* receive a message, removing it from the sent queue */
|
2001-11-30 18:46:42 +00:00
|
|
|
static void receive_message( struct msg_queue *queue, struct message *msg,
|
|
|
|
struct get_message_reply *reply )
|
2001-05-18 22:51:56 +00:00
|
|
|
{
|
|
|
|
struct message_result *result = msg->result;
|
|
|
|
|
2001-11-30 18:46:42 +00:00
|
|
|
reply->total = msg->data_size;
|
|
|
|
if (msg->data_size > get_reply_max_size())
|
|
|
|
{
|
|
|
|
set_error( STATUS_BUFFER_OVERFLOW );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
reply->type = msg->type;
|
|
|
|
reply->win = msg->win;
|
|
|
|
reply->msg = msg->msg;
|
|
|
|
reply->wparam = msg->wparam;
|
|
|
|
reply->lparam = msg->lparam;
|
|
|
|
reply->x = msg->x;
|
|
|
|
reply->y = msg->y;
|
|
|
|
reply->time = msg->time;
|
|
|
|
reply->info = msg->info;
|
|
|
|
|
|
|
|
if (msg->data) set_reply_data_ptr( msg->data, msg->data_size );
|
|
|
|
|
2001-06-19 19:16:41 +00:00
|
|
|
unlink_message( &queue->msg_list[SEND_MESSAGE], msg );
|
2001-05-18 22:51:56 +00:00
|
|
|
/* put the result on the receiver result stack */
|
2001-08-07 19:19:08 +00:00
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
result->recv_next = queue->recv_result;
|
|
|
|
queue->recv_result = result;
|
|
|
|
}
|
2001-05-18 22:51:56 +00:00
|
|
|
free( msg );
|
2001-08-07 19:19:08 +00:00
|
|
|
if (!queue->msg_list[SEND_MESSAGE].first) clear_queue_bits( queue, QS_SENDMESSAGE );
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set the result of the current received message */
|
|
|
|
static void reply_message( struct msg_queue *queue, unsigned int result,
|
2001-11-30 18:46:42 +00:00
|
|
|
unsigned int error, int remove, const void *data, size_t len )
|
2001-05-18 22:51:56 +00:00
|
|
|
{
|
|
|
|
struct message_result *res = queue->recv_result;
|
|
|
|
|
|
|
|
if (remove)
|
|
|
|
{
|
|
|
|
queue->recv_result = res->recv_next;
|
|
|
|
res->receiver = NULL;
|
|
|
|
if (!res->sender) /* no one waiting for it */
|
|
|
|
{
|
2001-08-07 19:19:08 +00:00
|
|
|
free_result( res );
|
2001-05-18 22:51:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!res->replied)
|
|
|
|
{
|
2001-08-07 19:19:08 +00:00
|
|
|
if (len && (res->data = memdup( data, len ))) res->data_size = len;
|
|
|
|
store_message_result( res, result, error );
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* empty a message list and free all the messages */
|
|
|
|
static void empty_msg_list( struct message_list *list )
|
|
|
|
{
|
|
|
|
struct message *msg = list->first;
|
|
|
|
while (msg)
|
|
|
|
{
|
|
|
|
struct message *next = msg->next;
|
|
|
|
free_message( msg );
|
|
|
|
msg = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cleanup all pending results when deleting a queue */
|
|
|
|
static void cleanup_results( struct msg_queue *queue )
|
|
|
|
{
|
|
|
|
struct message_result *result, *next;
|
|
|
|
|
|
|
|
result = queue->send_result;
|
|
|
|
while (result)
|
|
|
|
{
|
|
|
|
next = result->send_next;
|
|
|
|
result->sender = NULL;
|
2001-08-07 19:19:08 +00:00
|
|
|
if (!result->receiver) free_result( result );
|
2001-05-18 22:51:56 +00:00
|
|
|
result = next;
|
|
|
|
}
|
|
|
|
|
2001-08-07 19:19:08 +00:00
|
|
|
while (queue->recv_result)
|
|
|
|
reply_message( queue, 0, STATUS_ACCESS_DENIED /*FIXME*/, 1, NULL, 0 );
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
|
|
|
|
2000-05-30 19:48:18 +00:00
|
|
|
static int msg_queue_add_queue( struct object *obj, struct wait_queue_entry *entry )
|
|
|
|
{
|
|
|
|
struct msg_queue *queue = (struct msg_queue *)obj;
|
|
|
|
struct process *process = entry->thread->process;
|
|
|
|
|
2001-05-18 22:51:56 +00:00
|
|
|
/* a thread can only wait on its own queue */
|
|
|
|
if (entry->thread->queue != queue)
|
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
return 0;
|
|
|
|
}
|
2000-05-30 19:48:18 +00:00
|
|
|
/* if waiting on the main process queue, set the idle event */
|
2001-05-18 22:51:56 +00:00
|
|
|
if (process->queue == queue)
|
2000-05-30 19:48:18 +00:00
|
|
|
{
|
|
|
|
if (process->idle_event) set_event( process->idle_event );
|
|
|
|
}
|
|
|
|
add_queue( obj, entry );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void msg_queue_remove_queue(struct object *obj, struct wait_queue_entry *entry )
|
|
|
|
{
|
|
|
|
struct msg_queue *queue = (struct msg_queue *)obj;
|
|
|
|
struct process *process = entry->thread->process;
|
|
|
|
|
|
|
|
remove_queue( obj, entry );
|
|
|
|
|
2001-05-18 22:51:56 +00:00
|
|
|
assert( entry->thread->queue == queue );
|
|
|
|
|
2000-05-30 19:48:18 +00:00
|
|
|
/* if waiting on the main process queue, reset the idle event */
|
2001-05-18 22:51:56 +00:00
|
|
|
if (process->queue == queue)
|
2000-05-30 19:48:18 +00:00
|
|
|
{
|
|
|
|
if (process->idle_event) reset_event( process->idle_event );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void msg_queue_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
struct msg_queue *queue = (struct msg_queue *)obj;
|
2001-05-18 22:51:56 +00:00
|
|
|
fprintf( stderr, "Msg queue bits=%x mask=%x\n",
|
|
|
|
queue->wake_bits, queue->wake_mask );
|
2000-05-30 19:48:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int msg_queue_signaled( struct object *obj, struct thread *thread )
|
|
|
|
{
|
|
|
|
struct msg_queue *queue = (struct msg_queue *)obj;
|
2001-05-18 22:51:56 +00:00
|
|
|
return is_signaled( queue );
|
2000-05-30 19:48:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int msg_queue_satisfied( struct object *obj, struct thread *thread )
|
|
|
|
{
|
|
|
|
struct msg_queue *queue = (struct msg_queue *)obj;
|
2001-05-18 22:51:56 +00:00
|
|
|
queue->wake_mask = 0;
|
|
|
|
queue->changed_mask = 0;
|
2000-05-30 19:48:18 +00:00
|
|
|
return 0; /* Not abandoned */
|
|
|
|
}
|
|
|
|
|
2001-05-18 22:51:56 +00:00
|
|
|
static void msg_queue_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct msg_queue *queue = (struct msg_queue *)obj;
|
|
|
|
struct timer *timer = queue->first_timer;
|
2001-06-19 19:16:41 +00:00
|
|
|
int i;
|
2001-05-18 22:51:56 +00:00
|
|
|
|
|
|
|
cleanup_results( queue );
|
2001-06-19 19:16:41 +00:00
|
|
|
for (i = 0; i < NB_MSG_KINDS; i++) empty_msg_list( &queue->msg_list[i] );
|
2001-05-18 22:51:56 +00:00
|
|
|
|
|
|
|
while (timer)
|
|
|
|
{
|
|
|
|
struct timer *next = timer->next;
|
|
|
|
free( timer );
|
|
|
|
timer = next;
|
|
|
|
}
|
|
|
|
if (queue->timeout) remove_timeout_user( queue->timeout );
|
2002-10-11 18:50:15 +00:00
|
|
|
if (queue->input) release_object( queue->input );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void thread_input_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
struct thread_input *input = (struct thread_input *)obj;
|
|
|
|
fprintf( stderr, "Thread input focus=%x capture=%x active=%x\n",
|
|
|
|
input->focus, input->capture, input->active );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void thread_input_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct thread_input *input = (struct thread_input *)obj;
|
|
|
|
|
|
|
|
if (foreground_input == input) foreground_input = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fix the thread input data when a window is destroyed */
|
|
|
|
inline static void thread_input_cleanup_window( struct msg_queue *queue, user_handle_t window )
|
|
|
|
{
|
|
|
|
struct thread_input *input = queue->input;
|
|
|
|
|
|
|
|
if (window == input->focus) input->focus = 0;
|
|
|
|
if (window == input->capture) input->capture = 0;
|
|
|
|
if (window == input->active) input->active = 0;
|
|
|
|
if (window == input->menu_owner) input->menu_owner = 0;
|
|
|
|
if (window == input->move_size) input->move_size = 0;
|
|
|
|
if (window == input->caret) input->caret = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attach two thread input data structures */
|
|
|
|
int attach_thread_input( struct thread *thread_from, struct thread *thread_to )
|
|
|
|
{
|
|
|
|
struct thread_input *input;
|
|
|
|
|
|
|
|
if (!thread_to->queue && !(thread_to->queue = create_msg_queue( thread_to, NULL ))) return 0;
|
|
|
|
input = (struct thread_input *)grab_object( thread_to->queue->input );
|
|
|
|
|
|
|
|
if (thread_from->queue)
|
|
|
|
{
|
|
|
|
release_object( thread_from->queue->input );
|
|
|
|
thread_from->queue->input = input;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(thread_from->queue = create_msg_queue( thread_from, input ))) return 0;
|
|
|
|
}
|
|
|
|
memset( input->keystate, 0, sizeof(input->keystate) );
|
|
|
|
return 1;
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
|
|
|
|
2002-10-11 18:50:15 +00:00
|
|
|
/* detach two thread input data structures */
|
|
|
|
static void detach_thread_input( struct thread *thread_from, struct thread *thread_to )
|
|
|
|
{
|
|
|
|
struct thread_input *input;
|
|
|
|
|
|
|
|
if (!thread_from->queue || !thread_to->queue ||
|
|
|
|
thread_from->queue->input != thread_to->queue->input)
|
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((input = create_thread_input()))
|
|
|
|
{
|
|
|
|
release_object( thread_from->queue->input );
|
|
|
|
thread_from->queue->input = input;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-18 22:51:56 +00:00
|
|
|
/* set the next timer to expire */
|
|
|
|
static void set_next_timer( struct msg_queue *queue, struct timer *timer )
|
|
|
|
{
|
|
|
|
if (queue->timeout)
|
|
|
|
{
|
|
|
|
remove_timeout_user( queue->timeout );
|
|
|
|
queue->timeout = NULL;
|
|
|
|
}
|
|
|
|
if ((queue->next_timer = timer))
|
|
|
|
queue->timeout = add_timeout_user( &timer->when, timer_callback, queue );
|
|
|
|
|
|
|
|
/* set/clear QS_TIMER bit */
|
|
|
|
if (queue->next_timer == queue->first_timer)
|
2001-08-07 19:19:08 +00:00
|
|
|
clear_queue_bits( queue, QS_TIMER );
|
2001-05-18 22:51:56 +00:00
|
|
|
else
|
2001-08-07 19:19:08 +00:00
|
|
|
set_queue_bits( queue, QS_TIMER );
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* callback for the next timer expiration */
|
|
|
|
static void timer_callback( void *private )
|
|
|
|
{
|
|
|
|
struct msg_queue *queue = private;
|
|
|
|
|
|
|
|
queue->timeout = NULL;
|
|
|
|
/* move on to the next timer */
|
|
|
|
set_next_timer( queue, queue->next_timer->next );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* link a timer at its rightful place in the queue list */
|
|
|
|
static void link_timer( struct msg_queue *queue, struct timer *timer )
|
|
|
|
{
|
|
|
|
struct timer *pos = queue->next_timer;
|
|
|
|
|
|
|
|
while (pos && time_before( &pos->when, &timer->when )) pos = pos->next;
|
|
|
|
|
|
|
|
if (pos) /* insert before pos */
|
|
|
|
{
|
|
|
|
if ((timer->prev = pos->prev)) timer->prev->next = timer;
|
|
|
|
else queue->first_timer = timer;
|
|
|
|
timer->next = pos;
|
|
|
|
pos->prev = timer;
|
|
|
|
}
|
|
|
|
else /* insert at end */
|
|
|
|
{
|
|
|
|
timer->next = NULL;
|
|
|
|
timer->prev = queue->last_timer;
|
|
|
|
if (queue->last_timer) queue->last_timer->next = timer;
|
|
|
|
else queue->first_timer = timer;
|
|
|
|
queue->last_timer = timer;
|
|
|
|
}
|
|
|
|
/* check if we replaced the next timer */
|
|
|
|
if (pos == queue->next_timer) set_next_timer( queue, timer );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove a timer from the queue timer list */
|
|
|
|
static void unlink_timer( struct msg_queue *queue, struct timer *timer )
|
|
|
|
{
|
|
|
|
if (timer->next) timer->next->prev = timer->prev;
|
|
|
|
else queue->last_timer = timer->prev;
|
|
|
|
if (timer->prev) timer->prev->next = timer->next;
|
|
|
|
else queue->first_timer = timer->next;
|
|
|
|
/* check if we removed the next timer */
|
|
|
|
if (queue->next_timer == timer) set_next_timer( queue, timer->next );
|
2001-08-07 19:19:08 +00:00
|
|
|
else if (queue->next_timer == queue->first_timer) clear_queue_bits( queue, QS_TIMER );
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* restart an expired timer */
|
|
|
|
static void restart_timer( struct msg_queue *queue, struct timer *timer )
|
|
|
|
{
|
|
|
|
struct timeval now;
|
|
|
|
unlink_timer( queue, timer );
|
|
|
|
gettimeofday( &now, 0 );
|
|
|
|
while (!time_before( &now, &timer->when )) add_timeout( &timer->when, timer->rate );
|
|
|
|
link_timer( queue, timer );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find an expired timer matching the filtering parameters */
|
2001-08-28 18:44:52 +00:00
|
|
|
static struct timer *find_expired_timer( struct msg_queue *queue, user_handle_t win,
|
2001-05-18 22:51:56 +00:00
|
|
|
unsigned int get_first, unsigned int get_last,
|
|
|
|
int remove )
|
|
|
|
{
|
|
|
|
struct timer *timer;
|
|
|
|
for (timer = queue->first_timer; (timer && timer != queue->next_timer); timer = timer->next)
|
|
|
|
{
|
|
|
|
if (win && timer->win != win) continue;
|
|
|
|
if (timer->msg >= get_first && timer->msg <= get_last)
|
|
|
|
{
|
|
|
|
if (remove) restart_timer( queue, timer );
|
|
|
|
return timer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* kill a timer */
|
2001-08-28 18:44:52 +00:00
|
|
|
static int kill_timer( struct msg_queue *queue, user_handle_t win,
|
|
|
|
unsigned int msg, unsigned int id )
|
2001-05-18 22:51:56 +00:00
|
|
|
{
|
|
|
|
struct timer *timer;
|
|
|
|
|
|
|
|
for (timer = queue->first_timer; timer; timer = timer->next)
|
|
|
|
{
|
|
|
|
if (timer->win != win || timer->msg != msg || timer->id != id) continue;
|
|
|
|
unlink_timer( queue, timer );
|
|
|
|
free( timer );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add a timer */
|
|
|
|
static struct timer *set_timer( struct msg_queue *queue, unsigned int rate )
|
|
|
|
{
|
|
|
|
struct timer *timer = mem_alloc( sizeof(*timer) );
|
|
|
|
if (timer)
|
|
|
|
{
|
|
|
|
timer->rate = rate;
|
|
|
|
gettimeofday( &timer->when, 0 );
|
|
|
|
add_timeout( &timer->when, rate );
|
|
|
|
link_timer( queue, timer );
|
|
|
|
}
|
|
|
|
return timer;
|
|
|
|
}
|
|
|
|
|
2001-11-13 22:23:48 +00:00
|
|
|
|
|
|
|
/* increment (or decrement if 'incr' is negative) the queue paint count */
|
|
|
|
void inc_queue_paint_count( struct thread *thread, int incr )
|
|
|
|
{
|
|
|
|
struct msg_queue *queue = thread->queue;
|
|
|
|
|
|
|
|
assert( queue );
|
|
|
|
|
|
|
|
if ((queue->paint_count += incr) < 0) queue->paint_count = 0;
|
|
|
|
|
|
|
|
if (queue->paint_count)
|
|
|
|
set_queue_bits( queue, QS_PAINT );
|
|
|
|
else
|
|
|
|
clear_queue_bits( queue, QS_PAINT );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-18 22:51:56 +00:00
|
|
|
/* remove all messages and timers belonging to a certain window */
|
2001-08-28 18:44:52 +00:00
|
|
|
void queue_cleanup_window( struct thread *thread, user_handle_t win )
|
2001-05-18 22:51:56 +00:00
|
|
|
{
|
2001-08-28 18:44:52 +00:00
|
|
|
struct msg_queue *queue = thread->queue;
|
2001-05-18 22:51:56 +00:00
|
|
|
struct timer *timer;
|
|
|
|
struct message *msg;
|
2001-06-19 19:16:41 +00:00
|
|
|
int i;
|
2001-05-18 22:51:56 +00:00
|
|
|
|
2001-08-28 18:44:52 +00:00
|
|
|
if (!queue) return;
|
|
|
|
|
2001-05-18 22:51:56 +00:00
|
|
|
/* remove timers */
|
|
|
|
timer = queue->first_timer;
|
|
|
|
while (timer)
|
|
|
|
{
|
|
|
|
struct timer *next = timer->next;
|
|
|
|
if (timer->win == win)
|
|
|
|
{
|
|
|
|
unlink_timer( queue, timer );
|
|
|
|
free( timer );
|
|
|
|
}
|
|
|
|
timer = next;
|
|
|
|
}
|
|
|
|
|
2001-06-19 19:16:41 +00:00
|
|
|
/* remove messages */
|
|
|
|
for (i = 0; i < NB_MSG_KINDS; i++)
|
2001-05-18 22:51:56 +00:00
|
|
|
{
|
2001-06-19 19:16:41 +00:00
|
|
|
msg = queue->msg_list[i].first;
|
|
|
|
while (msg)
|
|
|
|
{
|
|
|
|
struct message *next = msg->next;
|
|
|
|
if (msg->win == win) remove_queue_message( queue, msg, i );
|
|
|
|
msg = next;
|
|
|
|
}
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
2002-10-11 18:50:15 +00:00
|
|
|
|
|
|
|
thread_input_cleanup_window( queue, win );
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
|
|
|
|
2002-03-23 20:43:52 +00:00
|
|
|
/* post a message to a window; used by socket handling */
|
|
|
|
void post_message( user_handle_t win, unsigned int message,
|
|
|
|
unsigned int wparam, unsigned int lparam )
|
|
|
|
{
|
|
|
|
struct message *msg;
|
|
|
|
struct thread *thread = get_window_thread( win );
|
|
|
|
|
|
|
|
if (!thread) return;
|
|
|
|
|
|
|
|
if (thread->queue && (msg = mem_alloc( sizeof(*msg) )))
|
|
|
|
{
|
|
|
|
msg->type = MSG_POSTED;
|
|
|
|
msg->win = get_user_full_handle( win );
|
|
|
|
msg->msg = message;
|
|
|
|
msg->wparam = wparam;
|
|
|
|
msg->lparam = lparam;
|
|
|
|
msg->time = get_tick_count();
|
|
|
|
msg->x = 0;
|
|
|
|
msg->y = 0;
|
|
|
|
msg->info = 0;
|
|
|
|
msg->result = NULL;
|
|
|
|
msg->data = NULL;
|
|
|
|
msg->data_size = 0;
|
|
|
|
|
|
|
|
append_message( &thread->queue->msg_list[POST_MESSAGE], msg );
|
|
|
|
set_queue_bits( thread->queue, QS_POSTMESSAGE );
|
|
|
|
}
|
|
|
|
release_object( thread );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-30 19:48:18 +00:00
|
|
|
/* get the message queue of the current thread */
|
|
|
|
DECL_HANDLER(get_msg_queue)
|
|
|
|
{
|
2001-05-18 22:51:56 +00:00
|
|
|
struct msg_queue *queue = get_current_queue();
|
2000-05-30 19:48:18 +00:00
|
|
|
|
2001-11-30 18:46:42 +00:00
|
|
|
reply->handle = 0;
|
|
|
|
if (queue) reply->handle = alloc_handle( current->process, queue, SYNCHRONIZE, 0 );
|
2000-05-30 19:48:18 +00:00
|
|
|
}
|
|
|
|
|
2001-05-18 22:51:56 +00:00
|
|
|
|
|
|
|
/* set the current message queue wakeup mask */
|
|
|
|
DECL_HANDLER(set_queue_mask)
|
|
|
|
{
|
|
|
|
struct msg_queue *queue = get_current_queue();
|
|
|
|
|
|
|
|
if (queue)
|
|
|
|
{
|
|
|
|
queue->wake_mask = req->wake_mask;
|
|
|
|
queue->changed_mask = req->changed_mask;
|
2001-11-30 18:46:42 +00:00
|
|
|
reply->wake_bits = queue->wake_bits;
|
|
|
|
reply->changed_bits = queue->changed_bits;
|
2001-05-18 22:51:56 +00:00
|
|
|
if (is_signaled( queue ))
|
|
|
|
{
|
|
|
|
/* if skip wait is set, do what would have been done in the subsequent wait */
|
|
|
|
if (req->skip_wait) msg_queue_satisfied( &queue->obj, current );
|
|
|
|
else wake_up( &queue->obj, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get the current message queue status */
|
|
|
|
DECL_HANDLER(get_queue_status)
|
|
|
|
{
|
|
|
|
struct msg_queue *queue = current->queue;
|
|
|
|
if (queue)
|
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
reply->wake_bits = queue->wake_bits;
|
|
|
|
reply->changed_bits = queue->changed_bits;
|
2001-05-18 22:51:56 +00:00
|
|
|
if (req->clear) queue->changed_bits = 0;
|
|
|
|
}
|
2001-11-30 18:46:42 +00:00
|
|
|
else reply->wake_bits = reply->changed_bits = 0;
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* send a message to a thread queue */
|
|
|
|
DECL_HANDLER(send_message)
|
|
|
|
{
|
|
|
|
struct message *msg;
|
|
|
|
struct msg_queue *send_queue = get_current_queue();
|
|
|
|
struct msg_queue *recv_queue;
|
|
|
|
struct thread *thread = get_thread_from_id( req->id );
|
|
|
|
|
|
|
|
if (!thread) return;
|
|
|
|
|
|
|
|
if (!(recv_queue = thread->queue))
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
release_object( thread );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((msg = mem_alloc( sizeof(*msg) )))
|
|
|
|
{
|
2001-08-07 19:19:08 +00:00
|
|
|
msg->type = req->type;
|
2001-09-12 17:09:24 +00:00
|
|
|
msg->win = get_user_full_handle( req->win );
|
2001-08-07 19:19:08 +00:00
|
|
|
msg->msg = req->msg;
|
|
|
|
msg->wparam = req->wparam;
|
|
|
|
msg->lparam = req->lparam;
|
|
|
|
msg->time = req->time;
|
|
|
|
msg->x = req->x;
|
|
|
|
msg->y = req->y;
|
|
|
|
msg->info = req->info;
|
|
|
|
msg->result = NULL;
|
|
|
|
msg->data = NULL;
|
|
|
|
msg->data_size = 0;
|
|
|
|
|
|
|
|
switch(msg->type)
|
2001-05-18 22:51:56 +00:00
|
|
|
{
|
2002-01-18 19:22:55 +00:00
|
|
|
case MSG_OTHER_PROCESS:
|
2001-11-30 18:46:42 +00:00
|
|
|
msg->data_size = get_req_data_size();
|
|
|
|
if (msg->data_size && !(msg->data = memdup( get_req_data(), msg->data_size )))
|
2001-07-11 17:29:01 +00:00
|
|
|
{
|
|
|
|
free( msg );
|
2001-08-07 19:19:08 +00:00
|
|
|
break;
|
2001-07-11 17:29:01 +00:00
|
|
|
}
|
2001-08-07 19:19:08 +00:00
|
|
|
/* fall through */
|
|
|
|
case MSG_ASCII:
|
|
|
|
case MSG_UNICODE:
|
|
|
|
case MSG_CALLBACK:
|
|
|
|
if (!(msg->result = alloc_message_result( send_queue, recv_queue, req->timeout )))
|
2001-07-11 17:29:01 +00:00
|
|
|
{
|
2001-08-07 19:19:08 +00:00
|
|
|
free( msg );
|
|
|
|
break;
|
2001-07-11 17:29:01 +00:00
|
|
|
}
|
2001-08-07 19:19:08 +00:00
|
|
|
/* fall through */
|
|
|
|
case MSG_NOTIFY:
|
|
|
|
append_message( &recv_queue->msg_list[SEND_MESSAGE], msg );
|
|
|
|
set_queue_bits( recv_queue, QS_SENDMESSAGE );
|
|
|
|
break;
|
|
|
|
case MSG_POSTED:
|
2002-01-18 19:22:55 +00:00
|
|
|
/* needed for posted DDE messages */
|
|
|
|
msg->data_size = get_req_data_size();
|
|
|
|
if (msg->data_size && !(msg->data = memdup( get_req_data(), msg->data_size )))
|
|
|
|
{
|
|
|
|
free( msg );
|
|
|
|
break;
|
|
|
|
}
|
2001-08-07 19:19:08 +00:00
|
|
|
append_message( &recv_queue->msg_list[POST_MESSAGE], msg );
|
|
|
|
set_queue_bits( recv_queue, QS_POSTMESSAGE );
|
2001-06-19 19:16:41 +00:00
|
|
|
break;
|
2001-08-07 19:19:08 +00:00
|
|
|
case MSG_HARDWARE_RAW:
|
|
|
|
case MSG_HARDWARE_COOKED:
|
|
|
|
{
|
|
|
|
struct message_list *list = ((msg->type == MSG_HARDWARE_RAW) ?
|
|
|
|
&recv_queue->msg_list[RAW_HW_MESSAGE] :
|
|
|
|
&recv_queue->msg_list[COOKED_HW_MESSAGE]);
|
|
|
|
if (msg->msg == WM_MOUSEMOVE && merge_message( list, msg ))
|
|
|
|
{
|
|
|
|
free( msg );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
append_message( list, msg );
|
|
|
|
set_queue_bits( recv_queue, get_hardware_msg_bit(msg) );
|
|
|
|
break;
|
|
|
|
}
|
2001-06-19 19:16:41 +00:00
|
|
|
default:
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
2001-08-07 19:19:08 +00:00
|
|
|
free( msg );
|
2001-06-19 19:16:41 +00:00
|
|
|
break;
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
release_object( thread );
|
|
|
|
}
|
|
|
|
|
2001-06-28 04:37:22 +00:00
|
|
|
/* return a message to the application, removing it from the queue if needed */
|
2001-11-30 18:46:42 +00:00
|
|
|
static void return_message_to_app( struct msg_queue *queue, int flags,
|
|
|
|
struct get_message_reply *reply,
|
2001-06-28 04:37:22 +00:00
|
|
|
struct message *msg, enum message_kind kind )
|
|
|
|
{
|
2002-01-18 19:22:55 +00:00
|
|
|
reply->total = msg->data_size;
|
|
|
|
if (msg->data_size > get_reply_max_size())
|
|
|
|
{
|
|
|
|
set_error( STATUS_BUFFER_OVERFLOW );
|
|
|
|
return;
|
|
|
|
}
|
2001-11-30 18:46:42 +00:00
|
|
|
reply->type = msg->type;
|
|
|
|
reply->win = msg->win;
|
|
|
|
reply->msg = msg->msg;
|
|
|
|
reply->wparam = msg->wparam;
|
|
|
|
reply->lparam = msg->lparam;
|
|
|
|
reply->x = msg->x;
|
|
|
|
reply->y = msg->y;
|
|
|
|
reply->time = msg->time;
|
|
|
|
reply->info = msg->info;
|
|
|
|
|
2001-06-28 04:37:22 +00:00
|
|
|
/* raw messages always get removed */
|
2001-11-30 18:46:42 +00:00
|
|
|
if ((msg->type == MSG_HARDWARE_RAW) || (flags & GET_MSG_REMOVE))
|
2001-06-28 04:37:22 +00:00
|
|
|
{
|
|
|
|
queue->last_msg = NULL;
|
2002-01-18 19:22:55 +00:00
|
|
|
if (msg->data)
|
|
|
|
{
|
|
|
|
set_reply_data_ptr( msg->data, msg->data_size );
|
|
|
|
msg->data = NULL;
|
|
|
|
msg->data_size = 0;
|
|
|
|
}
|
2001-06-28 04:37:22 +00:00
|
|
|
remove_queue_message( queue, msg, kind );
|
|
|
|
}
|
|
|
|
else /* remember it as the last returned message */
|
|
|
|
{
|
2002-01-18 19:22:55 +00:00
|
|
|
if (msg->data) set_reply_data( msg->data, msg->data_size );
|
2001-06-28 04:37:22 +00:00
|
|
|
queue->last_msg = msg;
|
|
|
|
queue->last_msg_kind = kind;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-28 18:44:52 +00:00
|
|
|
inline static struct message *find_matching_message( const struct message_list *list,
|
|
|
|
user_handle_t win,
|
2001-06-19 19:16:41 +00:00
|
|
|
unsigned int first, unsigned int last )
|
|
|
|
{
|
|
|
|
struct message *msg;
|
|
|
|
|
|
|
|
for (msg = list->first; msg; msg = msg->next)
|
|
|
|
{
|
|
|
|
/* check against the filters */
|
2001-06-28 04:37:22 +00:00
|
|
|
if (msg->msg == WM_QUIT) break; /* WM_QUIT is never filtered */
|
2001-09-21 21:08:40 +00:00
|
|
|
if (win && msg->win && msg->win != win && !is_child_window( win, msg->win )) continue;
|
2001-06-19 19:16:41 +00:00
|
|
|
if (msg->msg < first) continue;
|
|
|
|
if (msg->msg > last) continue;
|
|
|
|
break; /* found one */
|
|
|
|
}
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-18 22:51:56 +00:00
|
|
|
/* get a message from the current queue */
|
|
|
|
DECL_HANDLER(get_message)
|
|
|
|
{
|
|
|
|
struct timer *timer;
|
|
|
|
struct message *msg;
|
|
|
|
struct msg_queue *queue = get_current_queue();
|
2001-09-12 17:09:24 +00:00
|
|
|
user_handle_t get_win = get_user_full_handle( req->get_win );
|
2001-05-18 22:51:56 +00:00
|
|
|
|
2001-11-30 18:46:42 +00:00
|
|
|
if (!queue) return;
|
2001-05-18 22:51:56 +00:00
|
|
|
|
|
|
|
/* first check for sent messages */
|
2001-06-19 19:16:41 +00:00
|
|
|
if ((msg = queue->msg_list[SEND_MESSAGE].first))
|
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
receive_message( queue, msg, reply );
|
2001-05-18 22:51:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-06-19 19:16:41 +00:00
|
|
|
if (req->flags & GET_MSG_SENT_ONLY) goto done; /* nothing else to check */
|
2001-05-18 22:51:56 +00:00
|
|
|
|
2001-06-28 04:37:22 +00:00
|
|
|
/* if requested, remove the last returned but not yet removed message */
|
|
|
|
if ((req->flags & GET_MSG_REMOVE_LAST) && queue->last_msg)
|
|
|
|
remove_queue_message( queue, queue->last_msg, queue->last_msg_kind );
|
|
|
|
queue->last_msg = NULL;
|
|
|
|
|
|
|
|
/* clear changed bits so we can wait on them if we don't find a message */
|
|
|
|
queue->changed_bits = 0;
|
|
|
|
|
2001-06-19 19:16:41 +00:00
|
|
|
/* then check for posted messages */
|
2001-09-12 17:09:24 +00:00
|
|
|
if ((msg = find_matching_message( &queue->msg_list[POST_MESSAGE], get_win,
|
2001-06-19 19:16:41 +00:00
|
|
|
req->get_first, req->get_last )))
|
2001-05-18 22:51:56 +00:00
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
return_message_to_app( queue, req->flags, reply, msg, POST_MESSAGE );
|
2001-06-19 19:16:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* then check for cooked hardware messages */
|
2001-09-12 17:09:24 +00:00
|
|
|
if ((msg = find_matching_message( &queue->msg_list[COOKED_HW_MESSAGE], get_win,
|
2001-06-19 19:16:41 +00:00
|
|
|
req->get_first, req->get_last )))
|
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
return_message_to_app( queue, req->flags, reply, msg, COOKED_HW_MESSAGE );
|
2001-06-19 19:16:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* then check for any raw hardware message */
|
|
|
|
if ((msg = queue->msg_list[RAW_HW_MESSAGE].first))
|
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
return_message_to_app( queue, req->flags, reply, msg, RAW_HW_MESSAGE );
|
2001-06-19 19:16:41 +00:00
|
|
|
return;
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* now check for WM_PAINT */
|
2001-11-14 21:28:36 +00:00
|
|
|
if (queue->paint_count &&
|
|
|
|
(WM_PAINT >= req->get_first) && (WM_PAINT <= req->get_last) &&
|
2001-11-30 18:46:42 +00:00
|
|
|
(reply->win = find_window_to_repaint( get_win, current )))
|
|
|
|
{
|
|
|
|
reply->type = MSG_POSTED;
|
|
|
|
reply->msg = WM_PAINT;
|
|
|
|
reply->wparam = 0;
|
|
|
|
reply->lparam = 0;
|
|
|
|
reply->x = 0;
|
|
|
|
reply->y = 0;
|
|
|
|
reply->time = get_tick_count();
|
|
|
|
reply->info = 0;
|
2001-05-18 22:51:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now check for timer */
|
2001-09-12 17:09:24 +00:00
|
|
|
if ((timer = find_expired_timer( queue, get_win, req->get_first,
|
2001-06-19 19:16:41 +00:00
|
|
|
req->get_last, (req->flags & GET_MSG_REMOVE) )))
|
2001-05-18 22:51:56 +00:00
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
reply->type = MSG_POSTED;
|
|
|
|
reply->win = timer->win;
|
|
|
|
reply->msg = timer->msg;
|
|
|
|
reply->wparam = timer->id;
|
|
|
|
reply->lparam = timer->lparam;
|
|
|
|
reply->x = 0;
|
|
|
|
reply->y = 0;
|
|
|
|
reply->time = get_tick_count();
|
|
|
|
reply->info = 0;
|
2001-05-18 22:51:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
set_error( STATUS_PENDING ); /* FIXME */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* reply to a sent message */
|
|
|
|
DECL_HANDLER(reply_message)
|
|
|
|
{
|
2001-05-19 17:38:21 +00:00
|
|
|
if (current->queue && current->queue->recv_result)
|
2001-08-07 19:19:08 +00:00
|
|
|
reply_message( current->queue, req->result, 0, req->remove,
|
2001-11-30 18:46:42 +00:00
|
|
|
get_req_data(), get_req_data_size() );
|
2001-05-19 17:38:21 +00:00
|
|
|
else
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* retrieve the reply for the last message sent */
|
|
|
|
DECL_HANDLER(get_message_reply)
|
|
|
|
{
|
2001-08-07 19:19:08 +00:00
|
|
|
struct msg_queue *queue = current->queue;
|
2001-05-18 22:51:56 +00:00
|
|
|
|
2001-08-07 19:19:08 +00:00
|
|
|
if (queue)
|
|
|
|
{
|
|
|
|
struct message_result *result = queue->send_result;
|
2001-05-18 22:51:56 +00:00
|
|
|
|
2001-08-07 19:19:08 +00:00
|
|
|
set_error( STATUS_PENDING );
|
2001-11-30 18:46:42 +00:00
|
|
|
reply->result = 0;
|
2001-05-18 22:51:56 +00:00
|
|
|
|
2001-08-07 19:19:08 +00:00
|
|
|
if (result && (result->replied || req->cancel))
|
2001-05-18 22:51:56 +00:00
|
|
|
{
|
2001-08-07 19:19:08 +00:00
|
|
|
if (result->replied)
|
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
reply->result = result->result;
|
2001-08-07 19:19:08 +00:00
|
|
|
set_error( result->error );
|
|
|
|
if (result->data)
|
|
|
|
{
|
2001-11-30 18:46:42 +00:00
|
|
|
size_t data_len = min( result->data_size, get_reply_max_size() );
|
|
|
|
set_reply_data_ptr( result->data, data_len );
|
2001-08-07 19:19:08 +00:00
|
|
|
result->data = NULL;
|
|
|
|
result->data_size = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
queue->send_result = result->send_next;
|
|
|
|
result->sender = NULL;
|
|
|
|
if (!result->receiver) free_result( result );
|
|
|
|
if (!queue->send_result || !queue->send_result->replied)
|
|
|
|
clear_queue_bits( queue, QS_SMRESULT );
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
|
|
|
}
|
2001-08-07 19:19:08 +00:00
|
|
|
else set_error( STATUS_ACCESS_DENIED );
|
2001-05-18 22:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* set a window timer */
|
|
|
|
DECL_HANDLER(set_win_timer)
|
|
|
|
{
|
|
|
|
struct timer *timer;
|
|
|
|
struct msg_queue *queue = get_current_queue();
|
2001-09-12 17:09:24 +00:00
|
|
|
user_handle_t win = get_user_full_handle( req->win );
|
2001-05-18 22:51:56 +00:00
|
|
|
|
|
|
|
if (!queue) return;
|
|
|
|
|
|
|
|
/* remove it if it existed already */
|
2001-09-12 17:09:24 +00:00
|
|
|
if (win) kill_timer( queue, win, req->msg, req->id );
|
2001-05-18 22:51:56 +00:00
|
|
|
|
|
|
|
if ((timer = set_timer( queue, req->rate )))
|
|
|
|
{
|
2001-09-12 17:09:24 +00:00
|
|
|
timer->win = win;
|
2001-05-18 22:51:56 +00:00
|
|
|
timer->msg = req->msg;
|
|
|
|
timer->id = req->id;
|
|
|
|
timer->lparam = req->lparam;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* kill a window timer */
|
|
|
|
DECL_HANDLER(kill_win_timer)
|
|
|
|
{
|
|
|
|
struct msg_queue *queue = current->queue;
|
|
|
|
|
2001-09-12 17:09:24 +00:00
|
|
|
if (!queue || !kill_timer( queue, get_user_full_handle(req->win), req->msg, req->id ))
|
2001-05-18 22:51:56 +00:00
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
}
|
2002-10-11 18:50:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* attach (or detach) thread inputs */
|
|
|
|
DECL_HANDLER(attach_thread_input)
|
|
|
|
{
|
|
|
|
struct thread *thread_from = get_thread_from_id( req->tid_from );
|
|
|
|
struct thread *thread_to = get_thread_from_id( req->tid_to );
|
|
|
|
|
|
|
|
if (!thread_from || !thread_to)
|
|
|
|
{
|
|
|
|
if (thread_from) release_object( thread_from );
|
|
|
|
if (thread_to) release_object( thread_to );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (thread_from != thread_to)
|
|
|
|
{
|
|
|
|
if (req->attach) attach_thread_input( thread_from, thread_to );
|
|
|
|
else detach_thread_input( thread_from, thread_to );
|
|
|
|
}
|
|
|
|
else set_error( STATUS_ACCESS_DENIED );
|
|
|
|
release_object( thread_from );
|
|
|
|
release_object( thread_to );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get thread input data */
|
|
|
|
DECL_HANDLER(get_thread_input)
|
|
|
|
{
|
|
|
|
struct thread *thread = NULL;
|
|
|
|
struct thread_input *input;
|
|
|
|
|
|
|
|
if (req->tid)
|
|
|
|
{
|
|
|
|
if (!(thread = get_thread_from_id( req->tid ))) return;
|
|
|
|
input = thread->queue ? thread->queue->input : NULL;
|
|
|
|
}
|
|
|
|
else input = foreground_input; /* get the foreground thread info */
|
|
|
|
|
|
|
|
if (input)
|
|
|
|
{
|
|
|
|
reply->focus = input->focus;
|
|
|
|
reply->capture = input->capture;
|
|
|
|
reply->active = input->active;
|
|
|
|
reply->menu_owner = input->menu_owner;
|
|
|
|
reply->move_size = input->move_size;
|
|
|
|
reply->caret = input->caret;
|
|
|
|
reply->rect = input->rect;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reply->focus = 0;
|
|
|
|
reply->capture = 0;
|
|
|
|
reply->active = 0;
|
|
|
|
reply->menu_owner = 0;
|
|
|
|
reply->move_size = 0;
|
|
|
|
reply->caret = 0;
|
|
|
|
reply->rect.left = reply->rect.top = reply->rect.right = reply->rect.bottom = 0;
|
|
|
|
}
|
|
|
|
/* foreground window is active window of foreground thread */
|
|
|
|
reply->foreground = foreground_input ? foreground_input->active : 0;
|
|
|
|
if (thread) release_object( thread );
|
|
|
|
}
|