su_port.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of the Sofia-SIP package
00003  *
00004  * Copyright (C) 2005 Nokia Corporation.
00005  *
00006  * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation; either version 2.1 of
00011  * the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  *
00023  */
00024 
00025 #ifndef SU_PORT_H
00026 
00027 #define SU_PORT_H
00028 
00040 #ifndef SU_MSG_ARG_T
00041 #define SU_MSG_ARG_T union { char anoymous[4]; }
00042 #endif
00043 
00044 #ifndef SU_WAIT_H
00045 #include "sofia-sip/su_wait.h"
00046 #endif
00047 
00048 #ifndef SU_MODULE_DEBUG_H
00049 #include "su_module_debug.h"
00050 #endif
00051 
00052 #ifndef SU_ALLOC_H
00053 #include <sofia-sip/su_alloc.h>
00054 #endif
00055 
00056 #include <assert.h>
00057 
00058 #define SU_WAIT_MIN    (16)
00059 
00060 SOFIA_BEGIN_DECLS
00061 
00063 struct su_msg_s {
00064   isize_t        sum_size;
00065   su_msg_t      *sum_next;
00066   su_task_r      sum_to;
00067   su_task_r      sum_from;
00068   su_msg_f       sum_func;
00069   su_msg_f       sum_report;
00070   su_msg_arg_t   sum_data[1];           /* minimum size, may be extended */
00071 };
00072 
00073 struct _GSource;
00074 
00076 struct su_root_s {
00077   int              sur_size;
00078   su_root_magic_t *sur_magic;
00079   su_root_deinit_f sur_deinit;
00080   su_task_r        sur_task;
00081   su_task_r        sur_parent;
00082   unsigned         sur_threading : 1;
00083   unsigned         sur_deiniting : 1;
00084 };
00085 
00086 #define SU_ROOT_MAGIC(r) ((r) ? (r)->sur_magic : NULL)
00087 
00089 typedef struct {
00090   unsigned su_vtable_size;
00091   void (*su_port_lock)(su_port_t *port, char const *who);
00092   void (*su_port_unlock)(su_port_t *port, char const *who);
00093   void (*su_port_incref)(su_port_t *port, char const *who);
00094   void (*su_port_decref)(su_port_t *port, int block, char const *who);
00095   struct _GSource *(*su_port_gsource)(su_port_t *port);
00096   int (*su_port_send)(su_port_t *self, su_msg_r rmsg);
00097   int (*su_port_register)(su_port_t *self,
00098                        su_root_t *root, 
00099                        su_wait_t *wait, 
00100                        su_wakeup_f callback,
00101                        su_wakeup_arg_t *arg,
00102                        int priority);
00103   int (*su_port_unregister)(su_port_t *port,
00104                             su_root_t *root, 
00105                             su_wait_t *wait,    
00106                             su_wakeup_f callback, 
00107                             su_wakeup_arg_t *arg);
00108   int (*su_port_deregister)(su_port_t *self, int i);
00109   int (*su_port_unregister_all)(su_port_t *self,
00110                              su_root_t *root);
00111   int (*su_port_eventmask)(su_port_t *self, int index, int socket, int events);
00112   void (*su_port_run)(su_port_t *self);
00113   void (*su_port_break)(su_port_t *self);
00114   su_duration_t (*su_port_step)(su_port_t *self, su_duration_t tout);
00115   
00116   int (*su_port_own_thread)(su_port_t const *port);
00117   
00118   int (*su_port_add_prepoll)(su_port_t *port,
00119                              su_root_t *root, 
00120                              su_prepoll_f *, 
00121                              su_prepoll_magic_t *);
00122   
00123   int (*su_port_remove_prepoll)(su_port_t *port,
00124                                 su_root_t *root);
00125 
00126   su_timer_t **(*su_port_timers)(su_port_t *port);
00127 
00128   int (*su_port_multishot)(su_port_t *port, int multishot);
00129 
00130   int (*su_port_threadsafe)(su_port_t *port);
00131   
00132   /* Extension from > 1.12.0 */
00133   int (*su_port_yield)(su_port_t *port);
00134 } su_port_vtable_t;
00135 
00136 SOFIAPUBFUN su_port_t *su_port_create(void)
00137      __attribute__((__malloc__));
00138 
00139 SOFIAPUBFUN void su_msg_delivery_report(su_msg_r msg);
00140 SOFIAPUBFUN su_duration_t su_timer_next_expires(su_timer_t const * t,
00141                                                 su_time_t now);
00142 SOFIAPUBFUN su_root_t *su_root_create_with_port(su_root_magic_t *magic,
00143                                                 su_port_t *port);
00144 
00145 #if SU_PORT_IMPLEMENTATION
00146 
00147 #else
00148 struct su_port_s {
00149   su_home_t               sup_home[1];
00150   su_port_vtable_t const *sup_vtable;
00151 };
00152 
00153 static inline
00154 void su_port_lock(su_port_t *self, char const *who)
00155 {
00156   if (self) self->sup_vtable->su_port_lock(self, who);
00157 }
00158 
00159 #define SU_PORT_LOCK(p, f)      (su_port_lock(p, #f))
00160  
00161 static inline
00162 void su_port_unlock(su_port_t *self, char const *who)
00163 {
00164   if (self) self->sup_vtable->su_port_unlock(self, who);
00165 }
00166 
00167 #define SU_PORT_UNLOCK(p, f)    (su_port_unlock(p, #f))
00168 
00169 static inline
00170 void su_port_incref(su_port_t *self, char const *who)
00171 {
00172   if (self) self->sup_vtable->su_port_incref(self, who);
00173 }
00174 
00175 #define SU_PORT_INCREF(p, f)    (su_port_incref(p, #f))
00176  
00177 static inline
00178 void su_port_decref(su_port_t *self, char const *who)
00179 {
00180   if (self) self->sup_vtable->su_port_decref(self, 0, who);
00181 }
00182 
00183 #define SU_PORT_DECREF(p, f)    (su_port_decref(p, #f))
00184 
00185 static inline
00186 void su_port_zapref(su_port_t *self, char const *who)
00187 {
00188   if (self) self->sup_vtable->su_port_decref(self, 1, who);
00189 }
00190 
00191 #define SU_PORT_ZAPREF(p, f)    (su_port_zapref(p, #f))
00192 
00193 static inline
00194 struct _GSource *su_port_gsource(su_port_t *self)
00195 {
00196   return self ? self->sup_vtable->su_port_gsource(self) : NULL;
00197 }
00198 
00199 
00200 static inline
00201 int su_port_send(su_port_t *self, su_msg_r rmsg)
00202 {
00203   if (self) 
00204     return self->sup_vtable->su_port_send(self, rmsg);
00205   errno = EINVAL;
00206   return -1;
00207 }
00208 
00209 
00210 static inline
00211 int su_port_register(su_port_t *self,
00212                      su_root_t *root, 
00213                      su_wait_t *wait, 
00214                      su_wakeup_f callback,
00215                      su_wakeup_arg_t *arg,
00216                      int priority)
00217 {
00218   if (self)
00219     return self->sup_vtable->su_port_register(self, root, wait,
00220                                               callback, arg, priority);
00221   errno = EINVAL;
00222   return -1;
00223 }
00224 
00225 static inline
00226 int su_port_unregister(su_port_t *self,
00227                        su_root_t *root, 
00228                        su_wait_t *wait, 
00229                        su_wakeup_f callback, 
00230                        su_wakeup_arg_t *arg)
00231 {
00232   if (self)
00233     return self->sup_vtable->
00234       su_port_unregister(self, root, wait, callback, arg);
00235   errno = EINVAL;
00236   return -1;
00237 }
00238 
00239 static inline
00240 int su_port_deregister(su_port_t *self, int i)
00241 {
00242   if (self)
00243     return self->sup_vtable->
00244       su_port_deregister(self, i);
00245   errno = EINVAL;
00246   return -1;
00247 }
00248 
00249 static inline
00250 int su_port_unregister_all(su_port_t *self,
00251                            su_root_t *root)
00252 {
00253   if (self)
00254     return self->sup_vtable->
00255       su_port_unregister_all(self, root);
00256   errno = EINVAL;
00257   return -1;
00258 }
00259 
00260 static inline
00261 int su_port_eventmask(su_port_t *self, int index, int socket, int events)
00262 {
00263   if (self)
00264     return self->sup_vtable->
00265       su_port_eventmask(self, index, socket, events);
00266   assert(self);
00267   errno = EINVAL;
00268   return -1;
00269 }
00270 
00271 static inline
00272 void su_port_run(su_port_t *self)
00273 {
00274   if (self)
00275     self->sup_vtable->su_port_run(self);
00276 }
00277 
00278 static inline
00279 void su_port_break(su_port_t *self)
00280 {
00281   if (self)
00282     self->sup_vtable->su_port_break(self);
00283 }
00284 
00285 static inline
00286 su_duration_t su_port_step(su_port_t *self, su_duration_t tout)
00287 {
00288   if (self)
00289     return self->sup_vtable->su_port_step(self, tout);
00290   errno = EINVAL;
00291   return (su_duration_t)-1;
00292 }
00293 
00294 
00295 static inline
00296 int su_port_own_thread(su_port_t const *self)
00297 {
00298   return self == NULL || self->sup_vtable->su_port_own_thread(self);
00299 }
00300 
00301 static inline
00302 int su_port_add_prepoll(su_port_t *self,
00303                         su_root_t *root, 
00304                         su_prepoll_f *prepoll, 
00305                         su_prepoll_magic_t *magic)
00306 {
00307   if (self)
00308     return self->sup_vtable->
00309       su_port_add_prepoll(self, root, prepoll, magic);
00310   errno = EINVAL;
00311   return -1;
00312 }
00313 
00314 static inline
00315 int su_port_remove_prepoll(su_port_t *self,
00316                            su_root_t *root)
00317 {
00318   if (self)
00319     return self->sup_vtable->su_port_remove_prepoll(self, root);
00320   errno = EINVAL;
00321   return -1;
00322 }
00323 
00324 static inline
00325 su_timer_t **su_port_timers(su_port_t *self)
00326 {
00327   if (self)
00328     return self->sup_vtable->su_port_timers(self);
00329   errno = EINVAL;
00330   return NULL;
00331 }
00332 
00333 static inline
00334 int su_port_multishot(su_port_t *self, int multishot)
00335 {
00336   if (self)
00337     return self->sup_vtable->su_port_multishot(self, multishot);
00338 
00339   assert(self);
00340   errno = EINVAL;
00341   return -1;
00342 }
00343 
00344 static inline
00345 int su_port_threadsafe(su_port_t *self)
00346 {
00347   if (self)
00348     return self->sup_vtable->su_port_threadsafe(self);
00349 
00350   assert(self);
00351   errno = EINVAL;
00352   return -1;
00353 }
00354 
00355 
00356 #endif
00357 
00358 SOFIA_END_DECLS
00359 
00360 #endif /* SU_PORT_H */

Sofia-SIP 1.12.4 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.