Drizzled Public API Documentation

table_ms.h
00001 /* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
00002  *
00003  * PrimeBase Media Stream for MySQL
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00018  *
00019  * Original author: Paul McCullagh
00020  * Continued development: Barry Leslie
00021  *
00022  * 2007-06-26
00023  *
00024  * H&G2JCtL
00025  *
00026  * Contains the information about a table.
00027  *
00028  */
00029 
00030 #pragma once
00031 #ifndef __TABLE_MS_H__
00032 #define __TABLE_MS_H__
00033 
00034 #include "defs_ms.h"
00035 
00036 #define MS_TABLE_FILE_MAGIC     0x1234ABCD
00037 #define MS_TABLE_FILE_VERSION   1
00038 #define MS_TABLE_FILE_HEAD_SIZE   128
00039 
00040 class MSOpenTable;
00041 class MSDatabase;
00042 class CSHTTPOutputStream;
00043 
00044 typedef struct MSTableHead {
00045   CSDiskValue4      th_magic_4;             /* Table magic number. */
00046   CSDiskValue2      th_version_2;           /* The header version. */
00047   CSDiskValue2      th_head_size_2;           /* The size of the header. */
00048   CSDiskValue8      th_free_list_8;
00049 
00050   /* These 3 fields are written together by prepareToDelete()! */
00051   CSDiskValue4      th_del_time_4;            /* The time this table was deleted. */
00052   CSDiskValue4      th_temp_log_id_4;         /* The temp log entry for this deleted table. */
00053   CSDiskValue4      th_temp_log_offset_4;
00054 
00055   CSDiskValue4      th_reserved_4;
00056 } MSTableHeadRec, *MSTableHeadPtr;
00057 
00058 /* File offset = th_size_4 + (Blob ID - 1) * sizeof(MSTableBlobRec) */ 
00059 typedef struct MSTableBlob {
00060   CSDiskValue1      tb_status_1;            /* 0 = free, 1 = inuse*/
00061 
00062   /* These 3 fields are written together: */
00063   CSDiskValue3      tb_repo_id_3;           /* File ID (non-zero). */
00064   CSDiskValue6      tb_offset_6;            /* Offset into the file of the BLOB. */
00065   CSDiskValue2      tb_header_size_2;         /* Size of the header section of the blob. */
00066 
00067   CSDiskValue6      tb_size_6;              /* Size of the BLOB data. (Where ever it may be stored.) */ 
00068   CSDiskValue4      tb_auth_code_4;           /* BLOB authorisation code. */
00069 } MSTableBlobRec, *MSTableBlobPtr;
00070 
00071 typedef struct MSTableFreeBlob {
00072   CSDiskValue4      tf_null_4;              /* Set to zero */
00073   CSDiskValue6      tf_next_6;              /* Next record in the free list. */
00074 } MSTableFreeBlobRec, *MSTableFreeBlobPtr;
00075 
00076 class MSTable : public CSSharedRefObject {
00077 public:
00078   CSString  *myTableName;
00079   uint32_t    myTableID;
00080   MSDatabase  *myDatabase;
00081 
00082   MSTable();
00083   virtual ~MSTable();
00084 
00085   CSPath *getTableFile(const char *table_name, bool to_delete);
00086 
00087   CSPath *getTableFile();
00088 
00089   CSFile *openTableFile();
00090   
00091   void prepareToDelete();
00092 
00093   uint64_t createBlobHandle(MSOpenTable *otab, uint32_t repo_id, uint64_t file_offset, uint64_t size, uint16_t head_size, uint32_t auth_code);
00094 
00095   uint64_t findBlobHandle(MSOpenTable *otab, uint32_t repo_id, uint64_t file_offset, uint64_t size, uint16_t head_size, uint32_t auth_code);
00096 
00097   void setBlobHandle(MSOpenTable *otab, uint64_t blob_id, uint32_t repo_id, uint64_t file_offset, uint64_t size, uint16_t head_size, uint32_t auth_code);
00098 
00099   void updateBlobHandle(MSOpenTable *otab, uint64_t blob_id, uint32_t repo_id, uint64_t offset, uint16_t head_size);
00100 
00101   bool readBlobHandle(MSOpenTable *otab, uint64_t blob_id, uint32_t *auth_code, uint32_t *repo_id, uint64_t *offset, uint64_t *data_size, uint16_t *head_size, bool throw_error);
00102 
00103   void freeBlobHandle(MSOpenTable *otab, uint64_t blob_id, uint32_t repo_id, uint64_t file_offset, uint32_t auth_code);
00104 
00105   /* Make this object hashable: */
00106   virtual CSObject *getKey();
00107   virtual int compareKey(CSObject *);
00108   virtual uint32_t hashKey();
00109 
00110   off64_t getTableFileSize() { return iTableFileSize; }
00111   CSString *getTableName();
00112   bool isToDelete() { return iToDelete; }
00113   void getDeleteInfo(uint32_t *log, uint32_t *offs, time_t *tim);
00114   bool isNoTable() { return myTableName->length() == 0; }
00115 
00116 private:
00117   off64_t   iTableFileSize;
00118   size_t    iTableHeadSize;
00119   off64_t   iFreeList;
00120   bool    iToDelete;
00121   uint32_t    iTabDeleteTime;
00122   uint32_t    iTabTempLogID;
00123   uint32_t    iTabTempLogOffset;
00124 
00125 public:
00126   static MSTable *newTable(uint32_t tab_id, CSString *name, MSDatabase *db, off64_t file_size, bool to_delete);
00127 
00128   static MSTable *newTable(uint32_t tab_id, const char *name, MSDatabase *db, off64_t file_size, bool to_delete); 
00129 };
00130 
00131 #endif