Kannel: Open Source WAP and SMS gateway  svn-r5335
heartbeat.h File Reference
#include "gwlib/gwlib.h"
#include "msg.h"

Go to the source code of this file.

Macros

#define DEFAULT_HEARTBEAT   30
 
#define ALL_HEARTBEATS   -1
 

Typedefs

typedef long hb_load_func_t(void)
 
typedef void hb_send_func_t(Msg *hb)
 

Functions

long heartbeat_start (hb_send_func_t *send_func, double freq, hb_load_func_t *load_func)
 
void heartbeat_stop (long hb_thread)
 

Macro Definition Documentation

◆ ALL_HEARTBEATS

#define ALL_HEARTBEATS   -1

Definition at line 68 of file heartbeat.h.

Referenced by heartbeat_stop(), and main().

◆ DEFAULT_HEARTBEAT

#define DEFAULT_HEARTBEAT   30

Definition at line 67 of file heartbeat.h.

Referenced by heartbeat_start(), main(), and run_smppbox().

Typedef Documentation

◆ hb_load_func_t

typedef long hb_load_func_t(void)

Definition at line 72 of file heartbeat.h.

◆ hb_send_func_t

typedef void hb_send_func_t(Msg *hb)

Definition at line 78 of file heartbeat.h.

Function Documentation

◆ heartbeat_start()

long heartbeat_start ( hb_send_func_t send_func,
double  freq,
hb_load_func_t load_func 
)

Definition at line 126 of file heartbeat.c.

References DEFAULT_HEARTBEAT, hb_info::freq, gwlist_append(), gwlist_create, gwthread_create, heartbeat_thread(), heartbeats, info(), hb_info::load_func, and hb_info::send_func.

Referenced by main(), and run_smppbox().

128 {
129  struct hb_info *info;
130 
131  /* can't start with send_funct NULL */
132  if (send_func == NULL)
133  return -1;
134 
135  info = gw_malloc(sizeof(*info));
136  info->send_func = send_func;
137  info->freq = (freq <= 0 ? DEFAULT_HEARTBEAT : freq);
138  info->load_func = load_func;
139  info->running = 1;
141  if (info->thread >= 0) {
142  if (heartbeats == NULL)
145  return info->thread;
146  } else {
147  gw_free(info);
148  return -1;
149  }
150 }
void info(int err, const char *fmt,...)
Definition: log.c:672
void gwlist_append(List *list, void *item)
Definition: list.c:179
hb_send_func_t * send_func
Definition: heartbeat.c:72
double freq
Definition: heartbeat.c:73
static List * heartbeats
Definition: heartbeat.c:80
hb_load_func_t * load_func
Definition: heartbeat.c:74
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define DEFAULT_HEARTBEAT
Definition: heartbeat.h:67
#define gwlist_create()
Definition: list.h:136
static void heartbeat_thread(void *arg)
Definition: heartbeat.c:96

◆ heartbeat_stop()

void heartbeat_stop ( long  hb_thread)

Definition at line 160 of file heartbeat.c.

References ALL_HEARTBEATS, find_hb(), gw_assert(), gwlist_destroy(), gwlist_extract_first(), gwlist_extract_matching(), gwlist_len(), gwthread_join(), gwthread_wakeup(), heartbeats, info(), and warning().

Referenced by main().

161 {
162  List *matching_info;
163  struct hb_info *info;
164 
165  /*
166  * First, check if there are heartbeats to stop.
167  * If not, do not continue, otherwise this function will crash
168  */
169  if (heartbeats == NULL)
170  return;
171 
172  if (hb_thread == ALL_HEARTBEATS) {
173  while (NULL != (info = gwlist_extract_first(heartbeats))) {
174  gw_assert(info);
175  info->running = 0;
176  gwthread_wakeup(info->thread);
177  gwthread_join(info->thread);
178  gw_free(info);
179  }
180  } else {
181  matching_info = gwlist_extract_matching(heartbeats, &hb_thread, find_hb);
182  if (matching_info == NULL) {
183  warning(0, "Could not stop heartbeat %ld: not found.", hb_thread);
184  return;
185  }
186  gw_assert(gwlist_len(matching_info) == 1);
187  info = gwlist_extract_first(matching_info);
188  gwlist_destroy(matching_info, NULL);
189 
190  info->running = 0;
191  gwthread_wakeup(hb_thread);
192  gwthread_join(hb_thread);
193  gw_free(info);
194  }
195  if (gwlist_len(heartbeats) == 0) {
196  gwlist_destroy(heartbeats, NULL);
197  heartbeats = NULL;
198  }
199 }
void info(int err, const char *fmt,...)
Definition: log.c:672
gw_assert(wtls_machine->packet_to_send !=NULL)
void gwthread_join(long thread)
long gwlist_len(List *list)
Definition: list.c:166
List * gwlist_extract_matching(List *list, void *pat, gwlist_item_matches_t *cmp)
Definition: list.c:322
static int find_hb(void *item, void *pattern)
Definition: heartbeat.c:85
static List * heartbeats
Definition: heartbeat.c:80
void * gwlist_extract_first(List *list)
Definition: list.c:305
void warning(int err, const char *fmt,...)
Definition: log.c:660
#define ALL_HEARTBEATS
Definition: heartbeat.h:68
void gwthread_wakeup(long thread)
Definition: list.c:102
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.