*
* 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
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
static void serial_dump( struct object *obj, int verbose );
static struct fd *serial_get_fd( struct object *obj );
-static unsigned int serial_map_access( struct object *obj, unsigned int access );
static void serial_destroy(struct object *obj);
-static int serial_get_poll_events( struct fd *fd );
-static void serial_poll_event( struct fd *fd, int event );
-static int serial_get_info( struct fd *fd );
-static int serial_flush( struct fd *fd, struct event **event );
-static void serial_queue_async( struct fd *fd, void *apc, void *user, void *iosb, int type, int count );
-static void serial_cancel_async( struct fd *fd );
+static enum server_fd_type serial_get_fd_type( struct fd *fd );
+static void serial_flush( struct fd *fd, struct event **event );
+static void serial_queue_async( struct fd *fd, const async_data_t *data, int type, int count );
struct serial
{
struct object obj;
struct fd *fd;
- unsigned int options;
/* timeout values */
unsigned int readinterval;
struct termios original;
- struct list read_q;
- struct list write_q;
- struct list wait_q;
-
/* FIXME: add dcb, comm status, handler module, sharing */
};
{
sizeof(struct serial), /* size */
serial_dump, /* dump */
- default_fd_add_queue, /* add_queue */
- default_fd_remove_queue, /* remove_queue */
+ no_get_type, /* get_type */
+ add_queue, /* add_queue */
+ remove_queue, /* remove_queue */
default_fd_signaled, /* signaled */
no_satisfied, /* satisfied */
no_signal, /* signal */
serial_get_fd, /* get_fd */
- serial_map_access, /* map_access */
+ default_fd_map_access, /* map_access */
+ default_get_sd, /* get_sd */
+ default_set_sd, /* set_sd */
no_lookup_name, /* lookup_name */
- no_close_handle, /* close_handle */
+ no_open_file, /* open_file */
+ fd_close_handle, /* close_handle */
serial_destroy /* destroy */
};
static const struct fd_ops serial_fd_ops =
{
- serial_get_poll_events, /* get_poll_events */
- serial_poll_event, /* poll_event */
+ default_fd_get_poll_events, /* get_poll_events */
+ default_poll_event, /* poll_event */
serial_flush, /* flush */
- serial_get_info, /* get_file_info */
+ serial_get_fd_type, /* get_fd_type */
+ default_fd_ioctl, /* ioctl */
serial_queue_async, /* queue_async */
- serial_cancel_async /* cancel_async */
+ default_fd_reselect_async, /* reselect_async */
+ default_fd_cancel_async /* cancel_async */
};
/* check if the given fd is a serial port */
}
/* create a serial object for a given fd */
-struct object *create_serial( struct fd *fd, unsigned int options )
+struct object *create_serial( struct fd *fd )
{
struct serial *serial;
- int unix_fd = get_unix_fd( fd );
-
- /* set the fd back to blocking if necessary */
- if (options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT))
- fcntl( unix_fd, F_SETFL, 0 );
if (!(serial = alloc_object( &serial_ops ))) return NULL;
- serial->options = options;
serial->readinterval = 0;
serial->readmult = 0;
serial->readconst = 0;
serial->writemult = 0;
serial->writeconst = 0;
serial->eventmask = 0;
- list_init( &serial->read_q );
- list_init( &serial->write_q );
- list_init( &serial->wait_q );
serial->fd = (struct fd *)grab_object( fd );
set_fd_user( fd, &serial_fd_ops, &serial->obj );
return &serial->obj;
return (struct fd *)grab_object( serial->fd );
}
-static unsigned int serial_map_access( struct object *obj, unsigned int access )
-{
- if (access & GENERIC_READ) access |= FILE_GENERIC_READ;
- if (access & GENERIC_WRITE) access |= FILE_GENERIC_WRITE;
- if (access & GENERIC_EXECUTE) access |= FILE_GENERIC_EXECUTE;
- if (access & GENERIC_ALL) access |= FILE_ALL_ACCESS;
- return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
-}
-
static void serial_destroy( struct object *obj)
{
struct serial *serial = (struct serial *)obj;
-
- async_terminate_queue( &serial->read_q, STATUS_CANCELLED );
- async_terminate_queue( &serial->write_q, STATUS_CANCELLED );
- async_terminate_queue( &serial->wait_q, STATUS_CANCELLED );
- if (serial->fd) release_object( serial->fd );
+ release_object( serial->fd );
}
static void serial_dump( struct object *obj, int verbose )
return (struct serial *)get_handle_obj( process, handle, access, &serial_ops );
}
-static int serial_get_poll_events( struct fd *fd )
-{
- struct serial *serial = get_fd_user( fd );
- int events = 0;
- assert( serial->obj.ops == &serial_ops );
-
- if (!list_empty( &serial->read_q )) events |= POLLIN;
- if (!list_empty( &serial->write_q )) events |= POLLOUT;
- if (!list_empty( &serial->wait_q )) events |= POLLIN;
-
- /* fprintf(stderr,"poll events are %04x\n",events); */
-
- return events;
-}
-
-static int serial_get_info( struct fd *fd )
-{
- int flags = 0;
- struct serial *serial = get_fd_user( fd );
- assert( serial->obj.ops == &serial_ops );
-
- if (!(serial->options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT)))
- flags |= FD_FLAG_OVERLAPPED;
- else if (!(serial->readinterval == MAXDWORD &&
- serial->readmult == 0 && serial->readconst == 0))
- flags |= FD_FLAG_TIMEOUT;
- if (serial->readinterval == MAXDWORD &&
- serial->readmult == 0 && serial->readconst == 0)
- flags |= FD_FLAG_AVAILABLE;
-
- return flags;
-}
-
-static void serial_poll_event(struct fd *fd, int event)
+static enum server_fd_type serial_get_fd_type( struct fd *fd )
{
- struct serial *serial = get_fd_user( fd );
-
- /* fprintf(stderr,"Poll event %02x\n",event); */
-
- if (!list_empty( &serial->read_q ) && (POLLIN & event) )
- async_terminate_head( &serial->read_q, STATUS_ALERTED );
-
- if (!list_empty( &serial->write_q ) && (POLLOUT & event) )
- async_terminate_head( &serial->write_q, STATUS_ALERTED );
-
- if (!list_empty( &serial->wait_q ) && (POLLIN & event) )
- async_terminate_head( &serial->wait_q, STATUS_ALERTED );
-
- set_fd_events( fd, serial_get_poll_events(fd) );
+ return FD_TYPE_SERIAL;
}
-static void serial_queue_async( struct fd *fd, void *apc, void *user, void *iosb,
- int type, int count )
+static void serial_queue_async( struct fd *fd, const async_data_t *data, int type, int count )
{
struct serial *serial = get_fd_user( fd );
- struct list *queue;
- int timeout;
- int events;
+ timeout_t timeout = 0;
+ struct async *async;
assert(serial->obj.ops == &serial_ops);
switch (type)
{
case ASYNC_TYPE_READ:
- queue = &serial->read_q;
- timeout = serial->readconst + serial->readmult*count;
- break;
- case ASYNC_TYPE_WAIT:
- queue = &serial->wait_q;
- timeout = 0;
+ timeout = serial->readconst + (timeout_t)serial->readmult*count;
break;
case ASYNC_TYPE_WRITE:
- queue = &serial->write_q;
- timeout = serial->writeconst + serial->writemult*count;
+ timeout = serial->writeconst + (timeout_t)serial->writemult*count;
break;
- default:
- set_error(STATUS_INVALID_PARAMETER);
- return;
}
- if (!create_async( current, &timeout, queue, apc, user, iosb ))
- return;
-
- /* Check if the new pending request can be served immediately */
- events = check_fd_events( fd, serial_get_poll_events( fd ) );
- if (events)
+ if ((async = fd_queue_async( fd, data, type )))
{
- /* serial_poll_event() calls set_select_events() */
- serial_poll_event( fd, events );
- return;
+ if (timeout) async_set_timeout( async, timeout * -10000, STATUS_TIMEOUT );
+ release_object( async );
+ set_error( STATUS_PENDING );
}
-
- set_fd_events( fd, serial_get_poll_events( fd ) );
-}
-
-static void serial_cancel_async( struct fd *fd )
-{
- struct serial *serial = get_fd_user( fd );
- assert(serial->obj.ops == &serial_ops);
-
- async_terminate_queue( &serial->read_q, STATUS_CANCELLED );
- async_terminate_queue( &serial->write_q, STATUS_CANCELLED );
- async_terminate_queue( &serial->wait_q, STATUS_CANCELLED );
}
-static int serial_flush( struct fd *fd, struct event **event )
+static void serial_flush( struct fd *fd, struct event **event )
{
/* MSDN says: If hFile is a handle to a communications device,
* the function only flushes the transmit buffer.
*/
- int ret = (tcflush( get_unix_fd(fd), TCOFLUSH ) != -1);
- if (!ret) file_set_error();
- return ret;
+ if (tcflush( get_unix_fd(fd), TCOFLUSH ) == -1) file_set_error();
}
DECL_HANDLER(get_serial_info)
serial->eventmask = req->eventmask;
if (!serial->eventmask)
{
- async_terminate_queue( &serial->wait_q, STATUS_SUCCESS );
+ fd_async_wake_up( serial->fd, ASYNC_TYPE_WAIT, STATUS_SUCCESS );
}
}