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.
This commit is contained in:
parent
29b556490f
commit
c4d01f9a90
|
@ -43,8 +43,8 @@ void app_mncc_disconnected(struct mncc_connection *conn)
|
||||||
*/
|
*/
|
||||||
LOGP(DAPP, LOGL_NOTICE,
|
LOGP(DAPP, LOGL_NOTICE,
|
||||||
"Going to release call(%u) due MNCC.\n", call->id);
|
"Going to release call(%u) due MNCC.\n", call->id);
|
||||||
call_leg_release(call, call->initial);
|
call_leg_release(call->initial);
|
||||||
call_leg_release(call, call->remote);
|
call_leg_release(call->remote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,11 @@ static uint32_t last_call_id = 5000;
|
||||||
void calls_init(void)
|
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)
|
if (leg == call->initial)
|
||||||
call->initial = NULL;
|
call->initial = NULL;
|
||||||
else if (leg == call->remote)
|
else if (leg == call->remote)
|
||||||
|
@ -70,6 +73,7 @@ struct call *sip_call_mncc_create(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
call->initial->type = CALL_TYPE_MNCC;
|
call->initial->type = CALL_TYPE_MNCC;
|
||||||
|
call->initial->call = call;
|
||||||
llist_add(&call->entry, &g_call_list);
|
llist_add(&call->entry, &g_call_list);
|
||||||
return call;
|
return call;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,13 @@ enum {
|
||||||
|
|
||||||
struct call_leg {
|
struct call_leg {
|
||||||
int type;
|
int type;
|
||||||
|
struct call *call;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set by the call_leg implementation and will be called
|
* Set by the call_leg implementation and will be called
|
||||||
* by the application to release the call.
|
* 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 {
|
struct sip_call_leg {
|
||||||
|
@ -63,7 +64,7 @@ extern struct llist_head g_call_list;
|
||||||
void calls_init(void);
|
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);
|
struct call *sip_call_mncc_create(void);
|
||||||
|
|
22
src/mncc.c
22
src/mncc.c
|
@ -36,28 +36,23 @@
|
||||||
static void close_connection(struct mncc_connection *conn);
|
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;
|
struct call *call;
|
||||||
|
|
||||||
llist_for_each_entry(call, &g_call_list, entry) {
|
llist_for_each_entry(call, &g_call_list, entry) {
|
||||||
if (call->initial && call->initial->type == CALL_TYPE_MNCC) {
|
if (call->initial && call->initial->type == CALL_TYPE_MNCC) {
|
||||||
struct mncc_call_leg *leg = (struct mncc_call_leg *) call->initial;
|
struct mncc_call_leg *leg = (struct mncc_call_leg *) call->initial;
|
||||||
if (leg->callref == callref) {
|
if (leg->callref == callref)
|
||||||
*out_call = call;
|
|
||||||
return leg;
|
return leg;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (call->remote && call->remote->type == CALL_TYPE_MNCC) {
|
if (call->remote && call->remote->type == CALL_TYPE_MNCC) {
|
||||||
struct mncc_call_leg *leg = (struct mncc_call_leg *) call->remote;
|
struct mncc_call_leg *leg = (struct mncc_call_leg *) call->remote;
|
||||||
if (leg->callref == callref) {
|
if (leg->callref == callref)
|
||||||
*out_call = call;
|
|
||||||
return leg;
|
return leg;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*out_call = NULL;
|
|
||||||
return 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;
|
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 */
|
/* drop it directly, if not connected */
|
||||||
if (leg->conn->state != MNCC_READY)
|
if (leg->conn->state != MNCC_READY)
|
||||||
return call_leg_release(call, _leg);
|
return call_leg_release(_leg);
|
||||||
|
|
||||||
switch (leg->state) {
|
switch (leg->state) {
|
||||||
case MNCC_CC_INITIAL:
|
case MNCC_CC_INITIAL:
|
||||||
mncc_send(leg->conn, MNCC_REJ_REQ, leg->callref);
|
mncc_send(leg->conn, MNCC_REJ_REQ, leg->callref);
|
||||||
call_leg_release(call, _leg);
|
call_leg_release(_leg);
|
||||||
break;
|
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)
|
static void check_rtp_create(struct mncc_connection *conn, char *buf, int rc)
|
||||||
{
|
{
|
||||||
struct gsm_mncc_rtp *rtp;
|
struct gsm_mncc_rtp *rtp;
|
||||||
struct call *call;
|
|
||||||
struct mncc_call_leg *leg;
|
struct mncc_call_leg *leg;
|
||||||
|
|
||||||
if (rc < sizeof(*rtp)) {
|
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;
|
rtp = (struct gsm_mncc_rtp *) buf;
|
||||||
leg = mncc_find_leg(rtp->callref, &call);
|
leg = mncc_find_leg(rtp->callref);
|
||||||
if (!leg) {
|
if (!leg) {
|
||||||
LOGP(DMNCC, LOGL_ERROR, "call(%u) can not be found\n", rtp->callref);
|
LOGP(DMNCC, LOGL_ERROR, "call(%u) can not be found\n", rtp->callref);
|
||||||
return mncc_send(conn, MNCC_REJ_REQ, 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 */
|
/* TODO.. now we can continue with the call */
|
||||||
mncc_send(leg->conn, MNCC_REJ_REQ, leg->callref);
|
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)
|
static void check_setup(struct mncc_connection *conn, char *buf, int rc)
|
||||||
|
|
Loading…
Reference in New Issue