1 #ifndef CARMA_DBMS_TAGIDAUTHORITY_H
2 #define CARMA_DBMS_TAGIDAUTHORITY_H
21 #include "carma/util/PthreadRWLock.h"
61 static ::std::string getDefaultCanonicalNamesToTagIDsConfFile( );
84 const ::std::string & dbConfFile,
85 const bool useConfFileIfDBIsDown =
true,
86 const ::std::string & canonicalNamesToTagIDsConfFile =
87 getDefaultCanonicalNamesToTagIDsConfFile( ) );
102 carma::monitor::tagIDType
lookupID( const ::std::string & name )
const;
114 bool tagIdAssignedOnTheFly( const ::std::string & name )
const;
116 bool tagIdAssignedOnTheFly( carma::monitor::tagIDType tagId )
const;
123 ::std::string
lookupName( carma::monitor::tagIDType tagId )
const;
170 unsigned short subsystemId,
unsigned short monitorPointId );
179 static unsigned short getSubsystemID( carma::monitor::tagIDType tagId );
188 static unsigned short getPointID( carma::monitor::tagIDType tagId );
190 static unsigned short maxPossiblePointID(
unsigned short subsystemId );
198 struct TagIdOriginStats {
201 size_t totalConfFile;
206 ::std::map< unsigned short, size_t > subsystemTotal;
207 ::std::map< unsigned short, size_t > subsystemDb;
208 ::std::map< unsigned short, size_t > subsystemConfFile;
209 ::std::map< unsigned short, size_t > subsystemOtf;
212 TagIdOriginStats collectTagIdOriginStats( )
const;
214 void logTagIdOriginStats()
const;
216 void logNotableOnTheFlyCreationsThusFarAndInTheFuture();
219 logNotableOnTheFlyCreationsThusFarAndInTheFuture(
size_t targetLineCount );
222 struct StrictlyWeakStringOrdering {
223 bool operator()( const ::std::string & lhs,
224 const ::std::string & rhs )
const;
239 SUBSYS_DOES_NOT_EXIST,
247 carma::monitor::tagIDType tagId_;
250 NameMapInfo( carma::monitor::tagIDType
id, OriginType origin );
260 NameMapInfo & nameMapInfo )
const;
264 typedef ::std::map< ::std::string, NameMapInfo, StrictlyWeakStringOrdering >
267 typedef ::std::map< ::std::string, carma::monitor::tagIDType, StrictlyWeakStringOrdering >
270 typedef ::std::map< carma::monitor::tagIDType, ::std::string > Id2NameMap;
274 const ::std::string & dbConfFile,
275 const ::std::string & tagsConfFile );
281 void registerNameHoldingWriteLock( const ::std::string & name,
282 carma::monitor::tagIDType tagId,
291 void registerSubsystemNamesHoldingWriteLock( );
297 void getNamesToTagIDsFromConfFile( const ::std::string & fileName );
298 void getNamesToTagIDsFromBinaryConfFile( const ::std::string & fileName );
299 void getNamesToTagIDsFromTextConfFile( const ::std::string & fileName );
303 carma::monitor::tagIDType
304 convertNameToTagIdHoldingLock( const ::std::string & name )
const;
308 carma::monitor::tagIDType
309 findIdOrAssignOtf( const ::std::string & name,
311 const ::std::string & subsysName );
315 TagIdOriginStats collectTagIdOriginStatsHoldingLock( )
const;
317 SubsysMatchType checkSubsysMatchHoldingLock(
318 const ::std::string & canonicalName,
319 carma::monitor::tagIDType nonSubsysTagId,
320 Name2InfoMap::const_iterator & hint )
const;
322 size_t estimateMemHoldingLock()
const;
326 static const char *
const subsysnames_[ ];
329 static const int subsysnamesCount_;
334 OriginType masterOrigin_;
335 ::std::string sha1sum_;
337 Name2InfoMap name2Info_;
339 Name2IdMap subsys2NextOtfId_;
341 bool logNotableOtfCreations_;
342 bool haveUnloggedNotableOtfCreations_;
350 inline carma::monitor::tagIDType
352 const unsigned short monitorPointId )
354 return ((static_cast< carma::monitor::tagIDType >( subsystemId ) << 16) |
355 static_cast< carma::monitor::tagIDType >( monitorPointId ));
358 inline unsigned short
361 return (tagId >> 16);
365 inline unsigned short
368 return (tagId & 0x0000FFFF);
371 inline unsigned short
372 carma::dbms::TagIDAuthority::maxPossiblePointID(
const unsigned short subsystemId )
378 #endif // CARMA_DBMS_TAGIDAUTHORITY_H
Class used for configuring a DBConnection.
::std::string getSubsystemName(const ::std::string &canonicalName)
return the subsystem name from a monitor component's canonical name the singleton does not need to ex...
A simple wrapper class that makes use of ::pthread_rwlock_t easier in a C++ world.
::std::string tagIDNameMapSha1Sum() const
get the sha1 sum of the tagID to canonical name map.
::std::string lookupName(carma::monitor::tagIDType tagId) const
return the full hierarchical name for for an ID
carma::monitor::tagIDType lookupID(const ::std::string &name) const
static int getSubsystemCount()
return the number of subsystems, the singleton object does not need to be instantiated ...
static TagIDAuthority & getAuthority()
get the singleton instance of the TagIDAuthority.
static carma::monitor::tagIDType composeTagID(unsigned short subsystemId, unsigned short monitorPointId)
Crafts a tagID given the subsystemID and the ID of the monitor point (pointID) and returns the tagID...
static unsigned short getPointID(carma::monitor::tagIDType tagId)
Converse of composeTagID.
A lookup class for mapping names and IDs.
static unsigned short getSubsystemID(carma::monitor::tagIDType tagId)
Converse of composeTagID.
type definitions for monitor system
static void configureAuthority(const bool useDb, const ::std::string &dbConfFile, const bool useConfFileIfDBIsDown=true, const ::std::string &canonicalNamesToTagIDsConfFile=getDefaultCanonicalNamesToTagIDsConfFile())
configure the singleton, this should be called before the initial call to getAuthority; the singleton...
static void closeAuthority()
indicate that one's use of the authority is complete.
bool retrieveTagInfo(const std::string &canonicalName, NameMapInfo &nameMapInfo) const
Retrieve tag id and origin information for a given canonical name.
unsigned short lookupSubsystemID(const ::std::string &name) const
return the subsystem ID for a given subsystem name.