CARMA C++
MonitorConfigurationDatabase.h
Go to the documentation of this file.
1 #ifndef CARMA_DBMS_MONITORCONFIGURATIONDATABASE_H
2 #define CARMA_DBMS_MONITORCONFIGURATIONDATABASE_H
3 
14 #include <map>
15 #include "carma/dbms/Table.h"
16 #include "carma/dbms/ColumnNames.h"
17 #include "carma/dbms/Typedefs.h"
18 #include "carma/util/Logger.h"
19 #include "carma/util/Time.h"
20 
21 namespace carma {
22 namespace dbms {
23 
24  class DBConnection;
25  class MonitorDescription;
26 
31 
32 public:
36  explicit MonitorConfigurationDatabase( const DBConnection * dbc );
37 
38  //--------------- Subsystems table access methods --------------------
39 
44  void populateSubsystemsTable( ) const;
45 
53  short getSubsystemID( const ::std::string & subsysName,
54  bool ignoreCase = false ) const;
55 
65  ::std::string * getSubsystemName( unsigned short subsysID ) const;
66 
72 
73  //-------------- AggregateSubsystems table access methods -------------
74 
85  const ::std::string & name,
86  unsigned count,
87  unsigned maxsamples,
88  unsigned maxpoints ) const;
89 
95 
100  unsigned getTotalMaxPoints( ) const;
101 
106  unsigned getTotalMaxSamples( ) const;
107 
108  //--------------- Locations table access methods --------------------
118  void populateLocationsTable( ) const;
119 
125 
126  //--------------- Devices table access methods --------------------
134  void populateDevicesTable( ) const;
135 
140  dbms::Table getDevicesTable( ) const;
141 
160  const MonitorDescription & md,
161  bool updateOnlyIfNecessary = true ) const;
162 
170  const MonitorDescription & Md,
171  ::std::string &msg,
172  bool updateOnlyIfNecessary = true,
173  bool noInsertDenied=false ) const;
174 
195  bool mutateStaticParms(const ::std::string &disposition,
196  unsigned tagID, const ::std::string &mpName,
197  const ::std::string &fieldName,
198  const ::std::string &newValue,
199  const ::std::string &requester);
200 
206  bool mutateStaticParms(const ::std::string &changeString);
207 
221  const ::std::string & canonicalName,
222  util::frameType frameCount =
224 
225 
259  const ::std::vector< int > * const tagIDs = 0,
260  bool retreiveOnlyValidConfigs = false,
261  util::frameType frameCount =
263 
264 
275  const ::std::vector< int > * tagIDs,
276  util::frameType frameCount =
278 
292  int tagID,
293  util::frameType frameCount = util::Time::computeCurrentFrame( ) ) const;
294 
302  unsigned getMaxTagID( unsigned short subsysID ) const;
303 
310  bool tagIDExists( int tagID ) const;
311 
321  void getContainerAndMPNames( const char * hname,
322  ::std::string & cname,
323  ::std::string & mpname) const;
324 
330  ::std::map< int, ::std::string > getTagID2NameMap( ) const;
331 
337 
338 
346  ::std::string getCanonicalName( const int tagID ) const;
347 
355  ::std::string getCanonicalName( const ::std::string & tagID ) const;
356 
365  int getTagID( const ::std::string & mpName ) const;
366 
375  //dbms::Column<int> getTagIDs
376  //(const ::std::vector<::std::string>* const canonicalNames=0) const;
377 
398  ::std::map< int, ::std::string > getTagIDs(
399  const ::std::string & wildcardedName,
400  const ::std::string & multiCharacterWildcard = "%",
401  const ::std::string & singleCharacterWildcard = "_" ) const;
402 
411  bool monitorConfigExists( const ::std::string & canonicalName ) const;
412 
416  void populateValiditiesTable( ) const;
417 
423 
427  void populateBlankingFlagsTable( ) const;
428 
434 
439 
445 
449  void populateMonitorPointTypesTable( ) const;
450 
456 
457 
469  const dbms::Table & t,
470  int row ) const;
471 
477  //static unsigned shortNameMaxLength() { return 64; }
478 
489  util::frameType frameCount,
490  const ::std::string & signature,
491  bool updateOnlyIfNecessary = true ) const;
492 
501  const dbms::DBColumn * orderBy,
502  dbms::SortOrder sortOrder = dbms::DESCENDING ) const;
503 
513  ::std::string * getCurrentTagIDNameSignature( ) const;
514 
526  ::std::string * getTagIDNameSignature(
527  util::frameType frameCount= util::Time::computeCurrentFrame( ) ) const;
528 
529 
530 private:
531 
538  void setEnumerators_( int tagID,
539  const ::std::string & name,
540  dbms::MonitorDescription & md ) const;
541 
542 
553  void getEnumerators_( unsigned tagID,
554  const ::std::string * name,
555  dbms::Column< ::std::string > & enumValues,
556  dbms::Column< ::std::string > & enumDescriptions,
557  dbms::Column< short > & enumIndices ) const;
558 
559 
563  void insertEnumerators_( unsigned tagID,
564  const dbms::MonitorDescription & md ) const;
565 
566  /********************************************************************/
567  /* Routines to support editing of static fields. */
572  bool mutateEnumerator(
573  const MonitorDescription &existingMD,
574  carma::util::frameType frameCount,
575  unsigned tagID, const std::string &mpName,
576  const std::string &fieldName, const std::string &newValue,
577  const std::string &username);
578 
579  /* Get max version # for this monitor point. */
580  int getMaxVersionNumber(const std::string &mpname) const;
581 
584  bool makeNewMPVersion(const MonitorDescription &md,
585  carma::util::frameType frameCount,
586  unsigned tagID, const ::std::string &mpName,
587  const ::std::string &userName);
588 
589 
590  /* Make an entry in the static parameter change log table indicating
591  * what was done.
592  * This is usually called from within the same try/catch block that
593  * contains the SQL command changing the database.
594  * This is only called by the mutate routines and is used to keep
595  * track of potentially dangerous changes.
596  */
597  void makeStaticParamChangeLogEntry(carma::util::frameType frameCount,
598  unsigned tagID,
599  const ::std::string &mpname, const ::std::string &fieldname,
600  const ::std::string &newValue, const ::std::string &oldValue,
601  const ::std::string &userName, int index=0);
602  /********************************************************************/
603 
607  bool getEnumID(const ::std::string &enumName,
608  const ::std::string &description,
609  int &enumID);
617  short getLocationID_( const ::std::string & locationName,
618  bool ignoreCase = false ) const;
619 
629  ::std::string * getLocationName_( unsigned short locationID ) const;
630 
638  short getDeviceID_( const ::std::string & deviceName,
639  bool ignoreCase = false ) const;
640 
650  ::std::string * getDeviceName_( unsigned short deviceID ) const;
651 
652 
653  const DBConnection * dbc_;
654  log4cpp::Category & logger_;
655 };
656 
657 
658 }
659 }
660 
661 
662 #endif // CARMA_DBMS_MONITORCONFIGURATIONDATABASE_H
bool monitorConfigExists(const ::std::string &canonicalName) const
does the monitor configuration exist in the db?
Class to mimic a db table The Table class is meant to mimic a database table.
Definition: Table.h:34
template to mimic a db column.
Definition: Column.h:31
bool insertTagIDNameSignaturesRecord(util::frameType frameCount, const ::std::string &signature, bool updateOnlyIfNecessary=true) const
get the maximum length permitted for the shortName of a monitor point
void getContainerAndMPNames(const char *hname,::std::string &cname,::std::string &mpname) const
get the conanical container name and monitor point name of a monitor point with the specified canonic...
::std::map< int,::std::string > getTagIDs(const ::std::string &wildcardedName, const ::std::string &multiCharacterWildcard="%", const ::std::string &singleCharacterWildcard="_") const
get the tagIDs corresponding to the specified canonical names
dbms::Table getTagIDNameSignatures(const dbms::DBColumn *orderBy, dbms::SortOrder sortOrder=dbms::DESCENDING) const
get the TagIDNameSignatures table
dbms::ID2MDMap getMonitorConfigurations(const ::std::vector< int > *tagIDs, util::frameType frameCount=util::Time::computeCurrentFrame()) const
get monitor configuration info for the specified tagIDs
::std::string * getSubsystemName(unsigned short subsysID) const
get the subsystem name associated with the specified subsystem ID callers are responsible for deletin...
Common time functions.
::std::string * getTagIDNameSignature(util::frameType frameCount=util::Time::computeCurrentFrame()) const
get the tagID-&gt;canonical names map signature valid at the specified frame count.
::std::map< int,::std::string > getTagID2NameMap() const
get a map of tagid&#39;s to canonical names of monitor points
bool mutateStaticParms(const ::std::string &disposition, unsigned tagID, const ::std::string &mpName, const ::std::string &fieldName, const ::std::string &newValue, const ::std::string &requester)
Change a value in the static parameter table for a monitor point.
dbms::Table getDevicesTable() const
get the devices table
bool tagIDExists(int tagID) const
Does the specified tagID exist in the DB?
unsigned int frameType
Half second frames since Jan 1, 2000.
Definition: types.h:29
int getTagID(const ::std::string &mpName) const
get the tagID associated with the specified monitor point name
This class contains methods for accessing monitor configuration information.
A MonitorDescription object holds all information on a monitor point which is stored in the database ...
dbms::Table getAggregateSubsystemsTable() const
get the aggregate subsystems table
void populateMonitorPointTypesTable() const
populate the MonitorPointTypes table
dbms::Table getValiditiesTable() const
get the Validities table
dbms::Table getMonitorPointTypesTable() const
get the MonitorPointTypes table
SortOrder
enum representing table sort order in an order by clause
Definition: ColumnNames.h:69
static frameType computeCurrentFrame()
Get integral half-second frame since 2000, rounded down.
void populateLocationsTable() const
populate the Locations table
dbms::Table getMonitorPointDataTypesTable() const
get the MonitorPointDataTypes table
dbms::MonitorDescription tableRow2MonitorDescription(const dbms::Table &t, int row) const
transform a monitor configuration represented by a table row into a MonitorDescription object...
void insertAggregateSubsystemsRecord(const ::std::string &name, unsigned count, unsigned maxsamples, unsigned maxpoints) const
insert a record into the aggregate subsystems table
dbms::Table getBlankingFlagsTable() const
get the BlankingFlags table
void populateBlankingFlagsTable() const
populate the Validities table
void populateMonitorPointDataTypesTable() const
populate the MonitorPointDataTypes table
dbms::Table getTagIDToDataTypeIDTable() const
get a table containing the tagID to dataTypeID mappings for all monitor points
access of column names in the database
dbms::Table getFullMonitorConfigurationTable(const ::std::vector< int > *const tagIDs=0, bool retreiveOnlyValidConfigs=false, util::frameType frameCount=util::Time::computeCurrentFrame()) const
get the full monitor configuration table (static parms table joined with changable parms table + join...
short getSubsystemID(const ::std::string &subsysName, bool ignoreCase=false) const
get the ID for the specified subsystem
::std::string * getCurrentTagIDNameSignature() const
get the currently valid tagID-&gt;canonical names map signature the returned pointer is created by by th...
dbms::Table getSubsystemsTable() const
get the subsystem table
void populateSubsystemsTable() const
populate the Subsystem table using values from monitor::TagIDAuthority::subsysnames ...
void populateValiditiesTable() const
populate the Validities table
unsigned getMaxTagID(unsigned short subsysID) const
get the maximum tagID for the specified subsystem
void populateDevicesTable() const
populate the Devices table using values from monitor::PhysicalDeviceIDAuthority::deviceNames if an ID...
unsigned getTotalMaxSamples() const
get the value of maxsamples summed over all subsystems
MonitorDescription getMonitorConfiguration(const ::std::string &canonicalName, util::frameType frameCount=util::Time::computeCurrentFrame()) const
get monitor description associated with the specified canonical name which is valid at the specified ...
an abstract class from which database queries may be launched.
Definition: DBConnection.h:46
typdefs for carma::dbms.
unsigned insertMonitorConfiguration(const MonitorDescription &md, bool updateOnlyIfNecessary=true) const
add a monitor point configuration to the database
Table class.
unsigned getTotalMaxPoints() const
get the value of maxpoints summed over all subsystems
DBColumn
database columns
Definition: ColumnNames.h:26
::std::string getCanonicalName(const int tagID) const
get the canonical name for a monitor point associated with the specified tagId
std::map< const int, const carma::dbms::MonitorDescription > ID2MDMap
map of id (normally a tagID) -&gt; monitor configuration
Definition: Typedefs.h:20
MonitorConfigurationDatabase(const DBConnection *dbc)
constructor
dbms::Table getLocationsTable() const
get the location table