📄 ss7_mtp2_array.cpp~
字号:
// pSUnLen->len, pSUnLen->header.LI ); // copy to corresponding recvBuffer ptrSS7Mtp2Array->mtp2Array[pRevSU->ChName].recvBuffer.write( (unsigned char *) pSUnLen, sizeof(unsigned short) + pSUnLen->len );
// notify the reception of SU to DAEDR: SU Received
event_out.FSMType = MTP2_FSM_DAEDR; event_out.name = DAEDREventSUReceived; event_out.param = REV_SU_CORRECT; // to read SU from recvBuffer ptrSS7Mtp2Array->mtp2Array[pRevSU->ChName].eventQueue.write( (unsigned char*)(&event_out), sizeof(event_out)); } if( posForNextSU == len ) // processed all bytes
{ // printf( "Processed all bytes\n" ); posForNextSU = 0;
break;
}
}
}
free( pRevSU ); free( pSUnLen ); //UT: uncomment the following line
// close( ptrSS7Mtp2Array->getDevfd() ); return NULL;
}
void * checkTimers(void * arg)
{
printf("beginning checkTimers()!\n"); SS7_MTP2_Array * ptrSS7Mtp2Array = (SS7_MTP2_Array *) arg;
while( ! ptrSS7Mtp2Array->toTerminate )
{
for(int i = 0 ; i < ptrSS7Mtp2Array->mtp2_port_count ; i++ )
{
ptrSS7Mtp2Array->mtp2Array[i].checkTimers( );
}
// have a rest here for transmitting usleep( 100000 ); // 100ms
// printf("checkTimers() - after usleep\n");
}
return NULL;}
void * updateMTP2FSMs(void * arg)
{
printf("beginning updateMTP2FSMs()!\n"); SS7_MTP2_Array * ptrSS7Mtp2Array = (SS7_MTP2_Array *) arg;
while( ! ptrSS7Mtp2Array->toTerminate )
{
for(int i = 0 ; i < ptrSS7Mtp2Array->mtp2_port_count ; i++ )
{
ptrSS7Mtp2Array->mtp2Array[i].updateStates( );
}
// Where to set the flag "toTerminate"? // -- do we need run "this" function in a separate thread?
// have a rest here for about 50ms ? usleep( 20000 ); // printf("updateMTP2FSMs() -- after usleep\n");
}
return NULL;}
int SS7_MTP2_Array::run(void){
printf("Get into SS7_MTP2_Array::run()!\n"); // open the device
/*********************************************
devfd = open("/dev/ss7Gw", O_RDWR);
if (devfd < 0) {
perror("ss7gate: open");
return -1;
}
FD_ZERO( & rdfdset );
FD_ZERO( & wrfdset );
FD_SET( devfd, & rdfdset );
FD_SET( devfd, & wrfdset );
maxfd = devfd;
*********************************/ // set devfd, maxfd, wrfdset, rdfdset to SS7_MTP2 for(int i = 0 ; i < mtp2_port_count ; i++ )
{
mtp2Array[i].setRdfSet( & rdfdset );
mtp2Array[i].setWrfSet( & wrfdset );
mtp2Array[i].setDevfd( devfd );
mtp2Array[i].setMaxfd( maxfd );
}
// power on each link
printf("power on & start each link ... !\n");
for(int i = 0 ; i < mtp2_port_count ; i++ )
{
mtp2Array[i].LSC( LSCEventPowerOn, 0 ); // MGMT
mtp2Array[i].LSC( LSCEventStart, 0 ); // L3 could start elsewhere
}
printf("create thread for timer checking ... !\n"); if( pthread_create( & threadCheckTimers, NULL, checkTimers, this ) != 0 ) { printf("Failed to create thread for timer checking!\n"); }
// start the MsgTransmissionL2ToL1 thread
// which will check Link State, if In Service, send MSUs out
// it also handles the error correction via re-transimission, under the help of RC
// MsgTransmissionL2ToL1 will loop through each TB/RTB to send MSUs in its buffer, we may need
// to regulate the rule for balance among the links, e.g. only send one MSU or send
// out all MSUs in one round?
// int retTXC = pthread_create( & threadTransmit,// NULL, TransmitMsg, this );
// start the RC thread
// which will check Link State, if not PowerOff, try to receive data form MTP-1
// then distribute the data to corresponding MTP-2 instance based on the port-number
// RC (or LSC?) will check the message and perform corresponding actions (in real time)
// [if use LSC to handle received message, have to tolerate the delay]
// loop to "update" the Finite State Machines
printf("create FSM state updating thread ... !\n"); if( pthread_create( & threadUpdateMTP2FSMs, NULL, updateMTP2FSMs, this ) != 0 ) { printf("Failed to create FSM state updating thread!\n"); } // start the RC thread
// which will check Link State, if not PowerOff, try to receive data form MTP-1
// then distribute the data to corresponding MTP-2 instance based on the port-number
// RC (or LSC?) will check the message and perform corresponding actions (in real time)
// [if use LSC to handle received message, have to tolerate the delay]
printf("create receiving thread ... !\n"); if( pthread_create( & threadReceive, NULL, ReceiveMsg, this ) != 0 ) { printf("Failed to create receiving thread!\n"); }
return 0;}void SS7_MTP2_Array::terminate()
{
printf("SS7_MTP2_Array::terminate() ... !\n"); toTerminate = true;
}
// join the four threads safely before exiting
int SS7_MTP2_Array::joinThread(){/********************************
#include <pthread.h> pthread_join - wait for termination of another thread int pthread_join(pthread_t th, void **thread_return); DESCRIPTION pthread_join suspends the execution of the calling thread until the thread identified by th terminates, either by calling pthread_exit(3) or by being cancelled. If thread_return is not NULL, the return value of th is stored in the location pointed to by thread_return. The return value of th is either the argument it gave to pthread_exit(3), or PTHREAD_CANCELED if th was cancelled. The joined thread th must be in the joinable state: it must not have been detached using pthread_detach(3) or the PTHREAD_CREATE_DETACHED attribute to pthread_create(3). When a joinable thread terminates, its memory resources (thread descriptor and stack) are not deallocated until another thread performs pthread_join on it. Therefore, pthread_join must be called once for each joinable thread created to avoid memory leaks. At most one thread can wait for the termination of a given thread. Calling pthread_join on a thread th on which another thread is already waiting for termination returns an error.CANCELLATION pthread_join is a cancellation point. If a thread is canceled while suspended in pthread_join, the thread execution resumes immediately and the cancellation is executed without waiting for the th thread to ter- minate. If cancellation occurs during pthread_join, the th thread remains not joined.RETURN VALUE On success, the return value of th is stored in the location pointed to by thread_return, and 0 is returned. On error, a non-zero error code is returned.ERRORS ESRCH No thread could be found corresponding to that specified by th. EINVAL The th thread has been detached. EINVAL Another thread is already waiting on termination of th. EDEADLK The th argument refers to the calling thread. *********************************/ return 0;}int SS7_MTP2_Array::sendMessage(unsigned char * _data, int _count, int _portNumber ){
this->mtp2Array[_portNumber].sendMessage( _data, _count );
return 0;}
int SS7_MTP2_Array::readMessage(unsigned char * _buffer, int _len, int _portNumber)
{
this->mtp2Array[_portNumber].readMesssage( _buffer, _len );
return 0;
}int SS7_MTP2_Array::L3Start(void){ return 0;}
int SS7_MTP2_Array::L3Stop(void){ return 0;}
int SS7_MTP2_Array::L3RetrieveBSNT(void){ return 0;}
int SS7_MTP2_Array::L3RetrievalRequestAndFSNC(void){ return 0;}
int SS7_MTP2_Array::L3FlushBuffers(void){ return 0;}
int SS7_MTP2_Array::L3Continue(void){ return 0;}
int SS7_MTP2_Array::L3Emergency(void){ return 0;}
int SS7_MTP2_Array::L3EmergencyCease(void){ return 0;}
int SS7_MTP2_Array::L3LocalProcRecovered(void){ return 0;}
int SS7_MTP2_Array::L3Msg4Transmission(void){ return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -