00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019 #ifndef __ENV_H__
00020 #define __ENV_H__
00021
00022 #include "jic/exc/excepcion.hpp"
00023 #include <string>
00024 #include <unistd.h>
00025
00026 EXCEPCION(ExcENVNoIniciado);
00027
00028 namespace UTIL {
00029
00030
00031 class ENV {
00032 public:
00033
00034 static void inicio(int &argc, char** argv,
00035 const char* aplicacion = 0,
00036 const char* modulo = 0);
00037
00038
00039 inline static const char* nombrePrograma();
00040 inline static const char* pathPrograma();
00041 inline static const char* dirPrograma();
00042 inline static int &argc();
00043 inline static char **argv();
00044 inline static pid_t pid();
00045 inline static const char* host();
00046 inline static const char* aplicacion();
00047 inline static const char* modulo();
00048 static const char* spid();
00049
00050 private:
00051
00052 inline static void valida();
00053
00054 static int *_argc;
00055 static char** _argv;
00056
00057 static std::string _nombrePrograma;
00058 static std::string _dir;
00059 static std::string _modulo;
00060 static pid_t _pid;
00061 static std::string _host;
00062 static std::string _aplicacion;
00063
00064 static bool _bIniciado;
00065
00066 };
00067
00069
00070 void
00071 ENV::valida()
00072 {
00073 if (! _bIniciado)
00074 {
00075 THROW(ExcENVNoIniciado,"");
00076 }
00077 }
00078
00079
00080
00081 const char*
00082 ENV::nombrePrograma()
00083 {
00084 valida();
00085 return _nombrePrograma.c_str();
00086 }
00087
00088
00089
00090 const char*
00091 ENV::pathPrograma()
00092 {
00093 valida();
00094 std::string sTmp = _dir + std::string("/") + _nombrePrograma;
00095 return sTmp.c_str();
00096 }
00097
00098
00099
00100 const char*
00101 ENV::dirPrograma()
00102 {
00103 valida();
00104 return _dir.c_str();
00105 }
00106
00107
00108
00109 int &
00110 ENV::argc()
00111 {
00112 valida();
00113 return *_argc;
00114 }
00115
00116
00117
00118 char **
00119 ENV::argv()
00120 {
00121 valida();
00122 return _argv;
00123 }
00124
00125
00126
00127 pid_t
00128 ENV::pid()
00129 {
00130 valida();
00131 return _pid;
00132 }
00133
00134
00135
00136 const char*
00137 ENV::host()
00138 {
00139 valida();
00140 return _host.c_str();
00141 }
00142
00143
00144
00145 const char*
00146 ENV::aplicacion()
00147 {
00148 valida();
00149 return _aplicacion.empty() ? "":_aplicacion.c_str();
00150 }
00151
00152
00153
00154 const char*
00155 ENV::modulo()
00156 {
00157 valida();
00158 return _modulo.empty() ?"":_modulo.c_str();
00159 }
00160
00162
00163 }
00164
00165 #endif
00166