CARMA C++
Connections.h
1 
2 #ifndef CARMA_UI_RTD_CONNECTIONS_H
3 #define CARMA_UI_RTD_CONNECTIONS_H
4 
5 #include <string>
6 #include "MemoryMappedFile.h"
7 
8 
9 
10 /*
11  * Class definition for the Connections classes. This class keeps track
12  * of all connections to the monitoring window package.
13  * The memory mapped filename is hardwired to be "connections.shmem"
14  * in the mmap directory.
15  *
16  * @author Steve Scott
17  *
18  * $id: $
19  *
20  * $CarmaCopyright$
21  *
22  */
23 
24 
25 
26 namespace carma {
27  namespace ui {
28  namespace rtd {
29 
30 
31 
32 
33 /*
34 ** Define the size of strings and arrays
35 */
36 const int SIZEOF_USERNAME = 14;
37 const int SIZEOF_LONGUSERNAME = 60;
38 const int SIZEOF_FULLNAME = 40;
39 const int SIZEOF_COMPACTNAME = 40;
40 const int SIZEOF_LOCATION = 10;
41 const int SIZEOF_FULLLOCATION = 50;
42 const int SIZEOF_WINDOWNAME = 20;
43 const int SIZEOF_CONNECTSTART = 20;
44 const int SIZEOF_WINDOWUPDATE = 10;
45 const int NUMBEROF_CONNECTIONS = 150;
46 
47 
51 struct Cnx {
53  int processId;
55  char windowName[SIZEOF_WINDOWNAME];
57  char userName[SIZEOF_USERNAME];
59  char fullName[SIZEOF_FULLNAME];
61  char compactName[SIZEOF_COMPACTNAME];
63  char location[SIZEOF_LOCATION];
65  char fullLocation[SIZEOF_FULLLOCATION];
67  char connectStartString[SIZEOF_CONNECTSTART];
71  char windowUpdateRate[SIZEOF_WINDOWUPDATE];
73  bool guest;
75  bool hasControl;
77  bool valid;
78 };
79 
92  char userName[SIZEOF_USERNAME];
94  char longUserName[SIZEOF_LONGUSERNAME];
96  Cnx cnx[NUMBEROF_CONNECTIONS];
97 };
98 
108 public:
112  ConnectionBase(int pid, const std::string& filename, MemoryMappedFile::Protection_t p);
114  virtual ~ConnectionBase();
116  virtual std::string toString();
118  void lockRead();
120  void lockWrite();
122  void unlock();
124  int getSerialNumber();
126  int getMaxConnections();
127 protected:
129  int pid_;
135  std::string memoryMappedFilename;
136 private:
137 };
138 
143 public:
145  ConnectionRW(int pid, const std::string& filename);
146 
148  virtual ~ConnectionRW() {};
149 
151  void registerWindow( const char * windowName,
152  const char * userName,
153  const char * fullName,
154  const char * location,
155  const char * fullLocation,
156  int guest );
158  void unregisterWindow(int pid);
160  void unregisterDeadWindows();
162  char* setControl(bool usurp);
164  void setUpdateRate(double updateRate);
166  void setReloadInProgress(int state);
168  int getReloadInProgress();
170  void setPID(int _pid);
171 private:
173  void updateCnxControlState();
175  char controlChangeMessage[200];
176 };
177 
178 
183 public:
185  ConnectionRO(int pid, const std::string& filename);
187  virtual ~ConnectionRO() {};
188 
190  Cnx* getThisCnx();
194  int getCacheSerialNumber();
196  std::string toString();
197 
198 private:
199  ConnectionData cachedData; // The cached data for ro operations
200  int cnxIndex; // Index for the cnx for this process
201 };
202 
203 
204 }}} // End namespace carma::ui::rtd
205 
206 
207 #endif // CARMA_UI_RTD_CONNECTIONS_H
char longUserName[SIZEOF_LONGUSERNAME]
Control user, includes location, gecos.
Definition: Connections.h:94
char connectStartString[SIZEOF_CONNECTSTART]
UT time of start of connection.
Definition: Connections.h:67
bool haveControlUser
Logical: 1 if someone has control.
Definition: Connections.h:88
MemoryMappedFile * memMap
Pointer to the memory mapped file that contains connection database.
Definition: Connections.h:133
char * setControl(bool usurp)
Usurp or abdicates control; returns a message suitable for logging.
char userName[SIZEOF_USERNAME]
Control user short form, null string if nobody in control.
Definition: Connections.h:92
virtual ~ConnectionRW()
Destructor.
Definition: Connections.h:148
double connectStartMJD
MJD time of start of connection.
Definition: Connections.h:69
int processId
Server process (unique for each window)
Definition: Connections.h:53
Cnx * getThisCnx()
This method gets the current cnx from cache (refreshing if necessary)
int getSerialNumber()
Get the serial number of this data set (debugging)
int serialNumber
Increment everytime control or cnx change.
Definition: Connections.h:86
void lockWrite()
Lock connection database shared memory for read access.
ConnectionData * connection
Pointer to a copy of connect database.
Definition: Connections.h:131
char fullLocation[SIZEOF_FULLLOCATION]
Nodename w/ domain.
Definition: Connections.h:65
Protection_t
File protection flags.
Memory Mapped file is a class that provides a C++ interface to the mmap(2) system call...
char compactName[SIZEOF_COMPACTNAME]
Concatenation of username(fullname)
Definition: Connections.h:61
bool hasControl
The user for this window is in control (has usurped)
Definition: Connections.h:75
ConnectionRW(int pid, const std::string &filename)
Constructor.
Cnx cnx[NUMBEROF_CONNECTIONS]
Array of all of the individual connections.
Definition: Connections.h:96
char windowUpdateRate[SIZEOF_WINDOWUPDATE]
Window update rate in hertz.
Definition: Connections.h:71
bool valid
This entry has a valid connection in it.
Definition: Connections.h:77
virtual std::string toString()
Dump status of all connections to a string.
MemoryMappedFile is a class that provides a C++ interface to the mmap(2) system call.
std::string toString()
Return state of this object as a string.
void unregisterDeadWindows()
Remove dead processes from the connection table.
void registerWindow(const char *windowName, const char *userName, const char *fullName, const char *location, const char *fullLocation, int guest)
Register the window in the connection table.
char windowName[SIZEOF_WINDOWNAME]
Window name.
Definition: Connections.h:55
Class to access connection shared memory object with readonly mode.
Definition: Connections.h:182
void unlock()
Release lock on connection database shared memory.
bool guest
Flag for guest access mode.
Definition: Connections.h:73
virtual ~ConnectionBase()
Destructor.
char userName[SIZEOF_USERNAME]
Username, e.g. jsmith.
Definition: Connections.h:57
char fullName[SIZEOF_FULLNAME]
Full username, e.g. &quot;Joe Smith&quot;.
Definition: Connections.h:59
int getMaxConnections()
Return the maximum number of connections possible.
Structure definition for a single connection to the system.
Definition: Connections.h:51
Structure definition for keeping track of all connections, windows, and user control of the system...
Definition: Connections.h:84
void lockRead()
Lock connection database shared memory for read access.
std::string memoryMappedFilename
Filename of connection database.
Definition: Connections.h:135
ConnectionBase(int pid, const std::string &filename, MemoryMappedFile::Protection_t p)
Constructor.
Base class for the connection objects.
Definition: Connections.h:107
int getCacheSerialNumber()
Get the serial number for the cached data (debugging)
virtual ~ConnectionRO()
Destructor.
Definition: Connections.h:187
int pid_
Process id for this connection.
Definition: Connections.h:129
void unregisterWindow(int pid)
Unregister the window in the connection table.
int getReloadInProgress()
Get the value of the reloadInProgress flag.
ConnectionData * getConnectionData()
This method gets the connectionData from cache (refreshing if necessary)
void setUpdateRate(double updateRate)
Set window update rate in seconds.
Class to access connection shared memory object with read/write mode.
Definition: Connections.h:142
void setPID(int _pid)
For backdoor debugging only.
void setReloadInProgress(int state)
Set or clear the reloadInProgress flag.
ConnectionRO(int pid, const std::string &filename)
Constructor.
char location[SIZEOF_LOCATION]
Nodename w/o domain.
Definition: Connections.h:63
bool reloadInProgress
Logical: 1 if a reload is in progress.
Definition: Connections.h:90