PROTON-1481: [C++ binding] Rename proton::defer -> proton::schedule_work
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/8aee73b6 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/8aee73b6 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/8aee73b6 Branch: refs/heads/master Commit: 8aee73b611bd0faff3d065e1ed16f89d5c222b73 Parents: 1e2efdb Author: Andrew Stitcher <[email protected]> Authored: Fri May 19 17:02:05 2017 -0400 Committer: Andrew Stitcher <[email protected]> Committed: Fri Jul 21 12:50:06 2017 -0400 ---------------------------------------------------------------------- examples/cpp/broker.cpp | 24 ++++++------ examples/cpp/scheduled_send_03.cpp | 6 +-- .../bindings/cpp/include/proton/thread_safe.hpp | 2 +- .../bindings/cpp/include/proton/work_queue.hpp | 40 ++++++++++---------- 4 files changed, 36 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8aee73b6/examples/cpp/broker.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/broker.cpp b/examples/cpp/broker.cpp index 09a771c..2cb2b36 100644 --- a/examples/cpp/broker.cpp +++ b/examples/cpp/broker.cpp @@ -139,7 +139,7 @@ class Queue { DOUT(std::cerr << "(" << current_->second << ") ";); if (current_->second>0) { DOUT(std::cerr << current_->first << " ";); - proton::defer(current_->first, &Sender::sendMsg, current_->first, messages_.front()); + proton::schedule_work(current_->first, &Sender::sendMsg, current_->first, messages_.front()); messages_.pop_front(); --current_->second; ++current_; @@ -178,14 +178,14 @@ public: // If we're about to erase the current subscription move on if (current_ != subscriptions_.end() && current_->first==s) ++current_; subscriptions_.erase(s); - proton::defer(s, &Sender::unsubscribed, s); + proton::schedule_work(s, &Sender::unsubscribed, s); } }; // We have credit to send a message. void Sender::on_sendable(proton::sender &sender) { if (queue_) { - proton::defer(queue_, &Queue::flow, queue_, this, sender.credit()); + proton::schedule_work(queue_, &Queue::flow, queue_, this, sender.credit()); } else { pending_credit_ = sender.credit(); } @@ -193,7 +193,7 @@ void Sender::on_sendable(proton::sender &sender) { void Sender::on_sender_close(proton::sender &sender) { if (queue_) { - proton::defer(queue_, &Queue::unsubscribe, queue_, this); + proton::schedule_work(queue_, &Queue::unsubscribe, queue_, this); } else { // TODO: Is it possible to be closed before we get the queue allocated? // If so, we should have a way to mark the sender deleted, so we can delete @@ -207,12 +207,12 @@ void Sender::boundQueue(Queue* q, std::string qn) { queue_ = q; queue_name_ = qn; - proton::defer(q, &Queue::subscribe, q, this); + proton::schedule_work(q, &Queue::subscribe, q, this); sender_.open(proton::sender_options() .source((proton::source_options().address(queue_name_))) .handler(*this)); if (pending_credit_>0) { - proton::defer(queue_, &Queue::flow, queue_, this, pending_credit_); + proton::schedule_work(queue_, &Queue::flow, queue_, this, pending_credit_); } std::cout << "sending from " << queue_name_ << std::endl; } @@ -237,7 +237,7 @@ class Receiver : public proton::messaging_handler { void queueMsgs() { DOUT(std::cerr << "Receiver: " << this << " queueing " << messages_.size() << " msgs to: " << queue_ << "\n";); while (!messages_.empty()) { - proton::defer(queue_, &Queue::queueMsg, queue_, messages_.front()); + proton::schedule_work(queue_, &Queue::queueMsg, queue_, messages_.front()); messages_.pop_front(); } } @@ -295,7 +295,7 @@ public: } else { q = i->second; } - proton::defer(&connection, &T::boundQueue, &connection, q, qn); + proton::schedule_work(&connection, &T::boundQueue, &connection, q, qn); } void findQueueSender(Sender* s, std::string qn) { @@ -325,7 +325,7 @@ public: std::string qn = sender.source().dynamic() ? "" : sender.source().address(); Sender* s = new Sender(sender, senders_); senders_[sender] = s; - proton::defer(&queue_manager_, &QueueManager::findQueueSender, &queue_manager_, s, qn); + proton::schedule_work(&queue_manager_, &QueueManager::findQueueSender, &queue_manager_, s, qn); } // A receiver receives messages from a publisher to a queue. @@ -341,7 +341,7 @@ public: DOUT(std::cerr << "ODD - trying to attach to a empty address\n";); } Receiver* r = new Receiver(receiver); - proton::defer(&queue_manager_, &QueueManager::findQueueReceiver, &queue_manager_, r, qname); + proton::schedule_work(&queue_manager_, &QueueManager::findQueueReceiver, &queue_manager_, r, qname); } } @@ -352,7 +352,7 @@ public: if (j == senders_.end()) continue; Sender* s = j->second; if (s->queue_) { - proton::defer(s->queue_, &Queue::unsubscribe, s->queue_, s); + proton::schedule_work(s->queue_, &Queue::unsubscribe, s->queue_, s); } senders_.erase(j); } @@ -370,7 +370,7 @@ public: if (j == senders_.end()) continue; Sender* s = j->second; if (s->queue_) { - proton::defer(s->queue_, &Queue::unsubscribe, s->queue_, s); + proton::schedule_work(s->queue_, &Queue::unsubscribe, s->queue_, s); } } delete this; // All done. http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8aee73b6/examples/cpp/scheduled_send_03.cpp ---------------------------------------------------------------------- diff --git a/examples/cpp/scheduled_send_03.cpp b/examples/cpp/scheduled_send_03.cpp index 8ac46a1..008853c 100644 --- a/examples/cpp/scheduled_send_03.cpp +++ b/examples/cpp/scheduled_send_03.cpp @@ -62,8 +62,8 @@ class scheduled_sender : public proton::messaging_handler { void on_sender_open(proton::sender & s) OVERRIDE { work_queue = &s.work_queue(); - proton::defer(work_queue, timeout, &scheduled_sender::cancel, this, s); - proton::defer(work_queue, interval, &scheduled_sender::tick, this, s); + proton::schedule_work(work_queue, timeout, &scheduled_sender::cancel, this, s); + proton::schedule_work(work_queue, interval, &scheduled_sender::tick, this, s); } void cancel(proton::sender sender) { @@ -73,7 +73,7 @@ class scheduled_sender : public proton::messaging_handler { void tick(proton::sender sender) { if (!canceled) { - proton::defer(work_queue, interval, &scheduled_sender::tick, this, sender); // Next tick + proton::schedule_work(work_queue, interval, &scheduled_sender::tick, this, sender); // Next tick if (sender.credit() > 0) // Only send if we have credit send(sender); else http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8aee73b6/proton-c/bindings/cpp/include/proton/thread_safe.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/thread_safe.hpp b/proton-c/bindings/cpp/include/proton/thread_safe.hpp index 04e39df..0b38883 100644 --- a/proton-c/bindings/cpp/include/proton/thread_safe.hpp +++ b/proton-c/bindings/cpp/include/proton/thread_safe.hpp @@ -70,7 +70,7 @@ class thread_safe : private internal::pn_ptr_base, private internal::endpoint_tr ~thread_safe() { if (ptr()) { - if (!!work_queue().impl_) defer(&work_queue(), &decref, (void*)ptr()); + if (!!work_queue().impl_) schedule_work(&work_queue(), &decref, (void*)ptr()); else decref(ptr()); } } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8aee73b6/proton-c/bindings/cpp/include/proton/work_queue.hpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/include/proton/work_queue.hpp b/proton-c/bindings/cpp/include/proton/work_queue.hpp index 61567b8..844680b 100644 --- a/proton-c/bindings/cpp/include/proton/work_queue.hpp +++ b/proton-c/bindings/cpp/include/proton/work_queue.hpp @@ -284,76 +284,76 @@ void_function0& make_work(R (*f)(A, B, C), A a, B b, C c) { namespace { template <class T> -bool defer_helper(T t, void_function0& w) { +bool schedule_work_helper(T t, void_function0& w) { bool r = t->add(w); if (!r) delete &w; return r; } } -/// defer is a convenience that is used for C++03 code to defer function calls +/// schedule_work is a convenience that is used for C++03 code to defer function calls /// to a work_queue template <class WQ, class F> -bool defer(WQ wq, F f) { - return defer_helper(wq, make_work(f)); +bool schedule_work(WQ wq, F f) { + return schedule_work_helper(wq, make_work(f)); } template <class WQ, class F, class A> -bool defer(WQ wq, F f, A a) { - return defer_helper(wq, make_work(f, a)); +bool schedule_work(WQ wq, F f, A a) { + return schedule_work_helper(wq, make_work(f, a)); } template <class WQ, class F, class A, class B> -bool defer(WQ wq, F f, A a, B b) { - return defer_helper(wq, make_work(f, a, b)); +bool schedule_work(WQ wq, F f, A a, B b) { + return schedule_work_helper(wq, make_work(f, a, b)); } template <class WQ, class F, class A, class B, class C> -bool defer(WQ wq, F f, A a, B b, C c) { - return defer_helper(wq, make_work(f, a, b, c)); +bool schedule_work(WQ wq, F f, A a, B b, C c) { + return schedule_work_helper(wq, make_work(f, a, b, c)); } template <class WQ, class F, class A, class B, class C, class D> -bool defer(WQ wq, F f, A a, B b, C c, D d) { - return defer_helper(wq, make_work(f, a, b, c, d)); +bool schedule_work(WQ wq, F f, A a, B b, C c, D d) { + return schedule_work_helper(wq, make_work(f, a, b, c, d)); } template <class WQ, class F> -void defer(WQ wq, duration dn, F f) { +void schedule_work(WQ wq, duration dn, F f) { wq->schedule(dn, make_work(f)); } template <class WQ, class F, class A> -void defer(WQ wq, duration dn, F f, A a) { +void schedule_work(WQ wq, duration dn, F f, A a) { wq->schedule(dn, make_work(f, a)); } template <class WQ, class F, class A, class B> -void defer(WQ wq, duration dn, F f, A a, B b) { +void schedule_work(WQ wq, duration dn, F f, A a, B b) { wq->schedule(dn, make_work(f, a, b)); } template <class WQ, class F, class A, class B, class C> -void defer(WQ wq, duration dn, F f, A a, B b, C c) { +void schedule_work(WQ wq, duration dn, F f, A a, B b, C c) { wq->schedule(dn, make_work(f, a, b, c)); } template <class WQ, class F, class A, class B, class C, class D> -void defer(WQ wq, duration dn, F f, A a, B b, C c, D d) { +void schedule_work(WQ wq, duration dn, F f, A a, B b, C c, D d) { wq->schedule(dn, make_work(f, a, b, c, d)); } -/// This version of proton::defer defers calling a free function to an arbitrary work queue +/// This version of proton::schedule_work schedule_works calling a free function to an arbitrary work queue #else // The C++11 version is *much* simpler and even so more general! // These definitions encompass everything in the C++03 section template <class WQ, class... Rest> -bool defer(WQ wq, Rest&&... r) { +bool schedule_work(WQ wq, Rest&&... r) { return wq->add(std::bind(std::forward<Rest>(r)...)); } template <class WQ, class... Rest> -void defer(WQ wq, duration d, Rest&&... r) { +void schedule_work(WQ wq, duration d, Rest&&... r) { wq->schedule(d, std::bind(std::forward<Rest>(r)...)); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
