aboutsummaryrefslogtreecommitdiff
path: root/gdb/rdi-share/hostchan.h
blob: b60804d437959dd8e91add0b5c362e569b0650d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/* 
 * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved.
 * 
 * This software may be freely used, copied, modified, and distributed
 * provided that the above copyright notice is preserved in all copies of the
 * software.
 */

/* -*-C-*-
 *
 * $Revision$
 *     $Date$
 *
 */
#ifndef angsd_hostchan_h
#define angsd_hostchan_h

/* A temporary sop to older compilers */
#if defined (__NetBSD__) || defined (unix)
#  ifndef __unix              /* (good for long-term portability?)  */
#    define __unix    1
#  endif
#endif

/* struct timeval */
#if defined(__unix) || defined(__CYGWIN__)
#  include <sys/time.h>
#else
#  include "winsock.h"
#  include "time.h"
#endif

#include "chandefs.h"
#include "adperr.h"
#include "devsw.h"

/*
 * asynchronous processing modes
 */
enum AsyncMode
{
    async_block_on_nothing,
    async_block_on_read,
    async_block_on_write
};

#ifndef __cplusplus
typedef enum AsyncMode AsyncMode;
#endif

/*
 * prototype for channels callback function
 */
typedef void (*ChannelCallback)(Packet *packet, void *state);

/*
 *  Function: Adp_initSeq
 *   Purpose: initialise the channel protocol and sequence numbers
 *
 *    Params: none
 *
 *   Returns: Nothing
 */
extern void Adp_initSeq(void);

/*
 *  Function: Adp_addToQueue
 *   Purpose: chain a Packet to the end of a linked list of such structures
 *
 *    Params:
 *      In/Out: head    Head of the linked list
 *
 *              newpkt  Packet to be chained onto the list
 *
 *   Returns: Nothing
 */
extern void Adp_addToQueue(Packet **head, Packet *newpkt);

/*
 *  Function: removeFromQueue
 *   Purpose: remove a Packet from the head of a linked list of such structures
 *
 *    Params:
 *      In/Out: head    Head of the linked list
 *
 *   Returns: Old head from the linked list
 *
 * Post-conditions: Second element in the list will be the new head.
 */

extern Packet *Adp_removeFromQueue(Packet **head);

/*
 * Set log file and Enable/disable logging of ADP packets to file.
 */

void Adp_SetLogfile(const char *filename);
void Adp_SetLogEnable(int logEnableFlag);

/*
 *  Function: Adp_OpenDevice
 *   Purpose: Open a device to use for channels communication.  This is a
 *              very thin veneer to the device drivers: what hostchan.c
 *              will do is call DeviceMatch for each device driver until it
 *              finds a driver that will accept name and arg, then call
 *              DeviceOpen for that device.
 *
 *  Pre-conditions: No previous open is still active
 *
 *    Params:
 *       Input: name    Identifies which device to open.  This can either be
 *                      a host specific identifier (e.g. "/dev/ttya",
 *                      "COM1:"), or a number which is used to refer to
 *                      `standard' interfaces, so "1" would be the first host
 *                      interface, "2" the second, and so on.
 *
 *              arg     Driver specific arguments.  For example, some serial
 *                      drivers accept speed and control arguments such as
 *                      "9600" or "19200/NO_BREAK".  These arguments are
 *                      completely free-form: it is the individual drivers
 *                      which do the necessary interpretation.
 *
 *              heartbeat_on  Incicates if the heartbeat is configured to be 
 *                      used or not, true if it is, false otherwise
 *
 *   Returns:
 *          OK: adp_ok
 *       Error: adp_device_not_known,
 *              adp_device_open_failed
 *              adp_device_already_open
 */
AdpErrs Adp_OpenDevice(const char *name, const char *arg,
                       unsigned int heartbeat_on);

/*
 *  Function: Adp_CloseDevice
 *   Purpose: Close the device used for channels communication.
 *
 *    Params: None
 *
 *   Returns:
 *          OK: adp_ok
 *       Error: adp_device_not_open
 */
AdpErrs Adp_CloseDevice(void);

/*
 *  Function: Adp_Ioctl
 *   Purpose: Perform miscellaneous control operations on
 *              the device used for channels communication.
 *              This is a minimal veneer to DevSW_Ioctl.
 *
 *    Params:
 *       Input: opcode  Reason code indicating the operation to perform.
 *      In/Out: args    Pointer to opcode-sensitive arguments/result space.
 *
 *
 *   Returns:
 *          OK: adp_ok
 *       Error: adp_device_not_open, adp_failed
 */
AdpErrs Adp_Ioctl(int opcode, void *args);

/*
 *  Function: Adp_ChannelRegisterRead
 *   Purpose: Register a callback function for received packets on a given
 *              channel
 *
 *    Params:
 *       Input: chan    The channel the callback function is for.
 *
 *              cbfunc  The callback function.  If NULL, then the current
 *                      callback is removed.
 *
 *              cbstate State pointer to pass into the callback function
 *
 *   Returns:
 *          OK: adp_ok
 *       Error: adp_device_not_open
 *              adp_bad_channel_id
 *
 * Post-conditions: The callback function is responsible for freeing the
 *                      packet that is passed to it, when that packet is
 *                      no longer needed.
 */
#ifdef __cplusplus
    extern "C" {
#endif

    
extern AdpErrs Adp_ChannelRegisterRead(const ChannelID chan,
                               const ChannelCallback cbfunc,
                                void *cbstate);

#ifdef __cplusplus
    }
#endif
/*
 *  Function: Adp_ChannelRead
 *   Purpose: Wait until a packet has been read for a given channel, and
 *              then return it.  Callbacks for other channels are still
 *              active while this read is blocking.
 *
 *  Pre-conditions: No callback has been already been registered for
 *                      the channel.
 *
 *    Params:
 *       Input: chan    The channel to read.
 *
 *      Output: packet  The received packet.
 *
 *   Returns:
 *          OK: adp_ok
 *       Error: adp_device_not_open
 *              adp_bad_channel_id
 *              adp_callback_already_registered
 *
 * Post-conditions: The calling function is responsible for freeing the
 *                      received packet, when that packet is no longer
 *                      needed.
 */
AdpErrs Adp_ChannelRead(const ChannelID chan, Packet **packet);

/*
 *  Function: Adp_ChannelWrite
 *   Purpose: Write a packet to the given channel
 *
 *  Pre-conditions: Channel must have been previously opened.
 *
 *    Params:
 *       Input: chan    The channel to write.
 *
 *              packet  The packet to write.
 *
 *   Returns:
 *          OK: adp_ok
 *       Error: adp_device_not_open
 *              adp_bad_channel_id
 *
 * Post-conditions: The packet being written becomes the "property" of
 *                      Adp_ChannelWrite, which is responsible for freeing
 *                      the packet when it is no longer needed.
 */
AdpErrs Adp_ChannelWrite(const ChannelID chan, Packet *packet);

/*
 *  Function: Adp_ChannelWriteAsync
 *   Purpose: Write a packet to the given channel, but don't wait
 *            for the write to complete before returning.
 *
 *  Pre-conditions: Channel must have been previously opened.
 *
 *    Params:
 *       Input: chan    The channel to write.
 *
 *              packet  The packet to write.
 *
 *   Returns:
 *          OK: adp_ok
 *       Error: adp_device_not_open
 *              adp_bad_channel_id
 *
 * Post-conditions: The packet being written becomes the "property" of
 *                      Adp_ChannelWrite, which is responsible for freeing
 *                      the packet when it is no longer needed.
 */
AdpErrs Adp_ChannelWriteAsync(const ChannelID chan, Packet *packet);

/*
 *  Function: Adp_AsynchronousProcessing
 *   Purpose: This routine should be called from persistent any idle loop
 *              to give the data I/O routines a chance to poll for packet
 *              activity.  Depending upon the requested mode, this routine
 *              may, or may not, block.
 *
 *    Params:
 *       Input: mode    Specifies whether to block until a complete packet
 *                      has been read, all pending writes have completed,
 *                      or not to block at all.
 *
 *   Returns: Nothing.
 */
void Adp_AsynchronousProcessing(const AsyncMode mode);

/*
 * prototype for DC_APPL packet handler
 */
typedef void (*DC_Appl_Handler)(const DeviceDescr *device, Packet *packet);

/*
 * install a handler for DC_APPL packets (can be NULL), returning old one.
 */
DC_Appl_Handler Adp_Install_DC_Appl_Handler(const DC_Appl_Handler handler);

/*
 * prototype for asynchronous processing callback
 */
typedef void (*Adp_Async_Callback)(const DeviceDescr *device,
                                   const struct timeval *const time_now);

/*
 * add an asynchronous processing callback to the list
 * TRUE == okay, FALSE == no more async processing slots
 */
bool Adp_Install_Async_Callback( const Adp_Async_Callback callback_proc );

/*
 * delay for a given period (in microseconds)
 */
void Adp_delay(unsigned int period);

#endif /* ndef angsd_hostchan_h */

/* EOF hostchan.h */