00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00024
00025 #ifndef UniSetTypes_H_
00026 #define UniSetTypes_H_
00027
00028 #include <cstdlib>
00029 #include <cstdio>
00030 #include <string>
00031 #include <list>
00032 #include <limits>
00033 #include <ostream>
00034
00035 #include <omniORB4/CORBA.h>
00036 #include "UniSetTypes_i.hh"
00037 #include "IOController_i.hh"
00038 #include "Mutex.h"
00039 #include "UniXML.h"
00040
00042 inline void msleep( unsigned int m ) { usleep(m*1000); }
00043
00045 namespace UniSetTypes
00046 {
00047 class Configuration;
00048 extern Configuration* conf;
00049
00050 typedef std::list<std::string> ListObjectName;
00052 typedef ObjectId SysId;
00053 typedef CORBA::Object_ptr ObjectPtr;
00054 typedef CORBA::Object_var ObjectVar;
00057 inline static UniSetTypes::ObjectType getObjectType(const char * name) { const void *t = name; return (UniSetTypes::ObjectType)t; }
00058
00059 UniversalIO::IOTypes getIOType( const std::string s );
00060 std::ostream& operator<<( std::ostream& os, const UniversalIO::IOTypes t );
00061
00062 std::ostream& operator<<( std::ostream& os, const IOController_i::CalibrateInfo c );
00063
00064
00066 enum LampCommand
00067 {
00068 lmpOFF = 0,
00069 lmpON = 1,
00070 lmpBLINK = 2,
00071 lmpBLINK2 = 3,
00072 lmpBLINK3 = 4
00073 };
00074
00075 static const long ChannelBreakValue = std::numeric_limits<long>::max();
00076
00077 class IDList
00078 {
00079 public:
00080 IDList();
00081 ~IDList();
00082
00083 void add( ObjectId id );
00084 void del( ObjectId id );
00085
00086 inline int size(){ return lst.size(); }
00087 inline bool empty(){ return lst.empty(); }
00088
00089 std::list<ObjectId> getList();
00090
00091
00092
00093 IDSeq* getIDSeq();
00094
00095
00096 ObjectId getFirst();
00097 ObjectId node;
00098
00099 private:
00100 std::list<ObjectId> lst;
00101 };
00102
00103 const ObjectId DefaultObjectId = -1;
00105
00106 const MessageCode DefaultMessageCode = 0;
00108 const ThresholdId DefaultThresholdId = -1;
00109 const ThresholdId DefaultTimerId = -1;
00113 struct MessageInfo
00114 {
00115 UniSetTypes::MessageCode code;
00116 std::string text;
00117 std::string idname;
00119 inline bool operator < ( const MessageInfo& m ) const
00120 {
00121 return (code < m.code);
00122 }
00123 };
00124
00126 struct ObjectInfo
00127 {
00128 ObjectInfo():
00129 id(DefaultObjectId),
00130 repName(0),textName(0),data(0){}
00131
00132 ObjectId id;
00133 char* repName;
00134 char* textName;
00135 void* data;
00136
00137 inline bool operator < ( const ObjectInfo& o ) const
00138 {
00139 return (id < o.id);
00140 }
00141 };
00142
00143 typedef std::list<NodeInfo> ListOfNode;
00144
00146 const char BadSymbols[]={'.','/'};
00147
00148 class uniset_mutex;
00149 class uniset_mutex_lock;
00150
00152 inline int uni_atoi( const char* str )
00153 {
00154 int n = 0;
00155
00156 if ( str != NULL )
00157 std::sscanf(str, "%i", &n);
00158 return n;
00159 }
00160 inline int uni_atoi( const std::string str )
00161 {
00162 return uni_atoi(str.c_str());
00163 }
00164
00165
00166 typedef long KeyType;
00174 inline static KeyType key( UniSetTypes::ObjectId id, UniSetTypes::ObjectId node )
00175 {
00176 return KeyType((id*node)+(id+2*node));
00177 }
00178
00183 inline std::string getArgParam( const std::string name,
00184 int _argc, const char* const* _argv,
00185 const std::string defval="" )
00186 {
00187 for( int i=1; i < (_argc - 1) ; i++ )
00188 {
00189 if( name == _argv[i] )
00190 return _argv[i+1];
00191 }
00192 return defval;
00193 }
00194
00195 inline int getArgInt( const std::string name,
00196 int _argc, const char* const* _argv,
00197 const std::string defval="" )
00198 {
00199 return uni_atoi(getArgParam(name, _argc, _argv, defval));
00200 }
00201
00207 inline int findArgParam( const std::string name, int _argc, const char* const* _argv )
00208 {
00209 for( int i=1; i<_argc; i++ )
00210 {
00211 if( name == _argv[i] )
00212 return i;
00213 }
00214 return -1;
00215 }
00216
00218 template<typename InputIterator,
00219 typename OutputIterator,
00220 typename Predicate>
00221 OutputIterator copy_if(InputIterator begin,
00222 InputIterator end,
00223 OutputIterator destBegin,
00224 Predicate p)
00225 {
00226 while( begin!=end)
00227 {
00228 if( p(*begin) ) &destBegin++=*begin;
00229 ++begin;
00230 }
00231 return destBegin;
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241 float fcalibrate(float raw, float rawMin, float rawMax, float calMin, float calMax, bool limit=true );
00242 long lcalibrate(long raw, long rawMin, long rawMax, long calMin, long calMax, bool limit=true );
00243
00244
00245 long setinregion(long raw, long rawMin, long rawMax);
00246
00247 long setoutregion(long raw, long rawMin, long rawMax);
00248
00249
00250
00251 bool file_exist( const std::string filename );
00252
00253 IDList explode( const std::string str, char sep=',' );
00254 std::list<std::string> explode_str( const std::string str, char sep=',' );
00255
00256
00257 struct ParamSInfo
00258 {
00259 IOController_i::SensorInfo si;
00260 long val;
00261 std::string fname;
00262 };
00263
00264
00265
00266
00267 std::list<ParamSInfo> getSInfoList( std::string s, Configuration* conf=UniSetTypes::conf);
00268 bool is_digit( const std::string s );
00269
00270
00271
00272 bool check_filter( UniXML_iterator& it, const std::string f_prop, const std::string f_val="" );
00273
00274 }
00275
00276 #define atoi atoi##_Do_not_use_atoi_function_directly_Use_getIntProp90,_getArgInt_or_uni_atoi
00277
00278
00279 #endif