converted by lore's source converter


//////////////////////////////////////////////////////////////////////////////
//
// MDataX.h: Declaration of the MDataX class
//
//////////////////////////////////////////////////////////////////////////////
//
// author:     Eckhard Kantz
// website:    http://wegalink.eu
//
//////////////////////////////////////////////////////////////////////////////
/* 
This is FREE software 

Permission is hereby granted, free of charge,  to any person obtaining  a copy 
of this software and associated documentation files (the "Software"),  to deal 
in the Software without restriction, including without limitation  the  rights 
to use,  copy,  modify,  merge,  publish,  distribute, sublicense, and/or sell 
copies  of  the  Software,   and  to  permit  persons  to  whom  the  Software 
is furnished to do so, subject to the following conditions: 

There are no conditions imposed on the use of this software.

THE SOFTWARE IS PROVIDED "AS IS",  WITHOUT  WARRANTY  OF ANY KIND,  EXPRESS OR
IMPLIED,  INCLUDING  BUT  NOT  LIMITED  TO  THE  WARRANTIES OF MERCHANTABILITY,
FITNESS  FOR  A  PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS  OR  COPYRIGHT  HOLDERS  BE  LIABLE  FOR  ANY CLAIM,  DAMAGES OR OTHER
LIABILITY,  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN  THE
SOFTWARE.
*/

#ifndef _MDataX_H_
#define _MDataX_H_

#include "MTypes.h"

struct stTimePeriodHierarchy;

// Define DataX data types
#define DATAX_BINX_MAX  (uint32)0x81BF0FFF   // = 216^4-1
enum DATAX_DATA_TYPE_IDENTIFIER {
   DATAX_OPEN  = DATAX_BINX_MAX - 0,
   BINX_WRAP   = DATAX_BINX_MAX - 1,
   BINX_BINARY = DATAX_BINX_MAX - 2,
   BINX_TEXT   = DATAX_BINX_MAX - 3,
   BINX_TIME   = DATAX_BINX_MAX - 4,
   BINMCL      = DATAX_BINX_MAX - 5,
};

class MDataX
{
public:
    MDataX(int8* szIdentifier,int8* szFileName="datax.csv",int8* szDataXroot="");
    virtual ~MDataX();

   // Test all functionality in the DataX unit
   void unitTest();

   // Convert numbers into legal BinX characters
   unsigned char bcode(unsigned char byt);
   unsigned char bdecode(unsigned char byt);

   // Convert numbers to and from a BinX string
   MString* num2BinX(MString*,uint64*);
   MString* num2BinX(MString*,uint64);
   uint64   BinX2num(MString&);

   // Convert binary data to and from a BinX string
   MString* bin2BinX(MString*,uint8*,int32,int32 =0);
   int32    BinX2bin(uint8*,int32,MString&,bool =false);

   // Convert binary data to and from a BinMCL string
   void bin2BinMCL(int n, uint16 *inp, uint16 *out);
   void BinMCL2bin(int n, uint16 *inp, uint16 *out);

   // Transfer data from and to a DataX repository
   void readData(time_t,MString*);
    void writeData(time_t,MString&);
    void writeData(time_t,char*,int);
   void dumpData(time_t,MString*,MString&);

   // Access measurement data
   bool getFirstTimestamp(uint64*);
   bool getNextTimestamp(uint64*);
   bool getNextSample(MString&);

   // Special functions
   bool isDataTypeIdentifier(MString&,DATAX_DATA_TYPE_IDENTIFIER);
   void logMessage(int8*,MString&,int8* ="\n");
   void logMessage(int8*,uint32,int8* ="\n");

public:
   MString        ParentCollection; // Starting point for parallel read/write operations
   MString        FileName;         // descriptive component in a DataX file name
   MString        Parameters;       // parameter template file
   unsigned int   FilePeriod;       // time period between two DataX files

protected:
    void openTimePeriodFile(time_t,bool fCreate=false);
   void enterSubDirectory(stTimePeriodHierarchy*,unsigned int*,MString&,bool fCreate=false);

private:
   int            data_fd;       // file descriptor
   unsigned int   TimeIndex;        // 
   unsigned int   FileIndex;        //
    MString         InitialDir;        // current directory before DataX changed it
    MString       Identifier;       // unique identifier for a DataX repository
   MString        DataXroot;        // root directory of the DataX repository
   MString        DeviceDir;        // identifier folder below the DataX root
    MString         Delimiter;         // operating system's path delimiter character
    MString       LogFile;       // default logfile
   uint16*        BinXconvert;      //

};

// Parameter definition for a time period based directory hierarchy
struct stTimePeriodHierarchy {
   unsigned int period;
   char*     dir_format;
   char*     file_format;
};

#endif