LCOV - code coverage report
Current view: top level - alma/ASDM - HistoryTable.h (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 3 7 42.9 %
Date: 2023-10-25 08:47:59 Functions: 1 1 100.0 %

          Line data    Source code
       1             : 
       2             : /*
       3             :  * ALMA - Atacama Large Millimeter Array
       4             :  * (c) European Southern Observatory, 2002
       5             :  * (c) Associated Universities Inc., 2002
       6             :  * Copyright by ESO (in the framework of the ALMA collaboration),
       7             :  * Copyright by AUI (in the framework of the ALMA collaboration),
       8             :  * All rights reserved.
       9             :  * 
      10             :  * This library is free software; you can redistribute it and/or
      11             :  * modify it under the terms of the GNU Lesser General Public
      12             :  * License as published by the Free software Foundation; either
      13             :  * version 2.1 of the License, or (at your option) any later version.
      14             :  * 
      15             :  * This library is distributed in the hope that it will be useful,
      16             :  * but WITHOUT ANY WARRANTY, without even the implied warranty of
      17             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      18             :  * Lesser General Public License for more details.
      19             :  * 
      20             :  * You should have received a copy of the GNU Lesser General Public
      21             :  * License along with this library; if not, write to the Free Software
      22             :  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      23             :  * MA 02111-1307  USA
      24             :  *
      25             :  * Warning!
      26             :  *  -------------------------------------------------------------------- 
      27             :  * | This is generated code!  Do not modify this file.                  |
      28             :  * | If you do, all changes will be lost when the file is re-generated. |
      29             :  *  --------------------------------------------------------------------
      30             :  *
      31             :  * File HistoryTable.h
      32             :  */
      33             :  
      34             : #ifndef HistoryTable_CLASS
      35             : #define HistoryTable_CLASS
      36             : 
      37             : #include <string>
      38             : #include <vector>
      39             : #include <map>
      40             : 
      41             : 
      42             : 
      43             :         
      44             : #include <alma/ASDM/ArrayTime.h>
      45             :         
      46             : 
      47             :         
      48             : #include <alma/ASDM/Tag.h>
      49             :         
      50             : 
      51             : 
      52             : 
      53             : 
      54             :         
      55             : 
      56             :         
      57             : 
      58             :         
      59             : 
      60             :         
      61             : 
      62             :         
      63             : 
      64             :         
      65             : 
      66             :         
      67             : 
      68             :         
      69             : 
      70             : 
      71             : 
      72             : #include <alma/ASDM/ConversionException.h>
      73             : #include <alma/ASDM/DuplicateKey.h>
      74             : #include <alma/ASDM/UniquenessViolationException.h>
      75             : #include <alma/ASDM/NoSuchRow.h>
      76             : #include <alma/ASDM/DuplicateKey.h>
      77             : 
      78             : 
      79             : #ifndef WITHOUT_ACS
      80             : #include <asdmIDLC.h>
      81             : #endif
      82             : 
      83             : #include <alma/ASDM/Representable.h>
      84             : 
      85             : #include <pthread.h>
      86             : 
      87             : namespace asdm {
      88             : 
      89             : //class asdm::ASDM;
      90             : //class asdm::HistoryRow;
      91             : 
      92             : class ASDM;
      93             : class HistoryRow;
      94             : /**
      95             :  * The HistoryTable class is an Alma table.
      96             :  * <BR>
      97             :  * 
      98             :  * \par Role
      99             :  * History information.
     100             :  * <BR>
     101             :  
     102             :  * Generated from model's revision "-1", branch ""
     103             :  *
     104             :  * <TABLE BORDER="1">
     105             :  * <CAPTION> Attributes of History </CAPTION>
     106             :  * <TR BGCOLOR="#AAAAAA"> <TH> Name </TH> <TH> Type </TH> <TH> Expected shape  </TH> <TH> Comment </TH></TR>
     107             :  
     108             :  * <TR> <TH BGCOLOR="#CCCCCC" colspan="4" align="center"> Key </TD></TR>
     109             :         
     110             :  * <TR>
     111             :                 
     112             :  * <TD> execBlockId </TD>
     113             :                  
     114             :  * <TD> Tag</TD>
     115             :  * <TD> &nbsp; </TD>
     116             :  * <TD> &nbsp; </TD>
     117             :  * </TR>
     118             :         
     119             :  * <TR>
     120             :                 
     121             :  * <TD> time </TD>
     122             :                  
     123             :  * <TD> ArrayTime</TD>
     124             :  * <TD> &nbsp; </TD>
     125             :  * <TD> &nbsp; </TD>
     126             :  * </TR>
     127             :         
     128             : 
     129             : 
     130             :  * <TR> <TH BGCOLOR="#CCCCCC"  colspan="4" valign="center"> Value <br> (Mandatory) </TH></TR>
     131             :         
     132             :  * <TR>
     133             :  * <TD> message </TD> 
     134             :  * <TD> std::string </TD>
     135             :  * <TD>  &nbsp;  </TD> 
     136             :  * <TD> &nbsp; </TD>
     137             :  * </TR>
     138             :         
     139             :  * <TR>
     140             :  * <TD> priority </TD> 
     141             :  * <TD> std::string </TD>
     142             :  * <TD>  &nbsp;  </TD> 
     143             :  * <TD> &nbsp; </TD>
     144             :  * </TR>
     145             :         
     146             :  * <TR>
     147             :  * <TD> origin </TD> 
     148             :  * <TD> std::string </TD>
     149             :  * <TD>  &nbsp;  </TD> 
     150             :  * <TD> &nbsp; </TD>
     151             :  * </TR>
     152             :         
     153             :  * <TR>
     154             :  * <TD> objectId </TD> 
     155             :  * <TD> std::string </TD>
     156             :  * <TD>  &nbsp;  </TD> 
     157             :  * <TD> &nbsp; </TD>
     158             :  * </TR>
     159             :         
     160             :  * <TR>
     161             :  * <TD> application </TD> 
     162             :  * <TD> std::string </TD>
     163             :  * <TD>  &nbsp;  </TD> 
     164             :  * <TD> &nbsp; </TD>
     165             :  * </TR>
     166             :         
     167             :  * <TR>
     168             :  * <TD> cliCommand </TD> 
     169             :  * <TD> std::string </TD>
     170             :  * <TD>  &nbsp;  </TD> 
     171             :  * <TD> &nbsp; </TD>
     172             :  * </TR>
     173             :         
     174             :  * <TR>
     175             :  * <TD> appParms </TD> 
     176             :  * <TD> std::string </TD>
     177             :  * <TD>  &nbsp;  </TD> 
     178             :  * <TD> &nbsp; </TD>
     179             :  * </TR>
     180             :         
     181             : 
     182             : 
     183             :  * </TABLE>
     184             :  */
     185             : class HistoryTable : public Representable {
     186             :         friend class ASDM;
     187             : 
     188             : public:
     189             : 
     190             : 
     191             :         /**
     192             :          * Return the list of field names that make up key key
     193             :          * as an array of strings.
     194             :          * @return a vector of string.
     195             :          */     
     196             :         static const std::vector<std::string>& getKeyName();
     197             : 
     198             : 
     199             :         virtual ~HistoryTable();
     200             :         
     201             :         /**
     202             :          * Return the container to which this table belongs.
     203             :          *
     204             :          * @return the ASDM containing this table.
     205             :          */
     206             :         ASDM &getContainer() const;
     207             :         
     208             :         /**
     209             :          * Return the number of rows in the table.
     210             :          *
     211             :          * @return the number of rows in an unsigned int.
     212             :          */
     213             :         unsigned int size() const;
     214             :         
     215             :         /**
     216             :          * Return the name of this table.
     217             :          *
     218             :          * This is a instance method of the class.
     219             :          *
     220             :          * @return the name of this table in a string.
     221             :          */
     222             :         std::string getName() const;
     223             :         
     224             :         /**
     225             :          * Return the name of this table.
     226             :          *
     227             :          * This is a static method of the class.
     228             :          *
     229             :          * @return the name of this table in a string.
     230             :          */
     231             :         static std::string name() ;     
     232             :         
     233             :         /**
     234             :          * Return the version information about this table.
     235             :          *
     236             :          */
     237             :          std::string getVersion() const ;
     238             :         
     239             :         /**
     240             :          * Return the names of the attributes of this table.
     241             :          *
     242             :          * @return a vector of string
     243             :          */
     244             :          static const std::vector<std::string>& getAttributesNames();
     245             : 
     246             :         /**
     247             :          * Return the default sorted list of attributes names in the binary representation of the table.
     248             :          *
     249             :          * @return a const reference to a vector of string
     250             :          */
     251             :          static const std::vector<std::string>& defaultAttributesNamesInBin();
     252             :          
     253             :         /**
     254             :          * Return this table's Entity.
     255             :          */
     256             :         Entity getEntity() const;
     257             : 
     258             :         /**
     259             :          * Set this table's Entity.
     260             :          * @param e An entity. 
     261             :          */
     262             :         void setEntity(Entity e);
     263             :                 
     264             :         /**
     265             :          * Produces an XML representation conform
     266             :          * to the schema defined for History (HistoryTable.xsd).
     267             :          *
     268             :          * @returns a string containing the XML representation.
     269             :          * @throws ConversionException
     270             :          */
     271             :         std::string toXML()  ;
     272             : 
     273             : #ifndef WITHOUT_ACS
     274             :         // Conversion Methods
     275             :         /**
     276             :          * Convert this table into a HistoryTableIDL CORBA structure.
     277             :          *
     278             :          * @return a pointer to a HistoryTableIDL
     279             :          */
     280             :         asdmIDL::HistoryTableIDL *toIDL() ;
     281             :         
     282             :         /**
     283             :          * Fills the CORBA data structure passed in parameter
     284             :          * with the content of this table.
     285             :          *
     286             :          * @param x a reference to the asdmIDL::HistoryTableIDL to be populated
     287             :          * with the content of this.
     288             :          */
     289             :          void toIDL(asdmIDL::HistoryTableIDL& x) const;
     290             :          
     291             : #endif
     292             : 
     293             : #ifndef WITHOUT_ACS
     294             :         /**
     295             :          * Populate this table from the content of a HistoryTableIDL Corba structure.
     296             :          *
     297             :          * @throws DuplicateKey Thrown if the method tries to add a row having a key that is already in the table.
     298             :          * @throws ConversionException
     299             :          */     
     300             :         void fromIDL(asdmIDL::HistoryTableIDL x) ;
     301             : #endif
     302             :         
     303             :         //
     304             :         // ====> Row creation.
     305             :         //
     306             :         
     307             :         /**
     308             :          * Create a new row with default values.
     309             :          * @return a pointer on a HistoryRow
     310             :          */
     311             :         HistoryRow *newRow();
     312             :         
     313             :         
     314             :         /**
     315             :          * Create a new row initialized to the specified values.
     316             :          * @return a pointer on the created and initialized row.
     317             :         
     318             :          * @param execBlockId
     319             :         
     320             :          * @param time
     321             :         
     322             :          * @param message
     323             :         
     324             :          * @param priority
     325             :         
     326             :          * @param origin
     327             :         
     328             :          * @param objectId
     329             :         
     330             :          * @param application
     331             :         
     332             :          * @param cliCommand
     333             :         
     334             :          * @param appParms
     335             :         
     336             :      */
     337             :         HistoryRow *newRow(Tag execBlockId, ArrayTime time, std::string message, std::string priority, std::string origin, std::string objectId, std::string application, std::string cliCommand, std::string appParms);
     338             :         
     339             : 
     340             : 
     341             :         /**
     342             :          * Create a new row using a copy constructor mechanism.
     343             :          * 
     344             :          * The method creates a new HistoryRow owned by this. Each attribute of the created row 
     345             :          * is a (deep) copy of the corresponding attribute of row. The method does not add 
     346             :          * the created row to this, its simply parents it to this, a call to the add method
     347             :          * has to be done in order to get the row added (very likely after having modified
     348             :          * some of its attributes).
     349             :          * If row is null then the method returns a new HistoryRow with default values for its attributes. 
     350             :          *
     351             :          * @param row the row which is to be copied.
     352             :          */
     353             :          HistoryRow *newRow(HistoryRow *row); 
     354             : 
     355             :         //
     356             :         // ====> Append a row to its table.
     357             :         //
     358             :  
     359             :         
     360             :         /**
     361             :          * Add a row.
     362             :          * @param x a pointer to the HistoryRow to be added.
     363             :          *
     364             :          * @return a pointer to a HistoryRow. If the table contains a HistoryRow whose attributes (key and mandatory values) are equal to x ones
     365             :          * then returns a pointer on that HistoryRow, otherwise returns x.
     366             :          *
     367             :          * @throw DuplicateKey { thrown when the table contains a HistoryRow with a key equal to the x one but having
     368             :          * and a value section different from x one }
     369             :          *
     370             :         
     371             :          * @note The row is inserted in the table in such a way that all the rows having the same value of
     372             :          * ( execBlockId ) are stored by ascending time.
     373             :          * @see method getByContext.
     374             :         
     375             :          */
     376             :         HistoryRow* add(HistoryRow* x) ; 
     377             : 
     378             :  
     379             : 
     380             : 
     381             : 
     382             :         //
     383             :         // ====> Methods returning rows.
     384             :         //
     385             :                 
     386             :         /**
     387             :          * Get a collection of pointers on the rows of the table.
     388             :          * @return Alls rows in a vector of pointers of HistoryRow. The elements of this vector are stored in the order 
     389             :          * in which they have been added to the HistoryTable.
     390             :          */
     391             :         std::vector<HistoryRow *> get() ;
     392             :         
     393             :         /**
     394             :          * Get a const reference on the collection of rows pointers internally hold by the table.
     395             :          * @return A const reference of a vector of pointers of HistoryRow. The elements of this vector are stored in the order 
     396             :          * in which they have been added to the HistoryTable.
     397             :          *
     398             :          */
     399             :          const std::vector<HistoryRow *>& get() const ;
     400             :         
     401             : 
     402             :         /**
     403             :          * Returns all the rows sorted by ascending startTime for a given context. 
     404             :          * The context is defined by a value of ( execBlockId ).
     405             :          *
     406             :          * @return a pointer on a vector<HistoryRow *>. A null returned value means that the table contains
     407             :          * no HistoryRow for the given ( execBlockId ).
     408             :          *
     409             :          * @throws IllegalAccessException when a call is done to this method when it's called while the dataset has been imported with the 
     410             :          * option checkRowUniqueness set to false.
     411             :          */
     412             :          std::vector <HistoryRow*> *getByContext(Tag execBlockId);
     413             :          
     414             : 
     415             : 
     416             :  
     417             :         
     418             :         /**
     419             :          * Returns a HistoryRow* given a key.
     420             :          * @return a pointer to the row having the key whose values are passed as parameters, or 0 if
     421             :          * no row exists for that key.
     422             :         
     423             :          * @param execBlockId
     424             :         
     425             :          * @param time
     426             :         
     427             :          *
     428             :          */
     429             :         HistoryRow* getRowByKey(Tag execBlockId, ArrayTime time);
     430             : 
     431             :                 
     432             : 
     433             : 
     434             : 
     435             :         /**
     436             :          * Look up the table for a row whose all attributes 
     437             :          * are equal to the corresponding parameters of the method.
     438             :          * @return a pointer on this row if any, null otherwise.
     439             :          *
     440             :                         
     441             :          * @param execBlockId
     442             :                         
     443             :          * @param time
     444             :                         
     445             :          * @param message
     446             :                         
     447             :          * @param priority
     448             :                         
     449             :          * @param origin
     450             :                         
     451             :          * @param objectId
     452             :                         
     453             :          * @param application
     454             :                         
     455             :          * @param cliCommand
     456             :                         
     457             :          * @param appParms
     458             :                          
     459             :          */
     460             :         HistoryRow* lookup(Tag execBlockId, ArrayTime time, std::string message, std::string priority, std::string origin, std::string objectId, std::string application, std::string cliCommand, std::string appParms); 
     461             : 
     462             : 
     463             :         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
     464             :         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
     465             : 
     466             : private:
     467             : 
     468             :         /**
     469             :          * Create a HistoryTable.
     470             :          * <p>
     471             :          * This constructor is private because only the
     472             :          * container can create tables.  All tables must know the container
     473             :          * to which they belong.
     474             :          * @param container The container to which this table belongs.
     475             :          */ 
     476             :         HistoryTable (ASDM & container);
     477             : 
     478             :         ASDM & container;
     479             :         
     480             :         bool archiveAsBin; // If true archive binary else archive XML
     481             :         bool fileAsBin ; // If true file binary else file XML   
     482             :         
     483             :         std::string version ; 
     484             :         
     485             :         Entity entity;
     486             :         
     487             : 
     488             :         
     489             :         
     490             : 
     491             : 
     492             :         /**
     493             :          * If this table has an autoincrementable attribute then check if *x verifies the rule of uniqueness and throw exception if not.
     494             :          * Check if *x verifies the key uniqueness rule and throw an exception if not.
     495             :          * Append x to its table.
     496             :          * @throws DuplicateKey
     497             :          
     498             :          */
     499             :         HistoryRow* checkAndAdd(HistoryRow* x, bool skipCheckUniqueness=false) ;
     500             :         
     501             :         /**
     502             :          * Brutally append an HistoryRow x to the collection of rows already stored in this table. No uniqueness check is done !
     503             :          *
     504             :          * @param HistoryRow* x a pointer onto the HistoryRow to be appended.
     505             :          */
     506             :          void append(HistoryRow* x) ;
     507             :          
     508             :         /**
     509             :          * Brutally append an HistoryRow x to the collection of rows already stored in this table. No uniqueness check is done !
     510             :          *
     511             :          * @param HistoryRow* x a pointer onto the HistoryRow to be appended.
     512             :          */
     513             :          void addWithoutCheckingUnique(HistoryRow* x) ;
     514             :          
     515             :          
     516             : 
     517             : 
     518             :         
     519             :         
     520             :    /**
     521             :          * Insert a HistoryRow* in a vector of HistoryRow* so that it's ordered by ascending time.
     522             :          *
     523             :          * @param HistoryRow* x . The pointer to be inserted.
     524             :          * @param vector <HistoryRow*>& row . A reference to the vector where to insert x.
     525             :          *
     526             :          */
     527             :         HistoryRow * insertByTime(HistoryRow* x, std::vector<HistoryRow *>&row );
     528             :          
     529             : 
     530             : 
     531             : // A data structure to store the pointers on the table's rows.
     532             : 
     533             : // In all cases we maintain a private vector of HistoryRow s.
     534             :    std::vector<HistoryRow * > privateRows;
     535             :    
     536             : 
     537             :         
     538             : 
     539             :         
     540             :         
     541             :                 
     542             :                                 
     543             :         typedef std::vector <HistoryRow* > TIME_ROWS;
     544             :         std::map<std::string, TIME_ROWS > context;
     545             :                 
     546             :         /** 
     547             :          * Returns a string built by concatenating the ascii representation of the
     548             :          * parameters values suffixed with a "_" character.
     549             :          */
     550             :          std::string Key(Tag execBlockId) ;
     551             :                  
     552             :                 
     553             :         
     554             :         
     555             :         /**
     556             :          * Fills the vector vout (passed by reference) with pointers on elements of vin 
     557             :          * whose attributes are equal to the corresponding parameters of the method.
     558             :          *
     559             :          */
     560             :         void getByKeyNoAutoIncNoTime(std::vector <HistoryRow*>& vin, std::vector <HistoryRow*>& vout,  Tag execBlockId);
     561             :         
     562             : 
     563             :         
     564             :         void error() ; //throw(ConversionException);
     565             : 
     566             :         
     567             :         /**
     568             :          * Populate this table from the content of a XML document that is required to
     569             :          * be conform to the XML schema defined for a History (HistoryTable.xsd).
     570             :          * @throws ConversionException
     571             :          * 
     572             :          */
     573             :         void fromXML(std::string& xmlDoc) ;
     574             :                 
     575             :         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
     576             : 
     577             :         /**
     578             :           * Private methods involved during the build of this table out of the content
     579             :           * of file(s) containing an external representation of a History table.
     580             :           */
     581             :         void setFromMIMEFile(const std::string& directory);
     582             :         /*
     583             :         void openMIMEFile(const std::string& directory);
     584             :         */
     585             :         void setFromXMLFile(const std::string& directory);
     586             :         
     587             :                  /**
     588             :          * Serialize this into a stream of bytes and encapsulates that stream into a MIME message.
     589             :          * @returns a string containing the MIME message.
     590             :          *
     591             :          * @param byteOrder a const pointer to a static instance of the class ByteOrder.
     592             :          * 
     593             :          */
     594             :         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
     595             :   
     596             :         
     597             :    /** 
     598             :      * Extracts the binary part of a MIME message and deserialize its content
     599             :          * to fill this with the result of the deserialization. 
     600             :          * @param mimeMsg the string containing the MIME message.
     601             :          * @throws ConversionException
     602             :          */
     603             :          void setFromMIME(const std::string & mimeMsg);
     604             :         
     605             :         /**
     606             :           * Private methods involved during the export of this table into disk file(s).
     607             :           */
     608             :         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
     609             :         
     610             :         /**
     611             :           * Stores a representation (binary or XML) of this table into a file.
     612             :           *
     613             :           * Depending on the boolean value of its private field fileAsBin a binary serialization  of this (fileAsBin==true)  
     614             :           * will be saved in a file "History.bin" or an XML representation (fileAsBin==false) will be saved in a file "History.xml".
     615             :           * The file is always written in a directory whose name is passed as a parameter.
     616             :          * @param directory The name of directory  where the file containing the table's representation will be saved.
     617             :           * 
     618             :           */
     619             :           void toFile(std::string directory);
     620             :           
     621             :           /**
     622             :            * Load the table in memory if necessary.
     623             :            */
     624             :           bool loadInProgress;
     625          72 :           void checkPresenceInMemory() {
     626          72 :                 if (!presentInMemory && !loadInProgress) {
     627           0 :                         loadInProgress = true;
     628           0 :                         setFromFile(getContainer().getDirectory());
     629           0 :                         presentInMemory = true;
     630           0 :                         loadInProgress = false;
     631             :                 }
     632          72 :           }
     633             :         /**
     634             :          * Reads and parses a file containing a representation of a HistoryTable as those produced  by the toFile method.
     635             :          * This table is populated with the result of the parsing.
     636             :          * @param directory The name of the directory containing the file te be read and parsed.
     637             :          * @throws ConversionException If any error occurs while reading the 
     638             :          * files in the directory or parsing them.
     639             :          *
     640             :          */
     641             :          void setFromFile(const std::string& directory);    
     642             :  
     643             : };
     644             : 
     645             : } // End namespace asdm
     646             : 
     647             : #endif /* HistoryTable_CLASS */

Generated by: LCOV version 1.16