prefix_ void senf::ppi::connector::Connector::connect(Connector & target)
{
// The connector is not registered -> route() or noroute() statement missing
- SENF_ASSERT( module_ &&
+ SENF_ASSERT( module_,
"senf::ppi::connector::Connector::connect(): (source) "
"Missing route() or noroute()" );
// The connector is already connected
- SENF_ASSERT( ! peer_ &&
+ SENF_ASSERT( ! peer_,
"senf::ppi::connector::Connector::connect(): (source) "
"duplicate connection" );
// The target connector is not registered -> route() or noroute() statement missing
- SENF_ASSERT( target.module_ &&
+ SENF_ASSERT( target.module_,
"senf::ppi::connector::Connector::connect(): (target) "
"Missing route() or noroute()" );
// The target connector is already connected
- SENF_ASSERT( ! target.peer_ &&
+ SENF_ASSERT( ! target.peer_,
"senf::ppi::connector::Connector::connect(): (target) "
"duplicate connection" );
if (! (packetTypeID() == typeid(void) ||
prefix_ void senf::ppi::connector::Connector::disconnect()
{
// Cannot disconnected a non-connected connector
- SENF_ASSERT( peer_ &&
+ SENF_ASSERT( peer_,
"senf::ppi::connector::Connector::disconnect(): Not connected" );
Connector & peer (*peer_);
const
{
// The connector is not connected
- SENF_ASSERT(peer_ && "senf::ppi::connect() call missing");
+ SENF_ASSERT(peer_, "senf::ppi::connect() call missing");
return *peer_;
}
{
// The connector is not registered in the module -> probably a route() or noroute() statement is
// missing.
- SENF_ASSERT(module_ && "Connector not registered: Missing route() or noroute()");
+ SENF_ASSERT(module_, "Connector not registered: Missing route() or noroute()");
return *module_;
}
prefix_ void senf::ppi::connector::PassiveConnector::emit()
{
// No event callback has been registered (onRequest() call missing)
- SENF_ASSERT(callback_ && "senf::ppi::connector::PassiveConnector: missing onRequest()");
+ SENF_ASSERT(callback_, "senf::ppi::connector::PassiveConnector: missing onRequest()");
if (!throttled())
callback_();
else
const
{
// Cannot peek() head of empty queue
- SENF_ASSERT( ! queue_.empty() &&
+ SENF_ASSERT( ! queue_.empty(),
"senf::ppi::connector::InputConnector: cannot call peek() on empty queue" );
return queue_.back();
}
prefix_ void senf::ppi::module::debug::PassiveSource::request()
{
- SENF_ASSERT( ! packets_.empty() &&
+ SENF_ASSERT( ! packets_.empty(),
"senf::ppi::module::debug::PassiveSource::request(): "
"Requesting packet from empty source." );
output(packets_.front());
SENF_ASSERT(
std::find_if(registrations_.begin(), registrations_.end(),
l::bind(&detail::EventBindingBase::descriptor_,_1) == &event)
- == registrations_.end());
+ == registrations_.end(),
+ "Internal failure: registrations still active while destroying event ??");
}
///////////////////////////////cc.e////////////////////////////////////////
prefix_ void senf::ppi::EventDescriptor::enabled(bool v)
{
- SENF_ASSERT(v_isRegistered() && "Module::registerEvent() call missing");
+ SENF_ASSERT(v_isRegistered(), "Module::registerEvent() call missing");
if (throttled_ && v)
return;
if (v && ! enabled_)
prefix_ senf::ppi::detail::EventBinding<EventType> &
senf::ppi::EventImplementationHelper<EventType,Self>::binding()
{
- SENF_ASSERT( static_cast<Self*>(this)->binding_ &&
+ SENF_ASSERT( static_cast<Self*>(this)->binding_,
"senf::ppi::EventImplementationHelper::binding(): Missing registerEvent()" );
return * static_cast<Self*>(this)->binding_;
}
prefix_ senf::ppi::detail::EventBinding<void> &
senf::ppi::EventImplementationHelper<void,Self>::binding()
{
- SENF_ASSERT( static_cast<Self*>(this)->binding_ &&
+ SENF_ASSERT( static_cast<Self*>(this)->binding_,
"senf::ppi::EventImplementationHelper::binding(): Missing registerEvent()" );
return * static_cast<Self*>(this)->binding_;
}
else if (event & Hup)
throw HangupException();
else
- SENF_ASSERT(false && "Internal failure in senf::ppi::IOEvent::cb(int)");
+ SENF_ASSERT(false, "Internal failure: IOEvent::cb() called with invalid flag??");
} else {
IOEventInfo info = { event };
callback(info);
prefix_ senf::ppi::module::Module::~Module()
{
- SENF_ASSERT(connectorRegistry_.empty());
- SENF_ASSERT(routes_.empty());
+ SENF_ASSERT(connectorRegistry_.empty(),
+ "Internal failure: connectors still registered in Module destructor ??");
+ SENF_ASSERT(routes_.empty(),
+ "internal failure: routes still registered in Module destructor ??");
moduleManager().unregisterModule(*this);
}
}
private:
void request() {
- SENF_ASSERT(input());
+ SENF_ASSERT(input(), "TestSink called without packet");
}
};
}
const
{
// Access out of range element
- SENF_ASSERT( i>=0 && i < difference_type(elements) );
+ SENF_ASSERT( i>=0 && i < difference_type(elements), "Access to out-of-range array element" );
return begin()[i];
}
while (i!=e) {
ElementParser p (i,selfp.state());
size_type sz (senf::bytes(p));
- SENF_ASSERT(sz);
+ SENF_ASSERT(sz, "Broken element parser: reports size of 0 bytes");
i = p.i(sz);
++ n_;
}
for (; d.n_; --d.n_, j += ElementParser(j,c.state()).bytes())
if (j==p)
return;
- SENF_ASSERT( false );
+ SENF_ASSERT( false, "setFromPosition: position does not point to any list element" );
}
template <class ElementParser, class AuxPolicy>
senf::ListParser<ListPolicy>::back()
const
{
- SENF_ASSERT( ! empty() );
+ SENF_ASSERT( ! empty(), "back() called on empty list" );
container c(*this);
typename container::iterator i (c.begin()), j;
typename container::iterator const e (c.end());
senf::ListParser_Container<ListPolicy>::back()
const
{
- SENF_ASSERT( ! empty() );
+ SENF_ASSERT( ! empty(), "back() called on empty list" );
iterator i (begin()), j;
iterator const e (end());
for (j=i; i!=e; j=i, ++i) ;
senf::ListParser<ListPolicy>::front()
const
{
- SENF_ASSERT( ! empty() );
+ SENF_ASSERT( ! empty(), "front() called on empty list" );
container c(*this);
return *(c.begin());
}
senf::ListParser_Container<ListPolicy>::front()
const
{
- SENF_ASSERT( ! empty() );
+ SENF_ASSERT( ! empty(), "front() called on empty list" );
return *begin();
}
prefix_ senf::PacketInterpreterBase::ptr senf::Packet::ptr()
const
{
- SENF_ASSERT(packet_);
+ SENF_ASSERT(packet_, "Invalid operation (dereferencing) on in-valid() Packet");
return packet_;
}
prefix_ senf::detail::PacketImpl & senf::PacketData::impl()
const
{
- SENF_ASSERT( impl_ );
+ SENF_ASSERT(
+ impl_,
+ "Internal failure: PacketData (PacketInterpreter) instance not part of any Packet?");
return *impl_;
}
prefix_ senf::PacketData::iterator senf::PacketData::begin()
const
{
- SENF_ASSERT(begin_ <= impl().size());
+ SENF_ASSERT(begin_ <= impl().size(),
+ "Internal failure: PacketInterpreter range outside of data container");
return boost::next(impl().begin(),begin_);
}
prefix_ senf::PacketData::iterator senf::PacketData::end()
const
{
- SENF_ASSERT(end_ <= impl().size());
+ SENF_ASSERT(end_ <= impl().size(),
+ "Internal failure: PacketInterpreter range outside of data container");
return boost::next(impl().begin(),end_);
}
prefix_ senf::PacketData::byte senf::PacketData::operator[](size_type n)
const
{
- SENF_ASSERT( n < size() );
+ SENF_ASSERT( n < size(), "Access out of container range" );
return *( boost::next(begin(),n) );
}
prefix_ senf::PacketData::byte & senf::PacketData::operator[](size_type n)
{
- SENF_ASSERT( n < size() );
+ SENF_ASSERT( n < size(), "Access out of container range" );
return *( boost::next(begin(),n) );
}
prefix_ void senf::detail::PacketImpl::release(refcount_t n)
{
- SENF_ASSERT(refcount_ >= n);
+ SENF_ASSERT(refcount_ >= n, "Internal failure: Releasing dead PacketImpl ??");
// uah ... we need to be extremely careful here. If refcount_ is n, we want to commit suicide,
// however the destructor will remove all PacketInterpreters from the list and will thereby
// decrement refcount -> only decrenebt refcount_ when *not* caling delete
prefix_ void senf::PacketInterpreterBase::assignImpl(detail::PacketImpl * impl)
{
- SENF_ASSERT(!impl_);
+ SENF_ASSERT(!impl_, "Internal failure: PacketInterpreter added to two Packets");
impl_ = impl;
impl_->add_ref(refcount());
}
prefix_ void senf::PacketInterpreterBase::releaseImpl()
{
- SENF_ASSERT(impl_);
+ SENF_ASSERT(impl_, "Internal failure: release of lone PacketInterpreter");
refcount_t refc (refcount());
if (refc) {
impl_->release(refc);
template <class PacketType>
prefix_ void senf::detail::PacketRegistryImpl<KeyType>::registerPacket(key_t key, int priority)
{
- bool ok (registry_.insert(
- typename Entry::ptr(new EntryImpl<PacketType>(key,priority))).second);
- SENF_ASSERT(ok && "Duplicate packet registration");
+ SENF_ASSERT_EXPRESSION(
+ registry_.insert(
+ typename Entry::ptr(new EntryImpl<PacketType>(key,priority))).second,
+ "Duplicate packet registration");
}
template <class KeyType>
prefix_ senf::PacketData::iterator senf::safe_data_iterator::i()
const
{
- SENF_ASSERT(data_);
+ SENF_ASSERT(data_, "Use/dereferencing of empty safe_data_iterator");
return boost::next(data_->begin(),i_);
}
prefix_ senf::safe_data_iterator & senf::safe_data_iterator::operator=(PacketData::iterator i)
{
- SENF_ASSERT(data_);
+ SENF_ASSERT(data_, "Use/dereferencing of empty safe_data_iterator");
i_ = std::distance(data_->begin(),i);
return *this;
}
prefix_ senf::PacketData & senf::safe_data_iterator::data()
const
{
- SENF_ASSERT(data_);
+ SENF_ASSERT(data_, "Use/dereferencing of empty safe_data_iterator");
return *data_;
}
prefix_ bool senf::safe_data_iterator::equal(safe_data_iterator const & other)
const
{
- SENF_ASSERT(data_ == other.data_);
+ SENF_ASSERT(data_ == other.data_, "Comparing iterators of two different containers is invalid");
return i_ == other.i_;
}
senf::safe_data_iterator::distance_to(safe_data_iterator const & other)
const
{
- SENF_ASSERT(data_ == other.data_);
+ SENF_ASSERT(data_ == other.data_, "Comparing iterators of two different containers is invalid");
return other.i_ - i_;
}
prefix_ void senf::safe_data_iterator::decrement()
{
- SENF_ASSERT(i_>0);
+ SENF_ASSERT(i_>0, "Decrementing iterator before beginning of container" );
--i_;
}
prefix_ void senf::safe_data_iterator::advance(difference_type n)
{
- SENF_ASSERT( -n < difference_type(i_) );
+ SENF_ASSERT( -n < difference_type(i_), "Moving iterator to before beginning of container" );
i_ += n;
}
prefix_ Parser & senf::SafePacketParserWrapper<Parser>::operator*()
const
{
- SENF_ASSERT( i_ );
+ SENF_ASSERT( i_, "Dereferencing empty SafePacketParserWrapper" );
parser_->i_ = PacketParserBase::data_iterator(i_);
return *parser_;
}
prefix_ Parser * senf::SafePacketParserWrapper<Parser>::operator->()
const
{
- SENF_ASSERT( i_ );
+ SENF_ASSERT( i_, "Dereferencing empty SafePacketParserWrapper" );
parser_->i_ = PacketParserBase::data_iterator(i_);
return & (*parser_);
}
senf::VariantParser<AuxPolicy,Parsers>::get()
const
{
- SENF_ASSERT( variant() == N );
+ SENF_ASSERT( variant() == N, "Access to non-active variant member" );
return typename boost::mpl::at<parsers, boost::mpl::int_<N> >::type(
AuxPolicy::adjust(i(), state()), state() );
}
scale = *match.first;
unit = *boost::next(match.first);
} else {
- SENF_ASSERT( match.length() == 1);
+ SENF_ASSERT( match.length() == 1,
+ "Internal failure: RegEx match returns weird number of matches" );
unit = *match.first;
}
switch (scale) {
i->setRunnable();
}
-prefix_ void senf::scheduler::detail::SignalDispatcher::sigHandler(int signal, ::siginfo_t * siginfo,
- void *)
+prefix_ void senf::scheduler::detail::SignalDispatcher::sigHandler(int signal,
+ ::siginfo_t * siginfo,
+ void *)
{
- SENF_ASSERT( alive() );
+ SENF_ASSERT( alive(), "Internal failure: Destroyed signal handler called" );
// The manpage says, si_signo is unused in linux so we set it here
siginfo->si_signo = signal;
// We can't do much on error anyway so we ignore errors here
prefix_ senf::FileBody & senf::FileHandle::body()
{
- SENF_ASSERT(body_);
+ SENF_ASSERT(body_, "dereferencing in-valid() FileHandle");
return *body_;
}
prefix_ senf::FileBody const & senf::FileHandle::body()
const
{
- SENF_ASSERT(body_);
+ SENF_ASSERT(body_, "dereferencing in-valid() FileHandle");
return *body_;
}
this->protocol().init_client();
}
-#define BOOST_PP_ITERATION_PARAMS_1 (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolClientSocketHandle.mpp), 2))
+#define BOOST_PP_ITERATION_PARAMS_1 \
+ (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolClientSocketHandle.mpp), 2))
#include BOOST_PP_ITERATE()
template <class SocketProtocol>
prefix_ SocketProtocol &
senf::ProtocolClientSocketHandle<SocketProtocol>::protocol()
{
- SENF_ASSERT( dynamic_cast<SocketProtocol *>(&this->body().protocol()) );
+ SENF_ASSERT( dynamic_cast<SocketProtocol *>(&this->body().protocol()),
+ "Internal failure: Incompatible protocol class fount it's way into this handle");
// Need dynamic_cast here, since senf::SocketProtocol is a
// virtual base
return dynamic_cast<SocketProtocol &>(this->body().protocol());
std::auto_ptr<senf::SocketBody>(new ProtocolSocketBody<SocketProtocol>(true)))
{}
-#define BOOST_PP_ITERATION_PARAMS_1 (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolServerSocketHandle.mpp), 2))
+#define BOOST_PP_ITERATION_PARAMS_1 \
+ (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolServerSocketHandle.mpp), 2))
#include BOOST_PP_ITERATE()
template <class SocketProtocol>
prefix_ SocketProtocol &
senf::ProtocolServerSocketHandle<SocketProtocol>::protocol()
{
- SENF_ASSERT( dynamic_cast<SocketProtocol const *>(&this->body().protocol()) );
+ SENF_ASSERT( dynamic_cast<SocketProtocol const *>(&this->body().protocol()),
+ "Internal failure: Incompatible protocol class fount it's way into this handle");
// Need dynamic_cast here, since senf::SocketProtocol is a
// virtual base
return dynamic_cast<SocketProtocol &>(this->body().protocol());
if (sockaddr_.sin6_scope_id == 0)
return "";
char buffer[IFNAMSIZ];
-#ifdef SENF_DEBUG
- SENF_ASSERT( if_indextoname(sockaddr_.sin6_scope_id,buffer) );
-#else
- if_indextoname(sockaddr_.sin6_scope_id,buffer);
-#endif
+ SENF_ASSERT_EXPRESSION(if_indextoname(sockaddr_.sin6_scope_id,buffer),
+ "Internal failure: Invalid interface index (how does it get here?)");
return std::string(buffer);
}
template <class SPolicy>
template <class OtherPolicy>
prefix_ senf::SocketHandle<SPolicy>::SocketHandle(SocketHandle<OtherPolicy> other,
- typename IsCompatible<OtherPolicy>::type *)
+ typename IsCompatible<OtherPolicy>::type *)
: FileHandle(other)
{}
prefix_ senf::SocketHandle<SPolicy>::SocketHandle(FileHandle other, bool isChecked)
: FileHandle(other)
{
- SENF_ASSERT( isChecked );
- SENF_ASSERT( ! valid() || dynamic_cast<SocketBody *>(&FileHandle::body()) );
+ SENF_ASSERT( isChecked, "Inrernal failure: Wrong overload called !!" );
+ SENF_ASSERT( ! valid() || dynamic_cast<SocketBody *>(&FileHandle::body()),
+ "Internal failure: Replacing or re-assigning non-empty incompatible handle");
}
template <class SPolicy>
prefix_ senf::SocketBody & senf::SocketHandle<SPolicy>::body()
{
- SENF_ASSERT( dynamic_cast<SocketBody *>(&FileHandle::body()) );
+ SENF_ASSERT( dynamic_cast<SocketBody *>(&FileHandle::body()),
+ "Internal failure: Invalid body found it's way into SocketHandle");
return static_cast<SocketBody &>(FileHandle::body());
}
prefix_ senf::SocketBody const & senf::SocketHandle<SPolicy>::body()
const
{
- SENF_ASSERT( dynamic_cast<SocketBody const *>(&FileHandle::body()) );
+ SENF_ASSERT( dynamic_cast<SocketBody const *>(&FileHandle::body()),
+ "Internal failure: Invalid body found it's way into SocketHandle");
return static_cast<SocketBody const &>(FileHandle::body());
}
boost::is_convertible<Target*,FileHandle*>::value &&
( boost::is_convertible<Source,Target>::value ||
boost::is_convertible<Target,Source>::value ) ));
- SENF_ASSERT( check_socket_cast<Target>(handle) );
+ SENF_ASSERT( check_socket_cast<Target>(handle),
+ "Invalid static_socket_cast" );
return Target::cast_static(handle);
}
prefix_ void senf::SocketProtocol::fd(int fd)
const
{
- SENF_ASSERT(! body().valid());
+ SENF_ASSERT(! body().valid(), "Replacing filedescriptor of open FileHandle");
body().fd(fd);
}
prefix_ senf::console::DirectoryNode & senf::console::Executor::cwd()
const
{
- SENF_ASSERT( ! cwd_.empty() );
+ SENF_ASSERT( ! cwd_.empty(), "Internal error: CWD history empty ?" );
while (cwd_.size()>1 && (cwd_.back().expired() || ! cwd_.back().lock()->active()))
cwd_.pop_back();
return * cwd_.back().lock();
prefix_ NodeType & senf::console::DirectoryNode::add(std::string const & name,
boost::shared_ptr<NodeType> node)
{
- SENF_ASSERT( ! node->parent() );
+ SENF_ASSERT( ! node->parent(), "Node can only be added to tree once" );
node->name(name);
add(node);
return *node;
prefix_ senf::console::OverloadedCommandNode & senf::console::CommandOverload::node()
const
{
- SENF_ASSERT( node_ );
+ SENF_ASSERT( node_, "Overload not added to any node yet" );
return *node_;
}
throwParserError(ex);
}
// Otherwise the error handling in the parser is broken
- SENF_ASSERT( result.hit );
+ SENF_ASSERT( result.hit, "Internal parser failure (error handling broken?)" );
if (! info.empty())
try {
cb(info);
prefix_ senf::console::CommandParser::Impl & senf::console::CommandParser::impl()
{
- SENF_ASSERT(impl_);
+ SENF_ASSERT(impl_, "Ineral error: PIMPL pointer NULL ??");
return *impl_;
}
prefix_ senf::console::ScopedDirectory<Owner>::ScopedDirectory(Owner * owner)
: owner_ (owner)
{
- SENF_ASSERT(owner_);
+ SENF_ASSERT(owner_, "ScopedDirectory owner is mandatory");
}
template <class Owner>
prefix_ std::string senf::console::detail::formatEnum(EnumTable const & table, long value)
{
EnumTable::right_map::const_iterator i (table.right.find(value));
- SENF_ASSERT( i != table.right.end() );
+ SENF_ASSERT( i != table.right.end(), "Invalid enum value" );
return i->second;
}
prefix_ senf::console::UDPServer &
senf::console::UDPServer::replies(senf::INet4SocketAddress const & address)
{
- SENF_ASSERT( handle_.local().family() == senf::INet4SocketAddress::addressFamily );
+ SENF_ASSERT( handle_.local().family() == senf::INet4SocketAddress::addressFamily,
+ "Internal failure: INet6 address on INet4 socket ??" );
target_ = address;
return *this;
}
prefix_ senf::console::UDPServer &
senf::console::UDPServer::replies(senf::INet6SocketAddress const & address)
{
- SENF_ASSERT( handle_.local().family() == senf::INet6SocketAddress::addressFamily );
+ SENF_ASSERT( handle_.local().family() == senf::INet6SocketAddress::addressFamily,
+ "Internal failure: INet4 address on INet6 socket ??" );
target_ = address;
return *this;
}
requestTimeout_ (ClockService::milliseconds(DEFAULT_REQUEST_TIMEOUT_MS)),
timeout_ ("senf::term::BaseTelnetProtocol::timeout", 0)
{
- SENF_ASSERT( false );
+ SENF_ASSERT( false,
+ "Missing BaseTelnetProtocol constructor call in derived class "
+ "(BaseTelnetProtocol is a VIRTUAL base and MUST be constructed explicitly "
+ "in the most derived class." );
}
prefix_ void senf::term::BaseTelnetProtocol::write(std::string const & s)
prefix_ std::type_info const & senf::TypeIdValue::id()
const
{
- SENF_ASSERT(p_);
+ SENF_ASSERT(
+ p_, "Internal failure: Empty TypeIdValue should have p_ point to typeid(void) not 0");
return *p_;
}
prefix_ bool senf::intrusive_refcount_base::release()
{
- SENF_ASSERT(refcount_>0 &&
+ SENF_ASSERT(refcount_>0,
"senf::intrusive_refcount_base: Internal inconsistency: "
"Calling release on dead object.");
return --refcount_ == 0;
{
// When deriving from Self you may not change the class's size without
// inheriting from pool_alloc_mixin again. See pool_alloc_mixin documentation.
- SENF_ASSERT( size <= sizeof(Self) &&
+ SENF_ASSERT( size <= sizeof(Self),
"senf::pool_alloc_mixin::operator new(): "
"Bad object size. Missing pool_alloc_mixin base in derived class?" );
#ifdef SENF_DEBUG
#ifndef SENF_DEBUG
-# define SENF_ASSERT(x)
+# define SENF_ASSERT(x, comment)
+# define SENF_ASSERT_EXPRESSION(expression, comment) expression
#else
# include <cassert>
-# define SENF_ASSERT(x) assert(x)
+# define SENF_ASSERT(x, comment) assert((x) && comment)
+# define SENF_ASSERT_EXPRESSION(expression, comment) assert((expression) && comment)
#endif