Example #1
0
int CSvrLink::CallBPFunction(MSGBUF *pmb)
{
   AP_REQUEST *preq;
   ST_CPACK rpack={0};
   /* ****** Updated by CHENYH at 2006-3-23 0:37:37 ****** 
   为了能够为具体业务处理模块留出足够的堆栈空间,因此这里采用动态分配空间方式分配
   ST_PACK pArrays[MAXROW]={0};   // 819200 / 在VC下缺省的stack空间本来也就1M (1048576)
   *******************************************************/
   ST_PACK *pArrays; 
   int recs;
   int rtn;
   char szMsg[256];
   char *rdata = pmb->data+sizeof(AP_REQUEST);
   int rdlen = pmb->head.len-sizeof(AP_REQUEST);
   preq = (AP_REQUEST *)(pmb->data);
   ruserid.SourceNo = ntohs(preq->SourceNo); 
   memcpy(&(ruserid.syshead),&(preq->syshead),sizeof(ruserid.syshead));

   if (pProcess!=NULL)
   {
      if (DecodeHead((unsigned char *)rdata,rdlen,&head,szMsg)==sizeof(ST_PACKHEAD))
      {
         memcpy(&reqhead,&head,sizeof(ST_PACKHEAD)); 
         iLastReqType = head.RequestType;
         iAnswerMode = iDefaultAnswerMode;
         eMsg[0]='\0';
         iLastRetCode = 0;
         rtn = (*pProcess)(&ruserid,rdata,rdlen,&iLastRetCode,eMsg);
         DataDone(iLastRetCode,eMsg);
         return(rtn);
      }
   }

   // 2006-3-23 0:56:40 采用动态分配,以少占用堆栈空间
   pArrays = (ST_PACK *)malloc(((CXPack *)GetDefaultXPack())->GetPackLength()*MAXROW);
   if (DecodeBufWithArray((unsigned char *)rdata,rdlen,&rpack,pArrays,&recs,szMsg)>0)
   {
      int fno;
      ASSERT(rpack.head.firstflag==1);  // 只有首包提交下来的。。。。
      memcpy(&reqhead,&(rpack.head),sizeof(ST_PACKHEAD));  // 将请求包头记录下来 2005-9-21 17:35:06

      memcpy(&head,&(rpack.head),sizeof(head));
      
      memset(head.ParmBits,0,sizeof(head.ParmBits));  // 将结果集位图清空
      
      head.recCount = 0;  // Reset the recCount
      
      iLastReqType = rpack.head.RequestType;
      iAnswerMode = iDefaultAnswerMode;
      
      eMsg[0]='\0';
      iLastRetCode = 0;
      
      fno = FindBPFunction(rpack.head.RequestType);
      if (fno>=0 && g_BDefines[fno].pFunc!=NULL)
      {
         unsigned int t1=GetTickCount();
         
         // OK,have found the process function:
#ifdef TESTINFO
         sprintf(szMsg,"Begin to call REQ%u <%s>!",
            rpack.head.RequestType,
            g_BDefines[fno].szRTName);
         DEBUG_RUNTIME_MSGOUT(szMsg);
#endif
         rtn = (*pCallBDFunc)(fno,&ruserid,&rpack,pArrays,&iLastRetCode,eMsg);
         // 如果需要统计功能处理能力,在这里加上。。。
         t1 = tc2_tc1(GetTickCount(),t1);
         DataDone(iLastRetCode,eMsg);
         if (iLastRetCode==0)
         {
            g_BDefines[fno].nSuccess++;
            g_BDefines[fno].dTakentime += t1;
            if (g_BDefines[fno].nSuccess==1)
            {
               g_BDefines[fno].nTt_max = g_BDefines[fno].nTt_min = t1;
            }
            else
            {
               if (g_BDefines[fno].nTt_max<t1)
                  g_BDefines[fno].nTt_max=t1;
               if (g_BDefines[fno].nTt_min>t1)
                  g_BDefines[fno].nTt_min = t1;
            }
         }
         else
            g_BDefines[fno].nFail++;
         //return(rtn);
      }
      else
      {
         iLastReqType = 0;
         iLastRetCode = 0;
         sprintf(szMsg,"BCC提交的请求<%u>在本业务单元中没有对应的处理定义!",
            rpack.head.RequestType);
         DEBUG_RUNTIME_MSGOUT(szMsg);
         rtn = -2;
      }
   }
   else 
   {
      DEBUG_RUNTIME_MSGOUT(szMsg);
      rtn = -1;
   }
   free(pArrays);
   return(rtn);
}
Example #2
0
int CSvrLink::CallBPFunction(MSGBUF *pmb)
{
   AP_REQUEST *preq;
   ST_CPACK rpack;
   // 20040409: QBIN希望能够处理多记录的请求
   ST_PACK pArrays[MAXROW];
   int recs;

   char szMsg[256];
   preq = (AP_REQUEST *)(pmb->data);
   ruserid.SourceNo = ntohs(preq->SourceNo); 
   memcpy(&(ruserid.syshead),&(preq->syshead),sizeof(ruserid.syshead));
   //memcpy(&head,pmb->data+sizeof(AP_REQUEST),sizeof(head));  // 将原始请求的头截获下来,字序按照实际打包字序格式
                       // 这里留个底,也就不用转换字序了

   if (DecodeBufWithArray((unsigned char *)(pmb->data+sizeof(AP_REQUEST)),
      pmb->head.len-sizeof(AP_REQUEST),
      &rpack,pArrays,&recs,szMsg))
   {
      int fno;
      ASSERT(rpack.head.firstflag==1);  // 只有首包提交下来的。。。。
      fno = FindBPFunction(rpack.head.RequestType);
      if (fno>=0 && g_BDefines[fno].pFunc!=NULL)
      {
         int rtn;
         unsigned int t1=GetTickCount();
         memcpy(&head,&(rpack.head),sizeof(head));
      
         memset(head.ParmBits,0,sizeof(head.ParmBits));  // 将结果集位图清空

         head.recCount = 0;  // Reset the recCount

         iLastReqType = rpack.head.RequestType;
         iAnswerMode = iDefaultAnswerMode;
         
         // OK,have found the process function:
#ifdef TESTINFO
         sprintf(szMsg,"Begin to call req%u <%s>!",
            rpack.head.RequestType,
            g_BDefines[fno].szRTName);
         DEBUG_RUNTIME_MSGOUT(szMsg);
#endif
         eMsg[0]='\0';
         iLastRetCode = 0;
/* ****** Updated by CHENYH at 2004-2-21 12:23:30 ****** 
         rtn = g_BDefines[fno].pFunc(
            &ruserid,
            &(rpack.pack),
            &retcode,
            szMsg
            );
*/
         rtn = CallBDFunc(fno,&ruserid,&rpack,pArrays,&iLastRetCode,eMsg);
         // 如果需要统计功能处理能力,在这里加上。。。
         t1 = tc2_tc1(GetTickCount(),t1);
         DataDone(iLastRetCode,eMsg);
         if (iLastRetCode==0)
         {
            g_BDefines[fno].nSuccess++;
            g_BDefines[fno].dTakentime += t1;
            if (g_BDefines[fno].nSuccess==1)
            {
               g_BDefines[fno].nTt_max = g_BDefines[fno].nTt_min = t1;
            }
            else
            {
               if (g_BDefines[fno].nTt_max<t1)
                  g_BDefines[fno].nTt_max=t1;
               if (g_BDefines[fno].nTt_min>t1)
                  g_BDefines[fno].nTt_min = t1;
            }
         }
         else
            g_BDefines[fno].nFail++;
         return(rtn);
      }
      else
      {
         iLastReqType = 0;
         iLastRetCode = 0;
         sprintf(szMsg,"BCC提交的请求<%u>在本业务单元中没有对应的处理定义!",
            rpack.head.RequestType);
         DEBUG_RUNTIME_MSGOUT(szMsg);
         return(-2);
      }
   }
   else
   {
      DEBUG_RUNTIME_MSGOUT(szMsg);
      return(-1);
   }
}