iipsrv  0.9.9
Environment.h
1 /*
2  IIP Environment Variable Class
3 
4  Copyright (C) 2006-2010 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 2 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
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 
41 
42 
43 #include <string>
44 
45 
47 class Environment {
48 
49 
50  public:
51 
52  static int getVerbosity(){
53  int loglevel = VERBOSITY;
54  char *envpara = getenv( "VERBOSITY" );
55  if( envpara ){
56  loglevel = atoi( envpara );
57  // If not a realistic level, set to zero
58  if( loglevel < 0 ) loglevel = 0;
59  }
60  return loglevel;
61  }
62 
63 
64  static std::string getLogFile(){
65  char* envpara = getenv( "LOGFILE" );
66  if( envpara ) return std::string( envpara );
67  else return LOGFILE;
68  }
69 
70 
71  static float getMaxImageCacheSize(){
72  float max_image_cache_size = MAX_IMAGE_CACHE_SIZE;
73  char* envpara = getenv( "MAX_IMAGE_CACHE_SIZE" );
74  if( envpara ){
75  max_image_cache_size = atof( envpara );
76  }
77  return max_image_cache_size;
78  }
79 
80 
81  static std::string getFileNamePattern(){
82  char* envpara = getenv( "FILENAME_PATTERN" );
83  std::string filename_pattern;
84  if( envpara ){
85  filename_pattern = std::string( envpara );
86  }
87  else filename_pattern = FILENAME_PATTERN;
88 
89  return filename_pattern;
90  }
91 
92 
93  static int getJPEGQuality(){
94  char* envpara = getenv( "JPEG_QUALITY" );
95  int jpeg_quality;
96  if( envpara ){
97  jpeg_quality = atoi( envpara );
98  if( jpeg_quality > 100 ) jpeg_quality = 100;
99  if( jpeg_quality < 1 ) jpeg_quality = 1;
100  }
101  else jpeg_quality = JPEG_QUALITY;
102 
103  return jpeg_quality;
104  }
105 
106 
107  static int getMaxCVT(){
108  char* envpara = getenv( "MAX_CVT" );
109  int max_CVT;
110  if( envpara ){
111  max_CVT = atoi( envpara );
112  if( max_CVT < 64 ) max_CVT = 64;
113  if( max_CVT == -1 ) max_CVT = -1;
114  }
115  else max_CVT = MAX_CVT;
116 
117  return max_CVT;
118  }
119 
120 
121  static int getMaxLayers(){
122  char* envpara = getenv( "MAX_LAYERS" );
123  int layers;
124  if( envpara ) layers = atoi( envpara );
125  else layers = MAX_LAYERS;
126 
127  return layers;
128  }
129 
130 
131  static std::string getFileSystemPrefix(){
132  char* envpara = getenv( "FILESYSTEM_PREFIX" );
133  std::string filesystem_prefix;
134  if( envpara ){
135  filesystem_prefix = std::string( envpara );
136  }
137  else filesystem_prefix = FILESYSTEM_PREFIX;
138 
139  return filesystem_prefix;
140  }
141 
142 
143  static std::string getWatermark(){
144  char* envpara = getenv( "WATERMARK" );
145  std::string watermark;
146  if( envpara ){
147  watermark = std::string( envpara );
148  }
149  else watermark = WATERMARK;
150 
151  return watermark;
152  }
153 
154 
155  static float getWatermarkProbability(){
156  float watermark_probability = WATERMARK_PROBABILITY;
157  char* envpara = getenv( "WATERMARK_PROBABILITY" );
158 
159  if( envpara ){
160  watermark_probability = atof( envpara );
161  if( watermark_probability > 1.0 ) watermark_probability = 1.0;
162  if( watermark_probability < 0 ) watermark_probability = 0.0;
163  }
164 
165  return watermark_probability;
166  }
167 
168 
169  static float getWatermarkOpacity(){
170  float watermark_opacity = WATERMARK_OPACITY;
171  char* envpara = getenv( "WATERMARK_OPACITY" );
172 
173  if( envpara ){
174  watermark_opacity = atof( envpara );
175  if( watermark_opacity > 1.0 ) watermark_opacity = 1.0;
176  if( watermark_opacity < 0 ) watermark_opacity = 0.0;
177  }
178 
179  return watermark_opacity;
180  }
181 
182 
183  static std::string getMemcachedServers(){
184  char* envpara = getenv( "MEMCACHED_SERVERS" );
185  std::string memcached_servers;
186  if( envpara ){
187  memcached_servers = std::string( envpara );
188  }
189  else memcached_servers = LIBMEMCACHED_SERVERS;
190 
191  return memcached_servers;
192  }
193 
194 
195  static unsigned int getMemcachedTimeout(){
196  char* envpara = getenv( "MEMCACHED_TIMEOUT" );
197  unsigned int memcached_timeout;
198  if( envpara ) memcached_timeout = atoi( envpara );
199  else memcached_timeout = LIBMEMCACHED_TIMEOUT;
200 
201  return memcached_timeout;
202  }
203 
204 
205 
206 
207 };
208 
209 
210 #endif
Class to obtain environment variables.
Definition: Environment.h:47