async_reception.h

00001 /*   
00002  *   (c) Copyright 2008 Philipp Skadorov (philipp_s@users.sourceforge.net)
00003  *
00004  *   This file is part of FREESECS.
00005  *
00006  *   FREESECS is free software: you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation, either version 3 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   FREESECS is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with FREESECS, see COPYING.
00018  *   If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 #ifndef _ASYNC_RECEPTION_H
00021 #define _ASYNC_RECEPTION_H
00022 
00023 #include <pthread.h>
00024 #include <list>
00025 #include "signals.h"
00026 
00027 #define MAX_FSM_NAME 48
00028 
00029 namespace freesecs
00030 {
00043     class async_reception_t
00044     {
00045     public:
00049         typedef enum
00050         {
00051             IDLE = 0,
00052             WTG_FOR_DATA,
00053             RECEIVED
00054         }state_t;
00055 
00061         async_reception_t(int fd, const char *name);
00062         virtual ~async_reception_t();
00063 
00077         void start_recv(void *buf, size_t count);
00078 
00082         void stop_recv();
00083 
00087         state_t get_state();
00088 
00093         size_t  get_bytes_read();
00094 
00099         signal_one_arg_t<size_t>    data_partially_recvd_signal;
00104         signal_one_arg_t<size_t>    data_recvd_signal;
00110         signal_one_arg_t<int>       recv_error_signal;
00111 
00112     private:
00116         typedef union
00117         {
00118             struct
00119             {
00120                 void    *buf;/*beginning of user data pool*/
00121                 size_t  count;/*length of data to receive*/
00122             }e0;
00123             struct
00124             {
00125                 int     rx_error;
00126                 ssize_t  bytes_read;
00127             }e1;
00128         }event_data_t;
00129 
00133         void process(int e, event_data_t data);
00134 
00135         void stop_read();
00136 
00137         void z1_0(event_data_t);
00138         void z2_0(event_data_t);
00139         void z1(event_data_t);
00140         void z2(event_data_t);
00141         void z3(event_data_t);
00142         bool x1();
00143         bool x2();
00144 
00145         bool check_fd_process(const fd_set*);
00146 
00147     private:
00148         char _name[MAX_FSM_NAME];
00149 
00150     private:
00151         int             _fd;
00152         void           *_buf;
00153         size_t          _bytes_to_read;
00154         size_t          _bytes_read;
00155         int             _rx_error;
00156         state_t         _state;
00157 
00158     private:
00159         static int                              _subscr_count;
00160         static int                              _update_fd[2];
00161         typedef std::list<async_reception_t*>   thisv_t;
00162         static thisv_t                          _thisv;
00163         static pthread_mutex_t                  _thisv_mx;
00164         
00165         static pthread_t                        _sigthread_id;
00166         static void                            *signalthread(void *arg);
00167 
00168     private:
00169         static void set_need_update_fdset();
00170         static void set_need_exit();
00171         static bool get_need_update_fdset();
00172         static void update_fdset(int *fdn, fd_set *fds, thisv_t *thisv, bool clear_cache);
00173 
00174 
00175     /*no default ctors, no copies*/
00176     private:
00177         async_reception_t();
00178         async_reception_t(const async_reception_t&);
00179         async_reception_t& operator = (const async_reception_t&);
00180     };
00181 }//namespace
00182 #endif/*_ASYNC_RECEPTION_H*/

Generated on Fri Oct 3 15:30:01 2008 for FREESECS hsms by  doxygen 1.5.1