Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2085826
  • 博文数量: 414
  • 博客积分: 10312
  • 博客等级: 上将
  • 技术积分: 4921
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-31 01:49
文章分类

全部博文(414)

文章存档

2011年(1)

2010年(29)

2009年(82)

2008年(301)

2007年(1)

分类: C/C++

2010-07-15 13:59:28

thread Task Call Sequcence

//Task的excutor的exucete的示例

void SM_ClientSessionSetupRequestTask :: Execute( void )
{


   GetApp()->GetOperationalMode() != OperationalMode_Primary ? True:false // If not operating as a Primary SM (e.g. switching to standby), reject the request


   int Result = VerifySetupRequest( DSMCC_ResponseCode ); // Extract parameters and verify SETUP request


   if( CleanupOrphanSession() ) return;

   // Session DB

   SMS_WaitServerAddResourceRequest;
   Session.SessionStates.ClientSessionState.SetState( GSRM_ClientSessionSetupRequest );
   AddSession( Session ); // 数据表填充

   UpdateSessionTimeout( Session, NewTimeout ); // 表入库

   SetupBmsSession( m_Session, DSMCC_ResponseCode );
   DsmccMessage->GetPrivateDataFormat() == #FORMAT //设定读写

       
   SendClientProceedingIndication( Session, DSMCC_RSP_CL_SESSION_PROCEED ); //调用TCP/IP SOCKET 发送 数据包


   return;
}

//Task的库表操作示例

int SM_CommTask :: SetupBmsSession(GSRM_SessionRecord & Session, unsigned short & DSMCC_ResponseCode )
{
   DSMCC_ResponseCode = DSMCC_RSP_OK;
   //lf: 表GetDeviceInfoTable

   GetApp()->GetSessionLogger();
   GetApp()->GetDeviceInfoTable(); //读取 DeviceInfoTable;Get the BMS device information

   /** Returns the specified record. 参数 GSRM_DeviceInfoRecord & Record 为 IN_OUT*/
   int GSRM_DeviceTable :: GetDeviceByAddress( SocketTypes SocketType, unsigned long DeviceIpAddress, unsigned short DevicePort, GSRM_DeviceInfoRecord & Record )
   {
        m_Lock.Lock();
      FindByAddress( SocketType, DeviceIpAddress, DevicePort ); //lf: 查表

      m_Lock.Unlock();
   }


   //lf:表TimingStatisticsTable

   SM_CommTask :: IncProcCommErrors(int DeviceType, int MsgType )
       {
            GSRM_TimingStatisticsTable * pStatsTable = GetApp()->GetDatabase()->GetTimingStatisticsTable();//lf: 寻表

            pStatsTable->AddTimingData( GSRM_DEVICE_TYPE_CLIENT, MsgType, GSRM_RESULT_TYPE_COMMERROR, 0 ); //插入数据

         //lf: 临界区

            GSRM_TimingStatisticsTable :: AddTimingData
            {
                    Lock.Lock();
                    
                        //lf: 数据库操作

                        if (已有StartTime节点 )
                     {
                            match->second.AddTimingData( DeviceTypeId, MsgTypeId, ResultTypeId, Duration );
                 }
                 else if (没有StartTime节点){
                      // 数据持久化

         GSRM_TimingStatsTimeSlice :: GSRM_TimingStatsTimeSlice( time_t StartTime )// *    This file defines a class to track Session Manager timing statistics in 15-minute blocks. It persists this data to the database and reloads a portion on startup so that statistics are available to the web pages.

                     // This method adds timing data to the current time slice. The caller specifies the type of timing data (setup success, setup failure, etc.) and the duration of the event in ms.

         bool GSRM_TimingStatsTimeSlice :: AddTimingData( unsigned long DeviceTypeId, unsigned long MsgTypeId, unsigned long ResultTypeId, unsigned long Duration );
         insert( std::make_pair( TimeSlice.StartTime, TimeSlice )); //lf: 为什么既 AddTimingData 又 insert?哪一个是插入操作,上面的有节点的只用了AddTimingData啊

     }
           //lf: 这里为什么又加了一次?

     m_OverallStats.AddTimingData( DeviceTypeId, MsgTypeId, ResultTypeId, Duration );

     m_Lock.Unlock();
        }
       }

   //lf: 表GSRM_SessionRecord

    void LogSetupTransaction( GSRM_SessionRecord &Session, unsigned short ResultCode, time_t SetupTime = 0 ); // This method uses some of the the Session parameters and the ResultCode to create and send a message to LogSessionData()


   // lf: 生成CSSR消息

   // We are processing a Client Session Setup Request.

   (DSMCC_ClientSessionSetupRequest *)DSMCC_SessionSocketMessage;

   //lf: TCP socket management

   // Create a unique transaction ID for this request.

   unsigned long SM_DSMCC_SocketManager::GetNextTcpTransactionNo( unsigned long Addr, unsigned short Port ) // Helper method which retreived Transaction IDs from the TCP Socket Manager

   {
       unsigned long DSMCC_TcpSocketManager :: GetNextTransactionNo(unsigned long IP_Address, unsigned short Port )
       {
            //lf 使用port和key构造出key

            Key( IP_Address, Port ); //Tracks sequence numbers based on the IP address and port of the DSMCC proxy/server. These are never cleared, so all message sequence numbers are unique by host, no matter how many sockets are used.

            Mutex.Lock()
           //lf 表DSMCC_TransactionNoMap

           DSMCC_TransactionNoMap::find()
           Unlock()
           & 0x3FFFFFFF //取得58个自节

       }
     }
    
   bool MacAddress48 :: ParseMacAddressString( const char * pText )//Extract the MAC Address from the Cient ID to build the message.


   //lf: 生成SSSI消息

   DSMCC_ServerSessionSetupIndication * pInd = new DSMCC_ServerSessionSetupIndication(); //Create SSSI which will inform the Purchase Server that we are setting up a session using the token previously created for the On-Demand Client during menu navigation


   //If session format is CHINA_E2E, set Stream Server Ip address as private data

   if( "CHINA_E2E_Format" )
   {
         //lf: 表GSRM_SGtoSSOMappingTable

      GSRM_SGtoSSOMappingTable * GSRM_Database :: GetSGtoSSOMappingTable( void )
      {
          GSRM_SGtoSSOMappingTable :: GSRM_SGtoSSOMappingTable( DBConnectionPool* pConPool )
        {
             typedef std::multimap< unsigned long, CStdString > SGtoSSOMappingMap
             DataChangeBroadcaster :: DataChangeBroadcaster( int TableId )
                //lf 具体的对数据库表的操作的编译后的inline方法的尸体

                  "SELECT ID,USER_SERVICE_GROUP_ID, STREAMING_SERVER_OUTPUT_NAME, STREAMING_SERVER_OUTPUT FROM SGTOSSOMAPPING ";
          "INSERT INTO SGTOSSOMAPPING ( USER_SERVICE_GROUP_ID,STREAMING_SERVER_OUTPUT_NAME,STREAMING_SERVER_OUTPUT ) VALUES ( %lu,'%s','%s' )";
          "INSERT INTO SGTOSSOMAPPING ( ID, USER_SERVICE_GROUP_ID, STREAMING_SERVER_OUTPUT_NAME, STREAMING_SERVER_OUTPUT ) VALUES ( %lu, %lu, '%s','%s' )";
          "UPDATE SGTOSSOMAPPING SET USER_SERVICE_GROUP_ID = %lu, STREAMING_SERVER_OUTPUT_NAME='%s', STREAMING_SERVER_OUTPUT = '%s' WHERE ID = %lu";
          "DELETE FROM SGTOSSOMAPPING WHERE ID = %lu";
          "TRUNCATE TABLE SGTOSSOMAPPING";
        }
      }
      bool DSMCC_SessionSocketMessage :: GetNodeGroupId(DSMCC_NodeGroupId & NodeGroupId ) //确定SGid

            SG.SG.ServiceGroup = ntohl( SG.SG.ServiceGroup ); //设定SG

            
            //从VOD读取媒体数据流指令

            unsigned long GetStreamingServerOutputbySGID( StreamingServerOutputSet & Set, unsigned long sgID ); // Returns the specified record number.

            GSRM_SGtoSSOMappingTable::GetStreamingServerOutputbySGID( SSOSet, SG.SG.ServiceGroup );

         //填充 DSMCC_StreamServer 消息尸体的UPD部分

         DSMCC_StreamServerEntry Entry;
         for( each in SSOSet)
         {
                ServerIpAddress = *it;
                Entry.Clear();
                Entry.Priority = 0;
                Entry.Reserved = 0xFFFF;
                Entry.ServerIdLength = ServerIpAddress.size();    
          Entry.ServerId = new unsigned char[ Entry.ServerIdLength ];
      
              void DSMCC_SessionSocketMessage :: SetStreamServer( DSMCC_StreamServerEntry & Entry )
              {
                  //lf: 内存数据库操作

             set.insert( DSMCC_STREAM_SERVER_DESCRIPTOR_TAG );
             list.push_back( Entry );    
              }    
      }
      
         //Set ServerSessionSetupIndication message as CHINA_E2E format; 即: pInd->SetPrivateDataFormat( CHINA_E2E_Format );

      void SetPrivateDataFormat( DSMCC_PrivateDataHeaderFormat Format ) //Changes the private data format used to build new messages. This MUST be set prior to calling BuildMessage.

   }

   //将前面设定的各种消息内容,写入新的SSSI的信息实体中

   pInd->BuildMessage( (DSMCC_ClientSessionSetupRequest *)DsmccMessage, DSMCC_TxNo );
   

   //lf: 完整的构造出SSRI消息二进制实体,根据CSSR

   int DSMCC_ServerSessionSetupIndication :: BuildMessage( DSMCC_ClientSessionSetupRequest * pReq, unsigned long TransactionId ) // // Constructs a DSMCC Session Setup Request message based the information in the specified DSMCC_ClientSessionSetupRequest message.

   {
        int DSMCC_SessionSocketMessage::Initialize( unsigned long TransactionIdOriginator, unsigned long TransactionNumber,unsigned short MessageDiscriminator, unsigned short MessageScenario,unsigned short MessageType ) //Initializes the header of a DSMCC message.    

        {
           int DSMCC_SessionSocketMessage::Initialize( unsigned char DsmccType, unsigned long TransactionIdOriginator,unsigned long TransactionNumber,unsigned short MessageDiscriminator,unsigned short MessageScenario,unsigned short MessageType )
           {
                DSMCC_SocketMessage::Initialize( unsigned char DsmccType, unsigned long TransactionIdOriginator, unsigned long TransactionNumber, unsigned short MessageId );// Initializes a DSM-CC Session message based on the data provided.

                {
                    //lf: 这里的内容,还没有完全理解透彻,以后反复研究

                     int OutputStream :: AppendBlock( void *& pNewBlock, unsigned long Size )                    //Add the specified amount of space to the buffer, but do not write to the new space. Returns SUCCESS_OK on success or error code on memory allocation failure. If SUCCESS_OK, the pointer to the first byte in the new memory is returned in the outputm parameter.

                     {
                          OutputStream :: GrowStream( unsigned long Size ) // Resets the read pointer.

                     }
                    
                     DSMCC_CommonMsgHeader * pMsg = (DSMCC_CommonMsgHeader*)((void*)pBlock)
                     {
                          // 填充DSMCC_CommonMsgHeader 的二进制message信息的UPD

                          pMsg->ProtocolDiscriminator = DSMCC_PROTOCOL_DISCRIMINATOR;
                                            pMsg->DsmccType = DsmccType;
                                            pMsg->MessageId = htons( MessageId );
                                            pMsg->TransactionId = htonl( TransactionIdOriginator | TransactionNumber );
                                            pMsg->Reserved = 0xFF;
                                        pMsg->AdaptationLength = 0;
                                            pMsg->MessageLength = htons( sizeof( DSMCC_CommonMsgHeader ) );
                     }
                    
                     DSMCC_SocketMessage :: BuildAdaptationField( void ) //Constructs the Adaptation Field based the current data values.

                }
           }
        }     
   }


   //消息实体构造完成,通过TCP/IP发送出去

   DSMCC_SocketManager->TcpSend( Device.SocketId, pInd, DSMCC_DEFAULT_TIMEOUT );
   // 日志记录,

   PS_SetupIndicationSyslogEvent( Session, Device.DeviceIpAddress, Device.DevicePort );
   return SUCCESS_OK;
}

//Task的进行库表查询示例

int GSRM_DeviceTable :: GetDeviceByAddress( SocketTypes SocketType, unsigned long DeviceIpAddress, unsigned short DevicePort, GSRM_DeviceInfoRecord & Record )
{
   m_Lock.Lock();
   
   GSRM_DeviceTable :: FindByAddress( SocketType, DeviceIpAddress, DevicePort )
   {
        for ( iterator it = begin(); it != end(); it++ ) {
        if ( it->second.SocketType != SocketType ) continue;
        if ( it->second.DeviceIpAddress != IpAddress )continue;
        if (( SocketType == SocketType_TCP_Client ) && ( it->second.DevicePort != Port ))continue;
        return it;
     }
   }
   
   m_Lock.Unlock();

}


阅读(1543) | 评论(0) | 转发(0) |
0

上一篇:回调函数

下一篇: 绘制余弦曲线

给主人留下些什么吧!~~