(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Using Sigslots Lite

Description: Shows how to set up signals and slots with ecl_sigslots_lite.

Keywords: ecl sigslots lite

Tutorial Level: INTERMEDIATE

Next Tutorial: Debugging Sigslots Lite

Slots in the Background

Users of lite sigslots don't actually directly use Slot classes (unlike ecl_sigslots). Slots are still there, but they are stored behind the scenes, either in a global slots manager or member slots manager inherited by a class.

Storage Capacities

Signals and slots need to reserve memory before usage. This identifies how many connections each can handle. For global slots, you need to set a static variable before making any connections to slots of that type.

   1 // allocate for global function slots with const char* and void arg footprints
   2 template<> const unsigned int ecl::lite::GlobalSlots<const char*>::capacity = 4;
   3 template<> const unsigned int ecl::lite::GlobalSlots<void>::capacity = 2;
   5 int main() {
   6     // ...

For member slots, your class needs to inherit from the MemberSlots interface and specify the capacity as a template parameter (default is 1).

   1 class Foo : public ecl::lite::MemberSlots<const char*,Foo>,
   2             public ecl::lite::MemberSlots<void,Foo,2>
   3 {
   4 public:
   5     Foo() {}
   7     void f(const char* str) { /* */ }
   8     void g() { /* */ }
   9     void h() { /* */ }
  10 };

For signals, simply specify the capacity template parameter (again default is 1) when instantiating the signal. This reflects the number of connections it can handle.

   1 ecl::lite::Signal<const char*, 2> signal;


Connections are made via the connect functions, linking directly to the function pointers.

   1 connect(signal,f);            // connecting to a global slot
   2 connect(signal,&Foo::f, foo); // connecting to a member slot

Wiki: ecl_sigslots_lite/Tutorials/Using Sigslots Lite (last edited 2012-01-14 15:32:49 by DanielStonier)