1 /*
2    Copyright (c) 2003, 2010, 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   void	             	setLength(Uint32 aLength);
76   void 			next(NdbApiSignal* anApiSignal);
77   NdbApiSignal* 	next();
78 
79    const Uint32 *       getDataPtr() const;
80          Uint32 *       getDataPtrSend();
81    const Uint32 *       getConstDataPtrSend() const;
82    STATIC_CONST(        MaxSignalWords = 25);
83 
84   NodeId                get_sender_node();
85 
86   /**
87    * Fragmentation
88    */
isFragmented() const89   bool isFragmented() const { return m_fragmentInfo != 0;}
isFirstFragment() const90   bool isFirstFragment() const { return m_fragmentInfo <= 1;}
isLastFragment() const91   bool isLastFragment() const {
92     return m_fragmentInfo == 0 || m_fragmentInfo == 3;
93   }
94 
getFragmentId() const95   Uint32 getFragmentId() const {
96     return (m_fragmentInfo == 0 ? 0 : getDataPtr()[theLength - 1]);
97   }
98 
operator =(const NdbApiSignal & src)99   NdbApiSignal& operator=(const NdbApiSignal& src) {
100     copyFrom(&src);
101     return *this;
102   }
103 
104 private:
105   void setDataPtr(Uint32 *);
106 
107   friend class NdbTransaction;
108   friend class NdbScanReceiver;
109   friend class Table;
110   friend class TransporterFacade;
111   void copyFrom(const NdbApiSignal * src);
112 
113   /**
114    * Only used when creating a signal in the api
115    */
116   Uint32 theData[MaxSignalWords];
117   NdbApiSignal *theNextSignal;
118   Uint32 *theRealData;
119 };
120 /**********************************************************************
121 NodeId get_sender_node
122 Remark:        Get the node id of the sender
123 ***********************************************************************/
124 inline
125 NodeId
get_sender_node()126 NdbApiSignal::get_sender_node()
127 {
128   return refToNode(theSendersBlockRef);
129 }
130 
131 /**********************************************************************
132 void getLength
133 Remark:        Get the length of the signal.
134 ******************************************************************************/
135 inline
136 Uint32
getLength() const137 NdbApiSignal::getLength() const{
138   return theLength;
139 }
140 
141 /**********************************************************************
142 void setLength
143 Parameters:    aLength: Signal length
144 Remark:        Set the length in the signal.
145 ******************************************************************************/
146 inline
147 void
setLength(Uint32 aLength)148 NdbApiSignal::setLength(Uint32 aLength){
149   theLength = aLength;
150 }
151 
152 /**********************************************************************
153 void next(NdbApiSignal* aSignal);
154 
155 Parameters:     aSignal: Signal object.
156 Remark:         Insert signal rear in a linked list.
157 *****************************************************************************/
158 inline
159 void
next(NdbApiSignal * aSignal)160 NdbApiSignal::next(NdbApiSignal* aSignal){
161   theNextSignal = aSignal;
162 }
163 /**********************************************************************
164 NdbApiSignal* next();
165 
166 Return Value:   Return theNext signal object if the next was successful.
167                 Return NULL: In all other case.
168 Remark:         Read the theNext in signal.
169 *****************************************************************************/
170 inline
171 NdbApiSignal*
next()172 NdbApiSignal::next(){
173   return theNextSignal;
174 }
175 /**********************************************************************
176 int readSignalNo();
177 
178 Return Value:    Return the signalNumber.
179 Remark:          Read signal number
180 *****************************************************************************/
181 inline
182 int
readSignalNumber() const183 NdbApiSignal::readSignalNumber() const
184 {
185   return (int)theVerId_signalNumber;
186 }
187 /**********************************************************************
188 Uint32 readData(Uint32 aDataNo);
189 
190 Return Value:   Return Data word in a signal.
191                 Return -1: In all other case.
192                 aDataNo: Data number in signal.
193 Remark:         Return the dataWord information in a signal for a dataNo.
194 ******************************************************************************/
195 inline
196 Uint32
readData(Uint32 aDataNo) const197 NdbApiSignal::readData(Uint32 aDataNo) const {
198   return getDataPtr()[aDataNo-1];
199 }
200 /**********************************************************************
201 int setData(Uint32 aWord, int aDataNo);
202 
203 Return Value:   Return 0 : setData was successful.
204                 Return -1: In all other case.
205 Parameters:     aWord: Data word.
206                 aDataNo: Data number in signal.
207 Remark:         Set Data word in signal 1 - 25
208 ******************************************************************************/
209 inline
210 void
setData(Uint32 aWord,Uint32 aDataNo)211 NdbApiSignal::setData(Uint32 aWord, Uint32 aDataNo){
212   getDataPtrSend()[aDataNo -1] = aWord;
213 }
214 
215 /**
216  * Return pointer to data structure
217  */
218 inline
219 const Uint32 *
getDataPtr() const220 NdbApiSignal::getDataPtr() const {
221   return theRealData;
222 }
223 
224 inline
225 Uint32 *
getDataPtrSend()226 NdbApiSignal::getDataPtrSend(){
227   return (Uint32*)&theData[0];
228 }
229 
230 inline
231 const Uint32 *
getConstDataPtrSend() const232 NdbApiSignal::getConstDataPtrSend() const
233 {
234   return (Uint32*)&theData[0];
235 }
236 
237 inline
238 void
setDataPtr(Uint32 * ptr)239 NdbApiSignal::setDataPtr(Uint32 * ptr){
240   theRealData = ptr;
241 }
242 
243 #endif
244