fgms 0.11.8
The
FlightGear MultiPlayer Server
project
fg_tracker.hxx
Go to the documentation of this file.
1 /**
2  * @file fg_tracker.hxx
3  * @author (c) 2006 Julien Pierru
4  *
5  */
6 
7 //////////////////////////////////////////////////////////////////////
8 //
9 // server tracker for FlightGear
10 // (c) 2006 Julien Pierru
11 //
12 // Licenced under GPL
13 //
14 //////////////////////////////////////////////////////////////////////
15 
16 #if !defined FG_TRACKER_HPP
17 // #define FG_TRACKER_HPP
18 
19 using namespace std;
20 
21 // #define ADD_TRACKER_LOG
22 
23 #include <iostream>
24 #include <fstream>
25 #include <string>
26 #include <vector>
27 #include <string.h>
28 #include <errno.h>
29 #include <time.h>
30 #include <stdint.h>
31 #include <unistd.h>
32 #include <plib/netSocket.h>
33 #include "daemon.hxx"
34 #include "fg_geometry.hxx"
35 
36 #define CONNECT 0
37 #define DISCONNECT 1
38 #define UPDATE 2
39 
40 void signal_handler(int s);
41 
42 //////////////////////////////////////////////////////////////////////
43 /**
44  * @class FG_TRACKER
45  * @brief The tracker class
46  */
48 {
49 public:
50  //////////////////////////////////////////////////
51  //
52  // constructors
53  //
54  //////////////////////////////////////////////////
55  FG_TRACKER (int port, string server, int id);
56  ~FG_TRACKER ();
57 
58  //////////////////////////////////////////////////
59  //
60  // public methods
61  //
62  //////////////////////////////////////////////////
63  int Loop ();
64  void AddMessage ( const string & message );
65 
66  /**
67  * @brief Return the server of the tracker
68  * @retval string Return tracker server as string
69  */
70  string GetTrackerServer () { return m_TrackerServer; };
71 
72  /**
73  * @brief Return the port no of the tracker
74  * @retval int Port Number
75  */
76  int GetTrackerPort () { return m_TrackerPort; };
77  int TrackerWrite (const string& str);
78  void TrackerRead ();
79  void ReplyToServer (const string& str);
80  void WriteQueue ();
81  void ReadQueue ();
82  pthread_t GetThreadID();
83 
84  //////////////////////////////////////////////////
85  //
86  // private methods
87  //
88  //////////////////////////////////////////////////
89  bool Connect ();
90  //////////////////////////////////////////////////
91  //
92  // private variables
93  //
94  //////////////////////////////////////////////////
97  bool m_connected; /*If connected to fgtracker*/
99 
100  typedef std::vector<std::string> vMSG; /* string vector */
101  typedef vMSG::iterator VI; /* string vector iterator */
102  pthread_mutex_t msg_mutex; /* message queue mutext */
103  pthread_cond_t condition_var; /* message queue condition */
104  vMSG msg_queue; /* the single message queue */
105  bool WantExit;
106  //////////////////////////////////////////////////
107  // stats
108  //////////////////////////////////////////////////
110  time_t LastSeen;
111  time_t LastSent;
112  uint64_t BytesSent;
113  uint64_t BytesRcvd;
114  uint64_t PktsSent;
115  uint64_t PktsRcvd;
117  pthread_t MyThreadID;
118 };
119 #endif
120 
121 // eof -fg_tracker.hxx
pthread_cond_t condition_var
Definition: fg_tracker.hxx:103
uint64_t PktsRcvd
Definition: fg_tracker.hxx:115
size_t LostConnections
Definition: fg_tracker.hxx:116
netSocket * m_TrackerSocket
Definition: fg_tracker.hxx:98
Socket type.
Definition: netSocket.h:125
std::vector< std::string > vMSG
Definition: fg_tracker.hxx:100
vMSG msg_queue
Definition: fg_tracker.hxx:104
The tracker class.
Definition: fg_tracker.hxx:47
uint64_t PktsSent
Definition: fg_tracker.hxx:114
bool m_connected
Definition: fg_tracker.hxx:97
time_t LastSent
Definition: fg_tracker.hxx:111
time_t LastSeen
Definition: fg_tracker.hxx:110
int GetTrackerPort()
Return the port no of the tracker.
Definition: fg_tracker.hxx:76
int m_TrackerPort
Definition: fg_tracker.hxx:95
pthread_mutex_t msg_mutex
Definition: fg_tracker.hxx:102
int Connect(int sockfd, const struct sockaddr *serveraddr, socklen_t addrlen)
Definition: wrappers.c:44
string m_TrackerServer
Definition: fg_tracker.hxx:96
uint64_t BytesRcvd
Definition: fg_tracker.hxx:113
static char * port
Definition: server.c:69
time_t LastConnected
Definition: fg_tracker.hxx:109
pthread_t MyThreadID
Definition: fg_tracker.hxx:117
netSocket is a thin C++ wrapper over bsd sockets to facilitate porting to other platforms. Part of PLIB - A Suite of Portable Game Libraries
uint64_t BytesSent
Definition: fg_tracker.hxx:112
string GetTrackerServer()
Return the server of the tracker.
Definition: fg_tracker.hxx:70
void signal_handler(int s)
Signal handling.
Definition: fg_tracker.cxx:461
vMSG::iterator VI
Definition: fg_tracker.hxx:101