Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 08C9F200B54 for ; Wed, 13 Jul 2016 11:54:50 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 07B42160A57; Wed, 13 Jul 2016 09:54:50 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 68F1B160A8A for ; Wed, 13 Jul 2016 11:54:47 +0200 (CEST) Received: (qmail 61891 invoked by uid 500); 13 Jul 2016 09:54:46 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 61576 invoked by uid 99); 13 Jul 2016 09:54:46 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Jul 2016 09:54:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 446E4ED317; Wed, 13 Jul 2016 09:54:46 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jross@apache.org To: commits@qpid.apache.org Date: Wed, 13 Jul 2016 09:54:52 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [07/26] qpid-site git commit: QPID-7350: Examples that should have gone with the previous commit archived-at: Wed, 13 Jul 2016 09:54:50 -0000 http://git-wip-us.apache.org/repos/asf/qpid-site/blob/75ca8b14/input/releases/qpid-proton-0.13.0/proton/cpp/examples/options.hpp.html.in ---------------------------------------------------------------------- diff --git a/input/releases/qpid-proton-0.13.0/proton/cpp/examples/options.hpp.html.in b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/options.hpp.html.in new file mode 100644 index 0000000..bf35557 --- /dev/null +++ b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/options.hpp.html.in @@ -0,0 +1,161 @@ + +

options.hpp

+
#ifndef OPTIONS_HPP
+#define OPTIONS_HPP
+
+
+#include <string>
+#include <sstream>
+#include <ostream>
+#include <vector>
+#include <stdexcept>
+
+namespace example {
+
+struct bad_option : public std::runtime_error {
+    bad_option(const std::string& s) : std::runtime_error(s) {}
+};
+
+
+class options {
+  public:
+
+    options(int argc, char const * const * argv) : argc_(argc), argv_(argv), prog_(argv[0]), help_() {
+        size_t slash = prog_.find_last_of("/\\");
+        if (slash != std::string::npos)
+            prog_ = prog_.substr(slash+1); // Extract prog name from path
+        add_flag(help_, 'h', "help", "Print the help message");
+    }
+
+    ~options() {
+        for (opts::iterator i = opts_.begin(); i != opts_.end(); ++i)
+            delete *i;
+    }
+
+    
+    template<class T>
+    void add_value(T& value, char short_name, const std::string& long_name, const std::string& description, const std::string var) {
+        opts_.push_back(new option_value<T>(value, short_name, long_name, description, var));
+    }
+
+    
+    void add_flag(bool& flag, char short_name, const std::string& long_name, const std::string& description) {
+        opts_.push_back(new option_flag(flag, short_name, long_name, description));
+    }
+
+    
+    int parse() {
+        int arg = 1;
+        for (; arg < argc_ && argv_[arg][0] == '-'; ++arg) {
+            opts::iterator i = opts_.begin();
+            while (i != opts_.end() && !(*i)->parse(argc_, argv_, arg))
+                ++i;
+            if (i == opts_.end())
+                throw bad_option(std::string("unknown option ") + argv_[arg]);
+        }
+        if (help_) throw bad_option("");
+        return arg;
+    }
+
+    
+  friend std::ostream& operator<<(std::ostream& os, const options& op) {
+      os << std::endl << "usage: " << op.prog_ << " [options]" << std::endl;
+      os << std::endl << "options:" << std::endl;
+      for (opts::const_iterator i = op.opts_.begin(); i < op.opts_.end(); ++i)
+          os << **i << std::endl;
+      return os;
+  }
+
+ private:
+    class option {
+      public:
+        option(char s, const std::string& l, const std::string& d, const std::string v) :
+            short_(std::string("-") + s), long_("--" + l), desc_(d), var_(v) {}
+        virtual ~option() {}
+
+        virtual bool parse(int argc, char const * const * argv, int &i) = 0;
+        virtual void print_default(std::ostream&) const {}
+
+      friend std::ostream& operator<<(std::ostream& os, const option& op) {
+          os << "  " << op.short_;
+          if (!op.var_.empty()) os << " " << op.var_;
+          os << ", " << op.long_;
+          if (!op.var_.empty()) os << "=" << op.var_;
+          os << std::endl << "        " << op.desc_;
+          op.print_default(os);
+          return os;
+      }
+
+      protected:
+        std::string short_, long_, desc_, var_;
+    };
+
+    template <class T>
+    class option_value : public option {
+      public:
+        option_value(T& value, char s, const std::string& l, const std::string& d, const std::string& v) :
+            option(s, l, d, v), value_(value) {}
+
+        bool parse(int argc, char const * const * argv, int &i) {
+            std::string arg(argv[i]);
+            if (arg == short_ || arg == long_) {
+                if (i < argc-1) {
+                    set_value(arg, argv[++i]);
+                    return true;
+                } else {
+                    throw bad_option("missing value for " + arg);
+                }
+            }
+            if (arg.compare(0, long_.size(), long_) == 0 && arg[long_.size()] == '=' ) {
+                set_value(long_, arg.substr(long_.size()+1));
+                return true;
+            }
+            return false;
+        }
+
+        virtual void print_default(std::ostream& os) const { os << " (default " << value_ << ")"; }
+
+        void set_value(const std::string& opt, const std::string& s) {
+            std::istringstream is(s);
+            is >> value_;
+            if (is.fail() || is.bad())
+                throw bad_option("bad value for " + opt + ": " + s);
+        }
+
+      private:
+        T& value_;
+    };
+
+    class option_flag: public option {
+      public:
+        option_flag(bool& flag, const char s, const std::string& l, const std::string& d) :
+            option(s, l, d, ""), flag_(flag)
+        { flag_ = false; }
+
+        bool parse(int , char const * const * argv, int &i) {
+            if (argv[i] == short_ || argv[i] == long_) {
+                flag_ = true;
+                return true;
+            } else {
+                return false;
+            }
+        }
+
+      private:
+        bool &flag_;
+    };
+
+    typedef std::vector<option*> opts;
+
+    int argc_;
+    char const * const * argv_;
+    std::string prog_;
+    opts opts_;
+    bool help_;
+};
+}
+
+#endif // OPTIONS_HPP
+
+ +

Download this file

http://git-wip-us.apache.org/repos/asf/qpid-site/blob/75ca8b14/input/releases/qpid-proton-0.13.0/proton/cpp/examples/queue_browser.cpp ---------------------------------------------------------------------- diff --git a/input/releases/qpid-proton-0.13.0/proton/cpp/examples/queue_browser.cpp b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/queue_browser.cpp new file mode 100644 index 0000000..649716b --- /dev/null +++ b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/queue_browser.cpp @@ -0,0 +1,67 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "fake_cpp11.hpp" + +using proton::source_options; + +class browser : public proton::messaging_handler { + private: + proton::url url; + + public: + browser(const std::string& u) : url(u) {} + + void on_container_start(proton::container &c) OVERRIDE { + proton::connection conn = c.connect(url); + source_options browsing = source_options().distribution_mode(proton::source::COPY); + conn.open_receiver(url.path(), proton::receiver_options().source(browsing)); + } + + void on_message(proton::delivery &, proton::message &m) OVERRIDE { + std::cout << m.body() << std::endl; + } +}; + +int main(int argc, char **argv) { + try { + std::string url = argc > 1 ? argv[1] : "127.0.0.1:5672/examples"; + + browser b(url); + proton::default_container(b).run(); + + return 0; + } catch (const std::exception& e) { + std::cerr << e.what() << std::endl; + } + + return 1; +} http://git-wip-us.apache.org/repos/asf/qpid-site/blob/75ca8b14/input/releases/qpid-proton-0.13.0/proton/cpp/examples/queue_browser.cpp.html.in ---------------------------------------------------------------------- diff --git a/input/releases/qpid-proton-0.13.0/proton/cpp/examples/queue_browser.cpp.html.in b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/queue_browser.cpp.html.in new file mode 100644 index 0000000..8494ed4 --- /dev/null +++ b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/queue_browser.cpp.html.in @@ -0,0 +1,51 @@ + +

queue_browser.cpp

+
#include <proton/connection.hpp>
+#include <proton/default_container.hpp>
+#include <proton/delivery.hpp>
+#include <proton/messaging_handler.hpp>
+#include <proton/receiver_options.hpp>
+#include <proton/source_options.hpp>
+#include <proton/url.hpp>
+
+#include <iostream>
+
+#include "fake_cpp11.hpp"
+
+using proton::source_options;
+
+class browser : public proton::messaging_handler {
+  private:
+    proton::url url;
+
+  public:
+    browser(const std::string& u) : url(u) {}
+
+    void on_container_start(proton::container &c) OVERRIDE {
+        proton::connection conn = c.connect(url);
+        source_options browsing = source_options().distribution_mode(proton::source::COPY);
+        conn.open_receiver(url.path(), proton::receiver_options().source(browsing));
+    }
+
+    void on_message(proton::delivery &, proton::message &m) OVERRIDE {
+        std::cout << m.body() << std::endl;
+    }
+};
+
+int main(int argc, char **argv) {
+    try {
+        std::string url = argc > 1 ? argv[1] : "127.0.0.1:5672/examples";
+
+        browser b(url);
+        proton::default_container(b).run();
+
+        return 0;
+    } catch (const std::exception& e) {
+        std::cerr << e.what() << std::endl;
+    }
+
+    return 1;
+}
+
+ +

Download this file

http://git-wip-us.apache.org/repos/asf/qpid-site/blob/75ca8b14/input/releases/qpid-proton-0.13.0/proton/cpp/examples/selected_recv.cpp ---------------------------------------------------------------------- diff --git a/input/releases/qpid-proton-0.13.0/proton/cpp/examples/selected_recv.cpp b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/selected_recv.cpp new file mode 100644 index 0000000..c7a63d9 --- /dev/null +++ b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/selected_recv.cpp @@ -0,0 +1,88 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "fake_cpp11.hpp" + +namespace { + + // Example custom function to configure an AMQP filter, + // specifically an APACHE.ORG:SELECTOR + // (http://www.amqp.org/specification/1.0/filters) + + void set_filter(proton::source_options &opts, const std::string& selector_str) { + proton::source::filter_map map; + proton::symbol filter_key("selector"); + proton::value filter_value; + // The value is a specific AMQP "described type": binary string with symbolic descriptor + proton::codec::encoder enc(filter_value); + enc << proton::codec::start::described() + << proton::symbol("apache.org:selector-filter:string") + << proton::binary(selector_str) + << proton::codec::finish(); + // In our case, the map has this one element + map[filter_key] = filter_value; + opts.filters(map); + } +} + + +class selected_recv : public proton::messaging_handler { + private: + proton::url url; + + public: + selected_recv(const std::string& u) : url(u) {} + + void on_container_start(proton::container &c) OVERRIDE { + proton::source_options opts; + set_filter(opts, "colour = 'green'"); + proton::connection conn = c.connect(url); + conn.open_receiver(url.path(), proton::receiver_options().source(opts)); + } + + void on_message(proton::delivery &, proton::message &m) OVERRIDE { + std::cout << m.body() << std::endl; + } +}; + +int main(int argc, char **argv) { + try { + std::string url = argc > 1 ? argv[1] : "127.0.0.1:5672/examples"; + + selected_recv recv(url); + proton::default_container(recv).run(); + + return 0; + } catch (const std::exception& e) { + std::cerr << e.what() << std::endl; + } + + return 1; +} http://git-wip-us.apache.org/repos/asf/qpid-site/blob/75ca8b14/input/releases/qpid-proton-0.13.0/proton/cpp/examples/selected_recv.cpp.html.in ---------------------------------------------------------------------- diff --git a/input/releases/qpid-proton-0.13.0/proton/cpp/examples/selected_recv.cpp.html.in b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/selected_recv.cpp.html.in new file mode 100644 index 0000000..e4585d0 --- /dev/null +++ b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/selected_recv.cpp.html.in @@ -0,0 +1,72 @@ + +

selected_recv.cpp

+
#include <proton/connection.hpp>
+#include <proton/default_container.hpp>
+#include <proton/messaging_handler.hpp>
+#include <proton/receiver_options.hpp>
+#include <proton/source_options.hpp>
+#include <proton/url.hpp>
+
+#include <iostream>
+
+#include "fake_cpp11.hpp"
+
+namespace {
+
+    // Example custom function to configure an AMQP filter,
+    // specifically an APACHE.ORG:SELECTOR
+    // (http://www.amqp.org/specification/1.0/filters)
+
+    void set_filter(proton::source_options &opts, const std::string& selector_str) {
+        proton::source::filter_map map;
+        proton::symbol filter_key("selector");
+        proton::value filter_value;
+        // The value is a specific AMQP "described type": binary string with symbolic descriptor
+        proton::codec::encoder enc(filter_value);
+        enc << proton::codec::start::described()
+            << proton::symbol("apache.org:selector-filter:string")
+            << proton::binary(selector_str)
+            << proton::codec::finish();
+        // In our case, the map has this one element
+        map[filter_key] = filter_value;
+        opts.filters(map);
+    }
+}
+
+
+class selected_recv : public proton::messaging_handler {
+  private:
+    proton::url url;
+
+  public:
+    selected_recv(const std::string& u) : url(u) {}
+
+    void on_container_start(proton::container &c) OVERRIDE {
+        proton::source_options opts;
+        set_filter(opts, "colour = 'green'");
+        proton::connection conn = c.connect(url);
+        conn.open_receiver(url.path(), proton::receiver_options().source(opts));
+    }
+
+    void on_message(proton::delivery &, proton::message &m) OVERRIDE {
+        std::cout << m.body() << std::endl;
+    }
+};
+
+int main(int argc, char **argv) {
+    try {
+        std::string url = argc > 1 ? argv[1] : "127.0.0.1:5672/examples";
+
+        selected_recv recv(url);
+        proton::default_container(recv).run();
+
+        return 0;
+    } catch (const std::exception& e) {
+        std::cerr << e.what() << std::endl;
+    }
+
+    return 1;
+}
+
+ +

Download this file

http://git-wip-us.apache.org/repos/asf/qpid-site/blob/75ca8b14/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server.cpp ---------------------------------------------------------------------- diff --git a/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server.cpp b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server.cpp new file mode 100644 index 0000000..ec24f9f --- /dev/null +++ b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server.cpp @@ -0,0 +1,100 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "options.hpp" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "fake_cpp11.hpp" + +class server : public proton::messaging_handler { + private: + typedef std::map sender_map; + proton::url url; + proton::connection connection; + sender_map senders; + + public: + server(const std::string &u) : url(u) {} + + void on_container_start(proton::container &c) OVERRIDE { + connection = c.connect(url); + connection.open_receiver(url.path()); + + std::cout << "server connected to " << url << std::endl; + } + + std::string to_upper(const std::string &s) { + std::string uc(s); + size_t l = uc.size(); + for (size_t i=0; i(std::toupper(uc[i])); + return uc; + } + + void on_message(proton::delivery &, proton::message &m) OVERRIDE { + std::cout << "Received " << m.body() << std::endl; + + std::string reply_to = m.reply_to(); + proton::message reply; + + reply.to(reply_to); + reply.body(to_upper(proton::get(m.body()))); + reply.correlation_id(m.correlation_id()); + + if (!senders[reply_to]) { + senders[reply_to] = connection.open_sender(reply_to); + } + + senders[reply_to].send(reply); + } +}; + +int main(int argc, char **argv) { + std::string address("amqp://0.0.0.0:5672/examples"); + example::options opts(argc, argv); + + opts.add_value(address, 'a', "address", "listen on URL", "URL"); + + try { + opts.parse(); + + server srv(address); + proton::default_container(srv).run(); + + return 0; + } catch (const example::bad_option& e) { + std::cout << opts << std::endl << e.what() << std::endl; + } catch (const std::exception& e) { + std::cerr << e.what() << std::endl; + } + + return 1; +} http://git-wip-us.apache.org/repos/asf/qpid-site/blob/75ca8b14/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server.cpp.html.in ---------------------------------------------------------------------- diff --git a/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server.cpp.html.in b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server.cpp.html.in new file mode 100644 index 0000000..06f2825 --- /dev/null +++ b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server.cpp.html.in @@ -0,0 +1,84 @@ + +

server.cpp

+
#include "options.hpp"
+
+#include <proton/connection.hpp>
+#include <proton/default_container.hpp>
+#include <proton/messaging_handler.hpp>
+#include <proton/tracker.hpp>
+#include <proton/url.hpp>
+
+#include <iostream>
+#include <map>
+#include <string>
+#include <cctype>
+
+#include "fake_cpp11.hpp"
+
+class server : public proton::messaging_handler {
+  private:
+    typedef std::map<std::string, proton::sender> sender_map;
+    proton::url url;
+    proton::connection connection;
+    sender_map senders;
+
+  public:
+    server(const std::string &u) : url(u) {}
+
+    void on_container_start(proton::container &c) OVERRIDE {
+        connection = c.connect(url);
+        connection.open_receiver(url.path());
+
+        std::cout << "server connected to " << url << std::endl;
+    }
+
+    std::string to_upper(const std::string &s) {
+        std::string uc(s);
+        size_t l = uc.size();
+        for (size_t i=0; i<l; i++)
+            uc[i] = static_cast<char>(std::toupper(uc[i]));
+        return uc;
+    }
+
+    void on_message(proton::delivery &, proton::message &m) OVERRIDE {
+        std::cout << "Received " << m.body() << std::endl;
+
+        std::string reply_to = m.reply_to();
+        proton::message reply;
+
+        reply.to(reply_to);
+        reply.body(to_upper(proton::get<std::string>(m.body())));
+        reply.correlation_id(m.correlation_id());
+
+        if (!senders[reply_to]) {
+            senders[reply_to] = connection.open_sender(reply_to);
+        }
+
+        senders[reply_to].send(reply);
+    }
+};
+
+int main(int argc, char **argv) {
+    std::string address("amqp://0.0.0.0:5672/examples");
+    example::options opts(argc, argv);
+
+    opts.add_value(address, 'a', "address", "listen on URL", "URL");
+
+    try {
+        opts.parse();
+
+        server srv(address);
+        proton::default_container(srv).run();
+
+        return 0;
+    } catch (const example::bad_option& e) {
+        std::cout << opts << std::endl << e.what() << std::endl;
+    } catch (const std::exception& e) {
+        std::cerr << e.what() << std::endl;
+    }
+
+    return 1;
+}
+
+ +

Download this file

http://git-wip-us.apache.org/repos/asf/qpid-site/blob/75ca8b14/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server_direct.cpp ---------------------------------------------------------------------- diff --git a/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server_direct.cpp b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server_direct.cpp new file mode 100644 index 0000000..220934f --- /dev/null +++ b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server_direct.cpp @@ -0,0 +1,119 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "options.hpp" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "fake_cpp11.hpp" + +class server : public proton::messaging_handler { + private: + typedef std::map sender_map; + std::string url; + sender_map senders; + int address_counter; + + public: + server(const std::string &u) : url(u), address_counter(0) {} + + void on_container_start(proton::container &c) OVERRIDE { + c.listen(url); + std::cout << "server listening on " << url << std::endl; + } + + std::string to_upper(const std::string &s) { + std::string uc(s); + size_t l = uc.size(); + + for (size_t i=0; i(std::toupper(uc[i])); + + return uc; + } + + std::string generate_address() { + std::ostringstream addr; + addr << "server" << address_counter++; + + return addr.str(); + } + + void on_sender_open(proton::sender &sender) OVERRIDE { + if (sender.source().dynamic()) { + std::string addr = generate_address(); + sender.open(proton::sender_options().source(proton::source_options().address(addr))); + senders[addr] = sender; + } + } + + void on_message(proton::delivery &, proton::message &m) OVERRIDE { + std::cout << "Received " << m.body() << std::endl; + + std::string reply_to = m.reply_to(); + sender_map::iterator it = senders.find(reply_to); + + if (it == senders.end()) { + std::cout << "No link for reply_to: " << reply_to << std::endl; + } else { + proton::sender sender = it->second; + proton::message reply; + + reply.to(reply_to); + reply.body(to_upper(proton::get(m.body()))); + reply.correlation_id(m.correlation_id()); + + sender.send(reply); + } + } +}; + +int main(int argc, char **argv) { + std::string address("amqp://127.0.0.1:5672/examples"); + example::options opts(argc, argv); + + opts.add_value(address, 'a', "address", "listen on URL", "URL"); + + try { + opts.parse(); + + server srv(address); + proton::default_container(srv).run(); + + return 0; + } catch (const example::bad_option& e) { + std::cout << opts << std::endl << e.what() << std::endl; + } catch (const std::exception& e) { + std::cerr << e.what() << std::endl; + } + + return 1; +} http://git-wip-us.apache.org/repos/asf/qpid-site/blob/75ca8b14/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server_direct.cpp.html.in ---------------------------------------------------------------------- diff --git a/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server_direct.cpp.html.in b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server_direct.cpp.html.in new file mode 100644 index 0000000..3a6203f --- /dev/null +++ b/input/releases/qpid-proton-0.13.0/proton/cpp/examples/server_direct.cpp.html.in @@ -0,0 +1,103 @@ + +

server_direct.cpp

+
#include "options.hpp"
+
+#include <proton/default_container.hpp>
+#include <proton/messaging_handler.hpp>
+#include <proton/sender.hpp>
+#include <proton/source_options.hpp>
+#include <proton/tracker.hpp>
+
+#include <iostream>
+#include <map>
+#include <string>
+#include <sstream>
+#include <cctype>
+
+#include "fake_cpp11.hpp"
+
+class server : public proton::messaging_handler {
+  private:
+    typedef std::map<std::string, proton::sender> sender_map;
+    std::string url;
+    sender_map senders;
+    int address_counter;
+
+  public:
+    server(const std::string &u) : url(u), address_counter(0) {}
+
+    void on_container_start(proton::container &c) OVERRIDE {
+        c.listen(url);
+        std::cout << "server listening on " << url << std::endl;
+    }
+
+    std::string to_upper(const std::string &s) {
+        std::string uc(s);
+        size_t l = uc.size();
+
+        for (size_t i=0; i<l; i++)
+            uc[i] = static_cast<char>(std::toupper(uc[i]));
+
+        return uc;
+    }
+
+    std::string generate_address() {
+        std::ostringstream addr;
+        addr << "server" << address_counter++;
+
+        return addr.str();
+    }
+
+    void on_sender_open(proton::sender &sender) OVERRIDE {
+        if (sender.source().dynamic()) {
+            std::string addr = generate_address();
+            sender.open(proton::sender_options().source(proton::source_options().address(addr)));
+            senders[addr] = sender;
+        }
+    }
+
+    void on_message(proton::delivery &, proton::message &m) OVERRIDE {
+        std::cout << "Received " << m.body() << std::endl;
+
+        std::string reply_to = m.reply_to();
+        sender_map::iterator it = senders.find(reply_to);
+
+        if (it == senders.end()) {
+            std::cout << "No link for reply_to: " << reply_to << std::endl;
+        } else {
+            proton::sender sender = it->second;
+            proton::message reply;
+
+            reply.to(reply_to);
+            reply.body(to_upper(proton::get<std::string>(m.body())));
+            reply.correlation_id(m.correlation_id());
+
+            sender.send(reply);
+        }
+    }
+};
+
+int main(int argc, char **argv) {
+    std::string address("amqp://127.0.0.1:5672/examples");
+    example::options opts(argc, argv);
+
+    opts.add_value(address, 'a', "address", "listen on URL", "URL");
+
+    try {
+        opts.parse();
+
+        server srv(address);
+        proton::default_container(srv).run();
+
+        return 0;
+    } catch (const example::bad_option& e) {
+        std::cout << opts << std::endl << e.what() << std::endl;
+    } catch (const std::exception& e) {
+        std::cerr << e.what() << std::endl;
+    }
+
+    return 1;
+}
+
+ +

Download this file

--------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org For additional commands, e-mail: commits-help@qpid.apache.org