//*****************************************************************************
// RCF - Remote Call Framework
// Copyright (c) 2005. All rights reserved.
// Developed by Jarl Lindrud.
// Contact: jlindrud@hotmail.com .
//*****************************************************************************
#include <RCF/MulticastClientTransport.hpp>
#include <RCF/Exception.hpp>
#include <RCF/Tools.hpp>
namespace RCF {
struct sharedPtrIsNull
{
template<typename T>
bool operator()(boost::shared_ptr<T> spt)
{
return spt.get() == NULL;
}
};
std::auto_ptr<I_ClientTransport> MulticastClientTransport::clone() const
{
RCF_THROW( ClientTransportException, "clone() not supported for MulticastClientTransport" );
}
EndpointPtr MulticastClientTransport::getEndpointPtr() const
{
RCF_THROW( ClientTransportException, "getEndpointPtr() not supported for MulticastClientTransport" );
}
int MulticastClientTransport::send(const std::string &data, unsigned int timeoutMs)
{
timeoutMs = 1000; // for now, allow each sub transport a max of 1s to send the data
bool needToRemove = false;
for (ClientTransportPtrList::iterator it = mClientTransports.begin(); it != mClientTransports.end(); ++it)
{
try
{
if ((*it)->isConnected())
{
(*it)->send(data, timeoutMs);
}
else
{
needToRemove = true;
(*it).reset();
}
}
catch(const Exception &e)
{
RCF_TRACE("")(e);
needToRemove = true;
(*it).reset();
}
}
if (needToRemove)
{
mClientTransports.remove_if( sharedPtrIsNull() );
}
return 1;
}
int MulticastClientTransport::receive(std::string &, unsigned int)
{
RCF_THROW( ClientTransportException, "receive() not supported for MulticastClientTransport" );
}
bool MulticastClientTransport::isConnected()
{
return true;
}
void MulticastClientTransport::addTransport(boost::shared_ptr<I_ClientTransport> clientTransportPtr)
{
mClientTransports.push_back(clientTransportPtr);
}
void MulticastClientTransport::setTransportFilters(const std::vector<FilterPtr> &)
{
// not supported
}
} // namespace RCF