Adding test framework and some sample test modules and test cases to the sytem.
[csql.git] / include / os.h
blob026e566fc20cfe2d1e3d4f27002475df09e947ef
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #ifndef OS_H
17 #define OS_H
18 #include<build.h>
19 //#define linux 1
20 //#define i686 1
21 //#define solaris
22 //#define sparc
24 #if defined(solaris) || defined(linux)
26 #include <stdio.h>
27 #include <sys/mman.h>
28 #include <sys/shm.h>
29 #include <sys/errno.h>
30 #include <crypt.h>
31 #include <unistd.h>
32 #include <string.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <pthread.h>
37 #include <math.h>
38 #include <signal.h>
39 #if defined(solaris)
40 #include <sys/varargs.h>
41 #endif
42 #if defined(linux)
43 #include <sys/time.h>
44 #include <stdarg.h>
45 #endif
46 typedef void (*sighandler_t)(int);
48 enum FileOpenMode
50 fileOpenReadOnly = O_RDONLY,
51 fileOpenWriteOnly = O_WRONLY,
52 fileOpenReadWrite = O_RDWR,
53 fileOpenAppend = O_APPEND |O_RDWR,
54 fileOpenCreat = O_CREAT |O_RDWR,
55 // If set and fileOpenExcl is set, the
56 // open will fail if the file already exists.
57 fileOpenExcl = O_EXCL,
58 fileOpenTrunc = O_TRUNC
61 enum MapProtMode
63 mapProtRead = PROT_READ,
64 mapProtWrite = PROT_WRITE,
65 mapProcExec = PROT_EXEC,
66 mapProcNone = PROT_NONE
69 enum MapMode
71 mapShared = MAP_SHARED,
72 mapPrivate = MAP_PRIVATE,
73 mapFixed = MAP_FIXED,
74 // Interpret address exactly.
75 mapNoReserve = MAP_NORESERVE,
76 // Don't reserver swap space.
78 //mapAlign = MAP_ALIGN,
79 //for msync system call
80 mapSync = MS_SYNC ,
81 mapASync = MS_ASYNC
85 #define MAX_FILE_LEN 1024
86 #define PAGE_SIZE 8192
87 #define IDENTIFIER_LENGTH 128
88 #define DEFAULT_VALUE_BUF_LENGTH 32
89 #define MAX_CHUNKS 100
90 #define MAX_TRANS 100
91 #define MAX_PROCESS 100
92 #define SYSTEMDB "SYSTEMDB"
93 #define DBAUSER "dba"
94 #define DBAPASS "manager"
95 #define SYSTEM_DB_SIZE 104857600
96 #define USER_DB_SIZE 104857600
97 #define SYSTEMDB_KEY 2222
98 #define USERDB_KEY 5555
99 #define LOGFILE "/tmp/log.out"
100 #define START_ADDR 400000000
101 typedef key_t shared_memory_key;
102 typedef int shared_memory_id;
104 #define LOCK_BUCKET_SIZE 2048
105 #define MUTEX_TIMEOUT_SECS 0
106 #define MUTEX_TIMEOUT_USECS 10
107 #endif
110 class os
112 public:
113 static caddr_t mmap(caddr_t addr, size_t len, int prot, int flags, int fildes, off_t off);
114 static int munmap(caddr_t addr, size_t len);
115 static int openFile(const char *name, FileOpenMode flags, size_t size);
116 static int closeFile(int fd);
117 static off_t lseek(int fildes, off_t offset, int whence);
118 static size_t write(int fildes, char *buf, size_t size);
119 static int msync(caddr_t addr, size_t len, int flags);
120 static int fsync(int fildes);
121 static size_t alignLong(size_t size);
122 static size_t align(size_t size);
123 static char* encrypt(const char * key, const char *salt);
124 static void* memset(void *src, int c, size_t size);
125 static void* memcpy(void *src, const void *dest, size_t size);
126 static int memcmp(const void *s1, const void *s2, size_t size);
127 static int select(int nfds, fd_set *readfds, fd_set *writefds,
128 fd_set *exceptfds, struct timeval * timeout);
130 static shared_memory_id shm_create(shared_memory_key key, size_t size, int flag);
131 static shared_memory_id shm_open(shared_memory_key key, size_t size, int flag);
132 static void* shm_attach(shared_memory_id id, const void *ptr, int flag);
133 static int shm_detach (void*);
134 static int shmctl(int shmid, int cmd);
135 static double floor(double val);
136 static sighandler_t signal(int signum, sighandler_t handler);
138 static int gettimeofday(struct timeval *tp);
139 static struct tm* localtime(long *secs);
140 static int getpid();
141 static int getthrid();
145 #endif