| 1 | = Adding inputs/outputs = |
| 2 | |
| 3 | To send data between components, Pacpus uses input/output system based on signals/slots. |
| 4 | |
| 5 | We will try to add to our component called ```MyComponent```: |
| 6 | 1. an output named ```"scan"``` of type ```LidarScan```, |
| 7 | 2. an input named ```"pose"``` of type ```GeoPose2D``` . |
| 8 | |
| 9 | So, add virtual methods overriden from ```ComponentBase```: ```addInputs()``` and ```addOutputs()``` to the component: |
| 10 | |
| 11 | {{{#!c++ |
| 12 | // MyComponent.h |
| 13 | |
| 14 | class My Component // ... |
| 15 | { |
| 16 | // ... |
| 17 | protected: |
| 18 | virtual void addInputs() /* override */; |
| 19 | virtual void addOutputs() /* override */; |
| 20 | }; |
| 21 | }}} |
| 22 | |
| 23 | {{{#!c++ |
| 24 | // MyComponent.cpp |
| 25 | |
| 26 | void MyComponent::addInputs() |
| 27 | { |
| 28 | // inputs go here |
| 29 | } |
| 30 | |
| 31 | void MyComponent::addOutputs() |
| 32 | { |
| 33 | // outputs go here |
| 34 | } |
| 35 | |
| 36 | }}} |
| 37 | |
| 38 | == Adding an output == |
| 39 | |
| 40 | To add an output, you have to use template method ```ComponentBase::addOutput<class OutputType, class ComponentType>(const char* outputName)```: |
| 41 | |
| 42 | {{{#!c++ |
| 43 | // MyComponent.cpp |
| 44 | |
| 45 | void MyComponent::addOutputs() |
| 46 | { |
| 47 | // outputs go here |
| 48 | addOutput<LidarScan, MyComponent>("scan"); |
| 49 | } |
| 50 | }}} |
| 51 | |
| 52 | == Adding an input == |
| 53 | |
| 54 | To add an input, you have to have a method in your class that will process it. |
| 55 | It should take as the only argument, a constant reference to the type of the input. |
| 56 | In our example, we suppose to have a function declared as follows: |
| 57 | |
| 58 | {{{#!c++ |
| 59 | void processPose(GeoPose2D const& pose); |
| 60 | }}} |
| 61 | |
| 62 | You have to use template method ```ComponentBase::addInput<class OutputType, class ComponentType, typename ProcessingFunction>(const char* outputName, ProcessingFunction inputProcessingFunction)```: |
| 63 | |
| 64 | {{{#!c++ |
| 65 | // MyComponent.cpp |
| 66 | |
| 67 | void MyComponent::addInputs() |
| 68 | { |
| 69 | // inputs go here |
| 70 | addInput<GeoPose2D, MyComponent>("pose", &MyComponent::processPose); |
| 71 | } |
| 72 | }}} |
| 73 | |
| 74 | The second argument is the address (```&```) of our processing method. |
| 75 | You can also use a free function or a functor object, as well as any other callable object, e.g. ```std::function```, ```boost::function```, etc. |
| 76 | |