iipsrv 0.9.9

Environment.h

00001 /*
00002     IIP Environment Variable Class
00003 
00004     Copyright (C) 2006-2010 Ruven Pillay.
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 */
00020 
00021 #ifndef _ENVIRONMENT_H
00022 #define _ENVIRONMENT_H
00023 
00024 
00025 /* Define some default values
00026  */ 
00027 #define VERBOSITY 1
00028 #define LOGFILE "/tmp/iipsrv.log"
00029 #define MAX_IMAGE_CACHE_SIZE 10.0
00030 #define FILENAME_PATTERN "_pyr_"
00031 #define JPEG_QUALITY 75
00032 #define MAX_CVT 5000
00033 #define MAX_LAYERS 0
00034 #define FILESYSTEM_PREFIX ""
00035 #define WATERMARK ""
00036 #define WATERMARK_PROBABILITY 1.0
00037 #define WATERMARK_OPACITY 1.0
00038 #define LIBMEMCACHED_SERVERS "localhost"
00039 #define LIBMEMCACHED_TIMEOUT 86400  // 24 hours
00040 
00041 
00042 
00043 #include <string>
00044 
00045 
00047 class Environment {
00048 
00049 
00050  public:
00051 
00052   static int getVerbosity(){
00053     int loglevel = VERBOSITY;
00054     char *envpara = getenv( "VERBOSITY" );
00055     if( envpara ){
00056       loglevel = atoi( envpara );
00057       // If not a realistic level, set to zero
00058       if( loglevel < 0 ) loglevel = 0;
00059     }
00060     return loglevel;
00061   }
00062 
00063 
00064   static std::string getLogFile(){
00065     char* envpara = getenv( "LOGFILE" );
00066     if( envpara ) return std::string( envpara );
00067     else return LOGFILE;
00068   }
00069 
00070 
00071   static float getMaxImageCacheSize(){
00072     float max_image_cache_size = MAX_IMAGE_CACHE_SIZE;
00073     char* envpara = getenv( "MAX_IMAGE_CACHE_SIZE" );
00074     if( envpara ){
00075       max_image_cache_size = atof( envpara );
00076     }
00077     return max_image_cache_size;
00078   }
00079 
00080 
00081   static std::string getFileNamePattern(){
00082     char* envpara = getenv( "FILENAME_PATTERN" );
00083     std::string filename_pattern;
00084     if( envpara ){
00085       filename_pattern = std::string( envpara );
00086     }
00087     else filename_pattern = FILENAME_PATTERN;
00088 
00089     return filename_pattern;
00090   }
00091 
00092 
00093   static int getJPEGQuality(){
00094     char* envpara = getenv( "JPEG_QUALITY" );
00095     int jpeg_quality;
00096     if( envpara ){
00097       jpeg_quality = atoi( envpara );
00098       if( jpeg_quality > 100 ) jpeg_quality = 100;
00099       if( jpeg_quality < 1 ) jpeg_quality = 1;
00100     }
00101     else jpeg_quality = JPEG_QUALITY;
00102 
00103     return jpeg_quality;
00104   }
00105 
00106 
00107   static int getMaxCVT(){
00108     char* envpara = getenv( "MAX_CVT" );
00109     int max_CVT;
00110     if( envpara ){
00111       max_CVT = atoi( envpara );
00112       if( max_CVT < 64 ) max_CVT = 64;
00113       if( max_CVT == -1 ) max_CVT = -1;
00114     }
00115     else max_CVT = MAX_CVT;
00116 
00117     return max_CVT;
00118   }
00119 
00120 
00121   static int getMaxLayers(){
00122     char* envpara = getenv( "MAX_LAYERS" );
00123     int layers;
00124     if( envpara ) layers = atoi( envpara );
00125     else layers = MAX_LAYERS;
00126 
00127     return layers;
00128   }
00129 
00130 
00131   static std::string getFileSystemPrefix(){
00132     char* envpara = getenv( "FILESYSTEM_PREFIX" );
00133     std::string filesystem_prefix; 
00134     if( envpara ){ 
00135       filesystem_prefix = std::string( envpara ); 
00136     } 
00137     else filesystem_prefix = FILESYSTEM_PREFIX; 
00138 
00139     return filesystem_prefix;
00140   }
00141 
00142 
00143   static std::string getWatermark(){
00144     char* envpara = getenv( "WATERMARK" );
00145     std::string watermark;
00146     if( envpara ){
00147       watermark = std::string( envpara );
00148     }
00149     else watermark = WATERMARK;
00150 
00151     return watermark;
00152   }
00153 
00154 
00155   static float getWatermarkProbability(){
00156     float watermark_probability = WATERMARK_PROBABILITY;
00157     char* envpara = getenv( "WATERMARK_PROBABILITY" );
00158 
00159     if( envpara ){
00160       watermark_probability = atof( envpara ); 
00161       if( watermark_probability > 1.0 ) watermark_probability = 1.0; 
00162       if( watermark_probability < 0 ) watermark_probability = 0.0; 
00163     }
00164 
00165     return watermark_probability;
00166   }
00167 
00168 
00169   static float getWatermarkOpacity(){ 
00170     float watermark_opacity = WATERMARK_OPACITY;
00171     char* envpara = getenv( "WATERMARK_OPACITY" );
00172 
00173     if( envpara ){
00174       watermark_opacity = atof( envpara );
00175       if( watermark_opacity > 1.0 ) watermark_opacity = 1.0;
00176       if( watermark_opacity < 0 ) watermark_opacity = 0.0;
00177     }
00178 
00179     return watermark_opacity;
00180   }
00181 
00182 
00183   static std::string getMemcachedServers(){
00184     char* envpara = getenv( "MEMCACHED_SERVERS" );
00185     std::string memcached_servers;
00186     if( envpara ){
00187       memcached_servers = std::string( envpara );
00188     }
00189     else memcached_servers = LIBMEMCACHED_SERVERS;
00190 
00191     return memcached_servers;
00192   }
00193 
00194 
00195   static unsigned int getMemcachedTimeout(){
00196     char* envpara = getenv( "MEMCACHED_TIMEOUT" );
00197     unsigned int memcached_timeout;
00198     if( envpara ) memcached_timeout = atoi( envpara );
00199     else memcached_timeout = LIBMEMCACHED_TIMEOUT;
00200 
00201     return memcached_timeout;
00202   }
00203 
00204 
00205 
00206 
00207 };
00208 
00209 
00210 #endif