Skip to content

Commit a7995ce

Browse files
authored
Merge pull request #152 from mujin/logEntry
Use direct logEntry and logEntryAttachment
2 parents 0fba876 + fa31671 commit a7995ce

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

CHANELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.72.0 (2024-04-27)
4+
5+
- change `CreateLogEntries` to use `vector<LogEntry>` for memory optimization
6+
37
## 0.71.0 (2024-03-26)
48

59
- Add objectType field in RegisterMinViableRegionInfo

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE )
1818
# Define here the needed parameters
1919
# make sure to change the version in docs/Makefile
2020
set (MUJINCLIENT_VERSION_MAJOR 0)
21-
set (MUJINCLIENT_VERSION_MINOR 71)
21+
set (MUJINCLIENT_VERSION_MINOR 72)
2222
set (MUJINCLIENT_VERSION_PATCH 0)
2323
set (MUJINCLIENT_VERSION ${MUJINCLIENT_VERSION_MAJOR}.${MUJINCLIENT_VERSION_MINOR}.${MUJINCLIENT_VERSION_PATCH})
2424
set (MUJINCLIENT_SOVERSION ${MUJINCLIENT_VERSION_MAJOR}.${MUJINCLIENT_VERSION_MINOR})

include/mujincontrollerclient/mujincontrollerclient.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ struct LogEntryAttachment
144144
{
145145
std::string filename; // filename
146146
std::vector<unsigned char> data; // data for the attachment
147+
148+
// default constructor
149+
LogEntryAttachment() = default;
150+
151+
// move constructor (delete copy constructor)
152+
LogEntryAttachment(LogEntryAttachment&& other) = default;
153+
LogEntryAttachment& operator=(LogEntryAttachment&& other) = default;
147154
};
148155

149156
typedef boost::shared_ptr<LogEntryAttachment> LogEntryAttachmentPtr;
@@ -154,7 +161,7 @@ struct LogEntry
154161
{
155162
rapidjson::Value rEntry; // log entry data in JSON format
156163
std::string logType; // log type
157-
std::vector<LogEntryAttachmentPtr> attachments; // a list of related attachments
164+
std::vector<LogEntryAttachment> attachments; // a list of related attachments
158165
};
159166

160167
typedef boost::shared_ptr<LogEntry> LogEntryPtr;
@@ -724,7 +731,7 @@ class MUJINCLIENT_API ControllerClient
724731
/// \param logEntries a vector of log entries to upload
725732
/// \param createdLogEntryIds an optional vector for storing the created log entry ids
726733
/// \param timeout timeout of uploading log entries in seconds
727-
virtual void CreateLogEntries(const std::vector<LogEntryPtr>& logEntries, std::vector<std::string>& createdLogEntryIds, double timeout = 5) = 0;
734+
virtual void CreateLogEntries(const std::vector<LogEntry>& logEntries, std::vector<std::string>& createdLogEntryIds, double timeout = 5) = 0;
728735
};
729736

730737
class MUJINCLIENT_API WebResource

src/controllerclientimpl.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,7 @@ void ControllerClientImpl::ListFilesInController(std::vector<FileEntry>& fileent
20782078
}
20792079
}
20802080

2081-
void ControllerClientImpl::CreateLogEntries(const std::vector<LogEntryPtr>& logEntries, std::vector<std::string>& createdLogEntryIds, double timeout)
2081+
void ControllerClientImpl::CreateLogEntries(const std::vector<LogEntry>& logEntries, std::vector<std::string>& createdLogEntryIds, double timeout)
20822082
{
20832083
if (logEntries.empty()) {
20842084
return;
@@ -2104,32 +2104,25 @@ void ControllerClientImpl::CreateLogEntries(const std::vector<LogEntryPtr>& logE
21042104
rapidjson::StringBuffer& rRequestStringBuffer = _rRequestStringBufferCache;
21052105
rapidjson::Writer<rapidjson::StringBuffer> writer(rRequestStringBuffer);
21062106

2107-
for (const LogEntryPtr logEntry : logEntries) {
2108-
if (!logEntry) {
2109-
continue;
2110-
}
2111-
2107+
for (const LogEntry &logEntry : logEntries) {
21122108
// add log entry content
21132109
rRequestStringBuffer.Clear();
21142110
writer.Reset(rRequestStringBuffer);
2115-
logEntry->rEntry.Accept(writer);
2116-
std::string formName = "logEntry/" + logEntry->logType;
2111+
logEntry.rEntry.Accept(writer);
2112+
std::string formName = "logEntry/" + logEntry.logType;
21172113
curl_formadd(&formpost, &lastptr,
21182114
CURLFORM_COPYNAME, formName.c_str(),
21192115
CURLFORM_COPYCONTENTS, rRequestStringBuffer.GetString(),
21202116
CURLFORM_CONTENTTYPE, "application/json",
21212117
CURLFORM_END);
21222118

21232119
// add attachments
2124-
for (const LogEntryAttachmentPtr attachment : logEntry->attachments) {
2125-
if (!attachment) {
2126-
continue;
2127-
}
2120+
for (const LogEntryAttachment &attachment : logEntry.attachments) {
21282121
curl_formadd(&formpost, &lastptr,
21292122
CURLFORM_COPYNAME, "attachment",
2130-
CURLFORM_BUFFER, attachment->filename.c_str(),
2131-
CURLFORM_BUFFERPTR, attachment->data.data(),
2132-
CURLFORM_BUFFERLENGTH, (long)(attachment->data.size()),
2123+
CURLFORM_BUFFER, attachment.filename.c_str(),
2124+
CURLFORM_BUFFERPTR, attachment.data.data(),
2125+
CURLFORM_BUFFERLENGTH, (long)(attachment.data.size()),
21332126
CURLFORM_END);
21342127
}
21352128
}

src/controllerclientimpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ControllerClientImpl : public ControllerClient, public boost::enable_share
172172
/// \param logEntries a vector of log entries to upload
173173
/// \param createdLogEntryIds an optional vector for storing the created log entry ids
174174
/// \param timeout timeout of uploading log entries in seconds
175-
void CreateLogEntries(const std::vector<LogEntryPtr>& logEntries, std::vector<std::string>& createdLogEntryIds, double timeout = 5) override;
175+
void CreateLogEntries(const std::vector<LogEntry>& logEntries, std::vector<std::string>& createdLogEntryIds, double timeout = 5) override;
176176

177177
inline std::string GetBaseUri() const
178178
{

0 commit comments

Comments
 (0)