Show
Ignore:
Timestamp:
08/30/08 15:15:48 (4 months ago)
Author:
frsyuki
Message:

lang/c/mpio: added mp::iothreads::reader and mp::iothreads::writer

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/c/mpio/trunk/mp/iothreads.pre.h

    r18340 r18476  
    5454public: 
    5555        template <typename ThreadIMPL> 
    56         static void add_thread(); 
     56        static ThreadIMPL* add_thread(); 
    5757MP_ARGS_BEGIN 
    5858        template <typename ThreadIMPL, MP_ARGS_TEMPLATE> 
    59         static void add_thread(MP_ARGS_PARAMS); 
     59        static ThreadIMPL* add_thread(MP_ARGS_PARAMS); 
    6060MP_ARGS_END 
    6161 
     
    7070private: 
    7171        template <typename ThreadIMPL> 
    72         void add_thread_impl(); 
     72        ThreadIMPL* add_thread_impl(); 
    7373MP_ARGS_BEGIN 
    7474        template <typename ThreadIMPL, MP_ARGS_TEMPLATE> 
    75         void add_thread_impl(MP_ARGS_PARAMS); 
     75        ThreadIMPL* add_thread_impl(MP_ARGS_PARAMS); 
    7676MP_ARGS_END 
    7777 
     
    145145 
    146146#include "mp/iothreads_impl.h" 
     147#include "mp/iothreads/writer.h" 
    147148#include "mp/iothreads/listen.h" 
    148149#include "mp/iothreads/timer.h" 
    149150 
    150  
    151 /* 
    152 namespace mp { 
    153  
    154  
    155 template <typename ThreadTag = main_thread_tag> 
    156 class iothreads { 
    157 public: 
    158  
    159         template <typename IMPL> 
    160         class handler { 
    161         public: 
    162                 handler(int fd); 
    163                 virtual ~handler(); 
    164         protected: 
    165                 template <typename T>  // fixme 
    166                 void submit(void (*callback)(T* obj, void* user), T* obj, void* user); 
    167         public: 
    168                 //virtual int read_event() = 0; 
    169         }; 
    170  
    171         template <typename IMPL> 
    172         class stream_handler : public handler { 
    173         public 
    174                 stream_handler(int fd);  // allocate buffer 
    175                 virtual ~stream_handler(); 
    176         public: 
    177                 int read_event(); 
    178         public: 
    179                 // throw exception to close fd 
    180                 //virtual void receive_data(stream& s) = 0; 
    181                 //virtual void unbind() = 0; 
    182         }; 
    183  
    184         template <typename IMPL> 
    185         class timer : public handler { 
    186         public: 
    187                 timer(int fd); 
    188                 virtual ~timer(); 
    189         public: 
    190                 static start(double interval); 
    191         public: 
    192                 //virtual void triger() = 0; 
    193         }; 
    194  
    195  
    196         struct thread { 
    197                 virtual ~thread() {} 
    198                 virtual void run() = 0; 
    199         }; 
    200  
    201         class io_thread : public thread { 
    202         public: 
    203                 io_thread(); 
    204                 ~io_thread(); 
    205         public: 
    206                 void run(); 
    207         private: 
    208                 struct cb_t { 
    209                 public: 
    210                         cb_t(); 
    211                         ~cb_t(); 
    212                 public: 
    213                         short event(); 
    214                         void event(short ev); 
    215                         handler& handler(); 
    216                         // fixme buffer accessor 
    217                 private: 
    218                         short m_event; 
    219                         handler& m_handler; 
    220                         char* m_wbuffer;  // fixme 
    221                 }; 
    222         private: 
    223                 void close_connection(cb_t& cb); 
    224                 void rswitch(cb_t& cb); 
    225                 void wswitch(cb_t& cb); 
    226         public: 
    227                 void add(handler* handler); 
    228                 bool have(int fd); 
    229                 void send_data(int fd, char* data, size_t len);  // fixme 
    230                 void send_message(int fd, char* msg, size_t len);  // fixme 
    231         private: 
    232                 // fixme 
    233                 void msg_add(); 
    234                 void msg_send_data(); 
    235                 void msg_send_message(); 
    236         }; 
    237  
    238  
    239 public: 
    240         static void initialize(unsigned int num_threads); 
    241         static void destroy(); 
    242         ~buffer(); 
    243  
    244         template <typename Handler> 
    245         void add(int fd); 
    246 MP_ARGS_BEGIN 
    247         template <typename Handler, MP_ARGS_TEMPLATE> 
    248         inline int add(int fd, MP_ARGS_PARAMS); 
    249 MP_ARGS_END 
    250  
    251 public: 
    252         void remove(handler* ctx); 
    253  
    254 public: 
    255         void send_data(int fd, const char* data, size_t len); 
    256         void send_message(int fd, const char* data, size_t len);  // fixme 
    257  
    258 public: 
    259         template <typename Thread> 
    260         void custom_thread(); 
    261 MP_ARGS_BEGIN 
    262         template <typename Thread, MP_ARGS_TEMPLATE> 
    263         inline int custom_thread(MP_ARGS_PARAMS); 
    264 MP_ARGS_END 
    265  
    266 public: 
    267         void run(); 
    268         void end(); 
    269         bool is_end() const; 
    270  
    271 public: 
    272         void submit(void* data);  // fixme 
    273  
    274 private: 
    275         iothreads(unsigned int num_threads); 
    276  
    277 private: 
    278         unsigned int m_num_threads; 
    279  
    280 private: 
    281         iothreads(const iothreads&); 
    282         iothreads(); 
    283 }; 
    284  
    285  
    286  
    287 }  // namespace mp 
    288 */ 
    289  
    290  
    291151#endif /* mp/iothreads.h */ 
    292152