|
UniSet
2.2.1
|
00001 /* This file is part of the UniSet project 00002 * Copyright (c) 2002-2005 Free Software Foundation, Inc. 00003 * Copyright (c) 2002 Pavel Vainerman 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 // -------------------------------------------------------------------------- 00024 // -------------------------------------------------------------------------- 00025 #ifndef UniSetTypes_H_ 00026 #define UniSetTypes_H_ 00027 // -------------------------------------------------------------------------- 00028 #include <memory> 00029 #include <cstdlib> 00030 #include <cstdio> 00031 #include <string> 00032 #include <list> 00033 #include <vector> 00034 #include <limits> 00035 #include <ostream> 00036 #include <unistd.h> 00037 00038 #include <omniORB4/CORBA.h> 00039 #include "UniSetTypes_i.hh" 00040 #include "IOController_i.hh" 00041 #include "Mutex.h" 00042 #include "UniXML.h" 00043 // ----------------------------------------------------------------------------------------- 00045 inline void msleep( unsigned int m ) 00046 { 00047 usleep(m * 1000); 00048 } 00049 00051 namespace UniSetTypes 00052 { 00053 class Configuration; 00054 // --------------------------------------------------------------- 00055 // Вспомогательные типы данных и константы 00056 00057 const ObjectId DefaultObjectId = -1; 00058 const ThresholdId DefaultThresholdId = -1; 00059 const ThresholdId DefaultTimerId = -1; 00061 const ObjectId AdminID = -2; 00063 typedef unsigned long KeyType; 00073 inline static KeyType key( const UniSetTypes::ObjectId id, const UniSetTypes::ObjectId node ) 00074 { 00075 return KeyType((id * node) + (id + 2 * node)); 00076 } 00077 00078 inline static KeyType key( const IOController_i::SensorInfo& si ) 00079 { 00080 return key(si.id, si.node); 00081 } 00082 00083 typedef std::list<std::string> ListObjectName; 00085 typedef ObjectId SysId; 00086 typedef CORBA::Object_ptr ObjectPtr; 00087 typedef CORBA::Object_var ObjectVar; 00089 UniversalIO::IOType getIOType( const std::string& s ); 00090 std::ostream& operator<<( std::ostream& os, const UniversalIO::IOType t ); 00091 std::ostream& operator<<( std::ostream& os, const IONotifyController_i::ThresholdInfo& ti ); 00092 std::ostream& operator<<( std::ostream& os, const IOController_i::ShortIOInfo& s ); 00093 std::ostream& operator<<( std::ostream& os, const IONotifyController_i::ThresholdState& s); 00094 00096 enum LampCommand 00097 { 00098 lmpOFF = 0, 00099 lmpON = 1, 00100 lmpBLINK = 2, 00101 lmpBLINK2 = 3, 00102 lmpBLINK3 = 4 00103 }; 00104 00105 static const long ChannelBreakValue = std::numeric_limits<long>::max(); 00106 00107 class IDList 00108 { 00109 public: 00110 00111 IDList( std::vector<std::string>& v ); 00112 IDList( std::vector<std::string>&& v ); 00113 IDList(); 00114 ~IDList(); 00115 00116 void add( ObjectId id ); 00117 void del( ObjectId id ); 00118 00119 inline int size() const 00120 { 00121 return lst.size(); 00122 } 00123 inline bool empty() const 00124 { 00125 return lst.empty(); 00126 } 00127 00128 std::list<ObjectId> getList(); 00129 00130 // за освобождение выделеной памяти 00131 // отвечает вызывающий! 00132 IDSeq* getIDSeq() const; 00133 00134 // 00135 ObjectId getFirst() const; 00136 ObjectId node; // узел, на котором находятся датчики 00137 00138 private: 00139 std::list<ObjectId> lst; 00140 }; 00141 00143 struct ObjectInfo 00144 { 00145 ObjectInfo(): 00146 id(DefaultObjectId), 00147 repName(""), textName(""), data(0) {} 00148 00149 ObjectId id; 00150 std::string repName; 00151 std::string textName; 00152 void* data; 00153 00154 inline bool operator < ( const ObjectInfo& o ) const 00155 { 00156 return (id < o.id); 00157 } 00158 }; 00159 00160 typedef std::list<NodeInfo> ListOfNode; 00161 00163 const char BadSymbols[] = {'.', '/'}; 00164 00165 // --------------------------------------------------------------- 00166 // Различные преобразования 00167 00169 int uni_atoi( const char* str ); 00170 inline int uni_atoi( const std::string& str ) 00171 { 00172 return uni_atoi(str.c_str()); 00173 } 00174 00175 char* uni_strdup( const std::string& src ); 00176 00177 std::string timeToString(time_t tm = time(0), const std::string& brk = ":"); 00178 std::string dateToString(time_t tm = time(0), const std::string& brk = "/"); 00181 IDList explode( const std::string& str, char sep = ',' ); 00182 std::vector<std::string> explode_str( const std::string& str, char sep = ',' ); 00183 00184 struct ParamSInfo 00185 { 00186 IOController_i::SensorInfo si; 00187 long val; 00188 std::string fname; // fullname id@node or id 00189 }; 00190 00194 std::list<ParamSInfo> getSInfoList( const std::string& s, std::shared_ptr<UniSetTypes::Configuration> conf = nullptr ); 00195 00196 00199 std::list<UniSetTypes::ConsumerInfo> getObjectsList( const std::string& s, std::shared_ptr<UniSetTypes::Configuration> conf = nullptr ); 00200 00202 bool is_digit( const std::string& s ); 00203 00204 // --------------------------------------------------------------- 00205 // Работа с командной строкой 00206 00211 inline std::string getArgParam( const std::string& name, 00212 int _argc, const char* const* _argv, 00213 const std::string& defval = "" ) 00214 { 00215 for( int i = 1; i < (_argc - 1) ; i++ ) 00216 { 00217 if( name == _argv[i] ) 00218 return _argv[i + 1]; 00219 } 00220 00221 return defval; 00222 } 00223 00224 inline int getArgInt( const std::string& name, 00225 int _argc, const char* const* _argv, 00226 const std::string defval = "" ) 00227 { 00228 return uni_atoi(getArgParam(name, _argc, _argv, defval)); 00229 } 00230 00238 inline int findArgParam( const std::string& name, int _argc, const char* const* _argv ) 00239 { 00240 for( int i = 1; i < _argc; i++ ) 00241 { 00242 if( name == _argv[i] ) 00243 return i; 00244 } 00245 00246 return -1; 00247 } 00248 00249 // --------------------------------------------------------------- 00250 // Калибровка 00251 00252 std::ostream& operator<<( std::ostream& os, const IOController_i::CalibrateInfo& c ); 00253 00254 // Функции калибровки значений 00255 // raw - преобразуемое значение 00256 // rawMin - минимальная граница исходного диапазона 00257 // rawMax - максимальная граница исходного диапазона 00258 // calMin - минимальная граница калиброванного диапазона 00259 // calMin - минимальная граница калиброванного диапазона 00260 // limit - обрезать итоговое значение по границам 00261 float fcalibrate(float raw, float rawMin, float rawMax, float calMin, float calMax, bool limit = true ); 00262 long lcalibrate(long raw, long rawMin, long rawMax, long calMin, long calMax, bool limit = true ); 00263 00264 // установка значения в нужный диапазон 00265 long setinregion(long raw, long rawMin, long rawMax); 00266 // установка значения вне диапазона 00267 long setoutregion(long raw, long rawMin, long rawMax); 00268 00269 // --------------------------------------------------------------- 00270 // Всякие helper-ы 00271 00272 bool file_exist( const std::string& filename ); 00273 00274 // Проверка xml-узла на соответствие <...f_prop="f_val">, 00275 // если не задано f_val, то проверяется, что просто f_prop!="" 00276 bool check_filter( UniXML::iterator& it, const std::string& f_prop, const std::string& f_val = "" ); 00277 00279 template<typename InputIterator, 00280 typename OutputIterator, 00281 typename Predicate> 00282 OutputIterator copy_if(InputIterator begin, 00283 InputIterator end, 00284 OutputIterator destBegin, 00285 Predicate p) 00286 { 00287 while( begin != end) 00288 { 00289 if( p(*begin) ) &destBegin++ = *begin; 00290 00291 ++begin; 00292 } 00293 00294 return destBegin; 00295 } 00296 // ----------------------------------------------------------------------------- 00297 } 00298 00299 // Варварский запрет на использование atoi вместо uni_atoi.. 00300 // #define atoi atoi##_Do_not_use_atoi_function_directly_Use_getIntProp90,_getArgInt_or_uni_atoi 00301 00302 // ----------------------------------------------------------------------------------------- 00303 #endif
1.7.6.1