26 #include <Ice/ObjectAdapter.h>
27 #include <IceStorm/IceStorm.h>
29 #include <SimoxUtility/algorithm/string/string_tools.h>
63 outputFilename = getProperty<std::string>(
"Outputfile").getValue();
73 auto allTopics =
getIceManager()->getTopicManager()->retrieveAll();
74 for (
auto& elem : allTopics)
80 Ice::StringSeq topics;
81 if (getProperty<std::string>(
"TopicsToLog").getValue() ==
"*")
83 for (
auto& elem : allTopics)
85 topics.push_back(elem.first);
90 topics =
Split(getProperty<std::string>(
"TopicsToLog").getValue(),
",");
92 for (
auto topic : topics)
94 float maxFrequency = -1.f;
98 maxFrequency = atof(topicAndFreq.at(1).c_str());
99 topic = topicAndFreq.at(0);
109 if (getProperty<bool>(
"EnableRecording").getValue())
122 std::lock_guard<std::mutex> lock(mutex);
124 if (isRecordingEnabled)
131 this->maxDuration = maxDuration;
132 outputfilePath = outputFilename;
133 if (getProperty<bool>(
"TimestampedFilename").getValue())
135 std::string time = IceUtil::Time::now().toDateTime();
136 time = simox::alg::replace_all(time,
"/",
"-");
137 time = simox::alg::replace_all(time,
" ",
"_");
138 time = simox::alg::replace_all(time,
":",
"-");
140 outputfilePath.parent_path() /
141 (outputfilePath.stem().string() +
"-" + time + outputfilePath.extension().string());
144 std::string outputfilePathStr = outputfilePath.string();
146 outputfilePath = outputfilePathStr;
150 std::string storageMode = getProperty<std::string>(
"StorageMode").getValue();
151 if (!storageMode.compare(
"file"))
155 else if (!storageMode.compare(
"database"))
162 <<
"StorageMode " << storageMode
163 <<
" is not supported (database, file). Falling back to default 'database' mode.";
169 for (
auto kv : topicsSubscribers)
171 kv.second->setTime(startTime);
172 std::queue<TopicUtil::TopicData>
data;
173 kv.second->getData(
data);
180 isRecordingEnabled =
true;
182 topicRecoderListener->onStartRecording();
188 std::lock_guard<std::mutex> lock(mutex);
190 if (!isRecordingEnabled)
197 idleCondition.notify_all();
198 if (queueTask->isRunning())
205 ARMARX_IMPORTANT <<
"Wrote everything to file '" << outputfilePath.string() <<
"'";
207 isRecordingEnabled =
false;
225 return "TopicRecorder";
247 std::vector<TopicUtil::TopicData> newDataOfAllTopics;
250 std::queue<TopicUtil::TopicData>
data;
251 elem.second->getData(
data);
253 while (!
data.empty())
255 newDataOfAllTopics.push_back(
data.front());
259 std::sort(newDataOfAllTopics.begin(), newDataOfAllTopics.end(), sortFunc);
260 for (
auto& e : newDataOfAllTopics)
264 if (newDataOfAllTopics.empty())
270 if (getProperty<int>(
"Duration").getValue() > 0)