Drizzled Public API Documentation

CSSys.h

00001 /* Copyright (C) 2010 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  * Author: Barry Leslie
00020  *
00021  * 2010-02-05
00022  *
00023  * CORE SYSTEM:
00024  * Basic system specific file I/O classes.
00025  * The classes in this header are defined in CSSys_unix.cc and  CSSys_win.cc
00026  *
00027  */
00028 
00029 #pragma once
00030 #ifndef __CSSYSFILE_H__
00031 #define __CSSYSFILE_H__
00032 
00033 #ifdef OS_WINDOWS
00034 #define INVALID_DIR_HANDLE (INVALID_HANDLE_VALUE)
00035 #define INVALID_FILE_HANDLE (INVALID_HANDLE_VALUE)
00036 #else
00037 #include <dirent.h>
00038 #define INVALID_DIR_HANDLE (NULL)
00039 #define INVALID_FILE_HANDLE (-1)
00040 #endif
00041 
00042 #include "CSString.h"
00043 #include "CSException.h"
00044 #include "CSTime.h"
00045 
00046 class CSSysDir {
00047 public:
00048   CSSysDir(): 
00049     sd_path(NULL),
00050     sd_filter(NULL),
00051     sd_dir(INVALID_DIR_HANDLE){}
00052   
00053   ~CSSysDir();
00054   
00055   void open();
00056   void close();
00057   bool next();
00058 
00059   bool entryIsFile();
00060   const char *entryName();
00061   void getEntryPath(char *path, size_t size);
00062   
00063   CSString *sd_path;
00064   
00065 private:
00066   CSStringBuffer *sd_filter;
00067 #ifdef OS_WINDOWS
00068   WIN32_FIND_DATAA sd_entry;
00069   HANDLE sd_dir;
00070 #else
00071   struct dirent sd_entry;
00072   DIR *sd_dir;
00073 #endif
00074 };
00075 
00076 
00077 class CSSysFile {
00078 public:
00079 
00080   static bool isDirNotFound(CSException *e);
00081   static bool isFileNotFound(CSException *e);
00082   static bool isDirExists(CSException *e);
00083 
00084 CSSysFile(): sf_path(NULL), sf_fh(INVALID_FILE_HANDLE){}
00085 
00086   ~CSSysFile(){ sf_close();}
00087   
00088   bool fs_isOpen() { return ( sf_fh != INVALID_FILE_HANDLE);}
00089   
00090   void sf_open(const char *path, bool readonly, bool create);
00091   void sf_close();
00092   
00093   size_t sf_pread(void *data, size_t size, off64_t offset);
00094   void sf_pwrite(const void *data, size_t size, off64_t offset);
00095   
00096   off64_t sf_getEOF();
00097   void sf_setEOF(off64_t offset);
00098   
00099   void sf_sync();
00100   
00101   void sf_lock(bool shared);
00102   void sf_unlock();
00103   
00104 private:
00105   CSString *sf_path;
00106 #ifdef OS_WINDOWS
00107   HANDLE  sf_fh;
00108 #else
00109   int   sf_fh;
00110 #endif
00111   
00112 };
00113 
00114 class CSSys {
00115   public:
00116   static bool sys_exists(const char *path);
00117   static void sys_makeDir(const char *path);
00118   static void sys_removeDir(const char *path);
00119   static void sys_removeFile(const char *path);
00120   static void sys_rename(const char *old_path, const char *new_path);
00121   static void sys_stat(const char *path, bool *is_dir, off64_t *size, CSTime *mod_time);
00122   static bool sys_isLink(const char *path);
00123   static void sys_getcwd(char *path, size_t size);
00124   static void sys_setcwd(const char *path);
00125   static uint32_t sys_getpid();
00126   static bool sys_isAlive(uint32_t pid);
00127 };
00128 
00129 #endif