casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
HistoryTable.h
Go to the documentation of this file.
00001 
00002 /*
00003  * ALMA - Atacama Large Millimeter Array
00004  * (c) European Southern Observatory, 2002
00005  * (c) Associated Universities Inc., 2002
00006  * Copyright by ESO (in the framework of the ALMA collaboration),
00007  * Copyright by AUI (in the framework of the ALMA collaboration),
00008  * All rights reserved.
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  * 
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY, without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023  * MA 02111-1307  USA
00024  *
00025  * Warning!
00026  *  -------------------------------------------------------------------- 
00027  * | This is generated code!  Do not modify this file.                  |
00028  * | If you do, all changes will be lost when the file is re-generated. |
00029  *  --------------------------------------------------------------------
00030  *
00031  * File HistoryTable.h
00032  */
00033  
00034 #ifndef HistoryTable_CLASS
00035 #define HistoryTable_CLASS
00036 
00037 #include <string>
00038 #include <vector>
00039 #include <map>
00040 
00041 
00042 
00043         
00044 #include <ArrayTime.h>
00045         
00046 
00047         
00048 #include <Tag.h>
00049         
00050 
00051 
00052 
00053 
00054         
00055 
00056         
00057 
00058         
00059 
00060         
00061 
00062         
00063 
00064         
00065 
00066         
00067 
00068         
00069 
00070 
00071 
00072 #include <ConversionException.h>
00073 #include <DuplicateKey.h>
00074 #include <UniquenessViolationException.h>
00075 #include <NoSuchRow.h>
00076 #include <DuplicateKey.h>
00077 
00078 
00079 #ifndef WITHOUT_ACS
00080 #include <asdmIDLC.h>
00081 #endif
00082 
00083 #include <Representable.h>
00084 
00085 #include <pthread.h>
00086 
00087 namespace asdm {
00088 
00089 //class asdm::ASDM;
00090 //class asdm::HistoryRow;
00091 
00092 class ASDM;
00093 class HistoryRow;
00185 class HistoryTable : public Representable {
00186         friend class ASDM;
00187 
00188 public:
00189 
00190 
00196         static const std::vector<std::string>& getKeyName();
00197 
00198 
00199         virtual ~HistoryTable();
00200         
00206         ASDM &getContainer() const;
00207         
00213         unsigned int size() const;
00214         
00222         std::string getName() const;
00223         
00231         static std::string name() ;     
00232         
00237          std::string getVersion() const ;
00238         
00244          static const std::vector<std::string>& getAttributesNames();
00245 
00251          static const std::vector<std::string>& defaultAttributesNamesInBin();
00252          
00256         Entity getEntity() const;
00257 
00262         void setEntity(Entity e);
00263                 
00271         std::string toXML()  ;
00272 
00273 #ifndef WITHOUT_ACS
00274         // Conversion Methods
00280         asdmIDL::HistoryTableIDL *toIDL() ;
00281         
00289          void toIDL(asdmIDL::HistoryTableIDL& x) const;
00290          
00291 #endif
00292 
00293 #ifndef WITHOUT_ACS
00294 
00300         void fromIDL(asdmIDL::HistoryTableIDL x) ;
00301 #endif
00302         
00303         //
00304         // ====> Row creation.
00305         //
00306         
00311         HistoryRow *newRow();
00312         
00313         
00337         HistoryRow *newRow(Tag execBlockId, ArrayTime time, string message, string priority, string origin, string objectId, string application, string cliCommand, string appParms);
00338         
00339 
00340 
00353          HistoryRow *newRow(HistoryRow *row); 
00354 
00355         //
00356         // ====> Append a row to its table.
00357         //
00358  
00359         
00376         HistoryRow* add(HistoryRow* x) ; 
00377 
00378  
00379 
00380 
00381 
00382         //
00383         // ====> Methods returning rows.
00384         //
00385                 
00391         std::vector<HistoryRow *> get() ;
00392         
00399          const std::vector<HistoryRow *>& get() const ;
00400         
00401 
00412          std::vector <HistoryRow*> *getByContext(Tag execBlockId);
00413          
00414 
00415 
00416  
00417         
00429         HistoryRow* getRowByKey(Tag execBlockId, ArrayTime time);
00430 
00431                 
00432 
00433 
00434 
00460         HistoryRow* lookup(Tag execBlockId, ArrayTime time, string message, string priority, string origin, string objectId, string application, string cliCommand, string appParms); 
00461 
00462 
00463         void setUnknownAttributeBinaryReader(const std::string& attributeName, BinaryAttributeReaderFunctor* barFctr);
00464         BinaryAttributeReaderFunctor* getUnknownAttributeBinaryReader(const std::string& attributeName) const;
00465 
00466 private:
00467 
00476         HistoryTable (ASDM & container);
00477 
00478         ASDM & container;
00479         
00480         bool archiveAsBin; // If true archive binary else archive XML
00481         bool fileAsBin ; // If true file binary else file XML   
00482         
00483         std::string version ; 
00484         
00485         Entity entity;
00486         
00487 
00488 
00496         HistoryRow* checkAndAdd(HistoryRow* x, bool skipCheckUniqueness=false) ;
00497         
00503          void append(HistoryRow* x) ;
00504          
00510          void addWithoutCheckingUnique(HistoryRow* x) ;
00511          
00512          
00513 
00514 
00515         
00516         
00524         HistoryRow * insertByTime(HistoryRow* x, std::vector<HistoryRow *>&row );
00525          
00526 
00527 
00528 // A data structure to store the pointers on the table's rows.
00529 
00530 // In all cases we maintain a private vector of HistoryRow s.
00531    std::vector<HistoryRow * > privateRows;
00532    
00533 
00534         
00535 
00536         
00537         
00538                 
00539                                 
00540         typedef std::vector <HistoryRow* > TIME_ROWS;
00541         std::map<std::string, TIME_ROWS > context;
00542                 
00547          std::string Key(Tag execBlockId) ;
00548                  
00549                 
00550         
00551         
00557         void getByKeyNoAutoIncNoTime(std::vector <HistoryRow*>& vin, std::vector <HistoryRow*>& vout,  Tag execBlockId);
00558         
00559 
00560         
00561         void error() ; //throw(ConversionException);
00562 
00563         
00570         void fromXML(std::string& xmlDoc) ;
00571                 
00572         std::map<std::string, BinaryAttributeReaderFunctor *> unknownAttributes2Functors;
00573 
00578         void setFromMIMEFile(const std::string& directory);
00579         /*
00580         void openMIMEFile(const std::string& directory);
00581         */
00582         void setFromXMLFile(const std::string& directory);
00583         
00591         std::string toMIME(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00592   
00593         
00600          void setFromMIME(const std::string & mimeMsg);
00601         
00605         std::string MIMEXMLPart(const asdm::ByteOrder* byteOrder=asdm::ByteOrder::Machine_Endianity);
00606         
00616           void toFile(std::string directory);
00617           
00621           bool loadInProgress;
00622           void checkPresenceInMemory() {
00623                 if (!presentInMemory && !loadInProgress) {
00624                         loadInProgress = true;
00625                         setFromFile(getContainer().getDirectory());
00626                         presentInMemory = true;
00627                         loadInProgress = false;
00628                 }
00629           }
00638          void setFromFile(const std::string& directory);        
00639  
00640 };
00641 
00642 } // End namespace asdm
00643 
00644 #endif /* HistoryTable_CLASS */