User Manual, Developers Guide and API Documentation

TcpClientBinding.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  * TCP ClientBinding                                                          *
00003  * __________________________________________________________________________ *
00004  *                                                                            *
00005  * Copyright (C) 2005                                                         *
00006  * Lehrstuhl fuer Kommunikationsnetze (ComNets)                               *
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany                                 *
00008  * phone: ++49-241-80-27910 (phone), fax: ++49-241-80-22242                   *
00009  * email: wns@comnetsrwth-aachen.de, www: http://wns.comnets.rwth-aachen.de/  *
00010  *****************************************************************************/
00011 
00012 #include <CONSTANZE/TcpClientBinding.hpp>
00013 #include <CONSTANZE/TcpClientListenerBinding.hpp>
00014 
00015 #include <WNS/StaticFactory.hpp>
00016 #include <WNS/service/nl/Address.hpp>
00017 #include <WNS/service/tl/PortPool.hpp>
00018 #include <WNS/module/Base.hpp>
00019 
00020 using namespace constanze;
00021 
00022 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00023     constanze::TcpClientBinding,
00024     constanze::Binding,
00025     "TcpClientBinding",
00026     wns::PyConfigViewCreator);
00027 
00028 TcpClientBinding::TcpClientBinding(const wns::pyconfig::View& _pyco):
00029     pyco(_pyco),
00030     dns(NULL),
00031     domainName(_pyco.get<std::string>("domainName")),
00032     destinationDomainName(_pyco.get<std::string>("destinationDomainName")),
00033     destinationPort(_pyco.get<int>("destinationPort")),
00034     qosClass(_pyco.get<int>("qosClass")), // aoz does not support this solution. aoz wanted the qosClass to be a parameter of the generator
00035     log(pyco.get("logger")),
00036     packetCounter(0),
00037     bitCounter(0)
00038 {
00039     startTrigger = NULL;
00040     stopTrigger = NULL;
00041     tcpService = NULL;
00042     connection = NULL;
00043     component = NULL;
00044 
00045     MESSAGE_BEGIN(NORMAL, log, m, "New TcpClientBinding created. Destination=");
00046     m << destinationDomainName << ":" << destinationPort;
00047     m << ", QoSClass="<<qosClass;
00048     MESSAGE_END();
00049 }
00050 
00051 TcpClientBinding::~TcpClientBinding()
00052 {
00053     MESSAGE_BEGIN(NORMAL, log, m, "Received a total of ");
00054     m << packetCounter << " packets with " << bitCounter << " bits";
00055     MESSAGE_END();
00056 }
00057 
00058 
00059 void TcpClientBinding::sendData(const wns::osi::PDUPtr& _data)
00060 {
00061     assure(connection, "No connection available.");
00062     //MESSAGE_SINGLE(NORMAL, log, "sendData to destination: " << destinationDomainName << ":" << destinationPort);
00063     MESSAGE_SINGLE(NORMAL, log, "sendData to destination: " << peerAddress << ":" << destinationPort);
00064     connection->sendData(_data);
00065 }
00066 
00067 void TcpClientBinding::registerComponent(wns::node::component::Component* _component)
00068 {
00069     component = _component;
00070     tcpService =
00071         component->getService<wns::service::tl::Service*>(pyco.get<std::string>("tcpService"));
00072     dns = component->getService<wns::service::nl::DNSService*>(pyco.get<std::string>("dnsService"));
00073 }
00074 
00075 void TcpClientBinding::onConnectionEstablished(wns::service::nl::Address, wns::service::tl::Connection* _connection)
00076 {
00077     connection = _connection;
00078     startTrigger->bindingReady();
00079     connection->registerDataHandler(this);
00080 }
00081 
00082 void TcpClientBinding::onData(const wns::osi::PDUPtr& _pdu)
00083 {
00084     assure(_pdu , "data is empty.");
00085     //assureType(_pdu.getPtr(), ConstanzePDU*);
00086     int bits = _pdu->getLengthInBits();
00087     packetCounter ++;
00088     bitCounter += bits;
00089 }
00090 
00091 void TcpClientBinding::initBinding(constanze::StartTrigger* _startTrigger)
00092 {
00093     startTrigger = _startTrigger;
00094     tcpService->openConnection( destinationPort, domainName, destinationDomainName, qosClass, this);
00095     assure(dns!=NULL,"dns needed");
00096     wns::service::nl::Address peerAddress = dns->lookup(destinationDomainName);
00097 }
00098 
00099 void TcpClientBinding::releaseBinding(constanze::StopTrigger* _stopTrigger)
00100 {
00101     stopTrigger = _stopTrigger;
00102     tcpService->closeConnection( connection );
00103     stopTrigger->bindingReady();
00104 }
00105 
00106 void TcpClientBinding::registerListener(constanze::Listener*)
00107 {
00108     // intentionally left empty
00109 }
00110 void TcpClientBinding::onConnectionClosed(wns::service::tl::Connection*)
00111 {
00112     // intentionally left empty
00113 }
00114 
00115 void TcpClientBinding::onConnectionClosedByPeer(wns::service::tl::Connection*)
00116 {
00117     // intentionally left empty
00118 }
00119 
00120 void TcpClientBinding::onConnectionLost(wns::service::tl::Connection*)
00121 {
00122     // intentionally left empty
00123 }
00124 
00125 std::string
00126 TcpClientBinding::printAddress() const
00127 {
00128     std::ostringstream tmp;
00129     //tmp << destinationDomainName << ":" << destinationPort;
00130     tmp << peerAddress << ":" << destinationPort;
00131     return tmp.str();
00132 }
00133 
00134 
00135 
00136 

Generated on Sat May 26 03:32:14 2012 for openWNS by  doxygen 1.5.5