1 /*
2 Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 /**********************************************************************
26 * Name: NdbApiSignal.H
27 * Include:
28 * Link:
29 * Author: UABMNST Mona Natterkvist UAB/B/SD
30 * Date: 97----
31 * Version: 0.1
32 * Description: Interface between TIS and NDB
33 * Documentation:
34 * Adjust: 971204 UABMNST First version.
35 * Adjust: 000705 QABANAB Changes in Protocol2
36 * Comment:
37 *****************************************************************************/
38 #ifndef NdbApiSignal_H
39 #define NdbApiSignal_H
40
41 #include <kernel_types.h>
42 #include <RefConvert.hpp>
43 #include <TransporterDefinitions.hpp>
44
45 class Ndb;
46
47 /**
48 * A NdbApiSignal : public SignalHeader
49 *
50 * Stores the address to theData in theSignalId
51 */
52 class NdbApiSignal : public SignalHeader
53 {
54 public:
55 NdbApiSignal(Ndb* ndb);
56 NdbApiSignal(BlockReference ref);
57 NdbApiSignal(const NdbApiSignal &);
NdbApiSignal(const SignalHeader & header)58 NdbApiSignal(const SignalHeader &header)
59 : SignalHeader(header), theNextSignal(0), theRealData(0) {}
60 ~NdbApiSignal();
61
62 void set(Uint8 trace,
63 Uint16 receiversBlockNumber,
64 Uint16 signalNumber,
65 Uint32 length);
66
67
68 void setData(Uint32 aWord, Uint32 aDataNo);
69 Uint32 readData(Uint32 aDataNo) const; // Read word in signal
70
71 // Set signal header
72 int setSignal(int NdbSignalType, Uint32 receiverBlockNo);
73 int readSignalNumber() const; // Read signal number
74 Uint32 getLength() const;
75 Uint32 getNoOfSections() const;
76 void setLength(Uint32 aLength);
77 void next(NdbApiSignal* anApiSignal);
78 NdbApiSignal* next();
79
80 const Uint32 * getDataPtr() const;
81 Uint32 * getDataPtrSend();
82 const Uint32 * getConstDataPtrSend() const;
83 STATIC_CONST( MaxSignalWords = 25);
84
85 NodeId get_sender_node() const;
86
87 /**
88 * Fragmentation
89 */
isFragmented() const90 bool isFragmented() const { return m_fragmentInfo != 0;}
isFirstFragment() const91 bool isFirstFragment() const { return m_fragmentInfo <= 1;}
isLastFragment() const92 bool isLastFragment() const {
93 return m_fragmentInfo == 0 || m_fragmentInfo == 3;
94 }
95
getFragmentId() const96 Uint32 getFragmentId() const {
97 return (m_fragmentInfo == 0 ? 0 : getDataPtr()[theLength - 1]);
98 }
99
getFragmentSectionNumber(Uint32 i) const100 Uint32 getFragmentSectionNumber(Uint32 i) const
101 {
102 return getDataPtr()[theLength - 1 - m_noOfSections + i];
103 }
104
operator =(const NdbApiSignal & src)105 NdbApiSignal& operator=(const NdbApiSignal& src) {
106 copyFrom(&src);
107 return *this;
108 }
109
110 private:
111 void setDataPtr(Uint32 *);
112
113 friend class AssembleBatchedFragments;
114 friend class NdbTransaction;
115 friend class NdbScanReceiver;
116 friend class Table;
117 friend class TransporterFacade;
118 void copyFrom(const NdbApiSignal * src);
119
120 /**
121 * Only used when creating a signal in the api
122 */
123 Uint32 theData[MaxSignalWords];
124 NdbApiSignal *theNextSignal;
125 Uint32 *theRealData;
126 };
127 /**********************************************************************
128 NodeId get_sender_node
129 Remark: Get the node id of the sender
130 ***********************************************************************/
131 inline
132 NodeId
get_sender_node() const133 NdbApiSignal::get_sender_node() const
134 {
135 return refToNode(theSendersBlockRef);
136 }
137
138 /**********************************************************************
139 void getLength
140 Remark: Get the length of the signal.
141 ******************************************************************************/
142 inline
143 Uint32
getLength() const144 NdbApiSignal::getLength() const{
145 return theLength;
146 }
147
148 /* Get number of sections in signal */
149 inline
150 Uint32
getNoOfSections() const151 NdbApiSignal::getNoOfSections() const
152 {
153 return m_noOfSections;
154 }
155
156 /**********************************************************************
157 void setLength
158 Parameters: aLength: Signal length
159 Remark: Set the length in the signal.
160 ******************************************************************************/
161 inline
162 void
setLength(Uint32 aLength)163 NdbApiSignal::setLength(Uint32 aLength){
164 theLength = aLength;
165 }
166
167 /**********************************************************************
168 void next(NdbApiSignal* aSignal);
169
170 Parameters: aSignal: Signal object.
171 Remark: Insert signal rear in a linked list.
172 *****************************************************************************/
173 inline
174 void
next(NdbApiSignal * aSignal)175 NdbApiSignal::next(NdbApiSignal* aSignal){
176 theNextSignal = aSignal;
177 }
178 /**********************************************************************
179 NdbApiSignal* next();
180
181 Return Value: Return theNext signal object if the next was successful.
182 Return NULL: In all other case.
183 Remark: Read the theNext in signal.
184 *****************************************************************************/
185 inline
186 NdbApiSignal*
next()187 NdbApiSignal::next(){
188 return theNextSignal;
189 }
190 /**********************************************************************
191 int readSignalNo();
192
193 Return Value: Return the signalNumber.
194 Remark: Read signal number
195 *****************************************************************************/
196 inline
197 int
readSignalNumber() const198 NdbApiSignal::readSignalNumber() const
199 {
200 return (int)theVerId_signalNumber;
201 }
202 /**********************************************************************
203 Uint32 readData(Uint32 aDataNo);
204
205 Return Value: Return Data word in a signal.
206 Return -1: In all other case.
207 aDataNo: Data number in signal.
208 Remark: Return the dataWord information in a signal for a dataNo.
209 ******************************************************************************/
210 inline
211 Uint32
readData(Uint32 aDataNo) const212 NdbApiSignal::readData(Uint32 aDataNo) const {
213 return getDataPtr()[aDataNo-1];
214 }
215 /**********************************************************************
216 int setData(Uint32 aWord, int aDataNo);
217
218 Return Value: Return 0 : setData was successful.
219 Return -1: In all other case.
220 Parameters: aWord: Data word.
221 aDataNo: Data number in signal.
222 Remark: Set Data word in signal 1 - 25
223 ******************************************************************************/
224 inline
225 void
setData(Uint32 aWord,Uint32 aDataNo)226 NdbApiSignal::setData(Uint32 aWord, Uint32 aDataNo){
227 getDataPtrSend()[aDataNo -1] = aWord;
228 }
229
230 /**
231 * Return pointer to data structure
232 */
233 inline
234 const Uint32 *
getDataPtr() const235 NdbApiSignal::getDataPtr() const {
236 return theRealData;
237 }
238
239 inline
240 Uint32 *
getDataPtrSend()241 NdbApiSignal::getDataPtrSend(){
242 return (Uint32*)&theData[0];
243 }
244
245 inline
246 const Uint32 *
getConstDataPtrSend() const247 NdbApiSignal::getConstDataPtrSend() const
248 {
249 return (Uint32*)&theData[0];
250 }
251
252 inline
253 void
setDataPtr(Uint32 * ptr)254 NdbApiSignal::setDataPtr(Uint32 * ptr){
255 theRealData = ptr;
256 }
257
258 #endif
259