make the obj_ primitives more liberal to make for easier calling

remotes/origin/2.0
Richard Fuchs 13 years ago
parent 540d847d08
commit 856c0b9cce

@ -611,11 +611,11 @@ struct callmaster *callmaster_new(struct poller *p) {
poller_timer(p, callmaster_timer, &c->obj); poller_timer(p, callmaster_timer, &c->obj);
obj_put(&c->obj); obj_put(c);
return c; return c;
fail: fail:
obj_put(&c->obj); obj_put(c);
return NULL; return NULL;
} }
@ -905,7 +905,7 @@ void callstream_init(struct callstream *s, struct call *ca, int port1, int port2
ZERO(pi); ZERO(pi);
s->call = obj_get(&ca->obj); s->call = obj_get(ca);
DBG("setting new callstream num to %i", num); DBG("setting new callstream num to %i", num);
s->num = num; s->num = num;
@ -970,7 +970,7 @@ static void callstream_free(void *ptr) {
} }
} }
} }
obj_put(&s->call->obj); obj_put(s->call);
} }
static int call_streams(struct call *c, GQueue *s, const char *tag, int opmode) { static int call_streams(struct call *c, GQueue *s, const char *tag, int opmode) {
@ -1209,10 +1209,10 @@ static void call_destroy(struct call *c) {
s->peers[1].rtps[1].localport, s->peers[1].rtps[1].stats.packets, s->peers[1].rtps[1].localport, s->peers[1].rtps[1].stats.packets,
s->peers[1].rtps[1].stats.bytes, s->peers[1].rtps[1].stats.errors); s->peers[1].rtps[1].stats.bytes, s->peers[1].rtps[1].stats.errors);
kill_callstream(s); kill_callstream(s);
obj_put(&s->obj); obj_put(s);
} }
obj_put(&c->obj); obj_put(c);
} }
@ -1333,10 +1333,10 @@ struct call *call_get_or_create(const char *callid, const char *viabranch, struc
if (!c) { if (!c) {
/* completely new call-id, create call */ /* completely new call-id, create call */
c = call_create(callid, m); c = call_create(callid, m);
g_hash_table_insert(m->callhash, c->callid, obj_get(&c->obj)); g_hash_table_insert(m->callhash, c->callid, obj_get(c));
} }
else else
obj_hold(&c->obj); obj_hold(c);
if (viabranch && !g_hash_table_lookup(c->branches, viabranch)) if (viabranch && !g_hash_table_lookup(c->branches, viabranch))
g_hash_table_insert(c->branches, strdup(viabranch), (void *) 0x1); g_hash_table_insert(c->branches, strdup(viabranch), (void *) 0x1);
@ -1415,14 +1415,14 @@ char *call_update_udp(const char **out, struct callmaster *m) {
ret = streams_print(c->callstreams, 1, (num >= 0) ? 0 : 1, out[RE_UDP_COOKIE], 1); ret = streams_print(c->callstreams, 1, (num >= 0) ? 0 : 1, out[RE_UDP_COOKIE], 1);
mylog(LOG_INFO, LOG_PREFIX_CI "Returning to SIP proxy: %s", LOG_PARAMS_CI(c), ret); mylog(LOG_INFO, LOG_PREFIX_CI "Returning to SIP proxy: %s", LOG_PARAMS_CI(c), ret);
c->log_info = NULL; c->log_info = NULL;
obj_put(&c->obj); obj_put(c);
return ret; return ret;
fail: fail:
mylog(LOG_WARNING, "Failed to parse a media stream: %s/%s:%s", out[RE_UDP_UL_ADDR4], out[RE_UDP_UL_ADDR6], out[RE_UDP_UL_PORT]); mylog(LOG_WARNING, "Failed to parse a media stream: %s/%s:%s", out[RE_UDP_UL_ADDR4], out[RE_UDP_UL_ADDR6], out[RE_UDP_UL_PORT]);
asprintf(&ret, "%s E8\n", out[RE_UDP_COOKIE]); asprintf(&ret, "%s E8\n", out[RE_UDP_COOKIE]);
c->log_info = NULL; c->log_info = NULL;
obj_put(&c->obj); obj_put(c);
return ret; return ret;
} }
@ -1440,7 +1440,7 @@ char *call_lookup_udp(const char **out, struct callmaster *m) {
asprintf(&ret, "%s 0 " IPF "\n", out[RE_UDP_COOKIE], IPP(m->ipv4)); asprintf(&ret, "%s 0 " IPF "\n", out[RE_UDP_COOKIE], IPP(m->ipv4));
return ret; return ret;
} }
obj_hold(&c->obj); obj_hold(c);
c->log_info = out[RE_UDP_UL_CALLID]; c->log_info = out[RE_UDP_UL_CALLID];
strdupfree(&c->called_agent, "UNKNOWN(udp)"); strdupfree(&c->called_agent, "UNKNOWN(udp)");
@ -1459,14 +1459,14 @@ char *call_lookup_udp(const char **out, struct callmaster *m) {
ret = streams_print(c->callstreams, 1, (num >= 0) ? 1 : 0, out[RE_UDP_COOKIE], 1); ret = streams_print(c->callstreams, 1, (num >= 0) ? 1 : 0, out[RE_UDP_COOKIE], 1);
mylog(LOG_INFO, LOG_PREFIX_CI "Returning to SIP proxy: %s", LOG_PARAMS_CI(c), ret); mylog(LOG_INFO, LOG_PREFIX_CI "Returning to SIP proxy: %s", LOG_PARAMS_CI(c), ret);
c->log_info = NULL; c->log_info = NULL;
obj_put(&c->obj); obj_put(c);
return ret; return ret;
fail: fail:
mylog(LOG_WARNING, "Failed to parse a media stream: %s/%s:%s", out[RE_UDP_UL_ADDR4], out[RE_UDP_UL_ADDR6], out[RE_UDP_UL_PORT]); mylog(LOG_WARNING, "Failed to parse a media stream: %s/%s:%s", out[RE_UDP_UL_ADDR4], out[RE_UDP_UL_ADDR6], out[RE_UDP_UL_PORT]);
asprintf(&ret, "%s E8\n", out[RE_UDP_COOKIE]); asprintf(&ret, "%s E8\n", out[RE_UDP_COOKIE]);
c->log_info = NULL; c->log_info = NULL;
obj_put(&c->obj); obj_put(c);
return ret; return ret;
} }
@ -1489,7 +1489,7 @@ char *call_request(const char **out, struct callmaster *m) {
ret = streams_print(c->callstreams, abs(num), (num >= 0) ? 0 : 1, NULL, 0); ret = streams_print(c->callstreams, abs(num), (num >= 0) ? 0 : 1, NULL, 0);
mylog(LOG_INFO, LOG_PREFIX_CI "Returning to SIP proxy: %s", LOG_PARAMS_CI(c), ret); mylog(LOG_INFO, LOG_PREFIX_CI "Returning to SIP proxy: %s", LOG_PARAMS_CI(c), ret);
obj_put(&c->obj); obj_put(c);
return ret; return ret;
} }
@ -1505,7 +1505,7 @@ char *call_lookup(const char **out, struct callmaster *m) {
return NULL; return NULL;
} }
obj_hold(&c->obj); obj_hold(c);
strdupfree(&c->called_agent, out[RE_TCP_RL_AGENT] ? : "UNKNOWN"); strdupfree(&c->called_agent, out[RE_TCP_RL_AGENT] ? : "UNKNOWN");
info_parse(out[RE_TCP_RL_INFO], &c->infohash); info_parse(out[RE_TCP_RL_INFO], &c->infohash);
@ -1518,7 +1518,7 @@ char *call_lookup(const char **out, struct callmaster *m) {
ret = streams_print(c->callstreams, abs(num), (num >= 0) ? 1 : 0, NULL, 0); ret = streams_print(c->callstreams, abs(num), (num >= 0) ? 1 : 0, NULL, 0);
mylog(LOG_INFO, LOG_PREFIX_CI "Returning to SIP proxy: %s", LOG_PARAMS_CI(c), ret); mylog(LOG_INFO, LOG_PREFIX_CI "Returning to SIP proxy: %s", LOG_PARAMS_CI(c), ret);
obj_put(&c->obj); obj_put(c);
return ret; return ret;
} }
@ -1538,7 +1538,7 @@ char *call_delete_udp(const char **out, struct callmaster *m) {
mylog(LOG_INFO, LOG_PREFIX_C "Call-ID to delete not found", out[RE_UDP_D_CALLID]); mylog(LOG_INFO, LOG_PREFIX_C "Call-ID to delete not found", out[RE_UDP_D_CALLID]);
goto err; goto err;
} }
obj_hold(&c->obj); obj_hold(c);
c->log_info = out[RE_UDP_D_VIABRANCH]; c->log_info = out[RE_UDP_D_VIABRANCH];
if (out[RE_UDP_D_FROMTAG] && *out[RE_UDP_D_FROMTAG]) { if (out[RE_UDP_D_FROMTAG] && *out[RE_UDP_D_FROMTAG]) {
@ -1597,7 +1597,7 @@ err:
out: out:
if (c) { if (c) {
c->log_info = NULL; c->log_info = NULL;
obj_put(&c->obj); obj_put(c);
} }
return ret; return ret;
} }
@ -1609,10 +1609,10 @@ void call_delete(const char **out, struct callmaster *m) {
if (!c) if (!c)
return; return;
obj_hold(&c->obj); obj_hold(c);
/* delete whole list, as we don't have branches in tcp controller */ /* delete whole list, as we don't have branches in tcp controller */
call_destroy(c); call_destroy(c);
obj_put(&c->obj); obj_put(c);
} }

@ -27,7 +27,7 @@ static void control_stream_closed(int fd, void *p, uintptr_t u) {
c = s->control; c = s->control;
c->streams = g_list_remove(c->streams, s); c->streams = g_list_remove(c->streams, s);
obj_put(&s->obj); obj_put(s);
if (poller_del_item(s->poller, fd)) if (poller_del_item(s->poller, fd))
abort(); abort();
@ -197,7 +197,7 @@ static void control_incoming(int fd, void *p, uintptr_t u) {
return; return;
fail: fail:
obj_put(&s->obj); obj_put(s);
} }
@ -244,11 +244,11 @@ struct control *control_new(struct poller *p, u_int32_t ip, u_int16_t port, stru
if (poller_add_item(p, &i)) if (poller_add_item(p, &i))
goto fail2; goto fail2;
obj_put(&c->obj); obj_put(c);
return c; return c;
fail2: fail2:
obj_put(&c->obj); obj_put(c);
fail: fail:
close(fd); close(fd);
return NULL; return NULL;

@ -100,11 +100,12 @@ static inline void *__obj_alloc0(unsigned int size, void (*free_func)(void *)
return r; return r;
} }
static inline struct obj *__obj_hold(struct obj *o static inline struct obj *__obj_hold(void *p
#if OBJ_DEBUG #if OBJ_DEBUG
, const char *file, unsigned int line , const char *file, unsigned int line
#endif #endif
) { ) {
struct obj *o = p;
#if OBJ_DEBUG #if OBJ_DEBUG
assert(o->magic == OBJ_MAGIC); assert(o->magic == OBJ_MAGIC);
mylog(LOG_DEBUG, "obj_hold(%p, \"%s\", size %u), refcnt before %u [%s:%u]", mylog(LOG_DEBUG, "obj_hold(%p, \"%s\", size %u), refcnt before %u [%s:%u]",
@ -118,23 +119,24 @@ static inline struct obj *__obj_hold(struct obj *o
return o; return o;
} }
static inline void *__obj_get(struct obj *o static inline void *__obj_get(void *p
#if OBJ_DEBUG #if OBJ_DEBUG
, const char *file, unsigned int line , const char *file, unsigned int line
#endif #endif
) { ) {
return __obj_hold(o return __obj_hold(p
#if OBJ_DEBUG #if OBJ_DEBUG
, file, line , file, line
#endif #endif
); );
} }
static inline void __obj_put(struct obj *o static inline void __obj_put(void *p
#if OBJ_DEBUG #if OBJ_DEBUG
, const char *file, unsigned int line , const char *file, unsigned int line
#endif #endif
) { ) {
struct obj *o = p;
#if OBJ_DEBUG #if OBJ_DEBUG
assert(o->magic == OBJ_MAGIC); assert(o->magic == OBJ_MAGIC);
mylog(LOG_DEBUG, "obj_put(%p, \"%s\", size %u), refcnt before %u [%s:%u]", mylog(LOG_DEBUG, "obj_put(%p, \"%s\", size %u), refcnt before %u [%s:%u]",

@ -122,14 +122,14 @@ static int __poller_add_item(struct poller *p, struct poller_item *i, int has_lo
ip = obj_alloc0("poller_item_int", sizeof(*ip), poller_item_free); ip = obj_alloc0("poller_item_int", sizeof(*ip), poller_item_free);
memcpy(&ip->item, i, sizeof(*i)); memcpy(&ip->item, i, sizeof(*i));
obj_hold(ip->item.obj); /* new ref in *ip */ obj_hold(ip->item.obj); /* new ref in *ip */
p->items[i->fd] = obj_get(&ip->obj); p->items[i->fd] = obj_get(ip);
mutex_unlock(&p->lock); mutex_unlock(&p->lock);
if (i->timer) if (i->timer)
poller_timer(p, poller_fd_timer, &ip->obj); poller_timer(p, poller_fd_timer, &ip->obj);
obj_put(&ip->obj); obj_put(ip);
return 0; return 0;
@ -189,11 +189,11 @@ int poller_del_item(struct poller *p, int fd) {
} }
p->timers = g_list_remove_link(p->timers, l); p->timers = g_list_remove_link(p->timers, l);
ti = l->data; ti = l->data;
obj_put(&ti->obj); obj_put(ti);
g_list_free_1(l); g_list_free_1(l);
} }
obj_put(&it->obj); obj_put(it);
return 0; return 0;
@ -287,7 +287,7 @@ int poller_poll(struct poller *p, int timeout) {
if (!it) if (!it)
continue; continue;
obj_hold(&it->obj); obj_hold(it);
mutex_unlock(&p->lock); mutex_unlock(&p->lock);
if (it->error) { if (it->error) {
@ -318,7 +318,7 @@ int poller_poll(struct poller *p, int timeout) {
abort(); abort();
next: next:
obj_put(&it->obj); obj_put(it);
mutex_lock(&p->lock); mutex_lock(&p->lock);
} }

Loading…
Cancel
Save