#define zap_set_state_locked(obj, s) if ( obj->state == s ) { \
zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \
} else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \
- int st = obj->state; \
+ zap_channel_state_t st = obj->state; \
zap_channel_set_state(obj, s, 1); \
if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \
else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \
#endif
/*!
- \brief Allocate uninitialized memory
- \command chunksize the chunk size
+ \brief Assert condition
+*/
+#define zap_assert(assertion, msg) \
+ if (!(assertion)) { \
+ zap_log(ZAP_LOG_CRIT, msg); \
+ if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \
+ abort(); \
+ } \
+ }
+
+/*!
+ \brief Assert condition and return
*/
-#define zap_assert(assertion, retval, msg) \
+#define zap_assert_return(assertion, retval, msg) \
if (!(assertion)) { \
zap_log(ZAP_LOG_CRIT, msg); \
if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \
if (--boost_request_timeout <= 0) {
status = ZAP_FAIL;
*zchan = NULL;
- zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response\n");
+ zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_WAITING\n");
goto done;
}
}
zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS [Csid:%d]\n", r);
}
- sanity = 5000;
+ boost_request_timeout = 5000;
while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_ACK) {
zap_sleep(1);
- if (--sanity <= 0) {
- status = ZAP_FAIL;
- *zchan = NULL;
- goto done;
+ if (--boost_request_timeout <= 0) {
+ status = ZAP_FAIL;
+ *zchan = NULL;
+ zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_ACK\n");
+ goto done;
}
//printf("WTF %d\n", sanity);
}
zap_sangoma_boost_data_t *sangoma_boost_data = NULL;
sangomabc_queue_element_t *element = NULL;
- zap_assert(msg != NULL, ZAP_FAIL, "Boost message to write was null");
+ zap_assert_return(msg != NULL, ZAP_FAIL, "Boost message to write was null");
if (!span) {
shortmsg = msg;
{
void *ptr = malloc(size);
pool = NULL; /* fix warning */
- zap_assert(ptr != NULL, NULL, "Out of memory");
+ zap_assert_return(ptr != NULL, NULL, "Out of memory");
return ptr;
}
{
void *ptr = calloc(elements, size);
pool = NULL;
- zap_assert(ptr != NULL, NULL, "Out of memory");
+ zap_assert_return(ptr != NULL, NULL, "Out of memory");
return ptr;
}
static __inline__ void zap_std_free(void *pool, void *ptr)
{
pool = NULL;
- zap_assert(ptr != NULL, , "Attempted to free null pointer");
+ zap_assert_return(ptr != NULL, , "Attempted to free null pointer");
free(ptr);
}
OZ_DECLARE(zap_status_t) zap_channel_get_sig_status(zap_channel_t *zchan, zap_channel_sig_status_t *sigstatus)
{
- zap_assert(zchan != NULL, ZAP_FAIL, "Null channel\n");
- zap_assert(sigstatus != NULL, ZAP_FAIL, "Null sig status");
+ zap_assert_return(zchan != NULL, ZAP_FAIL, "Null channel\n");
+ zap_assert_return(sigstatus != NULL, ZAP_FAIL, "Null sig status");
if (zchan->span->get_sig_status) {
return zchan->span->get_sig_status(zchan, sigstatus);
zap_module_t *mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type);
zap_status_t status = ZAP_FAIL;
- zap_assert(type != NULL, ZAP_FAIL, "No signaling type");
- zap_assert(span != NULL, ZAP_FAIL, "No span");
- zap_assert(sig_cb != NULL, ZAP_FAIL, "No signaling callback");
- zap_assert(parameters != NULL, ZAP_FAIL, "No parameters");
+ zap_assert_return(type != NULL, ZAP_FAIL, "No signaling type");
+ zap_assert_return(span != NULL, ZAP_FAIL, "No span");
+ zap_assert_return(sig_cb != NULL, ZAP_FAIL, "No signaling callback");
+ zap_assert_return(parameters != NULL, ZAP_FAIL, "No parameters");
if (!mod) {
zap_load_module_assume(type);
static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t capacity)
{
- zap_assert(outqueue, ZAP_FAIL, "Queue double pointer is null\n");
- zap_assert(capacity > 0, ZAP_FAIL, "Queue capacity is not bigger than 0\n");
+ zap_assert_return(outqueue, ZAP_FAIL, "Queue double pointer is null\n");
+ zap_assert_return(capacity > 0, ZAP_FAIL, "Queue capacity is not bigger than 0\n");
*outqueue = NULL;
zap_queue_t *queue = zap_calloc(1, sizeof(*queue));
{
zap_status_t status = ZAP_FAIL;
- zap_assert(queue != NULL, ZAP_FAIL, "Queue is null!");
+ zap_assert_return(queue != NULL, ZAP_FAIL, "Queue is null!");
zap_mutex_lock(queue->mutex);
{
void *obj = NULL;
- zap_assert(queue != NULL, NULL, "Queue is null!");
+ zap_assert_return(queue != NULL, NULL, "Queue is null!");
zap_mutex_lock(queue->mutex);
static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms)
{
zap_status_t ret;
- zap_assert(queue != NULL, ZAP_FAIL, "Queue is null!");
+ zap_assert_return(queue != NULL, ZAP_FAIL, "Queue is null!");
zap_mutex_lock(queue->mutex);
static zap_status_t zap_std_queue_destroy(zap_queue_t **inqueue)
{
zap_queue_t *queue = NULL;
- zap_assert(inqueue != NULL, ZAP_FAIL, "Queue is null!");
- zap_assert(*inqueue != NULL, ZAP_FAIL, "Queue is null!");
+ zap_assert_return(inqueue != NULL, ZAP_FAIL, "Queue is null!");
+ zap_assert_return(*inqueue != NULL, ZAP_FAIL, "Queue is null!");
queue = *inqueue;
zap_condition_destroy(&queue->condition);
{
zap_condition_t *condition = NULL;
- zap_assert(incondition != NULL, ZAP_FAIL, "Condition double pointer is null!\n");
- zap_assert(mutex != NULL, ZAP_FAIL, "Mutex for condition must not be null!\n");
+ zap_assert_return(incondition != NULL, ZAP_FAIL, "Condition double pointer is null!\n");
+ zap_assert_return(mutex != NULL, ZAP_FAIL, "Mutex for condition must not be null!\n");
condition = zap_calloc(1, sizeof(*condition));
if (!condition) {
#ifdef WIN32
DWORD res = 0;
#endif
- zap_assert(condition != NULL, ZAP_FAIL, "Condition is null!\n");
+ zap_assert_return(condition != NULL, ZAP_FAIL, "Condition is null!\n");
#ifdef WIN32
res = WaitForSingleObject(condition->condition, ms > 0 ? ms : INFINITE);
switch (res) {
OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *condition)
{
- zap_assert(condition != NULL, ZAP_FAIL, "Condition is null!\n");
+ zap_assert_return(condition != NULL, ZAP_FAIL, "Condition is null!\n");
#ifdef WIN32
if (!SetEvent(condition->condition)) {
return ZAP_FAIL;
OZ_DECLARE(zap_status_t) zap_condition_destroy(zap_condition_t **incondition)
{
zap_condition_t *condition = NULL;
- zap_assert(incondition != NULL, ZAP_FAIL, "Condition null when destroying!\n");
+ zap_assert_return(incondition != NULL, ZAP_FAIL, "Condition null when destroying!\n");
condition = *incondition;
#ifdef WIN32
CloseHandle(condition->condition);