include/os.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by www.databasecache.com                           *
00003  *   Contact: praba_tuty@databasecache.com                                 *
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   ***************************************************************************/
00016 #ifndef OS_H
00017 #define OS_H
00018 #include<build.h>
00019 
00020 #if defined(solaris) || defined(LINUX)
00021 
00022 #include <stdio.h>
00023 #include <sys/mman.h>
00024 #include <sys/shm.h>
00025 #include <sys/errno.h>
00026 #include <crypt.h>
00027 #include <unistd.h>
00028 #include <string.h>
00029 #include <stdlib.h>
00030 #include <sys/types.h>
00031 #include <sys/stat.h>
00032 #include <fcntl.h>
00033 #include <pthread.h>
00034 //#include <math.h>
00035 #include <signal.h>
00036 #include <ctype.h>
00037 #include <sys/socket.h>
00038 #if defined(solaris)
00039     #include <sys/varargs.h>
00040 #endif
00041 #if defined(LINUX)
00042     #include <sys/time.h>
00043     #include <stdarg.h>
00044 #endif
00045 typedef void (*sighandler_t)(int);
00046 
00047 enum FileOpenMode
00048 {
00049     fileOpenReadOnly = O_RDONLY,
00050     fileOpenWriteOnly = O_WRONLY,
00051     fileOpenReadWrite = O_RDWR,
00052     fileOpenAppend = O_APPEND |O_RDWR,
00053     fileOpenCreat = O_CREAT |O_RDWR,
00054     // If set and fileOpenExcl is set, the
00055     // open will fail if the file already exists.
00056     fileOpenExcl = O_EXCL,
00057     fileOpenTrunc = O_TRUNC
00058 };
00059 
00060 enum MapProtMode
00061 {
00062     mapProtRead = PROT_READ,
00063     mapProtWrite = PROT_WRITE,
00064     mapProcExec = PROT_EXEC,
00065     mapProcNone = PROT_NONE
00066 };
00067 
00068 enum MapMode
00069 {
00070     mapShared = MAP_SHARED,
00071     mapPrivate = MAP_PRIVATE,
00072     mapFixed = MAP_FIXED,
00073     // Interpret address exactly.
00074     mapNoReserve = MAP_NORESERVE,
00075     // Don't reserver swap space.
00076 
00077     //mapAlign = MAP_ALIGN,
00078     //for msync system call
00079     mapSync = MS_SYNC ,
00080     mapASync = MS_ASYNC
00081 
00082 };
00083 
00084 #define MAX_FILE_LEN 1024
00085 #define IDENTIFIER_LENGTH 128
00086 #define DEFAULT_VALUE_BUF_LENGTH 32
00087 #define SYSTEMDB "SYSTEMDB"
00088 #define DBAUSER "root"
00089 #define DBAPASS "manager"
00090 #define LOCK_BUCKET_SIZE 2048
00091 #define MAX_CHUNKS 20
00092 #define PAGE_SIZE Conf::config.getPageSize()
00093 #define MAX_MUTEX_PER_THREAD 3
00094 #define MAX_THREADS_PER_PROCESS 30
00095 #define MAX_FILE_PATH_LEN 1024
00096 
00097 
00098 #define BIT(x) (1 << (x))
00099 #define SETBITS(x,y) ((x) |= (y))
00100 #define CLEARBITS(x,y) ((x) &= (~(y)))
00101 #define SETBIT(x,y) SETBITS((x), (BIT((y))))
00102 #define CLEARBIT(x,y) CLEARBITS((x), (BIT((y))))
00103 #define BITSET(x,y) ((x) & (BIT(y))) 
00104 
00105 
00106 typedef key_t shared_memory_key;
00107 typedef int   shared_memory_id;
00108 
00109 #endif
00110 
00111 
00112 class os
00113 {
00114     public:
00115     static caddr_t mmap(caddr_t addr, size_t len, int prot, int flags, int fildes, off_t off);
00116     static int munmap(caddr_t addr, size_t len);
00117     static int openFile(const char *name, FileOpenMode flags, size_t size);
00118     static int closeFile(int fd);
00119     static off_t lseek(int fildes, off_t offset, int whence);
00120     static size_t write(int fildes, char *buf, size_t size);
00121     static int msync(caddr_t addr, size_t len, int flags);
00122     static int fsync(int fildes);
00123     static size_t alignLong(size_t size);
00124     static size_t align(size_t size);
00125     static char*  encrypt(const char * key, const char *salt);
00126     static void* memset(void *src, int c, size_t size);
00127     static void* memcpy(void *src, const void *dest, size_t size);
00128     static int   memcmp(const void *s1, const void *s2, size_t size);
00129     static int select(int nfds, fd_set *readfds, fd_set *writefds,
00130                       fd_set *exceptfds, struct timeval * timeout);
00131 
00132     static int usleep(int microsecs);
00133     static int sleep(int secs);
00134     static shared_memory_id shm_create(shared_memory_key key, size_t size, int flag);
00135     static shared_memory_id shm_open(shared_memory_key key, size_t size, int flag);
00136     static void*  shm_attach(shared_memory_id id, const void *ptr, int flag);
00137     static int shm_detach (void*);
00138     static int shmctl(int shmid, int cmd);
00139     static double floor(double val);
00140     static sighandler_t signal(int signum, sighandler_t handler);
00141 
00142     static int gettimeofday(struct timeval *tp);
00143     static struct tm* localtime(long *secs);
00144     static pid_t getpid();
00145     static pthread_t getthrid();
00146     static char* getenv(const char *envVarName);
00147     static int setenv(const char *envVarName, const char *value);
00148 
00149     static int kill(pid_t pid, int sig);
00150     static bool atobool(char *value);
00151     static pid_t createProcess(const char* cmdName, const char *arg0, ...);
00152     static pid_t fork();
00153     static size_t send(int fd, const void *buf, size_t len, int flags);
00154     static size_t recv(int fd, void *buf, size_t len, int flags);
00155 };
00156 
00157 #endif

Generated on Mon Jun 9 22:37:14 2008 for csql by  doxygen 1.4.7