notifier_domain.h

00001 /* 
00002  * Copyright (C) 2005 iptelorg GmbH
00003  *
00004  * This file is part of ser, a free SIP server.
00005  *
00006  * ser is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version
00010  *
00011  * For a license to use the ser software under conditions
00012  * other than those described here, or to purchase support for this
00013  * software, please contact iptel.org by e-mail at the following addresses:
00014  *    info@iptel.org
00015  *
00016  * ser is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  */
00025 
00026 #ifndef __NOTIFIER_DOMAIN_H
00027 #define __NOTIFIER_DOMAIN_H
00028 
00029 #include <cds/sstr.h>
00030 #include <cds/ptr_vector.h>
00031 #include <cds/sync.h>
00032 
00033 #include <presence/qsa_params.h>
00034 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038 
00039 struct _qsa_subscription_t;
00040 typedef struct _qsa_subscription_t qsa_subscription_t;
00041 struct _notifier_package_t;
00042 typedef struct _notifier_package_t notifier_package_t;
00043 struct _notifier_t;
00044 typedef struct _notifier_t notifier_t;
00045 struct _notifier_domain_t;
00046 typedef struct _notifier_domain_t notifier_domain_t;
00047 
00048 /* data hold by subscriber for the time of subscription duration 
00049  * (from subscribe to unsubscribe; after calling unsubscribe can
00050  * be destroyed contents of them) */
00051 typedef struct _qsa_subscription_data_t {
00052         msg_queue_t *dst;
00053         str_t record_id;
00054         str_t subscriber_id;
00055         qsa_subscription_params_t *first_param;
00056         void *subscriber_data;
00057 } qsa_subscription_data_t;
00058 
00062 struct _qsa_subscription_t {
00063         /* client_notify_func notify; */
00064         cds_mutex_t *mutex;
00065         notifier_package_t *package;
00066         int allow_notifications;
00067         qsa_subscription_data_t *data;
00068         struct _qsa_subscription_t *prev, *next;
00069         reference_counter_data_t ref;
00070 };
00071 
00072 /* typedef void (*client_notify_func)(client_notify_info_t *info); */
00073 
00074 typedef int (*server_subscribe_func)(notifier_t *n, qsa_subscription_t *subscription);
00075 
00076 typedef void (*server_unsubscribe_func)(notifier_t *n, qsa_subscription_t *subscription);
00077 
00078 typedef struct _qsa_content_type_t {
00079         struct _qsa_content_type_t *next, *prev;
00080         str_t name;
00081         destroy_function_f destroy_func;
00082         char buf[1]; /* buffer for name allocation together with the structure */
00083 } qsa_content_type_t;
00084 
00086 struct _notifier_t {
00087         server_subscribe_func subscribe;
00088         server_unsubscribe_func unsubscribe;
00089         void *user_data; /* private data for this notifier */
00090         notifier_package_t *package;
00091         struct _notifier_t *prev, *next; 
00092 };
00093 
00094 struct _notifier_package_t {
00095         str_t name;
00096         /* maybe: serialize and deserialize methods */
00097         notifier_domain_t *domain;
00098         notifier_t *first_notifier, *last_notifier; /* notifiers are linked in theirs package! */
00099         qsa_subscription_t *first_subscription, *last_subscription;
00100         notifier_package_t *next, *prev;
00101 };
00102 
00103 struct _notifier_domain_t {
00104         cds_mutex_t mutex;
00105         cds_mutex_t data_mutex; /* mutex for locking standalone subscription data, may be changed to mutex pool */
00106         str_t name;
00107         notifier_package_t *first_package, *last_package;
00108         qsa_content_type_t *first_content_type, *last_content_type;
00109         reference_counter_data_t ref;
00110         reference_counter_group_t *rc_grp;
00111 };
00112 
00113 /* -------- Domain initialization/destruction functions -------- */
00114 
00116 notifier_domain_t *create_notifier_domain(reference_counter_group_t *g, const str_t *name);
00117 
00121 void destroy_notifier_domain(notifier_domain_t *domain);
00122 
00123 qsa_content_type_t *register_content_type(notifier_domain_t *d, 
00124                 const str_t *name,
00125                 destroy_function_f destroy_func);
00126 
00127 #define lock_notifier_domain(d) cds_mutex_lock(&(d->mutex))
00128 #define unlock_notifier_domain(d) cds_mutex_unlock(&(d->mutex))
00129 
00130 #ifdef __cplusplus
00131 }
00132 #endif
00133 
00134 
00135 #endif