1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
/* 
 * File:   Simulator.h
 * Author: Heinrich
 *
 * Created on 4. April 2014, 16:51
 */

#ifndef _LogProviderModule_h_
#define _LogProviderModule_h_

#include <ModuleFramework/Module.h>
#include <Tools/Logfile/LogFileScanner.h>

#include <Tools/Debug/DebugRequest.h>


BEGIN_DECLARE_MODULE(LogProvider)
//  PROVIDE(DebugRequest)
END_DECLARE_MODULE(LogProvider)


class LogProvider: public LogProviderBase, virtual public BlackBoardInterface
{
protected:
  inline DebugRequest& getDebugRequest() {
    return *(BlackBoardInterface::getBlackBoard().getRepresentation<DataHolder<DebugRequest> >("DebugRequest"));
  }

private:
  const LogFileScanner::Frame* representations;
  std::set<std::string> exludeMap;
  LogFileScanner* scanner;

public:
  LogProvider() : representations(NULL) <--- Member variable 'LogProvider::scanner' is not initialized in the constructor.
  {
    // HACK: do not provide basic percepts (they are provided by get(...))
    exludeMap.insert("AccelerometerData");
    exludeMap.insert("SensorJointData");
    exludeMap.insert("Image");
    exludeMap.insert("ImageTop");
    exludeMap.insert("FSRData");
    exludeMap.insert("GyrometerData");
    exludeMap.insert("InertialSensorData");
    exludeMap.insert("CurrentCameraSettings");
    exludeMap.insert("ButtonData");
    exludeMap.insert("BatteryData");
    exludeMap.insert("UltraSoundReceiveData");
    exludeMap.insert("FrameInfo");
  }

  void init(LogFileScanner& logScanner, const LogFileScanner::Frame& rep, const std::set<std::string>& includedRepresentations)
  {
    scanner = &logScanner;
    representations = &rep;
    std::set<std::string>::iterator iter;

    for(iter = includedRepresentations.begin(); iter != includedRepresentations.end(); ++iter) {
      if(*iter != "") {
        DEBUG_REQUEST_REGISTER("LogProvider:"+(*iter), "", true);
      }
    }
    //DEBUG_REQUEST_REGISTER("FrameInfo", "", false);
  }//end init


  void execute()
  {
    BlackBoard& blackBoard = BlackBoardInterface::getBlackBoard();
    
    for(BlackBoard::Registry::iterator bbData = blackBoard.getRegistry().begin(); bbData != blackBoard.getRegistry().end(); ++bbData)
    {
      // look if there is a logged data for this representation 
      LogFileScanner::Frame::const_iterator frameData = representations->find(bbData->first); 
      if( frameData != representations->end() && 
          frameData->second.valid && 
          frameData->first != "" &&
          exludeMap.find(frameData->first) == exludeMap.end()
        )
      {
        DEBUG_REQUEST_GENERIC("LogProvider:"+(frameData->first),
          std::istrstream stream(frameData->second.data.data(), frameData->second.data.size());
          bbData->second->getRepresentation().deserialize(stream);
        );
      }
    }//end for
  }//end execute

  bool getRepresentation(const std::string& name, std::ostream& stream)
  {
    BlackBoard& blackBoard = BlackBoardInterface::getBlackBoard();
    BlackBoard::Registry::iterator bbData = blackBoard.getRegistry().find(name);

    if(bbData == blackBoard.getRegistry().end()) {
      return false;
    }

    bbData->second->getRepresentation().serialize(stream);

    return true;
  }
};

#endif  /* _LogProviderModule_h_ */