digest: add support for OpenSSL 1.1.0
[siplcs.git] / src / core / sipe-schedule.c
blob56d205bf64a17c693eece1206236554f9a056cb4
1 /**
2 * @file sipe-schedule.c
4 * pidgin-sipe
6 * Copyright (C) 2010 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <glib.h>
25 #include "sipe-backend.h"
26 #include "sipe-core.h"
27 #include "sipe-core-private.h"
28 #include "sipe-schedule.h"
30 struct sipe_schedule {
31 /**
32 * Name of action.
33 * Format is <Event>[<Data>...]
34 * Example: <presence><sip:user@domain.com> or <registration>
36 gchar *name;
37 struct sipe_core_private *sipe_private;
38 gpointer backend_private;
39 gpointer payload;
40 sipe_schedule_action action;
41 GDestroyNotify destroy;
44 static void sipe_schedule_deallocate(struct sipe_schedule *schedule)
46 if (schedule->destroy) (*schedule->destroy)(schedule->payload);
47 g_free(schedule->name);
48 g_free(schedule);
51 void sipe_core_schedule_execute(gpointer data)
53 struct sipe_schedule *expired = data;
54 struct sipe_core_private *sipe_private = expired->sipe_private;
56 SIPE_DEBUG_INFO("sipe_core_schedule_execute: executing %s", expired->name);
57 sipe_private->timeouts = g_slist_remove(sipe_private->timeouts, expired);
58 SIPE_DEBUG_INFO("sipe_core_schedule_execute timeouts count %d after removal",
59 g_slist_length(sipe_private->timeouts));
61 (*expired->action)(sipe_private, expired->payload);
62 sipe_schedule_deallocate(expired);
65 static struct sipe_schedule *sipe_schedule_allocate(struct sipe_core_private *sipe_private,
66 const gchar *name,
67 gpointer payload,
68 sipe_schedule_action action,
69 GDestroyNotify destroy)
71 struct sipe_schedule *new;
73 /* Make sure each action only exists once */
74 sipe_schedule_cancel(sipe_private, name);
76 new = g_new0(struct sipe_schedule, 1);
77 new->name = g_strdup(name);
78 new->sipe_private = sipe_private;
79 new->payload = payload;
80 new->action = action;
81 new->destroy = destroy;
82 sipe_private->timeouts = g_slist_append(sipe_private->timeouts, new);
83 SIPE_DEBUG_INFO("sipe_schedule_allocate timeouts count %d after addition",
84 g_slist_length(sipe_private->timeouts));
85 return(new);
88 void sipe_schedule_seconds(struct sipe_core_private *sipe_private,
89 const gchar *name,
90 gpointer payload,
91 guint seconds,
92 sipe_schedule_action action,
93 GDestroyNotify destroy)
95 struct sipe_schedule *new = sipe_schedule_allocate(sipe_private,
96 name,
97 payload,
98 action,
99 destroy);
100 SIPE_DEBUG_INFO("scheduling action %s timeout %d seconds",
101 name, seconds);
102 new->backend_private = sipe_backend_schedule_seconds(SIPE_CORE_PUBLIC,
103 seconds,
104 new);
107 void sipe_schedule_mseconds(struct sipe_core_private *sipe_private,
108 const gchar *name,
109 gpointer payload,
110 guint milliseconds,
111 sipe_schedule_action action,
112 GDestroyNotify destroy)
114 struct sipe_schedule *new = sipe_schedule_allocate(sipe_private,
115 name,
116 payload,
117 action,
118 destroy);
119 SIPE_DEBUG_INFO("scheduling action %s timeout %d milliseconds",
120 name, milliseconds);
121 new->backend_private = sipe_backend_schedule_mseconds(SIPE_CORE_PUBLIC,
122 milliseconds,
123 new);
126 static void sipe_schedule_remove(struct sipe_core_private *sipe_private,
127 struct sipe_schedule *schedule)
129 SIPE_DEBUG_INFO("sipe_schedule_remove: action name=%s",
130 schedule->name);
131 sipe_backend_schedule_cancel(SIPE_CORE_PUBLIC,
132 schedule->backend_private);
133 sipe_schedule_deallocate(schedule);
136 void sipe_schedule_cancel(struct sipe_core_private *sipe_private,
137 const gchar *name)
139 GSList *entry;
141 if (!sipe_private->timeouts || !name) return;
143 entry = sipe_private->timeouts;
144 while (entry) {
145 struct sipe_schedule *schedule = entry->data;
146 if (sipe_strequal(schedule->name, name)) {
147 GSList *to_delete = entry;
148 entry = entry->next;
149 sipe_private->timeouts = g_slist_delete_link(sipe_private->timeouts,
150 to_delete);
151 sipe_schedule_remove(sipe_private, schedule);
152 } else {
153 entry = entry->next;
158 void sipe_schedule_cancel_all(struct sipe_core_private *sipe_private)
160 GSList *entry = sipe_private->timeouts;
162 while (entry) {
163 sipe_schedule_remove(sipe_private, entry->data);
164 entry = entry->next;
167 g_slist_free(sipe_private->timeouts);
168 sipe_private->timeouts = NULL;
172 Local Variables:
173 mode: c
174 c-file-style: "bsd"
175 indent-tabs-mode: t
176 tab-width: 8
177 End: