00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef sanei_wire_h
00044 #define sanei_wire_h
00045
00046 #include <sys/types.h>
00047
00048 #define MAX_MEM (1024 * 1024)
00049
00050 typedef enum
00051 {
00052 WIRE_ENCODE = 0,
00053 WIRE_DECODE,
00054 WIRE_FREE
00055 }
00056 WireDirection;
00057
00058 struct Wire;
00059
00060 typedef void (*WireCodecFunc) (struct Wire *w, void *val_ptr);
00061 typedef ssize_t (*WireReadFunc) (int fd, void * buf, size_t len);
00062 typedef ssize_t (*WireWriteFunc) (int fd, const void * buf, size_t len);
00063
00064 typedef struct Wire
00065 {
00066 int version;
00067 WireDirection direction;
00068 int status;
00069 int allocated_memory;
00070 struct
00071 {
00072 WireCodecFunc w_byte;
00073 WireCodecFunc w_char;
00074 WireCodecFunc w_word;
00075 WireCodecFunc w_string;
00076 }
00077 codec;
00078 struct
00079 {
00080 size_t size;
00081 char *curr;
00082 char *start;
00083 char *end;
00084 }
00085 buffer;
00086 struct
00087 {
00088 int fd;
00089 WireReadFunc read;
00090 WireWriteFunc write;
00091 }
00092 io;
00093 }
00094 Wire;
00095
00096 extern void sanei_w_init (Wire *w, void (*codec_init)(Wire *));
00097 extern void sanei_w_exit (Wire *w);
00098 extern void sanei_w_space (Wire *w, size_t howmuch);
00099 extern void sanei_w_void (Wire *w);
00100 extern void sanei_w_byte (Wire *w, SANE_Byte *v);
00101 extern void sanei_w_char (Wire *w, SANE_Char *v);
00102 extern void sanei_w_word (Wire *w, SANE_Word *v);
00103 extern void sanei_w_bool (Wire *w, SANE_Bool *v);
00104 extern void sanei_w_ptr (Wire *w, void **v, WireCodecFunc w_value,
00105 size_t value_size);
00106 extern void sanei_w_string (Wire *w, SANE_String *v);
00107 extern void sanei_w_status (Wire *w, SANE_Status *v);
00108 extern void sanei_w_constraint_type (Wire *w, SANE_Constraint_Type *v);
00109 extern void sanei_w_value_type (Wire *w, SANE_Value_Type *v);
00110 extern void sanei_w_unit (Wire *w, SANE_Unit *v);
00111 extern void sanei_w_action (Wire *w, SANE_Action *v);
00112 extern void sanei_w_frame (Wire *w, SANE_Frame *v);
00113 extern void sanei_w_range (Wire *w, SANE_Range *v);
00114 extern void sanei_w_range_ptr (Wire *w, SANE_Range **v);
00115 extern void sanei_w_device (Wire *w, SANE_Device *v);
00116 extern void sanei_w_device_ptr (Wire *w, SANE_Device **v);
00117 extern void sanei_w_option_descriptor (Wire *w, SANE_Option_Descriptor *v);
00118 extern void sanei_w_option_descriptor_ptr (Wire *w,
00119 SANE_Option_Descriptor **v);
00120 extern void sanei_w_parameters (Wire *w, SANE_Parameters *v);
00121
00122 extern void sanei_w_array (Wire *w, SANE_Word *len, void **v,
00123 WireCodecFunc w_element, size_t element_size);
00124
00125 extern void sanei_w_set_dir (Wire *w, WireDirection dir);
00126 extern void sanei_w_call (Wire *w, SANE_Word proc_num,
00127 WireCodecFunc w_arg, void *arg,
00128 WireCodecFunc w_reply, void *reply);
00129 extern void sanei_w_reply (Wire *w, WireCodecFunc w_reply, void *reply);
00130 extern void sanei_w_free (Wire *w, WireCodecFunc w_reply, void *reply);
00131
00132 #endif