📄 su_port.h
字号:
/* * This file is part of the Sofia-SIP package * * Copyright (C) 2005 Nokia Corporation. * * Contact: Pekka Pessi <pekka.pessi@nokia.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */#ifndef SU_PORT_H/** Defined when <su_port.h> has been included. */#define SU_PORT_H/**@internal @file su_port.h * * @brief Internal OS-independent syncronization interface. * * This looks like the "reactor" pattern. * * @author Pekka Pessi <Pekka.Pessi@nokia.com> * * @date Created: Fri May 12 14:13:34 2000 ppessi */#ifndef SU_MSG_ARG_T#define SU_MSG_ARG_T union { char anoymous[4]; }#endif#ifndef SU_WAIT_H#include "sofia-sip/su_wait.h"#endif#ifndef SU_MODULE_DEBUG_H#include "su_module_debug.h"#endif#ifndef SU_ALLOC_H#include <sofia-sip/su_alloc.h>#endif#include <assert.h>#define SU_WAIT_MIN (16)SOFIA_BEGIN_DECLS/** @internal Message */struct su_msg_s { size_t sum_size; su_msg_t *sum_next; su_task_r sum_to; su_task_r sum_from; su_msg_f sum_func; su_msg_f sum_report; su_msg_deinit_function *sum_deinit; su_msg_arg_t sum_data[1]; /* minimum size, may be extended */};struct _GSource;/** @internal Root structure */struct su_root_s { int sur_size; su_root_magic_t *sur_magic; su_root_deinit_f sur_deinit; su_task_r sur_task; su_task_r sur_parent; unsigned sur_threading : 1; unsigned sur_deiniting : 1;};#define SU_ROOT_MAGIC(r) ((r) ? (r)->sur_magic : NULL)enum su_port_thread_op { su_port_thread_op_is_obtained, su_port_thread_op_release, su_port_thread_op_obtain}; /** @internal Virtual function table for port */typedef struct su_port_vtable { unsigned su_vtable_size; void (*su_port_lock)(su_port_t *port, char const *who); void (*su_port_unlock)(su_port_t *port, char const *who); void (*su_port_incref)(su_port_t *port, char const *who); void (*su_port_decref)(su_port_t *port, int block, char const *who); struct _GSource *(*su_port_gsource)(su_port_t *port); int (*su_port_send)(su_port_t *self, su_msg_r rmsg); int (*su_port_register)(su_port_t *self, su_root_t *root, su_wait_t *wait, su_wakeup_f callback, su_wakeup_arg_t *arg, int priority); int (*su_port_unregister)(su_port_t *port, su_root_t *root, su_wait_t *wait, su_wakeup_f callback, su_wakeup_arg_t *arg); int (*su_port_deregister)(su_port_t *self, int i); int (*su_port_unregister_all)(su_port_t *self, su_root_t *root); int (*su_port_eventmask)(su_port_t *self, int index, int socket, int events); void (*su_port_run)(su_port_t *self); void (*su_port_break)(su_port_t *self); su_duration_t (*su_port_step)(su_port_t *self, su_duration_t tout); /* Reused slot */ int (*su_port_thread)(su_port_t *port, enum su_port_thread_op op); int (*su_port_add_prepoll)(su_port_t *port, su_root_t *root, su_prepoll_f *, su_prepoll_magic_t *); int (*su_port_remove_prepoll)(su_port_t *port, su_root_t *root); su_timer_queue_t *(*su_port_timers)(su_port_t *port); int (*su_port_multishot)(su_port_t *port, int multishot); /* Extension from >= 1.12.4 */ int (*su_port_wait_events)(su_port_t *port, su_duration_t timeout); int (*su_port_getmsgs)(su_port_t *port); /* Extension from >= 1.12.5 */ int (*su_port_getmsgs_from)(su_port_t *port, su_port_t *cloneport); char const *(*su_port_name)(su_port_t const *port); int (*su_port_start_shared)(su_root_t *root, su_clone_r return_clone, su_root_magic_t *magic, su_root_init_f init, su_root_deinit_f deinit); void (*su_port_wait)(su_clone_r rclone); int (*su_port_execute)(su_task_r const task, int (*function)(void *), void *arg, int *return_value); } su_port_vtable_t;SOFIAPUBFUN su_port_t *su_port_create(void) __attribute__((__malloc__));/* Extension from >= 1.12.5 */SOFIAPUBFUN void su_msg_delivery_report(su_msg_r msg);SOFIAPUBFUN su_duration_t su_timer_next_expires(su_timer_t const * t, su_time_t now);SOFIAPUBFUN su_root_t *su_root_create_with_port(su_root_magic_t *magic, su_port_t *port) __attribute__((__malloc__));/* Extension from >= 1.12.6 */SOFIAPUBFUN char const *su_port_name(su_port_t const *port);/* ---------------------------------------------------------------------- *//* React to multiple events per one poll() to make sure * that high-priority events can never completely mask other events. * Enabled by default on all platforms except WIN32 */#if !defined(WIN32)#define SU_ENABLE_MULTISHOT_POLL 1#else#define SU_ENABLE_MULTISHOT_POLL 0#endif/* ---------------------------------------------------------------------- *//* Virtual functions */typedef struct su_virtual_port_s { su_home_t sup_home[1]; su_port_vtable_t const *sup_vtable;} su_virtual_port_t;su_inlinesu_home_t *su_port_home(su_port_t const *self){ return (su_home_t *)self;}su_inlinevoid su_port_lock(su_port_t *self, char const *who){ su_virtual_port_t *base = (su_virtual_port_t *)self; base->sup_vtable->su_port_lock(self, who);}su_inlinevoid su_port_unlock(su_port_t *self, char const *who){ su_virtual_port_t *base = (su_virtual_port_t *)self; base->sup_vtable->su_port_unlock(self, who);}su_inlinevoid su_port_incref(su_port_t *self, char const *who){ su_virtual_port_t *base = (su_virtual_port_t *)self; base->sup_vtable->su_port_incref(self, who);}su_inlinevoid su_port_decref(su_port_t *self, char const *who){ su_virtual_port_t *base = (su_virtual_port_t *)self; base->sup_vtable->su_port_decref(self, 0, who);}su_inlinevoid su_port_zapref(su_port_t *self, char const *who){ su_virtual_port_t *base = (su_virtual_port_t *)self; base->sup_vtable->su_port_decref(self, 1, who);}su_inlinestruct _GSource *su_port_gsource(su_port_t *self){ su_virtual_port_t *base = (su_virtual_port_t *)self; return base->sup_vtable->su_port_gsource(self);}su_inlineint su_port_send(su_port_t *self, su_msg_r rmsg){ su_virtual_port_t *base = (su_virtual_port_t *)self; return base->sup_vtable->su_port_send(self, rmsg);}su_inlineint su_port_register(su_port_t *self, su_root_t *root, su_wait_t *wait, su_wakeup_f callback, su_wakeup_arg_t *arg, int priority){ su_virtual_port_t *base = (su_virtual_port_t *)self; return base->sup_vtable-> su_port_register(self, root, wait, callback, arg, priority);}su_inlineint su_port_unregister(su_port_t *self, su_root_t *root, su_wait_t *wait, su_wakeup_f callback, su_wakeup_arg_t *arg){ su_virtual_port_t *base = (su_virtual_port_t *)self; return base->sup_vtable-> su_port_unregister(self, root, wait, callback, arg);}su_inlineint su_port_deregister(su_port_t *self, int i){ su_virtual_port_t *base = (su_virtual_port_t *)self; return base->sup_vtable-> su_port_deregister(self, i);}su_inlineint su_port_unregister_all(su_port_t *self, su_root_t *root){ su_virtual_port_t *base = (su_virtual_port_t *)self; return base->sup_vtable-> su_port_unregister_all(self, root);}su_inline
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -