1141cc406Sopenharmony_ci/* SANE - Scanner Access Now Easy.
2141cc406Sopenharmony_ci
3141cc406Sopenharmony_ci   Copyright (C) 2006-2007 Wittawat Yamwong <wittawat@web.de>
4141cc406Sopenharmony_ci
5141cc406Sopenharmony_ci   This file is part of the SANE package.
6141cc406Sopenharmony_ci
7141cc406Sopenharmony_ci   This program is free software; you can redistribute it and/or
8141cc406Sopenharmony_ci   modify it under the terms of the GNU General Public License as
9141cc406Sopenharmony_ci   published by the Free Software Foundation; either version 2 of the
10141cc406Sopenharmony_ci   License, or (at your option) any later version.
11141cc406Sopenharmony_ci
12141cc406Sopenharmony_ci   This program is distributed in the hope that it will be useful, but
13141cc406Sopenharmony_ci   WITHOUT ANY WARRANTY; without even the implied warranty of
14141cc406Sopenharmony_ci   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15141cc406Sopenharmony_ci   General Public License for more details.
16141cc406Sopenharmony_ci
17141cc406Sopenharmony_ci   You should have received a copy of the GNU General Public License
18141cc406Sopenharmony_ci   along with this program.  If not, see <https://www.gnu.org/licenses/>.
19141cc406Sopenharmony_ci
20141cc406Sopenharmony_ci   As a special exception, the authors of SANE give permission for
21141cc406Sopenharmony_ci   additional uses of the libraries contained in this release of SANE.
22141cc406Sopenharmony_ci
23141cc406Sopenharmony_ci   The exception is that, if you link a SANE library with other files
24141cc406Sopenharmony_ci   to produce an executable, this does not by itself cause the
25141cc406Sopenharmony_ci   resulting executable to be covered by the GNU General Public
26141cc406Sopenharmony_ci   License.  Your use of that executable is in no way restricted on
27141cc406Sopenharmony_ci   account of linking the SANE library code into it.
28141cc406Sopenharmony_ci
29141cc406Sopenharmony_ci   This exception does not, however, invalidate any other reasons why
30141cc406Sopenharmony_ci   the executable file might be covered by the GNU General Public
31141cc406Sopenharmony_ci   License.
32141cc406Sopenharmony_ci
33141cc406Sopenharmony_ci   If you submit changes to SANE to the maintainers to be included in
34141cc406Sopenharmony_ci   a subsequent release, you agree by submitting the changes that
35141cc406Sopenharmony_ci   those changes may be distributed with this exception intact.
36141cc406Sopenharmony_ci
37141cc406Sopenharmony_ci   If you write modifications of your own for SANE, it is your choice
38141cc406Sopenharmony_ci   whether to permit this exception to apply to your modifications.
39141cc406Sopenharmony_ci   If you do not wish that, delete this exception notice.
40141cc406Sopenharmony_ci */
41141cc406Sopenharmony_ci#ifndef PIXMA_IO_H
42141cc406Sopenharmony_ci#define PIXMA_IO_H
43141cc406Sopenharmony_ci
44141cc406Sopenharmony_ci/* TODO: move to pixma_common.h, to reduce the number of files */
45141cc406Sopenharmony_ci
46141cc406Sopenharmony_ci/*!
47141cc406Sopenharmony_ci * \defgroup IO IO interface
48141cc406Sopenharmony_ci * \brief The IO interface.
49141cc406Sopenharmony_ci *
50141cc406Sopenharmony_ci * Return value of functions that return \c int if not otherwise specified:
51141cc406Sopenharmony_ci *  - >=    if succeeded
52141cc406Sopenharmony_ci *  - < 0   if failed (e.g. \c PIXMA_ETIMEDOUT)
53141cc406Sopenharmony_ci * .
54141cc406Sopenharmony_ci * @{
55141cc406Sopenharmony_ci */
56141cc406Sopenharmony_ci
57141cc406Sopenharmony_ci/** Timeout for pixma_read() in milliseconds */
58141cc406Sopenharmony_ci#define PIXMA_BULKIN_TIMEOUT  1000
59141cc406Sopenharmony_ci/** Timeout for pixma_write() in milliseconds */
60141cc406Sopenharmony_ci#define PIXMA_BULKOUT_TIMEOUT 1000
61141cc406Sopenharmony_ci
62141cc406Sopenharmony_ci
63141cc406Sopenharmony_cistruct pixma_io_t;
64141cc406Sopenharmony_cistruct pixma_config_t;
65141cc406Sopenharmony_ci
66141cc406Sopenharmony_ci/** IO handle */
67141cc406Sopenharmony_citypedef struct pixma_io_t pixma_io_t;
68141cc406Sopenharmony_ci
69141cc406Sopenharmony_ci
70141cc406Sopenharmony_ci/** Initialize IO module. It must be called before any other functions in this
71141cc406Sopenharmony_ci *  module.
72141cc406Sopenharmony_ci *  \return 0 on success or
73141cc406Sopenharmony_ci *   - \c PIXMA_ENOMEM
74141cc406Sopenharmony_ci *   - \c PIXMA_EACCES
75141cc406Sopenharmony_ci *   - \c PIXMA_EIO */
76141cc406Sopenharmony_ciint pixma_io_init (void);
77141cc406Sopenharmony_ci
78141cc406Sopenharmony_ci/** Shutdown all connections and free resources allocated in this module. */
79141cc406Sopenharmony_civoid pixma_io_cleanup (void);
80141cc406Sopenharmony_ci
81141cc406Sopenharmony_ci/** Find devices currently connected to the computer.
82141cc406Sopenharmony_ci *  \c devnr passed to functions
83141cc406Sopenharmony_ci *  - pixma_get_device_config()
84141cc406Sopenharmony_ci *  - pixma_get_device_id()
85141cc406Sopenharmony_ci *  - pixma_connect()
86141cc406Sopenharmony_ci *  .
87141cc406Sopenharmony_ci *  should be less than the number of devices returned by this function.
88141cc406Sopenharmony_ci *  \param[in] pixma_devices A \c NULL terminated array of pointers to
89141cc406Sopenharmony_ci *             array of pixma_config_t which is terminated by setting
90141cc406Sopenharmony_ci *             pixma_config_t::name to \c NULL.
91141cc406Sopenharmony_ci *  \return Number of devices found */
92141cc406Sopenharmony_ciunsigned pixma_collect_devices (const char ** conf_devices,
93141cc406Sopenharmony_ci                                const struct pixma_config_t *const
94141cc406Sopenharmony_ci				pixma_devices[], SANE_Bool local_only);
95141cc406Sopenharmony_ci
96141cc406Sopenharmony_ci/** Get device configuration. */
97141cc406Sopenharmony_ciconst struct pixma_config_t *pixma_get_device_config (unsigned devnr);
98141cc406Sopenharmony_ci
99141cc406Sopenharmony_ci/** Get a unique ID of the device \a devnr. */
100141cc406Sopenharmony_ciconst char *pixma_get_device_id (unsigned devnr);
101141cc406Sopenharmony_ci
102141cc406Sopenharmony_ci/** Connect to the device and claim the scanner interface.
103141cc406Sopenharmony_ci *  \param[in] devnr
104141cc406Sopenharmony_ci *  \param[out] handle
105141cc406Sopenharmony_ci *  \return 0 on success or
106141cc406Sopenharmony_ci *   - \c PIXMA_ENODEV the device is gone from the system.
107141cc406Sopenharmony_ci *   - \c PIXMA_EINVAL \a devnr is invalid.
108141cc406Sopenharmony_ci *   - \c PIXMA_EBUSY
109141cc406Sopenharmony_ci *   - \c PIXMA_EACCES
110141cc406Sopenharmony_ci *   - \c PIXMA_ENOMEM
111141cc406Sopenharmony_ci *   - \c PIXMA_EIO */
112141cc406Sopenharmony_ciint pixma_connect (unsigned devnr, pixma_io_t ** handle);
113141cc406Sopenharmony_ci
114141cc406Sopenharmony_ci/** Release the scanner interface and disconnect from the device. */
115141cc406Sopenharmony_civoid pixma_disconnect (pixma_io_t *);
116141cc406Sopenharmony_ci
117141cc406Sopenharmony_ci/** Activate connection to scanner */
118141cc406Sopenharmony_ciint pixma_activate (pixma_io_t *);
119141cc406Sopenharmony_ci
120141cc406Sopenharmony_ci/** De-activate connection to scanner */
121141cc406Sopenharmony_ciint pixma_deactivate (pixma_io_t *);
122141cc406Sopenharmony_ci
123141cc406Sopenharmony_ci/** Reset the USB interface. \warning Use with care! */
124141cc406Sopenharmony_ciint pixma_reset_device (pixma_io_t *);
125141cc406Sopenharmony_ci
126141cc406Sopenharmony_ci/** Write data to the device. This function may not be interrupted by signals.
127141cc406Sopenharmony_ci *  It will return iff
128141cc406Sopenharmony_ci *   - \a len bytes have been successfully written or
129141cc406Sopenharmony_ci *   - an error (inclusive timeout) occurred.
130141cc406Sopenharmony_ci *  .
131141cc406Sopenharmony_ci *  \note Calling pixma_write(io, buf, n1) and pixma(io, buf+n1, n2) may
132141cc406Sopenharmony_ci *        not be the same as pixma_write(io, buf, n1+n2) if n1 is not
133141cc406Sopenharmony_ci *        multiple of the maximum packet size of the endpoint.
134141cc406Sopenharmony_ci *  \param[in] cmd Data
135141cc406Sopenharmony_ci *  \param[in] len Length of data
136141cc406Sopenharmony_ci *  \return Number of bytes successfully written (always = \a len) or
137141cc406Sopenharmony_ci *   - \c PIXMA_ETIMEDOUT
138141cc406Sopenharmony_ci *   - \c PIXMA_EIO
139141cc406Sopenharmony_ci *   - \c PIXMA_ENOMEM
140141cc406Sopenharmony_ci *  \see #PIXMA_BULKOUT_TIMEOUT */
141141cc406Sopenharmony_ciint pixma_write (pixma_io_t *, const void *cmd, unsigned len);
142141cc406Sopenharmony_ci
143141cc406Sopenharmony_ci/** Read data from the device. This function may not be interrupted by signals.
144141cc406Sopenharmony_ci *  It will return iff
145141cc406Sopenharmony_ci *   - \a size bytes have been successfully read,
146141cc406Sopenharmony_ci *   - a short packet has been read or
147141cc406Sopenharmony_ci *   - an error (inclusive timeout) occurred.
148141cc406Sopenharmony_ci *  .
149141cc406Sopenharmony_ci *  \param[out] buf
150141cc406Sopenharmony_ci *  \param[in]  size of the buffer
151141cc406Sopenharmony_ci *  \return Number of bytes successfully read. A return value of zero means that
152141cc406Sopenharmony_ci *       a zero length USB packet was received. Or
153141cc406Sopenharmony_ci *   - \c PIXMA_ETIMEDOUT
154141cc406Sopenharmony_ci *   - \c PIXMA_EIO
155141cc406Sopenharmony_ci *   - \c PIXMA_ENOMEM
156141cc406Sopenharmony_ci *  \see #PIXMA_BULKIN_TIMEOUT */
157141cc406Sopenharmony_ciint pixma_read (pixma_io_t *, void *buf, unsigned size);
158141cc406Sopenharmony_ci
159141cc406Sopenharmony_ci/** Wait for an interrupt. This function can be interrupted by signals.
160141cc406Sopenharmony_ci *  \a size should be less than or equal to the maximum packet size.
161141cc406Sopenharmony_ci *  \param[out] buf
162141cc406Sopenharmony_ci *  \param[in]  size of the buffer
163141cc406Sopenharmony_ci *  \param[in]  timeout in milliseconds; if < 0, wait forever.
164141cc406Sopenharmony_ci *  \return Number of bytes successfully read or
165141cc406Sopenharmony_ci *   - \c PIXMA_ETIMEDOUT
166141cc406Sopenharmony_ci *   - \c PIXMA_EIO
167141cc406Sopenharmony_ci *   - \c PIXMA_ENOMEM
168141cc406Sopenharmony_ci *   - \c PIXMA_ECANCELED if it was interrupted by a signal. */
169141cc406Sopenharmony_ciint pixma_wait_interrupt (pixma_io_t *, void *buf, unsigned size,
170141cc406Sopenharmony_ci			  int timeout);
171141cc406Sopenharmony_ci
172141cc406Sopenharmony_ci/** Enable or disable background interrupt monitoring.
173141cc406Sopenharmony_ci *  Background mode is enabled by default.
174141cc406Sopenharmony_ci *  \param[in] background if not zero, a URB is submitted in background
175141cc406Sopenharmony_ci *             for interrupt endpoint.
176141cc406Sopenharmony_ci *  \return 0 on success or
177141cc406Sopenharmony_ci *   - \c PIXMA_ENOTSUP
178141cc406Sopenharmony_ci *   - \c PIXMA_EIO
179141cc406Sopenharmony_ci *   - \c PIXMA_ENOMEM */
180141cc406Sopenharmony_ciint pixma_set_interrupt_mode (pixma_io_t *, int background);
181141cc406Sopenharmony_ci
182141cc406Sopenharmony_ci/** @} end of IO group */
183141cc406Sopenharmony_ci
184141cc406Sopenharmony_ci#endif
185