00001 #ifndef COMM_MANAGER_H 00002 #define COMM_MANAGER_H 00003 00004 #include <pthread.h> 00005 #include <list> 00006 #include <Socket.h> 00007 #include "Datagram.h" 00008 00009 class CommManager 00010 { 00011 protected : 00012 std::list<Datagram> inbox; 00013 Socket * sock; 00014 struct CallBack { 00015 void (*callback)(void*); 00016 void * arg; 00017 }; 00018 CallBack cb[256]; 00019 00020 pthread_t in_thread; 00021 pthread_mutex_t mtx; 00022 friend void * commmanager_inthread(void *); 00023 void store(const Datagram & dgm); 00024 public : 00025 CommManager(); 00026 ~CommManager(); 00027 00028 bool open(const char * hostname, unsigned int port); 00029 bool close(); 00030 00031 bool send(const Datagram & dgm); 00032 Datagram wait(unsigned char id); 00033 }; 00034 00035 00036 00037 00038 00039 #endif