You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2016/01/16 23:42:36 UTC
[3/3] qpid-proton git commit: NO-JIRA: c++: rename proton::engine to
proton::connection_engine, remove proton::event_loop
NO-JIRA: c++: rename proton::engine to proton::connection_engine, remove proton::event_loop
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/b3e143ac
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/b3e143ac
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/b3e143ac
Branch: refs/heads/master
Commit: b3e143acca0b741972a52c14595f7f692efc5878
Parents: e53302d
Author: Alan Conway <ac...@redhat.com>
Authored: Sat Jan 16 17:40:15 2016 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Sat Jan 16 17:40:15 2016 -0500
----------------------------------------------------------------------
examples/cpp/select_broker.cpp | 14 +-
proton-c/bindings/cpp/CMakeLists.txt | 4 +-
proton-c/bindings/cpp/docs/mainpage.md | 11 +-
.../bindings/cpp/include/proton/connection.hpp | 12 +-
.../cpp/include/proton/connection_engine.hpp | 155 +++++++++++++++++++
.../bindings/cpp/include/proton/container.hpp | 3 +-
proton-c/bindings/cpp/include/proton/engine.hpp | 155 -------------------
proton-c/bindings/cpp/include/proton/event.hpp | 8 +-
.../bindings/cpp/include/proton/event_loop.hpp | 44 ------
proton-c/bindings/cpp/src/connection_engine.cpp | 132 ++++++++++++++++
proton-c/bindings/cpp/src/engine.cpp | 132 ----------------
proton-c/bindings/cpp/src/event.cpp | 11 --
proton-c/bindings/cpp/src/messaging_event.cpp | 6 +-
proton-c/bindings/cpp/src/messaging_event.hpp | 2 +-
proton-c/bindings/cpp/src/proton_event.cpp | 25 +--
proton-c/bindings/cpp/src/proton_event.hpp | 8 +-
16 files changed, 316 insertions(+), 406 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/examples/cpp/select_broker.cpp
----------------------------------------------------------------------
diff --git a/examples/cpp/select_broker.cpp b/examples/cpp/select_broker.cpp
index ade47eb..871a180 100644
--- a/examples/cpp/select_broker.cpp
+++ b/examples/cpp/select_broker.cpp
@@ -20,7 +20,7 @@
#include "options.hpp"
#include "broker.hpp"
-#include "proton/engine.hpp"
+#include "proton/connection_engine.hpp"
#include <sstream>
#include <arpa/inet.h>
@@ -42,7 +42,7 @@ int do_accept(int listen_fd);
class broker {
- typedef std::map<int, proton::engine*> engine_map;
+ typedef std::map<int, proton::connection_engine*> engine_map;
queues queues_;
broker_handler handler_;
@@ -74,14 +74,14 @@ class broker {
if (fd == listen_fd) {
if (FD_ISSET(listen_fd, &readable_set)) {
int new_fd = do_accept(listen_fd);
- engines_[new_fd] = new proton::engine(handler_);
+ engines_[new_fd] = new proton::connection_engine(handler_);
FD_SET(new_fd, &reading_);
FD_SET(new_fd, &writing_);
}
continue;
}
if (engines_.find(fd) != engines_.end()) {
- proton::engine& eng = *engines_[fd];
+ proton::connection_engine& eng = *engines_[fd];
try {
if (FD_ISSET(fd, &readable_set))
readable(fd, eng);
@@ -109,7 +109,7 @@ class broker {
private:
- void readable(int fd, proton::engine& eng) {
+ void readable(int fd, proton::connection_engine& eng) {
proton::buffer<char> input = eng.input();
if (input.size()) {
ssize_t n = check(read(fd, input.begin(), input.size()));
@@ -121,7 +121,7 @@ class broker {
}
}
- void writable(int fd, proton::engine& eng) {
+ void writable(int fd, proton::connection_engine& eng) {
proton::buffer<const char> output = eng.output();
if (output.size()) {
ssize_t n = check(write(fd, output.begin(), output.size()));
@@ -182,5 +182,3 @@ int main(int argc, char **argv) {
}
return 1;
}
-
-
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/proton-c/bindings/cpp/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/CMakeLists.txt b/proton-c/bindings/cpp/CMakeLists.txt
index 7a345c0..be8cc1c 100644
--- a/proton-c/bindings/cpp/CMakeLists.txt
+++ b/proton-c/bindings/cpp/CMakeLists.txt
@@ -45,7 +45,7 @@ set(qpid-proton-cpp-source
src/duration.cpp
src/encoder.cpp
src/endpoint.cpp
- src/engine.cpp
+ src/connection_engine.cpp
src/error.cpp
src/event.cpp
src/handler.cpp
@@ -127,7 +127,7 @@ add_subdirectory(${CMAKE_SOURCE_DIR}/tests/tools/apps/cpp ${CMAKE_BINARY_DIR}/te
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/libqpid-proton-cpp.pc.in
${CMAKE_CURRENT_BINARY_DIR}/libqpid-proton-cpp.pc @ONLY)
-install (FILES
+install (FILES
${CMAKE_CURRENT_BINARY_DIR}/libqpid-proton-cpp.pc
DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/proton-c/bindings/cpp/docs/mainpage.md
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/docs/mainpage.md b/proton-c/bindings/cpp/docs/mainpage.md
index 9129307..3f7e35c 100644
--- a/proton-c/bindings/cpp/docs/mainpage.md
+++ b/proton-c/bindings/cpp/docs/mainpage.md
@@ -98,11 +98,12 @@ complex AMQP types. For details on converting between AMQP and C++ data types
see the \ref encode_decode.cpp example and classes `proton::encoder`,
`proton::decoder` and `proton::value`.
-`proton::engine` provides fewer facilities that `proton::container` but makes
-fewer (no) assumptions about application threading and IO. It may be easier to
-integrate with an existing IO framework, for multi-threaded applications or for
-non-socket IO. See the \ref select_broker.cpp example. The main application and
-AMQP logic is implemented the same way using the engine or the container.
+`proton::connection_engine` provides fewer facilities that `proton::container`
+but makes fewer (no) assumptions about application threading and IO. It may be
+easier to integrate with an existing IO framework, for multi-threaded
+applications or for non-socket IO. See the \ref select_broker.cpp example. The
+main application and AMQP logic is implemented the same way using the `connection_engine` or
+the container.
Delivery Guarantees
-------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/proton-c/bindings/cpp/include/proton/connection.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/connection.hpp b/proton-c/bindings/cpp/include/proton/connection.hpp
index 67091e3..c32452a 100644
--- a/proton-c/bindings/cpp/include/proton/connection.hpp
+++ b/proton-c/bindings/cpp/include/proton/connection.hpp
@@ -35,7 +35,6 @@ struct pn_connection_t;
namespace proton {
class handler;
-class engine;
/** connection to a remote AMQP peer. */
class connection : public object<pn_connection_t>, endpoint
@@ -43,15 +42,9 @@ class connection : public object<pn_connection_t>, endpoint
public:
connection(pn_connection_t* c=0) : object<pn_connection_t>(c) {}
- /// Get the event_loop, can be a container or an engine.
- PN_CPP_EXTERN class event_loop &event_loop() const;
-
- /// Get the container, throw an exception if event_loop is not a container.
+ /// Get the container, throw an exception if this connection is not managed by a container.
PN_CPP_EXTERN class container &container() const;
- /// Get the engine, throw an exception if event_loop is not an engine.
- PN_CPP_EXTERN class engine &engine() const;
-
/// Get the transport for the connection.
PN_CPP_EXTERN class transport transport() const;
@@ -61,8 +54,7 @@ class connection : public object<pn_connection_t>, endpoint
/// Set the AMQP host name for the connection
PN_CPP_EXTERN void host(const std::string& h);
- /// Return the container-ID for the connection. All connections have a container_id,
- /// even if they don't have a container event_loop.
+ /// Return the container-ID for the connection.
PN_CPP_EXTERN std::string container_id() const;
// Set the container-ID for the connection
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/proton-c/bindings/cpp/include/proton/connection_engine.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/connection_engine.hpp b/proton-c/bindings/cpp/include/proton/connection_engine.hpp
new file mode 100644
index 0000000..3a39be1
--- /dev/null
+++ b/proton-c/bindings/cpp/include/proton/connection_engine.hpp
@@ -0,0 +1,155 @@
+#ifndef CONNECTION_ENGINE_HPP
+#define CONNECTION_ENGINE_HPP
+/*
+ * 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 "proton/pn_unique_ptr.hpp"
+#include "proton/export.hpp"
+
+#include <cstddef>
+#include <utility>
+#include <string>
+
+namespace proton {
+
+class handler;
+class connection;
+
+/// Pointers to a byte range to use as a buffer.
+template <class T> class buffer {
+ public:
+ explicit buffer(T* begin__=0, T* end__=0) : begin_(begin__), end_(end__) {}
+ explicit buffer(T* ptr, size_t n) : begin_(ptr), end_(ptr + n) {}
+ T* begin() const { return begin_; }
+ T* end() const { return end_; }
+ size_t size() const { return end() - begin(); }
+ bool empty() const { return !size(); }
+
+ private:
+ T* begin_;
+ T* end_;
+};
+
+/**
+ * A connection_engine manages a single AMQP connection. It is useful for
+ * integrating AMQP into an existing IO framework.
+ *
+ * The engine provides a simple "bytes-in/bytes-out" interface. Incoming AMQP
+ * bytes from any kind of data connection are fed into the engine and processed
+ * to dispatch events to a proton::handler. The resulting AMQP output data is
+ * available from the engine and can sent back over the connection.
+ *
+ * The engine does no IO of its own. It assumes a two-way flow of bytes over
+ * some externally-managed "connection". The "connection" could be a socket
+ * managed by select, poll, epoll or some other mechanism, or it could be
+ * something else such as an RDMA connection, a shared-memory buffer or a Unix
+ * pipe.
+ *
+ * The engine is an alternative event_loop to the proton::container. The
+ * container is easier to use in single-threaded, stand-alone applications that
+ * want to use standard socket connections. The engine can be embedding into
+ * any existing IO framework for any type of IO.
+ *
+ * The application is coded the same way for engine or container: you implement
+ * proton::handler. Handlers attached to an engine will receive transport,
+ * connection, session, link and message events. They will not receive reactor,
+ * selectable or timer events, the engine assumes those are managed externally.
+ *
+ * THREAD SAFETY: A single engine instance cannot be called concurrently, but
+ * different engine instances can be processed concurrently in separate threads.
+ */
+class connection_engine {
+ public:
+
+ // TODO aconway 2015-11-02: engine() take connection-options, handle SSL
+ // TODO aconway 2015-11-02: engine needs to accept application events.
+ // TODO aconway 2015-11-02: generalize reconnect logic for container and engine.
+
+ /**
+ * Create an engine that will advertise id as the AMQP container-id for its connection.
+ */
+ PN_CPP_EXTERN connection_engine(handler&, const std::string& id=std::string());
+
+ PN_CPP_EXTERN ~connection_engine();
+
+ /**
+ * Input buffer. If input.size() == 0 means no input can be accepted right now, but
+ * sending output might free up space.
+ */
+ PN_CPP_EXTERN buffer<char> input();
+
+ /**
+ * Process n bytes from input(). Calls handler functions for the AMQP events
+ * encoded by the received data.
+ *
+ * After the call the input() and output() buffers may have changed.
+ */
+ PN_CPP_EXTERN void received(size_t n);
+
+ /**
+ * Indicate that no more input data is available from the external
+ * connection. May call handler functions.
+ */
+ PN_CPP_EXTERN void close_input();
+
+ /**
+ * Output buffer. Send data from this buffer and call sent() to indicate it
+ * has been sent. If output().size() == 0 there is no data to send,
+ * receiving more input data might make output data available.
+ */
+ PN_CPP_EXTERN buffer<const char> output();
+
+ /**
+ * Call when the first n bytes from the start of the output buffer have been
+ * sent. May call handler functions.
+ *
+ * After the call the input() and output() buffers may have changed.
+ */
+ PN_CPP_EXTERN void sent(size_t n);
+
+ /**
+ * Indicate that no more output data can be sent to the external connection.
+ * May call handler functions.
+ */
+ PN_CPP_EXTERN void close_output();
+
+ /**
+ * True if connection_engine is closed. This can either be because close_input() and
+ * close_output() were called to indicate the external connection has
+ * closed, or because AMQP close frames were received in the AMQP data. In
+ * either case no more input() buffer space or output() data will be
+ * available for this connection_engine.
+ */
+ PN_CPP_EXTERN bool closed() const;
+
+ /** The AMQP connection associated with this connection_engine. */
+ PN_CPP_EXTERN class connection connection() const;
+
+ /** The AMQP container-id associated with this connection_engine. */
+ PN_CPP_EXTERN std::string id() const;
+
+ private:
+ void run();
+
+ struct impl;
+ pn_unique_ptr<impl> impl_;
+};
+
+}
+#endif // CONNECTION_ENGINE_HPP
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/proton-c/bindings/cpp/include/proton/container.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/container.hpp b/proton-c/bindings/cpp/include/proton/container.hpp
index 44cc476..7c417de 100644
--- a/proton-c/bindings/cpp/include/proton/container.hpp
+++ b/proton-c/bindings/cpp/include/proton/container.hpp
@@ -23,7 +23,6 @@
*/
#include "proton/duration.hpp"
#include "proton/export.hpp"
-#include "proton/event_loop.hpp"
#include "proton/pn_unique_ptr.hpp"
#include "proton/reactor.hpp"
#include "proton/url.hpp"
@@ -50,7 +49,7 @@ class container_impl;
* Note that by default, links belonging to the container have generated link-names
* of the form
*/
-class container : public event_loop {
+class container {
public:
/// Container ID should be unique within your system. By default a random ID is generated.
PN_CPP_EXTERN container(const std::string& id=std::string());
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/proton-c/bindings/cpp/include/proton/engine.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/engine.hpp b/proton-c/bindings/cpp/include/proton/engine.hpp
deleted file mode 100644
index 340d21b..0000000
--- a/proton-c/bindings/cpp/include/proton/engine.hpp
+++ /dev/null
@@ -1,155 +0,0 @@
-#ifndef ENGINE_HPP
-#define ENGINE_HPP
-/*
- * 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 "proton/pn_unique_ptr.hpp"
-#include "proton/export.hpp"
-#include "proton/event_loop.hpp"
-
-#include <cstddef>
-#include <utility>
-
-namespace proton {
-
-class handler;
-class connection;
-
-/// Pointers to a byte range to use as a buffer.
-template <class T> class buffer {
- public:
- explicit buffer(T* begin__=0, T* end__=0) : begin_(begin__), end_(end__) {}
- explicit buffer(T* ptr, size_t n) : begin_(ptr), end_(ptr + n) {}
- T* begin() const { return begin_; }
- T* end() const { return end_; }
- size_t size() const { return end() - begin(); }
- bool empty() const { return !size(); }
-
- private:
- T* begin_;
- T* end_;
-};
-
-/**
- * An engine is an event_loop that manages a single AMQP connection. It is
- * useful for integrating AMQP into an existing IO framework.
- *
- * The engine provides a simple "bytes-in/bytes-out" interface. Incoming AMQP
- * bytes from any kind of data connection are fed into the engine and processed
- * to dispatch events to a proton::handler. The resulting AMQP output data is
- * available from the engine and can sent back over the connection.
- *
- * The engine does no IO of its own. It assumes a two-way flow of bytes over
- * some externally-managed "connection". The "connection" could be a socket
- * managed by select, poll, epoll or some other mechanism, or it could be
- * something else such as an RDMA connection, a shared-memory buffer or a Unix
- * pipe.
- *
- * The engine is an alternative event_loop to the proton::container. The
- * container is easier to use in single-threaded, stand-alone applications that
- * want to use standard socket connections. The engine can be embedding into
- * any existing IO framework for any type of IO.
- *
- * The application is coded the same way for engine or container: you implement
- * proton::handler. Handlers attached to an engine will receive transport,
- * connection, session, link and message events. They will not receive reactor,
- * selectable or timer events, the engine assumes those are managed externally.
- *
- * THREAD SAFETY: A single engine instance cannot be called concurrently, but
- * different engine instances can be processed concurrently in separate threads.
- */
-class engine : public event_loop {
- public:
-
- // TODO aconway 2015-11-02: engine() take connection-options.
- // TODO aconway 2015-11-02: engine needs to accept application events.
- // TODO aconway 2015-11-02: generalize reconnect logic for container and engine.
-
- /**
- * Create an engine that will advertise id as the AMQP container-id for its connection.
- */
- PN_CPP_EXTERN engine(handler&, const std::string& id=std::string());
-
- PN_CPP_EXTERN ~engine();
-
- /**
- * Input buffer. If input.size() == 0 means no input can be accepted right now, but
- * sending output might free up space.
- */
- PN_CPP_EXTERN buffer<char> input();
-
- /**
- * Process n bytes from input(). Calls handler functions for the AMQP events
- * encoded by the received data.
- *
- * After the call the input() and output() buffers may have changed.
- */
- PN_CPP_EXTERN void received(size_t n);
-
- /**
- * Indicate that no more input data is available from the external
- * connection. May call handler functions.
- */
- PN_CPP_EXTERN void close_input();
-
- /**
- * Output buffer. Send data from this buffer and call sent() to indicate it
- * has been sent. If output().size() == 0 there is no data to send,
- * receiving more input data might make output data available.
- */
- PN_CPP_EXTERN buffer<const char> output();
-
- /**
- * Call when the first n bytes from the start of the output buffer have been
- * sent. May call handler functions.
- *
- * After the call the input() and output() buffers may have changed.
- */
- PN_CPP_EXTERN void sent(size_t n);
-
- /**
- * Indicate that no more output data can be sent to the external connection.
- * May call handler functions.
- */
- PN_CPP_EXTERN void close_output();
-
- /**
- * True if engine is closed. This can either be because close_input() and
- * close_output() were called to indicate the external connection has
- * closed, or because AMQP close frames were received in the AMQP data. In
- * either case no more input() buffer space or output() data will be
- * available for this engine.
- */
- PN_CPP_EXTERN bool closed() const;
-
- /** The AMQP connection associated with this engine. */
- PN_CPP_EXTERN class connection connection() const;
-
- /** The AMQP container-id associated with this engine. */
- PN_CPP_EXTERN std::string id() const;
-
- private:
- void run();
-
- struct impl;
- pn_unique_ptr<impl> impl_;
-};
-
-}
-#endif // ENGINE_HPP
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/proton-c/bindings/cpp/include/proton/event.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/event.hpp b/proton-c/bindings/cpp/include/proton/event.hpp
index f0ba897..ea8ded2 100644
--- a/proton-c/bindings/cpp/include/proton/event.hpp
+++ b/proton-c/bindings/cpp/include/proton/event.hpp
@@ -45,15 +45,9 @@ class event {
/// Return the name of the event type
virtual PN_CPP_EXTERN std::string name() const = 0;
- /// Get the event_loop object, can be a container or an engine.
- virtual PN_CPP_EXTERN class event_loop& event_loop() const;
-
- /// Get the container, throw an exception if event_loop is not a container.
+ /// Get the container, throw an exception this event was not generated by a container.
virtual PN_CPP_EXTERN class container& container() const;
- /// Get the engine, , throw an exception if event_loop is not an engine.
- virtual PN_CPP_EXTERN class engine& engine() const;
-
/// Get connection.
virtual PN_CPP_EXTERN class connection connection() const;
/// Get sender @throws error if no sender.
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/proton-c/bindings/cpp/include/proton/event_loop.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/event_loop.hpp b/proton-c/bindings/cpp/include/proton/event_loop.hpp
deleted file mode 100644
index dcf9670..0000000
--- a/proton-c/bindings/cpp/include/proton/event_loop.hpp
+++ /dev/null
@@ -1,44 +0,0 @@
-#ifndef EVENT_LOOP_HPP
-#define EVENT_LOOP_HPP
-/*
- * 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 "proton/export.hpp"
-
-#include <string>
-
-namespace proton {
-
-/**
- * An event_loop dispatches events to event handlers. event_loop is an abstract
- * class, concrete subclasses are proton::container and prton::engine.
- */
-class event_loop {
- public:
- PN_CPP_EXTERN virtual ~event_loop();
-
- /// The AMQP container-id associated with this event loop.
- /// Any connections managed by this event loop will have this container id.
- PN_CPP_EXTERN virtual std::string id() const = 0;
-
- // TODO aconway 2015-11-02: injecting application events.
-};
-
-}
-#endif // EVENT_LOOP_HPP
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/proton-c/bindings/cpp/src/connection_engine.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/connection_engine.cpp b/proton-c/bindings/cpp/src/connection_engine.cpp
new file mode 100644
index 0000000..2fadd00
--- /dev/null
+++ b/proton-c/bindings/cpp/src/connection_engine.cpp
@@ -0,0 +1,132 @@
+/*
+ * 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 "proton/connection_engine.hpp"
+#include "proton/error.hpp"
+
+#include "uuid.hpp"
+#include "proton_bits.hpp"
+#include "messaging_event.hpp"
+
+#include <proton/connection.h>
+#include <proton/transport.h>
+#include <proton/event.h>
+
+namespace proton {
+
+struct connection_engine::impl {
+
+ impl(class handler& h, pn_transport_t *t) :
+ handler(h), transport(t), connection(pn_connection()), collector(pn_collector())
+ {}
+
+ ~impl() {
+ pn_transport_free(transport);
+ pn_connection_free(connection);
+ pn_collector_free(collector);
+ }
+
+ void check(int err, const std::string& msg) {
+ if (err)
+ throw proton::error(msg + error_str(pn_transport_error(transport), err));
+ }
+
+ pn_event_t *peek() { return pn_collector_peek(collector); }
+ void pop() { pn_collector_pop(collector); }
+
+ class handler& handler;
+ pn_transport_t *transport;
+ pn_connection_t *connection;
+ pn_collector_t * collector;
+};
+
+connection_engine::connection_engine(handler &h, const std::string& id_) : impl_(new impl(h, pn_transport())) {
+ if (!impl_->transport || !impl_->connection || !impl_->collector)
+ throw error("connection_engine setup failed");
+ std::string id = id_.empty() ? uuid().str() : id_;
+ pn_connection_set_container(impl_->connection, id.c_str());
+ impl_->check(pn_transport_bind(impl_->transport, impl_->connection), "connection_engine bind: ");
+ pn_connection_collect(impl_->connection, impl_->collector);
+}
+
+connection_engine::~connection_engine() {}
+
+buffer<char> connection_engine::input() {
+ ssize_t n = pn_transport_capacity(impl_->transport);
+ if (n <= 0)
+ return buffer<char>();
+ return buffer<char>(pn_transport_tail(impl_->transport), size_t(n));
+}
+
+void connection_engine::close_input() {
+ pn_transport_close_tail(impl_->transport);
+ run();
+}
+
+void connection_engine::received(size_t n) {
+ impl_->check(pn_transport_process(impl_->transport, n), "connection_engine process: ");
+ run();
+}
+
+void connection_engine::run() {
+ for (pn_event_t *e = impl_->peek(); e; e = impl_->peek()) {
+ switch (pn_event_type(e)) {
+ case PN_CONNECTION_REMOTE_CLOSE:
+ pn_transport_close_tail(impl_->transport);
+ break;
+ case PN_CONNECTION_LOCAL_CLOSE:
+ pn_transport_close_head(impl_->transport);
+ break;
+ default:
+ break;
+ }
+ messaging_event mevent(e, pn_event_type(e), 0);
+ mevent.dispatch(impl_->handler);
+ impl_->pop();
+ }
+}
+
+buffer<const char> connection_engine::output() {
+ ssize_t n = pn_transport_pending(impl_->transport);
+ if (n <= 0)
+ return buffer<const char>();
+ return buffer<const char>(pn_transport_head(impl_->transport), size_t(n));
+}
+
+void connection_engine::sent(size_t n) {
+ pn_transport_pop(impl_->transport, n);
+ run();
+}
+
+void connection_engine::close_output() {
+ pn_transport_close_head(impl_->transport);
+ run();
+}
+
+bool connection_engine::closed() const {
+ return pn_transport_closed(impl_->transport);
+}
+
+class connection connection_engine::connection() const {
+ return impl_->connection;
+}
+
+std::string connection_engine::id() const { return connection().container_id(); }
+
+}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/proton-c/bindings/cpp/src/engine.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/engine.cpp b/proton-c/bindings/cpp/src/engine.cpp
deleted file mode 100644
index 14d3ba1..0000000
--- a/proton-c/bindings/cpp/src/engine.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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 "proton/engine.hpp"
-#include "proton/error.hpp"
-
-#include "uuid.hpp"
-#include "proton_bits.hpp"
-#include "messaging_event.hpp"
-
-#include <proton/connection.h>
-#include <proton/transport.h>
-#include <proton/event.h>
-
-namespace proton {
-
-struct engine::impl {
-
- impl(class handler& h, pn_transport_t *t) :
- handler(h), transport(t), connection(pn_connection()), collector(pn_collector())
- {}
-
- ~impl() {
- pn_transport_free(transport);
- pn_connection_free(connection);
- pn_collector_free(collector);
- }
-
- void check(int err, const std::string& msg) {
- if (err)
- throw proton::error(msg + error_str(pn_transport_error(transport), err));
- }
-
- pn_event_t *peek() { return pn_collector_peek(collector); }
- void pop() { pn_collector_pop(collector); }
-
- class handler& handler;
- pn_transport_t *transport;
- pn_connection_t *connection;
- pn_collector_t * collector;
-};
-
-engine::engine(handler &h, const std::string& id_) : impl_(new impl(h, pn_transport())) {
- if (!impl_->transport || !impl_->connection || !impl_->collector)
- throw error("engine setup failed");
- std::string id = id_.empty() ? uuid().str() : id_;
- pn_connection_set_container(impl_->connection, id.c_str());
- impl_->check(pn_transport_bind(impl_->transport, impl_->connection), "engine bind: ");
- pn_connection_collect(impl_->connection, impl_->collector);
-}
-
-engine::~engine() {}
-
-buffer<char> engine::input() {
- ssize_t n = pn_transport_capacity(impl_->transport);
- if (n <= 0)
- return buffer<char>();
- return buffer<char>(pn_transport_tail(impl_->transport), size_t(n));
-}
-
-void engine::close_input() {
- pn_transport_close_tail(impl_->transport);
- run();
-}
-
-void engine::received(size_t n) {
- impl_->check(pn_transport_process(impl_->transport, n), "engine process: ");
- run();
-}
-
-void engine::run() {
- for (pn_event_t *e = impl_->peek(); e; e = impl_->peek()) {
- switch (pn_event_type(e)) {
- case PN_CONNECTION_REMOTE_CLOSE:
- pn_transport_close_tail(impl_->transport);
- break;
- case PN_CONNECTION_LOCAL_CLOSE:
- pn_transport_close_head(impl_->transport);
- break;
- default:
- break;
- }
- messaging_event mevent(e, pn_event_type(e), this);
- mevent.dispatch(impl_->handler);
- impl_->pop();
- }
-}
-
-buffer<const char> engine::output() {
- ssize_t n = pn_transport_pending(impl_->transport);
- if (n <= 0)
- return buffer<const char>();
- return buffer<const char>(pn_transport_head(impl_->transport), size_t(n));
-}
-
-void engine::sent(size_t n) {
- pn_transport_pop(impl_->transport, n);
- run();
-}
-
-void engine::close_output() {
- pn_transport_close_head(impl_->transport);
- run();
-}
-
-bool engine::closed() const {
- return pn_transport_closed(impl_->transport);
-}
-
-class connection engine::connection() const {
- return impl_->connection;
-}
-
-std::string engine::id() const { return connection().container_id(); }
-
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/proton-c/bindings/cpp/src/event.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/event.cpp b/proton-c/bindings/cpp/src/event.cpp
index b3e93d8..fd0e995 100644
--- a/proton-c/bindings/cpp/src/event.cpp
+++ b/proton-c/bindings/cpp/src/event.cpp
@@ -23,7 +23,6 @@
#include "proton/event.h"
#include "proton/delivery.hpp"
-#include "proton/engine.hpp"
#include "proton/error.hpp"
#include "proton/event.hpp"
#include "proton/handler.hpp"
@@ -39,20 +38,11 @@ event::event() {}
event::~event() {}
-event_loop& event::event_loop() const {
- throw error(MSG("No event_loop context for event"));
-}
-
container& event::container() const {
// Subclasses to override as appropriate
throw error(MSG("No container context for event"));
}
-engine& event::engine() const {
- // Subclasses to override as appropriate
- throw error(MSG("No engine context for event"));
-}
-
connection event::connection() const {
throw error(MSG("No connection context for event"));
}
@@ -77,5 +67,4 @@ class message &event::message() const {
throw error(MSG("No message associated with event"));
}
-event_loop::~event_loop() {}
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/proton-c/bindings/cpp/src/messaging_event.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/messaging_event.cpp b/proton-c/bindings/cpp/src/messaging_event.cpp
index 6574a55..b31e6f9 100644
--- a/proton-c/bindings/cpp/src/messaging_event.cpp
+++ b/proton-c/bindings/cpp/src/messaging_event.cpp
@@ -40,12 +40,12 @@
namespace proton {
-messaging_event::messaging_event(pn_event_t *ce, proton_event::event_type t, class event_loop *el) :
- proton_event(ce, t, el), type_(messaging_event::PROTON), parent_event_(0), message_(0)
+messaging_event::messaging_event(pn_event_t *ce, proton_event::event_type t, class container *c) :
+ proton_event(ce, t, c), type_(messaging_event::PROTON), parent_event_(0), message_(0)
{}
messaging_event::messaging_event(event_type t, proton_event &p) :
- proton_event(NULL, PN_EVENT_NONE, &p.event_loop()), type_(t), parent_event_(&p), message_(0)
+ proton_event(NULL, PN_EVENT_NONE, p.container_), type_(t), parent_event_(&p), message_(0)
{
if (type_ == messaging_event::PROTON)
throw error(MSG("invalid messaging event type"));
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/proton-c/bindings/cpp/src/messaging_event.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/messaging_event.hpp b/proton-c/bindings/cpp/src/messaging_event.hpp
index 13d2da3..31ba7d2 100644
--- a/proton-c/bindings/cpp/src/messaging_event.hpp
+++ b/proton-c/bindings/cpp/src/messaging_event.hpp
@@ -67,7 +67,7 @@ class messaging_event : public proton_event
TIMER
};
- messaging_event(pn_event_t *, proton_event::event_type, class event_loop *);
+ messaging_event(pn_event_t *, proton_event::event_type, class container *);
messaging_event(event_type t, proton_event &parent);
~messaging_event();
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/proton-c/bindings/cpp/src/proton_event.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/proton_event.cpp b/proton-c/bindings/cpp/src/proton_event.cpp
index ce61921..fca96c4 100644
--- a/proton-c/bindings/cpp/src/proton_event.cpp
+++ b/proton-c/bindings/cpp/src/proton_event.cpp
@@ -24,7 +24,6 @@
#include "proton/link.h"
#include "proton/container.hpp"
-#include "proton/engine.hpp"
#include "proton/delivery.hpp"
#include "proton/error.hpp"
#include "proton_event.hpp"
@@ -37,10 +36,10 @@
namespace proton {
-proton_event::proton_event(pn_event_t *ce, proton_event::event_type t, class event_loop *el) :
+proton_event::proton_event(pn_event_t *ce, proton_event::event_type t, class container *c) :
pn_event_(ce),
type_(t),
- event_loop_(el)
+ container_(c)
{}
int proton_event::type() const { return type_; }
@@ -49,24 +48,10 @@ std::string proton_event::name() const { return pn_event_type_name(pn_event_type
pn_event_t *proton_event::pn_event() const { return pn_event_; }
-event_loop& proton_event::event_loop() const {
- if (!event_loop_)
- throw error(MSG("No event_loop context for this event"));
- return *event_loop_;
-}
-
container& proton_event::container() const {
- class container *c = dynamic_cast<class container*>(event_loop_);
- if (!c)
+ if (!container_)
throw error(MSG("No container context for this event"));
- return *c;
-}
-
-engine& proton_event::engine() const {
- class engine *e = dynamic_cast<class engine*>(event_loop_);
- if (!e)
- throw error(MSG("No engine context for this event"));
- return *e;
+ return *container_;
}
connection proton_event::connection() const {
@@ -207,5 +192,3 @@ const proton_event::event_type proton_event::SELECTABLE_ERROR=PN_SELECTABLE_ERRO
const proton_event::event_type proton_event::SELECTABLE_EXPIRED=PN_SELECTABLE_EXPIRED;
const proton_event::event_type proton_event::SELECTABLE_FINAL=PN_SELECTABLE_FINAL;
}
-
-
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3e143ac/proton-c/bindings/cpp/src/proton_event.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/proton_event.hpp b/proton-c/bindings/cpp/src/proton_event.hpp
index 04a3e54..d65dc70 100644
--- a/proton-c/bindings/cpp/src/proton_event.hpp
+++ b/proton-c/bindings/cpp/src/proton_event.hpp
@@ -31,7 +31,6 @@ namespace proton {
class handler;
class container;
class connection;
-class container;
/** Event information for a proton::proton_handler */
class proton_event : public event
@@ -273,9 +272,7 @@ class proton_event : public event
///@}
virtual void dispatch(handler &h);
- virtual class event_loop& event_loop() const;
virtual class container& container() const;
- virtual class engine& engine() const;
virtual class connection connection() const;
virtual class sender sender() const;
virtual class receiver receiver() const;
@@ -288,12 +285,13 @@ class proton_event : public event
pn_event_t* pn_event() const;
protected:
- proton_event(pn_event_t *, proton_event::event_type, class event_loop *);
+ proton_event(pn_event_t *, proton_event::event_type, class container*);
private:
mutable pn_event_t *pn_event_;
event_type type_;
- class event_loop *event_loop_;
+ class container *container_;
+ friend class messaging_event;
};
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org