submitting patch from enterprise version
[csql.git] / include / Config.h
blob1c1268b9c11795ab8bacc9d269b53cf31695e3f3
1 /***************************************************************************
2 * *
3 * Copyright (C) Lakshya Solutions Ltd. All rights reserved. *
4 * *
5 ***************************************************************************/
7 #ifndef CONFIG_H
8 #define CONFIG_H
9 #include<os.h>
10 #include<Util.h>
12 enum CacheMode {
13 SYNC_MODE=0,
14 ASYNC_MODE=1,
15 UNKNOWN=100
17 enum TDBInfo
19 mysql=0,
20 postgres,
21 oracle,
22 sybase,
23 db2,
24 sqlserver,
27 class ConfigValues
29 public:
30 //All the members of the configuration file
31 char logFile[MAX_FILE_PATH_LEN];
32 char dbFile[MAX_FILE_PATH_LEN];
33 char tableConfigFile[MAX_FILE_PATH_LEN];
34 char dsConfigFile[MAX_FILE_PATH_LEN];// DSN Config file
35 char stderrFile[MAX_FILE_PATH_LEN];
36 char replConfigFile[MAX_FILE_PATH_LEN];
37 char conflResoFile[MAX_FILE_PATH_LEN];
39 bool isDurable;
40 bool mmap;
41 bool isCsqlSqlServer;
42 bool isCache;
43 bool isTwoWay;
44 bool isReplication;
46 int siteID;
47 int sysDbKey;
48 int userDbKey;
49 long maxSysSize;
50 long maxDbSize;
51 int pageSize;
52 int maxProcs;
54 long mapAddr;
56 int mutexSecs;
57 int mutexUSecs;
58 int mutexRetries;
59 int lockSecs;
60 int lockUSecs;
61 int lockRetries;
62 int logLevel;
64 int durableMode;
65 char dsn[IDENTIFIER_LENGTH];
66 CacheMode mode;
67 int cacheWaitSecs;
69 int port;
70 int nwResponseTimeout;
71 int nwConnectTimeout;
72 int maxReplSites;
74 int msgKey;
75 int asyncMsgMax;
76 int shmKeyForId;
77 long maxQueueLogs;
78 int noOfProcessors;
80 ConfigValues()
82 strcpy(logFile, "/tmp/log/log.out");
83 strcpy(dbFile, "/tmp/csql/db");
84 strcpy(tableConfigFile, "/tmp/csql/csqltable.conf");
85 strcpy(dsConfigFile,"/tmp/csql/csqlds.conf"); // DSN Config file
86 strcpy(stderrFile, "stderr");
87 strcpy(replConfigFile, "/tmp/csql/csqlnw.conf");
88 strcpy(conflResoFile, "/tmp/csql/ConflResoFile.txt");
90 isDurable = false;
91 mmap = false;
92 isCsqlSqlServer = false;
93 isCache = false;
94 isTwoWay=false;
95 isReplication = false;
97 siteID=1;
98 sysDbKey = 2222;
99 userDbKey = 5555;
100 maxSysSize = 10485760;
101 maxDbSize = 104857600;
102 pageSize = 8192;
103 maxProcs = 20;
105 mapAddr=400000000;
107 mutexSecs=0;
108 mutexUSecs=10;
109 mutexRetries = 10;
110 lockSecs =0;
111 lockUSecs = 10;
112 lockRetries = 10;
113 logLevel = 0;
115 durableMode=1;
116 strcpy(dsn,"myodbc3");
117 mode = SYNC_MODE;
118 cacheWaitSecs =10;
120 port = 5678;
121 nwResponseTimeout=3;
122 nwConnectTimeout=5;
123 maxReplSites=1;
124 msgKey=-1;
125 asyncMsgMax = 8192; //default for linux
126 shmKeyForId = -1;
127 maxQueueLogs = 100;
128 noOfProcessors = 1;
132 class Config
134 ConfigValues cVal;
135 bool isLoaded;
136 int readLine(FILE *fp, char * buffer);
137 int storeKeyVal(char *key, char *val);
138 int validateValues();
140 public:
141 Config() { isLoaded = false; }
142 int readAllValues(char *filename);
143 void print();
144 void logConfig();
145 inline int getPageSize() { return cVal.pageSize; }
146 inline int getMaxProcs() { return cVal.maxProcs; }
147 inline long getMaxSysDbSize() { return cVal.maxSysSize; }
148 inline long getMaxDbSize() { return cVal.maxDbSize; }
149 inline int getSysDbKey() { return cVal.sysDbKey; }
150 inline int getUserDbKey() { return cVal.userDbKey; }
151 inline bool useMmap() { return cVal.mmap; }
152 inline char* getLogFile() { return cVal.logFile; }
153 inline char* getDbFile() { return cVal.dbFile; }
154 inline long getMapAddress() { return cVal.mapAddr; }
155 inline int getMutexSecs() { return cVal.mutexSecs; }
156 inline int getMutexUSecs() { return cVal.mutexUSecs; }
157 inline int getMutexRetries() { return cVal.mutexRetries; }
158 inline int getLockSecs() { return cVal.lockSecs; }
159 inline int getLockUSecs() { return cVal.lockUSecs; }
160 inline int getLockRetries() { return cVal.lockRetries; }
161 inline int getSiteID(){ return cVal.siteID;}
162 inline bool useCache() { return cVal.isCache; }
163 inline int getCacheMode() { return (int) cVal.mode; }
164 inline char* getDSN() { return cVal.dsn; }
165 inline char* getDsConfigFile() { return cVal.dsConfigFile; }
166 inline char* getTableConfigFile() { return cVal.tableConfigFile; }
167 inline char* getStderrFile() { return cVal.stderrFile; }
168 inline bool useReplication() { return cVal.isReplication; }
169 inline bool useDurability() { return cVal.isDurable; }
170 inline int getDurableMode() { return cVal.durableMode; }
171 inline bool useCsqlSqlServer() { return cVal.isCsqlSqlServer; }
172 inline int getPort() { return cVal.port; }
173 inline char* getReplConfigFile() { return cVal.replConfigFile; }
174 inline char* getConflResoFile() { return cVal.conflResoFile; }
175 inline long getMaxQueueLogs() { return cVal.maxQueueLogs; }
176 inline int getNoOfReplSites() { return cVal.maxReplSites; }
177 inline int getMsgKey() { return cVal.msgKey; }
178 inline int getAsyncMsgMax() { return cVal.asyncMsgMax; }
179 inline int getShmIDKey() { return cVal.shmKeyForId; }
180 inline int getNetworkResponseTimeout() { return cVal.nwResponseTimeout; }
181 inline int getNetworkConnectTimeout() { return cVal.nwConnectTimeout; }
182 inline bool useTwoWayCache() { return cVal.isTwoWay; }
183 inline int getCacheWaitSecs() { return cVal.cacheWaitSecs; }
184 inline int getLogLevel() { return cVal.logLevel; }
185 inline int getNoOfProcessors() { return cVal.noOfProcessors; }
188 class Conf
190 public:
191 static Config config;
192 static Logger logger;
195 class SiteInfoData
197 public:
198 int siteId;
199 char hostName[IDENTIFIER_LENGTH];
200 int port;
201 char mode[32];
202 SiteInfoData() { siteId = -1; port = 0; hostName[0]='\0'; mode[0]='\0';};
206 class SiteInfo
208 DbRetVal populateSiteInfoList();
209 public:
210 List siteInfoList;
211 List asyncSiteList;
212 List syncSiteList;
213 bool isAsyncSitePresent();
214 bool isSyncSitePresent();
215 SiteInfo() { populateSiteInfoList(); }
216 ~SiteInfo();
217 List & getSiteInfoList() { return siteInfoList; }
218 List & getSyncSiteInfoList() { return syncSiteList; }
219 List & getAsyncSiteInfoList() { return asyncSiteList; }
222 #endif