Flip Reference

Signal Class Reference

Declared in

flip/Signal.h

template <class... Args>   class Signal;

flip::Signal is a type that allows signalling of flip objects in a type safe way.

Signals are only local and targetted at an object. They are not broadcasted to the other clients in a collaboration case, and they are not part of an observer. It is therefore not part of the document model.

However, if multiple documents are using a Hub on a local machine in different threads or processes, the signal will be delivered on the local machine.

Signals can also be a way to communicate directly with the server.

When messages should be part of a document model and broadcasted then Message shall be used instead.

Template Parameters

Args...

A variable number of arguments that compose the parameters of the signal

Member Functions Synopsys

Constructor

Constructs the Signal

Destructor

Destructs the Signal

operator ()

Fire signal

connect

Connect a listener

Member Functions

Constructor

Signal (uint32_t type, Object & object);

Constructor. Constructs the object by linking it to object. type is a unique number for the class of the object that represents the signal type.

Example :

class Form : public Object
{
public:
   enum
   {
      Signal_OPEN_VIEW = 0,
      Signal_CLOSE_VIEW,
   };
   Form ()
   : signal_open_view (Signal_OPEN_VIEW, *this)
   , signal_close_view (Signal_CLOSE_VIEW, *this)
   Signal <int /* width */, int /* height */> signal_open_view;
   Signal <> signal_close_view;
};

Destructor

~Signal ();

Destructor.


operator ()

void  operator () (Args... args);

Notify all connection listeners for this type of signal and this object as identified by its unique flip reference number.

All documents in the local document tree are also notified, and if the transport is configured to let those signal pass through, the server will be notified too.

form.signal_open_view (1280, 1024);
form.signal_close_view ();

connect

template <class T, class F>   SignalConnection  connect (T & t, F f);   (1)
template <class F>   SignalConnection  connect (F f);                   (2)
  1. function member delegate version
  2. lambda version

Connect a listener to this Signal. Returns a SignalConnection. This last type should be stored in a way to ensure that the listener could be signalled as long as the SignalConnection is alive.

SignalConnection cnx = form.signal_open_view.connect ([](int width, int height){
   // open view witdh x height
});
SignalConnection cnx2 = form.signal_close_view.connect ([](){
   // close view
});

Note that cnx and cnx2 in the above example needs to be stored. If they go below the function scope, they will be destroyed and therefore the signal connection will be broken.

SignalConnections cannot be copied, but can be moved with std::move.