NdbApiSignal.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:8k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. #include "API.hpp"
  14. #include "NdbApiSignal.hpp"
  15. /**
  16.  * The following include includes
  17.  *  definitions directly from the kernel
  18.  *
  19.  * Definitions that is shared between kernel and the API
  20.  */
  21. #include <signaldata/TcKeyReq.hpp>
  22. #include <signaldata/KeyInfo.hpp>
  23. #include <signaldata/AttrInfo.hpp>
  24. #include <signaldata/TestOrd.hpp>
  25. #include <signaldata/CreateIndx.hpp>
  26. #include <signaldata/DropIndx.hpp>
  27. #include <signaldata/TcIndx.hpp>
  28. #include <signaldata/IndxKeyInfo.hpp>
  29. #include <signaldata/IndxAttrInfo.hpp>
  30. #include <signaldata/TcHbRep.hpp>
  31. #include <signaldata/ScanTab.hpp>
  32. #include <NdbOut.hpp>
  33. /******************************************************************************
  34. NdbApiSignal();
  35. Return Value:   None  
  36. Remark:         Creates a NdbApiSignal object. 
  37. ******************************************************************************/
  38. NdbApiSignal::NdbApiSignal(BlockReference ref)
  39. {
  40.   theVerId_signalNumber   = 0;    // 4 bit ver id - 16 bit gsn
  41.   theReceiversBlockNumber = 0;  // Only 16 bit blocknum  
  42.   theSendersBlockRef      = refToBlock(ref);
  43.   theLength               = 0;
  44.   theSendersSignalId      = 0;
  45.   theSignalId             = 0;
  46.   theTrace                = 0;
  47.   m_noOfSections          = 0;
  48.   m_fragmentInfo          = 0;
  49.   for (int i = 0; i < 25; i++)
  50.     theData[i] = 0x13579753;
  51.   
  52.   setDataPtr(&theData[0]);
  53.   theNextSignal = 0;
  54. }
  55. NdbApiSignal::NdbApiSignal(Ndb* ndb)
  56. {
  57.   BlockReference ref = ndb->theMyRef;
  58.   theVerId_signalNumber   = 0;    // 4 bit ver id - 16 bit gsn
  59.   theReceiversBlockNumber = 0;  // Only 16 bit blocknum  
  60.   theSendersBlockRef      = refToBlock(ref);
  61.   theLength               = 0;
  62.   theSendersSignalId      = 0;
  63.   theSignalId             = 0;
  64.   theTrace                = 0;
  65.   m_noOfSections          = 0;
  66.   m_fragmentInfo          = 0;
  67.   for (int i = 0; i < 25; i++)
  68.     theData[i] = 0x13579753;
  69.   
  70.   setDataPtr(&theData[0]);
  71.   theNextSignal = 0;
  72. }
  73. /**
  74.  * Copy constructor
  75.  */
  76. NdbApiSignal::NdbApiSignal(const NdbApiSignal &src) {
  77.   copyFrom(&src);
  78. }
  79. /******************************************************************************
  80. ~NdbApiSignal();
  81. Return Value:   None  
  82. Remark:         Delete a NdbApiSignal object.
  83. ******************************************************************************/
  84. NdbApiSignal::~NdbApiSignal()
  85. }
  86. /******************************************************************************
  87. int setSignal(NdbSignalType aNdbSignalType);
  88. Return Value:   Return 0 : setSignal was successful.
  89.                 Return tErrorCode In all other case. 
  90. Parameters:     aNdbSignalType: Type of signal.
  91. Remark:         Set signal header and allocate 128 byte. 
  92. ******************************************************************************/
  93. int 
  94. NdbApiSignal::setSignal(int aNdbSignalType)
  95.   theSendersSignalId = 0;
  96.   switch (aNdbSignalType)
  97.   {
  98.     case GSN_DIHNDBTAMPER:
  99.     {
  100.       theTrace                = TestOrd::TraceAPI;
  101.       theReceiversBlockNumber = DBDIH;
  102.       theVerId_signalNumber   = GSN_DIHNDBTAMPER;
  103.       theLength               = 3;
  104.     }
  105.     break;
  106.     case GSN_TCSEIZEREQ:
  107.     {
  108.       theTrace                = TestOrd::TraceAPI;
  109.       theReceiversBlockNumber = DBTC;
  110.       theVerId_signalNumber   = GSN_TCSEIZEREQ;
  111.       theLength               = 2;
  112.     }
  113.     break;
  114.     case GSN_TCKEYREQ:
  115.     {
  116.       theTrace                = TestOrd::TraceAPI;
  117.       theReceiversBlockNumber = DBTC;
  118.       theVerId_signalNumber   = GSN_TCKEYREQ;
  119.       theLength               = TcKeyReq::SignalLength;
  120.     }
  121.     break;
  122.     case GSN_TCRELEASEREQ:
  123.     {
  124.       theTrace                = TestOrd::TraceAPI;
  125.       theReceiversBlockNumber = DBTC;
  126.       theVerId_signalNumber   = GSN_TCRELEASEREQ;
  127.       theLength               = 3;
  128.     }
  129.     break;
  130.     case GSN_ATTRINFO:
  131.     {
  132.       theTrace                = TestOrd::TraceAPI;
  133.       theReceiversBlockNumber = DBTC;
  134.       theVerId_signalNumber   = GSN_ATTRINFO;
  135.       theLength               = AttrInfo::MaxSignalLength;
  136.     }
  137.     break;
  138.     
  139.     case GSN_KEYINFO:
  140.     {
  141.       theTrace                = TestOrd::TraceAPI;
  142.       theReceiversBlockNumber = DBTC;
  143.       theVerId_signalNumber = GSN_KEYINFO;
  144.       theLength               = KeyInfo::MaxSignalLength; 
  145.     }
  146.     break;
  147.     case GSN_TCROLLBACKREQ:
  148.     {
  149.       theTrace                = TestOrd::TraceAPI;
  150.       theReceiversBlockNumber = DBTC;
  151.       theVerId_signalNumber   = GSN_TCROLLBACKREQ;
  152.       theLength               = 3;
  153.     }
  154.     break;
  155.     case GSN_TC_HBREP:
  156.     {
  157.       theTrace                = TestOrd::TraceAPI;
  158.       theReceiversBlockNumber = DBTC;
  159.       theVerId_signalNumber   = GSN_TC_HBREP;
  160.       theLength               = TcHbRep::SignalLength;
  161.     }
  162.     break;
  163.     case GSN_TC_COMMITREQ:
  164.     {
  165.       theTrace                = TestOrd::TraceAPI;
  166.       theReceiversBlockNumber = DBTC;
  167.       theVerId_signalNumber   = GSN_TC_COMMITREQ;
  168.       theLength               = 3;
  169.     }
  170.     break;
  171.     case GSN_SCAN_TABREQ:
  172.     {
  173.       theTrace                = TestOrd::TraceAPI;
  174.       theReceiversBlockNumber = DBTC;
  175.       theVerId_signalNumber   = GSN_SCAN_TABREQ;
  176.       theLength               = ScanTabReq::StaticLength;      
  177.     }
  178.     break;
  179.     case GSN_SCAN_NEXTREQ:
  180.     {
  181.       theTrace                = TestOrd::TraceAPI;
  182.       theReceiversBlockNumber = DBTC;
  183.       theVerId_signalNumber   = GSN_SCAN_NEXTREQ;
  184.       theLength               = ScanNextReq::SignalLength;
  185.     }
  186.     break;
  187.     case GSN_CREATE_INDX_REQ:
  188.     {
  189.       theTrace                = TestOrd::TraceAPI;
  190.       theReceiversBlockNumber = DBDICT;
  191.       theVerId_signalNumber   = GSN_CREATE_INDX_REQ;
  192.       theLength               = CreateIndxReq::SignalLength;   
  193.     }
  194.     break;
  195.     case GSN_DROP_INDX_REQ:
  196.     {
  197.       theTrace                = TestOrd::TraceAPI;
  198.       theReceiversBlockNumber = DBDICT;
  199.       theVerId_signalNumber   = GSN_DROP_INDX_REQ;
  200.       theLength               = DropIndxReq::SignalLength;   
  201.     }
  202.     break;
  203.     case GSN_TCINDXREQ:
  204.     {
  205.       theTrace                = TestOrd::TraceAPI;
  206.       theReceiversBlockNumber = DBTC;
  207.       theVerId_signalNumber   = GSN_TCINDXREQ;
  208.       theLength               = TcIndxReq::SignalLength;
  209.     }
  210.     break;
  211.     case GSN_INDXKEYINFO:
  212.     {
  213.       theTrace                = TestOrd::TraceAPI;
  214.       theReceiversBlockNumber = DBTC;
  215.       theVerId_signalNumber   = GSN_INDXKEYINFO;
  216.       theLength               = IndxKeyInfo::MaxSignalLength; 
  217.     }
  218.     break;
  219.     case GSN_INDXATTRINFO:
  220.     {
  221.       theTrace                = TestOrd::TraceAPI;
  222.       theReceiversBlockNumber = DBTC;
  223.       theVerId_signalNumber   = GSN_INDXATTRINFO;
  224.       theLength               = IndxAttrInfo::MaxSignalLength;
  225.     }
  226.     break;
  227.     
  228.     default: 
  229.     {
  230.       return -1;
  231.     }
  232.   }
  233.   return 0;
  234. }
  235. void
  236. NdbApiSignal::set(Uint8  trace,
  237.   Uint16 receiversBlockNumber,
  238.   Uint16 signalNumber,
  239.   Uint32 length){
  240.   
  241.   theTrace                = trace;
  242.   theReceiversBlockNumber = receiversBlockNumber;
  243.   theVerId_signalNumber   = signalNumber;
  244.   theLength               = length;
  245. }
  246. void
  247. NdbApiSignal::copyFrom(const NdbApiSignal * src){
  248.   theVerId_signalNumber   = src->theVerId_signalNumber;
  249.   theReceiversBlockNumber = src->theReceiversBlockNumber;
  250.   theSendersBlockRef      = src->theSendersBlockRef;
  251.   theLength               = src->theLength;
  252.   theTrace                = src->theTrace;
  253.   
  254.   Uint32 * dstData = getDataPtrSend();
  255.   const Uint32 * srcData = src->getDataPtr();
  256.   for (Uint32 i = 0; i < theLength; i++)
  257.     dstData[i] = srcData[i];
  258.   setDataPtr(dstData);
  259.   
  260.   /**
  261.    * NOTE that theSignalId is used as data ptr
  262.    *   and should not be copied
  263.    * NOTE that theSendersSignalId is used as next pointer
  264.    *   and should not be copied
  265.    */
  266. }