Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions parameter/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,38 +52,18 @@ CElement::~CElement()
// Logging
void CElement::log_info(const char* strMessage, ...) const
{
char *pacBuffer;
va_list listPointer;

va_start(listPointer, strMessage);

vasprintf(&pacBuffer, strMessage, listPointer);

vLog(false, strMessage, listPointer);
va_end(listPointer);

if (pacBuffer != NULL) {
doLog(false, pacBuffer);
}

free(pacBuffer);
}

void CElement::log_warning(const char* strMessage, ...) const
{
char *pacBuffer;
va_list listPointer;

va_start(listPointer, strMessage);

vasprintf(&pacBuffer, strMessage, listPointer);

vLog(true, strMessage, listPointer);
va_end(listPointer);

if (pacBuffer != NULL) {
doLog(true, pacBuffer);
}

free(pacBuffer);
}

// Log each element of the string list
Expand All @@ -99,6 +79,18 @@ void CElement::log_table(bool bIsWarning, const std::list<string> lstrMessage) c
}
}

void CElement::vLog(bool bIsWarning, const char *strMessage, va_list args) const
{
char *pacBuffer;
if(vasprintf(&pacBuffer, strMessage, args) == -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coding style

return doLog(true, std::string() + "Unable to format " +
(bIsWarning ? "warning" : "info log") +
": " + strMessage);
}
doLog(bIsWarning, pacBuffer);
free(pacBuffer);
}

void CElement::doLog(bool bIsWarning, const string& strLog) const
{
assert(_pParent);
Expand Down
2 changes: 2 additions & 0 deletions parameter/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <string>
#include <vector>
#include <stdint.h>
#include <stdio.h>
#include <list>
#include "XmlSink.h"
#include "XmlSource.h"
Expand All @@ -52,6 +53,7 @@ class CElement : public IXmlSink, public IXmlSource
void log_info(const char* strMessage, ...) const;
void log_warning(const char* strMessage, ...) const;
void log_table(bool bIsWarning, const std::list<std::string> lstrMessage) const;
void vLog(bool bIsWarning, const char *strMessage, va_list args) const;

// Description
void setDescription(const std::string& strDescription);
Expand Down
24 changes: 2 additions & 22 deletions parameter/SubsystemObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,38 +215,18 @@ void CSubsystemObject::blackboardWrite(const void* pvData, uint32_t uiSize)
// Logging
void CSubsystemObject::log_info(std::string strMessage, ...) const
{
char *pacBuffer;
va_list listPointer;

va_start(listPointer, strMessage);

vasprintf(&pacBuffer, strMessage.c_str(), listPointer);

_pInstanceConfigurableElement->vLog(false, strMessage.c_str(), listPointer);
va_end(listPointer);

if (pacBuffer != NULL) {
_pInstanceConfigurableElement->log_info("%s", pacBuffer);
}

free(pacBuffer);
}

void CSubsystemObject::log_warning(std::string strMessage, ...) const
{
char *pacBuffer;
va_list listPointer;

va_start(listPointer, strMessage);

vasprintf(&pacBuffer, strMessage.c_str(), listPointer);

_pInstanceConfigurableElement->vLog(true, strMessage.c_str(), listPointer);
va_end(listPointer);

if (pacBuffer != NULL) {
_pInstanceConfigurableElement->log_warning("%s", pacBuffer);
}

free(pacBuffer);
}

// Configurable element retrieval
Expand Down