Add INLINE declamations for foreign wrappers.
[iolib/alendvai.git] / io.streams / zeta / device.lisp
blobcc31ef0d2a3249fb1fa826d89462395ea632b555
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; --- Device common functions.
4 ;;;
6 (in-package :io.zeta-streams)
8 ;;;-----------------------------------------------------------------------------
9 ;;; Device Classes and Types
10 ;;;-----------------------------------------------------------------------------
12 (defclass device ()
13 ((input-handle :initarg :input-handle :accessor input-handle-of)
14 (output-handle :initarg :output-handle :accessor output-handle-of)))
16 (defclass single-channel-device (device) ())
18 (defclass dual-channel-device (device) ())
20 (defclass direct-device (single-channel-device) ())
22 (defclass memory-buffer-device (direct-device) ())
24 (defclass socket-device (dual-channel-device)
25 ((domain :initarg :domain)
26 (type :initarg :type)
27 (protocol :initarg :protocol)))
29 (deftype device-timeout ()
30 'non-negative-real)
32 (deftype stream-position () '(unsigned-byte 64))
35 ;;;-----------------------------------------------------------------------------
36 ;;; Generic functions
37 ;;;-----------------------------------------------------------------------------
39 (defgeneric device-open (device &rest initargs))
41 (defgeneric device-close (device &optional abort))
43 (defgeneric device-read (device vector start end &optional timeout))
45 (defgeneric read-octets/non-blocking (device vector start end))
47 (defgeneric read-octets/timeout (device vector start end timeout))
49 (defgeneric device-write (device vector start end &optional timeout))
51 (defgeneric write-octets/non-blocking (device vector start end))
53 (defgeneric write-octets/timeout (device vector start end timeout))
55 (defgeneric device-position (device))
57 (defgeneric (setf device-position) (position device &rest args))
59 (defgeneric device-length (device))
61 (defgeneric device-poll-input (device &optional timeout))
63 (defgeneric device-poll-output (device &optional timeout))
66 ;;;-----------------------------------------------------------------------------
67 ;;; Helper macros
68 ;;;-----------------------------------------------------------------------------
70 (defmacro with-device ((name) &body body)
71 `(let ((*device* ,name))
72 (declare (special *device*))
73 ,@body))
76 ;;;-----------------------------------------------------------------------------
77 ;;; Default no-op methods
78 ;;;-----------------------------------------------------------------------------
80 (defmethod device-position ((device device))
81 (values nil))
83 (defmethod (setf device-position) (position (device device) &rest args)
84 (declare (ignore position args))
85 (values nil))
87 (defmethod device-length ((device device))
88 (values nil))
91 ;;;-----------------------------------------------------------------------------
92 ;;; Default DEVICE-READ
93 ;;;-----------------------------------------------------------------------------
95 (defmethod device-read :around ((device device) vector start end &optional timeout)
96 (declare (ignore timeout))
97 (if (= start end) 0 (call-next-method)))
99 (defmethod device-read ((device device) vector start end &optional timeout)
100 (if (and timeout (zerop timeout))
101 (read-octets/non-blocking device vector start end)
102 (read-octets/timeout device vector start end timeout)))
105 ;;;-----------------------------------------------------------------------------
106 ;;; Default DEVICE-WRITE
107 ;;;-----------------------------------------------------------------------------
109 (defmethod device-write :around ((device device) vector start end &optional timeout)
110 (declare (ignore timeout))
111 (if (= start end) 0 (call-next-method)))
113 (defmethod device-write ((device device) vector start end &optional timeout)
114 (if (and timeout (zerop timeout))
115 (write-octets/non-blocking device vector start end)
116 (write-octets/timeout device vector start end timeout)))