Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
UDPClient.hh
1 #ifndef __UDPCLIENT__
2 #define __UDPCLIENT__
3 
4 #include <bias_config.h>
5 
6 #include <stdlib.h>
7 #include <vector>
8 
9 #ifdef WIN32
10 #include <winsock.h>
11 #else
12 #include <netinet/in.h>
13 #endif
14 #include "UDPDataConsumer.hh"
15 
16 namespace BIAS {
17 
18 
20 
21  bool is_free;
22  int number;
25  int frames_total; // WARNING: DO WE NEED FRAMES TOTAL REALLY?
26  char* frame_data;
27 };
28 
29 
30 
31 /**
32  @class UDPClient
33  @brief class for receiving UDP packages
34  @ingroup network
35  @author Ingo Thomsen
36  */
37 class BIASNetworkComm_EXPORT UDPClient {
38 
39 public:
40 
41  UDPClient();
42 
43  /**
44  Destructor
45  **/
46  ~UDPClient();
47 
48  /**
49  @param port Wait for incoming UDP packages on this port
50  @param bind_to_ip bin to this IP, of NULL is given use any ip
51  */
52  void Init(int port,const char* bind_to_ip=NULL);
53 
54  /**
55  Start receiving UDP packages. The is done in a seperated thread.
56  @author Ingo Thomsen
57  @param number_of_package_buffers How UDP packages shall be buffered?
58  @param max_message_size The maximum size of a completed message
59  @param number_of_message_buffers How many messages can be buffered (at least 1). Therefore
60  the allocated memory size is at least max_message_size * number_of_message_buffers !
61  @param uc The UDPDataConsumer whose consume_complete_message()-method is
62  called, when a message has been completed by this client.
63  @returns -1 if there occurs an error before or while creating the thread and returns 0 otherwise
64  **/
65  int start(int max_message_size, int number_of_message_buffers,
66  UDPDataConsumer* uc, bool UseTCP = false);
67 
68 
69  /**
70  Stop the running client thread
71 
72  @author Ingo Thomsen
73  @todo Leave the multicast group
74  **/
75  void stop();
76 
77 
78  // Is the UDPClient started?
79  inline bool IsActive() {return is_active_;}
80 
81  char *GetServerAddr(){return ServerAddr_;}
82 
83  void receive_loop();
84 
85 protected:
86 
88 
90 
92 
93  void check_for_complete_message(int last_number, int frames_total);
94 
95  int get_a_free_buffer();
96 
97  // Use multicast?
99 
100  // Is true while client is started
102  // true when client loop has ended
104 
105  // The local socket address
106  struct sockaddr_in local_socket_address_;
107 
108  // descriptor of the UDP socket
110 
111  // void* receive_loop(void* udpclient);
112 
113  std::vector<message_frame_buffer> Buffers_;
114 
115  void create_buffer_structure(unsigned int numbuffers);
116  void destroy_buffer_structure();
117 
118  // the servers IP address in numbers-and-dots notation
119  char *ServerAddr_;
120 
121  // number of UDP Package buffers
124 
125 }; // class MulticastClient
126 
127 } // namespace BIAS
128 
129 #endif
class for receiving UDP packages
Definition: UDPClient.hh:37
char * GetServerAddr()
Definition: UDPClient.hh:81
bool IsActive()
Definition: UDPClient.hh:79
Interface class for UDP data.
UDPDataConsumer * udc
Definition: UDPClient.hh:89
std::vector< message_frame_buffer > Buffers_
Definition: UDPClient.hh:113
bool TCPinsteadOfUDP_
Definition: UDPClient.hh:123
int number_of_package_buffers_
Definition: UDPClient.hh:122
char * ServerAddr_
Definition: UDPClient.hh:119
long message_counter
Definition: UDPClient.hh:87
char ** completed_message
Definition: UDPClient.hh:91