27 #include <Ice/ObjectAdapter.h>
29 #include <SimoxUtility/algorithm/string/string_tools.h>
31 #include <IceStorm/IceStorm.h>
57 outputFilename = getProperty<std::string>(
"Outputfile").getValue();
67 auto allTopics =
getIceManager()->getTopicManager()->retrieveAll();
68 for (
auto& elem : allTopics)
74 Ice::StringSeq topics;
75 if (getProperty<std::string>(
"TopicsToLog").getValue() ==
"*")
77 for (
auto& elem : allTopics)
79 topics.push_back(elem.first);
84 topics =
Split(getProperty<std::string>(
"TopicsToLog").getValue(),
",");
86 for (
auto topic : topics)
88 float maxFrequency = -1.f;
92 maxFrequency = atof(topicAndFreq.at(1).c_str());
93 topic = topicAndFreq.at(0);
102 if (getProperty<bool>(
"EnableRecording").getValue())
116 std::lock_guard<std::mutex> lock(mutex);
118 if (isRecordingEnabled)
125 this->maxDuration = maxDuration;
126 outputfilePath = outputFilename;
127 if (getProperty<bool>(
"TimestampedFilename").getValue())
129 std::string time = IceUtil::Time::now().toDateTime();
130 time = simox::alg::replace_all(time,
"/",
"-");
131 time = simox::alg::replace_all(time,
" ",
"_");
132 time = simox::alg::replace_all(time,
":",
"-");
133 outputfilePath = outputfilePath.parent_path() / (outputfilePath.stem().string() +
"-" + time + outputfilePath.extension().string());
136 std::string outputfilePathStr = outputfilePath.string();
138 outputfilePath = outputfilePathStr;
142 std::string storageMode = getProperty<std::string>(
"StorageMode").getValue();
143 if (!storageMode.compare(
"file"))
147 else if (!storageMode.compare(
"database"))
153 ARMARX_WARNING <<
"StorageMode " << storageMode <<
" is not supported (database, file). Falling back to default 'database' mode.";
159 for (
auto kv : topicsSubscribers)
161 kv.second->setTime(startTime);
162 std::queue<TopicUtil::TopicData>
data;
163 kv.second->getData(
data);
169 isRecordingEnabled =
true;
171 topicRecoderListener->onStartRecording();
177 std::lock_guard<std::mutex> lock(mutex);
179 if (!isRecordingEnabled)
186 idleCondition.notify_all();
187 if (queueTask->isRunning())
194 ARMARX_IMPORTANT <<
"Wrote everything to file '" << outputfilePath.string() <<
"'";
196 isRecordingEnabled =
false;
213 return "TopicRecorder";
236 std::vector<TopicUtil::TopicData> newDataOfAllTopics;
239 std::queue<TopicUtil::TopicData>
data;
240 elem.second->getData(
data);
242 while (!
data.empty())
244 newDataOfAllTopics.push_back(
data.front());
248 std::sort(newDataOfAllTopics.begin(), newDataOfAllTopics.end(),
250 for (
auto& e : newDataOfAllTopics)
254 if (newDataOfAllTopics.empty())
260 if (getProperty<int>(
"Duration").getValue() > 0)