rtems and C++ (OOP)

Stephen Tether tether at slac.stanford.edu
Tue Mar 12 18:31:22 UTC 2013


On 03/12/2013 11:14 AM, Nicolás Alvarez wrote:
> Hi, anyone knows how to define a non-estatic member function of a class
> like the entry point of a task? If not, what is the best way to bind a
> function to a task according the OOP?

You can define a non-member function that takes a pointer to the object
and uses it to call the right member-function. Then start the task at
the non-member function. Something like this:

class Foo {
public:

  void bar() {...}

};


rtems_task barCaller(rtems_task_argument arg) {
  Foo *obj(reinterpret_cast<Foo*>(arg));
  obj->bar();
}


rtems_task_create(..., &id);
f = new Foo;
rtems_task_start(id, barCaller, f);


If you need to pass arguments to bar() you could make the argument to
barCaller() a pointer to a struct containing the object pointer and the
arguments.

- Steve Tether



More information about the users mailing list