1 
2 /*-------------------------------------------------------------*/
3 /***************************************************************
4  * Functions herein allow to create a new netwib_io.           *
5  ***************************************************************/
6 
7 /*-------------------------------------------------------------*/
8 /***************************************************************
9  * Following functions can return :                            *
10  *  - NETWIB_ERR_OK : the job was done (by the io or a next in *
11  *                    the chain)                               *
12  *  - NETWIB_ERR_PLEASETRYNEXT : the io doesn't know how to do *
13  *                               what was requested, so please *
14  *                               try next                      *
15  *  - NETWIB_ERR_PLEASECONSTRUCT : if way is                   *
16  *                                 NETWIB_IO_WAYTYPE_RDWR or   *
17  *                                _SUPPORTED, the library has  *
18  *                                to do the task using _READ   *
19  *                                and _WRITE                   *
20  *  - NETWIB_ERR_PLEASELOOPTIME : there is no event, so please *
21  *                                loop to reach abstime        *
22  ***************************************************************/
23 
24 /* Function called when netwib_io_read is called on the io
25    This function should return :
26      NETWIB_ERR_OK
27      NETWIB_ERR_PLEASETRYNEXT
28 */
29 typedef netwib_err (*netwib_io_read_pf)(netwib_io *pio,
30                                         netwib_buf *pbuf);
31 
32 /* Function called when netwib_io_write is called on the io
33    This function should return :
34      NETWIB_ERR_OK
35      NETWIB_ERR_PLEASETRYNEXT
36 */
37 typedef netwib_err (*netwib_io_write_pf)(netwib_io *pio,
38                                          netwib_constbuf *pbuf);
39 
40 /* Function called when netwib_io_wait is called on the io
41    This function should return :
42      NETWIB_ERR_OK
43      NETWIB_ERR_PLEASETRYNEXT
44      NETWIB_ERR_PLEASECONSTRUCT
45      NETWIB_ERR_PLEASELOOPTIME
46 */
47 typedef netwib_err (*netwib_io_wait_pf)(netwib_io *pio,
48                                         netwib_io_waytype way,
49                                         netwib_consttime *pabstime,
50                                         netwib_bool *pevent);
51 
52 /* Function called when netwib_io_unread is called on the io
53    This function should return :
54      NETWIB_ERR_OK
55      NETWIB_ERR_PLEASETRYNEXT
56 */
57 typedef netwib_err (*netwib_io_unread_pf)(netwib_io *pio,
58                                           netwib_constbuf *pbuf);
59 
60 /* Function called when netwib_io_ctl_set is called on the io
61    This function should return :
62      NETWIB_ERR_OK
63      NETWIB_ERR_PLEASETRYNEXT
64      NETWIB_ERR_PLEASECONSTRUCT
65 */
66 typedef netwib_err (*netwib_io_ctl_set_pf)(netwib_io *pio,
67                                            netwib_io_waytype way,
68                                            netwib_io_ctltype ctltype,
69                                            netwib_ptr p,
70                                            netwib_uint32 ui);
71 /* Function called when netwib_io_ctl_get is called on the io
72    This function should return :
73      NETWIB_ERR_OK
74      NETWIB_ERR_PLEASETRYNEXT
75      NETWIB_ERR_PLEASECONSTRUCT
76 */
77 typedef netwib_err (*netwib_io_ctl_get_pf)(netwib_io *pio,
78                                            netwib_io_waytype way,
79                                            netwib_io_ctltype ctltype,
80                                            netwib_ptr p,
81                                            netwib_uint32 *pui);
82 
83 /* Function called when netwib_io_close is called on the io
84    This function should return :
85      NETWIB_ERR_OK
86 */
87 typedef netwib_err (*netwib_io_close_pf)(netwib_io *pio);
88 
89 /*-------------------------------------------------------------*/
90 /* Name : netwib_io_init
91    Description :
92      Create a user defined netwib_io.
93    Input parameter(s) :
94      readsupported : read is supported
95      writesupported : write is supported
96      pcommon : common data which can be shared between functions
97      pfx : functions or NULL if not needed
98    Input/output parameter(s) :
99    Output parameter(s) :
100      **ppio : io created
101    Normal return values :
102      NETWIB_ERR_OK : ok
103 */
104 netwib_err netwib_io_init(netwib_bool readsupported,
105                           netwib_bool writesupported,
106                           netwib_ptr pcommon,
107                           netwib_io_read_pf pfread,
108                           netwib_io_write_pf pfwrite,
109                           netwib_io_wait_pf pfwait,
110                           netwib_io_unread_pf pfunread,
111                           netwib_io_ctl_set_pf pfctl_set,
112                           netwib_io_ctl_get_pf pfctl_get,
113                           netwib_io_close_pf pfclose,
114                           netwib_io **ppio);
115 
116 /*-------------------------------------------------------------*/
117 /***************************************************************
118  * Those structure definitions should only be used in functions*
119  * for netwib_io_init.                                         *
120  ***************************************************************/
121 typedef struct {
122   netwib_io *pnext; /* next io in the chain */
123   netwib_bool supported; /* true if way is supported */
124   netwib_uint32 numusers; /* number of io using this one */
125 } netwib_io_way_t;
126 struct netwib_io {
127   netwib_io_way_t rd; /* read information */
128   netwib_io_way_t wr; /* write information */
129   netwib_ptr pcommon; /* pointer used in netwib_io_init */
130   netwib_io_write_pf pfwrite;
131   netwib_io_read_pf pfread;
132   netwib_io_unread_pf pfunread;
133   netwib_io_wait_pf pfwait;
134   netwib_io_ctl_set_pf pfctl_set;
135   netwib_io_ctl_get_pf pfctl_get;
136   netwib_io_close_pf pfclose;
137 };
138 
139 /*-------------------------------------------------------------*/
140 /***************************************************************
141  * Previous structure is useful to do simple things. But,      *
142  * it's complicated to deal with several netwib_io_waytype.    *
143  * Those defines can be used :                                 *
144  *  - to work on "pnext", use netwib_io_next (in io.h)         *
145  *  - to work on "supported", use netwib_io_ctl_s/get_support  *
146  *  - to work on "numusers", use netwib_io_ctl_s/get_numusers  *
147  ***************************************************************/
148 
149 /* netwib_err f(netwib_io *pio, netwib_io_waytype way, netwib_bool yes); */
150 #define netwib_io_ctl_set_support(pio,way,yes) netwib_io_ctl_set(pio,way,NETWIB_IO_CTLTYPE_SUPPORT,NULL,(netwib_uint32)yes)
151 #define netwib_io_ctl_get_support(pio,way,pyes) netwib_io_ctl_get(pio,way,NETWIB_IO_CTLTYPE_SUPPORT,NULL,(netwib_uint32*)pyes)
152 
153 /* netwib_err f(netwib_io *pio,netwib_io_waytype way,netwib_uint32 numusers);*/
154 #define netwib_io_ctl_set_numusers(pio,way,numusers) netwib_io_ctl_set(pio,way,NETWIB_IO_CTLTYPE_NUMUSERS,NULL,numusers)
155 #define netwib_io_ctl_get_numusers(pio,way,pnumusers) netwib_io_ctl_get(pio,way,NETWIB_IO_CTLTYPE_NUMUSERS,NULL,pnumusers)
156 /* only increment or decrement */
157 #define netwib_io_ctl_set_numusers_inc(pio,way) netwib_io_ctl_set(pio,way,NETWIB_IO_CTLTYPE_NUMUSERSINC,NULL,+1)
158 #define netwib_io_ctl_set_numusers_dec(pio,way) netwib_io_ctl_set(pio,way,NETWIB_IO_CTLTYPE_NUMUSERSINC,NULL,(netwib_uint32)-1)
159