adding mg stack add command code and sendign dummy rsp of add

This commit is contained in:
kapil 2012-06-26 13:05:23 +05:30
parent b6737e31a3
commit e777de3eef
1 changed files with 180 additions and 0 deletions

View File

@ -19,6 +19,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_media_gateway_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_media_gateway_shutdown);
SWITCH_MODULE_DEFINITION(mod_media_gateway, mod_media_gateway_load, mod_media_gateway_shutdown, NULL);
switch_status_t handle_mg_add_cmd(MgMgcoAmmReq *addReq);
switch_status_t mg_stack_free_mem(MgMgcoMsg* msg);
switch_status_t mg_stack_free_mem(MgMgcoMsg* msg);
switch_status_t mg_stack_alloc_mem( Ptr* _memPtr, Size _memSize );
switch_status_t mg_send_add_rsp(SuId suId, MgMgcoCommand *req);
S16 mg_fill_mgco_termid ( MgMgcoTermId *termId, CONSTANT U8 *str, CmMemListCp *memCp);
/**************************************************************************************************************/
@ -434,6 +439,7 @@ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd)
case MGT_ADD:
{
handle_mg_add_cmd(&cmd->u.mgCmdInd[0]->cmd.u.add);
mg_send_add_rsp(suId, cmd);
break;
}
@ -493,6 +499,9 @@ void handle_mgco_txn_sta_ind(Pst *pst, SuId suId, MgMgcoInd* txn_sta_ind)
{
/*TODO*/
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s\n", __PRETTY_FUNCTION__);
/*dump information*/
/*mgAccEvntPrntMgMgcoInd(txn_sta_ind, stdout);*/
}
/*****************************************************************************************************************************/
@ -719,9 +728,180 @@ switch_status_t handle_mg_add_cmd(MgMgcoAmmReq *addReq)
}
}
return SWITCH_STATUS_SUCCESS;
}
/*****************************************************************************************************************************/
switch_status_t mg_send_add_rsp(SuId suId, MgMgcoCommand *req)
{
MgMgcoCommand cmd;
int ret = 0x00;
MgMgcoTermId *termId;
memset(&cmd,0, sizeof(cmd));
/*copy transaction-id*/
memcpy(&cmd.transId, &req->transId,sizeof(MgMgcoTransId));
/*copy context-id*/ /*TODO - in case of $ context should be generated by app, we should not simply copy incoming structure */
memcpy(&cmd.contextId, &req->contextId,sizeof(MgMgcoContextId));
/*copy peer identifier */
memcpy(&cmd.peerId, &req->peerId,sizeof(TknU32));
/*fill response structue */
if(SWITCH_STATUS_FALSE == (ret = mg_stack_alloc_mem((Ptr*)&cmd.u.mgCmdRsp[0],sizeof(MgMgcoCmdReply)))){
return ret;
}
cmd.u.mgCmdRsp[0]->pres.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->type.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->type.val = MGT_ADD;
cmd.u.mgCmdRsp[0]->u.add.pres.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->u.add.termIdLst.num.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->u.add.termIdLst.num.val = 1;
mgUtlAllocMgMgcoTermIdLst(&cmd.u.mgCmdRsp[0]->u.add.termIdLst, &req->u.mgCmdReq[0]->cmd.u.add.termIdLst);
#ifdef GCP_VER_2_1
termId = cmd.u.mgCmdRsp[0]->u.add.termIdLst.terms[0];
#else
termId = &(cmd.u.mgCmdRsp[0]->u.add.termId);
#endif
mg_fill_mgco_termid(termId, (CONSTANT U8*)"term1",&req->u.mgCmdRsp[0]->memCp);
/* We will always send one command at a time..*/
cmd.cmdStatus.pres = PRSNT_NODEF;
cmd.cmdStatus.val = CH_CMD_STATUS_END_OF_CMD;
cmd.cmdType.pres = PRSNT_NODEF;
cmd.cmdType.val = CH_CMD_TYPE_RSP;
ret = sng_mgco_send_cmd(suId, &cmd);
return ret;
}
/*****************************************************************************************************************************/
switch_status_t mg_stack_alloc_mem( Ptr* _memPtr, Size _memSize )
{
Mem sMem;
sMem.region = 0;
sMem.pool = 0;
if ( _memSize <= 0 )
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " Failed mg_stack_alloc_mem: invalid size\n");
return SWITCH_STATUS_FALSE;
}
if ( ROK != cmAllocEvnt( _memSize, MG_MAXBLKSIZE, &sMem, _memPtr ) )
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " Failed mg_stack_alloc_mem: cmAllocEvnt return failure for _memSize=%d\n",_memSize);
return SWITCH_STATUS_FALSE;
}
// Note: memset done inside stack api
return SWITCH_STATUS_SUCCESS;
}
switch_status_t mg_stack_get_mem(MgMgcoMsg* msg, Ptr* _memPtr, Size _memSize )
{
if ( _memSize <= 0 )
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " Failed mg_stack_get_mem: invalid size\n");
return SWITCH_STATUS_FALSE;
}
if ( !msg )
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " Failed mg_stack_get_mem: invalid message\n");
return SWITCH_STATUS_FALSE;
}
if ( cmGetMem( (Ptr)msg, _memSize, (Ptr*)_memPtr ) != ROK )
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " Failed alloc_mg_stack_mem: get memory failed _memSize=%d\n", _memSize );
return SWITCH_STATUS_FALSE;
}
// Note: memset done inside stack api
return SWITCH_STATUS_SUCCESS;
}
switch_status_t mg_stack_free_mem(MgMgcoMsg* msg)
{
if ( !msg )
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " Failed mg_stack_get_mem: invalid message\n");
return SWITCH_STATUS_FALSE;
}
cmFreeMem( (Ptr)msg );
return SWITCH_STATUS_SUCCESS;
}
#define MG_ACC_GETMEM(_ptr,_len,_memCp,_ret) \
{ \
ret = cmGetMem((_memCp), (_len), (Ptr *)&(_ptr)); \
if( ret == ROK) \
cmMemset((U8 *)(_ptr), (U8)0, (PTR)(_len)); \
}
S16 mg_fill_mgco_termid ( MgMgcoTermId *termId, CONSTANT U8 *str, CmMemListCp *memCp)
{
#ifdef GCP_ASN
Size size;
#endif
S16 ret = ROK;
termId->name.pres.pres = PRSNT_NODEF;
/* mg011.105: Bug fixes */
termId->name.lcl.pres = PRSNT_NODEF;
termId->name.lcl.len = cmStrlen((CONSTANT U8*)str);
MG_ACC_GETMEM((termId->name.lcl.val), termId->name.lcl.len, memCp, ret);
if( ret != ROK)
RETVALUE(ret);
cmMemcpy((U8*)(termId->name.lcl.val), (CONSTANT U8*)str,termId->name.lcl.len);
#ifdef GCP_ASN
/* Remove comment to fill other term ID
termId->wildcard.num.pres = NOTPRSNT; */
/* Remove comment to fill wilcard term ID */
termId->wildcard.num.pres = PRSNT_NODEF;
termId->wildcard.num.val = 1;
size = ((sizeof(MgMgcoWildcardField*)));
MG_ACC_GETMEM((termId->wildcard.wildcard),size,memCp, ret);
if( ret != ROK)
RETVALUE(ret);
MG_ACC_GETMEM( ((termId->wildcard.wildcard)[0]),sizeof(MgMgcoWildcardField),
memCp, ret);
if( ret != ROK)
RETVALUE(ret);
termId->wildcard.wildcard[0]->pres = PRSNT_NODEF;
termId->wildcard.wildcard[0]->len = 1;
termId->wildcard.wildcard[0]->val[0] = 0x55;
#endif /* GCP_ASN */
RETVALUE(ROK);
}
/*****************************************************************************************************************************/
/* For Emacs: