[BACK]Return to file.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / aucat

Annotation of src/usr.bin/aucat/file.h, Revision 1.10

1.10    ! ratchov     1: /*     $OpenBSD: file.h,v 1.9 2009/09/27 11:51:20 ratchov Exp $        */
1.1       ratchov     2: /*
                      3:  * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
                      4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
                     17: #ifndef FILE_H
                     18: #define FILE_H
                     19:
                     20: #include <sys/queue.h>
                     21: #include <sys/types.h>
                     22:
1.4       ratchov    23: struct file;
1.1       ratchov    24: struct aproc;
1.4       ratchov    25: struct pollfd;
                     26:
1.7       ratchov    27: struct timo {
                     28:        struct timo *next;
                     29:        unsigned val;                   /* time to wait before the callback */
                     30:        unsigned set;                   /* true if the timeout is set */
                     31:        void (*cb)(void *arg);          /* routine to call on expiration */
                     32:        void *arg;                      /* argument to give to 'cb' */
                     33: };
                     34:
1.4       ratchov    35: struct fileops {
                     36:        char *name;
                     37:        size_t size;
                     38:        void (*close)(struct file *);
                     39:        unsigned (*read)(struct file *, unsigned char *, unsigned);
1.6       ratchov    40:        unsigned (*write)(struct file *, unsigned char *, unsigned);
1.4       ratchov    41:        void (*start)(struct file *);
                     42:        void (*stop)(struct file *);
                     43:        int (*nfds)(struct file *);
                     44:        int (*pollfd)(struct file *, struct pollfd *, int);
                     45:        int (*revents)(struct file *, struct pollfd *);
                     46: };
1.1       ratchov    47:
                     48: struct file {
1.4       ratchov    49:        struct fileops *ops;
1.1       ratchov    50:        struct pollfd *pfd;             /* arg to poll(2) syscall */
                     51: #define FILE_ROK       0x1             /* file readable */
                     52: #define FILE_WOK       0x2             /* file writable */
                     53: #define FILE_EOF       0x4             /* eof on the read end */
1.4       ratchov    54: #define FILE_HUP       0x8             /* hang-up on the write end */
                     55: #define FILE_ZOMB      0x10            /* closed, but struct not freed */
1.7       ratchov    56: #define FILE_RINUSE    0x20            /* inside rproc->ops->in() */
                     57: #define FILE_WINUSE    0x40            /* inside wproc->ops->out() */
1.4       ratchov    58:        unsigned state;                 /* one of above */
1.10    ! ratchov    59: #ifdef DEBUG
        !            60: #define FILE_MAXCYCLES 20
        !            61:        unsigned cycles;                /* number of POLLIN/POLLOUT events */
        !            62: #endif
1.1       ratchov    63:        char *name;                     /* for debug purposes */
                     64:        struct aproc *rproc, *wproc;    /* reader and/or writer */
                     65:        LIST_ENTRY(file) entry;
                     66: };
                     67:
                     68: LIST_HEAD(filelist,file);
                     69:
                     70: extern struct filelist file_list;
1.7       ratchov    71:
                     72: void timo_set(struct timo *, void (*)(void *), void *);
                     73: void timo_add(struct timo *, unsigned);
                     74: void timo_del(struct timo *);
1.1       ratchov    75:
1.4       ratchov    76: void filelist_init(void);
                     77: void filelist_done(void);
                     78: void filelist_unlisten(void);
                     79:
                     80: struct file *file_new(struct fileops *, char *, unsigned);
1.1       ratchov    81: void file_del(struct file *);
1.9       ratchov    82: void file_dbg(struct file *);
1.4       ratchov    83:
1.1       ratchov    84: void file_attach(struct file *, struct aproc *, struct aproc *);
                     85: unsigned file_read(struct file *, unsigned char *, unsigned);
                     86: unsigned file_write(struct file *, unsigned char *, unsigned);
                     87: int file_poll(void);
                     88: void file_eof(struct file *);
                     89: void file_hup(struct file *);
1.5       ratchov    90: void file_close(struct file *);
1.1       ratchov    91:
                     92: #endif /* !defined(FILE_H) */