summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-03-22 21:03:19 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-03-22 21:04:56 +0100
commitc4d01f9a909c3322ec803349615f83c2c695497e (patch)
tree78ac9abf45c787586a9183ac94099855fcf33281
parent29b556490f593a621e8356f5e64ced036152d306 (diff)
call: Add a backpointer from leg to call and drop the argument
Simplify the structure by either working with a call or just a leg of it. No need to carry both pointers all the time.
-rw-r--r--src/app.c4
-rw-r--r--src/call.c6
-rw-r--r--src/call.h5
-rw-r--r--src/mncc.c22
4 files changed, 18 insertions, 19 deletions
diff --git a/src/app.c b/src/app.c
index 80bd3af..6ab584d 100644
--- a/src/app.c
+++ b/src/app.c
@@ -43,8 +43,8 @@ void app_mncc_disconnected(struct mncc_connection *conn)
*/
LOGP(DAPP, LOGL_NOTICE,
"Going to release call(%u) due MNCC.\n", call->id);
- call_leg_release(call, call->initial);
- call_leg_release(call, call->remote);
+ call_leg_release(call->initial);
+ call_leg_release(call->remote);
}
}
diff --git a/src/call.c b/src/call.c
index ce339c0..c6d10ea 100644
--- a/src/call.c
+++ b/src/call.c
@@ -31,8 +31,11 @@ static uint32_t last_call_id = 5000;
void calls_init(void)
{}
-void call_leg_release(struct call *call, struct call_leg *leg)
+void call_leg_release(struct call_leg *leg)
{
+ struct call *call = leg->call;
+
+
if (leg == call->initial)
call->initial = NULL;
else if (leg == call->remote)
@@ -70,6 +73,7 @@ struct call *sip_call_mncc_create(void)
}
call->initial->type = CALL_TYPE_MNCC;
+ call->initial->call = call;
llist_add(&call->entry, &g_call_list);
return call;
}
diff --git a/src/call.h b/src/call.h
index c8e9f0b..a7d3385 100644
--- a/src/call.h
+++ b/src/call.h
@@ -30,12 +30,13 @@ enum {
struct call_leg {
int type;
+ struct call *call;
/**
* Set by the call_leg implementation and will be called
* by the application to release the call.
*/
- void (*release_call)(struct call *, struct call_leg *);
+ void (*release_call)(struct call_leg *);
};
struct sip_call_leg {
@@ -63,7 +64,7 @@ extern struct llist_head g_call_list;
void calls_init(void);
-void call_leg_release(struct call *call, struct call_leg *leg);
+void call_leg_release(struct call_leg *leg);
struct call *sip_call_mncc_create(void);
diff --git a/src/mncc.c b/src/mncc.c
index 9b48f5c..ef207a9 100644
--- a/src/mncc.c
+++ b/src/mncc.c
@@ -36,28 +36,23 @@
static void close_connection(struct mncc_connection *conn);
-static struct mncc_call_leg *mncc_find_leg(uint32_t callref, struct call **out_call)
+static struct mncc_call_leg *mncc_find_leg(uint32_t callref)
{
struct call *call;
llist_for_each_entry(call, &g_call_list, entry) {
if (call->initial && call->initial->type == CALL_TYPE_MNCC) {
struct mncc_call_leg *leg = (struct mncc_call_leg *) call->initial;
- if (leg->callref == callref) {
- *out_call = call;
+ if (leg->callref == callref)
return leg;
- }
}
if (call->remote && call->remote->type == CALL_TYPE_MNCC) {
struct mncc_call_leg *leg = (struct mncc_call_leg *) call->remote;
- if (leg->callref == callref) {
- *out_call = call;
+ if (leg->callref == callref)
return leg;
- }
}
}
- *out_call = NULL;
return NULL;
}
@@ -96,7 +91,7 @@ static void mncc_rtp_send(struct mncc_connection *conn, uint32_t msg_type, uint3
}
-static void mncc_call_leg_release(struct call *call, struct call_leg *_leg)
+static void mncc_call_leg_release(struct call_leg *_leg)
{
struct mncc_call_leg *leg;
@@ -105,12 +100,12 @@ static void mncc_call_leg_release(struct call *call, struct call_leg *_leg)
/* drop it directly, if not connected */
if (leg->conn->state != MNCC_READY)
- return call_leg_release(call, _leg);
+ return call_leg_release(_leg);
switch (leg->state) {
case MNCC_CC_INITIAL:
mncc_send(leg->conn, MNCC_REJ_REQ, leg->callref);
- call_leg_release(call, _leg);
+ call_leg_release(_leg);
break;
}
}
@@ -128,7 +123,6 @@ static void close_connection(struct mncc_connection *conn)
static void check_rtp_create(struct mncc_connection *conn, char *buf, int rc)
{
struct gsm_mncc_rtp *rtp;
- struct call *call;
struct mncc_call_leg *leg;
if (rc < sizeof(*rtp)) {
@@ -138,7 +132,7 @@ static void check_rtp_create(struct mncc_connection *conn, char *buf, int rc)
}
rtp = (struct gsm_mncc_rtp *) buf;
- leg = mncc_find_leg(rtp->callref, &call);
+ leg = mncc_find_leg(rtp->callref);
if (!leg) {
LOGP(DMNCC, LOGL_ERROR, "call(%u) can not be found\n", rtp->callref);
return mncc_send(conn, MNCC_REJ_REQ, rtp->callref);
@@ -146,7 +140,7 @@ static void check_rtp_create(struct mncc_connection *conn, char *buf, int rc)
/* TODO.. now we can continue with the call */
mncc_send(leg->conn, MNCC_REJ_REQ, leg->callref);
- call_leg_release(call, &leg->base);
+ call_leg_release(&leg->base);
}
static void check_setup(struct mncc_connection *conn, char *buf, int rc)