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 
26 #include <fstream>
27 
30 
31 namespace armarx
32 {
33 
34  FileTopicReader::FileTopicReader(std::istream* stream) : stream(stream)
35  {
36  }
37 
38  FileTopicReader::FileTopicReader(std::filesystem::path path)
39  {
40  std::ifstream* i = new std::ifstream(path.string().c_str());
41  if (!i->is_open())
42  {
43  ARMARX_ERROR_S << "Could not open '" << path.string() << "'!";
44  }
45  stream = i;
46  }
47 
49  {
50  if (!filepath.empty())
51  {
52  delete stream;
53  }
54  }
55 
56  bool
58  {
59  std::string line;
60  if (!std::getline(*stream, line))
61  {
62  return false;
63  }
64  JSONObjectPtr json = new JSONObject();
65  json->fromString(line);
66  auto payloadEncoded = json->getString("data");
67  data.topicName = json->getString("topic");
68  std::string payloadStr = TopicUtil::Decode64(payloadEncoded);
69  data.inParams.assign(payloadStr.begin(), payloadStr.end());
70  data.operationName = json->getString("op");
71  data.timestamp = IceUtil::Time::microSecondsDouble(json->getDouble("t"));
72  return true;
73  }
74 
75  bool
77  {
78  //Seeking is not supported
79  return false;
80  }
81 
84  {
85  //Finding length of replay file is not supported
86  return IceUtil::Time::microSeconds(0);
87  }
88 
89  std::vector<std::string>
91  {
92  return std::vector<std::string>();
93  }
94 
95 } // 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:48
armarx::TopicUtil::Decode64
std::string Decode64(const std::string &val)
Definition: TopicUtil.cpp:44
IceInternal::Handle< JSONObject >
armarx::TopicUtil::TopicData
Definition: TopicUtil.h:34
armarx::FileTopicReader::getReplayTopics
std::vector< std::string > getReplayTopics() override
Definition: FileTopicReader.cpp:90
armarx::FileTopicReader::read
bool read(TopicUtil::TopicData &data) override
Definition: FileTopicReader.cpp:57
FileTopicReader.h
armarx::FileTopicReader::getReplayLength
IceUtil::Time getReplayLength() override
Definition: FileTopicReader.cpp:83
ARMARX_ERROR_S
#define ARMARX_ERROR_S
Definition: Logging.h:216
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::FileTopicReader::seekTo
bool seekTo(IceUtil::Time timestamp) override
Definition: FileTopicReader.cpp:76
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:27