2 * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved.
4 * This software may be freely used, copied, modified, and distributed
5 * provided that the above copyright notice is preserved in all copies of the
15 #ifndef angsd_hostchan_h
16 #define angsd_hostchan_h
18 /* A temporary sop to older compilers */
19 #if defined (__NetBSD__) || defined (unix)
20 # ifndef __unix /* (good for long-term portability?) */
26 #if defined(__unix) || defined(__CYGWIN__)
27 # include <sys/time.h>
38 * asynchronous processing modes
42 async_block_on_nothing
,
48 typedef enum AsyncMode AsyncMode
;
52 * prototype for channels callback function
54 typedef void (*ChannelCallback
)(Packet
*packet
, void *state
);
57 * Function: Adp_initSeq
58 * Purpose: initialise the channel protocol and sequence numbers
64 extern void Adp_initSeq(void);
67 * Function: Adp_addToQueue
68 * Purpose: chain a Packet to the end of a linked list of such structures
71 * In/Out: head Head of the linked list
73 * newpkt Packet to be chained onto the list
77 extern void Adp_addToQueue(Packet
**head
, Packet
*newpkt
);
80 * Function: removeFromQueue
81 * Purpose: remove a Packet from the head of a linked list of such structures
84 * In/Out: head Head of the linked list
86 * Returns: Old head from the linked list
88 * Post-conditions: Second element in the list will be the new head.
91 extern Packet
*Adp_removeFromQueue(Packet
**head
);
94 * Set log file and Enable/disable logging of ADP packets to file.
97 void Adp_SetLogfile(const char *filename
);
98 void Adp_SetLogEnable(int logEnableFlag
);
101 * Function: Adp_OpenDevice
102 * Purpose: Open a device to use for channels communication. This is a
103 * very thin veneer to the device drivers: what hostchan.c
104 * will do is call DeviceMatch for each device driver until it
105 * finds a driver that will accept name and arg, then call
106 * DeviceOpen for that device.
108 * Pre-conditions: No previous open is still active
111 * Input: name Identifies which device to open. This can either be
112 * a host specific identifier (e.g. "/dev/ttya",
113 * "COM1:"), or a number which is used to refer to
114 * `standard' interfaces, so "1" would be the first host
115 * interface, "2" the second, and so on.
117 * arg Driver specific arguments. For example, some serial
118 * drivers accept speed and control arguments such as
119 * "9600" or "19200/NO_BREAK". These arguments are
120 * completely free-form: it is the individual drivers
121 * which do the necessary interpretation.
123 * heartbeat_on Incicates if the heartbeat is configured to be
124 * used or not, true if it is, false otherwise
128 * Error: adp_device_not_known,
129 * adp_device_open_failed
130 * adp_device_already_open
132 AdpErrs
Adp_OpenDevice(const char *name
, const char *arg
,
133 unsigned int heartbeat_on
);
136 * Function: Adp_CloseDevice
137 * Purpose: Close the device used for channels communication.
143 * Error: adp_device_not_open
145 AdpErrs
Adp_CloseDevice(void);
148 * Function: Adp_Ioctl
149 * Purpose: Perform miscellaneous control operations on
150 * the device used for channels communication.
151 * This is a minimal veneer to DevSW_Ioctl.
154 * Input: opcode Reason code indicating the operation to perform.
155 * In/Out: args Pointer to opcode-sensitive arguments/result space.
160 * Error: adp_device_not_open, adp_failed
162 AdpErrs
Adp_Ioctl(int opcode
, void *args
);
165 * Function: Adp_ChannelRegisterRead
166 * Purpose: Register a callback function for received packets on a given
170 * Input: chan The channel the callback function is for.
172 * cbfunc The callback function. If NULL, then the current
173 * callback is removed.
175 * cbstate State pointer to pass into the callback function
179 * Error: adp_device_not_open
182 * Post-conditions: The callback function is responsible for freeing the
183 * packet that is passed to it, when that packet is
191 extern AdpErrs
Adp_ChannelRegisterRead(const ChannelID chan
,
192 const ChannelCallback cbfunc
,
199 * Function: Adp_ChannelRead
200 * Purpose: Wait until a packet has been read for a given channel, and
201 * then return it. Callbacks for other channels are still
202 * active while this read is blocking.
204 * Pre-conditions: No callback has been already been registered for
208 * Input: chan The channel to read.
210 * Output: packet The received packet.
214 * Error: adp_device_not_open
216 * adp_callback_already_registered
218 * Post-conditions: The calling function is responsible for freeing the
219 * received packet, when that packet is no longer
222 AdpErrs
Adp_ChannelRead(const ChannelID chan
, Packet
**packet
);
225 * Function: Adp_ChannelWrite
226 * Purpose: Write a packet to the given channel
228 * Pre-conditions: Channel must have been previously opened.
231 * Input: chan The channel to write.
233 * packet The packet to write.
237 * Error: adp_device_not_open
240 * Post-conditions: The packet being written becomes the "property" of
241 * Adp_ChannelWrite, which is responsible for freeing
242 * the packet when it is no longer needed.
244 AdpErrs
Adp_ChannelWrite(const ChannelID chan
, Packet
*packet
);
247 * Function: Adp_ChannelWriteAsync
248 * Purpose: Write a packet to the given channel, but don't wait
249 * for the write to complete before returning.
251 * Pre-conditions: Channel must have been previously opened.
254 * Input: chan The channel to write.
256 * packet The packet to write.
260 * Error: adp_device_not_open
263 * Post-conditions: The packet being written becomes the "property" of
264 * Adp_ChannelWrite, which is responsible for freeing
265 * the packet when it is no longer needed.
267 AdpErrs
Adp_ChannelWriteAsync(const ChannelID chan
, Packet
*packet
);
270 * Function: Adp_AsynchronousProcessing
271 * Purpose: This routine should be called from persistent any idle loop
272 * to give the data I/O routines a chance to poll for packet
273 * activity. Depending upon the requested mode, this routine
274 * may, or may not, block.
277 * Input: mode Specifies whether to block until a complete packet
278 * has been read, all pending writes have completed,
279 * or not to block at all.
283 void Adp_AsynchronousProcessing(const AsyncMode mode
);
286 * prototype for DC_APPL packet handler
288 typedef void (*DC_Appl_Handler
)(const DeviceDescr
*device
, Packet
*packet
);
291 * install a handler for DC_APPL packets (can be NULL), returning old one.
293 DC_Appl_Handler
Adp_Install_DC_Appl_Handler(const DC_Appl_Handler handler
);
296 * prototype for asynchronous processing callback
298 typedef void (*Adp_Async_Callback
)(const DeviceDescr
*device
,
299 const struct timeval
*const time_now
);
302 * add an asynchronous processing callback to the list
303 * TRUE == okay, FALSE == no more async processing slots
305 bool Adp_Install_Async_Callback( const Adp_Async_Callback callback_proc
);
308 * delay for a given period (in microseconds)
310 void Adp_delay(unsigned int period
);
312 #endif /* ndef angsd_hostchan_h */