summaryrefslogtreecommitdiff
path: root/ndb/src/ndbapi/NdbApiSignal.cpp
blob: b1671e593e10639ca483d7bc3ea757bd1064adc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/* Copyright (C) 2003 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */


#include "API.hpp"
#include "NdbApiSignal.hpp"

/**
 * The following include includes
 *  definitions directly from the kernel
 *
 * Definitions that is shared between kernel and the API
 */
#include <signaldata/TcKeyReq.hpp>
#include <signaldata/KeyInfo.hpp>
#include <signaldata/AttrInfo.hpp>
#include <signaldata/TestOrd.hpp>
#include <signaldata/CreateIndx.hpp>
#include <signaldata/DropIndx.hpp>
#include <signaldata/TcIndx.hpp>
#include <signaldata/IndxKeyInfo.hpp>
#include <signaldata/IndxAttrInfo.hpp>
#include <signaldata/TcHbRep.hpp>
#include <signaldata/ScanTab.hpp>

#include <NdbOut.hpp>

/******************************************************************************
NdbApiSignal();

Return Value:   None  
Remark:         Creates a NdbApiSignal object. 
******************************************************************************/
NdbApiSignal::NdbApiSignal(BlockReference ref)
{
  theVerId_signalNumber   = 0;    // 4 bit ver id - 16 bit gsn
  theReceiversBlockNumber = 0;  // Only 16 bit blocknum  
  theSendersBlockRef      = refToBlock(ref);
  theLength               = 0;
  theSendersSignalId      = 0;
  theSignalId             = 0;
  theTrace                = 0;
  m_noOfSections          = 0;
  m_fragmentInfo          = 0;
  for (int i = 0; i < 25; i++)
    theData[i] = 0x13579753;
  
  setDataPtr(&theData[0]);
  theNextSignal = 0;
}

/**
 * Copy constructor
 */
NdbApiSignal::NdbApiSignal(const NdbApiSignal &src) {
  copyFrom(&src);
}
/******************************************************************************
~NdbApiSignal();

Return Value:   None  
Remark:         Delete a NdbApiSignal object.
******************************************************************************/
NdbApiSignal::~NdbApiSignal()
{ 
}
/******************************************************************************
int setSignal(NdbSignalType aNdbSignalType);

Return Value:   Return 0 : setSignal was successful.
                Return tErrorCode In all other case. 
Parameters:     aNdbSignalType: Type of signal.
Remark:         Set signal header and allocate 128 byte. 
******************************************************************************/
int 
NdbApiSignal::setSignal(int aNdbSignalType)
{ 	
  theSendersSignalId = 0;
  switch (aNdbSignalType)
  {
    case GSN_DIHNDBTAMPER:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber = DBDIH;
      theVerId_signalNumber   = GSN_DIHNDBTAMPER;
      theLength               = 3;
    }
    break;

    case GSN_TCSEIZEREQ:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber = DBTC;
      theVerId_signalNumber   = GSN_TCSEIZEREQ;
      theLength               = 2;
    }
    break;

    case GSN_TCKEYREQ:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber = DBTC;
      theVerId_signalNumber   = GSN_TCKEYREQ;
      theLength               = TcKeyReq::SignalLength;
    }
    break;

    case GSN_TCRELEASEREQ:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber = DBTC;
      theVerId_signalNumber   = GSN_TCRELEASEREQ;
      theLength               = 3;
    }
    break;

    case GSN_ATTRINFO:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber = DBTC;
      theVerId_signalNumber   = GSN_ATTRINFO;
      theLength               = AttrInfo::MaxSignalLength;
    }
    break;
    
    case GSN_KEYINFO:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber	= DBTC;
      theVerId_signalNumber = GSN_KEYINFO;
      theLength               = KeyInfo::MaxSignalLength; 
    }
    break;

    case GSN_TCROLLBACKREQ:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber = DBTC;
      theVerId_signalNumber   = GSN_TCROLLBACKREQ;
      theLength               = 3;
    }
    break;

    case GSN_TC_HBREP:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber = DBTC;
      theVerId_signalNumber   = GSN_TC_HBREP;
      theLength               = TcHbRep::SignalLength;
    }
    break;

    case GSN_TC_COMMITREQ:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber = DBTC;
      theVerId_signalNumber   = GSN_TC_COMMITREQ;
      theLength               = 3;
    }
    break;

    case GSN_SCAN_TABREQ:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber = DBTC;
      theVerId_signalNumber   = GSN_SCAN_TABREQ;
      theLength               = ScanTabReq::StaticLength;      
    }
    break;

    case GSN_SCAN_NEXTREQ:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber = DBTC;
      theVerId_signalNumber   = GSN_SCAN_NEXTREQ;
      theLength               = ScanNextReq::SignalLength;
    }
    break;

    case GSN_CREATE_INDX_REQ:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber = DBDICT;
      theVerId_signalNumber   = GSN_CREATE_INDX_REQ;
      theLength               = CreateIndxReq::SignalLength;   
    }
    break;

    case GSN_DROP_INDX_REQ:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber = DBDICT;
      theVerId_signalNumber   = GSN_DROP_INDX_REQ;
      theLength               = DropIndxReq::SignalLength;   
    }
    break;

    case GSN_TCINDXREQ:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber = DBTC;
      theVerId_signalNumber   = GSN_TCINDXREQ;
      theLength               = TcKeyReq::SignalLength;
    }
    break;

    case GSN_INDXKEYINFO:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber = DBTC;
      theVerId_signalNumber   = GSN_INDXKEYINFO;
      theLength               = IndxKeyInfo::MaxSignalLength; 
    }
    break;

    case GSN_INDXATTRINFO:
    {
      theTrace                = TestOrd::TraceAPI;
      theReceiversBlockNumber = DBTC;
      theVerId_signalNumber   = GSN_INDXATTRINFO;
      theLength               = IndxAttrInfo::MaxSignalLength;
    }
    break;
    
    default: 
    {
      return -1;
    }
  }
  return 0;
}

void
NdbApiSignal::set(Uint8  trace,
		  Uint16 receiversBlockNumber,
		  Uint16 signalNumber,
		  Uint32 length){
  
  theTrace                = trace;
  theReceiversBlockNumber = receiversBlockNumber;
  theVerId_signalNumber   = signalNumber;
  theLength               = length;
}

void
NdbApiSignal::copyFrom(const NdbApiSignal * src){
  theVerId_signalNumber   = src->theVerId_signalNumber;
  theReceiversBlockNumber = src->theReceiversBlockNumber;
  theSendersBlockRef      = src->theSendersBlockRef;
  theLength               = src->theLength;
  theTrace                = src->theTrace;
  
  Uint32 * dstData = getDataPtrSend();
  const Uint32 * srcData = src->getDataPtr();
  for (Uint32 i = 0; i < theLength; i++)
    dstData[i] = srcData[i];

  setDataPtr(dstData);
  
  /**
   * NOTE that theSignalId is used as data ptr
   *   and should not be copied
   * NOTE that theSendersSignalId is used as next pointer
   *   and should not be copied
   */
}