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