1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#ifndef SIMPLE_PROPERTIES_HPP
17
#define SIMPLE_PROPERTIES_HPP
19
#include <ndb_global.h>
23
* @class SimpleProperties
24
* @brief Key-value-pair container. Actully a list of named elements.
27
* - The keys are Uint16
28
* - The values are either Uint32 or null terminated c-strings
30
* @note Keys may be repeated.
32
* Examples of things that can be stored in a SimpleProperties object:
33
* - Lists like: ((1, "foo"), (2, "bar"), (3, 32), (2, "baz"))
35
class SimpleProperties {
48
* Struct for defining mapping to be used with unpack
50
struct SP2StructMapping {
56
Uint32 Length_Offset; // Offset used for looking up length of
57
// data if Type = BinaryValue
61
* UnpackStatus - Value returned from unpack
64
Eof = 0, // Success, end of SimpleProperties object reached
70
OutOfMemory = 6 // Only used when packing
77
static UnpackStatus unpack(class Reader & it,
79
const SP2StructMapping[], Uint32 mapSz,
81
bool ignoreUnknownKeys);
84
static UnpackStatus pack(class Writer &,
86
const SP2StructMapping[], Uint32 mapSz,
97
* Move to first element
98
* Return true if element exist
103
* Move to next element
104
* Return true if element exist
115
* Note only valid is valid() == true
117
Uint16 getKey() const;
120
* Get value length in bytes - (including terminating 0 for strings)
121
* Note only valid is valid() == true
123
Uint16 getValueLen() const;
127
* Note only valid is valid() == true
129
ValueType getValueType() const;
133
* Note only valid is valid() == true
135
Uint32 getUint32() const;
136
char * getString(char * dst) const;
139
* Print the complete simple properties (for debugging)
141
void printAll(NdbOut& ndbout);
150
Uint32 m_strLen; // Including 0-byte in words
155
virtual void reset() = 0;
157
virtual bool step(Uint32 len) = 0;
158
virtual bool getWord(Uint32 * dst) = 0;
159
virtual bool peekWord(Uint32 * dst) const = 0;
160
virtual bool peekWords(Uint32 * dst, Uint32 len) const = 0;
171
bool add(Uint16 key, Uint32 value);
172
bool add(Uint16 key, const char * value);
173
bool add(Uint16 key, const void* value, int len);
176
virtual bool reset() = 0;
177
virtual bool putWord(Uint32 val) = 0;
178
virtual bool putWords(const Uint32 * src, Uint32 len) = 0;
180
bool add(const char* value, int len);
185
* Reader for linear memory
187
class SimplePropertiesLinearReader : public SimpleProperties::Reader {
189
SimplePropertiesLinearReader(const Uint32 * src, Uint32 len);
190
virtual ~SimplePropertiesLinearReader() {}
192
virtual void reset();
193
virtual bool step(Uint32 len);
194
virtual bool getWord(Uint32 * dst);
195
virtual bool peekWord(Uint32 * dst) const ;
196
virtual bool peekWords(Uint32 * dst, Uint32 len) const;
200
const Uint32 * m_src;
204
* Writer for linear memory
206
class LinearWriter : public SimpleProperties::Writer {
208
LinearWriter(Uint32 * src, Uint32 len);
209
virtual ~LinearWriter() {}
211
virtual bool reset();
212
virtual bool putWord(Uint32 val);
213
virtual bool putWords(const Uint32 * src, Uint32 len);
214
Uint32 getWordsUsed() const;
222
* Writer for UtilBuffer
224
class UtilBufferWriter : public SimpleProperties::Writer {
226
UtilBufferWriter(class UtilBuffer & buf);
227
virtual ~UtilBufferWriter() {}
229
virtual bool reset();
230
virtual bool putWord(Uint32 val);
231
virtual bool putWords(const Uint32 * src, Uint32 len);
232
Uint32 getWordsUsed() const;
234
class UtilBuffer & m_buf;
238
* Reader for long signal section memory
241
* Implemented in kernel/vm/SimplePropertiesSection.cpp
243
class SimplePropertiesSectionReader : public SimpleProperties::Reader {
245
SimplePropertiesSectionReader(struct SegmentedSectionPtr &,
246
class SectionSegmentPool &);
247
virtual ~SimplePropertiesSectionReader() {}
249
virtual void reset();
250
virtual bool step(Uint32 len);
251
virtual bool getWord(Uint32 * dst);
252
virtual bool peekWord(Uint32 * dst) const ;
253
virtual bool peekWords(Uint32 * dst, Uint32 len) const;
254
Uint32 getSize() const;
255
bool getWords(Uint32 * dst, Uint32 len);
260
class SectionSegmentPool & m_pool;
261
struct SectionSegment * m_head;
262
struct SectionSegment * m_currentSegment;
266
Uint32 SimplePropertiesSectionReader::getSize() const
272
* Writer for long signal section memory
275
* Implemented in kernel/vm/SimplePropertiesSection.cpp
277
class SimplePropertiesSectionWriter : public SimpleProperties::Writer {
279
SimplePropertiesSectionWriter(class SectionSegmentPool &);
280
virtual ~SimplePropertiesSectionWriter() {}
282
virtual bool reset();
283
virtual bool putWord(Uint32 val);
284
virtual bool putWords(const Uint32 * src, Uint32 len);
287
* This "unlinks" the writer from the memory
289
void getPtr(struct SegmentedSectionPtr & dst);
294
class SectionSegmentPool & m_pool;
295
struct SectionSegment * m_head;
296
Uint32 m_prevPtrI; // Prev to m_currentSegment
297
struct SectionSegment * m_currentSegment;