00001 00002 // 00003 // Fichero : SvcDeSocket.hpp 00004 // Autor : 00005 // Fecha creacion : 00006 // 00007 // Descripcion : 00008 // 00009 // Notas 00010 // - 00012 00013 #ifndef __SvcDeSocket_H__ 00014 #define __SvcDeSocket_H__ 00015 00016 #include "jic/log/trazas.hpp" 00017 #include "jic/socket/acceptor.hpp" 00018 #include "jic/task/producers/fndesocketdin.hpp" 00019 #include "jic/task/CMessageBlock.hpp" 00020 #include "jic/task/CChainTask.hpp" 00021 #include "jic/socket/sockets.hpp" 00022 00023 00024 namespace SOCKETS 00025 { 00026 00027 EXCEPCION(ExcSalidaNoConectada); 00028 00029 //------------------------------------------------------------------------------ 00030 //------------------------------------------------------------------------------ 00031 template<class Msg> 00032 class SvcDeSocket : public SOCKETS::Servicio 00033 { 00034 public: 00035 SvcDeSocket(); 00036 00037 // Es llamado por cada Msg recibido 00038 int open(void *); 00039 00040 // Es llamado por cada Msg recibido 00041 virtual int handle_input(ACE_HANDLE idConexion); 00042 00043 void set_pNext(TASK::CChainTask<Msg> * next); 00044 00045 private: 00046 TASK::CChainTask<Msg> * _objAct; 00047 00048 00049 // Conexiones activas 00050 TASK::PRODUCERS::FnDeSocketDin<Msg> _fnDeSocketDin; 00051 typedef std::map<ACE_HANDLE, SOCKETS::Socket > MapaConexiones; 00052 MapaConexiones _mapaConexiones; 00053 }; 00054 00055 //------------------------------------------------------------------------------ 00056 //------------------------------------------------------------------------------ 00057 template<class Msg> 00058 class LectorDeSocket 00059 : public SOCKETS::Acceptor<SvcDeSocket<Msg> > 00060 { 00061 public: 00062 LectorDeSocket(int puertoEscucha) 00063 : SOCKETS::Acceptor<SvcDeSocket<Msg> > (puertoEscucha, 00064 (_svc = new SvcDeSocket<Msg>)) 00065 { 00066 O_TRAZA("SERVICIOS::LectorDeSocket::LectorDeSocket(puertoEscucha=" << puertoEscucha << ")"); 00067 } 00068 00069 virtual ~LectorDeSocket() { 00070 O_TRAZA("SERVICIOS::LectorDeSocket::~LectorSondaInelcom()"); 00071 delete _svc; 00072 } 00073 00074 void set_pNext(TASK::CChainTask<Msg> * next) 00075 { 00076 _svc->set_pNext(next); 00077 }; 00078 00079 private: 00080 SvcDeSocket<Msg> * _svc; 00081 00082 }; 00083 00084 00085 00086 #ifdef ACE_TEMPLATES_REQUIRE_SOURCE 00087 #include "svcdesocket.cpp" 00088 #endif 00089 00090 } // namespace SERVICES 00091 00092 #endif 00093 00094 00095 00096