00001
00002 #ifndef UDP_SRV_HH
00003 #define UDP_SRV_HH
00004
00005 #include "rcs_defs.hh"
00006 #include "cms_srv.hh"
00007 #include "linklist.hh"
00008 #include "msghdr.h"
00009 #include "sokintrf.h"
00010
00011 #ifdef sunos5
00012 #include <thread.h>
00013 #endif
00014
00015 #ifdef linux
00016 #define NO_THREADS
00017 #endif
00018
00019 #ifdef POSIX_THREADS
00020 #include <pthread.h>
00021 #endif
00022
00023
00024 #define MAX_UDP_BUFFER_SIZE 16
00025
00026 class UDP_BROADCAST_DATA;
00027
00028 class CLIENT_UDP_PORT
00029 {
00030 public:
00031 CLIENT_UDP_PORT ();
00032 int subscription_id;
00033 int last_read_id;
00034 unsigned long serial_number;
00035 int errors, max_errors;
00036 struct sockaddr_in address;
00037 int socket_fd;
00038 RCS_LINKED_LIST *subscriptions;
00039 struct msghdr reply_message_header;
00040 struct sockaddr_in client_socket_address;
00041 struct iovec reply_iov2[2];
00042 int client_list_id;
00043
00044 #if defined(WIN32) && !defined(gnuwin32)
00045 DWORD tid;
00046 DWORD pid;
00047 #else
00048 #ifdef VXWORKS
00049 int tid;
00050 int pid;
00051 #else
00052 pid_t tid;
00053 pid_t pid;
00054 #endif
00055 #endif
00056 int blocking;
00057 #ifdef sunos5
00058 thread_t threadId;
00059 #else
00060 #ifdef POSIX_THREADS
00061 pthread_t threadId;
00062 #else
00063 int threadId;
00064 #endif
00065 #endif
00066 };
00067
00068
00069 class CMS_SERVER_REMOTE_UDP_PORT:public CMS_SERVER_REMOTE_PORT
00070 {
00071 public:
00072 CMS_SERVER_REMOTE_UDP_PORT (CMS_SERVER * _cms_server);
00073 virtual ~ CMS_SERVER_REMOTE_UDP_PORT ();
00074 int accept_local_port_cms (CMS *);
00075 void run ();
00076 void register_port ();
00077 void unregister_port ();
00078 double dtimeout;
00079
00080 protected:
00081 fd_set read_fd_set, write_fd_set;
00082 void handle_request ();
00083 int maxfdpl;
00084 int request_length;
00085 RCS_LINKED_LIST *client_ports;
00086 int connection_socket;
00087 long connection_port;
00088 struct sockaddr_in server_socket_address;
00089 REMOTE_CMS_REQUEST *request;
00090 char temp_buffer[32];
00091 CMS_SERVER *server;
00092 struct sockaddr_in client_address;
00093 struct msghdr message_header;
00094 int client_addresslen;
00095 double polling_period;
00096 struct iovec iov2[2];
00097 RCS_LINKED_LIST *subscription_buffers;
00098 int current_poll_interval_millis;
00099 int polling_enabled;
00100 struct timeval select_timeout;
00101 void update_subscriptions ();
00102 void add_subscription_client (int buffer_number, int subdiv,
00103 int subscription_type,
00104 int poll_interval_millis,
00105 CLIENT_UDP_PORT * clnt);
00106 void remove_subscription (int subscription_id, int buffer_number,
00107 int subdiv);
00108 void remove_subscription_client (CLIENT_UDP_PORT * clnt, int buffer_number,
00109 int subdiv);
00110 CLIENT_UDP_PORT *get_client_port (sockaddr_in * client_address);
00111 void recalculate_polling_interval ();
00112 int last_subscription_id;
00113 RCS_LINKED_LIST *broadcast_ports;
00114 int request_header_size;
00115 int reply_header_size;
00116 struct sockaddr_in broadcast_address;
00117 int broadcast_address_set;
00118 void set_broadcast_address (CMS *);
00119 #ifndef VXWORKS
00120 struct hostent *broadcast_server_host_entry;
00121 #endif
00122 int broadcast_subscriptions;
00123 };
00124
00125 class UDP_BROADCAST_DATA
00126 {
00127 public:
00128 int buffer_number;
00129 struct sockaddr_in broadcast_address;
00130 int broadcast_clnt_port;
00131 };
00132
00133
00134 class UDP_BUFFER_SUBSCRIPTION_INFO
00135 {
00136 public:
00137 UDP_BUFFER_SUBSCRIPTION_INFO ();
00138 ~UDP_BUFFER_SUBSCRIPTION_INFO ();
00139 int buffer_number;
00140 int subdiv;
00141 int min_last_id;
00142 unsigned long max_serial_number;
00143 int list_id;
00144 double last_update_time;
00145 double min_update_interval;
00146 UDP_BROADCAST_DATA *broadcast_data;
00147 RCS_LINKED_LIST *sub_clnt_info;
00148 };
00149
00150 class UDP_CLIENT_SUBSCRIPTION_INFO
00151 {
00152 public:
00153 UDP_CLIENT_SUBSCRIPTION_INFO ();
00154 ~UDP_CLIENT_SUBSCRIPTION_INFO ();
00155 int subscription_type;
00156 int poll_interval_millis;
00157 double last_sub_sent_time;
00158 int subscription_list_id;
00159 int buffer_number;
00160 int subdiv;
00161 int subscription_paused;
00162 int last_id_read;
00163 int subscription_id;
00164 CLIENT_UDP_PORT *clnt_port;
00165 UDP_BUFFER_SUBSCRIPTION_INFO *sub_buf_info;
00166 };
00167
00168
00169 #endif