iipsrv  1.0
Environment.h
1 /*
2  IIP Environment Variable Class
3 
4  Copyright (C) 2006-2016 Ruven Pillay.
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software Foundation,
18  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef _ENVIRONMENT_H
22 #define _ENVIRONMENT_H
23 
24 
25 /* Define some default values
26  */
27 #define VERBOSITY 1
28 #define LOGFILE "/tmp/iipsrv.log"
29 #define MAX_IMAGE_CACHE_SIZE 10.0
30 #define FILENAME_PATTERN "_pyr_"
31 #define JPEG_QUALITY 75
32 #define MAX_CVT 5000
33 #define MAX_LAYERS 0
34 #define FILESYSTEM_PREFIX ""
35 #define WATERMARK ""
36 #define WATERMARK_PROBABILITY 1.0
37 #define WATERMARK_OPACITY 1.0
38 #define LIBMEMCACHED_SERVERS "localhost"
39 #define LIBMEMCACHED_TIMEOUT 86400 // 24 hours
40 #define INTERPOLATION 1
41 #define CORS "";
42 #define BASE_URL "";
43 #define CACHE_CONTROL "max-age=86400"; // 24 hours
44 
45 
46 #include <string>
47 
48 
50 class Environment {
51 
52 
53  public:
54 
55  static int getVerbosity(){
56  int loglevel = VERBOSITY;
57  char *envpara = getenv( "VERBOSITY" );
58  if( envpara ){
59  loglevel = atoi( envpara );
60  // If not a realistic level, set to zero
61  if( loglevel < 0 ) loglevel = 0;
62  }
63  return loglevel;
64  }
65 
66 
67  static std::string getLogFile(){
68  char* envpara = getenv( "LOGFILE" );
69  if( envpara ) return std::string( envpara );
70  else return LOGFILE;
71  }
72 
73 
74  static float getMaxImageCacheSize(){
75  float max_image_cache_size = MAX_IMAGE_CACHE_SIZE;
76  char* envpara = getenv( "MAX_IMAGE_CACHE_SIZE" );
77  if( envpara ){
78  max_image_cache_size = atof( envpara );
79  }
80  return max_image_cache_size;
81  }
82 
83 
84  static std::string getFileNamePattern(){
85  char* envpara = getenv( "FILENAME_PATTERN" );
86  std::string filename_pattern;
87  if( envpara ){
88  filename_pattern = std::string( envpara );
89  }
90  else filename_pattern = FILENAME_PATTERN;
91 
92  return filename_pattern;
93  }
94 
95 
96  static int getJPEGQuality(){
97  char* envpara = getenv( "JPEG_QUALITY" );
98  int jpeg_quality;
99  if( envpara ){
100  jpeg_quality = atoi( envpara );
101  if( jpeg_quality > 100 ) jpeg_quality = 100;
102  if( jpeg_quality < 1 ) jpeg_quality = 1;
103  }
104  else jpeg_quality = JPEG_QUALITY;
105 
106  return jpeg_quality;
107  }
108 
109 
110  static int getMaxCVT(){
111  char* envpara = getenv( "MAX_CVT" );
112  int max_CVT;
113  if( envpara ){
114  max_CVT = atoi( envpara );
115  if( max_CVT < 64 ) max_CVT = 64;
116  }
117  else max_CVT = MAX_CVT;
118 
119  return max_CVT;
120  }
121 
122 
123  static int getMaxLayers(){
124  char* envpara = getenv( "MAX_LAYERS" );
125  int layers;
126  if( envpara ) layers = atoi( envpara );
127  else layers = MAX_LAYERS;
128 
129  return layers;
130  }
131 
132 
133  static std::string getFileSystemPrefix(){
134  char* envpara = getenv( "FILESYSTEM_PREFIX" );
135  std::string filesystem_prefix;
136  if( envpara ){
137  filesystem_prefix = std::string( envpara );
138  }
139  else filesystem_prefix = FILESYSTEM_PREFIX;
140 
141  return filesystem_prefix;
142  }
143 
144 
145  static std::string getWatermark(){
146  char* envpara = getenv( "WATERMARK" );
147  std::string watermark;
148  if( envpara ){
149  watermark = std::string( envpara );
150  }
151  else watermark = WATERMARK;
152 
153  return watermark;
154  }
155 
156 
157  static float getWatermarkProbability(){
158  float watermark_probability = WATERMARK_PROBABILITY;
159  char* envpara = getenv( "WATERMARK_PROBABILITY" );
160 
161  if( envpara ){
162  watermark_probability = atof( envpara );
163  if( watermark_probability > 1.0 ) watermark_probability = 1.0;
164  if( watermark_probability < 0 ) watermark_probability = 0.0;
165  }
166 
167  return watermark_probability;
168  }
169 
170 
171  static float getWatermarkOpacity(){
172  float watermark_opacity = WATERMARK_OPACITY;
173  char* envpara = getenv( "WATERMARK_OPACITY" );
174 
175  if( envpara ){
176  watermark_opacity = atof( envpara );
177  if( watermark_opacity > 1.0 ) watermark_opacity = 1.0;
178  if( watermark_opacity < 0 ) watermark_opacity = 0.0;
179  }
180 
181  return watermark_opacity;
182  }
183 
184 
185  static std::string getMemcachedServers(){
186  char* envpara = getenv( "MEMCACHED_SERVERS" );
187  std::string memcached_servers;
188  if( envpara ){
189  memcached_servers = std::string( envpara );
190  }
191  else memcached_servers = LIBMEMCACHED_SERVERS;
192 
193  return memcached_servers;
194  }
195 
196 
197  static unsigned int getMemcachedTimeout(){
198  char* envpara = getenv( "MEMCACHED_TIMEOUT" );
199  unsigned int memcached_timeout;
200  if( envpara ) memcached_timeout = atoi( envpara );
201  else memcached_timeout = LIBMEMCACHED_TIMEOUT;
202 
203  return memcached_timeout;
204  }
205 
206 
207  static unsigned int getInterpolation(){
208  char* envpara = getenv( "INTERPOLATION" );
209  unsigned int interpolation;
210  if( envpara ) interpolation = atoi( envpara );
211  else interpolation = INTERPOLATION;
212 
213  return interpolation;
214  }
215 
216 
217  static std::string getCORS(){
218  char* envpara = getenv( "CORS" );
219  std::string cors;
220  if( envpara ) cors = std::string( envpara );
221  else cors = CORS;
222  return cors;
223  }
224 
225 
226  static std::string getBaseURL(){
227  char* envpara = getenv( "BASE_URL" );
228  std::string base_url;
229  if( envpara ) base_url = std::string( envpara );
230  else base_url = BASE_URL;
231  return base_url;
232  }
233 
234 
235  static std::string getCacheControl(){
236  char* envpara = getenv( "CACHE_CONTROL" );
237  std::string cache_control;
238  if( envpara ) cache_control = std::string( envpara );
239  else cache_control = CACHE_CONTROL;
240  return cache_control;
241  }
242 
243 };
244 
245 
246 #endif
Class to obtain environment variables.
Definition: Environment.h:50