[88] | 1 | // %flair:license{
|
---|
| 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
| 4 | // %flair:license}
|
---|
| 5 | // created: 2016/09/02
|
---|
| 6 | // filename: Forwarder.cpp
|
---|
| 7 | //
|
---|
| 8 | // authors: Thomas Fuhrmann
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: Forward input data to output data, using sockets
|
---|
| 14 | //
|
---|
| 15 | //
|
---|
| 16 | /*********************************************************************/
|
---|
| 17 |
|
---|
| 18 | #include "Forwarder.h"
|
---|
| 19 |
|
---|
[178] | 20 | #include <UdpSocket.h>
|
---|
[88] | 21 | #include <Thread.h>
|
---|
| 22 | #include <FrameworkManager.h>
|
---|
| 23 |
|
---|
| 24 | //todo remove for tests
|
---|
| 25 | #include <iostream>
|
---|
| 26 |
|
---|
| 27 | using namespace std;
|
---|
| 28 | using namespace flair::core;
|
---|
| 29 |
|
---|
[137] | 30 | Forwarder::Forwarder(string name, string &inputAddress,
|
---|
[88] | 31 | int inputPort, string &outputAddress, int outputPort):
|
---|
[137] | 32 | Thread(getFrameworkManager(), name, 6), inputAddress(inputAddress),
|
---|
[88] | 33 | inputPort(inputPort), outputAddress(outputAddress),
|
---|
| 34 | outputPort(outputPort) {
|
---|
| 35 | cout << "MavPlanner Forwarder constructor" << endl;
|
---|
| 36 |
|
---|
| 37 | // string tmpOutput = outputAddress + ":" + to_string(outputPort);
|
---|
| 38 | // cout << "MavPlanner Forwarder output address : " << tmpOutput << endl;
|
---|
| 39 |
|
---|
| 40 | // cout << "input socket : " << inputAddress + ":" + to_string(inputPort) << endl;
|
---|
| 41 | // cout << "output socket : " << outputAddress + ":" + to_string(outputPort) << endl;
|
---|
| 42 |
|
---|
[178] | 43 | inputSocket = new UdpSocket((Thread *)this, "input socket", inputPort);
|
---|
| 44 | outputSocket = new UdpSocket((Thread *)this, "output socket", outputAddress + ":" + to_string(outputPort));
|
---|
[88] | 45 | }
|
---|
| 46 |
|
---|
| 47 | Forwarder::~Forwarder() {
|
---|
| 48 |
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | void Forwarder::Run() {
|
---|
| 52 | if (getFrameworkManager()->ErrorOccured()) {
|
---|
| 53 | SafeStop();
|
---|
| 54 | Thread::Err("An error occurred, we don't launch the Run loop.\n");
|
---|
| 55 | }
|
---|
| 56 | int recvDataSize = 0;
|
---|
| 57 | char inputBuffer[200];
|
---|
| 58 | while (!ToBeStopped()) {
|
---|
| 59 | recvDataSize = inputSocket->RecvMessage(inputBuffer, 200, 1000000000);
|
---|
| 60 | outputSocket->SendMessage(inputBuffer, recvDataSize);
|
---|
| 61 | }
|
---|
[178] | 62 | }
|
---|