Skip to content
Dmitry Koplyarov edited this page Apr 9, 2017 · 16 revisions

Back to reference

The signal itself.
Most of the tutorial is dedicated to the signal class. I recommend reading at least basic and intermediate parts before writing any code.

Defined in wigwag/signal.hpp

template < typename Signature_, typename... Policies_ >
class signal;

template < typename... ArgTypes_, typename... Policies_ >
class signal<void(ArgTypes_...), Policies_...>
{
public:
	using signature = void(ArgTypes_...);
	using handler_type = std::function<signature>;

	template < typename... Args_ >
	signal(Args_&&... args);

	template < typename... Args_ >
	signal(signal_attributes attributes, Args_&&... args);

	signal(const signal&) = delete;
	signal& operator = (const signal&) = delete;

	auto lock_primitive() const -> decltype(_storage.get_lock_primitive().get_primitive());

	signal_connector<signature> connector() const;

	template < typename HandlerFunc_ >
	token connect(HandlerFunc_ handler, handler_attributes attributes = handler_attributes::none) const;

	template < typename HandlerFunc_ >
	token connect(std::shared_ptr<task_executor> worker, HandlerFunc_ handler, handler_attributes attributes = handler_attributes::none) const;

	void operator() (ArgTypes_&&... args) const;
};

Table of contents

Template arguments

Signature_

The signature of a signal.

Policies_...

The custom policies list. You can read more in this tutorial section.

Supported policies:

Nested types

signature

using signature = void(ArgTypes_...);

The signature of a signal. The same type as the Signature_ template argument.

handler_type

using handler_type = std::function<signature>;

The signal handler type. A type alias for std::function<signature>.

Constructors

variadic arguments constructor

template < typename... Args_ >
signal(Args_&&... args);

Forwards the arguments to the policies' internals You can read more in the tutorial.

Arguments:

  • args... - forwarded to the policies' internals

variadic arguments constructor with signal_attributes

template < typename... Args_ >
signal(signal_attributes attributes, Args_&&... args);

Sets the signal attributes, and forwards the remaining arguments to the policies' internals You can read more in the tutorial.

Arguments:

  • attributes - signal_attributes enum flags
  • args... - forwarded to the policies' internals

copy constructor

signal(const signal&) = delete;

The copy constructor is prohibited

Methods

connector

signal_connector<signature> connector() const;

Gets the signal_connector for this signal.

Thread safety: This is a thread-safe method.

Return value: a signal_connector object.

connect

(1)
template < typename HandlerFunc_ >
token connect(HandlerFunc_ handler, handler_attributes attributes = handler_attributes::none) const;

(2)
template < typename HandlerFunc_ >
token connect(std::shared_ptr<task_executor> worker, HandlerFunc_ handler, handler_attributes attributes = handler_attributes::none) const;

(1) connects a synchronous handler to a signal.
(2) connects an asynchronous handler to a signal.

Thread safety: This is a thread-safe method for the default signal version. If you use custom policies, it is thread-safe as long as the threading policy assures that.

Arguments:

  • worker - a task_executor that should be used to invoke the handler
  • handler - an function object to be connected to a signal
  • attributes - handler_attributes enum flags

Return value: a RAII token object that manages the connection to a signal.

lock_primitive

auto lock_primitive() const -> decltype(_storage.get_lock_primitive().get_primitive());

Return value: a reference to the lock primitive (std::recursive_mutex for the default signal version). The actual type is the same as that of threading policy's lock_primitive::get_primitive() method.

Operators

operator ()

void operator() (ArgTypes_&&... args) const;

Invokes the signal.
Please note that in general case you should lock the signal's lock primitive in the code that calls this method. You can get more information here.

Thread safety: This is a thread-safe method for the default signal version. If you use custom policies, it MAY OR MAY NOT BE a thread-safe method even with a thread-safe threading policy (e.g. with all policies that use a non-recursive mutex)!

Arguments:

  • args... - forwarded to the connected handlers

operator =

signal& operator = (const signal&) = delete;

The assignment operator is prohibited

Clone this wiki locally