2G ems initial

This commit is contained in:
2024-03-13 09:30:40 +08:00
commit eed6460ad2
1234 changed files with 419571 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
ClearCase CopyAreaDB|4
vobs\r9\plat\mgc_v2
2
5
3:doc|2|0|0|0|8290c245a0da11dd9cdb001c23e19543|0
2:ut|2|0|0|0|9a60c5fda0d911dd9cdb001c23e19543|0
3:src|2|0|0|0|a76f9fe5aa3711dd84a8001c23e19543|0
8:Makefile|1|11d70a499b3|b2f|913dc01d|5a6593f5a19211dd8868001c23e19543|0
3:lib|2|0|0|0|8320c261a0da11dd9cdb001c23e19543|0

98
omc/plat/mgc_v2/Makefile Normal file
View File

@@ -0,0 +1,98 @@
##----------------------------------------------------------##
## ##
## Universal Makefile for module template : V1.6.3 ##
## ##
## Created : Wei Liu 07/04/11 ##
## Revision: [Last]Wei Liu 07/07/07 ##
## ##
##----------------------------------------------------------##
##---------------------------------------------------------------------##
##--------------------------------------
##
## Project correlation(Customer define)
##
##--------------------------------------
## MODULE= [Module Name]
## TYPE = app/plat => Module Type
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Debug ]
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Release]
## BUILD = lib/exef => Output file format
## CFG = debug/release => Build Configuration
## SRC_PATH = [Source file path]
## INC_PATH = [Include file path]
## APP_PATH = [App Module path]
## PLT_PATH = [Plat Module path]
## PLT_LIB = [Needed plat lib for Link] => just for test or wxc2main
## APP_LIB = [Needed app lib for Link] => just for test or wxc2main
## LIB_ADD = [Needed Extend lib for Link] => just for test or wxc2main
## PLT_LIB e.g. = haepub fsm mng proto kernel aif mgc mgcp sip rtp \
## 8ecp bicc smpp xapp tcap mtp3 m2ua \
## snmp iptrans debug sccp public
##
## APP_LIB e.g. = msc vlr ssf hlr ae pps mnp smsc vms aas
## LIB_ADD e.g. = -liba3a8 -lm
## OBJ_ADD = [Extend third party object files needed]
## TEST_OBJ_PATH = [module object files Path for test ] => just for test
##---------------------------------------------------------------------##
MODULE = mgc_v2
TYPE = plat
DBUG_FLAGS_ADD =
RELS_FLAGS_ADD =
##Default commonly as below
BUILD = lib
CFG = debug
PLT_LIB =
APP_LIB =
LIB_ADD =
SRC_PATH = ./src
INC_PATH = ./src/include
PLT_PATH = ../../plat
APP_PATH = ../../app
OBJ_ADD =
TEST_OBJ_PATH =
PREPROC_CMD =
POSTPROC_CMD =
##---------------------------------------------------------------------##
##--------------------------------------
##
## Make configuration(Customer define)
##
##--------------------------------------
## CCFLAG_SWITCH = on/off => gcc flag show on/off
## COVER_NEED = yes/no => PTF cover report needed
## COVER_REPORT_PATH = [path ] => PTF cover report path
CCFLAG_SWITCH = off
COVER_NEED = no
COVER_REPORT_PATH = ./output
##---------------------------------------------------------------------##
##--------------------------------------
##
## include makefile.rules (Do not change)
##
##--------------------------------------
include Makefile.rules

Binary file not shown.

BIN
omc/plat/mgc_v2/obj/mgc.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,19 @@
ClearCase CopyAreaDB|4
vobs\r9\plat\mgc_v2\src
2
f
5:mgc.c|1|11d8a87d5f1|1680b|b37fa4ff|ed30309baf1211dd889f001c23e19543|0
e:mgc_phy_port.c|1|11d758d245c|39c5|19d92b91|4bef2902ac8911dd898a001c23e19543|0
9:mgc_ctl.c|1|11d70a49a6e|c42|38290aaa|8450c2b5a0da11dd9cdb001c23e19543|0
7:include|2|0|0|0|a8af9fefaa3711dd84a9001c23e19543|0
b:mgc_debug.c|1|11d8a87d573|4224|9c39cdf9|ec903096af1211dd889f001c23e19543|0
f:mgc_conn_info.c|1|11d9047aeff|d723|d2d41af|729a9c52b0a011dd8699001c23e19543|0
a:mgc_8ecp.c|1|11d70a49cfe|1f39|7f156c80|99d0c5e1a0d911dd9cdb001c23e19543|0
f:mgc_port_info.c|1|11d9047ae72|c952|49635542|720a9c51b0a011dd8699001c23e19543|0
a:mgc_mgcp.c|1|11d70a49ba6|aa41|2b916ec6|faeffffeaa4511dd84f5001c23e19543|0
e:mgc_internal.c|1|11d70a49c81|28df|b3280c26|8a769633a67d11dd9624001c23e19543|0
e:mgc_sur_info.c|1|11d70a49aad|2fe8|6b6c0368|ab0f9ff9aa3711dd84ab001c23e19543|0
f:mgc_chnl_info.c|1|11d70a49be5|4a2b|defdbfdd|e783fb8baade11dd8649001c23e19543|0
d:mgc_mg_info.c|1|11d758d2548|61ff|2112d650|4dbf290eac8911dd898b001c23e19543|0
11:mgc_tandem_info.c|1|11d9047af6c|9e18|e7265e11|1d0a0d28b08b11dd8640001c23e19543|0
f:mgc_port_list.c|1|11d70a49d3c|177f|7247bcbd|b22fa028aa3711dd84b1001c23e19543|0

View File

@@ -0,0 +1,21 @@
ClearCase CopyAreaDB|4
vobs\r9\plat\mgc_v2\src\include
2
11
f:mgc_port_list.h|1|11d70a4a143|12c|af836631|b19fa025aa3711dd84b0001c23e19543|0
d:mgc_mg_info.h|1|11d70a4a0c6|5b4|4897f55e|fe700014aa4611dd84f8001c23e19543|0
5:mgc.h|1|11d70a49de8|303d|1aeae8c3|fcb0000daa4611dd84f6001c23e19543|0
b:mgc_debug.h|1|11d758d25c5|7ef|9d383e4c|4c8f2904ac8911dd898b001c23e19543|0
e:mgc_phy_port.h|1|11d70a49e17|39e|c68240ab|57a5023ba64111dd959c001c23e19543|0
c:mgc_struct.h|1|11d9047afca|10d1|c79d204d|733a9c57b0a011dd8699001c23e19543|0
f:mgc_port_info.h|1|11d758d2633|809|3d02b243|4d1f2909ac8911dd898b001c23e19543|0
e:mgc_sur_info.h|1|11d70a49f8e|312|630c0801|af2fa013aa3711dd84ad001c23e19543|0
f:mgc_chnl_info.h|1|11d70a4a114|50e|4aa3b7f4|e953fb97aade11dd864a001c23e19543|0
e:mgc_internal.h|1|11d70a49ef2|24d|ecaab846|9040c491a0da11dd9cdb001c23e19543|0
a:mgc_8ecp.h|1|11d70a4a059|26b|d354ca86|95a0c555a0d911dd9cdb001c23e19543|0
9:mgc_pub.h|1|11d70a49e56|94|80012e65|8e70c43da0da11dd9cdb001c23e19543|0
a:mgc_mgcp.h|1|11d70a49fcc|89f|13d2e268|e823fb8daade11dd864a001c23e19543|0
11:mgc_tandem_info.h|1|11d70a49eb3|7f6|6239f17|8fa0c475a0da11dd9cdb001c23e19543|0
f:mgc_conn_info.h|1|11d70a4a01b|f77|dac22645|e8b3fb92aade11dd864a001c23e19543|0
a:mgc_snmp.h|1|11d70a49f5f|11f|912c48d5|9210c4c9a0da11dd9cdb001c23e19543|0
9:mgc_ctl.h|1|11d70a49ffb|19a|f731901d|9470c51da0d911dd9cdb001c23e19543|0

View File

@@ -0,0 +1,449 @@
#ifndef _MGC_H
#define _MGC_H
#define MGC_MAX_NUM_OF_SAP 5
#define MGC_MAX_USER_NAME_LEN 32
#define MGC_MAX_DOMAIN_LEN 64
#define MGC_MAX_PHY_PORT_PER_MG 32
#define MGC_MAX_CHNL_NUM_PER_PHY 1024
#define MGC_MAX_NUM_OF_CHNL_CON 512
#define MGC_MAX_NUM_OF_CON 8192
#define MGC_MAX_OPER_STEPS_NUM 15
#define MGC_MAX_NUM_OF_MG 1024
#define MGC_MAX_NUM_OF_PHY_PORT 1024
#define MGC_MAX_NUM_OF_CHNL 9424
#define MGC_MAX_NUM_OF_PORT 8192
#define MGC_MAX_NUM_OF_SESS 1024
#define MGC_MAX_NUM_OF_RTP_PROXY_SESS 4096
#define MGC_MGCF_TIMER_50MS 5
#define MGC_MGCF_TIMER_20MS 2
#define MGC_MGCF_TIMER_1S 100
#define MGC_MGCF_TIMER_10S 10 * MGC_MGCF_TIMER_1S
#define MGC_MGCF_TIMER_20S 20 * MGC_MGCF_TIMER_1S
#define MGC_MGCF_TIMER_1H 3600 * MGC_MGCF_TIMER_1S
#define MGC_CHNL_NUM_INTERNAL_PER_PORT 1024
#define MGC_CHNL_NUM_AALN_PER_PORT 1
#define MGC_CHNL_NUM_ANN_PER_TYPE 200
#define MGC_CHNL_NUM_DS_PER_PORT 32
#define MGC_CHNL_NUM_TANDEM_PER_TYPE 1024
#define MGC_CHNL_NUM_SERVEILLANCE_PER_TYPE 1024
#define MGC_HOLD_MUSIC 7
#define MGC_TONE_RING 8
#define MGC_TONE_BUSY 9
#define MGC_TONE_WARN 10
#define MGC_MGCP_MGC_PORT 2727
#define MGC_MGCP_MG_PORT 2427
#define MGC_MG_NETWORK_PORT 4967
#define MGC_MGC_NETWORK_PORT 4966
#define MGC_OPERA_NO_DELAY 0
#define MGC_CONNECT_SILENT_TONE 0x01
#define MGC_MAX_NUM_OF_TANDEM 4096
#define MGC_MAX_NUM_OF_RTP_PROXY_NUM 2
#define MGC_MAX_NUM_OF_TANDEM_CONN (MGC_MAX_NUM_OF_TANDEM*2)
#define MGC_MAX_NUM_OF_TANDEM_CHNL (MGC_MAX_NUM_OF_TANDEM)
#define MGC_TANDEM_CONN_STAR_ID (MGC_MAX_NUM_OF_CON)
#define MGC_TANDEM_CHNL_STAR_ID (MGC_MAX_NUM_OF_CHNL)
#define MGC_TANDEM_PHY_PORT_STAR_ID (MGC_MAX_NUM_OF_PHY_PORT)
#define MGC_MAX_NUM_OF_SURVEILLANCE_NUM 2
#define MGC_MAX_NUM_OF_SURVEILLANCE_CONN 1024
#define MGC_MAX_NUM_OF_SURVEILLANCE_NODE (MGC_MAX_NUM_OF_SURVEILLANCE_CONN)
#define MGC_MAX_NUM_OF_SURVEILLIANCE_CHNL (MGC_MAX_NUM_OF_SURVEILLANCE_CONN)
#define MGC_SURVEILLIANCE_CONN_STAR_ID (MGC_TANDEM_CONN_STAR_ID+MGC_MAX_NUM_OF_TANDEM_CONN)
#define MGC_SURVEILLIANCE_CHNL_STAR_ID (MGC_TANDEM_CHNL_STAR_ID+MGC_MAX_NUM_OF_TANDEM_CHNL)
#define MGC_SURVEILLIANCE_PHY_PORT_STAR_ID (MGC_TANDEM_PHY_PORT_STAR_ID+ MGC_MAX_NUM_OF_RTP_PROXY_NUM)
#include "../../../public/src/include/includes.h"
#include "../../../public/src/include/public.h"
#include "../../../public/src/include/license_id.h"
#include "../../../public/src/include/pub_sdp.h"
//#include "../../../mgcp/src/include/mgcp.h"
typedef enum
{
MGC_RESULT_LACK_PARA = -4,
MGC_RESULT_NO_RES = -3 ,
MGC_RESULT_INPUT_ILLEGAL = -2,
MGC_RESULT_FAILURE = -1,
MGC_RESULT_OK = 0,
MGC_RESULT_8ECP_OK = 1
}MGC_RESULT;
typedef enum{
MGC_DTMF_1 = 1,
MGC_DTMF_2 = 2,
MGC_DTMF_3 = 3,
MGC_DTMF_4 = 4,
MGC_DTMF_5 = 5,
MGC_DTMF_6 = 6,
MGC_DTMF_7 = 7,
MGC_DTMF_8 = 8,
MGC_DTMF_9 = 9,
MGC_DTMF_0 = 10,
MGC_DTMF_START = 11,
MGC_DTMF_POUND = 12
}MGC_DTMF_DEF;
typedef enum{
MGC_PKG_L = 0,
MGC_PKG_D = 1,
MGC_PKG_G = 2
}MGC_PKG_TYPE;
typedef enum
{
MGC_USER_TYPE_UNDEF = -1,
MGC_USER_TYPE_MGC = 0,
MGC_USER_TYPE_MG = 1
}MGC_USER_TYPE;
typedef enum
{
MGC_CONNECT_STATUS_UNDEF = -1,
MGC_CONNECT_STATUS_IDLE ,
MGC_CONNECT_STATUS_CREATING ,
MGC_CONNECT_STATUS_CREATE,
MGC_CONNECT_STATUS_CREATED
}MGC_CONNECT_STATUS;
typedef enum
{
MGC_CON_MODE_UNDEF = -1,
MGC_CON_MODE_INACTIVE ,
MGC_CON_MODE_RECVONLY ,
MGC_CON_MODE_SENDONLY ,
MGC_CON_MODE_SENDRECV ,
MGC_CON_MODE_OWN
}MGC_CON_MODE;
typedef enum
{
MGC_CHNL_INFO_STATUS_UNDEF = -1,
MGC_CHNL_INFO_STATUS_IDLE,
MGC_CHNL_INFO_STATUS_USED
}MGC_CHNL_INFO_STATUS;
typedef enum
{
MGC_PHY_PORT_STATUS_UNDEF = -1,
MGC_PHY_PORT_STATUS_OFF_LINE,
MGC_PHY_PORT_STATUS_ON_LINE
}MGC_PHY_PORT_STATUS;
typedef enum
{
MGC_PHY_PORT_TYPE_UNDEF = -1,
MGC_PHY_PORT_TYPE_E1 = 1 ,
MGC_PHY_PORT_TYPE_T1 = 2 ,
MGC_PHY_PORT_TYPE_ANALOG ,
MGC_PHY_VIRTUAL_TYPE_ANN,
MGC_PHY_VIRTUAL_TYPE_INTERNAL,
MGC_PHY_VIRTUAL_TYPE_TANDEM,
MGC_PHY_VIRTUAL_TYPE_SURVEILLANCE
}MGC_PHY_PORT_TYPE;
typedef enum
{
MGC_MG_CTRL_TYPE_UNDEF = -1,
MGC_MG_CTRL_TYPE_MGCP,
MGC_MG_CTRL_TYPE_8ECP
}MGC_MG_CTRL_TYPE;
typedef enum
{
MGC_MG_TYPE_UNDEF = -1,
MGC_MG_TYPE_INTERNAL = 0 ,
MGC_MG_TYPE_AudioCoder = 1 ,
MGC_MG_TYPE_LGC_MG = 2,
MGC_MG_TYPE_SSW_CSS = 3 ,
MGC_MG_TYPE_IPBSS =4 ,
MGC_MG_TYPE_ANALOG = 11 ,
MGC_MG_TYPE_TANDEM = 20,
MGC_MG_TYPE_ANN =21
}MGC_MG_TYPE;
typedef enum
{
MGC_OPER_ID_UNDEF =-1,
MGC_OPER_ID_CONNECT_CHNL = 1,
MGC_OPER_ID_CONNECT_DTMF = 2,
MGC_OPER_ID_CONNECT_TONE =3,
MGC_OPER_ID_CRCX = 4,
MGC_OPER_ID_MDCX = 5,
MGC_OPER_ID_DLCX = 6,
MGC_OPER_ID_RQNT = 7,
MGC_OPER_ID_AUEP = 8,
MGC_OPER_ID_CONNECT_AAS = 9,
MGC_OPER_ID_TANDEM_CREATE,
MGC_OPER_ID_TANDEM_SET_TAR,
MGC_OPER_ID_TANDEM_UNSET_TAR,
MGC_OPER_ID_TANDEM_CLEAR,
MGC_OPER_ID_TANDEM_FORK_CHNL,
MGC_OPER_ID_CREATE_VIRTUAL_CHNL,
MGC_OPER_ID_RELEASE_VIRTUAL_CHNL,
MGC_OPER_ID_UPDATE_CHNL_MEDIA,
MGC_OPER_ID_IND
}MGC_MG_OPER_ID_TYPE;
typedef enum
{
MGC_CMD_UNDEF = -1,
MGC_CMD_CRCX = 1,
MGC_CMD_MDCX ,
MGC_CMD_DLCX ,
MGC_CMD_RQNT ,
MGC_CMD_NTFY ,
MGC_CMD_AUEP ,
MGC_CMD_RSIP ,
MGC_CMD_NOP //do noting
}MGC_CMD_TYPE;
typedef enum
{
MGCP_OPER_STEP_UNDEF =-1,
MGCP_OPER_STEP_REQUEST,
MGCP_OPER_STEP_REQUEST_SENT,
MGCP_OPER_STEP_RESPONSE_GET,
/***************************************************
* up status is used for MGC , following status is used for MG
*****************************************************/
MGCP_OPER_STEP_IND,
MGCP_OPER_STEP_IND_SENT,
MGCP_OPER_STEP_RESPONSE
}MGCP_OPER_STEP_STATUS;
typedef enum
{
MGC_OPER_FAILURE = 0,
MGC_OPER_SUCCESS = 1
}MGC_OPER_RESULT;
typedef enum
{
MGC_VCTYPE_PCMA = 0 ,
MGC_VCTYPE_PCMU = 1,
MGC_VCTYPE_GSM =2 ,
MGC_VCTYPE_GSM_EFR = 3,
MGC_VCTYPE_AMR_12_2 = 4,
MGC_VCTYPE_G729B = 5,
MGC_VCTYPE_AMR_10_2 = 6,
MGC_VCTYPE_AMR_7_95 = 7,
MGC_VCTYPE_AMR_7_4 = 8,
MGC_VCTYPE_AMR_6_7 = 9,
MGC_VCTYPE_AMR_5_15 = 10,
MGC_VCTYPE_AMR_5_9 = 11,
MGC_VCTYPE_AMR_4_75 = 12,
MGC_VCTYPE_NUM,
MGC_VCTYPE_UNSUPPORT
}MGC_VCTYPE;
typedef enum
{
MGC_TANDEM_STATUS_UNDEF = -1,
MGC_TANDEM_STATUS_IDLE,
MGC_TANDEM_STATUS_USED
}MGC_TANDEM_STATUS;
typedef struct _MGC_ESCCD
{
char domain[MGC_MAX_DOMAIN_LEN];
WORD port;
}MGC_ESCCD;
typedef struct _OPER_REC
{
MGC_MG_OPER_ID_TYPE operaId;
BYTE tone;
WORD duration;
WORD times;
}OPER_REC;
typedef struct _CHNL
{
WORD mgNo; // mg No.
BYTE portNo; // local physical port No. of that mg
WORD chlNo; // local channel No. of that trunk
WORD connectNo;
}CHNL;
typedef struct _MGC_CODEC_LIST
{
BYTE num; // num of codecs
WORD priority; // priority level, used when comparing different codec list
MGC_VCTYPE codec[MGC_VCTYPE_NUM]; // codec ID number, high priority codec first
}MGC_CODEC_LIST;
typedef struct _MG_ATTR
{
BYTE ptime; // ptime, in ms
MGC_MG_TYPE mgType; // non-virtual/ann
MGC_MG_CTRL_TYPE ctrlType; // 8ecp or mgcp
BYTE epDes; // endpoint description method: structured or unstructured
BYTE toneCap; // Tone generation capability
BYTE maxPorts; // maximum physical ports of this MG
WORD maxChnls; // maximum channels of this MG, only applicable to virtual MG.
DWORD ip; // IP address of the MG
char domain[MGC_MAX_DOMAIN_LEN]; // domain name of the mg
BYTE e1cardNo;
DWORD auditTimer;
MGC_CODEC_LIST codecList; // list of codecs that the MG supports
}MG_ATTR;
typedef struct _PKG_EVENT
{
BYTE pkg; // package name
BYTE event; // event name
}PKG_EVENT;
typedef struct _PKG_SIGNAL
{
BYTE pkg; // package name
BYTE signal; // signal name
}PKG_SIGNAL;
typedef struct _PKG_REQ
{
BYTE pkg; // package name
BYTE req; // request name
}PKG_REQ;
#define MGC_MEDIA_PARA_FLAG_EC 0x0001
#define MGC_MEDIA_PARA_FLAG_SS 0x0002
#define MGC_MEDIA_PARA_FLAG_VT 0x0004
#define MGC_MEDIA_PARA_FLAG_CM 0x0008
#define MGC_MEDIA_PARA_FLAG_PT 0x0010
typedef struct _MEDIA_PARA
{
WORD flag; // which media attribute is affected
BYTE ecDisable; // echo canceller disable or enable
BYTE ssDisable; // silence suppression disable or enable;
BYTE conMode; // connect mode
BYTE ptime; // packetization period
MGC_CODEC_LIST vocoderType; // vocoder type
}MEDIA_PARA;
typedef struct _MEDIA_ATTR
{
BYTE ecDisable; // echo canceller disable or enable
BYTE ssDisable; // silence suppression disable or enable
MGC_VCTYPE vocoderType; // vocoder type
MGC_CON_MODE conMode; // connect mode
char callId[33]; // call Id
char conId[33]; // connection id
BYTE ptime; // packetization period
PKG_EVENT pkgEvent; // package + event
PKG_SIGNAL pkgSignal; // package + signal
PKG_REQ pkgReq;
PUB_SDP_MSG sdp; // media info of this channel
}MEDIA_ATTR;
typedef int (*mgc_ind_callback)(CHNL chnl, MGC_CMD_TYPE cmd, WORD *usrPort, WORD mgcPort, MEDIA_ATTR *mediaAttr);
typedef int (*mgc_cnf_callback)(WORD usrPort, WORD mgcPort, MGC_MG_OPER_ID_TYPE operId, MGC_OPER_RESULT success, WORD cause);
typedef struct _MGC_SAP
{
int id; //internal used , should not be modified by up layer
char usrName[MGC_MAX_USER_NAME_LEN]; // user name
MGC_USER_TYPE usrType; // user acts as a mg or mgc
mgc_ind_callback ind_func;
mgc_cnf_callback cnf_func;
}MGC_SAP;
void mgc_init(DWORD systemId, DWORD localIp, DWORD peerIp);
int mgc_bind(MGC_SAP *pSap);
int mgc_unbind(MGC_SAP *pSap, BYTE sapIndex);
void mgc_timer(void);
int mgc_create_MG(BYTE sapIndex, MG_ATTR *pMgAttr);
int mgc_delete_MG(BYTE sapIndex, WORD mgNo);
int mgc_modify_MG(BYTE sapIndex, WORD mgNo, MG_ATTR *pMgAttr);
int mgc_add_port(BYTE sapIndex, WORD mgNo, BYTE portNo, MGC_PHY_PORT_TYPE portType);
int mgc_delete_port(BYTE sapIndex, WORD mgNo, BYTE portNo);
int mgc_crcx_chnl(WORD usrPort, CHNL chnl);
int mgc_mdcx_chnl(WORD usrPort, CHNL chnl, MEDIA_PARA *pMediaPara);
int mgc_dlcx_chnl(WORD usrPort, CHNL chnl);
int mgc_rqnt_chnl(WORD usrPort, CHNL chnl, PKG_EVENT *pPkgEvent, PKG_SIGNAL *pPkgSig);
int mgc_connect_chnl(WORD usrPort, CHNL orgChnl, CHNL destChnl, BYTE flag);
int mgc_connect_dtmf(WORD usrPort, CHNL chnl,CHNL dstChnl, BYTE dtmfNo);
int mgc_recvonly_chnl(WORD usrPort, CHNL orgChnl, CHNL destChnl);
int mgc_connect_AAS(WORD usrPort, CHNL orgChnl, CHNL destChnl, BYTE toneNo, WORD duration, WORD times);
int mgc_connect_tone(WORD usrPort, CHNL orgChnl, CHNL destChnl, BYTE toneNo, WORD duration);
int mgc_query_mg_status(WORD mgNo);
int mgc_query_port_status(WORD mgNo, BYTE portNo);
int mgc_query_channel_status(CHNL chnl);
int mgc_create_virtual_chnl(WORD usrPort, CHNL *pChnl);
int mgc_release_virtual_chnl(WORD usrPort,CHNL chnl);
int mgc_query_chnl_media(WORD usrPort, CHNL chnl, PUB_SDP_MSG **ppMediaInfo, BYTE *pMgPayloads, BYTE *pMgPlNum);
int mgc_update_chnl_media(WORD usrPort, CHNL chnl, PUB_SDP_MSG *pMediaInfo);
int mgc_chnl_codec_update(CHNL chnl , MGC_CODEC_LIST codecList);
OPER_REC *mgc_query_chnl_oper_rec(CHNL chnl);
int mgc_license_ctrl(WORD maxMgNum, WORD maxChnlNum);
int mgc_rsp(BYTE cmd, WORD usrPort, WORD port, WORD retCode, MEDIA_ATTR *pMediaAttr);
int mgc_get_idle_tandem_id(void);
int mgc_bind_chnl_to_tandem(WORD usrPort , CHNL tarChnl , DWORD tandId);
int mgc_create_tandem(WORD usrPort , DWORD tandId);
int mgc_unbind_chnl_from_tandem(WORD usrPort , CHNL tarChnl , DWORD tandId);
int mgc_delete_tandem(WORD usrPort , DWORD tandemId);
int mgc_get_tandem_near_end(DWORD tandem_id, CHNL *pChnl);
int mgc_get_tandem_far_end(DWORD tandem_id, CHNL *pChnl);
int mgc_fork_chnl(WORD usrPort , CHNL parent, CHNL *pChild);
char *mgc_print_failure_reason(int ret);
#endif

View File

@@ -0,0 +1,17 @@
#ifndef _MGC_8ECP_H
#define _MGC_8ECP_H
#include "mgc_struct.h"
#define MGC_8ECP_MAX_TRK_PER_MG 8
int mgc_bind_8ecp_setup(void);
int mgc_8ecp_update_trk_status(BYTE mgNo, BYTE trkNo, BYTE status);
int mgc_8ecp_update_mg_status(BYTE mgNo, BYTE status);
BOOL mgc_8ecp_create(MG_INFO *pMgInfo , MG_ATTR *pMgAttr);
BOOL mgc_8ecp_delete(MG_INFO *pMgInfo);
BOOL mgc_8ecp_dlcx_chnl(CHNL chnl);
BOOL mgc_8ecp_connect_chnl(CHNL orgChnl, CHNL destChnl, BYTE flag);
BOOL mgc_8ecp_connect_dtmf(CHNL orgChnl, CHNL destChnl, BYTE digit);
BOOL mgc_8ecp_connect_tone(CHNL orgChnl, CHNL destChnl, BYTE tone , BYTE duration);
#endif

View File

@@ -0,0 +1,32 @@
#ifndef _MGC_CHNL_INFO_H
#define _MGC_CHNL_INFO_H
#include "mgc_struct.h"
void mgc_chnl_info_setup(void);
void mgc_chnl_info_init(CHNL_INFO *pChnlInfo , int id);
void mgc_chnl_info_clear(CHNL_INFO *pChnlInfo);
void mgc_chnl_info_status_set(CHNL_INFO *pChnlInfo , MGC_CHNL_INFO_STATUS status);
CHNL_INFO *mgc_chnl_info_get_unused_chnl(void);
CHNL_INFO *mgc_chnl_info_get_chnl(CHNL chnl);
BOOL mgc_chnl_info_attach_to_phy_port(CHNL_INFO *pChnlInfo , PHY_PORT_INFO *pPhyPort);
CHNL_INFO *mgc_chnl_info_find_chnl_of_phy(PHY_PORT_INFO *pPhyPort , int chnlNo);
int mgc_chnl_info_get_chnl_no_of_phy(CHNL_INFO *pChnlInfo , PHY_PORT_INFO *pPhyPort);
BOOL mgc_chnl_info_attach_connect(CHNL_INFO *pChnlInfo , CONNECT_INFO *pConnect , int connNo);
BOOL mgc_chnl_info_detach_connect(CHNL_INFO *pChnlInfo , CONNECT_INFO *pConnect);
CONNECT_INFO *mgc_chnl_info_assign_connect(CHNL_INFO *pChnlInfo , int connNo);
CONNECT_INFO *mgc_chnl_info_assign_idle_connect(CHNL_INFO *pChnlInfo);
void mgc_chnl_info_set_mon(int id, BOOL enable);
BYTE *mgc_chnl_info_get_res_addr(void);
char *mgc_chnl_info_print_status(CHNL_INFO *pChnlInfo);
char *mgc_chnl_info_print_remote(CHNL_INFO *pChnlInfo);
char *mgc_chnl_info_print_mode(CHNL_INFO *pChnlInfo);
char *mgc_chnl_info_print_codec(CHNL_INFO *pChnlInfo);
#endif

View File

@@ -0,0 +1,71 @@
#ifndef _MGC_CONNECT_H
#define _MGC_CONNECT_H
#include "mgc_struct.h"
void mgc_connect_setup(void);
void mgc_connect_init(CONNECT_INFO *pConnect , int id);
CONNECT_INFO *mgc_connect_get_unused(void);
void mgc_connect_set_status(CONNECT_INFO *pConnect , MGC_CONNECT_STATUS status);
MGC_CONNECT_STATUS mgc_connect_get_status(CONNECT_INFO *pConnect);
char *mgc_connect_print_statuts(MGC_CONNECT_STATUS status);
void mgc_connect_codec_list_init(MGC_CODEC_LIST *pList);
/*fuplayers and downlayer operation*/
CHNL_INFO *mgc_connect_get_own_chnl_info(CONNECT_INFO *pConnect);
PHY_PORT_INFO *mgc_connect_get_own_phy_port_info(CONNECT_INFO *pConnect);
MGC_SAP *mgc_connect_get_conn_report_sap(CONNECT_INFO *pConnect);
MG_INFO *mgc_connect_get_own_mg_info(CONNECT_INFO *pConnect);
CONNECT_INFO *mgc_connect_find_connect_of_chnl(CHNL_INFO *pChnlInfo , int connNo);
BOOL mgc_connect_attach_connect_to_chnl(CONNECT_INFO *pConnect , CHNL_INFO *pChnlInfo);
int mgc_connect_get_connNo_of_chnl_info(CONNECT_INFO *pConnect , CHNL_INFO *pChnlInfo);
/*attr*/
BOOL mgc_connect_set_conn_mode(CONNECT_INFO *pConnect , MGC_CON_MODE mode);
MGC_CON_MODE mgc_connect_get_conn_mode(CONNECT_INFO *pConnect);
void mgc_connect_attr_init(CONNECT_INFO *pConnect);
BOOL mgc_connect_attr_negotiate(CONNECT_INFO *pConnect);
BOOL mgc_connect_set_dtmf(CONNECT_INFO *pConnect , BYTE dtmfNo);
BOOL mgc_connect_set_tone(CONNECT_INFO *pConnect , BYTE toneNo);
BOOL mgc_connect_clear_tone(CONNECT_INFO *pConnect);
BOOL mgc_connect_set_req(CONNECT_INFO *pConnect , BYTE pkg , BYTE req);
/*operate */
BOOL mgc_connect_attach_step_info(CONNECT_INFO *pConnect , MGCF_OPER_STEP *pOperStep);
BOOL mgc_connect_dettach_step_info(CONNECT_INFO *pConnect);
MGCF_OPER_STEP *mgc_connect_get_step_info(CONNECT_INFO *pConnect);
/*para create*/
BOOL mgc_connect_auep_para_create(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_connect_crcx_para_create(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_connect_mdcx_para_create(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_connect_dlcx_para_create(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_connect_crcx_resp_parse_para(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_connect_mdcx_resp_parse_para(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_connect_rqnt_para_create(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_connect_is_conn_need_update(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
/*para parse*/
CONNECT_INFO *mgc_connect_assign_conn_by_para(MGCP_PARA *pPara);
CONNECT_INFO *mgc_connect_find_conn_by_conid(MGCP_PARA *pPara);
BOOL mgc_connect_crcx_req_parse_para(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_connect_mdcx_req_parse_para(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_connect_req_parse_para(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_connect_add_auep(CONNECT_INFO *pConnect, PORT_INFO *pPortInfo);
BOOL mgc_connect_add_crcx(CONNECT_INFO *pConnect, PORT_INFO *pPortInfo);
BOOL mgc_connect_add_crcx_with_mode(CONNECT_INFO *pConnect, MGC_CON_MODE mode ,PORT_INFO *pPortInfo);
BOOL mgc_connect_add_crcx_aas(CONNECT_INFO *pConnect, CONNECT_INFO *pPeerConnect, PORT_INFO *pPortInfo);
BOOL mgc_connect_add_mdcx_aas(CONNECT_INFO *pConnect, CONNECT_INFO *pPeerConnect,PORT_INFO *pPortInfo);
BOOL mgc_connect_add_dlcx(CONNECT_INFO *pConnect, PORT_INFO *pPortInfo);
BOOL mgc_connect_add_mdcx(CONNECT_INFO *pConnect, CONNECT_INFO *pPeerConnect , MGC_CON_MODE mode, PORT_INFO *pPortInfo);
BOOL mgc_connect_add_nop_with_delay(CONNECT_INFO *pConnect, DWORD delay ,PORT_INFO *pPortInfo);
BOOL mgc_connect_add_nop(CONNECT_INFO *pConnect, PORT_INFO *pPortInfo);
BOOL mgc_connect_add_rqnt(CONNECT_INFO *pConnect, PKG_EVENT *pPkgEvent, PKG_SIGNAL *pPkgSig, PORT_INFO *pPortInfo);
BOOL mgc_connect_add_rqnt_with_delay(CONNECT_INFO *pConnect, WORD delay, PKG_EVENT *pPkgEvent, PKG_SIGNAL *pPkgSig, PORT_INFO *pPortInfo);
CONNECT_INFO *mgc_connect_dup_attr(CONNECT_INFO *pConnect);
#endif

View File

@@ -0,0 +1,16 @@
#ifndef _MGC_CTL_H
#define _MGC_CTL_H
#include "mgc_struct.h"
void mgc_ctl_num_init(WORD sysId , WORD localIp , WORD peerIp);
BOOL mgc_ctl_is_mg_full(void);
void mgc_ctl_mg_add_one(void);
void mgc_ctl_mg_remove_one(void);
BOOL mgc_ctl_is_chnl_full(void);
void mgc_ctl_chnl_add_one(void);
void mgc_ctl_chnl_remove_one(void);
int mgc_ctl_set_mg_max_num(int num);
int mgc_ctl_set_chnl_max_num(int num);
#endif

View File

@@ -0,0 +1,67 @@
#ifndef _MGC_DEBUG_H
#define _MGC_DEBUG_H
#include "mgc_struct.h"
//#define MGC_TEST_DEBUG
#define MGC_MAX_LINE_LENGTH 256
#define MGC_MAX_ASCIIIN_LEN 4096
#define MGC_MAX_ASCIIOUT_LEN (4096*2)
#define MGC_MAX_ASCITMP_LEN 4096
#define MGC_MONITOR_NONE 0x0000
#define MGC_MONITOR_DEBUG 0x0001
#define MGC_MONITOR_ERROR 0x0010
#define MGC_MONITOR_WARN 0x0100
#define MGC_MONITOR_INFO 0x1000
#define MGC_MONITOR_ALL 0xffff
#ifdef MGC_TEST_DEBUG
#define MGC_DEBUG(msg...) printf("\33[37m DEBUG: [%s:%d]",__FILE__ ,__LINE__ );printf(msg);printf("\n \33[37m")
#define MGC_WARN(msg...) printf("\33[33m WARN: [%s:%d]",__FILE__ ,__LINE__ );printf(msg);printf("\n \33[37m")
#define MGC_ERROR(msg...) printf("\33[31m ERROR: [%s:%d]",__FILE__ ,__LINE__ );printf(msg);printf("\n \33[37m")
#define MGC_INFO(msg...) printf("\33[32m INFO: [%s:%d]",__FILE__ ,__LINE__ );printf(msg);printf("\n \33[37m")
#else
void MGC_DEBUG(char *msg,...);
void MGC_WARN(char *msg,...);
void MGC_ERROR(char *msg,...);
void MGC_INFO(char *msg,...);
#endif
/*
#define NONE "\033[m"
#define RED "\033[0;32;31m"
#define LIGHT_RED "\033[1;31m"
#define GREEN "\033[0;32;32m"
#define LIGHT_GREEN "\033[1;32m"
#define BLUE "\033[0;32;34m"
#define LIGHT_BLUE "\033[1;34m"
#define DARY_GRAY "\033[1;30m"
#define CYAN "\033[0;36m"
#define LIGHT_CYAN "\033[1;36m"
#define PURPLE "\033[0;35m"
#define LIGHT_PURPLE "\033[1;35m"
#define BROWN "\033[0;33m"
#define YELLOW "\033[1;33m"
#define LIGHT_GRAY "\033[0;37m"
#define WHITE "\033[1;37m"
*/
BYTE mgcAsciInBuf[MGC_MAX_ASCIIIN_LEN];
BYTE mgcAsciOutBuf[MGC_MAX_ASCIIOUT_LEN];
BYTE mgcAsciTempBuf[MGC_MAX_ASCITMP_LEN];
WORD mgcMonitorFg;
void mgc_mon(void);
int mgc_debug_set(void);
int mgc_asciout_proc(BYTE *out_str);
int mgc_hex_to_ascii(BYTE *from_hex, BYTE from_len, BYTE *to_asc);
int mgc_log_err(char *err_msg);
int mgc_log_procedure(WORD mgNo, WORD portIndex, WORD chnlIndex, char *msg);
#endif

View File

@@ -0,0 +1,32 @@
#ifndef _MGC_INTERNAL_H
#define _MGC_INTERNAL_H
#include "mgc_struct.h"
#define ITL_OPERA_NUM 1024
#define ITL_OPERA_PORT_NO 127
#define ITL_MG_INFO_PORT_NO 37
typedef enum
{
ITL_OPERA_STATE_UNDEF =-1 ,
ITL_OPERA_STATE_IDLE,
ITL_OPERA_STATE_REQUEST ,
ITL_OPERA_STATE_RESPONSE
}ITL_OPERA_STATE;
typedef struct _ITL_OPERA_STRUCT
{
int userPort;
ITL_OPERA_STATE status;
CHNL chnl;
}ITL_OPERA_STRUCT;
BOOL mgc_internal_sap_bind(void);
BOOL mgc_internal_mg_create(void);
BOOL mgc_internal_opera_auep_request(MG_INFO *pMgInfo);
int mgc_internal_get_sap_index(void);
#endif

View File

@@ -0,0 +1,30 @@
#ifndef _MGC_MG_INFO_H
#define _MGC_MG_INFO_H
#include "mgc_struct.h"
void mgc_mg_info_setup(void);
void mgc_mg_info_init(MG_INFO *pMgInfo , int id);
void mgc_mg_info_clear(MG_INFO *pMgInfo);
int mgc_mg_info_attached_phy_port_num(MG_INFO *pMgInfo);
BOOL mgc_mg_info_attach_phy_port(MG_INFO *pMgInfo , PHY_PORT_INFO *pPhyPort, MGC_SAP *pSap);
void mgc_mg_info_dettach_phy_port(MG_INFO *pMgInfo , PHY_PORT_INFO *pPhyPort);
MG_INFO *mgc_mg_info_get_unused_mg(void);
MG_INFO *mgc_mg_info_get_index_mg(int index);
BOOL mgc_mg_info_assign_attr(MG_INFO *pMgInfo , MG_ATTR *pMgAttr);
void mgc_mg_info_update_mg_status(MG_INFO *pMgInfo , BOOL status);
MG_INFO *mgc_mg_info_check_mg_is_exsit(MG_ATTR *pMgAttr);
void mgc_mg_info_state_check(MG_INFO *pMgInfo);
CHNL_INFO *mgc_mg_info_find_idle_chnl_info(MG_INFO *pMgInfo);
BOOL mgc_mg_info_is_port_already_exist(MG_INFO *pMgInfo , int portNo , MGC_SAP *pSap);
MG_INFO *mgc_mg_info_find_available_mg(MGC_MG_TYPE mgType);
CONNECT_INFO *mgc_mg_info_assign_idle_connection(MG_INFO *pMgInfo);
CONNECT_INFO *mgc_mg_info_assign_aas_tone_connection(BYTE toneNo);
PHY_PORT_INFO *mgc_mg_info_find_port_by_name(char *name ,WORD localPort);
PHY_PORT_INFO *mgc_mg_info_find_port_by_name_and_portNo(char *name , BYTE portNo ,WORD localPort);
MG_INFO *mgc_mg_info_find_mg_by_name(char *name);
void mgc_mg_info_set_mon(int id , BOOL enable );
BYTE *mgc_mg_info_get_res_addr(void);
void mgc_mg_info_print_info(MG_INFO *pMgInfo);
#endif

View File

@@ -0,0 +1,41 @@
#ifndef _MGC_MGCP_H
#define _MGC_MGCP_H
#include "mgc_struct.h"
#include "../../../mgcp/src/include/mgcp.h"
int mgc_mgcp_get_sap_index(void);
int mgc_mgcp_match_codec_list(MGC_CODEC_LIST *dest, MGC_CODEC_LIST *aParty, MGC_CODEC_LIST *bParty);
BOOL mgc_mgcp_check_codec_valid(MGC_VCTYPE codec);
int mgc_bind_mgcp_setup(void);
int mgc_mgcp_print_vc_num(MGC_VCTYPE vcCodec);
char *mgc_mgcp_print_vc_codec(MGC_VCTYPE vcCodec);
BYTE mgc_mgcp_convert_cmd_to_mgcp(MGC_CMD_TYPE mgcCmd);
MGC_CMD_TYPE mgc_mgcp_convert_mgcp_to_cmd(BYTE mgcpCmd);
MGC_CON_MODE mgc_mgcp_convert_to_mgc_mode(BYTE mode);
BYTE mgc_mgcp_conver_to_mgcp_mode(MGC_CON_MODE mode);
char *mgc_mgcp_print_mgc_mode(MGC_CON_MODE mode);
char *mgc_mgcp_print_ip(DWORD addr);
BOOL mgc_mgcp_create_connect_dest_ip(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_create_connect_port(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_create_connect_req_start_line(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_create_connect_con_mode(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_create_connect_con_id(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_create_connect_call_id(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_create_connect_local_opt(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_create_connect_pkg_sig(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_create_connect_pkg_req(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_create_connect_sdp(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_create_connect_resp_start_line(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_response_msg(CONNECT_INFO *pConnect , MGCP_PARA *pPara, int retCode);
BOOL mgc_mgcp_parse_connect_sdp(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_parse_connect_pkg_sig(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_parse_connect_pkg_event(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_parse_connect_call_id(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_parse_connect_mode(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
BOOL mgc_mgcp_parse_connect_local_opt(CONNECT_INFO *pConnect , MGCP_PARA *pPara);
#endif

View File

@@ -0,0 +1,24 @@
#ifndef _MGC_PHY_PORT_H
#define _MGC_PHY_PORT_H
#include "mgc_struct.h"
void mgc_phy_port_setup(void);
void mgc_phy_port_init(PHY_PORT_INFO *pPhyPort , int id);
void mgc_phy_port_clear(PHY_PORT_INFO *pPhyPort);
PHY_PORT_INFO *mgc_phy_port_get_unused_phy(void);
PHY_PORT_INFO *mgc_phy_port_find_port_of_mg(MG_INFO *pMgInfo , int portNo);
PHY_PORT_INFO *mgc_phy_port_find_port_of_mg_by_index(MG_INFO *pMgInfo , int index);
void mgc_phy_port_set_chnl_num(PHY_PORT_INFO *pPhyPort , MGC_PHY_PORT_TYPE portType);
BOOL mgc_phy_port_attach_chnl(PHY_PORT_INFO *pPhyPort);
void mgc_phy_port_update_status(PHY_PORT_INFO *pPhyPort , BOOL status);
CHNL_INFO *mgc_phy_port_find_idle_chnl(PHY_PORT_INFO *pPhyPort);
CONNECT_INFO *mgc_phy_port_assign_idle_connection(PHY_PORT_INFO *pPhyPort);
void mgc_phy_port_set_mon(int id, BOOL enalbe);
BYTE *mgc_phy_port_get_res_addr(void);
void mgc_phy_port_print(PHY_PORT_INFO *pPhyPort);
#endif

View File

@@ -0,0 +1,38 @@
#ifndef _MGC_PORT_INFO_H
#define _MGC_PORT_INFO_H
#include "mgc_struct.h"
void mgc_port_info_setup(void);
void mgc_port_info_init(PORT_INFO *pPortInfo , int id);
void mgc_port_info_clear(PORT_INFO *pPortInfo);
PORT_INFO *mgc_port_info_get_unused_port(void);
void mgc_port_info_fsm(PORT_INFO *pPortInfo);
void mgc_port_info_oper_failure_report(PORT_INFO *pPortInfo , MGC_SAP *pMgcSap);
void mgc_port_info_oper_success_report(PORT_INFO *pPortInfo , MGC_SAP *pMgcSap);
PORT_INFO *mgc_port_info_find_port_by_id(int id);
PORT_INFO *mgc_port_info_get_step_port(MGCF_OPER_STEP *pOperStep);
BOOL mgc_port_info_add_opera_to_port(PORT_INFO *pPortInfo , CONNECT_INFO *pConnect , MGCF_STEP_INFO *pStepInfo);
BOOL mgc_port_info_add_ind_to_port(PORT_INFO *pPortInfo , CONNECT_INFO *pConnect , MGC_CMD_TYPE cmd , int hdlPort , DWORD remoteIp);
int mgc_port_info_cnf(PORT_INFO *pPortInfo , BYTE cmd, WORD hdlPort, WORD retCode, MGCP_PARA *pPara);
MGCF_OPER_STEP *mgc_port_info_get_unused_oper_step(PORT_INFO *pPortInfo);
void mgc_port_info_set_step_to_start(PORT_INFO *pPortInfo);
BOOL mgc_port_info_set_step_to_next(PORT_INFO *pPortInfo);
void mgc_port_info_set_oper_id(PORT_INFO *pPortInfo , MGC_MG_OPER_ID_TYPE operId);
void mgc_port_info_set_fsm_time(PORT_INFO *pPortInfo , WORD timer);
BOOL mgc_port_info_set_oper_step(MGCF_OPER_STEP *pMgcfOperStep , CONNECT_INFO *pConnect , MGCF_STEP_INFO *pStepInfo);
BOOL mgc_port_info_oper_step_cnf(MGCF_OPER_STEP *pMgcOperStep , MGCP_PARA *pPara);
void mgc_port_info_set_step_info(MGCF_STEP_INFO *pStepInfo , MGC_CMD_TYPE cmd , CONNECT_INFO *pPeerConn ,
WORD delay, MGC_CON_MODE mode, PKG_EVENT *pPkgEvent, PKG_SIGNAL *pPkgSig , PKG_REQ *pPkgReq);
BYTE *mgc_port_info_get_res_addr(void);
char *mgc_port_info_print_cmd(MGC_CMD_TYPE cmd);
char *mgc_port_info_print_opera_id(MGC_MG_OPER_ID_TYPE operaId);
BOOL mgc_port_info_insert_dlcx_req(PORT_INFO *pPortInfo , CONNECT_INFO *pConnect);
BOOL mgc_port_info_mv_step_into_new_port(PORT_INFO *pPortInfo , MGCF_OPER_STEP *pOperStep);
#endif

View File

@@ -0,0 +1,10 @@
#ifndef _MGC_PORT_LIST_H
#define _MGC_PORT_LIST_H
#include "mgc_struct.h"
void mgc_port_active_list_proc(void);
BOOL mgc_port_list_remove_from_active_list(PORT_INFO *pPortInfo);
MGC_PORT_NODE *mgc_port_list_add_to_active_list(PORT_INFO *pPortInfo);
void mgc_port_list_setup(void);
#endif

View File

@@ -0,0 +1,8 @@
#ifndef _MGC_PUB__H
#define _MGC_PUB__H
#include "../../../public/src/include/includes.h"
#include "../../../public/src/include/public.h"
#endif

View File

@@ -0,0 +1,17 @@
#ifndef _MGC_SNMP_H
#define _MGC_SNMP_H
const BYTE MGC_AC_LINE_STATUS_IDLEN = 12;
DWORD MGC_AC_LINE_STATUS_OID[20] =
{
1,3,6,1,2,1,10,18,6,1,10,0
};
const BYTE MGC_LGC_MG_STATUS_IDLEN = 13;
DWORD MGC_LGC_MG_STATUS_OID[20] =
{
1,3,6,1,4,1,1373,2,2,30,2,1,0
};
#endif

View File

@@ -0,0 +1,196 @@
#ifndef _MGC_STRUCT_H
#define _MGC_STRUCT_H
#include "mgc.h"
#include "../../../mgcp/src/include/mgcp.h"
#include "../../../8ecp/src/include/8ecp.h"
#define MGC_PORT_LIST_EN
#define MGC_REC_PORT
typedef struct _MGCP_REC_TAG
{
PUB_SDP_MEDIA m;
PUB_SDP_C c;
MGCP_M mode;
char esCci[32];
}MGCP_REC_TAG;
typedef struct _CONNECT_INFO
{
int id;
DWORD flag;
struct _MGCF_OPER_STEP *pOperStep;
#ifdef MGC_REC_PORT
struct _PORT_INFO *pPrePortInfo;
#endif
struct _CHNL_INFO *pChnlInfo;
MGC_CONNECT_STATUS status;
MGC_CODEC_LIST codecList;
MEDIA_ATTR mediaAttr;
OPER_REC operRec;
MGCP_REC_TAG mgcpRec;
struct _MGC_TANDEM_INFO *pTandem;
}CONNECT_INFO;
typedef struct _CHNL_INFO
{
int id;
BOOL monFlag; // monitor flag
MGC_CHNL_INFO_STATUS status;
struct _PHY_PORT_INFO *pPhyPort; //chnl's owner
WORD connectNum; //how many connection is attached
WORD maxConnectNum; //max connection num could be attached to the chnl accroding to chnl's owner
struct _CONNECT_INFO *pConnection[MGC_MAX_NUM_OF_CHNL_CON]; //Media Index
}CHNL_INFO;
typedef struct _PHY_PORT_INFO
{
int id;
int portNo; // mg local physical port No. ??
MGC_SAP *pMgcSap; // sap index, indicating which user creates this port
BOOL monFlag;
MGC_PHY_PORT_STATUS status; // physical port status: online/offline
MGC_PHY_PORT_TYPE portType; // port type: E1/T1/analogue
struct _MG_INFO *pMgInfo; // mg No. this port resides on ??
WORD chnlNum; // depend on mg type
struct _CHNL_INFO *pChnlInfo[MGC_MAX_CHNL_NUM_PER_PHY];
}PHY_PORT_INFO;
typedef struct _MG_INFO
{
int id; //internal used
BOOL created; // created flag;
BOOL enable; // MG status: available/unavailable
BOOL monFlag;
MG_ATTR mgAttr; // MG attributes
PHY_PORT_INFO *pPhyPort[MGC_MAX_PHY_PORT_PER_MG];
DWORD requestId; // SNMP request id
DWORD auditTimer;
}MG_INFO;
typedef struct _MGCF_STEP_INFO
{
struct _CONNECT_INFO *pPeerConn;
int delay;
MGC_CON_MODE mode;
MGC_CMD_TYPE cmd;
MGC_CODEC_LIST codecList;
PKG_SIGNAL pkgSig;
BOOL sigEn;
PKG_EVENT pkgEvent;
BOOL eventEn;
PKG_REQ pkgReq;
BOOL reqEn;
DWORD remoteIp; //only used for MG
}MGCF_STEP_INFO;
typedef struct _MGCF_OPER_STEP
{
int id;
struct _CONNECT_INFO *pConnect; //chnl connectIndex
struct _PORT_INFO *pPortInfo;
MGCF_STEP_INFO stepInfo;
MGCP_OPER_STEP_STATUS status;
WORD hdlPort; // lower layer port
WORD llCmd; // lower layer command or response
}MGCF_OPER_STEP;
typedef struct _PORT_INFO{
int id;
BOOL assigned;
WORD usrPort;
WORD mgcfTimer; // mgcf timer
MGC_MG_OPER_ID_TYPE mgcfOperId;
WORD cause; //reason to tell uplayer
struct _MGCF_OPER_STEP *pMgcOperCurrent;
struct _MGCF_OPER_STEP mgcfOperSteps[MGC_MAX_OPER_STEPS_NUM]; // max 8 steps
}
PORT_INFO;
typedef struct _MGC_8ECP_SAP
{
struct _8ECP_SAP sap8ecp;
int sapIndex;
}MGC_8ECP_SAP;
typedef struct _MGC_MGCP_SAP
{
struct _MGCP_SAP sapMgcp;
int sapIndex;
}MGC_MGCP_SAP;
typedef struct _MGC_CTL
{
WORD sysId;
WORD localIp;
WORD peerIp; //???
WORD mgcMaxMgNo;
WORD mgcMaxChlNo;
WORD mgcMgCreated;
WORD mgcChlAssigned;
}MGC_CTL;
typedef struct _MGC_INTERNAL_SAP
{
MGC_SAP mgcSap;
int mgcSapIndex;
int mgNoITL;
}MGC_INTERNAL_SAP;
typedef struct _MGC_SUR_INFO_NODE
{
int id;
struct _CONNECT_INFO *pConn;
struct _MGC_SUR_INFO_NODE *pPrior;
struct _MGC_SUR_INFO_NODE *pNext;
}MGC_SUR_INFO_NODE;
typedef struct _MGC_SUR_INFO_LIST
{
struct _MGC_SUR_INFO_NODE *pHead;
WORD len;
}MGC_SUR_INFO_LIST;
typedef struct _MGC_TANDEM_INFO
{
int id;
char escci[32];
struct _MGC_SUR_INFO_LIST list;
MGC_TANDEM_STATUS status;
CONNECT_INFO *pTconn; //pointer to target
CONNECT_INFO *pTxconn; //pointer to where target conn to send
CONNECT_INFO *pRxconn; //pointer to where targe conn to recieve from
CONNECT_INFO *pAconn; // pointer to associator
}MGC_TANDEM_INFO;
typedef struct _MGC_PORT_LIST
{
struct _MGC_PORT_NODE *pHead;
WORD len;
}MGC_PORT_LIST;
typedef struct _MGC_PORT_NODE
{
int id;
struct _PORT_INFO *pPortInfo;
struct _MGC_PORT_NODE *pPrior;
struct _MGC_PORT_NODE *pNext;
struct _MGC_PORT_LIST *pList;
}MGC_PORT_NODE;
#endif

View File

@@ -0,0 +1,19 @@
#ifndef _MGC_SUR_INFO_H
#define _MGC_SUR_INFO_H
#include "mgc_struct.h"
void mgc_sur_info_list_init(MGC_SUR_INFO_LIST *pList);
BOOL mgc_sur_info_add_conn_to_list(MGC_SUR_INFO_LIST *pList , CONNECT_INFO *pConn);
BOOL mgc_sur_info_remove_conn_to_list(MGC_SUR_INFO_LIST *pList , CONNECT_INFO *pConn);
MGC_SUR_INFO_NODE *mgc_sur_info_find_conn_in_list(MGC_SUR_INFO_LIST *pList , CONNECT_INFO *pConn);
MGC_SUR_INFO_NODE *mgc_sur_info_get_list_tail(MGC_SUR_INFO_LIST *pList);
MGC_SUR_INFO_NODE *mgc_sur_info_get_list_node(MGC_SUR_INFO_LIST *pList , WORD index);
BOOL mgc_sur_info_add_survillance_res(BYTE sapIndex, WORD mgNo);
void mgc_sur_info_setup(void);
void mgc_sur_info_clear_list(MGC_SUR_INFO_LIST *pList);
CONNECT_INFO *mgc_sur_info_find_sur_conn_in_mg(MG_INFO *pMgInfo);
#endif

View File

@@ -0,0 +1,37 @@
#ifndef _MGC_TANDEM_INFO_H
#define _MGC_TANDEM_INFO_H
#include "mgc_struct.h"
typedef enum
{
MGC_TANDEM_CONN_POS_UNDEF = -1,
MGC_TANDEM_CONN_POS_TAR,
MGC_TANDEM_CONN_POS_TX,
MGC_TANDEM_CONN_POS_RX,
MGC_TANDEM_CONN_POS_AOR,
MGC_TANDEM_CONN_POS_SUR
}MGC_TANDEM_CONN_POS;
BOOL mgc_tandem_info_unset_conn(MGC_TANDEM_INFO *pTandem , CONNECT_INFO *pConnect);
BOOL mgc_tandem_info_set_conn(MGC_TANDEM_INFO *pTandem , CONNECT_INFO *pConn, MGC_TANDEM_CONN_POS pos);
MGC_TANDEM_CONN_POS mgc_tandem_info_get_conn_pos(MGC_TANDEM_INFO *pTandem , CONNECT_INFO *pConn);
MGC_TANDEM_INFO *mgc_tandem_info_get_tandem_by_id(DWORD id);
MGC_TANDEM_INFO *mgc_tandem_info_get_idle_tandem(void);
void mgc_tandem_info_setup(void);
BOOL mgc_tandem_info_add_tandem_res(BYTE sapIndex, WORD mgNo);
BOOL mgc_tandem_info_set_esccd_info(MGC_TANDEM_INFO *pTandem , MGCP_ESCCD rxEsccd , MGCP_ESCCD txEsccd);
BOOL mgc_tandem_info_create_tar_tandem(CONNECT_INFO *pConnect, PORT_INFO *pPortInfo);
BOOL mgc_tandem_info_create_tandem(MGC_TANDEM_INFO *pTandem , PORT_INFO *pPortInfo);
BOOL mgc_tandem_info_stop_tandem_send_to_tar(CONNECT_INFO *pConnect, PORT_INFO *pPortInfo);
BOOL mgc_tandem_info_stop_tandem_send_to_aor(CONNECT_INFO *pConnect, PORT_INFO *pPortInfo);
MGC_TANDEM_STATUS mgc_tandem_info_get_status(MGC_TANDEM_INFO *pTandem);
BOOL mgc_tandem_info_dettach_aor_related_tandem(CONNECT_INFO *pConnect, CONNECT_INFO *pPeerConnect, PORT_INFO *pPortInfo);
BOOL mgc_tandem_info_connect(CONNECT_INFO *pConnect, CONNECT_INFO *pPeerConnect, MGC_CON_MODE mode , PORT_INFO *pPortInfo);
BOOL mgc_tandem_info_remove_connection_from_tandem(CONNECT_INFO *pConnect, PORT_INFO *pPortInfo);
BOOL mgc_tandem_info_mdcx(CONNECT_INFO *pConnect , PORT_INFO *pPortInfo);
BOOL mgc_tandem_info_add_crcx_aas(CONNECT_INFO *pAasConnect, CONNECT_INFO *pPeerConnect, PORT_INFO *pPortInfo);
BOOL mgc_tandem_info_add_mdcx_aas(CONNECT_INFO *pConnect, CONNECT_INFO *pAasConnect, PORT_INFO *pPortInfo);
BOOL mgc_tandem_info_clear(MGC_TANDEM_INFO *pTandem, PORT_INFO *pPortInfo);
#endif

2633
omc/plat/mgc_v2/src/mgc.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,326 @@
/*
*********************************************************************************
* *
* NOTICE: *
* *
*********************************************************************************
* do not support now
*/
/*********************************************************************************
* <mgc_8ecp.c>
* This file should include 8ecp related APIs used in MGC module, but now is not supported!!!!
*
*
* Author Date
* ------ ------
* Sam Yao Aug 2008
*********************************************************************************/
/*-----------------------------------------------------------------------*/
/* INCLUDE HEADER FILES */
/*-----------------------------------------------------------------------*/
#include "./include/mgc_8ecp.h"
#include "./include/mgc_mg_info.h"
#include "./include/mgc_phy_port.h"
#include "./include/mgc_debug.h"
static WORD mgc_e1card0_mgNo;
static WORD mgc_e1card1_mgNo;
static WORD mgc_8k_tone_card_silent;
static MGC_8ECP_SAP mgc8ecpSap;
/*-----------------------------------------------------------------------
MGC - 8ECP M A N A G E R
------------------------------------------------------------------------*/
int mgc_8ecp_update_mg_status(BYTE mgNo, BYTE status)
{
MG_INFO *pMgInfo = NULL ;
MG_INFO *pMgInfoE1 = NULL;
pMgInfo = mgc_mg_info_get_index_mg(mgNo);
pMgInfoE1 = mgc_mg_info_get_index_mg(mgc_e1card0_mgNo);
if((pMgInfo == NULL)||(pMgInfoE1 == NULL))
return -1;
if(pMgInfo->created == FALSE)
{
MGC_ERROR("%s : mg[%d] not created" , __FUNCTION__, pMgInfo->id);
return -1;
}
pMgInfo->enable = status;
if(pMgInfo->mgAttr.e1cardNo == 1)
{
if((status == 1)&&((0 == mgc_e1card0_mgNo)||(0 == pMgInfoE1->enable)))
{
mgc_8k_tone_card_silent = 1;
}
else
{
mgc_8k_tone_card_silent = 0;
}
}
else if(pMgInfo->mgAttr.e1cardNo == 0)
{
if ((0 == status)
&& (0 != mgc_e1card1_mgNo) && (1 == pMgInfoE1->enable))
{
mgc_8k_tone_card_silent = 1;
}
else
{
mgc_8k_tone_card_silent = 0;
}
}
return 0;
}
int mgc_8ecp_update_trk_status(BYTE mgNo, BYTE trkNo, BYTE status)
{
MG_INFO *pMgInfo = NULL;
PHY_PORT_INFO *pPhyPort = NULL;
pMgInfo = mgc_mg_info_get_index_mg(mgNo);
if(pMgInfo == NULL)
return -1;
if(pMgInfo->created == FALSE)
{
MGC_ERROR("%s : mg[%d] not created" , __FUNCTION__, pMgInfo->id);
return -1;
}
if (trkNo >= MGC_8ECP_MAX_TRK_PER_MG)
{
MGC_ERROR("%s : invalid trkNo, trkNo = %d" , __FUNCTION__ , trkNo);
return -1;
}
pPhyPort = mgc_phy_port_find_port_of_mg(pMgInfo, trkNo);
if(pPhyPort == NULL)
return -1;
pPhyPort->status = status;
return 0;
}
static int mgc_bind_8ecp(MGC_8ECP_SAP *pSap)
{
if(pSap == NULL)
return -1;
sprintf(pSap->sap8ecp.name, "MGC");
pSap->sap8ecp.update_mg_status = mgc_8ecp_update_mg_status;
pSap->sap8ecp.update_trk_status = mgc_8ecp_update_trk_status;
pSap->sapIndex= _8ecp_bind(&pSap->sap8ecp);
if(pSap->sapIndex < 0)
{
MGC_ERROR("8ecp %s bind failed!" , pSap->sap8ecp.name);
return -1;
}
mgc_8k_tone_card_silent = 0;
mgc_e1card0_mgNo = 0;
mgc_e1card1_mgNo = 0;
return pSap->sapIndex;
}
int mgc_bind_8ecp_setup(void)
{
MGC_8ECP_SAP *pSap = NULL;
pSap = &mgc8ecpSap;
if(mgc_bind_8ecp(pSap)<0)
return -1;
return 0;
}
BOOL mgc_8ecp_create(MG_INFO *pMgInfo , MG_ATTR *pMgAttr)
{
BYTE cardNo;
if((pMgInfo == NULL)||(pMgAttr == NULL))
return FALSE;
if(pMgAttr->ctrlType != MGC_MG_CTRL_TYPE_8ECP)
return FALSE;
cardNo = atoi(pMgAttr->domain);
if(cardNo > 31)
return FALSE;
_8ecp_createMG(pMgInfo->id, pMgAttr->ip, cardNo);
if (0 == cardNo)
{
mgc_e1card0_mgNo = pMgInfo->id;
}
else if (1 == cardNo)
{
mgc_e1card1_mgNo = pMgInfo->id;
}
memcpy(&pMgInfo->mgAttr , pMgAttr , sizeof(MG_ATTR));
return TRUE;
}
BOOL mgc_8ecp_delete(MG_INFO *pMgInfo)
{
BYTE cardNo;
if(pMgInfo == NULL)
return FALSE;
if(pMgInfo->mgAttr.ctrlType != MGC_MG_CTRL_TYPE_8ECP)
return FALSE;
cardNo = atoi(pMgInfo->mgAttr.domain);
if(cardNo > 31)
return FALSE;
_8ecp_deleteMG(pMgInfo->id, pMgInfo->mgAttr.ip, cardNo);
if (0 == cardNo)
{
mgc_e1card0_mgNo = 0;
}
else if (1 == cardNo)
{
mgc_e1card1_mgNo = 0;
}
return TRUE;
}
BOOL mgc_8ecp_dlcx_chnl(CHNL chnl)
{
MG_INFO *pMgInfo = NULL;
WORD org, dest;
pMgInfo = mgc_mg_info_get_index_mg(chnl.mgNo);
if(pMgInfo == NULL)
return FALSE;
if(pMgInfo->mgAttr.ctrlType != MGC_MG_CTRL_TYPE_8ECP)
return FALSE;
org = (pMgInfo->mgAttr.e1cardNo*8 + chnl.portNo)*32 + chnl.chlNo;
dest = (mgc_8k_tone_card_silent * 8 + 7) * 32 + 31;
_8ecp_connect_chnl(org, dest, 0);
return TRUE;
}
BOOL mgc_8ecp_connect_chnl(CHNL orgChnl, CHNL destChnl, BYTE flag)
{
MG_INFO *pOrgMgInfo = NULL;
MG_INFO *pDestMgInfo = NULL;
WORD org, dest;
pOrgMgInfo = mgc_mg_info_get_index_mg(orgChnl.mgNo);
pDestMgInfo = mgc_mg_info_get_index_mg(destChnl.mgNo);
if((pOrgMgInfo == NULL)||(pDestMgInfo == NULL))
return FALSE;
if(pOrgMgInfo->mgAttr.ctrlType != MGC_MG_CTRL_TYPE_8ECP)
return FALSE;
if(pDestMgInfo->mgAttr.ctrlType != MGC_MG_CTRL_TYPE_8ECP)
return FALSE;
org = (pOrgMgInfo->mgAttr.e1cardNo*8 + orgChnl.portNo)*32 + orgChnl.chlNo;
dest= (pDestMgInfo->mgAttr.e1cardNo*8 + destChnl.portNo)*32 + destChnl.chlNo;
if((flag & MGC_CONNECT_SILENT_TONE) == MGC_CONNECT_SILENT_TONE)
dest = (mgc_8k_tone_card_silent * 8 + 7) * 32 + 31;
_8ecp_connect_chnl(org, dest, 0);
return TRUE;
}
BOOL mgc_8ecp_connect_dtmf(CHNL orgChnl, CHNL destChnl, BYTE digit)
{
MG_INFO *pOrgMgInfo = NULL;
MG_INFO *pDestMgInfo = NULL;
WORD org, dest;
pOrgMgInfo = mgc_mg_info_get_index_mg(orgChnl.mgNo);
pDestMgInfo = mgc_mg_info_get_index_mg(destChnl.mgNo);
if((pOrgMgInfo == NULL)||(pDestMgInfo == NULL))
return FALSE;
if(pOrgMgInfo->mgAttr.ctrlType != MGC_MG_CTRL_TYPE_8ECP)
return FALSE;
if(pDestMgInfo->mgAttr.ctrlType != MGC_MG_CTRL_TYPE_8ECP)
return FALSE;
org = (pOrgMgInfo->mgAttr.e1cardNo*8 + orgChnl.portNo)*32 + orgChnl.chlNo;
dest= (pDestMgInfo->mgAttr.e1cardNo*8 + destChnl.portNo)*32 + destChnl.chlNo;
if(digit == 0)
digit = 10;
_8ecp_connect_chnl(org, dest, digit);
return TRUE;
}
BOOL mgc_8ecp_connect_tone(CHNL orgChnl, CHNL destChnl, BYTE tone , BYTE duration)
{
MG_INFO *pOrgMgInfo = NULL;
MG_INFO *pDestMgInfo = NULL;
WORD org, dest;
pOrgMgInfo = mgc_mg_info_get_index_mg(orgChnl.mgNo);
pDestMgInfo = mgc_mg_info_get_index_mg(destChnl.mgNo);
if((pOrgMgInfo == NULL)||(pDestMgInfo == NULL))
return FALSE;
if(pOrgMgInfo->mgAttr.ctrlType != MGC_MG_CTRL_TYPE_8ECP)
return FALSE;
if(pDestMgInfo->mgAttr.ctrlType != MGC_MG_CTRL_TYPE_8ECP)
return FALSE;
org = (pOrgMgInfo->mgAttr.e1cardNo*8 + orgChnl.portNo)*32 + orgChnl.chlNo;
dest= (pDestMgInfo->mgAttr.e1cardNo*8 + destChnl.portNo)*32 + destChnl.chlNo;
_8ecp_connect_tone(org, dest, tone ,duration);
return TRUE;
}

View File

@@ -0,0 +1,613 @@
/*
*********************************************************************************
* *
* NOTICE: *
* *
*********************************************************************************
* mgcPhyPort <---------- mgcChnls <-----------mgcConnections
*/
/*********************************************************************************
* <mgc_chnl_info.c>
* This file should provide CHNL_INFO APIs used in MGC module. Every chnl should be attached to
*a phyport if used, and could contain servral connections
*
* Author Date
* ------ ------
* Sam Yao Aug 2008
*********************************************************************************/
/*-----------------------------------------------------------------------*/
/* INCLUDE HEADER FILES */
/*-----------------------------------------------------------------------*/
#include "./include/mgc_chnl_info.h"
#include "./include/mgc_debug.h"
#include "./include/mgc_conn_info.h"
#include "./include/mgc_phy_port.h"
#include "./include/mgc_mg_info.h"
#include "./include/mgc_mgcp.h"
static CHNL_INFO mgcChnl[MGC_MAX_NUM_OF_CHNL];
/*-----------------------------------------------------------------------
CHNL_INFO M A N A G E R
------------------------------------------------------------------------*/
/***************************************************************************
* mgc_chnl_info_init
* ------------------------------------------------------------------------
* General: init CHNL_INFO structure objcet
* Return Value: void.
* ------------------------------------------------------------------------
* Arguments:
* Input: pChnlInfo- the pointer of the CHNL_INFO object which should be init
* id - the id of the CHNL_INFO object
***************************************************************************/
void mgc_chnl_info_init(CHNL_INFO *pChnlInfo , int id)
{
int i;
if((pChnlInfo == NULL)||(id < 0))
return;
pChnlInfo->id = id;
pChnlInfo->status = MGC_CHNL_INFO_STATUS_UNDEF;
pChnlInfo->pPhyPort = NULL;
pChnlInfo->connectNum = 0;
pChnlInfo->monFlag = 0;
pChnlInfo->maxConnectNum = 0;
for(i=0 ; i<MGC_MAX_NUM_OF_CHNL_CON ; i++)
{
pChnlInfo->pConnection[i] = NULL;
}
return;
}
void mgc_chnl_info_setup(void)
{
int i;
CHNL_INFO *pChnlInfo = NULL;
for(i=0 ; i<MGC_MAX_NUM_OF_CHNL ; i++)
{
pChnlInfo = &mgcChnl[i];
mgc_chnl_info_init(pChnlInfo, i);
}
return;
}
/***************************************************************************
* mgc_chnl_info_clear
* ------------------------------------------------------------------------
* General: clear and init CHNL_INFO structure objcet , if any connection is created in this chnl,
* DLCX will be sent out
* Return Value: void.
* ------------------------------------------------------------------------
* Arguments:
* Input: pChnlInfo- the pointer of the CHNL_INFO object which should be init
***************************************************************************/
void mgc_chnl_info_clear(CHNL_INFO *pChnlInfo)
{
int i;
CONNECT_INFO *pConnect = NULL;
MGCP_PARA mgcpPara;
if(pChnlInfo == NULL)
return;
for(i=0 ; i<MGC_MAX_NUM_OF_CHNL_CON ; i++)
{
pConnect = pChnlInfo->pConnection[i];
if(pConnect == NULL)
continue;
if((mgc_connect_get_status(pConnect) == MGC_CONNECT_STATUS_CREATED)||(mgc_connect_get_status(pConnect) == MGC_CONNECT_STATUS_CREATE))
{
if(mgc_connect_dlcx_para_create(pConnect , &mgcpPara) == TRUE)
MGCP_req(mgc_mgcp_get_sap_index(), MGCP_CMD_DLCX , 0xFFFF , &mgcpPara);
}
mgc_connect_init(pConnect , pConnect->id);
}
mgc_chnl_info_init(pChnlInfo , pChnlInfo->id);
return;
}
/***************************************************************************
* mgc_chnl_info_get_unused_chnl
* ------------------------------------------------------------------------
* General: get a unused CHNL_INFO structure
* Return Value: if failure return NULL , else return a pointer
* ------------------------------------------------------------------------
* Arguments:
* Input: void
***************************************************************************/
CHNL_INFO *mgc_chnl_info_get_unused_chnl(void)
{
int i;
CHNL_INFO *pChnlInfo = NULL;
for(i=0 ; i<MGC_MAX_NUM_OF_CHNL ; i++)
{
pChnlInfo = &mgcChnl[i];
if(pChnlInfo->pPhyPort != NULL)
continue;
return pChnlInfo;
}
return NULL;
}
/***************************************************************************
* mgc_chnl_info_attach_to_phy_port
* ------------------------------------------------------------------------
* General: record the owner phyPort of the chnl
* Return Value: if failure return FALSE , else return TRUE
* ------------------------------------------------------------------------
* Arguments:
* Input: pChnlInfo - the pointer of the CHNL_INFO object which need to record it's own phyPort
* pPhyPort - the pointer of the PHY_PORT_INFO object which is the owner of the chnl
***************************************************************************/
BOOL mgc_chnl_info_attach_to_phy_port(CHNL_INFO *pChnlInfo , PHY_PORT_INFO *pPhyPort)
{
if((pChnlInfo == NULL) || (pPhyPort == NULL))
return FALSE;
if(pChnlInfo->status != MGC_CHNL_INFO_STATUS_UNDEF)
return FALSE;
switch(pPhyPort->portType)
{
case MGC_PHY_PORT_TYPE_E1:
case MGC_PHY_PORT_TYPE_T1:
case MGC_PHY_PORT_TYPE_ANALOG:
case MGC_PHY_VIRTUAL_TYPE_INTERNAL:
pChnlInfo->maxConnectNum = 1;
break;
case MGC_PHY_VIRTUAL_TYPE_TANDEM:
pChnlInfo->maxConnectNum = 2;
break;
case MGC_PHY_VIRTUAL_TYPE_SURVEILLANCE:
pChnlInfo->maxConnectNum = 1;
break;
case MGC_PHY_VIRTUAL_TYPE_ANN:
pChnlInfo->maxConnectNum = MGC_MAX_NUM_OF_CHNL_CON;
break;
default:
pChnlInfo->maxConnectNum = 0;
break;
}
pChnlInfo->pPhyPort = pPhyPort;
return TRUE;
}
/***************************************************************************
* mgc_chnl_info_status_set
* ------------------------------------------------------------------------
* General: set the status of the CHNL_INFO object
* Return Value: void
* ------------------------------------------------------------------------
* Arguments:
* Input: pChnlInfo - the pointer of the CHNL_INFO object which need to be set
* status - the status of the CHNL_INFO object
***************************************************************************/
void mgc_chnl_info_status_set(CHNL_INFO *pChnlInfo , MGC_CHNL_INFO_STATUS status)
{
if(pChnlInfo == NULL)
return;
pChnlInfo->status = status;
return;
}
/***************************************************************************
* mgc_chnl_info_find_chnl_of_phy
* ------------------------------------------------------------------------
* General: get the CHNL_INFO object in the phyPort according to the chnl id
* Return Value: if failure return NULL , else return the pointor of the object
* ------------------------------------------------------------------------
* Arguments:
* Input: pPhyPort - the pointer of the phyPort which contain the CHNL_INFO objects pointers
* chnlNo - the CHNL_INFO object id
***************************************************************************/
CHNL_INFO *mgc_chnl_info_find_chnl_of_phy(PHY_PORT_INFO *pPhyPort , int chnlNo)
{
if(pPhyPort == NULL)
return NULL;
if(chnlNo > MGC_MAX_CHNL_NUM_PER_PHY)
return NULL;
if(chnlNo >= pPhyPort->chnlNum)
{
MGC_WARN("chnlNo is out of suppose to be ");
}
return pPhyPort->pChnlInfo[chnlNo];
}
/***************************************************************************
* mgc_chnl_info_get_chnl
* ------------------------------------------------------------------------
* General: get the CHNL_INFO object according to the CHNL parameters
* Return Value: if failure return NULL , else return the pointor of the object
* ------------------------------------------------------------------------
* Arguments:
* Input: chnl - CHNL object which contain mgNo , chnlNo, connectNo and phyPort No
***************************************************************************/
CHNL_INFO *mgc_chnl_info_get_chnl(CHNL chnl)
{
MG_INFO *pMgInfo = NULL;
PHY_PORT_INFO *pPhyPort = NULL;
CHNL_INFO *pChnlInfo = NULL;
pMgInfo = mgc_mg_info_get_index_mg(chnl.mgNo);
if(pMgInfo == NULL)
return NULL;
pPhyPort = mgc_phy_port_find_port_of_mg(pMgInfo , chnl.portNo);
if(pPhyPort == NULL)
return NULL;
pChnlInfo = mgc_chnl_info_find_chnl_of_phy(pPhyPort , chnl.chlNo);
if(pChnlInfo == NULL)
return NULL;
return pChnlInfo;
}
/***************************************************************************
* mgc_chnl_info_attach_connect
* ------------------------------------------------------------------------
* General: record a connection in the assgined place
* Return Value: if failure return FALSE , else return TRUE
* ------------------------------------------------------------------------
* Arguments:
* Input: pChnlInfo - the pointer of the CHNL_INFO object which need to record the connect
* pConnect - the pointer of the CONNECT_INFO object
* connNo - the place where the CONNECT_INFO should be record in
***************************************************************************/
BOOL mgc_chnl_info_attach_connect(CHNL_INFO *pChnlInfo , CONNECT_INFO *pConnect , int connNo)
{
if((pChnlInfo == NULL)||(pConnect == NULL))
return FALSE;
if(connNo >= MGC_MAX_NUM_OF_CHNL_CON)
return FALSE;
if(mgc_connect_get_status(pConnect)!= MGC_CONNECT_STATUS_UNDEF)
return FALSE;
if(pChnlInfo->pConnection[connNo] != NULL)
return FALSE;
if(pChnlInfo->connectNum >= pChnlInfo->maxConnectNum)
return FALSE;
if(mgc_connect_attach_connect_to_chnl(pConnect , pChnlInfo) == FALSE)
return FALSE;
pChnlInfo->pConnection[connNo] = pConnect;
pChnlInfo->connectNum++;
mgc_connect_set_status(pConnect , MGC_CONNECT_STATUS_IDLE);
mgc_chnl_info_status_set(pChnlInfo , MGC_CHNL_INFO_STATUS_USED);
return TRUE;
}
/***************************************************************************
* mgc_chnl_info_detach_connect
* ------------------------------------------------------------------------
* General: remove a connect info from the CHNL_INFO object
* Return Value: if failure return FALSE , else return TRUE
* ------------------------------------------------------------------------
* Arguments:
* Input: pChnlInfo - the pointer of the CHNL_INFO object which need to remove connect info
* pConnect - the pointer of the CONNECT_INFO object which need to be remove
***************************************************************************/
BOOL mgc_chnl_info_detach_connect(CHNL_INFO *pChnlInfo , CONNECT_INFO *pConnect)
{
int i;
if((pChnlInfo == NULL)||(pConnect == NULL))
return FALSE;
for(i=0 ; i<MGC_MAX_NUM_OF_CHNL_CON ; i++)
{
if(pConnect != pChnlInfo->pConnection[i])
continue;
pChnlInfo->pConnection[i] = NULL;
pChnlInfo->connectNum--;
mgc_connect_init(pConnect, pConnect->id);
// MGC_DEBUG("conn[%d] detach from chnlInfo[%d], as connNo %d" , pConnect->id , pChnlInfo->id , i);
return TRUE;
}
return FALSE;
}
/***************************************************************************
* mgc_chnl_info_get_chnl_no_of_phy
* ------------------------------------------------------------------------
* General: find the record place of the CHNL_INFO object in it's owner phyPort
* Return Value: if failure return -1 , else return the place number
* ------------------------------------------------------------------------
* Arguments:
* Input: pChnlInfo - the pointer of the CHNL_INFO object which need to be find
* pPhyPort - the pointer of the PHY_PORT_INFO object which contain the CHNL_INFO
***************************************************************************/
int mgc_chnl_info_get_chnl_no_of_phy(CHNL_INFO *pChnlInfo , PHY_PORT_INFO *pPhyPort)
{
int i;
if((pChnlInfo == NULL)||(pPhyPort == NULL))
return -1;
for(i=0 ; i<MGC_MAX_CHNL_NUM_PER_PHY ; i++)
{
if(pChnlInfo != pPhyPort->pChnlInfo[i])
continue;
return i;
}
return -1;
}
/***************************************************************************
* mgc_chnl_info_assign_connect
* ------------------------------------------------------------------------
* General: assgin a connection on the assigned place
* Return Value: if failure return NULL, else return the pointer of the connect
* ------------------------------------------------------------------------
* Arguments:
* Input: pChnlInfo - the pointer of the CHNL_INFO object which need to assign
* connNo - the assgined place NO
***************************************************************************/
CONNECT_INFO *mgc_chnl_info_assign_connect(CHNL_INFO *pChnlInfo , int connNo)
{
CONNECT_INFO *pConnect = NULL;
if(pChnlInfo == NULL)
return NULL;
pConnect = mgc_connect_find_connect_of_chnl(pChnlInfo, connNo);
if(pConnect != NULL)
{
//MGC_DEBUG("chnlInfo[%d] already have conn[%d], as connNo %d" , pChnlInfo->id , pConnect->id , connNo);
return pConnect;
}
if(pChnlInfo->connectNum >= pChnlInfo->maxConnectNum)
return FALSE;
pConnect = mgc_connect_get_unused();
if(pConnect == NULL)
return NULL;
if(mgc_chnl_info_attach_connect(pChnlInfo , pConnect , connNo) == FALSE)
return NULL;
//MGC_DEBUG("assign unused conn[%d] to chnlInfo[%d]connNo[%d]" , pConnect->id , pChnlInfo->id, connNo);
return pConnect;
}
/***************************************************************************
* mgc_chnl_info_assign_idle_connect
* ------------------------------------------------------------------------
* General: assgin a connection on the CHNL_INFO object
* Return Value: if failure return NULL, else return the pointer of the connect
* ------------------------------------------------------------------------
* Arguments:
* Input: pChnlInfo - the pointer of the CHNL_INFO object which need to assign
***************************************************************************/
CONNECT_INFO *mgc_chnl_info_assign_idle_connect(CHNL_INFO *pChnlInfo)
{
int i;
CONNECT_INFO *pConnect = NULL;
CONNECT_INFO *pConnectTmp = NULL;
if(pChnlInfo == NULL)
return NULL;
//MGC_DEBUG("func %s " , __FUNCTION__);
for(i=0 ; i<MGC_MAX_NUM_OF_CHNL_CON ; i++)
{
pConnect = pChnlInfo->pConnection[i];
if(pConnect != NULL)
{
if(mgc_connect_get_status(pConnect) != MGC_CONNECT_STATUS_IDLE)
continue;
return pConnect;
}
pConnectTmp = mgc_chnl_info_assign_connect(pChnlInfo , i);
if(pConnectTmp == NULL)
continue;
return pConnectTmp;
}
return NULL;
}
void mgc_chnl_info_set_mon(int id, BOOL enable)
{
if((id < 0) || (id > MGC_MAX_NUM_OF_CHNL))
return;
mgcChnl[id].monFlag = enable;
}
BYTE *mgc_chnl_info_get_res_addr(void)
{
return (BYTE *)mgcChnl;
}
char *mgc_chnl_info_print_codec(CHNL_INFO *pChnlInfo)
{
int i;
CONNECT_INFO *pConnect = NULL;
if(pChnlInfo == NULL)
return "UNKNOWN";
if(pChnlInfo->maxConnectNum > 1)
return "UNKNOWN";
for(i=0 ; i<pChnlInfo->maxConnectNum ; i++)
{
pConnect = pChnlInfo->pConnection[i];
if(pConnect != NULL)
break;
}
if(pConnect == NULL)
return "UNKNOWN";
return mgc_mgcp_print_vc_codec(pConnect->mediaAttr.vocoderType);
}
char *mgc_chnl_info_print_remote(CHNL_INFO *pChnlInfo)
{
int i;
CONNECT_INFO *pConnect = NULL;
PUB_SDP_MEDIA *pMedia = NULL;
PUB_SDP_MSG *pSdp = NULL;
static char buf[32];
sprintf(buf , "0.0.0.0:0");
if(pChnlInfo == NULL)
return buf;
if(pChnlInfo->maxConnectNum > 1)
return buf;
for(i=0 ; i<pChnlInfo->maxConnectNum ; i++)
{
pConnect = pChnlInfo->pConnection[i];
if(pConnect != NULL)
break;
}
if(pConnect == NULL)
return buf;
pSdp = &pConnect->mediaAttr.sdp;
pMedia = &pSdp->medias.medias[0];
if((pMedia->m.port != 0)||(strlen(pSdp->c.addr) != 0))
sprintf(buf , "%s:%d" , pSdp->c.addr, pMedia->m.port);
return buf;
}
char *mgc_chnl_info_print_mode(CHNL_INFO *pChnlInfo)
{
int i;
CONNECT_INFO *pConnect = NULL;
if(pChnlInfo == NULL)
return "INACTIVE";
if(pChnlInfo->maxConnectNum > 1)
return "INACTIVE";
for(i=0 ; i<pChnlInfo->maxConnectNum ; i++)
{
pConnect = pChnlInfo->pConnection[i];
if(pConnect != NULL)
break;
}
if(pConnect == NULL)
return "INACTIVE";
switch(mgc_connect_get_conn_mode(pConnect))
{
case MGC_CON_MODE_INACTIVE:
return "INACTIVE";
case MGC_CON_MODE_RECVONLY:
return "RECVONLY";
case MGC_CON_MODE_SENDONLY:
return "SENDONLY";
case MGC_CON_MODE_SENDRECV:
return "SENDRECV";
default:
break;
}
return "INACTIVE";
}
char *mgc_chnl_info_print_status(CHNL_INFO *pChnlInfo)
{
int i;
CONNECT_INFO *pConnect = NULL;
if(pChnlInfo == NULL)
return "UNDEF";
if(pChnlInfo->maxConnectNum > 1)
return "UNDEF";
for(i=0 ; i<pChnlInfo->maxConnectNum ; i++)
{
pConnect = pChnlInfo->pConnection[i];
if(pConnect != NULL)
break;
}
if(pConnect == NULL)
return "IDLE";
switch(mgc_connect_get_status(pConnect))
{
case MGC_CONNECT_STATUS_IDLE:
return "IDLE";
case MGC_CONNECT_STATUS_CREATE:
return "CREATE";
case MGC_CONNECT_STATUS_CREATED:
return "CONNECT";
case MGC_CONNECT_STATUS_CREATING:
return "CREATING";
default:
break;
}
return "UNDEF";
}
#ifdef MGC_TEST_ENABLE
int mgc_chnl_info_assigned_num(void)
{
int i , num;
CHNL_INFO *pChnlInfo = NULL;
num = 0;
for(i=0 ; i<MGC_MAX_NUM_OF_CHNL ; i++)
{
pChnlInfo = &mgcChnl[i];
if(pChnlInfo->pPhyPort != NULL)
num++;
}
return num;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,146 @@
/*
*********************************************************************************
* *
* NOTICE: *
* *
*********************************************************************************
*/
/*********************************************************************************
* <mgc_ctl.c>
* This file contain global variable control
*
* Author Date
* ------ ------
* Sam Yao Aug 2008
*********************************************************************************/
/*-----------------------------------------------------------------------*/
/* INCLUDE HEADER FILES */
/*-----------------------------------------------------------------------*/
#include "./include/mgc_ctl.h"
MGC_CTL mgcCtl;
void mgc_ctl_num_init(WORD sysId , WORD localIp , WORD peerIp)
{
MGC_CTL *pMgcCtl = NULL;
pMgcCtl = &mgcCtl;
pMgcCtl->mgcChlAssigned = 0;
pMgcCtl->mgcMgCreated = 0;
pMgcCtl->mgcMaxChlNo = MGC_MAX_NUM_OF_CHNL;
pMgcCtl->mgcMaxMgNo = MGC_MAX_NUM_OF_MG;
pMgcCtl->sysId = sysId;
pMgcCtl->localIp = localIp;
pMgcCtl->peerIp = peerIp;
return;
}
BOOL mgc_ctl_is_mg_full(void)
{
MGC_CTL *pMgcCtl = NULL;
pMgcCtl = &mgcCtl;
if((pMgcCtl->mgcMgCreated + 1) > pMgcCtl->mgcMaxMgNo)
return TRUE;
return FALSE;
}
void mgc_ctl_mg_add_one(void)
{
MGC_CTL *pMgcCtl = NULL;
pMgcCtl = &mgcCtl;
pMgcCtl->mgcMgCreated++;
return;
}
void mgc_ctl_mg_remove_one(void)
{
MGC_CTL *pMgcCtl = NULL;
pMgcCtl = &mgcCtl;
pMgcCtl->mgcMgCreated--;
return;
}
BOOL mgc_ctl_is_chnl_full(void)
{
MGC_CTL *pMgcCtl = NULL;
pMgcCtl = &mgcCtl;
if((pMgcCtl->mgcChlAssigned+ 1) > pMgcCtl->mgcMaxChlNo)
return TRUE;
return FALSE;
}
void mgc_ctl_chnl_add_one(void)
{
MGC_CTL *pMgcCtl = NULL;
pMgcCtl = &mgcCtl;
pMgcCtl->mgcChlAssigned++;
return;
}
void mgc_ctl_chnl_remove_one(void)
{
MGC_CTL *pMgcCtl = NULL;
pMgcCtl = &mgcCtl;
pMgcCtl->mgcChlAssigned--;
return;
}
int mgc_ctl_set_mg_max_num(int num)
{
MGC_CTL *pMgcCtl = NULL;
pMgcCtl = &mgcCtl;
if((num <= 0)||(num>MGC_MAX_NUM_OF_MG))
return -1;
pMgcCtl->mgcMaxMgNo = num;
return num;
}
int mgc_ctl_set_chnl_max_num(int num)
{
MGC_CTL *pMgcCtl = NULL;
pMgcCtl = &mgcCtl;
if((num <= 0)||( num > MGC_MAX_NUM_OF_CHNL))
return -1;
pMgcCtl->mgcMaxChlNo = num;
return num;
}
#ifdef MGC_TEST_ENABLE
int mgc_ctl_chnl_num(void)
{
MGC_CTL *pMgcCtl;
pMgcCtl = &mgcCtl;
return pMgcCtl->mgcChlAssigned;
}
int mgc_ctl_mg_num(void)
{
MGC_CTL *pMgcCtl;
pMgcCtl = &mgcCtl;
return pMgcCtl->mgcMgCreated;
}
#endif

View File

@@ -0,0 +1,779 @@
#include "./include/mgc_debug.h"
#include "./include/mgc_mg_info.h"
#include "./include/mgc_phy_port.h"
#include "./include/mgc_chnl_info.h"
#include "./include/mgc_port_info.h"
#include "../../debug/src/include/debug.h"
#define MGC_DEBUG_ID 18
#define MGC_VER_DEBUG "R9V0_07"
static char ascii[16] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46};
static BYTE log_help[] = {
"MGC Debug Monitor Help:\n\r\
\n\r\
1.[help] display help menu\n\r\
2.[log info on/off] display info logs\n\r\
3.[log error on/off] display error logs \n\r\
4.[log warn on/off] display warn logs \n\r\
5.[log all/none] display all/none logs\n\r\
6.[log record -f FILENAME] write debug message to FILENAME \n\r\
7.[print mg ID/Domain] print mg[ID]/Domain info \n\r\
"
};
static WORD disp_page[10];
static BYTE *disp_ptr = (BYTE *) disp_page;
static DWORD debug_status_id[20] =
{
1,3,6,1,4,1,1373,1,1,2,3,1,2,MGC_DEBUG_ID + 2,1
};
static BYTE debug_status = 1;
static DWORD debug_name_id[20] =
{
1,3,6,1,4,1,1373,1,1,2,3,1,2,MGC_DEBUG_ID + 2,2
};
static DWORD debug_ascin_id[20] =
{
1,3,6,1,4,1,1373,1,1,2,3,1,2,MGC_DEBUG_ID + 2,3
};
static DWORD debug_ascout_id[20] =
{
1,3,6,1,4,1,1373,1,1,2,3,1,2,MGC_DEBUG_ID + 2,4
};
static DWORD debug_page_title[20] =
{
1,3,6,1,4,1,1373,1,1,2,3,1,2,MGC_DEBUG_ID + 2,1,1
};
static DWORD debug_page_line[20] =
{
1,3,6,1,4,1,1373,1,1,2,3,1,2,MGC_DEBUG_ID + 2,1,2,1
};
const static BYTE MGC_BASE_ID_LEN = 15;
const static BYTE MGC_PAGE_POINT = 14;
const static BYTE MGC_LINE_POINT = 15;
static BYTE title1_p[] =
{
" MGC Page 01 MG Info\n\r\
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n\r\
Subpage\n\r\
MG_Info\n\r"
};
static BYTE title2_p[] =
{
" MGC Page 02 Phy Port Info\n\r\
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n\r\
Subpage\n\r\
Phy_Port\n\r"
};
static BYTE title3_p[] =
{
" MGC Page 03 Channel Info\n\r\
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n\r\
Subpage\n\r\
Chnl_Info\n\r"
};
static BYTE title4_p[] =
{
" MGC Page 04 Port Info\n\r\
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n\r\
Port_Info\n\r"
};
#define FILENAMELEN 128
static char fileName[FILENAMELEN];
BYTE mgc_disp_line(BYTE page, BYTE line)
{
BYTE disp_length;
disp_length = 16;
disp_ptr = (BYTE *) disp_page;
switch (page)
{
case 1: // Page 1: MG Info
if (line == 0)
{
disp_ptr = (BYTE *) &disp_page[page];
disp_length = 2;
}
else
disp_ptr = (BYTE *) mgc_mg_info_get_res_addr() + disp_page[page] * sizeof(MG_INFO) + (line - 1) * 16;
break;
case 2: // Page 2: Phy Port Info
if (line == 0)
{
disp_ptr = (BYTE *) &disp_page[page];
disp_length = 2;
}
else
disp_ptr = (BYTE *) mgc_phy_port_get_res_addr() + disp_page[page] * sizeof(PHY_PORT_INFO) + (line - 1) * 16;
break;
case 3: // Page 3: Channel Info
if (line == 0)
{
disp_ptr = (BYTE *) &disp_page[page];
disp_length = 2;
}
else
disp_ptr = (BYTE *) mgc_chnl_info_get_res_addr + disp_page[page] * sizeof(CHNL_INFO) + (line - 1) * 16;
break;
case 4: // Page 4: Software Port Info
if (line == 0)
{
disp_ptr = (BYTE *) &disp_page[page];
disp_length = 2;
}
else
disp_ptr = (BYTE *) mgc_port_info_get_res_addr + disp_page[page] * sizeof(PORT_INFO) + (line - 1) * 16;
break;
default:
disp_length = 0;
break;
}
return disp_length;
}
void mgc_disp_page(BYTE page)
{
BYTE disp_line;
BYTE disp_length;
debug_page_line[MGC_PAGE_POINT] = page + 5;
for (disp_line = 0; disp_line < 22; disp_line++)
{
disp_length = mgc_disp_line(page, disp_line);
debug_page_line[MGC_LINE_POINT] = disp_line + 2;
debug_page_line[MGC_LINE_POINT + 1] = 2; // Data Pointer
debug_set_response(MGC_BASE_ID_LEN + 2, debug_page_line, disp_ptr, disp_length);
}
}
int mgc_debug_set(void)
{
BYTE page;
BYTE data[10];
BYTE *ptr;
time_t timep;
struct tm *p;
bzero(disp_page, 20);
ptr = data;
debug_set_response(MGC_BASE_ID_LEN, debug_status_id, &debug_status, 1);
debug_set_response(MGC_BASE_ID_LEN, debug_name_id, MGC_VER_DEBUG, 10);
debug_set_response(MGC_BASE_ID_LEN, debug_ascin_id, mgcAsciInBuf, 4096);
debug_set_response(MGC_BASE_ID_LEN, debug_ascout_id, mgcAsciOutBuf, MGC_MAX_ASCIIOUT_LEN);
for (page = 1; page < 5; page++)
{
switch (page)
{
case 1: //page 1
ptr = title1_p;
break;
case 2: //page 2
ptr = title2_p;
break;
case 3: //page 3
ptr = title3_p;
break;
case 4: //page 4
ptr = title4_p;
break;
default:
break;
}
debug_page_title[MGC_PAGE_POINT] = 5 + page;
debug_set_response(MGC_BASE_ID_LEN + 1, debug_page_title, ptr, strlen(ptr));
mgc_disp_page(page);
}
// mkdir("mgc_log" , 777);
time(&timep);
p = gmtime(&timep);
memset(fileName , 0 , FILENAMELEN);
//sprintf(fileName , "mgc_log/mgc_log_%d_%d_%d_%d.txt", p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
return 1;
}
BOOL mgc_debug_parse_print_info(char *pAscin)
{
char *ptr = NULL;
char *ptrTmp = NULL;
MG_INFO *pMgInfo = NULL;
int id = -1;
if(pAscin == NULL)
return FALSE;
if(strstr(pAscin , "print") == NULL)
return FALSE;
ptr = strstr(pAscin , "mg");
if(ptr == NULL)
return FALSE;
ptr = ptr+2;
while(*ptr != '\n')
{
if(*ptr != ' ')
{
ptrTmp = ptr;
break;
}
ptr++;
}
if(ptrTmp == NULL)
return FALSE;
pMgInfo = mgc_mg_info_find_mg_by_name(ptrTmp);
if(pMgInfo == NULL)
{
id = atoi(ptrTmp);
pMgInfo = mgc_mg_info_get_index_mg(id);
}
if(pMgInfo == NULL)
return FALSE;
mgc_mg_info_print_info(pMgInfo);
return TRUE;
}
BOOL mgc_debug_parse_log_file(char *pAscin)
{
char *ptr = NULL;
char *ptrTmp = NULL;
int i=0;
FILE *fp;
if(pAscin == NULL)
return FALSE;
if(strstr(pAscin , "log record") == NULL)
return FALSE;
ptr = strstr(pAscin , "-f");
if(ptr == NULL)
return FALSE;
memset(fileName , 0 , FILENAMELEN);
ptr = ptr+2;
while(*ptr != '\n')
{
if(*ptr != ' ')
{
ptrTmp = ptr;
break;
}
ptr++;
}
if(ptrTmp == NULL)
return FALSE;
while(*ptr != '\0')
{
ptr++;
i++;
if(i>=FILENAMELEN)
break;
}
if(i>=FILENAMELEN)
return FALSE;
memcpy(fileName, ptrTmp , ptr-ptrTmp);
fp = fopen(fileName , "w+");
if(fp == NULL)
return FALSE;
fclose(fp);
return TRUE;
}
BOOL mgc_debug_write_file(char *msg , int len)
{
FILE *fp = NULL;
if(strlen(fileName) == 0)
return FALSE;
fp = fopen(fileName , "a");
if(fp == NULL)
return FALSE;
if(fwrite(msg, sizeof(char) , len , fp) < len)
return FALSE;
fclose(fp);
return TRUE;
}
int mgc_asciout_proc(BYTE *out_str)
{
int out_len;
out_len = strlen(out_str);
if (out_len + strlen(mgcAsciOutBuf) > MGC_MAX_ASCIIOUT_LEN - 2)
{
strcpy(mgcAsciOutBuf, out_str);
}
else
strcat(mgcAsciOutBuf, out_str);
return 1;
}
void mgc_log_all()
{
WORD i;
for (i = 0; i < MGC_MAX_NUM_OF_MG; i++)
mgc_mg_info_set_mon(i , TRUE);
for (i = 0; i < MGC_MAX_NUM_OF_PHY_PORT; i++)
mgc_phy_port_set_mon(i, TRUE);
for (i = 0; i < MGC_MAX_NUM_OF_CHNL; i++)
mgc_chnl_info_set_mon(i, TRUE);
}
void mgc_log_none()
{
WORD i;
for (i = 0; i < MGC_MAX_NUM_OF_MG; i++)
mgc_mg_info_set_mon(i , FALSE);
for (i = 0; i < MGC_MAX_NUM_OF_PHY_PORT; i++)
mgc_phy_port_set_mon(i, FALSE);
for (i = 0; i < MGC_MAX_NUM_OF_CHNL; i++)
mgc_chnl_info_set_mon(i, FALSE);
memset(fileName , 0 , FILENAMELEN);
}
void mgc_mon(void)
{
BYTE in_page, err_fg = 0;
BYTE *ascii_in_ptr = NULL;
BYTE *str_start = NULL;
WORD str_len;
WORD num;
// WORD mgNo, chlNo , portNo;
//PHY_PORT_INFO *pPhyPort;
//CHNL_INFO *pChnlInfo;
if ((str_len = strlen(mgcAsciInBuf)) > 0)
{
in_page = mgcAsciInBuf[0] - 1;
ascii_in_ptr = mgcAsciInBuf + 1;
if (in_page > 4)
err_fg = 1;
else if (strcmp(ascii_in_ptr,"log error on") == 0)
{
mgcMonitorFg = mgcMonitorFg | MGC_MONITOR_ERROR;
}
else if (strcmp(ascii_in_ptr,"log error off") == 0)
{
mgcMonitorFg = mgcMonitorFg & (~MGC_MONITOR_ERROR);
}
else if (strcmp(ascii_in_ptr,"log warn on") == 0)
{
mgcMonitorFg = mgcMonitorFg | MGC_MONITOR_WARN;
}
else if (strcmp(ascii_in_ptr,"log warn off") == 0)
{
mgcMonitorFg = mgcMonitorFg & (~MGC_MONITOR_WARN);
}
else if (strcmp(ascii_in_ptr,"log info on") == 0)
{
mgcMonitorFg = mgcMonitorFg | MGC_MONITOR_INFO;
}
else if (strcmp(ascii_in_ptr,"log info off") == 0)
{
mgcMonitorFg = mgcMonitorFg & (~MGC_MONITOR_INFO);
}
else if (strcmp(ascii_in_ptr,"log all") == 0)
{
mgcMonitorFg = MGC_MONITOR_ALL;
mgc_log_all();
}
else if (strcmp(ascii_in_ptr,"log none") == 0)
{
mgcMonitorFg = MGC_MONITOR_NONE;
mgc_log_none();
}
else if (strcmp(ascii_in_ptr,"help") == 0)
{
mgc_asciout_proc(log_help);
}
else if(strstr(ascii_in_ptr, "log record") != NULL)
{
if(mgc_debug_parse_log_file(ascii_in_ptr) == FALSE)
err_fg = 1;
}
else if(strstr(ascii_in_ptr, "print") != NULL)
{
if(mgc_debug_parse_print_info(ascii_in_ptr) == FALSE)
err_fg = 1;
}
#if 0
else if (strstr(ascii_in_ptr, "log mg") != NULL)
{
if ((str_start = strstr(ascii_in_ptr, "-")) != NULL)
{
mgNo = strtoul(str_start + 1, NULL, 10);
if (mgNo >= MGC_MAX_NUM_OF_MG)
err_fg = 1;
else if (strstr(ascii_in_ptr, "on") != NULL)
mgcMgInfo[mgNo].monFlag = 1;
else if (strstr(ascii_in_ptr, "off") != NULL)
mgcMgInfo[mgNo].monFlag = 0;
else
err_fg = 1;
}
else
err_fg = 1;
}
else if (strstr(ascii_in_ptr, "log port") != NULL)
{
if ((str_start = strstr(ascii_in_ptr, "-")) != NULL)
{
mgNo = strtoul(str_start + 1, NULL, 10);
if (mgNo >= MGC_MAX_NUM_OF_MG)
err_fg = 1;
if ((str_start = strstr(str_start + 1, "-")) != NULL)
{
portNo = strtoul(str_start + 1, NULL, 10);
if (portNo >= MGC_MAX_PHY_PORT_PER_MG)
err_fg = 1;
pPhyPort = mgc_phy_port_find_port_of_mg(&(mgcMgInfo[mgNo]), portNo);
if (pPhyPort == NULL)
err_fg = 2;
else
{
if (strstr(str_start + 1, "on") != NULL)
pPhyPort->monFlag = 1;
else if (strstr(ascii_in_ptr, "off") != NULL)
pPhyPort->monFlag = 0;
else
err_fg = 1;
}
}
}
else
err_fg = 1;
}
else if (strstr(ascii_in_ptr, "log chnl") != NULL)
{
if ((str_start = strstr(ascii_in_ptr, "-")) != NULL)
{
mgNo = strtoul(str_start + 1, NULL, 10);
if (mgNo >= MGC_MAX_NUM_OF_MG)
err_fg = 1;
if ((str_start = strstr(str_start + 1, "-")) != NULL)
{
portNo = strtoul(str_start + 1, NULL, 10);
if (portNo >= MGC_MAX_PHY_PORT_PER_MG)
err_fg = 1;
pPhyPort = mgc_phy_port_find_port_of_mg(&mgcMgInfo[mgNo], portNo);
if (pPhyPort == NULL)
err_fg = 2;
else
{
if ((str_start = strstr(str_start + 1, "-")) != NULL)
{
chlNo = strtoul(str_start + 1, NULL, 10);
pChnlInfo = mgc_chnl_info_find_chnl_of_phy(pPhyPort, chlNo);
if (strstr(str_start + 1, "on") != NULL)
pChnlInfo->monFlag = 1;
else if (strstr(ascii_in_ptr, "off") != NULL)
pChnlInfo->monFlag = 0;
else
err_fg = 1;
}
}
}
}
else
err_fg = 1;
}
#endif
else if (isdigit(ascii_in_ptr[0]))
{
num = strtoul(ascii_in_ptr, NULL, 10);
disp_page[in_page] = num;
mgc_disp_page(in_page);
}
else if ((str_start = strstr(ascii_in_ptr, ">")) != NULL)
{
num = strtoul(str_start + 1, NULL, 10);
disp_page[in_page] += num;
mgc_disp_page(in_page);
}
else if ((str_start = strstr(ascii_in_ptr, "<"))!= NULL)
{
num = strtoul(str_start + 1, NULL, 10);
disp_page[in_page] -= num;
mgc_disp_page(in_page);
}
else
err_fg = 1;
if (err_fg == 0)
mgc_asciout_proc("Command OK!\n\r");
else if (err_fg == 2)
mgc_asciout_proc("MG port not created!\n\r");
else
mgc_asciout_proc("Command Error!\n\r");
strcpy(mgcAsciInBuf, "\0");
}
}
int mgc_hex_to_ascii(BYTE *from_hex, BYTE from_len, BYTE *to_asc)
{
int i, j;
j = 0;
for (i = 0; i< from_len; i++)
{
to_asc[j] = ascii[from_hex[i] >> 4];
j++;
to_asc[j] = ascii[from_hex[i] & 0x0F];
j++;
to_asc[j] = ' ';
j++;
}
to_asc[j] = '\0';
return 1;
}
int mgc_log_err(char *err_msg)
{
if ((mgcMonitorFg & MGC_MONITOR_ERROR) == MGC_MONITOR_ERROR)
{
mgc_asciout_proc("\33[31m");
if (strlen(err_msg) >= MGC_MAX_ASCITMP_LEN)
sprintf(mgcAsciTempBuf, "log msg is too long!\n\r");
else
sprintf(mgcAsciTempBuf, "%s", err_msg);
strcat(mgcAsciTempBuf, "\33[37m");
mgc_asciout_proc(mgcAsciTempBuf);
}
return 1;
}
int mgc_log_warn(char *err_msg)
{
if ((mgcMonitorFg & MGC_MONITOR_WARN) == MGC_MONITOR_WARN)
{
mgc_asciout_proc("\33[33m");
if (strlen(err_msg) >= MGC_MAX_ASCITMP_LEN)
sprintf(mgcAsciTempBuf, "log msg is too long!\n\r");
else
sprintf(mgcAsciTempBuf, "%s", err_msg);
strcat(mgcAsciTempBuf, "\33[37m");
mgc_asciout_proc(mgcAsciTempBuf);
}
return 1;
}
int mgc_log_info(char *err_msg)
{
if ((mgcMonitorFg & MGC_MONITOR_INFO) == MGC_MONITOR_INFO)
{
mgc_asciout_proc("\33[32m");
if (strlen(err_msg) >= MGC_MAX_ASCITMP_LEN)
sprintf(mgcAsciTempBuf, "log msg is too long!\n\r");
else
sprintf(mgcAsciTempBuf, "%s", err_msg);
strcat(mgcAsciTempBuf, "\33[37m");
mgc_asciout_proc(mgcAsciTempBuf);
}
return 1;
}
int mgc_log_procedure(WORD mgNo, WORD portIndex, WORD chnlIndex, char *msg)
{
/*
BYTE monFlag = 0;
if ((mgNo < MGC_MAX_NUM_OF_MG) && (mgcMgInfo[mgNo].monFlag == 1))
monFlag = 1;
else if ((portIndex < MGC_MAX_NUM_OF_PHY_PORT) && (mgcPhyPort[portIndex].monFlag == 1))
monFlag = 1;
else if ((chnlIndex < MGC_MAX_NUM_OF_CHNL) && (mgcChnl[chnlIndex].monFlag == 1))
monFlag = 1;
if (monFlag == 1)
{
if (strlen(msg) >= MGC_MAX_ASCITMP_LEN)
sprintf(mgcAsciTempBuf, "log msg is too long!\n\r");
else
sprintf(mgcAsciTempBuf, "%s\n\r", msg);
mgc_asciout_proc(mgcAsciTempBuf);
return 0;
}
*/
return -1;
}
#ifndef MGC_TEST_DEBUG
void MGC_DEBUG(char *msg,...)
{
char printedMessage[MGC_MAX_LINE_LENGTH];
char* ptr;
va_list v;
ptr = printedMessage;
memset(ptr , 0 , MGC_MAX_LINE_LENGTH);
sprintf(ptr, "DEBUG:");
ptr = ptr+strlen(ptr);
/* Format the given line with the arguments */
va_start(v, msg);
vsprintf(ptr, msg, v);
va_end(v);
ptr = ptr+strlen(ptr);
sprintf(ptr, "\r\n");
ptr = printedMessage;
if((mgcMonitorFg&MGC_MONITOR_DEBUG) != MGC_MONITOR_DEBUG)
return;
mgc_debug_write_file(ptr, strlen(ptr));
mgc_asciout_proc(ptr);
return;
}
void MGC_WARN(char *msg,...)
{
char printedMessage[MGC_MAX_LINE_LENGTH];
char* ptr;
va_list v;
ptr = printedMessage;
memset(ptr , 0 , MGC_MAX_LINE_LENGTH);
sprintf(ptr, "WARN:");
ptr = ptr+strlen(ptr);
/* Format the given line with the arguments */
va_start(v, msg);
vsprintf(ptr, msg, v);
va_end(v);
ptr = ptr+strlen(ptr);
sprintf(ptr, "\r\n");
ptr = printedMessage;
if((mgcMonitorFg&MGC_MONITOR_WARN) != MGC_MONITOR_WARN)
return;
mgc_debug_write_file(ptr, strlen(ptr));
mgc_log_warn(ptr);
return;
}
void MGC_INFO(char *msg,...)
{
char printedMessage[MGC_MAX_LINE_LENGTH];
char* ptr;
va_list v;
ptr = printedMessage;
memset(ptr , 0 , MGC_MAX_LINE_LENGTH);
sprintf(ptr, "INFO:");
ptr = ptr+strlen(ptr);
/* Format the given line with the arguments */
va_start(v, msg);
vsprintf(ptr, msg, v);
va_end(v);
ptr = ptr+strlen(ptr);
sprintf(ptr, "\r\n");
ptr = printedMessage;
if((mgcMonitorFg&MGC_MONITOR_INFO) != MGC_MONITOR_INFO)
return;
mgc_debug_write_file(ptr, strlen(ptr));
mgc_log_info(ptr);
return;
}
void MGC_ERROR(char *msg,...)
{
char printedMessage[MGC_MAX_LINE_LENGTH];
char* ptr;
va_list v;
ptr = printedMessage;
memset(ptr , 0 , MGC_MAX_LINE_LENGTH);
sprintf(ptr, "ERROR:");
ptr = ptr+strlen(ptr);
/* Format the given line with the arguments */
va_start(v, msg);
vsprintf(ptr, msg, v);
va_end(v);
ptr = ptr+strlen(ptr);
sprintf(ptr, "\r\n");
ptr = printedMessage;
if((mgcMonitorFg&MGC_MONITOR_ERROR) != MGC_MONITOR_ERROR)
return;
mgc_debug_write_file(ptr, strlen(ptr));
mgc_log_err(ptr);
return;
}
#endif

View File

@@ -0,0 +1,377 @@
/*
*********************************************************************************
* *
* NOTICE: *
* *
*********************************************************************************
*/
/*********************************************************************************
* <mgc_interanl.c>
* This file should is internal interface to do misc operation. So far, only AUEP is used
* Author Date
* ------ ------
* Sam Yao Aug 2008
*********************************************************************************/
/*-----------------------------------------------------------------------*/
/* INCLUDE HEADER FILES */
/*-----------------------------------------------------------------------*/
#include "./include/mgc_internal.h"
#include "./include/mgc_debug.h"
#include "./include/mgc_mg_info.h"
static MGC_INTERNAL_SAP mgcItlSap;
static ITL_OPERA_STRUCT opera[ITL_OPERA_NUM];
extern int mgc_update_phy_port_status(CHNL chnl, BOOL status);
extern int mgc_auep_chnl(WORD usrPort, CHNL chnl);
void mgc_internal_opera_init(ITL_OPERA_STRUCT *pOpera , int usrPort);
BOOL mgc_internal_get_local_ip(char *ipAddr)
{
struct hostent *host;
char localName[50];
if(ipAddr == NULL)
return FALSE;
if (gethostname(localName , 50) == -1)
{
return FALSE;
}
if ((host = gethostbyname(localName)) == NULL)
{
return FALSE;
}
sprintf(ipAddr, "%d.%d.%d.%d",
(BYTE)host->h_addr_list[0][0],
(BYTE)host->h_addr_list[0][1],
(BYTE)host->h_addr_list[0][2],
(BYTE)host->h_addr_list[0][3]);
return TRUE;
}
char *mgc_internal_print_opera_id(MGC_MG_OPER_ID_TYPE operaId)
{
switch(operaId)
{
case MGC_OPER_ID_CONNECT_CHNL:
return "MGC_OPER_ID_CONNECT_CHNL";
case MGC_OPER_ID_CONNECT_DTMF:
return "MGC_OPER_ID_CONNECT_DTMF";
case MGC_OPER_ID_CONNECT_TONE:
return "MGC_OPER_ID_CONNECT_TONE";
case MGC_OPER_ID_CRCX:
return "MGC_OPER_ID_CRCX";
case MGC_OPER_ID_MDCX:
return "MGC_OPER_ID_MDCX";
case MGC_OPER_ID_DLCX:
return "MGC_OPER_ID_DLCX";
case MGC_OPER_ID_RQNT:
return "MGC_OPER_ID_RQNT";
case MGC_OPER_ID_AUEP:
return "MGC_OPER_ID_AUEP";
case MGC_OPER_ID_CONNECT_AAS:
return "MGC_OPER_ID_CONNECT_AAS";
case MGC_OPER_ID_UNDEF:
return "MGC_OPER_ID_UNDEF";
case MGC_OPER_ID_IND:
return "MGC_OPER_ID_IND";
case MGC_OPER_ID_TANDEM_CREATE:
return "MGC_OPER_ID_TANDEM_CREATE";
case MGC_OPER_ID_TANDEM_CLEAR:
return "MGC_OPER_ID_TANDEM_CLEAR";
case MGC_OPER_ID_TANDEM_SET_TAR:
return "MGC_OPER_ID_TANDEM_SET_TAR";
case MGC_OPER_ID_TANDEM_UNSET_TAR:
return "MGC_OPER_ID_TANDEM_UNSET_TAR";
default:
break;
}
return "MGC_OPERA_ID_UNSUPPORTED";
}
int mgc_internal_get_sap_index(void)
{
return mgcItlSap.mgcSapIndex;
}
ITL_OPERA_STRUCT *mgc_internal_find_owne_opera(int usrPort)
{
ITL_OPERA_STRUCT *pOpera = NULL;
int i;
for(i=0; i<ITL_OPERA_NUM ; i++)
{
pOpera = &opera[i];
if(pOpera->userPort != usrPort)
continue;
return pOpera;
}
return NULL;
}
int mgc_internal_ind_callback(CHNL chnl, MGC_CMD_TYPE cmd, WORD *usrPort, WORD mgcPort, MEDIA_ATTR *mediaAttr)
{
return 0;
}
int mgc_internal_cnf_callback(WORD usrPort, WORD mgcPort, MGC_MG_OPER_ID_TYPE operId, MGC_OPER_RESULT success, WORD cause)
{
ITL_OPERA_STRUCT *pOpera = NULL;
MG_INFO *pMgInfo = NULL;
BOOL status = FALSE;
pOpera = mgc_internal_find_owne_opera(usrPort);
if(pOpera == NULL)
{
MGC_WARN("internal usrport[%d] lost owner" , usrPort);
return -1;
}
if(pOpera->status != ITL_OPERA_STATE_REQUEST)
{
mgc_internal_opera_init(pOpera, pOpera->userPort);
return -1;
}
// MGC_DEBUG("opera[%d] operate %s" , pOpera->userPort , success?"success" : "failure");
switch(operId)
{
case MGC_OPER_ID_AUEP:
pMgInfo = mgc_mg_info_get_index_mg(pOpera->chnl.mgNo);
if(success == MGC_OPER_SUCCESS)
{
status = TRUE;
}
mgc_mg_info_update_mg_status(pMgInfo, status);
mgc_delete_port(mgc_internal_get_sap_index(), pOpera->chnl.mgNo, pOpera->chnl.portNo);
break;
default:
MGC_WARN("internal opera do not support %s" , mgc_internal_print_opera_id(operId));
break;
}
mgc_internal_opera_init(pOpera, pOpera->userPort);
return 0;
}
ITL_OPERA_STRUCT *mgc_internal_get_idle_opera(void)
{
ITL_OPERA_STRUCT *pOpera = NULL;
int i;
for(i=0 ; i<ITL_OPERA_NUM ; i++)
{
pOpera = &opera[i];
if(pOpera->status != ITL_OPERA_STATE_IDLE)
continue;
return pOpera;
}
return NULL;
}
void mgc_internal_opera_init(ITL_OPERA_STRUCT *pOpera , int usrPort)
{
if(pOpera == NULL)
return;
pOpera->userPort = usrPort;
pOpera->status = ITL_OPERA_STATE_IDLE;
memset(&pOpera->chnl , 0 ,sizeof(CHNL));
return;
}
void mgc_internal_opera_clear(void)
{
int i;
ITL_OPERA_STRUCT *pOpera = NULL;
for(i=0 ; i<ITL_OPERA_NUM ; i++)
{
pOpera = &opera[i];
if(pOpera->status == ITL_OPERA_STATE_IDLE)
continue;
mgc_delete_port(mgc_internal_get_sap_index(), pOpera->chnl.mgNo, pOpera->chnl.portNo);
mgc_internal_opera_init(pOpera, pOpera->userPort);
}
return;
}
/***************************************************************************
* mgc_internal_opera_auep_request
* ------------------------------------------------------------------------
* General: inferace to be used for auep detection
* Return Value: if failure return FALSE, else return TRUE
* ------------------------------------------------------------------------
* Arguments:
* Input: pMgInfo - the pointer of the MG_INFO object which need to send auep
***************************************************************************/
BOOL mgc_internal_opera_auep_request(MG_INFO *pMgInfo)
{
ITL_OPERA_STRUCT *pOpera = NULL;
int i,ret;
PHY_PORT_INFO *pPhyPort = NULL;
if(pMgInfo == NULL)
return FALSE;
if((pMgInfo->created == FALSE)||(pMgInfo->mgAttr.ctrlType != MGC_MG_CTRL_TYPE_MGCP))
return FALSE;
if(pMgInfo->mgAttr.mgType ==MGC_MG_TYPE_INTERNAL)
{
pMgInfo->enable = TRUE;
return TRUE;
}
for(i=0 ; i< MGC_MAX_PHY_PORT_PER_MG ; i++)
{
pPhyPort = pMgInfo->pPhyPort[i];
pOpera = mgc_internal_get_idle_opera();
if(pOpera == NULL)
{
MGC_ERROR("internal opera is no more resource!");
mgc_internal_opera_clear();
continue;
}
if(pPhyPort == NULL)
continue;
if(pPhyPort->pMgcSap == NULL)
continue;
if(pPhyPort->pMgcSap->usrType != MGC_USER_TYPE_MGC)
continue;
ret = mgc_add_port(mgc_internal_get_sap_index(), pMgInfo->id, ITL_OPERA_PORT_NO , MGC_PHY_PORT_TYPE_E1);
if(ret < 0)
{
mgc_delete_port(mgc_internal_get_sap_index(),pMgInfo->id,ITL_OPERA_PORT_NO);
mgc_internal_opera_init(pOpera, pOpera->userPort);
return FALSE;
}
pOpera->chnl.mgNo = pMgInfo->id;
pOpera->chnl.portNo = ITL_OPERA_PORT_NO;
pOpera->chnl.chlNo = 0;
pOpera->chnl.connectNo = 0;
pOpera->status = ITL_OPERA_STATE_REQUEST;
if(MGC_RESULT_OK != mgc_auep_chnl(pOpera->userPort , pOpera->chnl))
mgc_internal_opera_init(pOpera, pOpera->userPort);
break;
}
return TRUE;
}
/***************************************************************************
* mgc_internal_sap_bind
* ------------------------------------------------------------------------
* General: inferace to be called in mgc_init
* Return Value: if failure return FALSE, else return TRUE
* ------------------------------------------------------------------------
* Arguments:
* Input: void
***************************************************************************/
BOOL mgc_internal_sap_bind(void)
{
MGC_INTERNAL_SAP *pSap = NULL;
ITL_OPERA_STRUCT *pOpera = NULL;
MGC_SAP *pMgcSap = NULL;
int ret , i;
pSap = &mgcItlSap;
if(pSap == NULL)
return FALSE;
pSap->mgcSapIndex = -1;
pMgcSap = &(pSap->mgcSap);
sprintf(pMgcSap->usrName , "%s" , "MGC_ITL_SAP");
pMgcSap->cnf_func = mgc_internal_cnf_callback;
pMgcSap->ind_func = mgc_internal_ind_callback;
pMgcSap->usrType = MGC_USER_TYPE_MGC;
ret = mgc_bind(pMgcSap);
if(ret < 0)
return FALSE;
pSap->mgcSapIndex = ret;
for(i=0 ; i<ITL_OPERA_NUM ; i++)
{
pOpera = &opera[i];
mgc_internal_opera_init(pOpera, i);
}
return TRUE;
}
/***************************************************************************
* mgc_internal_mg_create
* ------------------------------------------------------------------------
* General: inferace to be called in mgc_init to create internal mg
* Return Value: if failure return FALSE, else return TRUE
* ------------------------------------------------------------------------
* Arguments:
* Input: void
***************************************************************************/
BOOL mgc_internal_mg_create(void)
{
MGC_INTERNAL_SAP *pSap = NULL;
MG_ATTR mgAttr;
char localIp[33];
int ret;
pSap = &mgcItlSap;
if(pSap->mgcSapIndex < 0)
return FALSE;
memset(&mgAttr , 0 , sizeof(MG_ATTR));
mgAttr.mgType = MGC_MG_TYPE_INTERNAL;
mgAttr.ctrlType = MGC_MG_CTRL_TYPE_MGCP;
mgAttr.epDes = MGCP_EP_NAME_UNSTRUCTURED;
mgAttr.ptime = 20;
sprintf(mgAttr.domain , "InternalMG");
mgc_internal_get_local_ip(localIp);
mgAttr.ip = inet_addr(localIp);
ret = mgc_create_MG(pSap->mgcSapIndex , &mgAttr);
if(ret < 0)
return FALSE;
pSap->mgNoITL = ret;
ret = mgc_add_port(pSap->mgcSapIndex, pSap->mgNoITL , ITL_MG_INFO_PORT_NO , MGC_PHY_VIRTUAL_TYPE_INTERNAL);
if(ret < 0)
return FALSE;
return TRUE;
}

View File

@@ -0,0 +1,937 @@
/*
*********************************************************************************
* *
* NOTICE: *
* *
*********************************************************************************
*
*
*
* mgcSap <---------mgcPhyPorts --------> mgcMgInfo
*
*
*/
/*********************************************************************************
* <mgc_mg_info.c>
* This file should provide MG_INFO object APIs
*
* Author Date
* ------ ------
* Sam Yao Aug 2008
*********************************************************************************/
/*-----------------------------------------------------------------------*/
/* INCLUDE HEADER FILES */
/*-----------------------------------------------------------------------*/
#include "./include/mgc_mg_info.h"
#include "./include/mgc_phy_port.h"
#include "./include/mgc_8ecp.h"
#include "./include/mgc_internal.h"
#include "./include/mgc_chnl_info.h"
#include "./include/mgc_debug.h"
#include "./include/mgc_mgcp.h"
#include "./include/mgc_conn_info.h"
static MG_INFO mgcMgInfo[MGC_MAX_NUM_OF_MG];
extern int mgc_get_non_virtual_trk_status(MG_INFO *pMgInfo);
/*-----------------------------------------------------------------------
MG_INFO M A N A G E R
------------------------------------------------------------------------*/
/***************************************************************************
* mgc_mg_info_init
* ------------------------------------------------------------------------
* General: init MG_INFO structure objcet
* Return Value: void.
* ------------------------------------------------------------------------
* Arguments:
* Input: pMgInfo- the pointer of the MG_INFO object which should be init
* id - the id of the MG_INFO object
***************************************************************************/
void mgc_mg_info_init(MG_INFO *pMgInfo , int id)
{
int i;
if((pMgInfo == NULL)||(id < 0))
return ;
pMgInfo->id = id;
pMgInfo->requestId = 0;
pMgInfo->created = FALSE;
pMgInfo->enable = FALSE;
memset(&pMgInfo->mgAttr , 0 , sizeof(MG_ATTR));
pMgInfo->mgAttr.ctrlType = MGC_MG_CTRL_TYPE_UNDEF;
pMgInfo->mgAttr.mgType= MGC_MG_TYPE_UNDEF;
pMgInfo->auditTimer = 0;
for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
{
pMgInfo->pPhyPort[i] = NULL ;
}
return;
}
void mgc_mg_info_setup(void)
{
int i;
MG_INFO *pMgInfo = NULL;
for(i=0 ; i<MGC_MAX_NUM_OF_MG ;i++)
{
pMgInfo = &mgcMgInfo[i];
mgc_mg_info_init(pMgInfo, i);
}
return;
}
/***************************************************************************
* mgc_mg_info_clear
* ------------------------------------------------------------------------
* General: clear MG_INFO structure objcet
* Return Value: void.
* ------------------------------------------------------------------------
* Arguments:
* Input: pMgInfo- the pointer of the MG_INFO object which should be cleared
***************************************************************************/
void mgc_mg_info_clear(MG_INFO *pMgInfo)
{
int i;
PHY_PORT_INFO *pPhyPort = NULL;
for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
{
pPhyPort = pMgInfo->pPhyPort[i];
if(pPhyPort == NULL)
continue;
mgc_phy_port_clear(pPhyPort);
}
mgc_mg_info_init(pMgInfo, pMgInfo->id);
return;
}
/***************************************************************************
* mgc_mg_info_attached_phy_port_num
* ------------------------------------------------------------------------
* General: calculate how many phyPort is attached on the MG_INFO objec
* Return Value: the number of attached phyPort.
* ------------------------------------------------------------------------
* Arguments:
* Input: pMgInfo- the pointer of the MG_INFO object
***************************************************************************/
int mgc_mg_info_attached_phy_port_num(MG_INFO *pMgInfo)
{
int num , i;
if(pMgInfo == NULL)
return 0;
num = 0;
for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
{
if(pMgInfo->pPhyPort[i] != NULL)
num++;
}
return num;
}
/***************************************************************************
* mgc_mg_info_is_port_already_exist
* ------------------------------------------------------------------------
* General: check whether the phyport is already attached on this MG_INFO object
* Return Value: if already attached return TRUE, else return FALSE
* ------------------------------------------------------------------------
* Arguments:
* Input: pMgInfo- the pointer of the MG_INFO object
* portNo - the phyPort number
***************************************************************************/
BOOL mgc_mg_info_is_port_already_exist(MG_INFO *pMgInfo , int portNo , MGC_SAP *pSap)
{
int i;
if(pMgInfo == NULL)
return FALSE;
for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
{
if(pMgInfo->pPhyPort[i] == NULL)
continue;
if(pMgInfo->pPhyPort[i]->pMgcSap != pSap)
continue;
if(pMgInfo->pPhyPort[i]->portNo != portNo)
continue;
if(portNo != ITL_OPERA_PORT_NO)
{
MGC_WARN("mg[%d] already have Port[%d]" , pMgInfo->id , portNo);
}
return TRUE;
}
return FALSE;
}
/***************************************************************************
* mgc_mg_info_attach_phy_port
* ------------------------------------------------------------------------
* General: attach a phyport on the MG_INFO object
* Return Value: if failure return FALSE, else return TRUE
* ------------------------------------------------------------------------
* Arguments:
* Input: pMgInfo- the pointer of the MG_INFO object
* pPhyPort - the pointer of the phyPort
***************************************************************************/
BOOL mgc_mg_info_attach_phy_port(MG_INFO *pMgInfo , PHY_PORT_INFO *pPhyPort , MGC_SAP *pSap)
{
int i;
if((pMgInfo == NULL)||(pPhyPort == NULL))
return FALSE;
if(mgc_mg_info_is_port_already_exist(pMgInfo , pPhyPort->portNo , pSap) == TRUE)
return FALSE;
for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
{
if(pMgInfo->pPhyPort[i] != NULL)
continue;
pMgInfo->pPhyPort[i] = pPhyPort;
return TRUE;
}
return FALSE;
}
/***************************************************************************
* mgc_mg_info_dettach_phy_port
* ------------------------------------------------------------------------
* General: remove a phyport from the MG_INFO object
* Return Value: void
* ------------------------------------------------------------------------
* Arguments:
* Input: pMgInfo- the pointer of the MG_INFO object
* pPhyPort - the pointer of the phyPort
***************************************************************************/
void mgc_mg_info_dettach_phy_port(MG_INFO *pMgInfo , PHY_PORT_INFO *pPhyPort)
{
int i;
if((pMgInfo == NULL)||(pPhyPort == NULL))
return;
for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
{
if(pMgInfo->pPhyPort[i] != pPhyPort)
continue;
pMgInfo->pPhyPort[i] = NULL;
//MGC_DEBUG("mgcMgInfo[%d] dettach phyport[%d]" , pMgInfo->id , pPhyPort->id);
return;
}
return ;
}
/***************************************************************************
* mgc_mg_info_get_unused_mg
* ------------------------------------------------------------------------
* General: get unused MG_INFO object
* Return Value: if failure return FALSE, else return TRUE
* ------------------------------------------------------------------------
* Arguments:
* Input: void
***************************************************************************/
MG_INFO *mgc_mg_info_get_unused_mg(void)
{
int i;
MG_INFO *pMgInfo = NULL;
for(i=0 ; i<MGC_MAX_NUM_OF_MG ; i++)
{
pMgInfo = &mgcMgInfo[i];
if(pMgInfo->created == TRUE)
continue;
return pMgInfo;
}
return NULL;
}
/***************************************************************************
* mgc_mg_info_get_index_mg
* ------------------------------------------------------------------------
* General: get the pointer of the MG_INFO object by index
* Return Value: if failure return NULL , else return the pointer
* ------------------------------------------------------------------------
* Arguments:
* Input: index - index of the MG_INFO
***************************************************************************/
MG_INFO *mgc_mg_info_get_index_mg(int index)
{
if((index < 0)||(index >= MGC_MAX_NUM_OF_MG))
return NULL;
return &mgcMgInfo[index];
}
BOOL mgc_mg_info_check_codec_list(MG_INFO *pMgInfo)
{
int i;
MGC_CODEC_LIST codecList;
MGC_CODEC_LIST *pList = NULL;
if(pMgInfo == NULL)
return FALSE;
mgc_connect_codec_list_init(&codecList);
pList = &pMgInfo->mgAttr.codecList;
for(i = 0 ; i<pList->num ; i++)
{
if(mgc_mgcp_check_codec_valid(pList->codec[i]) != TRUE)
continue;
codecList.codec[codecList.num] = pList->codec[i];
codecList.num++;
}
if(pList->num != codecList.num)
{
MGC_WARN("mg[%d] codeclist rec wrong" , pMgInfo->id);
}
if(codecList.num > 0)
memcpy(pList , &codecList , sizeof(MGC_CODEC_LIST));
return TRUE;
}
/***************************************************************************
* mgc_mg_info_assign_attr
* ------------------------------------------------------------------------
* General: give MG_INFO object attribute
* Return Value: if failure return FALSE, else return TRUE
* ------------------------------------------------------------------------
* Arguments:
* Input: pMgInfo - the pointer of the MG_INFO object
* pMgAttr - the pointer of the attribute descprition
***************************************************************************/
BOOL mgc_mg_info_assign_attr(MG_INFO *pMgInfo , MG_ATTR *pMgAttr)
{
if((pMgInfo == NULL)||(pMgAttr == NULL))
return FALSE;
if(strlen(pMgAttr->domain) == 0)
return FALSE;
switch(pMgAttr->ctrlType)
{
case MGC_MG_CTRL_TYPE_8ECP:
mgc_8ecp_create(pMgInfo , pMgAttr);
break;
case MGC_MG_CTRL_TYPE_MGCP:
memcpy(&pMgInfo->mgAttr , pMgAttr , sizeof(MG_ATTR));
if(pMgInfo->mgAttr.auditTimer == 0)
{
pMgInfo->mgAttr.auditTimer = MGC_MGCF_TIMER_10S;
}
else
{
pMgInfo->mgAttr.auditTimer = pMgInfo->mgAttr.auditTimer*MGC_MGCF_TIMER_1S;
}
break;
default:
MGC_ERROR("unsupport ctrlType %d" , pMgAttr->ctrlType);
return FALSE;
}
mgc_mg_info_check_codec_list(pMgInfo);
pMgInfo->auditTimer = pMgInfo->mgAttr.auditTimer;
pMgInfo->created = TRUE;
return TRUE;
}
/***************************************************************************
* mgc_mg_info_state_check
* ------------------------------------------------------------------------
* General: check MG status
* Return Value: void
* ------------------------------------------------------------------------
* Arguments:
* Input: pMgInfo - the pointer of the MG_INFO object
***************************************************************************/
void mgc_mg_info_state_check(MG_INFO *pMgInfo)
{
if(pMgInfo == NULL)
return;
if(pMgInfo->created == FALSE)
return;
if(++pMgInfo->auditTimer < pMgInfo->mgAttr.auditTimer)
return;
switch(pMgInfo->mgAttr.ctrlType)
{
case MGC_MG_CTRL_TYPE_MGCP:
mgc_internal_opera_auep_request(pMgInfo);
mgc_get_non_virtual_trk_status(pMgInfo);
break;
case MGC_MG_CTRL_TYPE_8ECP:
break;
default:
break;
}
pMgInfo->auditTimer = 0;
return;
}
/***************************************************************************
* mgc_mg_info_update_mg_status
* ------------------------------------------------------------------------
* General: update MG_INFO object status
* Return Value: void
* ------------------------------------------------------------------------
* Arguments:
* Input: pMgInfo - the pointer of the MG_INFO object
* status - TRUE stand for enable, FALSE stand for disable
***************************************************************************/
void mgc_mg_info_update_mg_status(MG_INFO *pMgInfo , BOOL status)
{
int i;
PHY_PORT_INFO *pPhyPort = NULL;
if(pMgInfo == NULL)
return;
pMgInfo->enable = status;
if(pMgInfo->mgAttr.mgType == MGC_MG_TYPE_AudioCoder)
return;
for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
{
pPhyPort = pMgInfo->pPhyPort[i];
if(pPhyPort == NULL)
continue;
if(status == TRUE)
pPhyPort->status = MGC_PHY_PORT_STATUS_ON_LINE;
if(status == FALSE)
pPhyPort->status = MGC_PHY_PORT_STATUS_OFF_LINE;
}
return;
}
/***************************************************************************
* mgc_mg_info_check_mg_is_exsit
* ------------------------------------------------------------------------
* General: check MG_INFO object is already be created
* Return Value: if already created return the pointer , else return NULL
* ------------------------------------------------------------------------
* Arguments:
* Input: pMgAttr - the pointer of the MG attribute description
***************************************************************************/
MG_INFO *mgc_mg_info_check_mg_is_exsit(MG_ATTR *pMgAttr)
{
int i;
MG_INFO *pMgInfo= NULL;
if(pMgAttr == NULL)
return NULL;
for(i=0 ; i<MGC_MAX_NUM_OF_MG ; i++)
{
pMgInfo = &mgcMgInfo[i];
if(pMgInfo->created == FALSE)
continue;
if(strcmp(pMgInfo->mgAttr.domain , pMgAttr->domain) != 0)
continue;
if(pMgInfo->mgAttr.ip != pMgAttr->ip)
continue;
return pMgInfo;
}
return NULL;
}
/***************************************************************************
* mgc_mg_info_find_port_by_name
* ------------------------------------------------------------------------
* General: find the phyPort by mg name and local port
* Return Value: if failure return NUL , else return the pointer of the phyPort
* ------------------------------------------------------------------------
* Arguments:
* Input: name - the name of the mg
* localPort - the local MGCP port
***************************************************************************/
PHY_PORT_INFO *mgc_mg_info_find_port_by_name_and_portNo(char *name , BYTE portNo ,WORD localPort)
{
int i , j;
MG_INFO *pMgInfo = NULL;
PHY_PORT_INFO *pPhyPort = NULL;
MGC_USER_TYPE usrType ;
if(localPort == MGC_MG_NETWORK_PORT)
{
usrType = MGC_USER_TYPE_MG;
}
else if(localPort == MGC_MGC_NETWORK_PORT)
{
usrType = MGC_USER_TYPE_MGC;
}
else
{
return NULL;
}
for(i=0 ; i<MGC_MAX_NUM_OF_MG ; i++)
{
pMgInfo = &mgcMgInfo[i];
if(strcmp(pMgInfo->mgAttr.domain , name) != 0)
continue;
for(j=0 ; j<MGC_MAX_PHY_PORT_PER_MG ; j++)
{
pPhyPort = pMgInfo->pPhyPort[j];
if(pPhyPort == NULL)
continue;
if(pPhyPort->pMgcSap->usrType != usrType)
continue;
if(pPhyPort->portNo != portNo)
continue;
return pPhyPort;
}
}
return NULL;
}
PHY_PORT_INFO *mgc_mg_info_find_port_by_name(char *name ,WORD localPort)
{
int i , j;
MG_INFO *pMgInfo = NULL;
PHY_PORT_INFO *pPhyPort = NULL;
MGC_USER_TYPE usrType ;
if(localPort == MGC_MG_NETWORK_PORT)
{
usrType = MGC_USER_TYPE_MG;
}
else if(localPort == MGC_MGC_NETWORK_PORT)
{
usrType = MGC_USER_TYPE_MGC;
}
else
{
return NULL;
}
for(i=0 ; i<MGC_MAX_NUM_OF_MG ; i++)
{
pMgInfo = &mgcMgInfo[i];
if(strcmp(pMgInfo->mgAttr.domain , name) != 0)
continue;
for(j=0 ; j<MGC_MAX_PHY_PORT_PER_MG ; j++)
{
pPhyPort = pMgInfo->pPhyPort[j];
if(pPhyPort == NULL)
continue;
if(pPhyPort->pMgcSap->usrType != usrType)
continue;
return pPhyPort;
}
}
return NULL;
}
MG_INFO *mgc_mg_info_find_mg_by_name(char *name)
{
int i ;
MG_INFO *pMgInfo = NULL;
for(i=0 ; i<MGC_MAX_NUM_OF_MG ; i++)
{
pMgInfo = &mgcMgInfo[i];
if(strcmp(pMgInfo->mgAttr.domain , name) != 0)
continue;
return pMgInfo;
}
return NULL;
}
/***************************************************************************
* mgc_mg_info_find_available_mg
* ------------------------------------------------------------------------
* General: find a MG_INFO object which is enabled according to the mgType
* Return Value: if failure return NUL , else return the pointer of the MG_INFO object
* ------------------------------------------------------------------------
* Arguments:
* Input: mgType - the Type of MG
***************************************************************************/
MG_INFO *mgc_mg_info_find_available_mg(MGC_MG_TYPE mgType)
{
int i;
MG_INFO *pMgInfo = NULL;
if(mgType == MGC_MG_TYPE_UNDEF)
return NULL;
for(i=0 ; i<MGC_MAX_NUM_OF_MG ; i++)
{
pMgInfo = &mgcMgInfo[i];
if(pMgInfo->mgAttr.mgType != mgType)
continue;
if(pMgInfo->enable == FALSE)
continue;
return pMgInfo;
}
return NULL;
}
/***************************************************************************
* mgc_mg_info_assign_idle_connection
* ------------------------------------------------------------------------
* General: assign a idle connection of the specific MG_INFO objcet
* Return Value: if failure return NUL , else return the pointer of the connection
* ------------------------------------------------------------------------
* Arguments:
* Input: pMgInfo - the pointer of the MG_INFO
***************************************************************************/
CONNECT_INFO *mgc_mg_info_assign_idle_connection(MG_INFO *pMgInfo)
{
int i;
PHY_PORT_INFO *pPhyPort = NULL;
CONNECT_INFO *pConnect = NULL;
if(pMgInfo == NULL)
return NULL;
for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
{
pPhyPort = pMgInfo->pPhyPort[i];
if(pPhyPort == NULL)
continue;
pConnect = mgc_phy_port_assign_idle_connection(pPhyPort);
if(pConnect == NULL)
continue;
return pConnect;
}
return NULL;
}
/***************************************************************************
* mgc_mg_info_find_idle_chnl_info
* ------------------------------------------------------------------------
* General: find a idle chnl which is not attached by any connection in the specific MG_INFO object
* Return Value: if failure return NUL , else return the pointer of the CHNL_INFO
* ------------------------------------------------------------------------
* Arguments:
* Input: pMgInfo - the pointer of the MG_INFO
***************************************************************************/
CHNL_INFO *mgc_mg_info_find_idle_chnl_info(MG_INFO *pMgInfo)
{
int i;
PHY_PORT_INFO *pPhyPort = NULL;
CHNL_INFO *pChnlInfo = NULL;
if(pMgInfo == NULL)
return NULL;
for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
{
pPhyPort = pMgInfo->pPhyPort[i];
if(pPhyPort == NULL)
continue;
pChnlInfo = mgc_phy_port_find_idle_chnl(pPhyPort);
if(pChnlInfo == NULL)
continue;
return pChnlInfo;
}
return NULL;
}
/***************************************************************************
* mgc_mg_info_assign_aas_tone_connection
* ------------------------------------------------------------------------
* General: assign a idle connection according to the Tone
* Return Value: if failure return NUL , else return the pointer of the connection
* ------------------------------------------------------------------------
* Arguments:
* Input: toneNo - tone id
***************************************************************************/
CONNECT_INFO *mgc_mg_info_assign_aas_tone_connection(BYTE toneNo)
{
int i;
MG_INFO *pMgInfo = NULL;
CHNL_INFO *pChnlInfo = NULL;
PHY_PORT_INFO *pPhyPort = NULL;
CONNECT_INFO *pConnect = NULL;
pMgInfo = mgc_mg_info_find_available_mg(MGC_MG_TYPE_ANN);
if(pMgInfo == NULL)
return NULL;
for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
{
pPhyPort = pMgInfo->pPhyPort[i];
if(pPhyPort == NULL)
continue;
if(pPhyPort->pMgcSap->usrType != MGC_USER_TYPE_MGC)
continue;
break;
}
if(pPhyPort == NULL)
return NULL;
pChnlInfo = mgc_chnl_info_find_chnl_of_phy(pPhyPort, toneNo);
if(pChnlInfo == NULL)
return NULL;
pConnect = mgc_chnl_info_assign_idle_connect(pChnlInfo);
if(pConnect == NULL)
return NULL;
MGC_DEBUG("aas phyPort[%d] assign chnl[%d] conn[%d] to send tone" , pPhyPort->id, toneNo, pConnect->id);
return pConnect;
}
void mgc_mg_info_set_mon(int id , BOOL enable )
{
MG_INFO *pMgInfo = NULL;
pMgInfo = mgc_mg_info_get_index_mg(id);
if(pMgInfo == NULL)
return;
pMgInfo->monFlag = enable;
}
BYTE *mgc_mg_info_get_res_addr(void)
{
return (BYTE *)mgcMgInfo;
}
static char *mgc_mg_info_print_mg_type(MGC_MG_TYPE type)
{
switch(type)
{
case MGC_MG_TYPE_INTERNAL:
return "MGC_MG_TYPE_INTERNAL";
case MGC_MG_TYPE_AudioCoder:
return "MGC_MG_TYPE_AudioCoder";
case MGC_MG_TYPE_LGC_MG:
return "MGC_MG_TYPE_LGC_MG";
case MGC_MG_TYPE_SSW_CSS:
return "MGC_MG_TYPE_SSW_CSS";
case MGC_MG_TYPE_IPBSS:
return "MGC_MG_TYPE_IPBSS";
case MGC_MG_TYPE_ANALOG:
return "MGC_MG_TYPE_ANALOG";
case MGC_MG_TYPE_TANDEM:
return "MGC_MG_TYPE_TANDEM";
case MGC_MG_TYPE_ANN:
return "MGC_MG_TYPE_ANN";
default:
break;
}
return "MGC_MG_TYPE_UNDEF";
}
static char *mgc_mg_info_print_ip(DWORD addr)
{
struct sockaddr_in sin;
sin.sin_addr.s_addr = addr;
return ((char *) inet_ntoa(sin.sin_addr) );
}
static char *mgc_mg_info_print_ctl_type(MGC_MG_CTRL_TYPE ctlType)
{
switch(ctlType)
{
case MGC_MG_CTRL_TYPE_MGCP:
return "MGC_MG_CTRL_TYPE_MGCP";
case MGC_MG_CTRL_TYPE_8ECP:
return "MGC_MG_CTRL_TYPE_8ECP";
default:
break;
}
return "MGC_MG_CTRL_TYPE_UNDEF";
}
static char *mgc_mg_info_print_codec_list(MGC_CODEC_LIST codecList)
{
int i;
static char buf[256];
memset(buf , 0 ,256);
for(i=0 ; i<codecList.num ; i++)
{
strcat(buf, mgc_mgcp_print_vc_codec(codecList.codec[i]));
strcat(buf, " ");
if(strlen(buf) >= 255)
break;
}
return buf;
}
void mgc_mg_info_print_info(MG_INFO *pMgInfo)
{
MG_ATTR *pAttr;
int i;
PHY_PORT_INFO *pPhyPort;
if(pMgInfo == NULL)
return;
if(pMgInfo->created == FALSE)
{
MGC_INFO("mgInfo[%d] is not created! " , pMgInfo->id);
return;
}
pAttr = &pMgInfo->mgAttr;
MGC_INFO("--------mgInfo[%d] %s---------" , pMgInfo->id , pMgInfo->enable?"ENABLE":"DISABLE");
MGC_INFO("Domain : %s" , pAttr->domain);
MGC_INFO("Type : %s" , mgc_mg_info_print_mg_type(pAttr->mgType));
MGC_INFO("Ip : %s" , mgc_mg_info_print_ip(pAttr->ip));
MGC_INFO("CTL TYPE : %s" , mgc_mg_info_print_ctl_type(pAttr->ctrlType));
if(pAttr->epDes == MGCP_EP_NAME_UNSTRUCTURED)
{
MGC_INFO("epDes : MGCP_EP_NAME_UNSTRUCTURED");
}
else if(pAttr->epDes == MGCP_EP_NAME_STRUCTURED)
{
MGC_INFO("epDes : MGCP_EP_NAME_STRUCTURED");
}
else
{
MGC_INFO("epDes : MGCP_EP_NAME_UNKNOWN");
}
MGC_INFO("tonCap : %s" , (pAttr->toneCap == 1)?"ON":"OFF");
MGC_INFO("ptime : %d" , pAttr->ptime);
MGC_INFO("audit time : %ld" , pAttr->auditTimer);
MGC_INFO("e1cardNo : %d" , pAttr->e1cardNo);
MGC_INFO("maxPort : %d" , pAttr->maxPorts);
MGC_INFO("maxChnl : %d" , pAttr->maxChnls);
MGC_INFO("codelist len %d : %s" , pAttr->codecList.num , mgc_mg_info_print_codec_list(pAttr->codecList));
for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
{
pPhyPort = pMgInfo->pPhyPort[i];
if(pPhyPort == NULL)
continue;
if(pPhyPort->portNo == ITL_OPERA_PORT_NO)
continue;
mgc_phy_port_print(pPhyPort);
}
MGC_INFO("--------mgInfo[%d] end---------" , pMgInfo->id);
return;
}
#ifdef MGC_TEST_ENABLE
int mgc_mg_info_created_num(void)
{
int i , num;
MG_INFO *pMgInfo = NULL;
num = 0;
for(i=0 ; i<MGC_MAX_NUM_OF_MG ; i++)
{
pMgInfo = &mgcMgInfo[i];
if(pMgInfo->created)
num++;
}
return num;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,482 @@
/*
*********************************************************************************
* *
* NOTICE: *
* *
*********************************************************************************
*
*
*
* mgcSap <---------mgcPhyPorts --------> mgcMgInfo
*
*
*/
/*********************************************************************************
* <mgc_phy_port.c>
* This file should provide MG_INFO object APIs
*
* Author Date
* ------ ------
* Sam Yao Aug 2008
*********************************************************************************/
/*-----------------------------------------------------------------------*/
/* INCLUDE HEADER FILES */
/*-----------------------------------------------------------------------*/
#include "./include/mgc_phy_port.h"
#include "./include/mgc_debug.h"
#include "./include/mgc_chnl_info.h"
#include "./include/mgc_ctl.h"
#include "./include/mgc_mg_info.h"
#include "./include/mgc_internal.h"
static PHY_PORT_INFO mgcPhyPort[MGC_MAX_NUM_OF_PHY_PORT];
/*-----------------------------------------------------------------------
PHY_PORT_INFO M A N A G E R
------------------------------------------------------------------------*/
/***************************************************************************
* mgc_phy_port_init
* ------------------------------------------------------------------------
* General: init PHY_PORT_INFO structure objcet
* Return Value: void.
* ------------------------------------------------------------------------
* Arguments:
* Input: pPhyPort- the pointer of the PHY_PORT_INFO object which should be init
* id - the id of the MG_INFO object
***************************************************************************/
void mgc_phy_port_init(PHY_PORT_INFO *pPhyPort , int id)
{
int i;
if((pPhyPort == NULL)||(id < 0))
return;
pPhyPort->id = id;
pPhyPort->portNo = -1;
pPhyPort->monFlag = 0;
pPhyPort->status = MGC_PHY_PORT_STATUS_UNDEF;
pPhyPort->portType = MGC_PHY_PORT_TYPE_UNDEF;
pPhyPort->pMgInfo = NULL;
pPhyPort->pMgcSap= NULL;
pPhyPort->chnlNum = 0;
for(i=0 ; i<MGC_MAX_CHNL_NUM_PER_PHY ; i++)
{
pPhyPort->pChnlInfo[i] = NULL;
}
return;
}
void mgc_phy_port_setup(void)
{
int i;
PHY_PORT_INFO *pPhyPort;
for(i=0 ; i<MGC_MAX_NUM_OF_PHY_PORT ; i++)
{
pPhyPort = &mgcPhyPort[i];
mgc_phy_port_init(pPhyPort, i);
}
return;
}
/***************************************************************************
* mgc_phy_port_clear
* ------------------------------------------------------------------------
* General: clear PHY_PORT_INFO structure objcet
* Return Value: void.
* ------------------------------------------------------------------------
* Arguments:
* Input: pPhyPort- the pointer of the PHY_PORT_INFO object which should be init
***************************************************************************/
void mgc_phy_port_clear(PHY_PORT_INFO *pPhyPort)
{
int i;
CHNL_INFO *pChnlInfo = NULL;
if(pPhyPort == NULL)
return;
for(i=0 ; i<MGC_MAX_CHNL_NUM_PER_PHY ; i++)
{
pChnlInfo = pPhyPort->pChnlInfo[i];
if(pChnlInfo == NULL)
continue;
mgc_chnl_info_clear(pChnlInfo);
if(pPhyPort->pMgInfo->mgAttr.mgType != MGC_MG_TYPE_TANDEM)
mgc_ctl_chnl_remove_one();
}
mgc_phy_port_init(pPhyPort , pPhyPort->id);
}
/***************************************************************************
* mgc_phy_port_get_unused_phy
* ------------------------------------------------------------------------
* General: get unused PHY_PORT_INFO structure objcet
* Return Value: if failure return NULL , else return the pointer of the PHY_PORT_INFO object.
* ------------------------------------------------------------------------
* Arguments:
* Input: void
***************************************************************************/
PHY_PORT_INFO *mgc_phy_port_get_unused_phy(void)
{
int i;
PHY_PORT_INFO *pPhyPort = NULL;
for(i=0 ; i<MGC_MAX_NUM_OF_PHY_PORT ; i++)
{
pPhyPort = &mgcPhyPort[i];
if((pPhyPort->chnlNum == 0)&&(pPhyPort->pMgInfo == NULL))
return pPhyPort;
}
return NULL;
}
/***************************************************************************
* mgc_phy_port_set_chnl_num
* ------------------------------------------------------------------------
* General: set the chnl number of the phyport according to the portType
* Return Value: void
* ------------------------------------------------------------------------
* Arguments:
* Input: pPhyPort - the pointer of the PHY_PORT_INFO object
* portType - the type of the port
***************************************************************************/
void mgc_phy_port_set_chnl_num(PHY_PORT_INFO *pPhyPort , MGC_PHY_PORT_TYPE portType)
{
if(pPhyPort == NULL)
return;
switch(portType)
{
case MGC_PHY_PORT_TYPE_UNDEF:
pPhyPort->chnlNum = 0;
break;
case MGC_PHY_PORT_TYPE_ANALOG:
pPhyPort->chnlNum = MGC_CHNL_NUM_AALN_PER_PORT;
break;
case MGC_PHY_VIRTUAL_TYPE_ANN:
pPhyPort->chnlNum = MGC_CHNL_NUM_ANN_PER_TYPE;
break;
case MGC_PHY_VIRTUAL_TYPE_TANDEM:
pPhyPort->chnlNum = MGC_CHNL_NUM_TANDEM_PER_TYPE;
break;
case MGC_PHY_VIRTUAL_TYPE_INTERNAL:
pPhyPort->chnlNum = MGC_CHNL_NUM_INTERNAL_PER_PORT;
break;
case MGC_PHY_VIRTUAL_TYPE_SURVEILLANCE:
pPhyPort->chnlNum = MGC_CHNL_NUM_SERVEILLANCE_PER_TYPE;
default :
pPhyPort->chnlNum = MGC_CHNL_NUM_DS_PER_PORT;
break;
}
return;
}
/***************************************************************************
* mgc_phy_port_attach_chnl
* ------------------------------------------------------------------------
* General: attach chnls to the phyPort
* Return Value: if failure return FALSE , else return TRUE
* ------------------------------------------------------------------------
* Arguments:
* Input: pPhyPort - the pointer of the PHY_PORT_INFO object
***************************************************************************/
BOOL mgc_phy_port_attach_chnl(PHY_PORT_INFO *pPhyPort)
{
int i;
CHNL_INFO *pChnlInfo = NULL;
if(pPhyPort == NULL)
return FALSE;
for(i=0 ; i<pPhyPort->chnlNum ; i++)
{
pChnlInfo = mgc_chnl_info_get_unused_chnl();
if(pChnlInfo == NULL)
return FALSE;
if((mgc_ctl_is_chnl_full() == TRUE)&&(pPhyPort->pMgInfo->mgAttr.mgType != MGC_MG_TYPE_TANDEM))
return FALSE;
pPhyPort->pChnlInfo[i] = pChnlInfo;
if(mgc_chnl_info_attach_to_phy_port(pChnlInfo , pPhyPort) == FALSE)
return FALSE;
mgc_chnl_info_status_set(pChnlInfo , MGC_CHNL_INFO_STATUS_IDLE);
if(pPhyPort->pMgInfo->mgAttr.mgType != MGC_MG_TYPE_TANDEM)
mgc_ctl_chnl_add_one();
}
if(pPhyPort->chnlNum == 0)
{
MGC_ERROR("mg[%d]port[%d] not support type!" , pPhyPort->pMgInfo->id , pPhyPort->portNo);
return FALSE;
}
if(pPhyPort->portNo != ITL_OPERA_PORT_NO)
{
MGC_DEBUG("mg[%d]port[%d] ==> phyPort[%d] {chnlInfo[%d] ~ chnlInfo[%d]}" ,
pPhyPort->pMgInfo->id ,pPhyPort->portNo,pPhyPort->id , pPhyPort->pChnlInfo[0]->id, pPhyPort->pChnlInfo[pPhyPort->chnlNum-1]->id);
}
return TRUE;
}
/***************************************************************************
* mgc_phy_port_find_port_of_mg
* ------------------------------------------------------------------------
* General: find the phyPort in the MG accroding to the PortNo
* Return Value: if failure return NULL , else return the pointer of the PHY_PORT_INFO object
* ------------------------------------------------------------------------
* Arguments:
* Input: pMgInfo - the pointer of the MG
* portNo - the portNo of the phyPort
***************************************************************************/
PHY_PORT_INFO *mgc_phy_port_find_port_of_mg(MG_INFO *pMgInfo , int portNo)
{
int i;
PHY_PORT_INFO *pPhyPort = NULL;
if(pMgInfo == NULL)
return NULL;
for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
{
pPhyPort = pMgInfo->pPhyPort[i];
if(pPhyPort == NULL)
continue;
if(pPhyPort->portNo != portNo)
continue;
return pPhyPort;
}
return NULL;
}
/***************************************************************************
* mgc_phy_port_find_port_of_mg_by_index
* ------------------------------------------------------------------------
* General: find the phyPort in the MG accroding to the index
* Return Value: if failure return NULL , else return the pointer of the PHY_PORT_INFO object
* ------------------------------------------------------------------------
* Arguments:
* Input: pMgInfo - the pointer of the MG
* index - index
***************************************************************************/
PHY_PORT_INFO *mgc_phy_port_find_port_of_mg_by_index(MG_INFO *pMgInfo , int index)
{
PHY_PORT_INFO *pPhyPort = NULL;
if(pMgInfo == NULL)
return NULL;
pPhyPort = pMgInfo->pPhyPort[index];
if(pPhyPort == NULL)
return NULL;
return pPhyPort;
}
/***************************************************************************
* mgc_phy_port_update_status
* ------------------------------------------------------------------------
* General: update phyPort status
* Return Value: void
* ------------------------------------------------------------------------
* Arguments:
* Input: pPhyPort - the pointer of the PHY_PORT_INFO object
* status - the status of the phyPort
***************************************************************************/
void mgc_phy_port_update_status(PHY_PORT_INFO *pPhyPort , BOOL status)
{
if(pPhyPort == NULL)
return;
if(status)
{
pPhyPort->status = MGC_PHY_PORT_STATUS_ON_LINE;
}
else
{
pPhyPort->status = MGC_PHY_PORT_STATUS_OFF_LINE;
}
return;
}
/***************************************************************************
* mgc_phy_port_find_idle_chnl
* ------------------------------------------------------------------------
* General: find a idle chnl in the phyPort
* Return Value: if failure return NULL , else return the pointer of the chnl
* ------------------------------------------------------------------------
* Arguments:
* Input: pPhyPort - the pointer of the PHY_PORT_INFO object
***************************************************************************/
CHNL_INFO *mgc_phy_port_find_idle_chnl(PHY_PORT_INFO *pPhyPort)
{
int i;
CHNL_INFO *pChnlInfo = NULL;
if(pPhyPort == NULL)
return NULL;
for(i=0 ; i<MGC_MAX_CHNL_NUM_PER_PHY ; i++)
{
pChnlInfo = pPhyPort->pChnlInfo[i];
if(pChnlInfo == NULL)
continue;
if(pChnlInfo->connectNum != 0)
continue;
return pChnlInfo;
}
return NULL;
}
/***************************************************************************
* mgc_phy_port_assign_idle_connection
* ------------------------------------------------------------------------
* General: find a idle connection in the phyPort
* Return Value: if failure return NULL , else return the pointer of the connction
* ------------------------------------------------------------------------
* Arguments:
* Input: pPhyPort - the pointer of the PHY_PORT_INFO object
***************************************************************************/
CONNECT_INFO *mgc_phy_port_assign_idle_connection(PHY_PORT_INFO *pPhyPort)
{
int i;
CHNL_INFO *pChnlInfo = NULL;
CONNECT_INFO *pConnect = NULL;
if(pPhyPort == NULL)
return NULL;
for(i=0 ; i<MGC_MAX_CHNL_NUM_PER_PHY ; i++)
{
pChnlInfo = pPhyPort->pChnlInfo[i];
if(pChnlInfo == NULL)
continue;
pConnect = mgc_chnl_info_assign_idle_connect(pChnlInfo);
if(pConnect == NULL)
continue;
return pConnect;
}
return NULL;
}
BYTE *mgc_phy_port_get_res_addr(void)
{
return (BYTE *)mgcPhyPort;
}
static char *mgc_phy_port_print_user_type(MGC_USER_TYPE type)
{
switch(type)
{
case MGC_USER_TYPE_MGC:
return "MGC_USER_TYPE_MGC";
case MGC_USER_TYPE_MG:
return "MGC_USER_TYPE_MG";
default :
break;
}
return "MGC_USER_TYPE_UNDEF";
}
void mgc_phy_port_print_chnl_info(PHY_PORT_INFO *pPhyPort)
{
int i;
CHNL_INFO *pChnlInfo;
if(pPhyPort == NULL)
return;
if((pPhyPort->portType != MGC_PHY_PORT_TYPE_E1)&&(pPhyPort->portType != MGC_PHY_PORT_TYPE_T1))
{
MGC_INFO("port type do not support!");
return;
}
MGC_INFO("%8s %10s %10s %10s %20s" , "ChnlNo", "Status", "Mode" , "Codec" , "LocalIP");
for(i=0 ; i<pPhyPort->chnlNum ; i++)
{
pChnlInfo = pPhyPort->pChnlInfo[i];
if(pChnlInfo == NULL)
continue;
MGC_INFO("chnl[%02d] %10s %10s %10s %20s",
i , mgc_chnl_info_print_status(pChnlInfo), mgc_chnl_info_print_mode(pChnlInfo),
mgc_chnl_info_print_codec(pChnlInfo), mgc_chnl_info_print_remote(pChnlInfo));
}
return;
}
void mgc_phy_port_print(PHY_PORT_INFO *pPhyPort)
{
if(pPhyPort == NULL)
return;
if((pPhyPort->pMgInfo == NULL)||(pPhyPort->pMgcSap == NULL) )
{
MGC_INFO("mgcPhyPort[%d] is not used!" , pPhyPort->id);
return;
}
MGC_INFO("mgInfo[%d]Port[%d] ==>> mgcPhyPort[%d] " , pPhyPort->pMgInfo->id , pPhyPort->portNo , pPhyPort->id);
MGC_INFO("mgInfo[%d]Port[%d] ==>> %s %s" ,
pPhyPort->pMgInfo->id , pPhyPort->portNo , pPhyPort->pMgcSap->usrName,mgc_phy_port_print_user_type(pPhyPort->pMgcSap->usrType));
MGC_INFO("mgInfo[%d]Port[%d] %s" , pPhyPort->pMgInfo->id , pPhyPort->portNo, (pPhyPort->status == MGC_PHY_PORT_STATUS_ON_LINE)?"on":"off");
mgc_phy_port_print_chnl_info(pPhyPort);
return;
}
int mgc_modify_port(BYTE sapIndex, WORD mgNo, BYTE portNo, BYTE portType)
{
MGC_ERROR("port modify is not support now!");
MGC_ERROR("Please delete first , and then re-add");
return -1;
}
void mgc_phy_port_set_mon(int id, BOOL enalbe)
{
if((id<0)||(id >= MGC_MAX_NUM_OF_PHY_PORT))
return;
mgcPhyPort[id].monFlag = enalbe;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,291 @@
#include "./include/mgc_port_list.h"
#include "./include/mgc_port_info.h"
#include "./include/mgc_debug.h"
#define MGC_MAX_NUM_OF_PORT_NODE (MGC_MAX_NUM_OF_PORT)
MGC_PORT_NODE mgcPortNode[MGC_MAX_NUM_OF_PORT_NODE];
MGC_PORT_LIST mgcPortActiveList;
static void mgc_port_list_node_init(MGC_PORT_NODE *pNode , int id)
{
if(pNode == NULL)
return;
pNode->id = id;
pNode->pPortInfo = NULL;
pNode->pPrior = NULL;
pNode->pNext = NULL;
pNode->pList = NULL;
return;
}
static void mgc_port_list_init(MGC_PORT_LIST *pList)
{
if(pList == NULL)
return;
pList->pHead = NULL;
pList->len = 0;
return;
}
static MGC_PORT_NODE *mgc_port_list_get_unused_node(void)
{
int i;
static int index = 0 ;
MGC_PORT_NODE *pNode = NULL;
MGC_PORT_NODE *pNodeTmp = NULL;
i = index;
do
{
i++;
if(i == MGC_MAX_NUM_OF_PORT_NODE)
i = 0;
pNode = &mgcPortNode[i];
if((pNode->pNext != NULL)||(pNode->pPrior != NULL))
continue;
if((pNode->pPortInfo != NULL)||(pNode->pList != NULL))
{
MGC_ERROR("mgcNode[%d] error rec" , pNode->id);
mgc_port_list_node_init(pNode, pNode->id);
continue;
}
pNodeTmp = pNode;
index = i;
break;
}while( i!=index);
return pNodeTmp;
}
void mgc_port_list_setup(void)
{
int i;
MGC_PORT_NODE *pNode = NULL;
for(i=0 ; i<MGC_MAX_NUM_OF_PORT_NODE ; i++)
{
pNode = &mgcPortNode[i];
mgc_port_list_node_init(pNode, i);
}
mgc_port_list_init(&mgcPortActiveList);
}
WORD mgc_port_list_get_len(MGC_PORT_LIST *pList)
{
if(pList == NULL)
return 0;
return pList->len;
}
MGC_PORT_NODE *mgc_port_list_get_tail(MGC_PORT_LIST *pList)
{
if((pList == NULL)||(pList->pHead == NULL))
return NULL;
return (pList->pHead->pPrior);
}
static BOOL mgc_port_list_add_node_to_list(MGC_PORT_LIST *pList , MGC_PORT_NODE *pNode)
{
MGC_PORT_NODE *pNodeTail;
if((pList == NULL)||(pNode == NULL))
return FALSE;
if(pList->pHead == NULL)
{
pList->pHead = pNode;
pList->pHead->pPrior = pNode;
pList->pHead->pNext = pNode;
pNode->pList = pList;
}
pNodeTail = mgc_port_list_get_tail(pList);
if(pNodeTail == NULL)
{
MGC_ERROR("lost portlist tail");
return FALSE;
}
pNode->pPrior = pNodeTail;
pNode->pNext = pNodeTail->pNext;
pNode->pList = pList;
pNodeTail->pNext = pNode;
pList->pHead->pPrior = pNode;
pList->len++;
return TRUE;
}
static MGC_PORT_NODE *mgc_port_list_find_port_in_active_list(PORT_INFO *pPortInfo)
{
MGC_PORT_NODE *pNode = NULL;
MGC_PORT_NODE *pNodeTmp = NULL;
MGC_PORT_NODE *pHead = NULL;
if(pPortInfo == NULL)
return NULL;
pHead = mgcPortActiveList.pHead;
if(pHead == NULL)
return NULL;
pNode = pHead;
do{
if(pNode->pPortInfo == pPortInfo)
{
pNodeTmp = pNode;
break;
}
pNode = pNode->pNext;
}while(pNode != pHead);
return pNodeTmp;
}
MGC_PORT_NODE *mgc_port_list_add_to_active_list(PORT_INFO *pPortInfo)
{
MGC_PORT_NODE *pNode = NULL;
if(pPortInfo == NULL)
return NULL;
pNode = mgc_port_list_find_port_in_active_list(pPortInfo);
if(pNode != NULL)
return pNode;
pNode = mgc_port_list_get_unused_node();
if(pNode == NULL)
{
MGC_ERROR("mgcPortNode is full!");
return NULL;
}
pNode->pPortInfo = pPortInfo;
if(mgc_port_list_add_node_to_list(&mgcPortActiveList, pNode) == FALSE)
{
mgc_port_list_node_init(pNode, pNode->id);
return NULL;
}
//MGC_DEBUG("mgcPort[%d] add to mgcPortNode[%d]" , pPortInfo->id , pNode->id);
return pNode;
}
static BOOL mgc_port_list_remove_node_from_list(MGC_PORT_LIST *pList , MGC_PORT_NODE *pNode)
{
MGC_PORT_NODE *pPrior = NULL;
MGC_PORT_NODE *pNext = NULL;
if((pList == NULL) || (pNode == NULL))
return FALSE;
if(pNode->pList != pList)
{
MGC_ERROR("mgcPortNode[%d] not belong to the list" , pNode->id);
return FALSE;
}
pPrior = pNode->pPrior;
pNext = pNode->pNext;
if((pPrior == NULL)||(pNext == NULL))
{
MGC_ERROR("mgcPortNode[%d] lost rec" , pNode->id);
return FALSE;
}
pPrior->pNext = pNext;
pNext->pPrior = pPrior;
pList->len--;
if(pList->pHead == pNode)
{
pList->pHead = pNext;
}
if((pPrior == pNode)&&(pNext == pNode))
{
pList->pHead = NULL;
}
mgc_port_list_node_init(pNode, pNode->id);
return TRUE;
}
BOOL mgc_port_list_remove_from_active_list(PORT_INFO *pPortInfo)
{
MGC_PORT_NODE *pNode = NULL;
if(pPortInfo == NULL)
return FALSE;
pNode = mgc_port_list_find_port_in_active_list(pPortInfo);
if(pNode == NULL)
{
MGC_ERROR("mgcPort[%d] is not in the active list" , pPortInfo->id);
return FALSE;
}
if(mgc_port_list_remove_node_from_list(&mgcPortActiveList, pNode) == FALSE)
return FALSE;
//MGC_DEBUG("mgcPort[%d] remove from mgcPortNode[%d]" , pPortInfo->id , pNode->id);
return TRUE;
}
void mgc_port_active_list_proc(void)
{
MGC_PORT_NODE *pNode = NULL;
MGC_PORT_NODE *pNodeTmp = NULL;
PORT_INFO *pPortInfo = NULL;
MGC_PORT_LIST *pList = &mgcPortActiveList;
if(pList->pHead == NULL)
return;
pNode = pList->pHead;
do{
pPortInfo = pNode->pPortInfo;
pNodeTmp = pNode;
pNode = pNode->pNext;
if(pPortInfo == NULL)
{
MGC_ERROR("mgcPortNode[%d] lost rec" , pNodeTmp->id);
mgc_port_list_remove_node_from_list(pNodeTmp->pList, pNodeTmp);
}
else
{
mgc_port_info_fsm(pNode->pPortInfo);
if(pPortInfo->assigned == FALSE)
mgc_port_list_remove_from_active_list(pPortInfo);
}
}while((pNode != pList->pHead)&&(pList->pHead != NULL));
return;
}

View File

@@ -0,0 +1,562 @@
#include "./include/mgc_sur_info.h"
#include "./include/mgc_debug.h"
#include "./include/mgc_mgcp.h"
#include "./include/mgc_conn_info.h"
#include "./include/mgc_chnl_info.h"
#include "./include/mgc_mg_info.h"
#include "./include/mgc_phy_port.h"
#include "./include/mgc_tandem_info.h"
static CONNECT_INFO mgcSurvillanceConn[MGC_MAX_NUM_OF_SURVEILLANCE_CONN];
static CHNL_INFO mgcSurvillianceChnl[MGC_MAX_NUM_OF_SURVEILLIANCE_CHNL];
static PHY_PORT_INFO mgcSurvilliancePort[MGC_MAX_NUM_OF_SURVEILLANCE_NUM];
static MGC_SUR_INFO_NODE mgcSurvillianceNode[MGC_MAX_NUM_OF_SURVEILLANCE_NODE];
extern MGC_SAP *mgc_sap_get_index_sap(int index);
static void mgc_sur_info_node_init(MGC_SUR_INFO_NODE *pNode , int id)
{
if(pNode == NULL)
return ;
pNode->id = id;
pNode->pConn = NULL;
pNode->pNext = NULL;
pNode->pPrior = NULL;
return;
}
static MGC_SUR_INFO_NODE *mgc_sur_info_get_unused_node(void)
{
int i;
static int index = 0;
MGC_SUR_INFO_NODE *pNode = NULL;
MGC_SUR_INFO_NODE *pNodeTmp = NULL;
i = index;
do
{
i++;
if(i == MGC_MAX_NUM_OF_SURVEILLANCE_NODE)
i = 0;
pNode = &mgcSurvillianceNode[i];
if(pNode->pConn != NULL)
continue;
index = i;
pNodeTmp = pNode;
break;
}while(i != index);
return pNodeTmp;
}
void mgc_sur_info_list_init(MGC_SUR_INFO_LIST *pList)
{
if(pList == NULL)
return ;
pList->len = 0;
pList->pHead = NULL;
return;
}
MGC_SUR_INFO_NODE *mgc_sur_info_get_list_tail(MGC_SUR_INFO_LIST *pList)
{
MGC_SUR_INFO_NODE *pNode = NULL;
MGC_SUR_INFO_NODE *pNodeHead = NULL;
if((pList == NULL)||(pList->pHead == NULL))
return NULL;
pNode = NULL;
pNodeHead = pList->pHead;
pNode = pNodeHead->pNext;
while(pNode->pNext != pNodeHead)
{
pNode = pNode->pNext;
}
return pNode;
}
MGC_SUR_INFO_NODE *mgc_sur_info_get_list_node(MGC_SUR_INFO_LIST *pList , WORD index)
{
MGC_SUR_INFO_NODE *pNode = NULL;
MGC_SUR_INFO_NODE *pNodeTmp = NULL;
int i;
if((pList == NULL) || (pList->pHead == NULL))
return NULL;
if(index >= pList->len)
{
MGC_WARN("list len %d <= %d" , pList->len , index);
return NULL;
}
i = 0;
pNode = pList->pHead;
do
{
if(i == index)
{
pNodeTmp = pNode;
break;
}
i++;
pNode = pNode->pNext;
}while(pNode != pList->pHead);
return pNodeTmp;
}
MGC_SUR_INFO_NODE *mgc_sur_info_find_conn_in_list(MGC_SUR_INFO_LIST *pList , CONNECT_INFO *pConn)
{
MGC_SUR_INFO_NODE *pNode = NULL;
BOOL result = FALSE;
if((pList == NULL)||(pConn == NULL)||(pList->pHead == NULL))
return NULL;
pNode = pList->pHead;
do
{
if(pNode->pConn == pConn)
{
result = TRUE;
//MGC_DEBUG("find conn[%d] in the list" , pConn->id);
break;
}
pNode = pNode->pNext;
}while(pNode != pList->pHead);
if(result == TRUE)
return pNode;
return NULL;
}
BOOL mgc_sur_info_add_conn_to_list(MGC_SUR_INFO_LIST *pList , CONNECT_INFO *pConn)
{
MGC_SUR_INFO_NODE *pNode = NULL;
MGC_SUR_INFO_NODE *pNodeTail = NULL;
if((pList == NULL)||(pConn == NULL))
return FALSE;
pNode = mgc_sur_info_get_unused_node();
if(pNode == NULL)
return FALSE;
pNode->pConn = pConn;
pNode->pPrior = pNode;
pNode->pNext = pNode;
if(pList->pHead == NULL)
pList->pHead = pNode;
pNodeTail = mgc_sur_info_get_list_tail(pList);
if(pNodeTail == NULL)
{
MGC_ERROR("lost list tail");
return FALSE;
}
pNode->pPrior = pNodeTail;
pNode->pNext = pNodeTail->pNext;
pNodeTail->pNext = pNode;
pList->pHead->pPrior = pNode;
pList->len++;
MGC_DEBUG("conn[%d] is add to node[%d] , list len %d" , pConn->id , pNode->id , pList->len);
return TRUE;
}
BOOL mgc_sur_info_remove_conn_to_list(MGC_SUR_INFO_LIST *pList , CONNECT_INFO *pConn)
{
MGC_SUR_INFO_NODE *pNode = NULL;
MGC_SUR_INFO_NODE *pPrior = NULL;
MGC_SUR_INFO_NODE *pNext = NULL;
if((pList == NULL)||(pConn == NULL)||(pList->pHead == NULL))
return FALSE;
pNode = mgc_sur_info_find_conn_in_list(pList, pConn);
if(pNode == NULL)
{
MGC_ERROR("conn[%d] is not find in the list" , pConn->id);
return FALSE;
}
pPrior = pNode->pPrior;
pNext = pNode->pNext;
pPrior->pNext = pNext;
pNext->pPrior = pPrior;
pList->len--;
if(pList->pHead == pNode)
{
pList->pHead = pNext;
}
if((pPrior == pNode)&&(pNext == pNode))
{
if(pList->len != 0)
{
MGC_DEBUG("list shoulde be empty, len %d" , pList->len);
}
pList->pHead = NULL;
}
MGC_DEBUG("conn[%d] is removed from node[%d] list len %d" , pConn->id , pNode->id , pList->len);
mgc_sur_info_node_init(pNode, pNode->id);
return TRUE;
}
void mgc_sur_info_clear_list(MGC_SUR_INFO_LIST *pList)
{
MGC_SUR_INFO_NODE *pNodeTail = NULL;
CONNECT_INFO *pConn = NULL;
MGCP_PARA mgcpPara;
if((pList == NULL)||(pList->pHead == NULL))
return ;
pNodeTail = mgc_sur_info_get_list_tail(pList);
while(pNodeTail != NULL)
{
pConn = pNodeTail->pConn;
if((mgc_connect_get_status(pConn) == MGC_CONNECT_STATUS_CREATED)||(mgc_connect_get_status(pConn) == MGC_CONNECT_STATUS_CREATE))
{
if(mgc_connect_dlcx_para_create(pConn , &mgcpPara) == TRUE)
MGCP_req(mgc_mgcp_get_sap_index(), MGCP_CMD_DLCX , 0xFFFF , &mgcpPara);
}
mgc_tandem_info_unset_conn(pConn->pTandem, pConn);
mgc_chnl_info_detach_connect(pConn->pChnlInfo, pConn);
mgc_connect_init(pConn, pConn->id);
mgc_sur_info_remove_conn_to_list(pList , pConn);
pNodeTail = mgc_sur_info_get_list_tail(pList);
}
if(pList->len != 0)
{
MGC_ERROR("list clear failed!");
}
return;
}
static CHNL_INFO *mgc_sur_info_get_unsed_chnl(void)
{
int i;
CHNL_INFO *pChnlInfo = NULL;
for(i=0 ; i<MGC_MAX_NUM_OF_CHNL ; i++)
{
pChnlInfo = &mgcSurvillianceChnl[i];
if(pChnlInfo->status != MGC_CHNL_INFO_STATUS_UNDEF)
continue;
return pChnlInfo;
}
return NULL;
}
static CONNECT_INFO *mgc_sur_info_get_unsed_conn(void)
{
int i;
CONNECT_INFO *pConnect = NULL;
for(i=0 ; i<MGC_MAX_NUM_OF_CON ; i++)
{
pConnect = &mgcSurvillanceConn[i];
if(pConnect->pChnlInfo != NULL)
continue;
return pConnect;
}
return NULL;
}
#if 0
static BOOL mgc_sur_info_add_conn_to_chnl(CHNL_INFO *pChnlInfo)
{
int i;
CONNECT_INFO *pConn;
if(pChnlInfo == NULL)
return FALSE;
for(i=0 ; i<pChnlInfo->maxConnectNum ; i++)
{
pConn = mgc_sur_info_get_unsed_conn();
if(pConn == NULL)
return FALSE;
if(mgc_chnl_info_attach_connect(pChnlInfo, pConn, i) == FALSE)
return FALSE;
//MGC_DEBUG("surConn[%d] add to chnlInfo[%d]", pConn->id , pChnlInfo->id);
}
return TRUE;
}
#endif
static BOOL mgc_sur_info_add_chnl_to_port(PHY_PORT_INFO *pPhyPort)
{
int i;
CHNL_INFO *pChnlInfo = NULL;
if(pPhyPort == NULL)
return FALSE;
for(i=0 ; i<pPhyPort->chnlNum ; i++)
{
pChnlInfo = mgc_sur_info_get_unsed_chnl();
if(pChnlInfo == NULL)
return FALSE;
pPhyPort->pChnlInfo[i] = pChnlInfo;
if(mgc_chnl_info_attach_to_phy_port(pChnlInfo , pPhyPort) == FALSE)
return FALSE;
// if(mgc_sur_info_add_conn_to_chnl(pChnlInfo) == FALSE)
// return FALSE;
mgc_chnl_info_status_set(pChnlInfo , MGC_CHNL_INFO_STATUS_IDLE);
//MGC_DEBUG("chnlInfo[%d] add to phyPort[%d]" , pChnlInfo->id, pPhyPort->id);
}
return TRUE;
}
static PHY_PORT_INFO *mgc_sur_info_get_unused_phy_port(void)
{
int i;
PHY_PORT_INFO *pPhyPort = NULL;
for(i=0 ; i<MGC_MAX_NUM_OF_PHY_PORT ; i++)
{
pPhyPort = &mgcSurvilliancePort[i];
if((pPhyPort->chnlNum == 0)&&(pPhyPort->pMgInfo == NULL))
return pPhyPort;
}
return NULL;
}
BOOL mgc_sur_info_add_survillance_res(BYTE sapIndex, WORD mgNo)
{
MG_INFO *pMgInfo;
MGC_SAP *pMgcSap;
int i;
BOOL result = FALSE;
PHY_PORT_INFO *pPhyPort = NULL;
pMgInfo = mgc_mg_info_get_index_mg(mgNo);
pMgcSap = mgc_sap_get_index_sap(sapIndex);
if((pMgInfo == NULL)||(pMgcSap == NULL))
return FALSE;
if(pMgInfo->mgAttr.mgType != MGC_MG_TYPE_TANDEM)
return FALSE;
pPhyPort = mgc_sur_info_get_unused_phy_port();
if(pPhyPort == NULL)
return FALSE;
for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
{
if(pMgInfo->pPhyPort[i] != NULL)
continue;
result = TRUE;
break;
}
if(result == FALSE)
{
MGC_DEBUG("mg[%d] is full of phyport" , pMgInfo->id);
return FALSE;
}
pPhyPort->portType = MGC_PHY_VIRTUAL_TYPE_SURVEILLANCE;
pPhyPort->portNo = i;
pPhyPort->pMgcSap = pMgcSap;
pPhyPort->pMgInfo = pMgInfo;
switch(pMgInfo->mgAttr.ctrlType)
{
case MGC_MG_CTRL_TYPE_MGCP:
mgc_phy_port_set_chnl_num(pPhyPort , pPhyPort->portType);
break;
default:
mgc_phy_port_clear(pPhyPort);
MGC_ERROR("mgcMgInfo[%d] unsupport ctrl type %d" , pMgInfo->id , pMgInfo->mgAttr.ctrlType);
return FALSE;
}
if(mgc_sur_info_add_chnl_to_port(pPhyPort) == FALSE)
{
mgc_phy_port_clear(pPhyPort);
return FALSE;
}
if(mgc_mg_info_attach_phy_port(pMgInfo , pPhyPort, pMgcSap)== FALSE)
{
mgc_phy_port_clear(pPhyPort);
return FALSE;
}
return TRUE;
}
void mgc_sur_info_setup(void)
{
int i;
CONNECT_INFO *pConn = NULL;
CHNL_INFO *pChnl = NULL;
PHY_PORT_INFO *pPhyPort = NULL;
MGC_SUR_INFO_NODE *pNode = NULL;
for(i=0; i<MGC_MAX_NUM_OF_SURVEILLANCE_CONN ; i++)
{
pConn = &mgcSurvillanceConn[i];
mgc_connect_init(pConn , i + MGC_SURVEILLIANCE_CONN_STAR_ID);
}
for(i=0 ; i<MGC_MAX_NUM_OF_SURVEILLANCE_NODE; i++)
{
pNode = &mgcSurvillianceNode[i];
mgc_sur_info_node_init(pNode, i);
}
for(i=0 ; i<MGC_MAX_NUM_OF_SURVEILLIANCE_CHNL; i++)
{
pChnl = &mgcSurvillianceChnl[i];
mgc_chnl_info_init(pChnl, i + MGC_SURVEILLIANCE_CHNL_STAR_ID);
}
for(i=0 ; i<MGC_MAX_NUM_OF_SURVEILLANCE_NUM ; i++)
{
pPhyPort = &mgcSurvilliancePort[i];
mgc_phy_port_init(pPhyPort, i+MGC_SURVEILLIANCE_PHY_PORT_STAR_ID);
}
}
static CONNECT_INFO *mgc_sur_info_find_unattached_conn_in_phy_port(PHY_PORT_INFO *pPhyPort)
{
int i,j;
CONNECT_INFO *pConnect = NULL;
CHNL_INFO *pChnlInfo = NULL;
if(pPhyPort == NULL)
return NULL;
for(i=0 ; i<pPhyPort->chnlNum ; i++)
{
pChnlInfo = pPhyPort->pChnlInfo[i];
if(pChnlInfo == NULL)
{
MGC_WARN("phyPort[%d] lost chnl[%d] info" , pPhyPort->id , i);
continue;
}
for(j=0 ; j<pChnlInfo->maxConnectNum ; j++)
{
pConnect = pChnlInfo->pConnection[j];
if(pConnect == NULL)
{
pConnect = mgc_sur_info_get_unsed_conn();
if(pConnect == NULL)
continue;
if(pConnect->pTandem != NULL)
{
MGC_WARN("surConn[%d] attached illegal tandem[%d]", pConnect->id, pConnect->pTandem->id);
mgc_connect_init(pConnect, pConnect->id);
continue;
}
if(mgc_chnl_info_attach_connect(pChnlInfo, pConnect, j) == FALSE)
continue;
return pConnect;
}
}
}
MGC_DEBUG("no unattached conn find in phyport[%d]" , pPhyPort->id);
return NULL;
}
CONNECT_INFO *mgc_sur_info_find_sur_conn_in_mg(MG_INFO *pMgInfo)
{
int i;
CONNECT_INFO *pConnect = NULL;
PHY_PORT_INFO *pPhyPort = NULL;
if((pMgInfo == NULL)||(pMgInfo->mgAttr.mgType != MGC_MG_TYPE_TANDEM))
return NULL;
for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
{
pPhyPort = pMgInfo->pPhyPort[i];
if(pPhyPort == NULL)
continue;
if(pPhyPort->portType != MGC_PHY_VIRTUAL_TYPE_SURVEILLANCE)
continue;
break;
}
if(pPhyPort == NULL)
{
MGC_ERROR("no surveillant port find in mg[%d]" , pMgInfo->id);
return NULL;
}
pConnect = mgc_sur_info_find_unattached_conn_in_phy_port(pPhyPort);
return pConnect;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
ClearCase CopyAreaDB|4
vobs\r9\plat\mgc_v2\ut
2
a
4:conf|2|0|0|0|9fc0c6dda0d911dd9cdb001c23e19543|0
3:obj|2|0|0|0|a950c865a0d911dd9cdb001c23e19543|0
d:CUnit-Run.xsl|1|11d70a4a4fc|1072|f098c142|9e90c6a5a0d911dd9cdb001c23e19543|0
b:mgc_v2_test|1|11d70a4a431|e4e69|dadd61f1|9c30c651a0d911dd9cdb001c23e19543|0
7:include|2|0|0|0|a190c731a0d911dd9cdb001c23e19543|0
d:CUnit-Run.dtd|1|11d70a4a1ff|596|1d497e8b|9b90c635a0d911dd9cdb001c23e19543|0
e:CUnit-List.xsl|1|11d70a4a4ae|f87|f6516bae|9d60c689a0d911dd9cdb001c23e19543|0
8:Makefile|1|11d70a4a52b|b72|2a5d4e7|9f20c6c1a0d911dd9cdb001c23e19543|0
d:mgc_v2_test.c|1|11d70a4a1d0|bdfe|e603ddac|9b00c619a0d911dd9cdb001c23e19543|0
e:CUnit-List.dtd|1|11d70a4a460|5bb|ad46941b|9cc0c66da0d911dd9cdb001c23e19543|0

View File

@@ -0,0 +1,26 @@
<!ELEMENT CUNIT_TEST_LIST_REPORT
(CUNIT_HEADER, CUNIT_LIST_TOTAL_SUMMARY, CUNIT_ALL_TEST_LISTING*, CUNIT_FOOTER)>
<!ELEMENT CUNIT_HEADER EMPTY>
<!ELEMENT CUNIT_LIST_TOTAL_SUMMARY (CUNIT_LIST_TOTAL_SUMMARY_RECORD*)>
<!ELEMENT CUNIT_LIST_TOTAL_SUMMARY_RECORD
(CUNIT_LIST_TOTAL_SUMMARY_RECORD_TEXT, CUNIT_LIST_TOTAL_SUMMARY_RECORD_VALUE)>
<!ELEMENT CUNIT_LIST_TOTAL_SUMMARY_RECORD_TEXT (#PCDATA)>
<!ELEMENT CUNIT_LIST_TOTAL_SUMMARY_RECORD_VALUE (#PCDATA)>
<!ELEMENT CUNIT_ALL_TEST_LISTING (CUNIT_ALL_TEST_LISTING_SUITE*|CUNIT_ALL_TEST_LISTING_GROUP*)>
<!ELEMENT CUNIT_ALL_TEST_LISTING_SUITE (CUNIT_ALL_TEST_LISTING_SUITE_DEFINITION, CUNIT_ALL_TEST_LISTING_SUITE_TESTS*)>
<!ELEMENT CUNIT_ALL_TEST_LISTING_SUITE_DEFINITION (SUITE_NAME, INITIALIZE_VALUE, CLEANUP_VALUE, TEST_COUNT_VALUE)>
<!ELEMENT SUITE_NAME (#PCDATA)>
<!ELEMENT INITIALIZE_VALUE (#PCDATA)>
<!ELEMENT CLEANUP_VALUE (#PCDATA)>
<!ELEMENT TEST_COUNT_VALUE (#PCDATA)>
<!ELEMENT CUNIT_ALL_TEST_LISTING_SUITE_TESTS (TEST_CASE_NAME*)>
<!ELEMENT TEST_CASE_NAME (#PCDATA)>
<!ELEMENT CUNIT_ALL_TEST_LISTING_GROUP (CUNIT_ALL_TEST_LISTING_GROUP_DEFINITION, CUNIT_ALL_TEST_LISTING_GROUP_TESTS*)>
<!ELEMENT CUNIT_ALL_TEST_LISTING_GROUP_DEFINITION (GROUP_NAME, INITIALIZE_VALUE, CLEANUP_VALUE, TEST_COUNT_VALUE)>
<!ELEMENT GROUP_NAME (#PCDATA)>
<!ELEMENT CUNIT_ALL_TEST_LISTING_GROUP_TESTS (TEST_CASE_NAME*)>
<!ELEMENT CUNIT_FOOTER (#PCDATA)>

View File

@@ -0,0 +1,119 @@
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="CUNIT_TEST_LIST_REPORT">
<html>
<head>
<title> CUnit - Logical Test Case Organization in Test Registry </title>
</head>
<body bgcolor="#e0e0f0">
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="CUNIT_HEADER">
<div align="center">
<h3> <b> CUnit - A Unit testing framework for C. </b>
<br/> <a href="http://cunit.sourceforge.net/"> http://cunit.sourceforge.net/ </a> </h3>
</div>
</xsl:template>
<xsl:template match="CUNIT_LIST_TOTAL_SUMMARY">
<p/>
<table align="center" width="50%">
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="CUNIT_LIST_TOTAL_SUMMARY_RECORD">
<tr>
<td bgcolor="#f0f0e0" width="70%">
<xsl:value-of select="CUNIT_LIST_TOTAL_SUMMARY_RECORD_TEXT" />
</td>
<td bgcolor="#f0e0e0" align="center">
<xsl:value-of select="CUNIT_LIST_TOTAL_SUMMARY_RECORD_VALUE" />
</td>
</tr>
</xsl:template>
<xsl:template match="CUNIT_ALL_TEST_LISTING">
<p/>
<div align="center"> <h2> Listing of All Tests </h2> </div>
<table align="center" width="90%">
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="CUNIT_ALL_TEST_LISTING_SUITE">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="CUNIT_ALL_TEST_LISTING_SUITE_DEFINITION">
<tr>
<td width="10%" bgcolor="#f0e0f0"> Suite </td>
<td width="20%" bgcolor="#e0f0f0" > <b> <xsl:value-of select="SUITE_NAME" /> </b> </td>
<td width="15%" bgcolor="#f0e0f0"> Initialize Function? </td>
<td width="5%" bgcolor="#e0f0f0"> <xsl:value-of select="INITIALIZE_VALUE" /> </td>
<td width="15%" bgcolor="#f0e0f0"> Cleanup Function? </td>
<td width="5%" bgcolor="#e0f0f0"> <xsl:value-of select="CLEANUP_VALUE" /> </td>
<td width="10%" bgcolor="#f0e0f0"> Test Count </td>
<td width="5%" bgcolor="#e0f0f0"> <xsl:value-of select="TEST_COUNT_VALUE" /> </td>
</tr>
</xsl:template>
<xsl:template match="CUNIT_ALL_TEST_LISTING_SUITE_TESTS">
<tr>
<td align="center" bgcolor="#e0f0d0"> Test Cases </td>
<td align="left" colspan="7" bgcolor="#e0e0d0">
<xsl:for-each select="TEST_CASE_NAME">
<xsl:apply-templates/><br />
</xsl:for-each>
</td> </tr>
<tr bgcolor="#00ccff"> <td colspan="8"> </td> </tr>
</xsl:template>
<xsl:template match="CUNIT_ALL_TEST_LISTING_GROUP">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="CUNIT_ALL_TEST_LISTING_GROUP_DEFINITION">
<tr>
<td width="10%" bgcolor="#f0e0f0"> Suite </td>
<td width="20%" bgcolor="#e0f0f0" > <b> <xsl:value-of select="GROUP_NAME" /> </b> </td>
<td width="15%" bgcolor="#f0e0f0"> Initialize Function? </td>
<td width="5%" bgcolor="#e0f0f0"> <xsl:value-of select="INITIALIZE_VALUE" /> </td>
<td width="15%" bgcolor="#f0e0f0"> Cleanup Function? </td>
<td width="5%" bgcolor="#e0f0f0"> <xsl:value-of select="CLEANUP_VALUE" /> </td>
<td width="10%" bgcolor="#f0e0f0"> Test Count </td>
<td width="5%" bgcolor="#e0f0f0"> <xsl:value-of select="TEST_COUNT_VALUE" /> </td>
</tr>
</xsl:template>
<xsl:template match="CUNIT_ALL_TEST_LISTING_GROUP_TESTS">
<tr>
<td align="center" bgcolor="#e0f0d0"> Test Cases </td>
<td align="left" colspan="7" bgcolor="#e0e0d0">
<xsl:for-each select="TEST_CASE_NAME">
<xsl:apply-templates/><br />
</xsl:for-each>
</td> </tr>
<tr bgcolor="#00ccff"> <td colspan="8"> </td> </tr>
</xsl:template>
<xsl:template match="CUNIT_FOOTER">
<p/>
<hr align="center" width="90%" color="red" />
<h5 align="center">
<xsl:apply-templates/>
</h5>
</xsl:template>
</xsl:stylesheet>

View File

@@ -0,0 +1,35 @@
<!ELEMENT CUNIT_TEST_RUN_REPORT
(CUNIT_HEADER, CUNIT_RESULT_LISTING, CUNIT_RUN_SUMMARY, CUNIT_FOOTER)>
<!ELEMENT CUNIT_HEADER EMPTY>
<!ELEMENT CUNIT_RESULT_LISTING (CUNIT_RUN_SUITE*|CUNIT_RUN_GROUP*)>
<!ELEMENT CUNIT_RUN_SUITE (CUNIT_RUN_SUITE_SUCCESS|CUNIT_RUN_SUITE_FAILURE)>
<!ELEMENT CUNIT_RUN_SUITE_SUCCESS (SUITE_NAME,CUNIT_RUN_TEST_RECORD*)>
<!ELEMENT CUNIT_RUN_SUITE_FAILURE (SUITE_NAME,FAILURE_REASON)>
<!ELEMENT SUITE_NAME (#PCDATA)>
<!ELEMENT FAILURE_REASON (#PCDATA)>
<!ELEMENT CUNIT_RUN_GROUP (CUNIT_RUN_GROUP_SUCCESS|CUNIT_RUN_GROUP_FAILURE)>
<!ELEMENT CUNIT_RUN_GROUP_SUCCESS (GROUP_NAME,CUNIT_RUN_TEST_RECORD*)>
<!ELEMENT CUNIT_RUN_GROUP_FAILURE (GROUP_NAME,FAILURE_REASON)>
<!ELEMENT GROUP_NAME (#PCDATA)>
<!ELEMENT CUNIT_RUN_TEST_RECORD (CUNIT_RUN_TEST_SUCCESS|CUNIT_RUN_TEST_FAILURE)>
<!ELEMENT CUNIT_RUN_TEST_SUCCESS (TEST_NAME)>
<!ELEMENT CUNIT_RUN_TEST_FAILURE (TEST_NAME, FILE_NAME, LINE_NUMBER, CONDITION)>
<!ELEMENT TEST_NAME (#PCDATA)>
<!ELEMENT FILE_NAME (#PCDATA)>
<!ELEMENT LINE_NUMBER (#PCDATA)>
<!ELEMENT CONDITION (#PCDATA)>
<!ELEMENT CUNIT_RUN_SUMMARY (CUNIT_RUN_SUMMARY_RECORD*)>
<!ELEMENT CUNIT_RUN_SUMMARY_RECORD (TYPE, TOTAL, RUN, SUCCEEDED, FAILED)>
<!ELEMENT TYPE (#PCDATA)>
<!ELEMENT TOTAL (#PCDATA)>
<!ELEMENT RUN (#PCDATA)>
<!ELEMENT SUCCEEDED (#PCDATA)>
<!ELEMENT FAILED (#PCDATA)>
<!ELEMENT CUNIT_FOOTER (#PCDATA)>

View File

@@ -0,0 +1,131 @@
<?xml version='1.0'?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="CUNIT_TEST_RUN_REPORT">
<html>
<head>
<title> CUnit - All Test Run Summary Report </title>
</head>
<body bgcolor="#e0e0f0">
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="CUNIT_HEADER">
<div align="center">
<h3> <b> CUnit - A Unit testing framework for C. </b>
<br/> <a href="http://cunit.sourceforge.net/"> http://cunit.sourceforge.net/ </a> </h3>
</div>
</xsl:template>
<xsl:template match="CUNIT_RESULT_LISTING">
<table cols="4" width="90%" align="center">
<tr>
<td width="25%"> </td>
<td width="25%"> </td>
<td width="25%"> </td>
<td width="25%"> </td>
</tr>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="CUNIT_RUN_SUITE">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="SUITE_NAME">
</xsl:template>
<xsl:template match="CUNIT_RUN_SUITE_SUCCESS">
<tr bgcolor="#f0e0f0">
<td colspan="4"> Running Suite <xsl:value-of select="SUITE_NAME"/> </td>
</tr>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="CUNIT_RUN_GROUP">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="CUNIT_RUN_GROUP_SUCCESS">
<tr bgcolor="#f0e0f0">
<td colspan="4"> Running Group <xsl:apply-templates/> </td>
</tr>
</xsl:template>
<xsl:template match="CUNIT_RUN_TEST_RECORD">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="CUNIT_RUN_TEST_SUCCESS">
<tr bgcolor="#e0f0d0">
<td> </td> <td colspan="2"> Running test <xsl:apply-templates/>... </td> <td bgcolor="#50ff50"> Passed </td>
</tr>
</xsl:template>
<xsl:template match="CUNIT_RUN_TEST_FAILURE">
<tr bgcolor="#e0f0d0">
<td> </td> <td colspan="2"> Running test <xsl:value-of select="TEST_NAME"/>... </td> <td bgcolor="#ff5050"> Failed </td>
</tr>
<tr>
<td colspan="4" bgcolor="#ff9090">
<table width="100%">
<tr> <th width="15%"> File Name </th> <td width="50%" bgcolor="#e0eee0"> <xsl:value-of select="FILE_NAME"/> </td> <th width="20%"> Line Number </th> <td width="10%" bgcolor="#e0eee0"> <xsl:value-of select="LINE_NUMBER"/> </td> </tr>
<tr> <th width="15%"> Condition </th> <td colspan="3" width="85%" bgcolor="#e0eee0"> <xsl:value-of select="CONDITION"/> </td> </tr>
</table>
</td>
</tr>
</xsl:template>
<xsl:template match="CUNIT_RUN_SUITE_FAILURE">
<tr>
<td colspan="3" bgcolor="#f0b0f0">Running Suite <xsl:value-of select="SUITE_NAME"/>... </td>
<td bgcolor="#ff7070"> <xsl:value-of select="FAILURE_REASON"/> </td>
</tr>
</xsl:template>
<xsl:template match="CUNIT_RUN_GROUP_FAILURE">
<tr>
<td colspan="3" bgcolor="#f0b0f0">Running Group <xsl:value-of select="GROUP_NAME"/>... </td>
<td bgcolor="#ff7070"> <xsl:value-of select="FAILURE_REASON"/> </td>
</tr>
</xsl:template>
<xsl:template match="CUNIT_RUN_SUMMARY">
<p/>
<table width="90%" rows="5" align="center">
<tr align="center" bgcolor="skyblue"> <th colspan="5"> Cumulative Summary for Run </th> </tr>
<tr>
<th width="20%" bgcolor="#ffffc0" align="center"> Type </th>
<th width="20%" bgcolor="#ffffc0" align="center"> Total </th>
<th width="20%" bgcolor="#ffffc0" align="center"> Run </th>
<th width="20%" bgcolor="#ffffc0" align="center"> Succeeded </th>
<th width="20%" bgcolor="#ffffc0" align="center"> Failed </th>
</tr>
<xsl:for-each select="CUNIT_RUN_SUMMARY_RECORD">
<tr align="center" bgcolor="lightgreen">
<td> <xsl:value-of select="TYPE" /> </td>
<td> <xsl:value-of select="TOTAL" /> </td>
<td> <xsl:value-of select="RUN" /> </td>
<td> <xsl:value-of select="SUCCEEDED" /> </td>
<td> <xsl:value-of select="FAILED" /> </td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="CUNIT_FOOTER">
<p/>
<hr align="center" width="90%" color="red" />
<h5 align="center">
<xsl:apply-templates/>
</h5>
</xsl:template>
</xsl:stylesheet>

100
omc/plat/mgc_v2/ut/Makefile Normal file
View File

@@ -0,0 +1,100 @@
##----------------------------------------------------------##
## ##
## Universal Makefile for module template : V1.6.3 ##
## ##
## Created : Wei Liu 07/04/11 ##
## Revision: [Last]Wei Liu 07/07/07 ##
## ##
##----------------------------------------------------------##
##---------------------------------------------------------------------##
##--------------------------------------
##
## Project correlation(Customer define)
##
##--------------------------------------
## MODULE= [Module Name]
## TYPE = app/plat => Module Type
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Debug ]
## DBUG_FLAGS_ADD = [Module Define Gcc Flags for Release]
## BUILD = lib/exef => Output file format
## CFG = debug/release => Build Configuration
## SRC_PATH = [Source file path]
## INC_PATH = [Include file path]
## APP_PATH = [App Module path]
## PLT_PATH = [Plat Module path]
## PLT_LIB = [Needed plat lib for Link] => just for test or wxc2main
## APP_LIB = [Needed app lib for Link] => just for test or wxc2main
## LIB_ADD = [Needed Extend lib for Link] => just for test or wxc2main
## PLT_LIB e.g. = haepub fsm mng proto kernel aif mgc mgcp sip rtp \
## 8ecp bicc smpp xapp tcap mtp3 m2ua \
## snmp iptrans debug sccp public
##
## APP_LIB e.g. = msc vlr ssf hlr ae pps mnp smsc vms aas
## LIB_ADD e.g. = -liba3a8 -lm
## OBJ_ADD = [Extend third party object files needed]
## TEST_OBJ_PATH = [module object files Path for test ] => just for test
##---------------------------------------------------------------------##
MODULE = mgc_v2_test
TYPE = plat
DBUG_FLAGS_ADD =
RELS_FLAGS_ADD =
##Default commonly as below
BUILD = exef
CFG = debug
PLT_LIB = mgcp debug snmp iptrans public sccp mtp3 rtp 8ecp
APP_LIB =
LIB_ADD = -lm -lcunit
SRC_PATH = ./
INC_PATH = ./
PLT_PATH = ../../../plat
APP_PATH = ../../../mss
OBJ_ADD =
TEST_OBJ_PATH =
PREPROC_CMD =
POSTPROC_CMD =
##---------------------------------------------------------------------##
##--------------------------------------
##
## Make configuration(Customer define)
##
##--------------------------------------
## CCFLAG_SWITCH = on/off => gcc flag show on/off
## COVER_NEED = yes/no => PTF cover report needed
## COVER_REPORT_PATH = [path ] => PTF cover report path
CCFLAG_SWITCH = off
COVER_NEED = no
COVER_REPORT_PATH = ./output
##---------------------------------------------------------------------##
##--------------------------------------
##
## include makefile.rules (Do not change)
##
##--------------------------------------
include Makefile.rules

View File

@@ -0,0 +1,6 @@
ClearCase CopyAreaDB|4
vobs\r9\plat\mgc_v2\ut\conf
2
2
c:iptrans.conf|1|11d70a4a615|227|b33f8c12|a0f0c715a0d911dd9cdb001c23e19543|0
9:menu_page|1|11d70a4a5e6|2ce|7a7341|a060c6f9a0d911dd9cdb001c23e19543|0

View File

@@ -0,0 +1,43 @@
#ipconfig for pps
#port=type,num,interface
#type=UDP/TCP
#num=0-6
#interface=BUFFER/DIRECT
4950=UDP,6,DIRECT
#SS7
4952=UDP,3,BUFFER
#MSC
4953=UDP,3,BUFFER
#VLR
4954=UDP,3,BUFFER
#SMSC
4955=UDP,3,BUFFER
#PPS
4956=UDP,3,BUFFER
#DEBUG
4957=UDP,4,BUFFER
#HEARTBEAT
4959=UDP,2,BUFFER
#IWF
4960=UDP,3,BUFFER
#OMC
4965=TCP,3,BUFFER
#DEBUG
4966=UDP,3,DIRECT
#MGCP_SERVER
4967=UDP,3,DIRECT
#MGCP_CLIENT
4968=UDP,2,BUFFER
#MSC GET
4969=UDP,3,BUFFER
#EIR
4970=UDP,3,BUFFER
#HLR
4971=UDP,2,BUFFER
#PPS
4972=UDP,2,BUFFER
#AUC
[port transfer]
4966=2727
4967=2427

View File

@@ -0,0 +1,17 @@
*******************
* MENU PAGE *
*******************
a -- IPTR m -- MNP
b -- MTP3 n -- DEBUG
c -- SCCP o -- AUC
d -- TCAP p -- SMPP
e -- XAPP r -- XUA
f -- MSC s -- BICC
g -- VLR t -- MGC
h -- SSF u -- GCP
i -- HLR v -- 8ECP
j -- SMSC w -- AIF
k -- PPS y -- ISUP
l -- SNMP z -- AAS

View File

@@ -0,0 +1,14 @@
ClearCase CopyAreaDB|4
vobs\r9\plat\mgc_v2\ut\include
2
a
9:CUError.h|1|11d70a4a895|13ee|f8001235|a820c849a0d911dd9cdb001c23e19543|0
b:Automated.h|1|11d70a4a7bb|800|13be81cf|a5b0c7d9a0d911dd9cdb001c23e19543|0
7:CUnit.h|1|11d70a4a6d0|494d|7d6cd6ab|a2c0c769a0d911dd9cdb001c23e19543|0
7:Basic.h|1|11d70a4a78c|7e4|6a018341|a480c7bda0d911dd9cdb001c23e19543|0
9:TestRun.h|1|11d70a4a73e|21e2|db012d57|a3f0c7a1a0d911dd9cdb001c23e19543|0
8:TestDB.h|1|11d70a4a838|3dd1|3bd3f2bd|a6e0c811a0d911dd9cdb001c23e19543|0
9:Console.h|1|11d70a4a7f9|6b2|95fb18d0|a650c7f5a0d911dd9cdb001c23e19543|0
a:CUCurses.h|1|11d70a4a867|6d1|ac3a22e3|a780c82da0d911dd9cdb001c23e19543|0
7:MyMem.h|1|11d70a4a70f|1001|e9410e14|a350c785a0d911dd9cdb001c23e19543|0
6:Util.h|1|11d70a4a692|b83|279b2ab|a220c74da0d911dd9cdb001c23e19543|0

View File

@@ -0,0 +1,63 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004,2005,2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Automated Interface (generates HTML Report Files).
*
* Feb 2002 Initial implementation (AK)
*
* 13/Feb/2002 Single interface to automated_run_tests. (AK)
*
* 20-Jul-2004 New interface, doxygen comments. (JDS)
*/
/** @file
* Automated testing interface with xml output (user interface).
*/
/** @addtogroup Automated
* @{
*/
#ifndef CUNIT_AUTOMATED_H_SEEN
#define CUNIT_AUTOMATED_H_SEEN
#include "CUnit.h"
#include "TestDB.h"
#ifdef __cplusplus
extern "C" {
#endif
CU_EXPORT void CU_automated_run_tests(void);
CU_EXPORT CU_ErrorCode CU_list_tests_to_file(void);
CU_EXPORT void CU_set_output_filename(const char* szFilenameRoot);
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Deprecated (version 1). @deprecated Use CU_automated_run_tests(). */
#define automated_run_tests() CU_automated_run_tests()
/** Deprecated (version 1). @deprecated Use CU_set_output_filename(). */
#define set_output_filename(x) CU_set_output_filename((x))
#endif /* USE_DEPRECATED_CUNIT_NAMES */
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_AUTOMATED_H_SEEN */
/** @} */

View File

@@ -0,0 +1,61 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2004,2005,2006 Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Interface for simple test runner.
*
* 11-Aug-2004 Initial implementation of basic test runner interface. (JDS)
*/
/** @file
* Basic interface with output to stdout.
*/
/** @addtogroup Basic
* @{
*/
#ifndef CUNIT_BASIC_H_SEEN
#define CUNIT_BASIC_H_SEEN
#include "CUnit.h"
#include "TestDB.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Run modes for the basic interface. */
typedef enum {
CU_BRM_NORMAL = 0, /**< Normal mode - failures and run summary are printed [default]. */
CU_BRM_SILENT, /**< Silent mode - no output is printed except framework error messages. */
CU_BRM_VERBOSE /**< Verbose mode - maximum output of run details. */
} CU_BasicRunMode;
CU_EXPORT CU_ErrorCode CU_basic_run_tests(void);
CU_EXPORT CU_ErrorCode CU_basic_run_suite(CU_pSuite pSuite);
CU_EXPORT CU_ErrorCode CU_basic_run_test(CU_pSuite pSuite, CU_pTest pTest);
CU_EXPORT void CU_basic_set_mode(CU_BasicRunMode mode);
CU_EXPORT CU_BasicRunMode CU_basic_get_mode(void);
CU_EXPORT void CU_basic_show_failures(CU_pFailureRecord pFailure);
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_BASIC_H_SEEN */
/** @} */

View File

@@ -0,0 +1,61 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004,2005,2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains Interface for console Run tests.
*
* Aug 2001 Initial implementation. (AK)
*
* 09/Aug/2001 Single interface to Console_run_tests. (AK)
*
* 18-Jul-2004 New interface. (JDS)
*
* 21-Apr-2005 Changed header name to avoid clash with system curses.h. (JDS)
*/
/** @file
* Curses testing interface with interactive output (user interface).
*/
/** @addtogroup Curses
* @{
*/
#ifndef CUNIT_CURSES_H_SEEN
#define CUNIT_CURSES_H_SEEN
#include "CUnit.h"
#include "TestDB.h"
#ifdef __cplusplus
extern "C" {
#endif
CU_EXPORT void CU_curses_run_tests(void);
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Deprecated (version 1). @deprecated Use CU_curses_run_tests(). */
#define curses_run_tests() CU_curses_run_tests()
#endif
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_CURSES_H_SEEN */
/** @} */

View File

@@ -0,0 +1,134 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004,2005,2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains CUnit error codes which can be used externally.
*
* Aug 2001 Initial implementation. (AK)
*
* 02/Oct/2001 Added proper Eror Codes. (AK)
*
* 13-Oct-2001 Added Error Codes for Duplicate TestGroup and Test. (AK)
*
* 03-Aug-2004 Converted error code macros to an enum, doxygen comments, moved
* error handing code here, changed file name from Errno.h, added
* error codes for file open errors, added error action selection. (JDS)
*
* 05-Sep-2004 Added internal test interface. (JDS)
*/
/** @file
* Error handling functions (user interface).
* CUnit uses a simple (and conventional) error handling strategy.
* Functions that can generate errors set (and usually return) an
* error code to indicate the run status. The error code can be
* inspected using the CU_get_error() function. A descriptive
* error message can be retrieved using CU_get_error_msg().
*/
/** @addtogroup Framework
* @{
*/
#ifndef CUNIT_CUERROR_H_SEEN
#define CUNIT_CUERROR_H_SEEN
#include <errno.h>
/*------------------------------------------------------------------------*/
/** CUnit error codes.
* If codes are added or removed, be sure to make a change to the
* error messages in CUError.c/get_error_desc().
* @see CU_set_error()
* @see CU_get_error()
* @see CU_get_error_msg()
*/
typedef enum {
/* basic errors */
CUE_SUCCESS = 0, /**< No error condition. */
CUE_NOMEMORY = 1, /**< Memory allocation failed. */
/* Test Registry Level Errors */
CUE_NOREGISTRY = 10, /**< Test registry not initialized. */
CUE_REGISTRY_EXISTS = 11, /**< Attempt to CU_set_registry() without CU_cleanup_registry(). */
/* Test Suite Level Errors */
CUE_NOSUITE = 20, /**< A required CU_pSuite pointer was NULL. */
CUE_NO_SUITENAME = 21, /**< Required CU_Suite name not provided. */
CUE_SINIT_FAILED = 22, /**< Suite initialization failed. */
CUE_SCLEAN_FAILED = 23, /**< Suite cleanup failed. */
CUE_DUP_SUITE = 24, /**< Duplicate suite name not allowed. */
/* Test Case Level Errors */
CUE_NOTEST = 30, /**< A required CU_pTest pointer was NULL. */
CUE_NO_TESTNAME = 31, /**< Required CU_Test name not provided. */
CUE_DUP_TEST = 32, /**< Duplicate test case name not allowed. */
CUE_TEST_NOT_IN_SUITE = 33, /**< Test not registered in specified suite. */
/* File handling errors */
CUE_FOPEN_FAILED = 40, /**< An error occurred opening a file. */
CUE_FCLOSE_FAILED = 41, /**< An error occurred closing a file. */
CUE_BAD_FILENAME = 42, /**< A bad filename was requested (NULL, empty, nonexistent, etc.). */
CUE_WRITE_ERROR = 43 /**< An error occurred during a write to a file. */
} CU_ErrorCode;
/*------------------------------------------------------------------------*/
/** CUnit error action codes.
* These are used to set the action desired when an error
* condition is detected in the CUnit framework.
* @see CU_set_error_action()
* @see CU_get_error_action()
*/
typedef enum CU_ErrorAction {
CUEA_IGNORE, /**< Runs should be continued when an error condition occurs (if possible). */
CUEA_FAIL, /**< Runs should be stopped when an error condition occurs. */
CUEA_ABORT /**< The application should exit() when an error conditions occurs. */
} CU_ErrorAction;
/* Error handling & reporting functions. */
#include "CUnit.h"
#ifdef __cplusplus
extern "C" {
#endif
CU_EXPORT CU_ErrorCode CU_get_error(void);
CU_EXPORT const char* CU_get_error_msg(void);
CU_EXPORT void CU_set_error_action(CU_ErrorAction action);
CU_EXPORT CU_ErrorAction CU_get_error_action(void);
#ifdef CUNIT_BUILD_TESTS
void test_cunit_CUError(void);
#endif
/* Internal function - users should not generally call this function */
void CU_set_error(CU_ErrorCode error);
#ifdef __cplusplus
}
#endif
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Deprecated (version 1). @deprecated Use CU_get_error_msg(). */
#define get_error() CU_get_error_msg()
#endif /* USE_DEPRECATED_CUNIT_NAMES */
#endif /* CUNIT_CUERROR_H_SEEN */
/** @} */

View File

@@ -0,0 +1,372 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004,2005,2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains ASSERT Macro definitions.
*
* 09/Aug/2001 ASSERT definitions. (AK)
*
* 12/Mar/2003 New Assert definitions. (AK)
*
* 27/Jul/2003 Modified ASSERT_XXX Macro definitions. (AK)
*
* 15-Jul-2004 New interface, changed action on assert failure to not
* return, provided _FATAL versions of assertions to return
* from test function on failure. (JDS)
*
* 01-Sep-2004 Modified assertions for setjmp/longjmp mechanism of
* aborting test runs, added CU_FAIL and CU_PASS macros. (JDS)
*
* 07-May-2005 Added CU_ prefix to remaining CUnit defines (BOOL, TRUE,
* FALSE, MAX_...). Added CU_UNREFERENCED_PARAMETER() define. (JDS)
*/
/** @file
* Basic CUnit include file for user and system code.
* Defines macros for assertions for use in user test cases.
* Basic system macro definitions also appear here.
*/
/** @addtogroup Framework
* @{
*/
#ifndef CUNIT_CUNIT_H_SEEN
#define CUNIT_CUNIT_H_SEEN
#include <string.h>
#include <math.h>
/** CUnit version number. */
#define CU_VERSION "2.1-0"
/* Max string lengths for names (includes terminating NULL. */
/** Maximum length of a test name string. */
#define CU_MAX_TEST_NAME_LENGTH 256
/** Maximim length of a suite name string. */
#define CU_MAX_SUITE_NAME_LENGTH 256
/* Global type Definitions to be used for boolean operators. */
#ifndef CU_BOOL
/** Boolean type for CUnit use. */
#define CU_BOOL int
#endif
#ifndef CU_TRUE
/** Boolean TRUE for CUnit use. */
#define CU_TRUE 1
#endif
#ifndef CU_FALSE
/** Boolean FALSE for CUnit use. */
#define CU_FALSE 0
#endif
#ifndef CU_UNREFERENCED_PARAMETER
/** Consistent approach to referencing unused parameters. */
#define CU_UNREFERENCED_PARAMETER(x) (void)x
#endif
#ifdef WIN32
# ifdef CU_DLL
# ifdef CU_BUILD_DLL
# define CU_EXPORT __declspec(dllexport)
# else
# define CU_EXPORT __declspec(dllimport)
# endif
# else
# define CU_EXPORT
# endif
#else
# define CU_EXPORT
#endif
#include "CUError.h"
#include "TestDB.h" /* not needed here - included for user convenience */
#include "TestRun.h" /* not needed here - include (after BOOL define) for user convenience */
/** Record a pass condition without performing a logical test. */
#define CU_PASS(msg) \
{ CU_assertImplementation(CU_TRUE, __LINE__, ("CU_PASS(" #msg ")"), __FILE__, "", CU_FALSE); }
/** Simple assertion.
* Reports failure with no other action.
*/
#define CU_ASSERT(value) \
{ CU_assertImplementation((value), __LINE__, #value, __FILE__, "", CU_FALSE); }
/** Simple assertion.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_FATAL(value) \
{ CU_assertImplementation((value), __LINE__, #value, __FILE__, "", CU_TRUE); }
/** Simple assertion.
* Reports failure with no other action.
*/
#define CU_TEST(value) \
{ CU_assertImplementation((value), __LINE__, #value, __FILE__, "", CU_FALSE); }
/** Simple assertion.
* Reports failure and causes test to abort.
*/
#define CU_TEST_FATAL(value) \
{ CU_assertImplementation((value), __LINE__, #value, __FILE__, "", CU_TRUE); }
/** Record a failure without performing a logical test. */
#define CU_FAIL(msg) \
{ CU_assertImplementation(CU_FALSE, __LINE__, ("CU_FAIL(" #msg ")"), __FILE__, "", CU_FALSE); }
/** Record a failure without performing a logical test, and abort test. */
#define CU_FAIL_FATAL(msg) \
{ CU_assertImplementation(CU_FALSE, __LINE__, ("CU_FAIL_FATAL(" #msg ")"), __FILE__, "", CU_TRUE); }
/** Asserts that value is CU_TRUE.
* Reports failure with no other action.
*/
#define CU_ASSERT_TRUE(value) \
{ CU_assertImplementation((value), __LINE__, ("CU_ASSERT_TRUE(" #value ")"), __FILE__, "", CU_FALSE); }
/** Asserts that value is CU_TRUE.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_TRUE_FATAL(value) \
{ CU_assertImplementation((value), __LINE__, ("CU_ASSERT_TRUE_FATAL(" #value ")"), __FILE__, "", CU_TRUE); }
/** Asserts that value is CU_FALSE.
* Reports failure with no other action.
*/
#define CU_ASSERT_FALSE(value) \
{ CU_assertImplementation(!(value), __LINE__, ("CU_ASSERT_FALSE(" #value ")"), __FILE__, "", CU_FALSE); }
/** Asserts that value is CU_FALSE.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_FALSE_FATAL(value) \
{ CU_assertImplementation(!(value), __LINE__, ("CU_ASSERT_FALSE_FATAL(" #value ")"), __FILE__, "", CU_TRUE); }
/** Asserts that actual == expected.
* Reports failure with no other action.
*/
#define CU_ASSERT_EQUAL(actual, expected) \
{ CU_assertImplementation(((actual) == (expected)), __LINE__, ("CU_ASSERT_EQUAL(" #actual "," #expected ")"), __FILE__, "", CU_FALSE); }
/** Asserts that actual == expected.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_EQUAL_FATAL(actual, expected) \
{ CU_assertImplementation(((actual) == (expected)), __LINE__, ("CU_ASSERT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", CU_TRUE); }
/** Asserts that actual != expected.
* Reports failure with no other action.
*/
#define CU_ASSERT_NOT_EQUAL(actual, expected) \
{ CU_assertImplementation(((actual) != (expected)), __LINE__, ("CU_ASSERT_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, "", CU_FALSE); }
/** Asserts that actual != expected.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_NOT_EQUAL_FATAL(actual, expected) \
{ CU_assertImplementation(((actual) != (expected)), __LINE__, ("CU_ASSERT_NOT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", CU_TRUE); }
/** Asserts that pointers actual == expected.
* Reports failure with no other action.
*/
#define CU_ASSERT_PTR_EQUAL(actual, expected) \
{ CU_assertImplementation(((void*)(actual) == (void*)(expected)), __LINE__, ("CU_ASSERT_PTR_EQUAL(" #actual "," #expected ")"), __FILE__, "", CU_FALSE); }
/** Asserts that pointers actual == expected.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_PTR_EQUAL_FATAL(actual, expected) \
{ CU_assertImplementation(((void*)(actual) == (void*)(expected)), __LINE__, ("CU_ASSERT_PTR_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", CU_TRUE); }
/** Asserts that pointers actual != expected.
* Reports failure with no other action.
*/
#define CU_ASSERT_PTR_NOT_EQUAL(actual, expected) \
{ CU_assertImplementation(((void*)(actual) != (void*)(expected)), __LINE__, ("CU_ASSERT_PTR_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, "", CU_FALSE); }
/** Asserts that pointers actual != expected.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_PTR_NOT_EQUAL_FATAL(actual, expected) \
{ CU_assertImplementation(((void*)(actual) != (void*)(expected)), __LINE__, ("CU_ASSERT_PTR_NOT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", CU_TRUE); }
/** Asserts that pointer value is NULL.
* Reports failure with no other action.
*/
#define CU_ASSERT_PTR_NULL(value) \
{ CU_assertImplementation((NULL == (void*)(value)), __LINE__, ("CU_ASSERT_PTR_NULL(" #value")"), __FILE__, "", CU_FALSE); }
/** Asserts that pointer value is NULL.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_PTR_NULL_FATAL(value) \
{ CU_assertImplementation((NULL == (void*)(value)), __LINE__, ("CU_ASSERT_PTR_NULL_FATAL(" #value")"), __FILE__, "", CU_TRUE); }
/** Asserts that pointer value is not NULL.
* Reports failure with no other action.
*/
#define CU_ASSERT_PTR_NOT_NULL(value) \
{ CU_assertImplementation((NULL != (void*)(value)), __LINE__, ("CU_ASSERT_PTR_NOT_NULL(" #value")"), __FILE__, "", CU_FALSE); }
/** Asserts that pointer value is not NULL.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_PTR_NOT_NULL_FATAL(value) \
{ CU_assertImplementation((NULL != (void*)(value)), __LINE__, ("CU_ASSERT_PTR_NOT_NULL_FATAL(" #value")"), __FILE__, "", CU_TRUE); }
/** Asserts that string actual == expected.
* Reports failure with no other action.
*/
#define CU_ASSERT_STRING_EQUAL(actual, expected) \
{ CU_assertImplementation(!(strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_EQUAL(" #actual "," #expected ")"), __FILE__, "", CU_FALSE); }
/** Asserts that string actual == expected.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_STRING_EQUAL_FATAL(actual, expected) \
{ CU_assertImplementation(!(strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", CU_TRUE); }
/** Asserts that string actual != expected.
* Reports failure with no other action.
*/
#define CU_ASSERT_STRING_NOT_EQUAL(actual, expected) \
{ CU_assertImplementation((strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, "", CU_FALSE); }
/** Asserts that string actual != expected.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_STRING_NOT_EQUAL_FATAL(actual, expected) \
{ CU_assertImplementation((strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_NOT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", CU_TRUE); }
/** Asserts that string actual == expected with length specified.
* The comparison is limited to count characters.
* Reports failure with no other action.
*/
#define CU_ASSERT_NSTRING_EQUAL(actual, expected, count) \
{ CU_assertImplementation(!(strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_EQUAL(" #actual "," #expected "," #count ")"), __FILE__, "", CU_FALSE); }
/** Asserts that string actual == expected with length specified.
* The comparison is limited to count characters.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_NSTRING_EQUAL_FATAL(actual, expected, count) \
{ CU_assertImplementation(!(strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_EQUAL_FATAL(" #actual "," #expected "," #count ")"), __FILE__, "", CU_TRUE); }
/** Asserts that string actual != expected with length specified.
* The comparison is limited to count characters.
* Reports failure with no other action.
*/
#define CU_ASSERT_NSTRING_NOT_EQUAL(actual, expected, count) \
{ CU_assertImplementation((strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_NOT_EQUAL(" #actual "," #expected "," #count ")"), __FILE__, "", CU_FALSE); }
/** Asserts that string actual != expected with length specified.
* The comparison is limited to count characters.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_NSTRING_NOT_EQUAL_FATAL(actual, expected, count) \
{ CU_assertImplementation((strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_NOT_EQUAL_FATAL(" #actual "," #expected "," #count ")"), __FILE__, "", CU_TRUE); }
/** Asserts that double actual == expected within the specified tolerance.
* If actual is within granularity of expected, the assertion passes.
* Reports failure with no other action.
*/
#define CU_ASSERT_DOUBLE_EQUAL(actual, expected, granularity) \
{ CU_assertImplementation(((fabs((double)(actual) - (expected)) <= fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_EQUAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", CU_FALSE); }
/** Asserts that double actual == expected within the specified tolerance.
* If actual is within granularity of expected, the assertion passes.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_DOUBLE_EQUAL_FATAL(actual, expected, granularity) \
{ CU_assertImplementation(((fabs((double)(actual) - (expected)) <= fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_EQUAL_FATAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", CU_TRUE); }
/** Asserts that double actual != expected within the specified tolerance.
* If actual is within granularity of expected, the assertion fails.
* Reports failure with no other action.
*/
#define CU_ASSERT_DOUBLE_NOT_EQUAL(actual, expected, granularity) \
{ CU_assertImplementation(((fabs((double)(actual) - (expected)) > fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_NOT_EQUAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", CU_FALSE); }
/** Asserts that double actual != expected within the specified tolerance.
* If actual is within granularity of expected, the assertion fails.
* Reports failure and causes test to abort.
*/
#define CU_ASSERT_DOUBLE_NOT_EQUAL_FATAL(actual, expected, granularity) \
{ CU_assertImplementation(((fabs((double)(actual) - (expected)) > fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_NOT_EQUAL_FATAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", CU_TRUE); }
#ifdef USE_DEPRECATED_CUNIT_NAMES
#ifndef BOOL
/** Deprecated (version 2.0-2). @deprecated Use CU_BOOL. */
#define BOOL int
#endif
#ifndef TRUE
/** Deprecated (version 2.0-2). @deprecated Use CU_TRUE. */
#define TRUE 1
#endif
#ifndef FALSE
/** Deprecated (version 2.0-2). @deprecated Use CU_FALSE. */
#define FALSE 0
#endif
/** Deprecated (version 2.0-2). @deprecated Use CU_MAX_TEST_NAME_LENGTH. */
#define MAX_TEST_NAME_LENGTH 256
/** Deprecated (version 2.0-2). @deprecated Use CU_MAX_SUITE_NAME_LENGTH. */
#define MAX_SUITE_NAME_LENGTH 256
/** Deprecated (version 1). @deprecated Use CU_ASSERT_FATAL. */
#define ASSERT(value) { if (FALSE == (int)(value)) { CU_assertImplementation((BOOL)value, __LINE__, #value, __FILE__, "", FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_TRUE_FATAL. */
#define ASSERT_TRUE(value) { if (FALSE == (value)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_TRUE(" #value ")"), __FILE__, "", FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_FALSE_FATAL. */
#define ASSERT_FALSE(value) { if (FALSE != (value)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_FALSE(" #value ")"), __FILE__, "", FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_EQUAL_FATAL. */
#define ASSERT_EQUAL(actual, expected) { if ((actual) != (expected)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_NOT_EQUAL_FATAL. */
#define ASSERT_NOT_EQUAL(actual, expected) { if ((void*)(actual) == (void*)(expected)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_PTR_EQUAL_FATAL. */
#define ASSERT_PTR_EQUAL(actual, expected) { if ((void*)(actual) != (void*)(expected)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_PTR_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_PTR_NOT_EQUAL_FATAL. */
#define ASSERT_PTR_NOT_EQUAL(actual, expected) { if ((void*)(actual) == (void*)(expected)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_PTR_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_PTR_NULL_FATAL. */
#define ASSERT_PTR_NULL(value) { if (NULL != (void*)(value)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_PTR_NULL(" #value")"), __FILE__, "", FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_PTR_NOT_NULL_FATAL. */
#define ASSERT_PTR_NOT_NULL(value) { if (NULL == (void*)(value)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_PTR_NOT_NULL(" #value")"), __FILE__, "", FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_STRING_EQUAL_FATAL. */
#define ASSERT_STRING_EQUAL(actual, expected) { if (strcmp((const char*)actual, (const char*)expected)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_STRING_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_STRING_NOT_EQUAL_FATAL. */
#define ASSERT_STRING_NOT_EQUAL(actual, expected) { if (!strcmp((const char*)actual, (const char*)expected)) { CU_assertImplementation(TRUE, __LINE__, ("ASSERT_STRING_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_NSTRING_EQUAL_FATAL. */
#define ASSERT_NSTRING_EQUAL(actual, expected, count) { if (strncmp((const char*)actual, (const char*)expected, (size_t)count)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_NSTRING_EQUAL(" #actual "," #expected "," #count ")"), __FILE__, "", FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_NSTRING_NOT_EQUAL_FATAL. */
#define ASSERT_NSTRING_NOT_EQUAL(actual, expected, count) { if (!strncmp((const char*)actual, (const char*)expected, (size_t)count)) { CU_assertImplementation(TRUE, __LINE__, ("ASSERT_NSTRING_NOT_EQUAL(" #actual "," #expected "," #count ")"), __FILE__, "", FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_DOUBLE_EQUAL_FATAL. */
#define ASSERT_DOUBLE_EQUAL(actual, expected, granularity) { if ((fabs((double)actual - expected) > fabs((double)granularity))) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_DOUBLE_EQUAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", FALSE); return; }}
/** Deprecated (version 1). @deprecated Use CU_ASSERT_DOUBLE_NOT_EQUAL_FATAL. */
#define ASSERT_DOUBLE_NOT_EQUAL(actual, expected, granularity) { if ((fabs((double)actual - expected) <= fabs((double)granularity))) { CU_assertImplementation(TRUE, __LINE__, ("ASSERT_DOUBLE_NOT_EQUAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", FALSE); return; }}
#endif /* USE_DEPRECATED_CUNIT_NAMES */
#endif /* CUNIT_CUNIT_H_SEEN */
/** @} */

View File

@@ -0,0 +1,59 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004,2005,2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains Interface for console Run tests.
*
* Aug 2001 Initial implementation. (AK)
*
* 09/Aug/2001 Single interface to Console_run_tests. (AK)
*
* 20-Jul-2004 New interface, doxygen comments. (JDS)
*/
/** @file
* Console interface with interactive output (user interface).
*/
/** @addtogroup Console
* @{
*/
#ifndef CUNIT_CONSOLE_H_SEEN
#define CUNIT_CONSOLE_H_SEEN
#include "CUnit.h"
#include "TestDB.h"
#ifdef __cplusplus
extern "C" {
#endif
CU_EXPORT void CU_console_run_tests(void);
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Deprecated (version 1). @deprecated Use CU_console_run_tests(). */
#define console_run_tests() CU_console_run_tests()
#endif /* USE_DEPRECATED_CUNIT_NAMES */
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_CONSOLE_H_SEEN */
/** @} */

View File

@@ -0,0 +1,104 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004,2005,2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains Memory Related Defines to use internal routines to detect Memory Leak
* in Debug Versions
*
* 18/Jun/2002 Memory Debug Functions. (AK)
*
* 17-Jul-2004 New interface for global function names. (JDS)
*
* 05-Sep-2004 Added internal test interface. (JDS)
*/
/** @file
* Memory management functions (user interface).
* Two versions of memory allocation/deallocation are available.
* If compiled with MEMTRACE defined, CUnit keeps track of all
* system allocations & deallocations. The memory record can
* then be reported using CU_CREATE_MEMORY_REPORT. Otherwise,
* standard system memory allocation is used without tracing.
*/
/** @addtogroup Framework
* @{
*/
#ifndef CUNIT_MYMEM_H_SEEN
#define CUNIT_MYMEM_H_SEEN
#ifdef __cplusplus
extern "C" {
#endif
#ifdef MEMTRACE
void* CU_calloc(size_t nmemb, size_t size, unsigned int uiLine, const char* szFileName);
void* CU_malloc(size_t size, unsigned int uiLine, const char* szFileName);
void CU_free(void *ptr, unsigned int uiLine, const char* szFileName);
void* CU_realloc(void *ptr, size_t size, unsigned int uiLine, const char* szFileName);
CU_EXPORT void CU_dump_memory_usage(const char*);
/** c-allocate with memory tracking. */
#define CU_CALLOC(x, y) CU_calloc((x), (y), __LINE__, __FILE__)
/** m-allocate with memory tracking. */
#define CU_MALLOC(x) CU_malloc((x), __LINE__, __FILE__)
/** Free with memory tracking. */
#define CU_FREE(x) CU_free((x), __LINE__, __FILE__)
/** Reallocate with memory tracking. */
#define CU_REALLOC(x, y) CU_realloc((x), (y), __LINE__, __FILE__)
/** Generate report on tracked memory. */
#define CU_CREATE_MEMORY_REPORT(x) CU_dump_memory_usage((x))
/** Generate report on tracked memory (old macro). */
#define CU_DUMP_MEMORY_USAGE(x) CU_dump_memory_usage((x))
#else /* MEMTRACE */
/** Standard calloc() if MEMTRACE not defined. */
#define CU_CALLOC(x, y) calloc((x), (y))
/** Standard malloc() if MEMTRACE not defined. */
#define CU_MALLOC(x) malloc((x))
/** Standard free() if MEMTRACE not defined. */
#define CU_FREE(x) free((x))
/** Standard realloc() if MEMTRACE not defined. */
#define CU_REALLOC(x, y) realloc((x), (y))
/** No-op if MEMTRACE not defined. */
#define CU_CREATE_MEMORY_REPORT(x)
/** No-op if MEMTRACE not defined. */
#define CU_DUMP_MEMORY_USAGE(x)
#endif /* MEMTRACE */
#ifdef CUNIT_BUILD_TESTS
/** Disable memory allocation for testing purposes. */
void test_cunit_deactivate_malloc(void);
/** Enable memory allocation for testing purposes. */
void test_cunit_activate_malloc(void);
/** Retrieve number of memory events for a given pointer */
unsigned int test_cunit_get_n_memevents(void* pLocation);
/** Retrieve number of allocations for a given pointer */
unsigned int test_cunit_get_n_allocations(void* pLocation);
/** Retrieve number of deallocations for a given pointer */
unsigned int test_cunit_get_n_deallocations(void* pLocation);
void test_cunit_MyMem(void);
#endif /* CUNIT_BUILD_TESTS */
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_MYMEM_H_SEEN */
/** @} */

View File

@@ -0,0 +1,357 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004,2005,2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains all the Type Definitions and functions declarations
* for the CUnit test database maintenance.
*
* Aug 2001 Initial implementation. (AK)
*
* 09/Aug/2001 Added Preprocessor conditionals for the file. (AK)
*
* 24/aug/2001 Made the linked list from SLL to DLL(doubly linked list). (AK)
*
* 31-Aug-2004 Restructured to eliminate global variables error_number,
* g_pTestRegistry; new interface, support for deprecated
* version 1 interface, moved error handling code to
* CUError.[ch], moved test run counts and _TestResult out
* of TestRegistry to TestRun.h. (JDS)
*
* 01-Sep-2004 Added jmp_buf to CU_Test. (JDS)
*
* 05-Sep-2004 Added internal test interface. (JDS)
*/
/** @file
* Management functions for tests, suites, and the test registry (user interface).
* Unit testing in CUnit follows the standard structure of unit
* tests aggregated in suites, which are themselves aggregated
* in a test registry. This module provides functions and
* typedef's to support the creation, registration, and manipulation
* of test cases, suites, and the registry.
*/
/** @addtogroup Framework
* @{
*/
#ifndef CUNIT_TESTDB_H_SEEN
#define CUNIT_TESTDB_H_SEEN
#include <setjmp.h> /* jmp_buf */
#include "CUnit.h"
#include "CUError.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Type definition for Initialization/Cleaup/TestFunction */
typedef int (*CU_InitializeFunc)(void); /**< Signature for suite initialization function. */
typedef int (*CU_CleanupFunc)(void); /**< Signature for suite cleanup function. */
typedef void (*CU_TestFunc)(void); /**< Signature for a testing function in a test case. */
/** CUnit test case data type.
* CU_Test is a linked list of unit tests. Each test
* has a name and a callable test function, as well as
* links to the next and previous tests in the list. A
* test also holds a jmp_buf reference for use in
* implementing fatal assertions.
* <P>
* Generally, the linked list includes tests which are
* associated with each other in a CU_Suite. As a result,
* tests are run in the order in which they are added to a
* suite (see CU_add_test()).
* <P>
* In the current implementation, the name of each CU_Test
* in a suite must have a unique name. There is no
* restriction on the test function. This means that the
* same function could, in principle, be called more than
* once as long as it is registered with different tests
* having distinct names.
* @see CU_Suite
* @see CU_TestRegistry
*/
typedef struct CU_Test
{
char* pName; /**< Test name. */
CU_TestFunc pTestFunc; /**< Pointer to the test function. */
jmp_buf* pJumpBuf; /**< Jump buffer for setjmp/longjmp test abort mechanism. */
struct CU_Test* pNext; /**< Pointer to the next test in linked list. */
struct CU_Test* pPrev; /**< Pointer to the previous test in linked list. */
} CU_Test;
typedef CU_Test* CU_pTest; /**< Pointer to a CUnit test case. */
/** CUnit suite data type.
* CU_Suite is a linked list of CU_Test containers.
* Each suite has a name and count of associated unit
* tests. It also holds a pointer to optional
* initialization and cleanup functions. If non-NULL,
* these are called before and after running the suite's
* tests, respectively. In addition, the suite holds a
* pointer to the head of the linked list of associated
* CU_Test objects. Finally, pointers to the next and
* previous suites in the linked list are maintained.
* <P>
* Generally, the linked list includes suites which are
* associated with each other in a CU_TestRegistry. As a
* result, suites are run in the order in which they are
* registered (see CU_add_suite()).
* <P>
* In the current implementation, the name of each CU_Suite
* in a test registry must have a unique name. There is no
* restriction on the contained tests. This means that the
* same CU_Test could, in principle, be run more than
* once as long as it is registered with different suites
* having distinct names.
* @see CU_Test
* @see CU_TestRegistry
*/
typedef struct CU_Suite
{
char* pName; /**< Suite name. */
CU_pTest pTest; /**< Pointer to the 1st test in the suite. */
CU_InitializeFunc pInitializeFunc; /**< Pointer to the suite initialization function. */
CU_CleanupFunc pCleanupFunc; /**< Pointer to the suite cleanup function. */
unsigned int uiNumberOfTests; /**< Number of tests in the suite. */
struct CU_Suite* pNext; /**< Pointer to the next suite in linked list. */
struct CU_Suite* pPrev; /**< Pointer to the previous suite in linked list. */
} CU_Suite;
typedef CU_Suite* CU_pSuite; /**< Pointer to a CUnit suite. */
/** CUnit test registry data type.
* CU_TestRegisty is the repository for suites containing
* unit tests. The test registry maintains a count of the
* number of CU_Suite objects contained in the registry, as
* well as a count of the total number of CU_Test objects
* associated with those suites. It also holds a pointer
* to the head of the linked list of CU_Suite objects.
* <P>
* With this structure, the user will normally add suites
* implictly to the internal test registry using CU_add_suite(),
* and then add tests to each suite using CU_add_test().
* Test runs are then initiated using one of the appropriate
* functions in TestRun.c via one of the interfaces.
* <P>
* Automatic creation and destruction of the internal registry
* and its objects is available using CU_initialize_registry()
* and CU_cleanup_registry(), respectively. For internal and
* testing purposes, the internal registry can be retrieved and
* assigned. Functions are also provided for creating and
* destroying independent registries.
* <P>
* Note that earlier versions of CUnit also contained a
* pointer to a linked list of CU_FailureRecord objects
* (termed _TestResults). This has been removed from the
* registry and relocated to TestRun.c.
* @see CU_Test
* @see CU_Suite
* @see CU_initialize_registry()
* @see CU_cleanup_registry()
* @see CU_get_registry()
* @see CU_set_registry()
* @see CU_create_new_registry()
* @see CU_destroy_existing_registry()
*/
typedef struct CU_TestRegistry
{
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Union to support v1.1-1 member name. */
union {
unsigned int uiNumberOfSuites; /**< Number of suites in the test registry. */
unsigned int uiNumberOfGroups; /**< Deprecated (version 1). @deprecated Use uiNumberOfSuites. */
};
unsigned int uiNumberOfTests; /**< Number of tests in the test registry. */
/** Union to support v1.1-1 member name. */
union {
CU_pSuite pSuite; /**< Pointer to the 1st suite in the test registry. */
CU_pSuite pGroup; /**< Deprecated (version 1). @deprecated Use pSuite. */
};
#else
unsigned int uiNumberOfSuites; /**< Number of suites in the test registry. */
unsigned int uiNumberOfTests; /**< Number of tests in the test registry. */
CU_pSuite pSuite; /**< Pointer to the 1st suite in the test registry. */
#endif
} CU_TestRegistry;
typedef CU_TestRegistry* CU_pTestRegistry; /**< Pointer to a CUnit test registry. */
/* Public interface functions */
CU_EXPORT CU_ErrorCode CU_initialize_registry(void);
CU_EXPORT void CU_cleanup_registry(void);
CU_EXPORT CU_BOOL CU_registry_initialized(void);
CU_EXPORT CU_pSuite CU_add_suite(const char* strName, CU_InitializeFunc pInit, CU_CleanupFunc pClean);
CU_EXPORT CU_pTest CU_add_test(CU_pSuite pSuite, const char* strName, CU_TestFunc pTestFunc);
/** Shortcut macro for adding a test to a suite. */
#define CU_ADD_TEST(suite, test) (CU_add_test(suite, #test, (CU_TestFunc)test))
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
/* This section is based conceptually on code
* Copyright (C) 2004 Aurema Pty Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Derived from code contributed by K. Cheung and Aurema Pty Ltd. (thanks!)
* test_case_t, test_group_t, test_suite_t
*/
/** Test case parameters.
* This data type is provided to assist CUnit users
* manage collections of test and suites. It is
* intended to be used to build arrays of test case
* parameters that can be then be referred to in
* a CU_suite_info_t variable.
*/
typedef struct CU_TestInfo {
char *pName; /**< Test name. */
CU_TestFunc pTestFunc; /**< Test function. */
} CU_TestInfo;
typedef CU_TestInfo* CU_pTestInfo; /**< Pointer to CU_TestInfo type. */
/** Suite parameters.
* This data type is provided to assist CUnit users
* manage collections of test and suites. It is
* intended to be used to build arrays of suite
* parameters that can be passed to a bulk registration
* function such as CU_register_suite() or
* CU_register_suites().
*/
typedef struct CU_SuiteInfo {
char *pName; /**< Suite name. */
CU_InitializeFunc pInitFunc; /**< Suite initialization function. */
CU_CleanupFunc pCleanupFunc; /**< Suite cleanup function */
CU_TestInfo *pTests; /**< Test case array - must be NULL terminated. */
} CU_SuiteInfo;
typedef CU_SuiteInfo* CU_pSuiteInfo; /**< Pointer to CU_SuiteInfo type. */
/** NULL CU_test_info_t to terminate arrays of tests. */
#define CU_TEST_INFO_NULL { NULL, NULL }
/** NULL CU_suite_info_t to terminate arrays of suites. */
#define CU_SUITE_INFO_NULL { NULL, NULL, NULL, NULL }
CU_EXPORT CU_ErrorCode CU_register_suites(CU_SuiteInfo suite_info[]);
CU_EXPORT CU_ErrorCode CU_register_nsuites(int suite_count, ...);
#ifdef USE_DEPRECATED_CUNIT_NAMES
typedef CU_TestInfo test_case_t; /**< Deprecated (version 1). @deprecated Use CU_TestInfo. */
typedef CU_SuiteInfo test_group_t; /**< Deprecated (version 1). @deprecated Use CU_SuiteInfo. */
/** Deprecated (version 1). @deprecated Use CU_SuiteInfo and CU_TestInfo. */
typedef struct test_suite {
char *name; /**< Suite name. Currently not used. */
test_group_t *groups; /**< Test groups. This must be a NULL terminated array. */
} test_suite_t;
/** Deprecated (version 1). @deprecated Use CU_TEST_INFO_NULL. */
#define TEST_CASE_NULL { NULL, NULL }
/** Deprecated (version 1). @deprecated Use CU_TEST_GROUP_NULL. */
#define TEST_GROUP_NULL { NULL, NULL, NULL, NULL }
/** Deprecated (version 1). @deprecated Use CU_register_suites(). */
#define test_group_register(tg) CU_register_suites(tg)
/** Deprecated (version 1). @deprecated Use CU_SuiteInfo and CU_register_suites(). */
CU_EXPORT int test_suite_register(test_suite_t *ts)
{
test_group_t *tg;
int error;
for (tg = ts->groups; tg->pName; tg++)
if ((error = CU_register_suites(tg)) != CUE_SUCCESS)
return error;
return CUE_SUCCESS;
}
#endif /* USE_DEPRECATED_CUNIT_NAMES */
/*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
#ifdef USE_DEPRECATED_CUNIT_NAMES
typedef CU_InitializeFunc InitializeFunc; /**< Deprecated (version 1). @deprecated Use CU_InitializeFunc. */
typedef CU_CleanupFunc CleanupFunc; /**< Deprecated (version 1). @deprecated Use CU_CleanupFunc. */
typedef CU_TestFunc TestFunc; /**< Deprecated (version 1). @deprecated Use CU_TestFunc. */
typedef CU_Test _TestCase; /**< Deprecated (version 1). @deprecated Use CU_Test. */
typedef CU_pTest PTestCase; /**< Deprecated (version 1). @deprecated Use CU_pTest. */
typedef CU_Suite _TestGroup; /**< Deprecated (version 1). @deprecated Use CU_Suite. */
typedef CU_pSuite PTestGroup; /**< Deprecated (version 1). @deprecated Use CU_pSuite. */
typedef CU_TestRegistry _TestRegistry; /**< Deprecated (version 1). @deprecated Use CU_TestRegistry. */
typedef CU_pTestRegistry PTestRegistry; /**< Deprecated (version 1). @deprecated Use CU_pTestRegistry. */
/* Public interface functions */
/** Deprecated (version 1). @deprecated Use CU_initialize_registry(). */
#define initialize_registry() CU_initialize_registry()
/** Deprecated (version 1). @deprecated Use CU_cleanup_registry(). */
#define cleanup_registry() CU_cleanup_registry()
/** Deprecated (version 1). @deprecated Use CU_add_suite(). */
#define add_test_group(name, init, clean) CU_add_suite(name, init, clean)
/** Deprecated (version 1). @deprecated Use CU_add_test(). */
#define add_test_case(group, name, test) CU_add_test(group, name, test)
/* private internal CUnit testing functions */
/** Deprecated (version 1). @deprecated Use CU_get_registry(). */
#define get_registry() CU_get_registry()
/** Deprecated (version 1). @deprecated Use CU_set_registry(). */
#define set_registry(reg) CU_set_registry((reg))
/** Deprecated (version 1). @deprecated Use CU_get_suite_by_name(). */
#define get_group_by_name(group, reg) CU_get_suite_by_name(group, reg)
/** Deprecated (version 1). @deprecated Use CU_get_test_by_name(). */
#define get_test_by_name(test, group) CU_get_test_by_name(test, group)
/** Deprecated (version 1). @deprecated Use ADD_TEST_TO_SUITE. */
#define ADD_TEST_TO_GROUP(group, test) (CU_add_test(group, #test, (CU_TestFunc)test))
#endif /* USE_DEPRECATED_CUNIT_NAMES */
/* Internal CUnit system functions. Should not be routinely called by users. */
CU_EXPORT CU_pTestRegistry CU_get_registry(void);
CU_EXPORT CU_pTestRegistry CU_set_registry(CU_pTestRegistry pTestRegistry);
CU_EXPORT CU_pTestRegistry CU_create_new_registry(void);
CU_EXPORT void CU_destroy_existing_registry(CU_pTestRegistry* ppRegistry);
CU_EXPORT CU_pSuite CU_get_suite_by_name(const char* szSuiteName, CU_pTestRegistry pRegistry);
CU_EXPORT CU_pTest CU_get_test_by_name(const char* szTestName, CU_pSuite pSuite);
#ifdef CUNIT_BUILD_TESTS
void test_cunit_TestDB(void);
#endif
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_TESTDB_H_SEEN */
/** @} */

View File

@@ -0,0 +1,193 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004,2005,2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains Interface to Run tests.
*
* Aug 2001 Initial implementation. (AK)
*
* 09/Aug/2001 Contains generic run tests interface which can be used
* for any type of frontend interface framework. (AK)
*
* 24/Nov/2001 Added Handler for Group Initialization failure condition. (AK)
*
* 05-Aug-2004 New interface. Since these should be internal functions,
* no support for deprecated version 1 names provided now,
* eliminated global variables for current test & suite,
* moved (renamed) _TestResult here from TestDB.h. (JDS)
*
* 05-Sep-2004 Added internal test interface. (JDS)
*/
/** @file
* Test run management functions (user interface).
* The TestRun module implements functions supporting the running
* of tests elements (suites and tests). This includes functions for
* running suites and tests, retrieving the number of tests/suites run,
* and managing callbacks during the run process.
*
* <P>The callback mechanism works as follows. The CUnit runtime system
* supports the registering and calling of functions at the start and end
* of each test, when all tests are complete, and when a suite
* initialialization function returns an error. This allows clients to
* perform actions associated with these events such as output formatting
* and reporting.</P>
*/
/** @addtogroup Framework
* @{
*/
#ifndef CUNIT_TESTRUN_H_SEEN
#define CUNIT_TESTRUN_H_SEEN
#include "CUnit.h"
#include "CUError.h"
#include "TestDB.h"
#ifdef __cplusplus
extern "C" {
#endif
/* CU_FailureRecord type definition. */
/** Data type for holding assertion failure information (linked list). */
typedef struct CU_FailureRecord
{
unsigned int uiLineNumber; /**< Line number of failure. */
char* strFileName; /**< Name of file where failure occurred. */
char* strCondition; /**< Test condition which failed. */
CU_pTest pTest; /**< Test containing failure. */
CU_pSuite pSuite; /**< Suite containing test having failure. */
struct CU_FailureRecord* pNext; /**< Pointer to next record in linked list. */
struct CU_FailureRecord* pPrev; /**< Pointer to previous record in linked list. */
} CU_FailureRecord;
typedef CU_FailureRecord* CU_pFailureRecord; /**< Pointer to CU_FailureRecord. */
/* CU_RunSummary type definition. */
/** Data type for holding statistics and assertion failures for a test run. */
typedef struct CU_RunSummary
{
unsigned int nSuitesRun; /**< Number of suites completed during run. */
unsigned int nSuitesFailed; /**< Number of suites for which initialization failed. */
unsigned int nTestsRun; /**< Number of tests completed during run. */
unsigned int nTestsFailed; /**< Number of tests containing failed assertions. */
unsigned int nAsserts; /**< Number of assertions tested during run. */
unsigned int nAssertsFailed; /**< Number of failed assertions. */
unsigned int nFailureRecords; /**< Number of failure records generated. */
} CU_RunSummary;
typedef CU_RunSummary* CU_pRunSummary; /**< Pointer to CU_RunSummary. */
/* Type Definitions for Message Handlers. */
/** Message handler called at the start of a test.
* The parameters are the test and suite being run.
* The test run is considered in progress when the
* message handler is called. Neither pTest nor
* pSuite may be null.
*/
typedef void (*CU_TestStartMessageHandler)(const CU_pTest pTest, const CU_pSuite pSuite);
/** Message handler called at the completion of a test.
* The parameters are the test and suite being run, plus
* a pointer to the first failure record applicable to
* this test. If the test did not have any assertion
* failures, pFailure will be NULL.
* The test run is considered in progress when the
* message handler is called.
*/
typedef void (*CU_TestCompleteMessageHandler)(const CU_pTest pTest, const CU_pSuite pSuite,
const CU_pFailureRecord pFailure);
/** Message handler called at the completion of a test run.
* The parameter is a pointer to the linked list holding
* the failure records for the test run.
* The test run is considered completed when the
* message handler is called.
*/
typedef void (*CU_AllTestsCompleteMessageHandler)(const CU_pFailureRecord pFailure);
/** Message handler called when a suite initializer fails.
* The test run is considered in progress when the
* message handler is called.
*/
typedef void (*CU_SuiteInitFailureMessageHandler)(const CU_pSuite pSuite);
/** Message handler called when a suite cleanup function fails.
* The test run is considered in progress when the
* message handler is called.
*/
typedef void (*CU_SuiteCleanupFailureMessageHandler)(const CU_pSuite pSuite);
/* Get/Set functions for Message Handlers. */
CU_EXPORT void CU_set_test_start_handler(CU_TestStartMessageHandler pTestStartMessage);
CU_EXPORT void CU_set_test_complete_handler(CU_TestCompleteMessageHandler pTestCompleteMessage);
CU_EXPORT void CU_set_all_test_complete_handler(CU_AllTestsCompleteMessageHandler pAllTestsCompleteMessage);
CU_EXPORT void CU_set_suite_init_failure_handler(CU_SuiteInitFailureMessageHandler pSuiteInitFailureMessage);
CU_EXPORT void CU_set_suite_cleanup_failure_handler(CU_SuiteCleanupFailureMessageHandler pSuiteCleanupFailureMessage);
CU_EXPORT CU_TestStartMessageHandler CU_get_test_start_handler(void);
CU_EXPORT CU_TestCompleteMessageHandler CU_get_test_complete_handler(void);
CU_EXPORT CU_AllTestsCompleteMessageHandler CU_get_all_test_complete_handler(void);
CU_EXPORT CU_SuiteInitFailureMessageHandler CU_get_suite_init_failure_handler(void);
CU_EXPORT CU_SuiteCleanupFailureMessageHandler CU_get_suite_cleanup_failure_handler(void);
/* Functions for running registered tests and suites. */
CU_EXPORT CU_ErrorCode CU_run_all_tests(void);
CU_EXPORT CU_ErrorCode CU_run_suite(CU_pSuite pSuite);
CU_EXPORT CU_ErrorCode CU_run_test(CU_pSuite pSuite, CU_pTest pTest);
/* Functions for getting information about the previous test run. */
CU_EXPORT unsigned int CU_get_number_of_suites_run(void);
CU_EXPORT unsigned int CU_get_number_of_suites_failed(void);
CU_EXPORT unsigned int CU_get_number_of_tests_run(void);
CU_EXPORT unsigned int CU_get_number_of_tests_failed(void);
CU_EXPORT unsigned int CU_get_number_of_asserts(void);
CU_EXPORT unsigned int CU_get_number_of_successes(void);
CU_EXPORT unsigned int CU_get_number_of_failures(void);
CU_EXPORT unsigned int CU_get_number_of_failure_records(void);
CU_EXPORT CU_pFailureRecord CU_get_failure_list(void);
CU_EXPORT CU_pRunSummary CU_get_run_summary(void);
/* Functions for internal & testing use. */
CU_EXPORT CU_pSuite CU_get_current_suite(void);
CU_EXPORT CU_pTest CU_get_current_test(void);
CU_EXPORT CU_BOOL CU_is_test_running(void);
CU_EXPORT void CU_clear_previous_results(void);
/* Assertion implementation function. */
CU_EXPORT CU_BOOL CU_assertImplementation(CU_BOOL bValue,
unsigned int uiLine,
char strCondition[],
char strFile[],
char strFunction[],
CU_BOOL bFatal);
#ifdef USE_DEPRECATED_CUNIT_NAMES
typedef CU_FailureRecord _TestResult; /**< @deprecated Use CU_FailureRecord. */
typedef CU_pFailureRecord PTestResult; /**< @deprecated Use CU_pFailureRecord. */
#endif /* USE_DEPRECATED_CUNIT_NAMES */
#ifdef CUNIT_BUILD_TESTS
void test_cunit_TestRun(void);
#endif
#ifdef __cplusplus
}
#endif
#endif /* CUNIT_TESTRUN_H_SEEN */
/** @} */

View File

@@ -0,0 +1,87 @@
/*
* CUnit - A Unit testing framework library for C.
* Copyright (C) 2001 Anil Kumar
* Copyright (C) 2004,2005,2006 Anil Kumar, Jerry St.Clair
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Contains Type Definitions for some generic functions used across
* CUnit project files.
*
* 13/Oct/2001 Moved some of the generic functions declarations from
* other files to this one so as to use the functions
* consitently. This file is not included in the distribution
* headers because it is used internally by CUnit. (AK)
*
* 20-Jul-2004 New interface, support for deprecated version 1 names. (JDS)
*
* 5-Sep-2004 Added internal test interface. (JDS)
*/
/** @file
* Utility functions (user interface).
*/
/** @addtogroup Framework
* @{
*/
#ifndef CUNIT_UTIL_H_SEEN
#define CUNIT_UTIL_H_SEEN
#include "CUnit.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Maximum string length. */
#define CUNIT_MAX_STRING_LENGTH 1024
/** maximum number of characters in a translated xml entity. */
#define CUNIT_MAX_ENTITY_LEN 5
CU_EXPORT int CU_translate_special_characters(const char* szSrc, char* szDest, size_t maxlen);
CU_EXPORT int CU_compare_strings(const char* szSrc, const char* szDest);
CU_EXPORT void CU_trim_left(char* szString);
CU_EXPORT void CU_trim_right(char* szString);
CU_EXPORT void CU_trim(char* szString);
#ifdef CUNIT_BUILD_TESTS
void test_cunit_Util(void);
#endif
#ifdef __cplusplus
}
#endif
#ifdef USE_DEPRECATED_CUNIT_NAMES
/** Deprecated (version 1). @deprecated Use CU_translate_special_characters(). */
#define translate_special_characters(src, dest, len) CU_translate_special_characters(src, dest, len)
/** Deprecated (version 1). @deprecated Use CU_compare_strings(). */
#define compare_strings(src, dest) CU_compare_strings(src, dest)
/** Deprecated (version 1). @deprecated Use CU_trim_left(). */
#define trim_left(str) CU_trim_left(str)
/** Deprecated (version 1). @deprecated Use CU_trim_right(). */
#define trim_right(str) CU_trim_right(str)
/** Deprecated (version 1). @deprecated Use CU_trim(). */
#define trim(str) CU_trim(str)
#endif /* USE_DEPRECATED_CUNIT_NAMES */
#endif /* CUNIT_UTIL_H_SEEN */
/** @} */

Binary file not shown.

File diff suppressed because it is too large Load Diff