Permalink
Browse files

implemented logging and default_protocol

libcppa emits log4j compatible output now to make use of available tools;
middleman uses `continuable_writer` and `continuable_reader` interfaces only;
´default_protocol´ encapsulates libcppa's binary protocol now;
`remote_actor` checks wheter a previous connection to the host already exists;
actor proxies are stored as weak pointers in peers, fixes #75;
`default_peer` created with `remote_actor` close connection on last proxy exit;
poll and epoll share meta data implementation and event-interface;
no global proxy cache, belongs to `protocol`/`actor_addressing` now;
new configure option: `--with-cppa-log-level`;
`to_string` is no longer a template (enables proper overload resolution)
  • Loading branch information...
1 parent 88953ad commit 561b43b0ddd278104ba96e415aa563929d7f8efe @Neverlord Neverlord committed Oct 16, 2012
Showing with 2,564 additions and 1,424 deletions.
  1. +7 −0 CMakeLists.txt
  2. +28 −0 configure
  3. +17 −10 cppa.files
  4. +78 −0 cppa/actor_addressing.hpp
  5. +23 −28 cppa/actor_proxy.hpp
  6. +11 −4 cppa/binary_deserializer.hpp
  7. +3 −1 cppa/binary_serializer.hpp
  8. +8 −1 cppa/deserializer.hpp
  9. +0 −108 cppa/detail/actor_proxy_cache.hpp
  10. +236 −0 cppa/detail/logging.hpp
  11. +3 −0 cppa/detail/singleton_manager.hpp
  12. +11 −27 cppa/network/continuable_reader.hpp
  13. +29 −19 cppa/network/{peer_acceptor.hpp → continuable_writer.hpp}
  14. +33 −38 cppa/network/{default_peer_impl.hpp → default_actor_addressing.hpp}
  15. +84 −0 cppa/network/default_actor_proxy.hpp
  16. +142 −0 cppa/network/default_peer.hpp
  17. +14 −6 cppa/network/{default_peer_acceptor_impl.hpp → default_peer_acceptor.hpp}
  18. +96 −0 cppa/network/default_protocol.hpp
  19. +25 −32 cppa/network/middleman.hpp
  20. +50 −49 cppa/network/{peer.hpp → protocol.hpp}
  21. +8 −2 cppa/serializer.hpp
  22. +28 −26 cppa/to_string.hpp
  23. +17 −2 cppa/weak_intrusive_ptr.hpp
  24. +2 −2 examples/group_chat.cpp
  25. +1 −78 src/actor_proxy.cpp
  26. +0 −128 src/actor_proxy_cache.cpp
  27. +7 −0 src/actor_registry.cpp
  28. +6 −6 src/binary_deserializer.cpp
  29. +2 −1 src/binary_serializer.cpp
  30. +4 −7 src/continuable_reader.cpp
  31. +2 −12 src/{peer.cpp → continuable_writer.cpp}
  32. +201 −0 src/default_actor_addressing.cpp
  33. +154 −0 src/default_actor_proxy.cpp
  34. +367 −0 src/default_peer.cpp
  35. +17 −9 src/{default_peer_acceptor_impl.cpp → default_peer_acceptor.cpp}
  36. +0 −284 src/default_peer_impl.cpp
  37. +214 −0 src/default_protocol.cpp
  38. +3 −2 src/deserializer.cpp
  39. +140 −0 src/logging.cpp
  40. +354 −393 src/middleman.cpp
  41. +25 −7 src/{peer_acceptor.cpp → protocol.cpp}
  42. +3 −2 src/serializer.cpp
  43. +21 −1 src/singleton_manager.cpp
  44. +16 −7 src/string_serialization.cpp
  45. +12 −36 src/unicast_network.cpp
  46. +11 −57 src/uniform_type_info.cpp
  47. +37 −26 unit_testing/ping_pong.cpp
  48. +11 −4 unit_testing/test__remote_actor.cpp
  49. +3 −9 unit_testing/test__serialization.cpp
View
7 CMakeLists.txt
@@ -65,6 +65,12 @@ if (ENABLE_DEBUG)
# set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif ()
+if (CPPA_LOG_LEVEL)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCPPA_LOG_LEVEL=${CPPA_LOG_LEVEL}")
+else ()
+ set(CPPA_LOG_LEVEL "0")
+endif()
+
# set build default build type if not set
if (CMAKE_BUILD_TYPE)
else (CMAKE_BUILD_TYPE)
@@ -207,6 +213,7 @@ message("\n====================| Build Summary |===================="
"\n"
"\nBuild type: ${CMAKE_BUILD_TYPE}"
"\nDebug mode: ${ENABLE_DEBUG}"
+ "\nLog level: ${CPPA_LOG_LEVEL}"
"\nContext switching: ${CONTEXT_SWITCHING}"
"\n"
"\nCXX: ${CMAKE_CXX_COMPILER}"
View
28 configure
@@ -37,6 +37,12 @@ Usage: $0 [OPTION]... [VAR=VALUE]...
--enable-debug compile in debugging mode
(always sets --build-type=Debug)
--enable-perftools use Google perftools
+ --with-cppa-log-level=LVL sets the debugging output, possible values:
+ - WARNING
+ - INFO
+ - DEBUG
+ - TRACE
+ (implicitly sets --enable-debug)
Platform-Dependent Adjustments:
--disable-context-switching compile libcppa without context-switching actors
@@ -147,6 +153,28 @@ while [ $# -ne 0 ]; do
--enable-debug)
append_cache_entry ENABLE_DEBUG BOOL true
;;
+ --with-cppa-log-level=*)
+ level=$(echo "$optarg" | tr '[:lower:]' '[:upper:]')
+ case $level in
+ WARNING)
+ append_cache_entry CPPA_LOG_LEVEL STRING 1
+ ;;
+ INFO)
+ append_cache_entry CPPA_LOG_LEVEL STRING 2
+ ;;
+ DEBUG)
+ append_cache_entry CPPA_LOG_LEVEL STRING 3
+ ;;
+ TRACE)
+ append_cache_entry CPPA_LOG_LEVEL STRING 4
+ ;;
+ *)
+ echo "Invalid log level '$level'. Try '$0 --help' to see valid values."
+ exit 1
+ ;;
+ esac
+ append_cache_entry ENABLE_DEBUG BOOL true
+ ;;
--disable-context-switching)
append_cache_entry DISABLE_CONTEXT_SWITCHING BOOL true
;;
View
27 cppa.files
@@ -38,7 +38,7 @@ cppa/deserializer.hpp
cppa/detail/abstract_scheduled_actor.hpp
cppa/detail/abstract_tuple.hpp
cppa/detail/actor_count.hpp
-cppa/detail/actor_proxy_cache.hpp
+cppa/actor_addressing.hpp
cppa/detail/actor_registry.hpp
cppa/network/addressed_message.hpp
cppa/detail/atom_val.hpp
@@ -174,7 +174,6 @@ src/abstract_tuple.cpp
src/actor.cpp
src/actor_count.cpp
src/actor_proxy.cpp
-src/actor_proxy_cache.cpp
src/actor_registry.cpp
src/addressed_message.cpp
src/any_tuple.cpp
@@ -269,16 +268,24 @@ cppa/detail/opt_impls.hpp
examples/type_plugins.hpp
cppa/detail/decorated_names_map.hpp
src/decorated_names_map.cpp
-cppa/network/peer_acceptor.hpp
-src/peer_acceptor.cpp
-cppa/network/peer.hpp
-src/peer.cpp
cppa/network/continuable_reader.hpp
src/continuable_reader.cpp
-cppa/network/default_peer_impl.hpp
-src/default_peer_impl.cpp
-cppa/network/default_peer_acceptor_impl.hpp
-src/default_peer_acceptor_impl.cpp
+cppa/network/default_peer.hpp
+src/default_peer.cpp
+cppa/network/default_peer_acceptor.hpp
+src/default_peer_acceptor.cpp
src/ref_counted.cpp
cppa/enable_weak_ptr_mixin.hpp
cppa/weak_intrusive_ptr.hpp
+cppa/network/default_actor_proxy.hpp
+src/default_actor_proxy.cpp
+cppa/network/default_actor_addressing.hpp
+src/default_actor_addressing.cpp
+cppa/network/protocol.hpp
+src/protocol.cpp
+cppa/network/default_protocol.hpp
+src/default_protocol.cpp
+cppa/detail/logging.hpp
+src/logging.cpp
+cppa/network/continuable_writer.hpp
+src/continuable_writer.cpp
View
78 cppa/actor_addressing.hpp
@@ -0,0 +1,78 @@
+/******************************************************************************\
+ * ___ __ *
+ * /\_ \ __/\ \ *
+ * \//\ \ /\_\ \ \____ ___ _____ _____ __ *
+ * \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
+ * \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
+ * /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
+ * \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
+ * \ \_\ \ \_\ *
+ * \/_/ \/_/ *
+ * *
+ * Copyright (C) 2011, 2012 *
+ * Dominik Charousset <dominik.charousset@haw-hamburg.de> *
+ * *
+ * This file is part of libcppa. *
+ * libcppa is free software: you can redistribute it and/or modify it under *
+ * the terms of the GNU Lesser General Public License as published by the *
+ * Free Software Foundation, either version 3 of the License *
+ * or (at your option) any later version. *
+ * *
+ * libcppa is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
+ * See the GNU Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public License *
+ * along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
+\******************************************************************************/
+
+
+#ifndef CPPA_ACTOR_PROXY_CACHE_HPP
+#define CPPA_ACTOR_PROXY_CACHE_HPP
+
+#include "cppa/atom.hpp"
+#include "cppa/actor.hpp"
+#include "cppa/ref_counted.hpp"
+
+namespace cppa {
+
+class serializer;
+class deserializer;
+
+/**
+ * @brief Different serialization protocols have different representations
+ * for actors. This class encapsulates a technology-specific
+ * actor addressing.
+ */
+class actor_addressing : public ref_counted {
+
+ public:
+
+ /**
+ * @brief Returns the technology identifier of the implementation.
+ * @note All-uppercase identifiers are reserved for libcppa's
+ * builtin implementations.
+ */
+ virtual atom_value technology_id() const = 0;
+
+ /**
+ * @brief Serializes @p ptr to @p sink according
+ * to the implemented addressing.
+ * @note Implementation should call {@link actor_registry::put()}
+ * to be able to restore instances later on from registry.
+ * @note Thi
+ */
+ virtual void write(serializer* sink, const actor_ptr& ptr) = 0;
+
+ /**
+ * @brief Deserializes an actor from @p source according
+ * to the implemented addressing.
+ */
+ virtual actor_ptr read(deserializer* source) = 0;
+
+};
+
+} // namespace cppa::detail
+
+#endif // CPPA_ACTOR_PROXY_CACHE_HPP
View
51 cppa/actor_proxy.hpp
@@ -32,57 +32,52 @@
#define CPPA_ACTOR_PROXY_HPP
#include "cppa/actor.hpp"
-#include "cppa/detail/abstract_actor.hpp"
+#include "cppa/weak_intrusive_ptr.hpp"
+#include "cppa/enable_weak_ptr_mixin.hpp"
namespace cppa {
-#ifdef CPPA_DOCUMENTATION
+class actor_proxy_cache;
/**
* @brief Represents a remote actor.
*/
-class actor_proxy : public actor { };
+class actor_proxy : public enable_weak_ptr_mixin<actor_proxy,actor> {
-#else // CPPA_DOCUMENTATION
-
-class actor_proxy : public detail::abstract_actor<actor> {
-
- typedef abstract_actor<actor> super;
+ typedef enable_weak_ptr_mixin<actor_proxy,actor> super;
public:
- actor_proxy(std::uint32_t mid, const process_information_ptr& parent);
-
- void enqueue(actor* sender, any_tuple msg);
-
- void sync_enqueue(actor* sender, message_id_t id, any_tuple msg);
-
- void link_to(const intrusive_ptr<actor>& other);
-
- // do not cause to send this actor an "UNLINK" message
- // to the "original" remote actor
- void local_link_to(const intrusive_ptr<actor>& other);
+ /**
+ * @brief Establishes a local link state that's not synchronized back
+ * to the remote instance.
+ */
+ virtual void local_link_to(const intrusive_ptr<actor>& other) = 0;
- void unlink_from(const intrusive_ptr<actor>& other);
+ /**
+ * @brief Removes a local link state.
+ */
+ virtual void local_unlink_from(const actor_ptr& other) = 0;
- // do not cause to send this actor an "UNLINK" message
- // to the "original" remote actor
- void local_unlink_from(const actor_ptr& other);
+ protected:
- bool remove_backlink(const intrusive_ptr<actor>& to);
-
- bool establish_backlink(const intrusive_ptr<actor>& to);
+ actor_proxy(actor_id mid,
+ const process_information_ptr& pinfo);
};
-#endif // CPPA_DOCUMENTATION
-
/**
* @brief A smart pointer to an {@link actor_proxy} instance.
* @relates actor_proxy
*/
typedef intrusive_ptr<actor_proxy> actor_proxy_ptr;
+/**
+ * @brief A weak smart pointer to an {@link actor_proxy} instance.
+ * @relates actor_proxy
+ */
+typedef weak_intrusive_ptr<actor_proxy> weak_actor_proxy_ptr;
+
} // namespace cppa
#endif // CPPA_ACTOR_PROXY_HPP
View
15 cppa/binary_deserializer.hpp
@@ -41,13 +41,15 @@ namespace cppa {
*/
class binary_deserializer : public deserializer {
- const char* pos;
- const char* end;
+ typedef deserializer super;
public:
- binary_deserializer(const char* buf, size_t buf_size);
- binary_deserializer(const char* begin, const char* end);
+ binary_deserializer(const char* buf, size_t buf_size,
+ actor_addressing* addressing = nullptr);
+
+ binary_deserializer(const char* begin, const char* end,
+ actor_addressing* addressing = nullptr);
std::string seek_object();
std::string peek_object();
@@ -61,6 +63,11 @@ class binary_deserializer : public deserializer {
primitive_variant* storage);
void read_raw(size_t num_bytes, void* storage);
+ private:
+
+ const char* pos;
+ const char* end;
+
};
} // namespace cppa
View
4 cppa/binary_serializer.hpp
@@ -46,13 +46,15 @@ namespace detail { class binary_writer; }
*/
class binary_serializer : public serializer {
+ typedef serializer super;
+
public:
/**
* @brief Creates a binary serializer writing to @p write_buffer.
* @warning @p write_buffer must be guaranteed to outlive @p this
*/
- binary_serializer(util::buffer* write_buffer);
+ binary_serializer(util::buffer* write_buffer, actor_addressing* ptr = 0);
void begin_object(const std::string& tname);
View
9 cppa/deserializer.hpp
@@ -40,6 +40,7 @@
namespace cppa {
class object;
+class actor_addressing;
/**
* @ingroup TypeSystem
@@ -52,7 +53,7 @@ class deserializer {
public:
- deserializer() = default;
+ deserializer(actor_addressing* addressing = nullptr);
virtual ~deserializer();
@@ -113,6 +114,12 @@ class deserializer {
*/
virtual void read_raw(size_t num_bytes, void* storage) = 0;
+ inline actor_addressing* addressing() { return m_addressing; }
+
+ private:
+
+ actor_addressing* m_addressing;
+
};
/**
View
108 cppa/detail/actor_proxy_cache.hpp
@@ -1,108 +0,0 @@
-/******************************************************************************\
- * ___ __ *
- * /\_ \ __/\ \ *
- * \//\ \ /\_\ \ \____ ___ _____ _____ __ *
- * \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
- * \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
- * /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
- * \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
- * \ \_\ \ \_\ *
- * \/_/ \/_/ *
- * *
- * Copyright (C) 2011, 2012 *
- * Dominik Charousset <dominik.charousset@haw-hamburg.de> *
- * *
- * This file is part of libcppa. *
- * libcppa is free software: you can redistribute it and/or modify it under *
- * the terms of the GNU Lesser General Public License as published by the *
- * Free Software Foundation, either version 3 of the License *
- * or (at your option) any later version. *
- * *
- * libcppa is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
- * See the GNU Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public License *
- * along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
-\******************************************************************************/
-
-
-#ifndef CPPA_ACTOR_PROXY_CACHE_HPP
-#define CPPA_ACTOR_PROXY_CACHE_HPP
-
-#include <mutex>
-#include <thread>
-#include <string>
-#include <limits>
-#include <vector>
-#include <functional>
-
-#include "cppa/actor_proxy.hpp"
-#include "cppa/process_information.hpp"
-
-#include "cppa/util/shared_spinlock.hpp"
-
-namespace cppa { namespace detail {
-
-class actor_proxy_cache {
-
- public:
-
- // returns existing instance if available or crates a new one
- actor_proxy_ptr get_or_put(actor_id aid,
- std::uint32_t process_id,
- const process_information::node_id_type& node_id);
-
- actor_proxy_ptr get(actor_id aid,
- std::uint32_t process_id,
- const process_information::node_id_type& node_id);
-
- // @returns true if pptr was successfully removed, false otherwise
- bool erase(const actor_proxy_ptr& pptr);
-
- template<typename Fun>
- void erase_all(const process_information::node_id_type& nid,
- std::uint32_t process_id,
- Fun fun) {
- key_tuple lb{nid, process_id, std::numeric_limits<actor_id>::min()};
- key_tuple ub{nid, process_id, std::numeric_limits<actor_id>::max()};
- { // lifetime scope of guard
- std::lock_guard<util::shared_spinlock> guard(m_lock);
- auto e = m_entries.end();
- auto first = m_entries.lower_bound(lb);
- if (first != e) {
- auto last = m_entries.upper_bound(ub);
- for (auto i = first; i != last; ++i) {
- fun(i->second);
- }
- m_entries.erase(first, last);
- }
- }
- }
-
- private:
-
- typedef std::tuple<process_information::node_id_type, // node id
- std::uint32_t, // process id
- actor_id> // (remote) actor id
- key_tuple;
-
- struct key_tuple_less {
- bool operator()(const key_tuple& lhs, const key_tuple& rhs) const;
- };
-
- util::shared_spinlock m_lock;
- std::map<key_tuple, actor_proxy_ptr, key_tuple_less> m_entries;
-
- actor_proxy_ptr get_impl(const key_tuple& key, bool do_put);
-
-
-};
-
-// get the thread-local cache object
-actor_proxy_cache& get_actor_proxy_cache();
-
-} } // namespace cppa::detail
-
-#endif // CPPA_ACTOR_PROXY_CACHE_HPP
View
236 cppa/detail/logging.hpp
@@ -0,0 +1,236 @@
+/******************************************************************************\
+ * ___ __ *
+ * /\_ \ __/\ \ *
+ * \//\ \ /\_\ \ \____ ___ _____ _____ __ *
+ * \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
+ * \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
+ * /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
+ * \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
+ * \ \_\ \ \_\ *
+ * \/_/ \/_/ *
+ * *
+ * Copyright (C) 2011, 2012 *
+ * Dominik Charousset <dominik.charousset@haw-hamburg.de> *
+ * *
+ * This file is part of libcppa. *
+ * libcppa is free software: you can redistribute it and/or modify it under *
+ * the terms of the GNU Lesser General Public License as published by the *
+ * Free Software Foundation, either version 3 of the License *
+ * or (at your option) any later version. *
+ * *
+ * libcppa is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
+ * See the GNU Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public License *
+ * along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
+\******************************************************************************/
+
+
+#ifndef CPPA_LOGGING_HPP
+#define CPPA_LOGGING_HPP
+
+#include <sstream>
+
+#include "cppa/detail/demangle.hpp"
+
+/*
+ * To enable logging, you have to define CPPA_DEBUG. This enables
+ * CPPA_LOG_ERROR messages. To enable more debugging output, you can define
+ * CPPA_LOG_LEVEL to:
+ * 1: + warning
+ * 2: + info
+ * 3: + debug
+ * 4: + trace (prints for each logged method entry and exit message)
+ *
+ * Note: this logger emits log4j style XML output; logs are best viewed
+ * using a log4j viewer, e.g., http://code.google.com/p/otroslogviewer/
+ *
+ */
+
+
+namespace cppa { namespace detail {
+
+class logging {
+
+ public:
+
+ virtual ~logging();
+
+ virtual void log(const char* level,
+ const char* class_name,
+ const char* function_name,
+ const char* file_name,
+ int line_num,
+ const std::string& msg ) = 0;
+
+ virtual void start() = 0;
+
+ virtual void stop() = 0;
+
+ static logging* instance();
+
+ static logging* create_singleton();
+
+ class trace_helper {
+
+ public:
+
+ inline trace_helper(std::string class_name,
+ const char* fun_name,
+ const char* file_name,
+ int line_num,
+ const std::string& msg)
+ : m_class(std::move(class_name)), m_fun_name(fun_name)
+ , m_file_name(file_name), m_line_num(line_num) {
+ logging::instance()->log("TRACE ", m_class.c_str(), fun_name,
+ file_name, line_num, "ENTRY " + msg);
+ }
+
+ inline ~trace_helper() {
+ logging::instance()->log("TRACE ", m_class.c_str(), m_fun_name,
+ m_file_name, m_line_num, "EXIT");
+ }
+
+ private:
+
+ std::string m_class;
+ const char* m_fun_name;
+ const char* m_file_name;
+ int m_line_num;
+
+ };
+
+};
+
+} } // namespace cppa::detail
+
+#ifndef CPPA_DEBUG
+
+#define CPPA_LOG_ERROR(unused) static_cast<void>(0)
+#define CPPA_LOG_ERROR_IF(unused1,unused2) static_cast<void>(0)
+#define CPPA_LOGF_ERROR(unused) static_cast<void>(0)
+#define CPPA_LOGF_ERROR_IF(unused1,unused2) static_cast<void>(0)
+
+#define CPPA_LOG_WARNING(unused) static_cast<void>(0)
+#define CPPA_LOG_WARNING_IF(unused1,unused2) static_cast<void>(0)
+#define CPPA_LOGF_WARNING(unused) static_cast<void>(0)
+#define CPPA_LOGF_WARNING_IF(unused1,unused2) static_cast<void>(0)
+
+#define CPPA_LOG_INFO(unused) static_cast<void>(0)
+#define CPPA_LOG_INFO_IF(unused1,unused2) static_cast<void>(0)
+#define CPPA_LOGF_INFO(unused) static_cast<void>(0)
+#define CPPA_LOGF_INFO_IF(unused1,unused2) static_cast<void>(0)
+
+#define CPPA_LOG_DEBUG(unused) static_cast<void>(0)
+#define CPPA_LOG_DEBUG_IF(unused1,unused2) static_cast<void>(0)
+#define CPPA_LOGF_DEBUG(unused) static_cast<void>(0)
+#define CPPA_LOGF_DEBUG_IF(unused1,unused2) static_cast<void>(0)
+
+#define CPPA_LOG_TRACE(unused) static_cast<void>(0)
+#define CPPA_LOGF_TRACE(unused) static_cast<void>(0)
+
+#else
+
+#define CPPA_DO_LOG_FUN(level, message) { \
+ std::ostringstream scoped_oss; scoped_oss << message; \
+ ::cppa::detail::logging::instance()->log( \
+ level, "NONE", \
+ __FUNCTION__, __FILE__, __LINE__, scoped_oss.str()); \
+} static_cast<void>(0)
+
+#define CPPA_DO_LOG_MEMBER_FUN(level, message) { \
+ std::ostringstream scoped_oss; scoped_oss << message; \
+ ::cppa::detail::logging::instance()->log( \
+ level, ::cppa::detail::demangle(typeid(*this)).c_str(), \
+ __FUNCTION__, __FILE__, __LINE__, scoped_oss.str()); \
+} static_cast<void>(0)
+
+#define CPPA_LOG_ERROR(message) CPPA_DO_LOG_MEMBER_FUN("ERROR ", message)
+#define CPPA_LOGF_ERROR(message) CPPA_DO_LOG_FUN("ERROR ", message)
+
+#if CPPA_LOG_LEVEL > 0
+# define CPPA_LOG_WARNING(message) CPPA_DO_LOG_MEMBER_FUN("WARNING", message)
+# define CPPA_LOGF_WARNING(message) CPPA_DO_LOG_FUN("WARNING", message)
+#else
+# define CPPA_LOG_WARNING(unused) static_cast<void>(0)
+# define CPPA_LOGF_WARNING(unused) static_cast<void>(0)
+#endif
+
+#if CPPA_LOG_LEVEL > 1
+# define CPPA_LOG_INFO(message) CPPA_DO_LOG_MEMBER_FUN("INFO ", message)
+# define CPPA_LOGF_INFO(message) CPPA_DO_LOG_FUN("INFO ", message)
+#else
+# define CPPA_LOG_INFO(unused) static_cast<void>(0)
+# define CPPA_LOGF_INFO(unused) static_cast<void>(0)
+#endif
+
+#if CPPA_LOG_LEVEL > 2
+# define CPPA_LOG_DEBUG(message) CPPA_DO_LOG_MEMBER_FUN("DEBUG ", message)
+# define CPPA_LOGF_DEBUG(message) CPPA_DO_LOG_FUN("DEBUG ", message)
+#else
+# define CPPA_LOG_DEBUG(unused) static_cast<void>(0)
+# define CPPA_LOGF_DEBUG(unused) static_cast<void>(0)
+#endif
+
+#if CPPA_LOG_LEVEL > 3
+# define CPPA_RPAREN )
+# define CPPA_LPAREN (
+# define CPPA_GET(what) what
+# define CPPA_CONCAT_I(lhs,rhs) lhs ## rhs
+# define CPPA_CONCAT(lhs,rhs) CPPA_CONCAT_I(lhs,rhs)
+# define CPPA_CONCATL(lhs) CPPA_CONCAT(lhs, __LINE__)
+# define CPPA_LOG_TRACE(message) \
+ ::std::ostringstream CPPA_CONCATL(cppa_trace_helper_) ; \
+ CPPA_CONCATL(cppa_trace_helper_) << message ; \
+ ::cppa::detail::logging::trace_helper CPPA_CONCATL(cppa_fun_trace_helper_) \
+ CPPA_LPAREN ::cppa::detail::demangle \
+ CPPA_LPAREN typeid CPPA_LPAREN *this CPPA_RPAREN CPPA_RPAREN , \
+ __func__ , __FILE__ , __LINE__ , \
+ CPPA_CONCATL(cppa_trace_helper_) .str() CPPA_RPAREN
+# define CPPA_LOGF_TRACE(message) \
+ ::std::ostringstream CPPA_CONCATL(cppa_trace_helper_) ; \
+ CPPA_CONCATL(cppa_trace_helper_) << message ; \
+ ::cppa::detail::logging::trace_helper CPPA_CONCATL(cppa_fun_trace_helper_) \
+ CPPA_LPAREN "NONE" , \
+ __func__ , __FILE__ , __LINE__ , \
+ CPPA_CONCATL(cppa_trace_helper_) .str() CPPA_RPAREN
+
+#else
+# define CPPA_LOG_TRACE(unused)
+# define CPPA_LOGF_TRACE(unused)
+#endif
+
+#define CPPA_LOG_ERROR_IF(stmt,message) \
+ if (stmt) { CPPA_LOG_ERROR(message); }; static_cast<void>(0)
+
+#define CPPA_LOG_WARNING_IF(stmt,message) \
+ if (stmt) { CPPA_LOG_WARNING(message); }; static_cast<void>(0)
+
+#define CPPA_LOG_INFO_IF(stmt,message) \
+ if (stmt) { CPPA_LOG_INFO(message); }; static_cast<void>(0)
+
+#define CPPA_LOG_DEBUG_IF(stmt,message) \
+ if (stmt) { CPPA_LOG_DEBUG(message); }; static_cast<void>(0)
+
+#define CPPA_LOGF_ERROR_IF(stmt,message) \
+ if (stmt) { CPPA_LOGF_ERROR(message); }; static_cast<void>(0)
+
+#define CPPA_LOGF_WARNING_IF(stmt,message) \
+ if (stmt) { CPPA_LOGF_WARNING(message); }; static_cast<void>(0)
+
+#define CPPA_LOGF_INFO_IF(stmt,message) \
+ if (stmt) { CPPA_LOGF_INFO(message); }; static_cast<void>(0)
+
+#define CPPA_LOGF_DEBUG_IF(stmt,message) \
+ if (stmt) { CPPA_LOGF_DEBUG(message); }; static_cast<void>(0)
+
+
+#endif // CPPA_DEBUG
+
+#define CPPA_ARG(arg) #arg << " = " << arg
+#define CPPA_TARG(arg, trans) #arg << " = " << trans ( arg )
+#define CPPA_MARG(arg, memfun) #arg << " = " << arg . memfun ()
+
+#endif // CPPA_LOGGING_HPP
View
3 cppa/detail/singleton_manager.hpp
@@ -44,6 +44,7 @@ namespace cppa { namespace network { class middleman; } }
namespace cppa { namespace detail {
+class logging;
class empty_tuple;
class group_manager;
class abstract_tuple;
@@ -59,6 +60,8 @@ class singleton_manager {
static void shutdown();
+ static logging* get_logger();
+
static scheduler* get_scheduler();
static bool set_scheduler(scheduler*);
View
38 cppa/network/continuable_reader.hpp
@@ -31,10 +31,13 @@
#ifndef CONTINUABLE_READER_HPP
#define CONTINUABLE_READER_HPP
+#include "cppa/atom.hpp"
#include "cppa/actor.hpp"
#include "cppa/config.hpp"
#include "cppa/ref_counted.hpp"
+#include "cppa/network/protocol.hpp"
+
namespace cppa { namespace network {
class middleman;
@@ -45,53 +48,34 @@ enum continue_reading_result {
read_continue_later
};
-class continuable_reader : public ref_counted {
+class continuable_writer;
+
+class continuable_reader : virtual public ref_counted {
public:
/**
* @brief Returns the file descriptor for incoming data.
*/
- inline native_socket_type read_handle() const {
- return m_read_handle;
- }
+ inline native_socket_type read_handle() const { return m_rd; }
/**
* @brief Reads from {@link read_handle()}.
*/
virtual continue_reading_result continue_reading() = 0;
/**
- * @brief Returns @p true if @p this is a {@link peer_acceptor} that
- * is assigned to the published actor @p whom.
+ * @return Casts @p this to a continuable_writer or returns @p nullptr.
*/
- virtual bool is_acceptor_of(const actor_ptr& whom) const;
-
- /**
- * @brief Returns true if this is a subtype of {@link peer}, i.e.,
- * if @p static_cast<peer*>(this) is well-defined.
- */
- inline bool is_peer() const {
- return m_is_peer;
- }
+ virtual continuable_writer* as_writer();
protected:
- continuable_reader(middleman* parent, native_socket_type rd, bool is_peer);
-
- inline middleman* parent() {
- return m_parent;
- }
-
- inline const middleman* parent() const {
- return m_parent;
- }
+ continuable_reader(native_socket_type rd);
private:
- bool m_is_peer;
- middleman* m_parent;
- native_socket_type m_read_handle;
+ native_socket_type m_rd;
};
View
48 cppa/network/peer_acceptor.hpp → cppa/network/continuable_writer.hpp
@@ -28,42 +28,52 @@
\******************************************************************************/
-#ifndef PEER_ACCEPTOR_HPP
-#define PEER_ACCEPTOR_HPP
+#ifndef CONTINUABLE_WRITER_HPP
+#define CONTINUABLE_WRITER_HPP
-#include "cppa/network/peer.hpp"
-#include "cppa/network/continuable_reader.hpp"
+#include "cppa/config.hpp"
+#include "cppa/ref_counted.hpp"
+#include "cppa/intrusive_ptr.hpp"
namespace cppa { namespace network {
-class peer_acceptor : public continuable_reader {
+enum continue_writing_result {
+ write_failure,
+ write_closed,
+ write_continue_later,
+ write_done
+};
- typedef continuable_reader super;
+class continuable_writer : virtual public ref_counted {
- public:
+ typedef ref_counted super;
- bool is_acceptor_of(const actor_ptr& whom) const;
+ public:
- protected:
+ /**
+ * @brief Returns the file descriptor for outgoing data.
+ */
+ native_socket_type write_handle() const {
+ return m_wr;
+ }
- peer_acceptor(middleman* parent,
- native_socket_type fd,
- const actor_ptr& published_actor);
+ /**
+ * @brief Writes to {@link write_handle()}.
+ */
+ virtual continue_writing_result continue_writing() = 0;
- void add_peer(const peer_ptr& ptr);
+ protected:
- inline const actor_ptr& published_actor() const {
- return m_published_actor;
- }
+ continuable_writer(native_socket_type write_handle);
private:
- actor_ptr m_published_actor;
+ native_socket_type m_wr;
};
-typedef intrusive_ptr<peer_acceptor> peer_acceptor_ptr;
+typedef intrusive_ptr<continuable_writer> continuable_writer_ptr;
} } // namespace cppa::network
-#endif // PEER_ACCEPTOR_HPP
+#endif // CONTINUABLE_WRITER_HPP
View
71 cppa/network/default_peer_impl.hpp → cppa/network/default_actor_addressing.hpp
@@ -28,63 +28,58 @@
\******************************************************************************/
-#ifndef IPV4_PEER_HPP
-#define IPV4_PEER_HPP
+#ifndef CPPA_DEFAULT_ACTOR_ADDRESSING_HPP
+#define CPPA_DEFAULT_ACTOR_ADDRESSING_HPP
-#include "cppa/process_information.hpp"
-
-#include "cppa/util/buffer.hpp"
+#include <map>
+#include <cstdint>
-#include "cppa/network/peer.hpp"
-#include "cppa/network/input_stream.hpp"
-#include "cppa/network/output_stream.hpp"
+#include "cppa/actor_proxy.hpp"
+#include "cppa/actor_addressing.hpp"
+#include "cppa/process_information.hpp"
namespace cppa { namespace network {
-class default_peer_impl : public peer {
+class default_protocol;
- typedef peer super;
+class default_actor_addressing : public actor_addressing {
public:
- default_peer_impl(middleman* parent,
- const input_stream_ptr& in,
- const output_stream_ptr& out,
- process_information_ptr peer_ptr = nullptr);
+ default_actor_addressing(default_protocol* parent = nullptr);
+
+ typedef std::map<actor_id,weak_actor_proxy_ptr> proxy_map;
+
+ atom_value technology_id() const;
+
+ void write(serializer* sink, const actor_ptr& ptr);
+
+ actor_ptr read(deserializer* source);
+
+ // returns the number of proxy instances for given parent
+ size_t count_proxies(const process_information& parent);
+
+ actor_ptr get(const process_information& parent, actor_id aid);
- continue_reading_result continue_reading();
+ actor_ptr get_or_put(const process_information& parent, actor_id aid);
- continue_writing_result continue_writing();
+ void put(const process_information& parent,
+ actor_id aid,
+ const actor_proxy_ptr& proxy);
- bool enqueue(const addressed_message& msg);
+ proxy_map& proxies(process_information& from);
- protected:
+ void erase(process_information& info);
- ~default_peer_impl();
+ void erase(process_information& info, actor_id aid);
private:
- enum read_state {
- // connection just established; waiting for process information
- wait_for_process_info,
- // wait for the size of the next message
- wait_for_msg_size,
- // currently reading a message
- read_message
- };
-
- input_stream_ptr m_in;
- output_stream_ptr m_out;
- read_state m_state;
- process_information_ptr m_peer;
- const uniform_type_info* m_meta_msg;
- bool m_has_unwritten_data;
-
- util::buffer m_rd_buf;
- util::buffer m_wr_buf;
+ default_protocol* m_parent;
+ std::map<process_information,proxy_map> m_proxies;
};
} } // namespace cppa::network
-#endif // IPV4_PEER_HPP
+#endif // CPPA_DEFAULT_ACTOR_ADDRESSING_HPP
View
84 cppa/network/default_actor_proxy.hpp
@@ -0,0 +1,84 @@
+/******************************************************************************\
+ * ___ __ *
+ * /\_ \ __/\ \ *
+ * \//\ \ /\_\ \ \____ ___ _____ _____ __ *
+ * \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
+ * \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
+ * /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
+ * \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
+ * \ \_\ \ \_\ *
+ * \/_/ \/_/ *
+ * *
+ * Copyright (C) 2011, 2012 *
+ * Dominik Charousset <dominik.charousset@haw-hamburg.de> *
+ * *
+ * This file is part of libcppa. *
+ * libcppa is free software: you can redistribute it and/or modify it under *
+ * the terms of the GNU Lesser General Public License as published by the *
+ * Free Software Foundation, either version 3 of the License *
+ * or (at your option) any later version. *
+ * *
+ * libcppa is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
+ * See the GNU Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public License *
+ * along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
+\******************************************************************************/
+
+
+#ifndef DEFAULT_ACTOR_PROXY_HPP
+#define DEFAULT_ACTOR_PROXY_HPP
+
+#include "cppa/actor_proxy.hpp"
+
+#include "cppa/network/default_protocol.hpp"
+
+#include "cppa/detail/abstract_actor.hpp"
+
+namespace cppa { namespace network {
+
+class default_actor_proxy : public detail::abstract_actor<actor_proxy> {
+
+ typedef detail::abstract_actor<actor_proxy> super;
+
+ public:
+
+ default_actor_proxy(actor_id mid,
+ const process_information_ptr& pinfo,
+ const default_protocol_ptr& parent);
+
+ void enqueue(actor* sender, any_tuple msg);
+
+ void sync_enqueue(actor* sender, message_id_t id, any_tuple msg);
+
+ void link_to(const intrusive_ptr<actor>& other);
+
+ void unlink_from(const intrusive_ptr<actor>& other);
+
+ bool remove_backlink(const intrusive_ptr<actor>& to);
+
+ bool establish_backlink(const intrusive_ptr<actor>& to);
+
+ void local_link_to(const intrusive_ptr<actor>& other);
+
+ void local_unlink_from(const actor_ptr& other);
+
+ protected:
+
+ ~default_actor_proxy();
+
+ private:
+
+ void forward_msg(const actor_ptr& sender,
+ any_tuple msg,
+ message_id_t mid = message_id_t());
+
+ default_protocol_ptr m_proto;
+
+};
+
+} } // namespace cppa::network
+
+#endif // DEFAULT_ACTOR_PROXY_HPP
View
142 cppa/network/default_peer.hpp
@@ -0,0 +1,142 @@
+/******************************************************************************\
+ * ___ __ *
+ * /\_ \ __/\ \ *
+ * \//\ \ /\_\ \ \____ ___ _____ _____ __ *
+ * \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
+ * \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
+ * /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
+ * \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
+ * \ \_\ \ \_\ *
+ * \/_/ \/_/ *
+ * *
+ * Copyright (C) 2011, 2012 *
+ * Dominik Charousset <dominik.charousset@haw-hamburg.de> *
+ * *
+ * This file is part of libcppa. *
+ * libcppa is free software: you can redistribute it and/or modify it under *
+ * the terms of the GNU Lesser General Public License as published by the *
+ * Free Software Foundation, either version 3 of the License *
+ * or (at your option) any later version. *
+ * *
+ * libcppa is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
+ * See the GNU Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public License *
+ * along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
+\******************************************************************************/
+
+
+#ifndef CPPA_DEFAULT_PEER_IMPL_HPP
+#define CPPA_DEFAULT_PEER_IMPL_HPP
+
+#include <map>
+#include <cstdint>
+
+#include "cppa/actor_proxy.hpp"
+#include "cppa/partial_function.hpp"
+#include "cppa/weak_intrusive_ptr.hpp"
+#include "cppa/process_information.hpp"
+
+#include "cppa/util/buffer.hpp"
+
+#include "cppa/network/input_stream.hpp"
+#include "cppa/network/output_stream.hpp"
+#include "cppa/network/continuable_reader.hpp"
+#include "cppa/network/continuable_writer.hpp"
+
+namespace cppa { namespace network {
+
+class default_protocol;
+
+class default_peer : public continuable_reader, public continuable_writer {
+
+ typedef continuable_reader lsuper;
+ typedef continuable_writer rsuper;
+
+ public:
+
+ default_peer(default_protocol* parent,
+ const input_stream_ptr& in,
+ const output_stream_ptr& out,
+ process_information_ptr peer_ptr = nullptr);
+
+ continue_reading_result continue_reading();
+
+ continue_writing_result continue_writing();
+
+ continuable_writer* as_writer();
+
+ void enqueue(const addressed_message& msg);
+
+ inline bool erase_on_last_proxy_exited() const {
+ return m_erase_on_last_proxy_exited;
+ }
+
+ inline const process_information& node() const {
+ return *m_node;
+ }
+
+ protected:
+
+ ~default_peer();
+
+ private:
+
+ void disconnected();
+
+ enum read_state {
+ // connection just established; waiting for process information
+ wait_for_process_info,
+ // wait for the size of the next message
+ wait_for_msg_size,
+ // currently reading a message
+ read_message
+ };
+
+ default_protocol* m_parent;
+ input_stream_ptr m_in;
+ output_stream_ptr m_out;
+ read_state m_state;
+ process_information_ptr m_node;
+ const uniform_type_info* m_meta_msg;
+ bool m_has_unwritten_data;
+
+ util::buffer m_rd_buf;
+ util::buffer m_wr_buf;
+
+ // if this peer was created using remote_actor(), then m_doorman will
+ // point to the published actor of the remote node
+ bool m_erase_on_last_proxy_exited;
+
+ partial_function m_content_handler;
+
+ void monitor(const actor_ptr& sender, const process_information_ptr& node, actor_id aid);
+
+ void kill_proxy(const actor_ptr& sender, const process_information_ptr& node, actor_id aid, std::uint32_t reason);
+
+ void link(const actor_ptr& sender, const actor_ptr& ptr);
+
+ void unlink(const actor_ptr& sender, const actor_ptr& ptr);
+
+ void deliver(const addressed_message& msg);
+
+ inline void enqueue(const any_tuple& msg) {
+ enqueue(addressed_message(nullptr, nullptr, msg));
+ }
+
+ template<typename Arg0, typename Arg1, typename... Args>
+ inline void enqueue(Arg0&& arg0, Arg1&& arg1, Args&&... args) {
+ enqueue(make_any_tuple(std::forward<Arg0>(arg0),
+ std::forward<Arg1>(arg1),
+ std::forward<Args>(args)...));
+ }
+
+};
+
+typedef intrusive_ptr<default_peer> default_peer_ptr;
+
+} } // namespace cppa::network
+
+#endif // CPPA_DEFAULT_PEER_IMPL_HPP
View
20 cppa/network/default_peer_acceptor_impl.hpp → cppa/network/default_peer_acceptor.hpp
@@ -34,28 +34,36 @@
#include "cppa/actor.hpp"
#include "cppa/network/ipv4_acceptor.hpp"
-#include "cppa/network/peer_acceptor.hpp"
+#include "cppa/network/continuable_reader.hpp"
namespace cppa { namespace network {
-class default_peer_acceptor_impl : public peer_acceptor {
+class default_protocol;
- typedef peer_acceptor super;
+class default_peer_acceptor : public continuable_reader {
+
+ typedef continuable_reader super;
public:
continue_reading_result continue_reading();
- default_peer_acceptor_impl(middleman* parent,
- acceptor_uptr ptr,
- const actor_ptr& published_actor);
+ default_peer_acceptor(default_protocol* parent,
+ acceptor_uptr ptr,
+ const actor_ptr& published_actor);
+
+ inline const actor_ptr& published_actor() const { return m_pa; }
private:
+ default_protocol* m_parent;
acceptor_uptr m_ptr;
+ actor_ptr m_pa;
};
+typedef intrusive_ptr<default_peer_acceptor> default_peer_acceptor_ptr;
+
} } // namespace cppa::detail
#endif // IPV4_PEER_ACCEPTOR_HPP
View
96 cppa/network/default_protocol.hpp
@@ -0,0 +1,96 @@
+/******************************************************************************\
+ * ___ __ *
+ * /\_ \ __/\ \ *
+ * \//\ \ /\_\ \ \____ ___ _____ _____ __ *
+ * \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
+ * \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
+ * /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
+ * \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
+ * \ \_\ \ \_\ *
+ * \/_/ \/_/ *
+ * *
+ * Copyright (C) 2011, 2012 *
+ * Dominik Charousset <dominik.charousset@haw-hamburg.de> *
+ * *
+ * This file is part of libcppa. *
+ * libcppa is free software: you can redistribute it and/or modify it under *
+ * the terms of the GNU Lesser General Public License as published by the *
+ * Free Software Foundation, either version 3 of the License *
+ * or (at your option) any later version. *
+ * *
+ * libcppa is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
+ * See the GNU Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public License *
+ * along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
+\******************************************************************************/
+
+
+#ifndef DEFAULT_PROTOCOL_HPP
+#define DEFAULT_PROTOCOL_HPP
+
+#include <map>
+#include <vector>
+
+#include "cppa/actor_addressing.hpp"
+#include "cppa/process_information.hpp"
+
+#include "cppa/network/protocol.hpp"
+#include "cppa/network/default_peer.hpp"
+#include "cppa/network/default_actor_addressing.hpp"
+#include "cppa/network/default_peer_acceptor.hpp"
+
+namespace cppa { namespace network {
+
+class default_protocol : public protocol {
+
+ typedef protocol super;
+
+ public:
+
+ default_protocol(middleman* parent);
+
+ atom_value identifier() const;
+
+ void publish(const actor_ptr& whom, variant_args args);
+
+ void publish(const actor_ptr& whom,
+ std::unique_ptr<acceptor> acceptor,
+ variant_args args );
+
+ void unpublish(const actor_ptr& whom);
+
+ actor_ptr remote_actor(variant_args args);
+
+ actor_ptr remote_actor(io_stream_ptr_pair ioptrs, variant_args args);
+
+ inline default_actor_addressing* addressing() { return &m_addressing; }
+
+ void register_peer(const process_information& node, default_peer* ptr);
+
+ default_peer_ptr get_peer(const process_information& node);
+
+ void new_peer(const input_stream_ptr& in,
+ const output_stream_ptr& out,
+ const process_information_ptr& node = nullptr);
+
+ void erase_peer(const default_peer_ptr& pptr);
+
+ void continue_writer(const default_peer_ptr& pptr);
+
+ private:
+
+ default_actor_addressing m_addressing;
+
+ std::map<actor_ptr,std::vector<default_peer_acceptor_ptr> > m_acceptors;
+ std::map<process_information,default_peer_ptr> m_peers;
+
+};
+
+typedef intrusive_ptr<default_protocol> default_protocol_ptr;
+
+} } // namespace cppa::network
+
+#endif // DEFAULT_PROTOCOL_HPP
View
57 cppa/network/middleman.hpp
@@ -34,11 +34,12 @@
#include <map>
#include <vector>
#include <memory>
+#include <functional>
-#include "cppa/network/peer.hpp"
+#include "cppa/network/protocol.hpp"
#include "cppa/network/acceptor.hpp"
-#include "cppa/network/peer_acceptor.hpp"
#include "cppa/network/continuable_reader.hpp"
+#include "cppa/network/continuable_writer.hpp"
namespace cppa { namespace detail { class singleton_manager; } }
@@ -52,7 +53,10 @@ void middleman_loop(middleman_impl*);
class middleman {
+ // the most popular class in libcppa
+
friend class peer;
+ friend class protocol;
friend class peer_acceptor;
friend class singleton_manager;
friend class middleman_overseer;
@@ -65,28 +69,9 @@ class middleman {
virtual ~middleman();
- virtual void publish(std::unique_ptr<acceptor> server,
- const actor_ptr& published_actor) = 0;
-
- virtual void add_peer(const io_stream_ptr_pair& io,
- const process_information_ptr& node_info) = 0;
-
- virtual void unpublish(const actor_ptr& whom) = 0;
-
- virtual void enqueue(const process_information_ptr& receiving_node,
- const addressed_message& message) = 0;
+ virtual void add_protocol(const protocol_ptr& impl) = 0;
- inline void enqueue(const process_information_ptr& receiving_node,
- actor_ptr sender,
- channel_ptr receiver,
- any_tuple msg,
- message_id_t id = message_id_t()) {
- enqueue(receiving_node,
- addressed_message(std::move(sender),
- std::move(receiver),
- std::move(msg),
- id));
- }
+ virtual protocol_ptr protocol(atom_value id) = 0;
protected:
@@ -95,7 +80,11 @@ class middleman {
virtual void stop() = 0;
virtual void start() = 0;
- private:
+ // to be called from protocol
+
+ // runs @p fun in the middleman's event loop
+ virtual void run_later(std::function<void()> fun) = 0;
+
// to be called from singleton_manager
@@ -104,29 +93,33 @@ class middleman {
// to be called from peer
- void continue_writing_later(const peer_ptr& ptr);
- void register_peer(const process_information& node, const peer_ptr& ptr);
+ /**
+ * @pre ptr->as_writer() != nullptr
+ */
+ void continue_writer(const continuable_reader_ptr& ptr);
+
+ /**
+ * @pre ptr->as_writer() != nullptr
+ */
+ void stop_writer(const continuable_reader_ptr& ptr);
+ // to be called form peer_acceptor or protocol
- // to be called form peer_acceptor
+ void continue_reader(const continuable_reader_ptr& what);
- void add(const continuable_reader_ptr& what);
+ void stop_reader(const continuable_reader_ptr& what);
// to be called from m_handler or middleman_overseer
inline void quit() { m_done = true; }
inline bool done() const { return m_done; }
- void erase(const continuable_reader_ptr& what);
- continuable_reader_ptr acceptor_of(const actor_ptr& whom);
- peer_ptr get_peer(const process_information& node);
// member variables
bool m_done;
std::vector<continuable_reader_ptr> m_readers;
- std::map<process_information,peer_ptr> m_peers;
std::unique_ptr<middleman_event_handler> m_handler;
};
View
99 cppa/network/peer.hpp → cppa/network/protocol.hpp
@@ -28,78 +28,79 @@
\******************************************************************************/
-#ifndef PEER_HPP
-#define PEER_HPP
+#ifndef CPPA_PROTOCOL_HPP
+#define CPPA_PROTOCOL_HPP
-#include "cppa/network/addressed_message.hpp"
-#include "cppa/network/continuable_reader.hpp"
+#include <memory>
+#include <functional>
+#include <initializer_list>
-enum continue_writing_result {
- write_failure,
- write_closed,
- write_continue_later,
- write_done
-};
+#include "cppa/atom.hpp"
+#include "cppa/actor.hpp"
+#include "cppa/ref_counted.hpp"
+#include "cppa/primitive_variant.hpp"
+#include "cppa/network/acceptor.hpp"
namespace cppa { namespace network {
class middleman;
+class continuable_reader;
+class continuable_writer;
-/**
- * @brief Represents a bidirectional connection to a peer.
- */
-class peer : public continuable_reader {
+class protocol : public ref_counted {
- typedef continuable_reader super;
+ typedef ref_counted super;
public:
- /**
- * @brief Returns the file descriptor for outgoing data.
- */
- native_socket_type write_handle() const {
- return m_write_handle;
- }
-
- /**
- * @brief Writes to {@link write_handle()}.
- */
- virtual continue_writing_result continue_writing() = 0;
-
- /**
- * @brief Enqueues @p msg to the list of outgoing messages.
- * @returns @p true on success, @p false otherwise.
- * @note Implementation should call {@link begin_writing()} and perform IO
- * only in its implementation of {@link continue_writing()}.
- * @note Returning @p false from this function is interpreted as error
- * and causes the middleman to remove this peer.
- */
- virtual bool enqueue(const addressed_message& msg) = 0;
+ typedef std::initializer_list<primitive_variant> variant_args;
+
+ protocol(middleman* parent);
+
+ virtual atom_value identifier() const = 0;
+
+ virtual void publish(const actor_ptr& whom, variant_args args) = 0;
+
+ virtual void publish(const actor_ptr& whom,
+ std::unique_ptr<acceptor> acceptor,
+ variant_args args ) = 0;
+
+ virtual void unpublish(const actor_ptr& whom) = 0;
+
+ virtual actor_ptr remote_actor(variant_args args) = 0;
+
+ virtual actor_ptr remote_actor(io_stream_ptr_pair ioptrs,
+ variant_args args ) = 0;
+
+ void run_later(std::function<void()> fun);
protected:
- /**
- * @brief Tells the middleman to add write_handle() to the list of
- * observed sockets and to call continue_writing() if
- * write_handle() is ready to write.
- * @note Does nothing if write_handle() is already registered for the
- * event loop.
- */
- void begin_writing();
+ // note: not thread-safe; call only in run_later functor!
+ void continue_reader(continuable_reader* what);
+
+ // note: not thread-safe; call only in run_later functor!
+ void continue_writer(continuable_reader* what);
+
+ // note: not thread-safe; call only in run_later functor!
+ void stop_reader(continuable_reader* what);
+
+ // note: not thread-safe; call only in run_later functor!
+ void stop_writer(continuable_reader* what);
- void register_peer(const process_information& pinfo);
+ inline middleman* parent() { return m_parent; }
- peer(middleman* parent, native_socket_type rd, native_socket_type wr);
+ inline const middleman* parent() const { return m_parent; }
private:
- native_socket_type m_write_handle;
+ middleman* m_parent;
};
-typedef intrusive_ptr<peer> peer_ptr;
+typedef intrusive_ptr<protocol> protocol_ptr;
} } // namespace cppa::network
-#endif // PEER_HPP
+#endif // CPPA_PROTOCOL_HPP
View
10 cppa/serializer.hpp
@@ -39,7 +39,7 @@
namespace cppa {
-// forward declaration
+class actor_addressing;
class primitive_variant;
/**
@@ -53,7 +53,7 @@ class serializer {
public:
- serializer() = default;
+ serializer(actor_addressing* addressing = nullptr);
virtual ~serializer();
@@ -99,6 +99,12 @@ class serializer {
*/
virtual void write_tuple(size_t num, const primitive_variant* values) = 0;
+ inline actor_addressing* addressing() { return m_addressing; }
+
+ private:
+
+ actor_addressing* m_addressing;
+
};
/**
View
54 cppa/to_string.hpp
@@ -44,51 +44,53 @@
#include "cppa/uniform_type_info.hpp"
#include "cppa/process_information.hpp"
+#include "cppa/network/addressed_message.hpp"
+
+namespace std { class exception; }
+
namespace cppa {
namespace detail {
std::string to_string_impl(const void* what, const uniform_type_info* utype);
template<typename T>
-struct has_cppa_to_string : std::false_type { };
-
-template<>
-struct has_cppa_to_string<any_tuple> : std::true_type { };
-
-template<>
-struct has_cppa_to_string<network::addressed_message> : std::true_type { };
+inline std::string to_string_impl(const T& what) {
+ return to_string_impl(&what, uniform_typeid<T>());
+}
-template<>
-struct has_cppa_to_string<actor_ptr> : std::true_type { };
+} // namespace detail
-template<>
-struct has_cppa_to_string<group_ptr> : std::true_type { };
+inline std::string to_string(const any_tuple& what) {
+ return detail::to_string_impl(what);
+}
-template<>
-struct has_cppa_to_string<channel_ptr> : std::true_type { };
+inline std::string to_string(const network::addressed_message& what) {
+ return detail::to_string_impl(what);
+}
-template<>
-struct has_cppa_to_string<process_information_ptr> : std::true_type { };
+inline std::string to_string(const actor_ptr& what) {
+ return detail::to_string_impl(what);
+}
-} // namespace detail
+inline std::string to_string(const group_ptr& what) {
+ return detail::to_string_impl(what);
+}
-/**
- * @brief Converts any of libcppa's core types to a string.
- */
-template<typename T>
-inline std::string to_string(const T& what,
- typename std::enable_if<detail::has_cppa_to_string<T>::value>::type* = 0) {
- return detail::to_string_impl(&what, uniform_typeid<T>());
+inline std::string to_string(const process_information& what) {
+ return detail::to_string_impl(what);
}
-/**
- * @brief Converts an object to a string.
- */
inline std::string to_string(const object& what) {
return detail::to_string_impl(what.value(), what.type());
}
+/**
+ * @brief Converts @p e to a string including the demangled type of e
+ * and @p e.what().
+ */
+std::string to_verbose_string(const std::exception& e);
+
} // namespace cppa
#endif // CPPA_TO_STRING_HPP
View
19 cppa/weak_intrusive_ptr.hpp
@@ -31,15 +31,18 @@
#ifndef CPPA_WEAK_INTRUSIVE_PTR_HPP
#define CPPA_WEAK_INTRUSIVE_PTR_HPP
+#include <cstddef>
+
#include "cppa/ref_counted.hpp"
#include "cppa/intrusive_ptr.hpp"
+#include "cppa/util/comparable.hpp"
namespace cppa {
template<typename T>
-class weak_intrusive_ptr {
+class weak_intrusive_ptr : util::comparable<weak_intrusive_ptr<T>> {
- typedef T::anchor anchor_type;
+ typedef typename T::weak_ptr_anchor anchor_type;
public:
@@ -66,6 +69,18 @@ class weak_intrusive_ptr {
return (m_anchor) ? m_anchor->expired() : true;
}
+ inline ptrdiff_t compare(const weak_intrusive_ptr& other) const {
+ return m_anchor.compare(other.m_anchor);
+ }
+
+ /**
+ * @brief Queries whether this weak pointer is invalid, i.e., does not
+ * point to an instance.
+ */
+ inline bool invalid() const {
+ return m_anchor == nullptr;
+ }
+
private:
intrusive_ptr<anchor_type> m_anchor;
View
4 examples/group_chat.cpp
@@ -144,8 +144,8 @@ auto main(int argc, char* argv[]) -> int {
catch (exception& e) {
ostringstream err;
err << "*** exception: group::get(\"" << gid.substr(0, p)
- << "\", \"" << gid.substr(p + 1) << "\") failed, what = "
- << e.what() << endl;
+ << "\", \"" << gid.substr(p + 1) << "\") failed; "
+ << to_verbose_string(e) << endl;
send(printer, err.str());
}
}
View
79 src/actor_proxy.cpp
@@ -45,84 +45,7 @@ using namespace std;
namespace cppa {
-namespace {
-
-template<typename... Args>
-void middleman_enqueue(Args&&... args) {
- detail::singleton_manager::get_middleman()->enqueue(forward<Args>(args)...);
-}
-
-} // namespace <anonymous>
-
-
-actor_proxy::actor_proxy(std::uint32_t mid, const process_information_ptr& pptr)
+actor_proxy::actor_proxy(actor_id mid, const process_information_ptr& pptr)
: super(mid, pptr) { }
-void actor_proxy::enqueue(actor* sender, any_tuple msg) {
- auto& arr = detail::static_types_array<atom_value, std::uint32_t>::arr;
- if ( msg.size() == 2
- && msg.type_at(0) == arr[0]
- && msg.get_as<atom_value>(0) == atom("KILL_PROXY")
- && msg.type_at(1) == arr[1]) {
- cleanup(msg.get_as<std::uint32_t>(1));
- return;
- }
- middleman_enqueue(parent_process_ptr(), sender, this, std::move(msg));
-}
-
-void actor_proxy::sync_enqueue(actor* sender, message_id_t id, any_tuple msg) {
- middleman_enqueue(parent_process_ptr(), sender, this, std::move(msg), id);
-}
-
-void actor_proxy::link_to(const intrusive_ptr<actor>& other) {
- if (link_to_impl(other)) {
- // causes remote actor to link to (proxy of) other
- middleman_enqueue(parent_process_ptr(),
- other,
- this,
- make_any_tuple(atom("LINK"), other));
- }
-}
-
-void actor_proxy::local_link_to(const intrusive_ptr<actor>& other) {
- link_to_impl(other);
-}
-
-void actor_proxy::unlink_from(const intrusive_ptr<actor>& other) {
- if (unlink_from_impl(other)) {
- // causes remote actor to unlink from (proxy of) other
- middleman_enqueue(parent_process_ptr(),
- other,
- this,
- make_any_tuple(atom("UNLINK"), other));
- }
-}
-
-void actor_proxy::local_unlink_from(const intrusive_ptr<actor>& other) {
- unlink_from_impl(other);
-}
-
-bool actor_proxy::establish_backlink(const intrusive_ptr<actor>& other) {
- bool result = super::establish_backlink(other);
- if (result) {
- // causes remote actor to unlink from (proxy of) other
- middleman_enqueue(parent_process_ptr(),
- other,
- this,
- make_any_tuple(atom("LINK"), other));
- }
- return result;
-}
-
-bool actor_proxy::remove_backlink(const intrusive_ptr<actor>& other) {
- bool result = super::remove_backlink(other);
- if (result) {
- middleman_enqueue(parent_process_ptr(),
- nullptr,
- this,
- make_any_tuple(atom("UNLINK"), actor_ptr(this)));
- }
- return result;
-}
-
} // namespace cppa
View
128 src/actor_proxy_cache.cpp
@@ -1,128 +0,0 @@
-/******************************************************************************\
- * ___ __ *
- * /\_ \ __/\ \ *
- * \//\ \ /\_\ \ \____ ___ _____ _____ __ *
- * \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
- * \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
- * /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
- * \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
- * \ \_\ \ \_\ *
- * \/_/ \/_/ *
- * *
- * Copyright (C) 2011, 2012 *
- * Dominik Charousset <dominik.charousset@haw-hamburg.de> *
- * *
- * This file is part of libcppa. *
- * libcppa is free software: you can redistribute it and/or modify it under *
- * the terms of the GNU Lesser General Public License as published by the *
- * Free Software Foundation, either version 3 of the License *
- * or (at your option) any later version. *
- * *
- * libcppa is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
- * See the GNU Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public License *
- * along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
-\******************************************************************************/
-
-
-#include <thread>
-#include <cstring>
-
-#include "cppa/atom.hpp"
-#include "cppa/any_tuple.hpp"
-
-#include "cppa/util/shared_lock_guard.hpp"
-#include "cppa/util/upgrade_lock_guard.hpp"
-
-#include "cppa/network/middleman.hpp"
-#include "cppa/detail/actor_proxy_cache.hpp"
-#include "cppa/detail/singleton_manager.hpp"
-
-// thread_specific_ptr
-//#include <boost/thread/tss.hpp>
-
-namespace cppa { namespace detail {
-
-namespace { actor_proxy_cache s_proxy_cache; }
-
-actor_proxy_cache& get_actor_proxy_cache() { return s_proxy_cache; }
-
-actor_proxy_ptr actor_proxy_cache::get_or_put(actor_id aid,
- std::uint32_t process_id,
- const process_information::node_id_type& node_id) {
- key_tuple k{node_id, process_id, aid};
- return get_impl(k, true);
-}
-
-actor_proxy_ptr actor_proxy_cache::get(actor_id aid,
- std::uint32_t process_id,
- const process_information::node_id_type& node_id) {
- key_tuple k{node_id, process_id, aid};
- return get_impl(k, false);
-}
-
-actor_proxy_ptr actor_proxy_cache::get_impl(const key_tuple& key, bool do_put) {
- { // lifetime scope of shared guard
- util::shared_lock_guard<util::shared_spinlock> guard{m_lock};
- auto i = m_entries.find(key);
- if (i != m_entries.end()) {
- return i->second;
- }
- }
- if (!do_put) { return nullptr; }
- process_information_ptr peer(new process_information(std::get<1>(key),
- std::get<0>(key)));
- actor_proxy_ptr result(new actor_proxy(std::get<2>(key), peer));
- { // lifetime scope of exclusive guard
- std::lock_guard<util::shared_spinlock> guard{m_lock};
- auto i = m_entries.find(key);
- if (i != m_entries.end()) {
- return i->second;
- }
- m_entries.insert(std::make_pair(key, result));
- }
- result->attach_functor([result](std::uint32_t) {
- get_actor_proxy_cache().erase(result);
- });
- auto pself = process_information::get();
- singleton_manager::get_middleman()->enqueue(
- peer,
- nullptr,
- nullptr,
- make_any_tuple(atom("MONITOR"), pself, std::get<2>(key)));
- return result;
-}
-
-bool actor_proxy_cache::erase(const actor_proxy_ptr& pptr) {
- auto pinfo = pptr->parent_process_ptr();
- key_tuple key(pinfo->node_id(), pinfo->process_id(), pptr->id()); {
- std::lock_guard<util::shared_spinlock> guard{m_lock};
- return m_entries.erase(key) > 0;
- }
- return false;
-}
-
-bool actor_proxy_cache::key_tuple_less::operator()(const key_tuple& lhs,
- const key_tuple& rhs) const {
- int cmp_res = strncmp(reinterpret_cast<const char*>(std::get<0>(lhs).data()),
- reinterpret_cast<const char*>(std::get<0>(rhs).data()),
- process_information::node_id_size);
- if (cmp_res < 0) {
- return true;
- }
- else if (cmp_res == 0) {
- if (std::get<1>(lhs) < std::get<1>(rhs)) {
- return true;
- }
- else if (std::get<1>(lhs) == std::get<1>(rhs)) {
- return std::get<2>(lhs) < std::get<2>(rhs);
- }
- }
- return false;
-}
-
-
-} } // namespace cppa::detail
View
7 src/actor_registry.cpp
@@ -38,6 +38,8 @@
#include "cppa/util/shared_lock_guard.hpp"
#include "cppa/util/upgrade_lock_guard.hpp"
+#include "cppa/detail/logging.hpp"
+
namespace {
typedef std::lock_guard<cppa::util::shared_spinlock> exclusive_guard;
@@ -52,15 +54,19 @@ actor_registry::actor_registry() : m_running(0), m_ids(1) {
}
actor_registry::value_type actor_registry::get_entry(actor_id key) const {
+ CPPA_LOG_TRACE("key = " << key);
shared_guard guard(m_instances_mtx);
auto i = m_entries.find(key);
if (i != m_entries.end()) {
+ CPPA_LOG_DEBUG("result = " << i->second.first.get());
return i->second;
}
+ CPPA_LOG_DEBUG("result = nullptr");
return {nullptr, exit_reason::not_exited};
}
void actor_registry::put(actor_id key, const actor_ptr& value) {
+ CPPA_LOG_TRACE("key = " << key << ", ptr = " << value.get());
bool add_attachable = false;
if (value != nullptr) {
shared_guard guard(m_instances_mtx);
@@ -90,6 +96,7 @@ void actor_registry::put(actor_id key, const actor_ptr& value) {
}
void actor_registry::erase(actor_id key, std::uint32_t reason) {
+ CPPA_LOG_TRACE("key = " << key << ", reason = " << std::hex << reason);
exclusive_guard guard(m_instances_mtx);
auto i = m_entries.find(key);
if (i != m_entries.end()) {
View
12 src/binary_deserializer.cpp
@@ -125,13 +125,13 @@ struct pt_reader {
} // namespace <anonmyous>
-binary_deserializer::binary_deserializer(const char* buf, size_t buf_size)
- : pos(buf), end(buf + buf_size) {
-}
+binary_deserializer::binary_deserializer(const char* buf, size_t buf_size,
+ actor_addressing* addressing)
+: super(addressing), pos(buf), end(buf + buf_size) { }
-binary_deserializer::binary_deserializer(const char* bbegin, const char* bend)
- : pos(bbegin), end(bend) {
-}
+binary_deserializer::binary_deserializer(const char* bbegin, const char* bend,
+ actor_addressing* addressing)
+: super(addressing), pos(bbegin), end(bend) { }
std::string binary_deserializer::seek_object() {
std::string result;
View
3 src/binary_serializer.cpp
@@ -110,7 +110,8 @@ class binary_writer {
} // namespace <anonymous>
-binary_serializer::binary_serializer(util::buffer* buf) : m_sink(buf) { }
+binary_serializer::binary_serializer(util::buffer* buf, actor_addressing* ptr)
+: super(ptr), m_sink(buf) { }
void binary_serializer::begin_object(const std::string& tname) {
binary_writer::write_string(m_sink, tname);
View
11 src/continuable_reader.cpp
@@ -29,16 +29,13 @@
#include "cppa/network/continuable_reader.hpp"
+#include "cppa/network/continuable_writer.hpp"
namespace cppa { namespace network {
-continuable_reader::continuable_reader(middleman* parent,
- native_socket_type rd,
- bool is_peer)
-: m_is_peer(is_peer), m_parent(parent), m_read_handle(rd) { }
+continuable_reader::continuable_reader(native_socket_type rd) : m_rd(rd) { }
+
+continuable_writer* continuable_reader::as_writer() { return nullptr; }
-bool continuable_reader::is_acceptor_of(const actor_ptr&) const {
- return false;
-}
} } // namespace cppa::network
View
14 src/peer.cpp → src/continuable_writer.cpp
@@ -28,20 +28,10 @@
\******************************************************************************/
-#include "cppa/network/peer.hpp"
-#include "cppa/network/middleman.hpp"
+#include "cppa/network/continuable_writer.hpp"
namespace cppa { namespace network {
-peer::peer(middleman* parent, native_socket_type rd, native_socket_type wr)
-: super(parent, rd, true), m_write_handle(wr) { }
-
-void peer::begin_writing() {
- parent()->continue_writing_later(this);
-}
-
-void peer::register_peer(const process_information& pinfo) {
- parent()->register_peer(pinfo, this);
-}
+continuable_writer::continuable_writer(native_socket_type wr) : m_wr(wr) { }
} } // namespace cppa::network
View
201 src/default_actor_addressing.cpp
@@ -0,0 +1,201 @@
+/******************************************************************************\
+ * ___ __ *
+ * /\_ \ __/\ \ *
+ * \//\ \ /\_\ \ \____ ___ _____ _____ __ *
+ * \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
+ * \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
+ * /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
+ * \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
+ * \ \_\ \ \_\ *
+ * \/_/ \/_/ *
+ * *
+ * Copyright (C) 2011, 2012 *
+ * Dominik Charousset <dominik.charousset@haw-hamburg.de> *
+ * *
+ * This file is part of libcppa. *
+ * libcppa is free software: you can redistribute it and/or modify it under *
+ * the terms of the GNU Lesser General Public License as published by the *
+ * Free Software Foundation, either version 3 of the License *
+ * or (at your option) any later version. *
+ * *
+ * libcppa is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
+ * See the GNU Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public License *
+ * along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
+\******************************************************************************/
+
+
+#include <cstdint>
+
+#include "cppa/to_string.hpp"
+#include "cppa/serializer.hpp"
+#include "cppa/deserializer.hpp"
+#include "cppa/primitive_variant.hpp"
+
+#include "cppa/network/default_actor_proxy.hpp"
+#include "cppa/network/default_actor_addressing.hpp"
+
+#include "cppa/detail/logging.hpp"
+#include "cppa/detail/actor_registry.hpp"
+#include "cppa/detail/singleton_manager.hpp"
+
+using namespace std;
+
+namespace cppa { namespace network {
+
+default_actor_addressing::default_actor_addressing(default_protocol* parent)
+: m_parent(parent) { }
+
+atom_value default_actor_addressing::technology_id() const {
+ return atom("DEFAULT");
+}
+
+void default_actor_addressing::write(serializer* sink, const actor_ptr& ptr) {
+ CPPA_LOG_TRACE("sink = " << sink << ", ptr" << ptr.get());
+ CPPA_REQUIRE(sink != nullptr);
+ if (ptr == nullptr) {
+ CPPA_LOG_DEBUG("serialized nullptr");
+ sink->begin_object("@0");
+ sink->end_object();
+ }
+ else {
+ // local actor?
+ if (*ptr->parent_process_ptr() == *process_information::get()) {
+ detail::singleton_manager::get_actor_registry()->put(ptr->id(), ptr);
+ }
+ primitive_variant ptup[2];
+ ptup[0] = ptr->id();