Skip to content

Commit

Permalink
implemented logging and default_protocol
Browse files Browse the repository at this point in the history
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
Neverlord committed Oct 16, 2012
1 parent 88953ad commit 561b43b
Show file tree
Hide file tree
Showing 49 changed files with 2,564 additions and 1,424 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Expand Up @@ -65,6 +65,12 @@ if (ENABLE_DEBUG)
# set(CMAKE_BUILD_TYPE RelWithDebInfo) # set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif () 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 # set build default build type if not set
if (CMAKE_BUILD_TYPE) if (CMAKE_BUILD_TYPE)
else (CMAKE_BUILD_TYPE) else (CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -207,6 +213,7 @@ message("\n====================| Build Summary |===================="
"\n" "\n"
"\nBuild type: ${CMAKE_BUILD_TYPE}" "\nBuild type: ${CMAKE_BUILD_TYPE}"
"\nDebug mode: ${ENABLE_DEBUG}" "\nDebug mode: ${ENABLE_DEBUG}"
"\nLog level: ${CPPA_LOG_LEVEL}"
"\nContext switching: ${CONTEXT_SWITCHING}" "\nContext switching: ${CONTEXT_SWITCHING}"
"\n" "\n"
"\nCXX: ${CMAKE_CXX_COMPILER}" "\nCXX: ${CMAKE_CXX_COMPILER}"
Expand Down
28 changes: 28 additions & 0 deletions configure
Expand Up @@ -37,6 +37,12 @@ Usage: $0 [OPTION]... [VAR=VALUE]...
--enable-debug compile in debugging mode --enable-debug compile in debugging mode
(always sets --build-type=Debug) (always sets --build-type=Debug)
--enable-perftools use Google perftools --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: Platform-Dependent Adjustments:
--disable-context-switching compile libcppa without context-switching actors --disable-context-switching compile libcppa without context-switching actors
Expand Down Expand Up @@ -147,6 +153,28 @@ while [ $# -ne 0 ]; do
--enable-debug) --enable-debug)
append_cache_entry ENABLE_DEBUG BOOL true 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) --disable-context-switching)
append_cache_entry DISABLE_CONTEXT_SWITCHING BOOL true append_cache_entry DISABLE_CONTEXT_SWITCHING BOOL true
;; ;;
Expand Down
27 changes: 17 additions & 10 deletions cppa.files
Expand Up @@ -38,7 +38,7 @@ cppa/deserializer.hpp
cppa/detail/abstract_scheduled_actor.hpp cppa/detail/abstract_scheduled_actor.hpp
cppa/detail/abstract_tuple.hpp cppa/detail/abstract_tuple.hpp
cppa/detail/actor_count.hpp cppa/detail/actor_count.hpp
cppa/detail/actor_proxy_cache.hpp cppa/actor_addressing.hpp
cppa/detail/actor_registry.hpp cppa/detail/actor_registry.hpp
cppa/network/addressed_message.hpp cppa/network/addressed_message.hpp
cppa/detail/atom_val.hpp cppa/detail/atom_val.hpp
Expand Down Expand Up @@ -174,7 +174,6 @@ src/abstract_tuple.cpp
src/actor.cpp src/actor.cpp
src/actor_count.cpp src/actor_count.cpp
src/actor_proxy.cpp src/actor_proxy.cpp
src/actor_proxy_cache.cpp
src/actor_registry.cpp src/actor_registry.cpp
src/addressed_message.cpp src/addressed_message.cpp
src/any_tuple.cpp src/any_tuple.cpp
Expand Down Expand Up @@ -269,16 +268,24 @@ cppa/detail/opt_impls.hpp
examples/type_plugins.hpp examples/type_plugins.hpp
cppa/detail/decorated_names_map.hpp cppa/detail/decorated_names_map.hpp
src/decorated_names_map.cpp 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 cppa/network/continuable_reader.hpp
src/continuable_reader.cpp src/continuable_reader.cpp
cppa/network/default_peer_impl.hpp cppa/network/default_peer.hpp
src/default_peer_impl.cpp src/default_peer.cpp
cppa/network/default_peer_acceptor_impl.hpp cppa/network/default_peer_acceptor.hpp
src/default_peer_acceptor_impl.cpp src/default_peer_acceptor.cpp
src/ref_counted.cpp src/ref_counted.cpp
cppa/enable_weak_ptr_mixin.hpp cppa/enable_weak_ptr_mixin.hpp
cppa/weak_intrusive_ptr.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
78 changes: 78 additions & 0 deletions 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
51 changes: 23 additions & 28 deletions cppa/actor_proxy.hpp
Expand Up @@ -32,57 +32,52 @@
#define CPPA_ACTOR_PROXY_HPP #define CPPA_ACTOR_PROXY_HPP


#include "cppa/actor.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 { namespace cppa {


#ifdef CPPA_DOCUMENTATION class actor_proxy_cache;


/** /**
* @brief Represents a remote actor. * @brief Represents a remote actor.
*/ */
class actor_proxy : public actor { }; class actor_proxy : public enable_weak_ptr_mixin<actor_proxy,actor> {


#else // CPPA_DOCUMENTATION typedef enable_weak_ptr_mixin<actor_proxy,actor> super;

class actor_proxy : public detail::abstract_actor<actor> {

typedef abstract_actor<actor> super;


public: public:


actor_proxy(std::uint32_t mid, const process_information_ptr& parent); /**

* @brief Establishes a local link state that's not synchronized back
void enqueue(actor* sender, any_tuple msg); * to the remote instance.

*/
void sync_enqueue(actor* sender, message_id_t id, any_tuple msg); virtual void local_link_to(const intrusive_ptr<actor>& other) = 0;

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);


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 protected:
// to the "original" remote actor
void local_unlink_from(const actor_ptr& other);


bool remove_backlink(const intrusive_ptr<actor>& to); actor_proxy(actor_id mid,

const process_information_ptr& pinfo);
bool establish_backlink(const intrusive_ptr<actor>& to);


}; };


#endif // CPPA_DOCUMENTATION

/** /**
* @brief A smart pointer to an {@link actor_proxy} instance. * @brief A smart pointer to an {@link actor_proxy} instance.
* @relates actor_proxy * @relates actor_proxy
*/ */
typedef intrusive_ptr<actor_proxy> actor_proxy_ptr; 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 } // namespace cppa


#endif // CPPA_ACTOR_PROXY_HPP #endif // CPPA_ACTOR_PROXY_HPP
15 changes: 11 additions & 4 deletions cppa/binary_deserializer.hpp
Expand Up @@ -41,13 +41,15 @@ namespace cppa {
*/ */
class binary_deserializer : public deserializer { class binary_deserializer : public deserializer {


const char* pos; typedef deserializer super;
const char* end;


public: public:


binary_deserializer(const char* buf, size_t buf_size); binary_deserializer(const char* buf, size_t buf_size,
binary_deserializer(const char* begin, const char* end); actor_addressing* addressing = nullptr);

binary_deserializer(const char* begin, const char* end,
actor_addressing* addressing = nullptr);


std::string seek_object(); std::string seek_object();
std::string peek_object(); std::string peek_object();
Expand All @@ -61,6 +63,11 @@ class binary_deserializer : public deserializer {
primitive_variant* storage); primitive_variant* storage);
void read_raw(size_t num_bytes, void* storage); void read_raw(size_t num_bytes, void* storage);


private:

const char* pos;
const char* end;

}; };


} // namespace cppa } // namespace cppa
Expand Down
4 changes: 3 additions & 1 deletion cppa/binary_serializer.hpp
Expand Up @@ -46,13 +46,15 @@ namespace detail { class binary_writer; }
*/ */
class binary_serializer : public serializer { class binary_serializer : public serializer {


typedef serializer super;

public: public:


/** /**
* @brief Creates a binary serializer writing to @p write_buffer. * @brief Creates a binary serializer writing to @p write_buffer.
* @warning @p write_buffer must be guaranteed to outlive @p this * @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); void begin_object(const std::string& tname);


Expand Down
9 changes: 8 additions & 1 deletion cppa/deserializer.hpp
Expand Up @@ -40,6 +40,7 @@
namespace cppa { namespace cppa {


class object; class object;
class actor_addressing;


/** /**
* @ingroup TypeSystem * @ingroup TypeSystem
Expand All @@ -52,7 +53,7 @@ class deserializer {


public: public:


deserializer() = default; deserializer(actor_addressing* addressing = nullptr);


virtual ~deserializer(); virtual ~deserializer();


Expand Down Expand Up @@ -113,6 +114,12 @@ class deserializer {
*/ */
virtual void read_raw(size_t num_bytes, void* storage) = 0; virtual void read_raw(size_t num_bytes, void* storage) = 0;


inline actor_addressing* addressing() { return m_addressing; }

private:

actor_addressing* m_addressing;

}; };


/** /**
Expand Down

0 comments on commit 561b43b

Please sign in to comment.