| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- /**
- * @file BReactor_glib.h
- * @author Ambroz Bizjak <ambrop7@gmail.com>
- *
- * @section LICENSE
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the author nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #ifndef BADVPN_SYSTEM_BREACTOR_H
- #define BADVPN_SYSTEM_BREACTOR_H
- #include <stdint.h>
- #include <glib.h>
- #include <misc/debug.h>
- #include <misc/debugcounter.h>
- #include <structure/LinkedList1.h>
- #include <base/DebugObject.h>
- #include <base/BPending.h>
- #include <system/BTime.h>
- typedef struct BReactor_s BReactor;
- typedef void (*BTimer_handler) (void *user);
- typedef struct BTimer_t {
- btime_t msTime;
- BTimer_handler handler;
- void *handler_pointer;
- uint8_t active;
- BReactor *reactor;
- GSource *source;
- } BTimer;
- void BTimer_Init (BTimer *bt, btime_t msTime, BTimer_handler handler, void *user);
- int BTimer_IsRunning (BTimer *bt);
- struct BFileDescriptor_t;
- #define BREACTOR_READ (1 << 0)
- #define BREACTOR_WRITE (1 << 1)
- #define BREACTOR_ERROR (1 << 2)
- typedef void (*BFileDescriptor_handler) (void *user, int events);
- typedef struct BFileDescriptor_t {
- int fd;
- BFileDescriptor_handler handler;
- void *user;
- int active;
- int waitEvents;
- BReactor *reactor;
- GSource *source;
- GPollFD pollfd;
- } BFileDescriptor;
- void BFileDescriptor_Init (BFileDescriptor *bs, int fd, BFileDescriptor_handler handler, void *user);
- struct BReactor_s {
- int exiting;
- int exit_code;
- GMainLoop *gloop;
- int unref_gloop_on_free;
- GSourceFuncs fd_source_funcs;
- BPendingGroup pending_jobs;
- LinkedList1 active_limits_list;
-
- DebugCounter d_fds_counter;
- DebugCounter d_limits_ctr;
- DebugCounter d_timers_ctr;
- DebugObject d_obj;
- };
- int BReactor_Init (BReactor *bsys) WARN_UNUSED;
- void BReactor_Free (BReactor *bsys);
- int BReactor_Exec (BReactor *bsys);
- void BReactor_Quit (BReactor *bsys, int code);
- void BReactor_SetTimer (BReactor *bsys, BTimer *bt);
- void BReactor_SetTimerAfter (BReactor *bsys, BTimer *bt, btime_t after);
- void BReactor_SetTimerAbsolute (BReactor *bsys, BTimer *bt, btime_t time);
- void BReactor_RemoveTimer (BReactor *bsys, BTimer *bt);
- BPendingGroup * BReactor_PendingGroup (BReactor *bsys);
- int BReactor_Synchronize (BReactor *bsys, BPending *ref);
- int BReactor_AddFileDescriptor (BReactor *bsys, BFileDescriptor *bs) WARN_UNUSED;
- void BReactor_RemoveFileDescriptor (BReactor *bsys, BFileDescriptor *bs);
- void BReactor_SetFileDescriptorEvents (BReactor *bsys, BFileDescriptor *bs, int events);
- int BReactor_InitFromExistingGMainLoop (BReactor *bsys, GMainLoop *gloop, int unref_gloop_on_free);
- GMainLoop * BReactor_GetGMainLoop (BReactor *bsys);
- int BReactor_SynchronizeAll (BReactor *bsys);
- typedef struct {
- BReactor *reactor;
- int limit;
- int count;
- LinkedList1Node active_limits_list_node;
- DebugObject d_obj;
- } BReactorLimit;
- void BReactorLimit_Init (BReactorLimit *o, BReactor *reactor, int limit);
- void BReactorLimit_Free (BReactorLimit *o);
- int BReactorLimit_Increment (BReactorLimit *o);
- void BReactorLimit_SetLimit (BReactorLimit *o, int limit);
- #endif
|