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

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. #ifndef TransporterInternalDefinitions_H
  14. #define TransporterInternalDefinitions_H
  15. #if defined DEBUG_TRANSPORTER || defined VM_TRACE
  16. #include <NdbOut.hpp>
  17. #endif
  18. #define NDB_TCP_TRANSPORTER
  19. #ifdef HAVE_NDB_SHM
  20. #define NDB_SHM_TRANSPORTER
  21. #endif
  22. #ifdef HAVE_NDB_SCI
  23. #define NDB_SCI_TRANSPORTER
  24. #endif
  25. #ifdef HAVE_NDB_OSE
  26. #define NDB_OSE_TRANSPORTER
  27. #endif
  28. #ifdef DEBUG_TRANSPORTER
  29. #define DEBUG(x) ndbout << x << endl
  30. #else
  31. #define DEBUG(x)
  32. #endif
  33. #if defined VM_TRACE || defined DEBUG_TRANSPORTER
  34. #define WARNING(X) ndbout << X << endl;
  35. #else
  36. #define WARNING(X)
  37. #endif
  38. // Calculate a checksum
  39. inline
  40. Uint32
  41. computeChecksum(const Uint32 * const startOfData, int nWords) {
  42.   Uint32 chksum = startOfData[0];
  43.   for (int i=1; i < nWords; i++)
  44.     chksum ^= startOfData[i];
  45.   return chksum;
  46. }
  47. struct Protocol6 {
  48.   Uint32 word1;
  49.   Uint32 word2;
  50.   Uint32 word3;
  51.   
  52. /**
  53.  *
  54.  * b = Byte order           -  4 Bits (Note 1 significant bit)
  55.  * g = GSN                  - 16 Bits
  56.  * p = Prio                 -  2 Bits
  57.  * c = Checksum included    -  1 Bit
  58.  * z = Compression          -  1 Bit
  59.  * v = Version id           -  4 Bits
  60.  * i = Signal id included   -  1 Bit
  61.  * m = Message length       - 16 Bits (0-65536) (In word -> 0-256k bytes)
  62.  * d = Signal data length   -  5 Bits (0-31)
  63.  * t = trace                -  6 Bits (0-63)
  64.  * r = Recievers block no   - 16 Bits
  65.  * s = Senders block no     - 16 Bits
  66.  * u = Unused               -  7 Bits
  67.  * f = FragmentInfo1        -  1 Bit
  68.  * h = FragmentInfo2        -  1 bit
  69.  * n = No of segments       -  2 Bits
  70.  * Word 1
  71.  *
  72.  *
  73.  *           1111111111222222222233
  74.  * 01234567890123456789012345678901
  75.  * bfizcppbmmmmmmmmmmmmmmmmbhdddddb
  76.  **
  77.  * Word 2
  78.  *
  79.  *           1111111111222222222233
  80.  * 01234567890123456789012345678901
  81.  * ggggggggggggggggvvvvttttttnn  
  82.  
  83.  **
  84.  * Word 3
  85.  *
  86.  *           1111111111222222222233
  87.  * 01234567890123456789012345678901
  88.  * rrrrrrrrrrrrrrrrssssssssssssssss
  89.  **
  90.  * Word 4 (Optional Signal Id)
  91.  */
  92.   
  93.   /**
  94.    * 0 = Big endian (Sparc), 1 = Little endian (Intel)
  95.    */
  96.   static Uint32 getByteOrder       (const Uint32 & word1);
  97.   static Uint32 getCompressed      (const Uint32 & word1);
  98.   static Uint32 getSignalIdIncluded(const Uint32 & word1);
  99.   static Uint32 getCheckSumIncluded(const Uint32 & word1);
  100.   static Uint32 getPrio            (const Uint32 & word1);
  101.   static Uint32 getMessageLength   (const Uint32 & word1);
  102.   static void setByteOrder       (Uint32 & word1, Uint32 byteOrder);
  103.   static void setCompressed      (Uint32 & word1, Uint32 compressed);
  104.   static void setSignalIdIncluded(Uint32 & word1, Uint32 signalId);
  105.   static void setCheckSumIncluded(Uint32 & word1, Uint32 checkSum);
  106.   static void setPrio            (Uint32 & word1, Uint32 prio);
  107.   static void setMessageLength   (Uint32 & word1, Uint32 messageLen);
  108.   
  109.   static void createSignalHeader(SignalHeader * const dst,
  110.  const Uint32 & word1, 
  111.  const Uint32 & word2, 
  112.  const Uint32 & word3);
  113.   
  114.   static void createProtocol6Header(Uint32 & word1, 
  115.     Uint32 & word2, 
  116.     Uint32 & word3,
  117.     const SignalHeader * const src);
  118. };  
  119. #define WORD1_BYTEORDER_MASK   (0x81000081)
  120. #define WORD1_SIGNALID_MASK    (0x00000004)
  121. #define WORD1_COMPRESSED_MASK  (0x00000008)
  122. #define WORD1_CHECKSUM_MASK    (0x00000010)
  123. #define WORD1_PRIO_MASK        (0x00000060)
  124. #define WORD1_MESSAGELEN_MASK  (0x00FFFF00)
  125. #define WORD1_SIGNAL_LEN_MASK  (0x7C000000)
  126. #define WORD1_FRAG_INF_MASK    (0x00000002)
  127. #define WORD1_FRAG_INF2_MASK   (0x02000000)
  128. #define WORD1_FRAG_INF_SHIFT   (1)
  129. #define WORD1_SIGNALID_SHIFT   (2)
  130. #define WORD1_COMPRESSED_SHIFT (3)
  131. #define WORD1_CHECKSUM_SHIFT   (4)
  132. #define WORD1_PRIO_SHIFT       (5)
  133. #define WORD1_MESSAGELEN_SHIFT (8)
  134. #define WORD1_FRAG_INF2_SHIFT  (25)
  135. #define WORD1_SIGNAL_LEN_SHIFT (26)
  136. #define WORD2_VERID_GSN_MASK   (0x000FFFFF)
  137. #define WORD2_TRACE_MASK       (0x03f00000)
  138. #define WORD2_SEC_COUNT_MASK   (0x0c000000)
  139. #define WORD2_TRACE_SHIFT      (20)
  140. #define WORD2_SEC_COUNT_SHIFT  (26)
  141. #define WORD3_SENDER_MASK      (0x0000FFFF)
  142. #define WORD3_RECEIVER_MASK    (0xFFFF0000)
  143. #define WORD3_RECEIVER_SHIFT   (16)
  144. inline
  145. Uint32
  146. Protocol6::getByteOrder(const Uint32 & word1){
  147.   return word1 & 1;
  148. }
  149. inline
  150. Uint32
  151. Protocol6::getCompressed(const Uint32 & word1){
  152.   return (word1 & WORD1_COMPRESSED_MASK) >> WORD1_COMPRESSED_SHIFT;
  153. }
  154. inline
  155. Uint32
  156. Protocol6::getSignalIdIncluded(const Uint32 & word1){
  157.   return (word1 & WORD1_SIGNALID_MASK) >> WORD1_SIGNALID_SHIFT;
  158. }
  159. inline
  160. Uint32
  161. Protocol6::getCheckSumIncluded(const Uint32 & word1){
  162.   return (word1 & WORD1_CHECKSUM_MASK) >> WORD1_CHECKSUM_SHIFT;
  163. }
  164. inline
  165. Uint32
  166. Protocol6::getMessageLength(const Uint32 & word1){
  167.   return (word1 & WORD1_MESSAGELEN_MASK) >> WORD1_MESSAGELEN_SHIFT;
  168. }
  169. inline
  170. Uint32
  171. Protocol6::getPrio(const Uint32 & word1){
  172.   return (word1 & WORD1_PRIO_MASK) >> WORD1_PRIO_SHIFT;
  173. }
  174. inline
  175. void
  176. Protocol6::setByteOrder(Uint32 & word1, Uint32 byteOrder){
  177.   Uint32 tmp = byteOrder;
  178.   tmp |= (tmp << 7);
  179.   tmp |= (tmp << 24);
  180.   word1 |= (tmp & WORD1_BYTEORDER_MASK);
  181. }
  182. inline
  183. void
  184. Protocol6::setCompressed(Uint32 & word1, Uint32 compressed){
  185.   word1 |= ((compressed << WORD1_COMPRESSED_SHIFT) & WORD1_COMPRESSED_MASK);
  186. }
  187. inline
  188. void
  189. Protocol6::setSignalIdIncluded(Uint32 & word1, Uint32 signalId){
  190.   word1 |= ((signalId << WORD1_SIGNALID_SHIFT) & WORD1_SIGNALID_MASK);
  191. }
  192. inline
  193. void
  194. Protocol6::setCheckSumIncluded(Uint32 & word1, Uint32 checkSum){
  195.   word1 |= ((checkSum << WORD1_CHECKSUM_SHIFT) & WORD1_CHECKSUM_MASK);
  196. }
  197. inline
  198. void
  199. Protocol6::setMessageLength(Uint32 & word1, Uint32 messageLen){
  200.   word1 |= ((messageLen << WORD1_MESSAGELEN_SHIFT) & WORD1_MESSAGELEN_MASK);
  201. }
  202. inline
  203. void
  204. Protocol6::setPrio(Uint32 & word1, Uint32 prio){
  205.   word1 |= ((prio << WORD1_PRIO_SHIFT) & WORD1_PRIO_MASK);
  206. }
  207. inline
  208. void
  209. Protocol6::createSignalHeader(SignalHeader * const dst,
  210.       const Uint32 & word1, 
  211.       const Uint32 & word2, 
  212.       const Uint32 & word3){
  213.   
  214.   Uint32 signal_len = (word1 & WORD1_SIGNAL_LEN_MASK)>> WORD1_SIGNAL_LEN_SHIFT;
  215.   Uint32 fragInfo1  = (word1 & WORD1_FRAG_INF_MASK) >> (WORD1_FRAG_INF_SHIFT-1);
  216.   Uint32 fragInfo2  = (word1 & WORD1_FRAG_INF2_MASK) >> (WORD1_FRAG_INF2_SHIFT);
  217.   Uint32 trace      = (word2 & WORD2_TRACE_MASK) >> WORD2_TRACE_SHIFT;
  218.   Uint32 verid_gsn  = (word2 & WORD2_VERID_GSN_MASK);
  219.   Uint32 secCount   = (word2 & WORD2_SEC_COUNT_MASK) >> WORD2_SEC_COUNT_SHIFT;
  220.   
  221.   dst->theTrace              = trace;
  222.   dst->m_noOfSections        = secCount;
  223.   dst->m_fragmentInfo        = fragInfo1 | fragInfo2;
  224.   
  225.   dst->theLength             = signal_len;
  226.   dst->theVerId_signalNumber = verid_gsn;
  227.   
  228.   Uint32 sBlockNum  = (word3 & WORD3_SENDER_MASK);
  229.   Uint32 rBlockNum  = (word3 & WORD3_RECEIVER_MASK) >> WORD3_RECEIVER_SHIFT;
  230.   
  231.   dst->theSendersBlockRef      = sBlockNum;
  232.   dst->theReceiversBlockNumber = rBlockNum;
  233. }
  234. inline
  235. void
  236. Protocol6::createProtocol6Header(Uint32 & word1, 
  237.  Uint32 & word2, 
  238.  Uint32 & word3,
  239.  const SignalHeader * const src){
  240.   const Uint32 signal_len = src->theLength;
  241.   const Uint32 fragInfo   = src->m_fragmentInfo;
  242.   const Uint32 fragInfo1 = (fragInfo & 2);
  243.   const Uint32 fragInfo2 = (fragInfo & 1);
  244.   
  245.   const Uint32 trace      = src->theTrace;
  246.   const Uint32 verid_gsn  = src->theVerId_signalNumber;
  247.   const Uint32 secCount   = src->m_noOfSections;
  248.   
  249.   word1 |= ((signal_len << WORD1_SIGNAL_LEN_SHIFT) & WORD1_SIGNAL_LEN_MASK);
  250.   word1 |= ((fragInfo1 << (WORD1_FRAG_INF_SHIFT-1)) & WORD1_FRAG_INF_MASK);
  251.   word1 |= ((fragInfo2 << WORD1_FRAG_INF2_SHIFT) & WORD1_FRAG_INF2_MASK);
  252.   word2 |= ((trace << WORD2_TRACE_SHIFT) & WORD2_TRACE_MASK);
  253.   word2 |= (verid_gsn & WORD2_VERID_GSN_MASK);
  254.   word2 |= ((secCount << WORD2_SEC_COUNT_SHIFT) & WORD2_SEC_COUNT_MASK);
  255.   
  256.   Uint32 sBlockNum  = src->theSendersBlockRef ;
  257.   Uint32 rBlockNum  = src->theReceiversBlockNumber ;
  258.   
  259.   word3 |= (sBlockNum & WORD3_SENDER_MASK);
  260.   word3 |= ((rBlockNum << WORD3_RECEIVER_SHIFT) & WORD3_RECEIVER_MASK);
  261. }
  262. // Define of TransporterInternalDefinitions_H
  263. #endif