aboutsummaryrefslogtreecommitdiffstats
path: root/remote-processor
diff options
context:
space:
mode:
Diffstat (limited to 'remote-processor')
-rw-r--r--remote-processor/AnswerMessage.cpp2
-rw-r--r--remote-processor/AnswerMessage.h6
-rw-r--r--remote-processor/Message.cpp14
-rw-r--r--remote-processor/Message.h64
-rw-r--r--remote-processor/RemoteCommandHandlerTemplate.h4
-rw-r--r--remote-processor/RequestMessage.cpp4
-rw-r--r--remote-processor/RequestMessage.h5
7 files changed, 70 insertions, 29 deletions
diff --git a/remote-processor/AnswerMessage.cpp b/remote-processor/AnswerMessage.cpp
index 341917e..8cfe8d3 100644
--- a/remote-processor/AnswerMessage.cpp
+++ b/remote-processor/AnswerMessage.cpp
@@ -61,7 +61,7 @@ bool CAnswerMessage::success() const
}
// Size
-uint32_t CAnswerMessage::getDataSize() const
+size_t CAnswerMessage::getDataSize() const
{
// Answer
return getStringSize(getAnswer());
diff --git a/remote-processor/AnswerMessage.h b/remote-processor/AnswerMessage.h
index 3f50e7e..9dbcdc8 100644
--- a/remote-processor/AnswerMessage.h
+++ b/remote-processor/AnswerMessage.h
@@ -47,8 +47,10 @@ private:
virtual void fillDataToSend();
// Collect received data
virtual void collectReceivedData();
- // Size
- virtual uint32_t getDataSize() const;
+
+ /** @return size of the answer message in bytes
+ */
+ virtual size_t getDataSize() const;
// Answer
void setAnswer(const std::string& strAnswer);
diff --git a/remote-processor/Message.cpp b/remote-processor/Message.cpp
index 8521117..2662e3d 100644
--- a/remote-processor/Message.cpp
+++ b/remote-processor/Message.cpp
@@ -57,7 +57,7 @@ uint8_t CMessage::getMsgId() const
}
// Data
-void CMessage::writeData(const void* pvData, uint32_t uiSize)
+void CMessage::writeData(const void* pvData, size_t uiSize)
{
assert(_uiIndex + uiSize <= _uiDataSize);
@@ -68,7 +68,7 @@ void CMessage::writeData(const void* pvData, uint32_t uiSize)
_uiIndex += uiSize;
}
-void CMessage::readData(void* pvData, uint32_t uiSize)
+void CMessage::readData(void* pvData, size_t uiSize)
{
assert(_uiIndex + uiSize <= _uiDataSize);
@@ -110,14 +110,14 @@ void CMessage::readString(string& strData)
strData = pcData;
}
-uint32_t CMessage::getStringSize(const string& strData) const
+size_t CMessage::getStringSize(const string& strData) const
{
// Return string length plus room to store its length
return strData.length() + sizeof(uint32_t);
}
// Remaining data size
-uint32_t CMessage::getRemainingDataSize() const
+size_t CMessage::getRemainingDataSize() const
{
return _uiDataSize - _uiIndex;
}
@@ -148,7 +148,7 @@ CMessage::Result CMessage::serialize(CSocket* pSocket, bool bOut, string& strErr
}
// Size
- uint32_t uiSize = sizeof(_ucMsgId) + _uiDataSize;
+ uint32_t uiSize = (uint32_t)(sizeof(_ucMsgId) + _uiDataSize);
if (!pSocket->write(&uiSize, sizeof(uiSize))) {
@@ -264,8 +264,8 @@ uint8_t CMessage::computeChecksum() const
return uiChecksum;
}
-// Data allocation
-void CMessage::allocateData(uint32_t uiSize)
+// Allocation of room to store the message
+void CMessage::allocateData(size_t uiSize)
{
// Remove previous one
if (_pucData) {
diff --git a/remote-processor/Message.h b/remote-processor/Message.h
index 2e52c09..3f5e847 100644
--- a/remote-processor/Message.h
+++ b/remote-processor/Message.h
@@ -64,25 +64,61 @@ public:
protected:
// Msg Id
uint8_t getMsgId() const;
- // Data
- void writeData(const void* pvData, uint32_t uiSize);
- void readData(void* pvData, uint32_t uiSize);
+
+ /** Write raw data to the message
+ *
+ * @param[in] pvData pointer to the data array
+ * @param[in] uiSize array size in bytes
+ */
+ void writeData(const void* pvData, size_t uiSize);
+
+ /** Read raw data from the message
+ *
+ * @param[out] pvData pointer to the data array
+ * @param[in] uiSize array size in bytes
+ */
+ void readData(void* pvData, size_t uiSize);
+
+ /** Write string to the message
+ *
+ * @param[in] strData the string to write
+ */
void writeString(const std::string& strData);
+
+ /** Write string to the message
+ *
+ * @param[out] strData the string to read to
+ */
void readString(std::string& strData);
- uint32_t getStringSize(const std::string& strData) const;
- // Remaining data size
- uint32_t getRemainingDataSize() const;
+
+ /** @return string length plus room to store its length
+ *
+ * @param[in] strData the string to get the size from
+ */
+ size_t getStringSize(const std::string& strData) const;
+
+ /** @return remaining data size to read or to write depending on the context
+ * (request: write, answer: read)
+ */
+ size_t getRemainingDataSize() const;
private:
CMessage(const CMessage&);
CMessage& operator=(const CMessage&);
- // Data allocation
- void allocateData(uint32_t uiDataSize);
+
+ /** Allocate room to store the message
+ *
+ * @param[int] uiDataSize the szie to allocate in bytes
+ */
+ void allocateData(size_t uiDataSize);
// Fill data to send
virtual void fillDataToSend() = 0;
// Collect received data
virtual void collectReceivedData() = 0;
- // Size
- virtual uint32_t getDataSize() const = 0;
+
+ /** @return size of the transaction data in bytes
+ */
+ virtual size_t getDataSize() const = 0;
+
// Checksum
uint8_t computeChecksum() const;
@@ -90,8 +126,8 @@ private:
uint8_t _ucMsgId;
// Data
uint8_t* _pucData;
- // Data size
- uint32_t _uiDataSize;
- // Read/Write Index
- uint32_t _uiIndex;
+ /** Size of the allocated memory to store the message */
+ size_t _uiDataSize;
+ /** Read/Write Index used to iterate across the message data */
+ size_t _uiIndex;
};
diff --git a/remote-processor/RemoteCommandHandlerTemplate.h b/remote-processor/RemoteCommandHandlerTemplate.h
index fbfa059..0b7428d 100644
--- a/remote-processor/RemoteCommandHandlerTemplate.h
+++ b/remote-processor/RemoteCommandHandlerTemplate.h
@@ -190,7 +190,7 @@ private:
const CRemoteCommandParserItem* pRemoteCommandParserItem = _remoteCommandParserVector[uiIndex];
- uint32_t uiRemoteCommandUsageLength = pRemoteCommandParserItem->usage().length();
+ uint32_t uiRemoteCommandUsageLength = (uint32_t)pRemoteCommandParserItem->usage().length();
if (uiRemoteCommandUsageLength > _uiMaxCommandUsageLength) {
@@ -220,7 +220,7 @@ private:
strResult += strUsage;
// Align
- uint32_t uiToSpacesAdd = _uiMaxCommandUsageLength + 5 - strUsage.length();
+ uint32_t uiToSpacesAdd = _uiMaxCommandUsageLength + 5 - (uint32_t)strUsage.length();
while (uiToSpacesAdd--) {
diff --git a/remote-processor/RequestMessage.cpp b/remote-processor/RequestMessage.cpp
index 32b25f6..3f1cdcc 100644
--- a/remote-processor/RequestMessage.cpp
+++ b/remote-processor/RequestMessage.cpp
@@ -140,10 +140,10 @@ void CRequestMessage::collectReceivedData()
}
// Size
-uint32_t CRequestMessage::getDataSize() const
+size_t CRequestMessage::getDataSize() const
{
// Command
- uint32_t uiSize = getStringSize(getCommand());
+ size_t uiSize = getStringSize(getCommand());
// Arguments
uint32_t uiArgument;
diff --git a/remote-processor/RequestMessage.h b/remote-processor/RequestMessage.h
index 17f433b..7a30aaa 100644
--- a/remote-processor/RequestMessage.h
+++ b/remote-processor/RequestMessage.h
@@ -64,7 +64,10 @@ private:
// Collect received data
virtual void collectReceivedData();
// Size
- virtual uint32_t getDataSize() const;
+ /**
+ * @return size of the request message in bytes
+ */
+ virtual size_t getDataSize() const;
// Trim input std::string
static std::string trim(const std::string& strToTrim);