1
votes

I'm trying to add proton::work function (opening a new sender) inside the work queue of the proton::connection object. I have a pointer to the working queue, but my problem is how to bind the open_sender function correctly.

I'm aware of the real problem here : the parameter of the function :

sender open_sender(const std::string& addr);

As the string is passed by reference, I have to de-reference it. I'm ok with that, but how to do it with the proton tools ?

Here my line of code :

proton::work w = proton::make_work( &proton::connection::open_sender, &m_connection, p_url);

Note :

  1. Of course I'm not using C++11 in my project, it would be too simple to ask ;) !
  2. Of course I cannot change to C++11
  3. If you have a better idea on how to create a new sender in a multi-threaded program let me know.
1
"As the string is passed by reference, I have to de-reference it." .. what? You dont need to "de-reference" a reference. How would that look like? - 463035818_is_not_a_number
What I meant was the equivalent of boost::cref(), to make a copy of the reference object for the internal mechanism of boost::bind(). It's why I called it "de-reference" it. - Baptiste
Well, you (and other people who have to use pre C++11) are the precise reason we added the make_work API to the proton C++ binding! This is precisely the way it is supposed to be used. You don't say if you are having some problem using it like this or what the problem is - it is a little hard to help in this case. - StitchedUp
Oh - I see now what you are trying to achieve - I'll write an actual answer. - StitchedUp

1 Answers

1
votes

Usually you will use the proton::open_sender API from within the handler for connection open or container start so you will not have to use proton::make_work in most cases. If you look at the Proton C++ examples, a good place to start is simple_send.cpp.

Abbreviated code might look like this:

class simple_send : public proton::messaging_handler {
  private:
    proton::sender sender;
    const std::string url;
    const std::string addr;
...
  public:
    simple_send(...) :
      url(...), 
      addr(...)
    {}
...
    // This handler is called when the container starts
    void on_container_start(proton::container &c) {
        c.connect(url);
    }

    // This handler is called when the connection is open
    void on_connection_open(proton::connection& c) {
        sender = c.open_sender(addr);
    }
...
}

int main() {
...
  simple_send send(...);
  proton::container(send).run();
...
}

There are other examples that come with Proton C++, that should help you figure out other ways to use Proton C++. See https://github.com/apache/qpid-proton/tree/master/examples/cpp.

There is also API documentation you can find at http://qpid.apache.org/releases/qpid-proton-0.20.0/proton/cpp/api/index.html (for the current release as of February 2018).