1141cc406Sopenharmony_ci/* sane - Scanner Access Now Easy. 2141cc406Sopenharmony_ci Copyright (C) 1997 David Mosberger-Tang 3141cc406Sopenharmony_ci This file is part of the SANE package. 4141cc406Sopenharmony_ci 5141cc406Sopenharmony_ci SANE is free software; you can redistribute it and/or modify it 6141cc406Sopenharmony_ci under the terms of the GNU General Public License as published by 7141cc406Sopenharmony_ci the Free Software Foundation; either version 2 of the License, or 8141cc406Sopenharmony_ci (at your option) any later version. 9141cc406Sopenharmony_ci 10141cc406Sopenharmony_ci SANE is distributed in the hope that it will be useful, but WITHOUT 11141cc406Sopenharmony_ci ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12141cc406Sopenharmony_ci or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 13141cc406Sopenharmony_ci License for more details. 14141cc406Sopenharmony_ci 15141cc406Sopenharmony_ci You should have received a copy of the GNU General Public License 16141cc406Sopenharmony_ci along with sane; see the file COPYING. 17141cc406Sopenharmony_ci If not, see <https://www.gnu.org/licenses/>. 18141cc406Sopenharmony_ci 19141cc406Sopenharmony_ci As a special exception, the authors of SANE give permission for 20141cc406Sopenharmony_ci additional uses of the libraries contained in this release of SANE. 21141cc406Sopenharmony_ci 22141cc406Sopenharmony_ci The exception is that, if you link a SANE library with other files 23141cc406Sopenharmony_ci to produce an executable, this does not by itself cause the 24141cc406Sopenharmony_ci resulting executable to be covered by the GNU General Public 25141cc406Sopenharmony_ci License. Your use of that executable is in no way restricted on 26141cc406Sopenharmony_ci account of linking the SANE library code into it. 27141cc406Sopenharmony_ci 28141cc406Sopenharmony_ci This exception does not, however, invalidate any other reasons why 29141cc406Sopenharmony_ci the executable file might be covered by the GNU General Public 30141cc406Sopenharmony_ci License. 31141cc406Sopenharmony_ci 32141cc406Sopenharmony_ci If you submit changes to SANE to the maintainers to be included in 33141cc406Sopenharmony_ci a subsequent release, you agree by submitting the changes that 34141cc406Sopenharmony_ci those changes may be distributed with this exception intact. 35141cc406Sopenharmony_ci 36141cc406Sopenharmony_ci If you write modifications of your own for SANE, it is your choice 37141cc406Sopenharmony_ci whether to permit this exception to apply to your modifications. 38141cc406Sopenharmony_ci If you do not wish that, delete this exception notice. 39141cc406Sopenharmony_ci 40141cc406Sopenharmony_ci Support routines to translate internal datatypes into a wire-format 41141cc406Sopenharmony_ci (used for RPCs and to save/restore options). */ 42141cc406Sopenharmony_ci 43141cc406Sopenharmony_ci#ifndef sanei_wire_h 44141cc406Sopenharmony_ci#define sanei_wire_h 45141cc406Sopenharmony_ci 46141cc406Sopenharmony_ci#include <sys/types.h> 47141cc406Sopenharmony_ci 48141cc406Sopenharmony_ci#define MAX_MEM (1024 * 1024) 49141cc406Sopenharmony_ci 50141cc406Sopenharmony_citypedef enum 51141cc406Sopenharmony_ci { 52141cc406Sopenharmony_ci WIRE_ENCODE = 0, 53141cc406Sopenharmony_ci WIRE_DECODE, 54141cc406Sopenharmony_ci WIRE_FREE 55141cc406Sopenharmony_ci } 56141cc406Sopenharmony_ciWireDirection; 57141cc406Sopenharmony_ci 58141cc406Sopenharmony_cistruct Wire; 59141cc406Sopenharmony_ci 60141cc406Sopenharmony_citypedef void (*WireCodecFunc) (struct Wire *w, void *val_ptr); 61141cc406Sopenharmony_citypedef ssize_t (*WireReadFunc) (int fd, void * buf, size_t len); 62141cc406Sopenharmony_citypedef ssize_t (*WireWriteFunc) (int fd, const void * buf, size_t len); 63141cc406Sopenharmony_ci 64141cc406Sopenharmony_citypedef struct Wire 65141cc406Sopenharmony_ci { 66141cc406Sopenharmony_ci int version; /* protocol version in use */ 67141cc406Sopenharmony_ci WireDirection direction; 68141cc406Sopenharmony_ci int status; 69141cc406Sopenharmony_ci int allocated_memory; 70141cc406Sopenharmony_ci struct 71141cc406Sopenharmony_ci { 72141cc406Sopenharmony_ci WireCodecFunc w_byte; 73141cc406Sopenharmony_ci WireCodecFunc w_char; 74141cc406Sopenharmony_ci WireCodecFunc w_word; 75141cc406Sopenharmony_ci WireCodecFunc w_string; 76141cc406Sopenharmony_ci } 77141cc406Sopenharmony_ci codec; 78141cc406Sopenharmony_ci struct 79141cc406Sopenharmony_ci { 80141cc406Sopenharmony_ci size_t size; 81141cc406Sopenharmony_ci char *curr; 82141cc406Sopenharmony_ci char *start; 83141cc406Sopenharmony_ci char *end; 84141cc406Sopenharmony_ci } 85141cc406Sopenharmony_ci buffer; 86141cc406Sopenharmony_ci struct 87141cc406Sopenharmony_ci { 88141cc406Sopenharmony_ci int fd; 89141cc406Sopenharmony_ci WireReadFunc read; 90141cc406Sopenharmony_ci WireWriteFunc write; 91141cc406Sopenharmony_ci } 92141cc406Sopenharmony_ci io; 93141cc406Sopenharmony_ci } 94141cc406Sopenharmony_ciWire; 95141cc406Sopenharmony_ci 96141cc406Sopenharmony_ciextern void sanei_w_init (Wire *w, void (*codec_init)(Wire *)); 97141cc406Sopenharmony_ciextern void sanei_w_exit (Wire *w); 98141cc406Sopenharmony_ciextern void sanei_w_space (Wire *w, size_t howmuch); 99141cc406Sopenharmony_ciextern void sanei_w_void (Wire *w, void *); 100141cc406Sopenharmony_ciextern void sanei_w_byte (Wire *w, SANE_Byte *v); 101141cc406Sopenharmony_ciextern void sanei_w_char (Wire *w, SANE_Char *v); 102141cc406Sopenharmony_ciextern void sanei_w_word (Wire *w, SANE_Word *v); 103141cc406Sopenharmony_ciextern void sanei_w_bool (Wire *w, SANE_Bool *v); 104141cc406Sopenharmony_ciextern void sanei_w_ptr (Wire *w, void **v, WireCodecFunc w_value, 105141cc406Sopenharmony_ci size_t value_size); 106141cc406Sopenharmony_ciextern void sanei_w_string (Wire *w, SANE_String *v); 107141cc406Sopenharmony_ciextern void sanei_w_status (Wire *w, SANE_Status *v); 108141cc406Sopenharmony_ciextern void sanei_w_constraint_type (Wire *w, SANE_Constraint_Type *v); 109141cc406Sopenharmony_ciextern void sanei_w_value_type (Wire *w, SANE_Value_Type *v); 110141cc406Sopenharmony_ciextern void sanei_w_unit (Wire *w, SANE_Unit *v); 111141cc406Sopenharmony_ciextern void sanei_w_action (Wire *w, SANE_Action *v); 112141cc406Sopenharmony_ciextern void sanei_w_frame (Wire *w, SANE_Frame *v); 113141cc406Sopenharmony_ciextern void sanei_w_range (Wire *w, SANE_Range *v); 114141cc406Sopenharmony_ciextern void sanei_w_range_ptr (Wire *w, SANE_Range **v); 115141cc406Sopenharmony_ciextern void sanei_w_device (Wire *w, SANE_Device *v); 116141cc406Sopenharmony_ciextern void sanei_w_device_ptr (Wire *w, SANE_Device **v); 117141cc406Sopenharmony_ciextern void sanei_w_option_descriptor (Wire *w, SANE_Option_Descriptor *v); 118141cc406Sopenharmony_ciextern void sanei_w_option_descriptor_ptr (Wire *w, 119141cc406Sopenharmony_ci SANE_Option_Descriptor **v); 120141cc406Sopenharmony_ciextern void sanei_w_parameters (Wire *w, SANE_Parameters *v); 121141cc406Sopenharmony_ci 122141cc406Sopenharmony_ciextern void sanei_w_array (Wire *w, SANE_Word *len, void **v, 123141cc406Sopenharmony_ci WireCodecFunc w_element, size_t element_size); 124141cc406Sopenharmony_ci 125141cc406Sopenharmony_ciextern void sanei_w_set_dir (Wire *w, WireDirection dir); 126141cc406Sopenharmony_ciextern void sanei_w_call (Wire *w, SANE_Word proc_num, 127141cc406Sopenharmony_ci WireCodecFunc w_arg, void *arg, 128141cc406Sopenharmony_ci WireCodecFunc w_reply, void *reply); 129141cc406Sopenharmony_ciextern void sanei_w_reply (Wire *w, WireCodecFunc w_reply, void *reply); 130141cc406Sopenharmony_ciextern void sanei_w_free (Wire *w, WireCodecFunc w_reply, void *reply); 131141cc406Sopenharmony_ci 132141cc406Sopenharmony_ci#endif /* sanei_wire_h */ 133