FileTopicReader.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarX
19 * @author Mirko Waechter( mirko.waechter at kit dot edu)
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 #include "FileTopicReader.h"
25 
28 
29 #include <fstream>
30 
31 namespace armarx
32 {
33 
34  FileTopicReader::FileTopicReader(std::istream* stream) :
35  stream(stream)
36  {
37 
38 
39  }
40 
41  FileTopicReader::FileTopicReader(std::filesystem::path path)
42  {
43  std::ifstream* i = new std::ifstream(path.string().c_str());
44  if (!i->is_open())
45  {
46  ARMARX_ERROR_S << "Could not open '" << path.string() << "'!";
47  }
48  stream = i;
49  }
50 
52  {
53  if (!filepath.empty())
54  {
55  delete stream;
56  }
57  }
58 
60  {
61  std::string line;
62  if (!std::getline(*stream, line))
63  {
64  return false;
65  }
66  JSONObjectPtr json = new JSONObject();
67  json->fromString(line);
68  auto payloadEncoded = json->getString("data");
69  data.topicName = json->getString("topic");
70  std::string payloadStr = TopicUtil::Decode64(payloadEncoded);
71  data.inParams.assign(payloadStr.begin(), payloadStr.end());
72  data.operationName = json->getString("op");
73  data.timestamp = IceUtil::Time::microSecondsDouble(json->getDouble("t"));
74  return true;
75  }
76 
78  {
79  //Seeking is not supported
80  return false;
81  }
82 
84  {
85  //Finding length of replay file is not supported
86  return IceUtil::Time::microSeconds(0);
87  }
88 
89  std::vector<std::string> FileTopicReader::getReplayTopics()
90  {
91  return std::vector<std::string>();
92  }
93 
94 } // namespace armarx
JSONObject.h
armarx::JSONObject
The JSONObject class is used to represent and (de)serialize JSON objects.
Definition: JSONObject.h:43
armarx::FileTopicReader::~FileTopicReader
~FileTopicReader()
Definition: FileTopicReader.cpp:51
armarx::TopicUtil::Decode64
std::string Decode64(const std::string &val)
Definition: TopicUtil.cpp:42
IceInternal::Handle< JSONObject >
armarx::TopicUtil::TopicData
Definition: TopicUtil.h:34
armarx::FileTopicReader::getReplayTopics
std::vector< std::string > getReplayTopics() override
Definition: FileTopicReader.cpp:89
armarx::FileTopicReader::read
bool read(TopicUtil::TopicData &data) override
Definition: FileTopicReader.cpp:59
FileTopicReader.h
armarx::FileTopicReader::getReplayLength
IceUtil::Time getReplayLength() override
Definition: FileTopicReader.cpp:83
ARMARX_ERROR_S
#define ARMARX_ERROR_S
Definition: Logging.h:209
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::FileTopicReader::seekTo
bool seekTo(IceUtil::Time timestamp) override
Definition: FileTopicReader.cpp:77
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::FileTopicReader::FileTopicReader
FileTopicReader(std::istream *stream)
Definition: FileTopicReader.cpp:34
Logging.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28