SANEI  1.2.1.189-7ab850
sanei_wire.h
1 /* sane - Scanner Access Now Easy.
2  Copyright (C) 1997 David Mosberger-Tang
3  This file is part of the SANE package.
4 
5  SANE is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  SANE is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
13  License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with sane; see the file COPYING.
17  If not, see <https://www.gnu.org/licenses/>.
18 
19  As a special exception, the authors of SANE give permission for
20  additional uses of the libraries contained in this release of SANE.
21 
22  The exception is that, if you link a SANE library with other files
23  to produce an executable, this does not by itself cause the
24  resulting executable to be covered by the GNU General Public
25  License. Your use of that executable is in no way restricted on
26  account of linking the SANE library code into it.
27 
28  This exception does not, however, invalidate any other reasons why
29  the executable file might be covered by the GNU General Public
30  License.
31 
32  If you submit changes to SANE to the maintainers to be included in
33  a subsequent release, you agree by submitting the changes that
34  those changes may be distributed with this exception intact.
35 
36  If you write modifications of your own for SANE, it is your choice
37  whether to permit this exception to apply to your modifications.
38  If you do not wish that, delete this exception notice.
39 
40  Support routines to translate internal datatypes into a wire-format
41  (used for RPCs and to save/restore options). */
42 
43 #ifndef sanei_wire_h
44 #define sanei_wire_h
45 
46 #include <sys/types.h>
47 
48 #define MAX_MEM (1024 * 1024)
49 
50 typedef enum
51  {
52  WIRE_ENCODE = 0,
53  WIRE_DECODE,
54  WIRE_FREE
55  }
56 WireDirection;
57 
58 struct Wire;
59 
60 typedef void (*WireCodecFunc) (struct Wire *w, void *val_ptr);
61 typedef ssize_t (*WireReadFunc) (int fd, void * buf, size_t len);
62 typedef ssize_t (*WireWriteFunc) (int fd, const void * buf, size_t len);
63 
64 typedef struct Wire
65  {
66  int version; /* protocol version in use */
67  WireDirection direction;
68  int status;
69  int allocated_memory;
70  struct
71  {
72  WireCodecFunc w_byte;
73  WireCodecFunc w_char;
74  WireCodecFunc w_word;
75  WireCodecFunc w_string;
76  }
77  codec;
78  struct
79  {
80  size_t size;
81  char *curr;
82  char *start;
83  char *end;
84  }
85  buffer;
86  struct
87  {
88  int fd;
89  WireReadFunc read;
90  WireWriteFunc write;
91  }
92  io;
93  }
94 Wire;
95 
96 extern void sanei_w_init (Wire *w, void (*codec_init)(Wire *));
97 extern void sanei_w_exit (Wire *w);
98 extern void sanei_w_space (Wire *w, size_t howmuch);
99 extern void sanei_w_void (Wire *w, void *);
100 extern void sanei_w_byte (Wire *w, SANE_Byte *v);
101 extern void sanei_w_char (Wire *w, SANE_Char *v);
102 extern void sanei_w_word (Wire *w, SANE_Word *v);
103 extern void sanei_w_bool (Wire *w, SANE_Bool *v);
104 extern void sanei_w_ptr (Wire *w, void **v, WireCodecFunc w_value,
105  size_t value_size);
106 extern void sanei_w_string (Wire *w, SANE_String *v);
107 extern void sanei_w_status (Wire *w, SANE_Status *v);
108 extern void sanei_w_constraint_type (Wire *w, SANE_Constraint_Type *v);
109 extern void sanei_w_value_type (Wire *w, SANE_Value_Type *v);
110 extern void sanei_w_unit (Wire *w, SANE_Unit *v);
111 extern void sanei_w_action (Wire *w, SANE_Action *v);
112 extern void sanei_w_frame (Wire *w, SANE_Frame *v);
113 extern void sanei_w_range (Wire *w, SANE_Range *v);
114 extern void sanei_w_range_ptr (Wire *w, SANE_Range **v);
115 extern void sanei_w_device (Wire *w, SANE_Device *v);
116 extern void sanei_w_device_ptr (Wire *w, SANE_Device **v);
117 extern void sanei_w_option_descriptor (Wire *w, SANE_Option_Descriptor *v);
118 extern void sanei_w_option_descriptor_ptr (Wire *w,
119  SANE_Option_Descriptor **v);
120 extern void sanei_w_parameters (Wire *w, SANE_Parameters *v);
121 
122 extern void sanei_w_array (Wire *w, SANE_Word *len, void **v,
123  WireCodecFunc w_element, size_t element_size);
124 
125 extern void sanei_w_set_dir (Wire *w, WireDirection dir);
126 extern void sanei_w_call (Wire *w, SANE_Word proc_num,
127  WireCodecFunc w_arg, void *arg,
128  WireCodecFunc w_reply, void *reply);
129 extern void sanei_w_reply (Wire *w, WireCodecFunc w_reply, void *reply);
130 extern void sanei_w_free (Wire *w, WireCodecFunc w_reply, void *reply);
131 
132 #endif /* sanei_wire_h */
SANE_Status ENTRY() read(SANE_Handle, SANE_Byte *, SANE_Int, SANE_Int *)
Internationalization for SANE backends.
SANE_Status ENTRY() start(SANE_Handle)
Internationalization for SANE backends.