From 4dc5c356469c6c1759c8aefb9486319e7e26ca31 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Sat, 16 Sep 2017 18:01:30 +0200 Subject: traffic-control: Use lambdas to make MacOS linker happy diff --git a/src/traffic-control/model/queue-disc.cc b/src/traffic-control/model/queue-disc.cc index f025d8e14..f234fc9f9 100644 --- a/src/traffic-control/model/queue-disc.cc +++ b/src/traffic-control/model/queue-disc.cc @@ -330,50 +330,36 @@ QueueDisc::QueueDisc () { NS_LOG_FUNCTION (this); - using namespace std::placeholders; - - // Remove ambiguity for overloaded member functions - typedef std::basic_string& (std::basic_string::*Function) (const char*); - - Function append = &std::basic_string::append, - assign = &std::basic_string::assign; - - // The operator() of these function objects calls the QueueDisc::DropBeforeEnqueue - // and QueueDisc::DropAfterDequeue methods of this QueueDisc object (these function - // objects are bound to this QueueDisc object), which require two arguments: a - // Ptr and a const char*. Given that a callback to the operator() - // is connected to the DropBeforeEnqueue and DropAfterDequeue traces of the Queue - // class, the first argument is provided by such traces, while the second argument - // (the reason why the packet was dropped) is bound to the INTERNAL_QUEUE_DROP constant. - m_internalQueueDbeFunctor = std::bind (&QueueDisc::DropBeforeEnqueue, this, - _1, (const char*)INTERNAL_QUEUE_DROP); - m_internalQueueDadFunctor = std::bind (&QueueDisc::DropAfterDequeue, this, - _1, (const char*)INTERNAL_QUEUE_DROP); - - // The operator() of these function objects calls the QueueDisc::DropBeforeEnqueue - // and QueueDisc::DropAfterDequeue methods of this QueueDisc object (these function - // objects are bound to this QueueDisc object), which require two arguments: a - // Ptr and a const char*. Given that a callback to the operator() - // is connected to the DropBeforeEnqueue and DropAfterDequeue traces of the QueueDisc - // class, both arguments are provided by such traces. The first argument is provided - // as is, while the second argument (the reason why the packet was dropped) is obtained - // by calling m_childQueueDiscDropMsg.assign (CHILD_QUEUE_DISC_DROP).append (_2).data () - // i.e., the second argument is the concatenation of the CHILD_QUEUE_DISC_DROP constant - // and the second argument provided by the traces of the QueueDisc class. - m_childQueueDiscDbeFunctor = std::bind (&QueueDisc::DropBeforeEnqueue, this, _1, - std::bind (&std::basic_string::data, - std::bind (append, - std::bind (assign, - &m_childQueueDiscDropMsg, - (const char*)CHILD_QUEUE_DISC_DROP), - _2))); - m_childQueueDiscDadFunctor = std::bind (&QueueDisc::DropAfterDequeue, this, _1, - std::bind (&std::basic_string::data, - std::bind (append, - std::bind (assign, - &m_childQueueDiscDropMsg, - (const char*)CHILD_QUEUE_DISC_DROP), - _2))); + // These lambdas call the DropBeforeEnqueue or DropAfterDequeue methods of this + // QueueDisc object. Given that a callback to the operator() of these lambdas + // is connected to the DropBeforeEnqueue and DropAfterDequeue traces of the + // internal queues, the INTERNAL_QUEUE_DROP constant is passed as the reason + // why the packet is dropped. + m_internalQueueDbeFunctor = [this] (Ptr item) + { + return DropBeforeEnqueue (item, INTERNAL_QUEUE_DROP); + }; + m_internalQueueDadFunctor = [this] (Ptr item) + { + return DropAfterDequeue (item, INTERNAL_QUEUE_DROP); + }; + + // These lambdas call the DropBeforeEnqueue or DropAfterDequeue methods of this + // QueueDisc object. Given that a callback to the operator() of these lambdas + // is connected to the DropBeforeEnqueue and DropAfterDequeue traces of the + // child queue discs, the concatenation of the CHILD_QUEUE_DISC_DROP constant + // and the second argument provided by such traces is passed as the reason why + // the packet is dropped. + m_childQueueDiscDbeFunctor = [this] (Ptr item, const char* r) + { + return DropBeforeEnqueue (item, + m_childQueueDiscDropMsg.assign (CHILD_QUEUE_DISC_DROP).append (r).data ()); + }; + m_childQueueDiscDadFunctor = [this] (Ptr item, const char* r) + { + return DropAfterDequeue (item, + m_childQueueDiscDropMsg.assign (CHILD_QUEUE_DISC_DROP).append (r).data ()); + }; } QueueDisc::~QueueDisc () diff --git a/src/traffic-control/model/queue-disc.h b/src/traffic-control/model/queue-disc.h index 4aad70b30..08aa756aa 100644 --- a/src/traffic-control/model/queue-disc.h +++ b/src/traffic-control/model/queue-disc.h @@ -142,8 +142,8 @@ private: * the sojourn time of every packet dequeued from a queue disc, including packets * that are dropped or requeued after being dequeued. The sojourn time is taken * when the packet is dequeued from the queue disc, hence it does not account for - * the additional time the packet is retained within the queue disc in case it is - * requeued. + * the additional time the packet is retained within the traffic control + * infrastructure in case it is requeued. * * The design and implementation of this class is heavily inspired by Linux. * For more details, see the traffic-control model page. -- 2.11.0 (Apple Git-81)