CARMA C++
SyslogMMAPFile.h
Go to the documentation of this file.
1 #ifndef CARMA_DBMS_SYSLOGMMAPFILE_H
2 #define CARMA_DBMS_SYSLOGMMAPFILE_H
3 
4 #include <string>
5 
6 #include <iostream>
7 
8 #include "carma/dbms/SyslogMessage.h"
9 
11 
12 #include "log4cpp/Category.hh"
13 
20 namespace carma
21 {
22  namespace dbms
23  {
24 
32  {
33 
34  public:
35 
41  SyslogMMAPFile( const std::string& mmapFileName, bool writer = false );
42 
45 
46  int getSize() { return mmapSize_; };
47  void *getPtr() { return mmapPtr_; };
48 
49  std::string computeVersionHash();
50  long long computeStateID(const char *);
51  long long getMapStateID();
52  void setMapStateID( long long val ) { *currentState_id_ = val; };
53 
54  bool isConsistent() { return ( myStateID_ == *currentState_id_ ); };
55 
56  static const size_t MMAP_SIZE = 50000300;
57  static const size_t VERSIONID_SIZE = 100;
58  static const size_t SYSLOGMEDIAN_SIZE = 165;
59  static const long MAX_MESSAGES = 300000;
60  static const char *MYID;
61 
62  std::string toString();
63  std::string toVerboseString();
64  std::string getMyID();
65  std::string getVersionHash();
66  size_t getHeaderSize();
67  size_t getMapSize();
68  size_t getVersionIDSize();
69  size_t getSyslogMedianSize();
70 
71  void atomicUpdate( SyslogMessage *aSyslogMessage );
72  long getCurrentPos();
73  long getLastPos();
74  long getPosLoc( long pos );
75 
76  long getNearestAgedPos( double mjd );
77  double peekMJD( long pos );
78 
79  long getNumMessages();
80 
81  SyslogMessage *getCurrentMessage();
82  SyslogMessage *getLastMessage();
83  SyslogMessage *getMessageAt( long pos );
84  SyslogMessage *getMessageAtAndUpdateNext( long &pos );
85 
86  private:
87  std::string mmapFileName_;
88  bool writer_;
89  int mmapFD_;
90  int mmapSize_;
91  log4cpp::Category &log_;
92 
93  unsigned char *mmapPtr_;
94  unsigned char *hashPtr_;
95  unsigned char *IDPtr_;
96  size_t *headerPtrStart_;
97  size_t *headerPtrEnd_;
98  size_t *headerCurrent_;
99  size_t *header_size_;
100  size_t *versionID_size_;
101  size_t *syslogMedian_size_;
102  size_t *lastBytePos_;
103  long long *currentState_id_;
104  long long myStateID_;
105  int headerSize_;
106  std::string versionHash_;
107  long *currentAtomicPos_;
108  long *lastPos_;
109  unsigned char *ringBufferStart_;
110  unsigned char *ringBufferEnd_;
111 
112  static carma::util::SemaphoreOperator *semOp_;
113 
114  // this is a little crazed...
115  static ::std::string *SEM_NAME;
116  static unsigned short num_;
117  };
118  }
119 }
120 
121 #endif // CARMA_DBMS_SYSLOGMMAPFILE_H
Helper class for semaphore operations.
~SyslogMMAPFile()
The destructor.
This class is responsible for opening/closing the syslog mmap file.
SyslogMMAPFile(const std::string &mmapFileName, bool writer=false)
Constructor.