CFEL - ASG Software Suite  2.5.0
CASS
tcp_input.h
Go to the documentation of this file.
1 // Copyright (C) 2011, 2012, 2013 Lutz Foucar
2 
3 /**
4  * @file tcp_input.h contains input that uses tcp as interface
5  *
6  * @author Lutz Foucar
7  */
8 
9 #ifndef __TCPINPUT_H__
10 #define __TCPINPUT_H__
11 
12 #include <string>
13 
14 #include "cass.h"
15 #include "input_base.h"
16 #include "cass_event.h"
17 #include "ringbuffer.hpp"
18 
19 class QTcpSocket;
20 
21 namespace cass
22 {
23 /** TCP Input for receiving data
24  *
25  * This class is a thread that to a TCP Server and retrieves the data from it.
26  * it expects that before the payload conatining the data arrives the size of
27  * the payload is transmitted.
28  *
29  * @cassttng TCPInput/{Server}\n
30  * The name or ip address of the machine that the server is running on.
31  * Default is "localhost"
32  * @cassttng TCPInput/{Port}\n
33  * The port that the TCP Server is listening for connections on.
34  * Default is "9090"
35  * @cassttng TCPInput/{DataType}\n
36  * The type of data that is streamed from the tcp server. Default is
37  * "agat". Possible values are:
38  * - "agat": The type of data that is streamed from a normal version
39  * of AGAT3.
40  * - "shm": Type of data that is streamed from RACOON shm2tcp server.
41  * is to be used with the new ccd analysis chain.
42  * @cassttng TCPInput/{SocketDataTimeout_ms}\n
43  * Time in ms to wait until the data should be available. If time was
44  * exeeded it will check if the connection on the socket to the server
45  * was lost. Default is 2000 ms.
46  * @cassttng TCPInput/{SocketConnectionTimout_ms}\n
47  * Time in ms to wait until the socket is connected to the server.
48  * Default is 1000 ms.
49  * @cassttng TCPInput/{WaitUntilReconnectionTry_s}\n
50  * Time in s to wait until another attempt is made to reconnect the
51  * socket to the server. Default is 5.
52  *
53  * @author Lutz Foucar
54  */
55 class TCPInput : public InputBase
56 {
57 public:
58  /** create an instance of this
59  *
60  * this initializes the _instance member of the base class. Check here if
61  * it is already initialized, if so throw logic error.
62  *
63  * @param buffer the ringbuffer, that we take events out and fill it
64  * with the incomming information
65  * @param ratemeter reference to the ratemeter to measure the rate of the input
66  * @param loadmeter reference to the ratemeter to measure the load of the input
67  * @param parent the parent of this object
68  */
69  static void instance(RingBuffer<CASSEvent>& buffer,
70  Ratemeter &ratemeter, Ratemeter &loadmeter,
71  QObject *parent=0);
72 
73  /** starts the thread
74  *
75  * Starts the thread and the loop that waits for data. When an timout occured
76  * it will just restart the loop until the quit flag is set.
77  */
78  void runthis();
79 
80  /** do not load anything */
81  void load() {}
82 
83 private:
84  /** constructor
85  *
86  * creates the thread. Connects to the tcp server and then retrieves the
87  * data streams. The data within the stream will be deserialized with the
88  * help of deserialization functions, where the user has to choose which
89  * one is appropriate via the .ini file parameters. The thread runs as long
90  * as noone calls the end() member of the base class.
91  * In case a timeout occurs when waiting for a new event, it will just continue
92  * and wait for the next timeout. In case that a timeout occurred when waiting
93  * for the data of an event it throws an runtime error.
94  *
95  * @param buffer the ringbuffer, that we take events out and fill it
96  * with the incomming information
97  * @param ratemeter reference to the ratemeter to measure the rate of the input
98  * @param loadmeter reference to the ratemeter to measure the load of the input
99  * @param parent the parent of this object
100  */
102  Ratemeter &ratemeter, Ratemeter &loadmeter,
103  QObject *parent=0);
104 
105 
106  /** connect the socket to server
107  *
108  * tries to connect the socket to the server as long as user did not finish
109  * the program or the socket has connected to the server
110  *
111  * @return true when connection is established. False otherwise
112  * @param socket the socket that one should connect to the server
113  */
114  bool connectToServer(QTcpSocket &socket);
115 
116  /** wait until the data is available
117  *
118  * waits until the requested datasize is available on the socket. In case there
119  * is a timeout, check if the connection was lost. If this is the case,
120  * reconnect. And return false.
121  *
122  * @return true when requested datasize is available on the socket for reading
123  * false otherwise.
124  * @param socket the socket for which to wait for data for
125  * @param datasize the amount of data to wait for.
126  */
127  bool dataAvailable(QTcpSocket &socket, qint64 datasize);
128 
129  /** the timeout of the socket */
130  int _timeout;
131 };
132 
133 }//end namespace cass
134 
135 #endif
class calculating a rate in Hz.
Definition: ratemeter.h:28
file contains declaration of the CASSEvent
Input base class.
Definition: input_base.h:31
bool connectToServer(QTcpSocket &socket)
connect the socket to server
Definition: tcp_input.cpp:42
TCPInput(RingBuffer< CASSEvent > &buffer, Ratemeter &ratemeter, Ratemeter &loadmeter, QObject *parent=0)
constructor
Definition: tcp_input.cpp:35
void runthis()
starts the thread
Definition: tcp_input.cpp:98
A Ringbuffer, handles communication between Input and Worker Threads.
Definition: ringbuffer.hpp:52
void load()
do not load anything
Definition: tcp_input.h:81
file contains the ringbuffer class
file contains global definitions for project cass
TCP Input for receiving data.
Definition: tcp_input.h:55
static shared_pointer instance()
get the signelton instance
Definition: input_base.cpp:20
bool dataAvailable(QTcpSocket &socket, qint64 datasize)
wait until the data is available
Definition: tcp_input.cpp:75
contains the base class for all input modules
int _timeout
the timeout of the socket
Definition: tcp_input.h:130