source: flair-src/branches/mavlink/tools/Controller/Mavlink/src/Forwarder.cpp @ 86

Last change on this file since 86 was 86, checked in by Thomas Fuhrmann, 5 years ago

FlairSockets? are working and used

File size: 1.9 KB
RevLine 
[71]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
20#include <Socket.h>
21#include <Thread.h>
22#include <FrameworkManager.h>
23
24//todo remove for tests
25#include <iostream>
26
27using namespace std;
28using namespace flair::core;
29
30Forwarder::Forwarder(const FrameworkManager *parent, string name, string &inputAddress,
31                                         int inputPort, string &outputAddress, int outputPort):
32                                         Thread(parent, name, 6), inputAddress(inputAddress), 
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
[86]40  // cout << "input socket : " << inputAddress + ":" + to_string(inputPort) << endl;
41  // cout << "output socket : " << outputAddress + ":" + to_string(outputPort) << endl;
[71]42
[86]43  inputSocket = new Socket((Thread *)this, "input socket", inputPort);
[71]44  outputSocket = new Socket((Thread *)this, "output socket", outputAddress + ":" + to_string(outputPort));
45}
46
47Forwarder::~Forwarder() {
48
49}
50
51void 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;
[86]57  char inputBuffer[200];
[71]58  while (!ToBeStopped()) {
[86]59    recvDataSize = inputSocket->RecvMessage(inputBuffer, 200, 1000000000);
60          outputSocket->SendMessage(inputBuffer, recvDataSize);
[71]61  }
62}
Note: See TracBrowser for help on using the repository browser.