mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 05:22:25 +01:00
97a3ff8e66
into dl145b.mysql.com:/home/ndbdev/tomas/mysql-5.1 libmysqld/Makefile.am: Auto merged mysql-test/mysql-test-run.sh: Auto merged sql/field.cc: Auto merged sql/ha_ndbcluster.cc: Auto merged sql/sql_select.cc: Auto merged storage/ndb/include/kernel/AttributeList.hpp: Auto merged storage/ndb/include/ndbapi/Ndb.hpp: Auto merged storage/ndb/include/transporter/TransporterDefinitions.hpp: Auto merged storage/ndb/include/util/SimpleProperties.hpp: Auto merged storage/ndb/src/common/transporter/SCI_Transporter.cpp: Auto merged storage/ndb/src/common/util/SimpleProperties.cpp: Auto merged storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp: Auto merged storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp: Auto merged storage/ndb/src/ndbapi/DictCache.cpp: Auto merged storage/ndb/src/ndbapi/DictCache.hpp: Auto merged storage/ndb/src/ndbapi/Ndb.cpp: Auto merged storage/ndb/src/ndbapi/NdbBlob.cpp: Auto merged storage/ndb/src/ndbapi/NdbDictionary.cpp: Auto merged storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp: Auto merged storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp: Auto merged storage/ndb/src/ndbapi/NdbImpl.hpp: Auto merged storage/ndb/src/ndbapi/NdbLinHash.hpp: Auto merged storage/ndb/src/ndbapi/NdbTransaction.cpp: Auto merged storage/ndb/test/ndbapi/testBlobs.cpp: Auto merged storage/ndb/test/ndbapi/testDict.cpp: Auto merged storage/ndb/test/ndbapi/testNodeRestart.cpp: Auto merged storage/ndb/test/ndbapi/testOIBasic.cpp: Auto merged storage/ndb/tools/restore/Restore.hpp: Auto merged storage/ndb/src/kernel/blocks/backup/Backup.cpp: Auto merged storage/ndb/src/kernel/blocks/dbacc/DbaccMain.cpp: Auto merged storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp: Auto merged storage/ndb/test/ndbapi/testNdbApi.cpp: Auto merged storage/ndb/test/run-test/daily-basic-tests.txt: Auto merged storage/ndb/tools/restore/Restore.cpp: Auto merged storage/ndb/tools/restore/consumer_restore.cpp: Auto merged BitKeeper/etc/logging_ok: auto-union configure.in: Auto merged sql/sql_parse.cc: Auto merged
291 lines
6.8 KiB
C++
291 lines
6.8 KiB
C++
/* 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 */
|
|
|
|
#ifndef SIMPLE_PROPERTIES_HPP
|
|
#define SIMPLE_PROPERTIES_HPP
|
|
|
|
#include <ndb_global.h>
|
|
#include <NdbOut.hpp>
|
|
|
|
/**
|
|
* @class SimpleProperties
|
|
* @brief Key-value-pair container. Actully a list of named elements.
|
|
*
|
|
* SimpleProperties:
|
|
* - The keys are Uint16
|
|
* - The values are either Uint32 or null terminated c-strings
|
|
*
|
|
* @note Keys may be repeated.
|
|
*
|
|
* Examples of things that can be stored in a SimpleProperties object:
|
|
* - Lists like: ((1, "foo"), (2, "bar"), (3, 32), (2, "baz"))
|
|
*/
|
|
class SimpleProperties {
|
|
public:
|
|
/**
|
|
* Value types
|
|
*/
|
|
enum ValueType {
|
|
Uint32Value = 0,
|
|
StringValue = 1,
|
|
BinaryValue = 2,
|
|
InvalidValue = 3
|
|
};
|
|
|
|
/**
|
|
* Struct for defining mapping to be used with unpack
|
|
*/
|
|
struct SP2StructMapping {
|
|
Uint16 Key;
|
|
Uint32 Offset;
|
|
ValueType Type;
|
|
Uint32 minValue;
|
|
Uint32 maxValue;
|
|
Uint32 Length_Offset; // Offset used for looking up length of
|
|
// data if Type = BinaryValue
|
|
};
|
|
|
|
/**
|
|
* UnpackStatus - Value returned from unpack
|
|
*/
|
|
enum UnpackStatus {
|
|
Eof = 0, // Success, end of SimpleProperties object reached
|
|
Break = 1, // Success
|
|
TypeMismatch = 2,
|
|
ValueTooLow = 3,
|
|
ValueTooHigh = 4,
|
|
UnknownKey = 5,
|
|
OutOfMemory = 6 // Only used when packing
|
|
};
|
|
|
|
/**
|
|
* Unpack
|
|
*/
|
|
class Reader;
|
|
static UnpackStatus unpack(class Reader & it,
|
|
void * dst,
|
|
const SP2StructMapping[], Uint32 mapSz,
|
|
bool ignoreMinMax,
|
|
bool ignoreUnknownKeys);
|
|
|
|
class Writer;
|
|
static UnpackStatus pack(class Writer &,
|
|
const void * src,
|
|
const SP2StructMapping[], Uint32 mapSz,
|
|
bool ignoreMinMax);
|
|
|
|
/**
|
|
* Reader class
|
|
*/
|
|
class Reader {
|
|
public:
|
|
/**
|
|
* Move to first element
|
|
* Return true if element exist
|
|
*/
|
|
bool first();
|
|
|
|
/**
|
|
* Move to next element
|
|
* Return true if element exist
|
|
*/
|
|
bool next();
|
|
|
|
/**
|
|
* Is this valid
|
|
*/
|
|
bool valid() const;
|
|
|
|
/**
|
|
* Get key
|
|
* Note only valid is valid() == true
|
|
*/
|
|
Uint16 getKey() const;
|
|
|
|
/**
|
|
* Get value length in bytes - (including terminating 0 for strings)
|
|
* Note only valid is valid() == true
|
|
*/
|
|
Uint16 getValueLen() const;
|
|
|
|
/**
|
|
* Get value type
|
|
* Note only valid is valid() == true
|
|
*/
|
|
ValueType getValueType() const;
|
|
|
|
/**
|
|
* Get value
|
|
* Note only valid is valid() == true
|
|
*/
|
|
Uint32 getUint32() const;
|
|
char * getString(char * dst) const;
|
|
|
|
/**
|
|
* Print the complete simple properties (for debugging)
|
|
*/
|
|
void printAll(NdbOut& ndbout);
|
|
|
|
private:
|
|
bool readValue();
|
|
|
|
Uint16 m_key;
|
|
Uint16 m_itemLen;
|
|
union {
|
|
Uint32 m_ui32_value;
|
|
Uint32 m_strLen; // Including 0-byte in words
|
|
};
|
|
ValueType m_type;
|
|
protected:
|
|
Reader();
|
|
virtual void reset() = 0;
|
|
|
|
virtual bool step(Uint32 len) = 0;
|
|
virtual bool getWord(Uint32 * dst) = 0;
|
|
virtual bool peekWord(Uint32 * dst) const = 0;
|
|
virtual bool peekWords(Uint32 * dst, Uint32 len) const = 0;
|
|
};
|
|
|
|
/**
|
|
* Writer class
|
|
*/
|
|
class Writer {
|
|
public:
|
|
bool first();
|
|
bool add(Uint16 key, Uint32 value);
|
|
bool add(Uint16 key, const char * value);
|
|
bool add(Uint16 key, const void* value, int len);
|
|
protected:
|
|
virtual bool reset() = 0;
|
|
virtual bool putWord(Uint32 val) = 0;
|
|
virtual bool putWords(const Uint32 * src, Uint32 len) = 0;
|
|
private:
|
|
bool add(const char* value, int len);
|
|
};
|
|
};
|
|
|
|
/**
|
|
* Reader for linear memory
|
|
*/
|
|
class SimplePropertiesLinearReader : public SimpleProperties::Reader {
|
|
public:
|
|
SimplePropertiesLinearReader(const Uint32 * src, Uint32 len);
|
|
|
|
virtual void reset();
|
|
virtual bool step(Uint32 len);
|
|
virtual bool getWord(Uint32 * dst);
|
|
virtual bool peekWord(Uint32 * dst) const ;
|
|
virtual bool peekWords(Uint32 * dst, Uint32 len) const;
|
|
private:
|
|
Uint32 m_len;
|
|
Uint32 m_pos;
|
|
const Uint32 * m_src;
|
|
};
|
|
|
|
/**
|
|
* Writer for linear memory
|
|
*/
|
|
class LinearWriter : public SimpleProperties::Writer {
|
|
public:
|
|
LinearWriter(Uint32 * src, Uint32 len);
|
|
|
|
virtual bool reset();
|
|
virtual bool putWord(Uint32 val);
|
|
virtual bool putWords(const Uint32 * src, Uint32 len);
|
|
Uint32 getWordsUsed() const;
|
|
private:
|
|
Uint32 m_len;
|
|
Uint32 m_pos;
|
|
Uint32 * m_src;
|
|
};
|
|
|
|
/**
|
|
* Writer for UtilBuffer
|
|
*/
|
|
class UtilBufferWriter : public SimpleProperties::Writer {
|
|
public:
|
|
UtilBufferWriter(class UtilBuffer & buf);
|
|
|
|
virtual bool reset();
|
|
virtual bool putWord(Uint32 val);
|
|
virtual bool putWords(const Uint32 * src, Uint32 len);
|
|
Uint32 getWordsUsed() const;
|
|
private:
|
|
class UtilBuffer & m_buf;
|
|
};
|
|
|
|
/**
|
|
* Reader for long signal section memory
|
|
*
|
|
*
|
|
* Implemented in kernel/vm/SimplePropertiesSection.cpp
|
|
*/
|
|
class SimplePropertiesSectionReader : public SimpleProperties::Reader {
|
|
public:
|
|
SimplePropertiesSectionReader(struct SegmentedSectionPtr &,
|
|
class SectionSegmentPool &);
|
|
|
|
virtual void reset();
|
|
virtual bool step(Uint32 len);
|
|
virtual bool getWord(Uint32 * dst);
|
|
virtual bool peekWord(Uint32 * dst) const ;
|
|
virtual bool peekWords(Uint32 * dst, Uint32 len) const;
|
|
Uint32 getSize() const;
|
|
bool getWords(Uint32 * dst, Uint32 len);
|
|
|
|
private:
|
|
Uint32 m_pos;
|
|
Uint32 m_len;
|
|
class SectionSegmentPool & m_pool;
|
|
struct SectionSegment * m_head;
|
|
struct SectionSegment * m_currentSegment;
|
|
};
|
|
|
|
inline
|
|
Uint32 SimplePropertiesSectionReader::getSize() const
|
|
{
|
|
return m_len;
|
|
}
|
|
|
|
/**
|
|
* Writer for long signal section memory
|
|
*
|
|
*
|
|
* Implemented in kernel/vm/SimplePropertiesSection.cpp
|
|
*/
|
|
class SimplePropertiesSectionWriter : public SimpleProperties::Writer {
|
|
public:
|
|
SimplePropertiesSectionWriter(class SectionSegmentPool &);
|
|
|
|
virtual bool reset();
|
|
virtual bool putWord(Uint32 val);
|
|
virtual bool putWords(const Uint32 * src, Uint32 len);
|
|
|
|
/**
|
|
* This "unlinks" the writer from the memory
|
|
*/
|
|
void getPtr(struct SegmentedSectionPtr & dst);
|
|
|
|
private:
|
|
Int32 m_pos;
|
|
Uint32 m_sz;
|
|
class SectionSegmentPool & m_pool;
|
|
struct SectionSegment * m_head;
|
|
Uint32 m_prevPtrI; // Prev to m_currentSegment
|
|
struct SectionSegment * m_currentSegment;
|
|
};
|
|
|
|
#endif
|