EPICS Base  7.0.6.1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
fdmgr.h
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * SPDX-License-Identifier: EPICS
7 * EPICS Base is distributed subject to a Software License Agreement found
8 * in file LICENSE that is included with this distribution.
9 \*************************************************************************/
10 /* fdmgr.h
11  *
12  * Header file associated with a file descriptor manager
13  * for use with the UNIX system call select
14  *
15  * Author Jeffrey O. Hill
17  * 505 665 1831
18  */
19 
20 #ifndef includeFdmgrH
21 #define includeFdmgrH
22 
23 #include "ellLib.h"
24 #include "bucketLib.h"
25 #include "osiSock.h"
26 #include "epicsThread.h"
27 #include "libComAPI.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 enum fdi_type {fdi_read, fdi_write, fdi_excp};
34 enum alarm_list_type {alt_invalid, alt_alarm, alt_expired, alt_free};
35 
36 typedef void fdctx;
37 typedef void (*pCallBackFDMgr)(void *);
38 
39 /*
40  * C "typedef" name "alarm" was changed to "fdmgrAlarm" to avoid collisions
41  * with other libraries. Next the identifier was changed again to
42  * an unsigned integer type "fdmgrAlarmId".
43  *
44  * This "#define" is for codes that used to use a pointer to the old typedef
45  * "alarm" or "fdmgrAlarm" types to identify an alarm.
46  *
47  * ie the following code will allow compilation against
48  * all versions:
49  *
50  * #if defined (NEW_FDMGR_ALARMID)
51  * fdmgrAlarmId XXXX
52  * #elif defined (NEW_FDMGR_ALARM)
53  * fdmgrAlarm *XXXX;
54  * #else
55  * alarm *XXXX;
56  * #endif
57  *
58  * XXXX = fdmgrAlarmId fdmgr_add_timeout()
59  */
60 typedef unsigned fdmgrAlarmId;
61 #define NEW_FDMGR_ALARMID
62 
63 /*
64  *
65  * Initialize a file descriptor manager session
66  *
67  */
68 LIBCOM_API fdctx * epicsStdCall fdmgr_init(void);
69 
70 /*
71  * Specify a function to be called with a specified parameter
72  * after a specified delay relative to the current time
73  *
74  * Returns fdmgrNoAlarm (zero) if alarm cant be created
75  */
76 #define fdmgrNoAlarm 0
77 LIBCOM_API fdmgrAlarmId epicsStdCall fdmgr_add_timeout(
78 fdctx *pfdctx, /* fd mgr ctx from fdmgr_init() */
79 struct timeval *ptimeout, /* relative delay from current time */
80 pCallBackFDMgr pfunc, /* function (handler) to call */
81 void *param /* first parameter passed to the func */
82 );
83 
84 /*
85  * Clear a timeout which has not executed its function (handler)
86  * yet.
87  */
88 LIBCOM_API int epicsStdCall fdmgr_clear_timeout(
89 fdctx *pfdctx, /* fd mgr ctx from fdmgr_init() */
90 fdmgrAlarmId id /* alarm to delete */
91 );
92 
93 /*
94  *
95  * Specify a function (handler) to be called with a specified parameter
96  * when a file descriptor becomes active. The parameter fdi (file
97  * descriptor interest) specifies the type of activity (IO) we wish
98  * to be informed of: read, write, or exception. For more
99  * info on this see the man pages for the UNIX system call select().
100  *
101  * read and exception callbacks are permanent( ie the application's
102  * function (handler) continues to be called each time the
103  * file descriptor becomes active until fdmgr_add_callback()
104  * is called).
105  *
106  * write callbacks are called only once after each call to
107  * fdmgr_add_callback()
108  *
109  */
110 LIBCOM_API int epicsStdCall fdmgr_add_callback(
111 fdctx *pfdctx, /* fd mgr ctx from fdmgr_init() */
112 SOCKET fd, /* file descriptor */
113 enum fdi_type fdi, /* file descriptor interest type */
114 pCallBackFDMgr pfunc, /* function (handler) to call */
115 void *param /* first parameter passed to the func */
116 );
117 
118 /*
119  *
120  * Clear interest in a type of file descriptor activity (IO).
121  *
122  */
123 LIBCOM_API int epicsStdCall fdmgr_clear_callback(
124 fdctx *pfdctx, /* fd mgr ctx from fdmgr_init() */
125 SOCKET fd, /* file descriptor */
126 enum fdi_type fdi /* file descriptor interest type */
127 );
128 
129 /*
130  *
131  * Wait a specified delay relative from the current time for file
132  * descriptor activity (IO) or timeouts (timer expiration). Application
133  * specified functions (handlers) will not be called unless the
134  * application waits in this function or polls it frequently
135  * enough.
136  *
137  */
138 LIBCOM_API int epicsStdCall fdmgr_pend_event(
139 fdctx *pfdctx, /* fd mgr ctx from fdmgr_init() */
140 struct timeval *ptimeout
141 );
142 
143 
144 /*
145  * obsolete interface
146  */
147 LIBCOM_API int epicsStdCall fdmgr_clear_fd(
148 fdctx *pfdctx, /* fd mgr ctx from fdmgr_init() */
149 SOCKET fd
150 );
151 
152 /*
153  * obsolete interface
154  */
155 LIBCOM_API int epicsStdCall fdmgr_add_fd(
156 fdctx *pfdctx, /* fd mgr ctx from fdmgr_init() */
157 SOCKET fd,
158 pCallBackFDMgr pfunc, /* function (handler) to call */
159 void *param
160 );
161 
162 LIBCOM_API int epicsStdCall fdmgr_delete(fdctx *pfdctx);
163 
164 #ifdef __cplusplus
165 }
166 #endif
167 
168 #endif /* ifndef includeFdmgrH (last line in this file) */
169 
C++ and C descriptions for a thread.
A doubly-linked list library.
A hash table. Do not use for new code.
BSD and SRV5 Unix timestamp.
Definition: epicsTime.h:65