Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cberge/dynamic-graph
  • ostasse/dynamic-graph
  • gsaurel/dynamic-graph
  • stack-of-tasks/dynamic-graph
4 results
Show changes
Showing
with 199 additions and 164 deletions
......@@ -8,6 +8,7 @@
*/
#include <dynamic-graph/debug.h>
#include <fstream>
#include <ios>
......@@ -32,7 +33,7 @@ std::ofstream dg_debugfile("/tmp/dynamic-graph-traces.txt",
#else
std::ofstream dg_debugfile;
class dgDebug_init {
public:
public:
dgDebug_init() { dg_debugfile.setstate(std::ios::failbit); }
};
dgDebug_init dgDebug_initialisator;
......@@ -42,11 +43,10 @@ dgDebug_init dgDebug_initialisator;
namespace dynamicgraph {
DebugTrace dgDEBUGFLOW(dg_debugfile);
DebugTrace dgERRORFLOW(dg_debugfile);
} // namespace dynamicgraph
} // namespace dynamicgraph
void DebugTrace::openFile(const char *filename) {
if (dg_debugfile.good() && dg_debugfile.is_open())
dg_debugfile.close();
if (dg_debugfile.good() && dg_debugfile.is_open()) dg_debugfile.close();
dg_debugfile.clear();
dg_debugfile.open(filename, std::ios::trunc & std::ios::out);
}
......
......@@ -13,17 +13,18 @@
#define ENABLE_RT_LOG
#include <dynamic-graph/logger.h>
#include <iomanip> // std::setprecision
#include <iostream>
#include <sstream>
#include <dynamic-graph/real-time-logger.h>
#include <stdio.h>
#include <dynamic-graph/real-time-logger.h>
#include <iomanip> // std::setprecision
#include <iostream>
#include <sstream>
namespace dynamicgraph {
Logger::Logger(double timeSample, double streamPrintPeriod)
: m_timeSample(timeSample), m_streamPrintPeriod(streamPrintPeriod),
: m_timeSample(timeSample),
m_streamPrintPeriod(streamPrintPeriod),
m_printCountdown(0.0) {
m_lv = VERBOSITY_ERROR;
}
......@@ -34,8 +35,7 @@ void Logger::setVerbosity(LoggerVerbosity lv) { m_lv = lv; }
LoggerVerbosity Logger::getVerbosity() { return m_lv; }
void Logger::countdown() {
if (m_printCountdown < 0.0)
m_printCountdown = m_streamPrintPeriod;
if (m_printCountdown < 0.0) m_printCountdown = m_streamPrintPeriod;
m_printCountdown -= m_timeSample;
}
......@@ -51,15 +51,13 @@ void Logger::sendMsg(std::string msg, MsgType type, const std::string &file,
}
bool Logger::setTimeSample(double t) {
if (t <= 0.0)
return false;
if (t <= 0.0) return false;
m_timeSample = t;
return true;
}
bool Logger::setStreamPrintPeriod(double s) {
if (s <= 0.0)
return false;
if (s <= 0.0) return false;
m_streamPrintPeriod = s;
return true;
}
......@@ -79,9 +77,9 @@ bool Logger::checkStreamPeriod(const std::string &lineId) {
counter -= m_timeSample;
if (counter > 0.0) {
return false;
} else // otherwise reset counter and print
} else // otherwise reset counter and print
counter = m_streamPrintPeriod;
return true;
}
} // namespace dynamicgraph
} // namespace dynamicgraph
......@@ -13,21 +13,21 @@
namespace dynamicgraph {
RealTimeLogger::RealTimeLogger(const std::size_t &bufferSize)
: buffer_(bufferSize, NULL), frontIdx_(0), backIdx_(0), oss_(NULL),
: buffer_(bufferSize, NULL),
frontIdx_(0),
backIdx_(0),
oss_(NULL),
nbDiscarded_(0) {
for (std::size_t i = 0; i < buffer_.size(); ++i)
buffer_[i] = new Data;
for (std::size_t i = 0; i < buffer_.size(); ++i) buffer_[i] = new Data;
}
RealTimeLogger::~RealTimeLogger() {
// Check that we are not spinning...
for (std::size_t i = 0; i < buffer_.size(); ++i)
delete buffer_[i];
for (std::size_t i = 0; i < buffer_.size(); ++i) delete buffer_[i];
}
bool RealTimeLogger::spinOnce() {
if (empty())
return false;
if (empty()) return false;
Data *data = buffer_[frontIdx_];
frontIdx_ = (frontIdx_ + 1) % buffer_.size();
std::string str = data->buf.str();
......@@ -67,8 +67,11 @@ struct RealTimeLogger::thread {
boost::thread t_;
explicit thread(RealTimeLogger *logger)
: requestShutdown_(false), threadPolicy_(SCHED_OTHER), threadPriority_(0),
changedThreadParams(true), t_(&thread::spin, this, logger) {}
: requestShutdown_(false),
threadPolicy_(SCHED_OTHER),
threadPriority_(0),
changedThreadParams(true),
t_(&thread::spin, this, logger) {}
// void setThreadPolicy(int policy) {
// threadPolicy_ = policy;
......@@ -107,8 +110,7 @@ struct RealTimeLogger::thread {
// Do a pause
if (!logger->spinOnce())
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
if (changedThreadParams)
changeThreadParams();
if (changedThreadParams) changeThreadParams();
}
}
};
......@@ -125,11 +127,10 @@ RealTimeLogger &RealTimeLogger::instance() {
}
void RealTimeLogger::destroy() {
if (instance_ == NULL)
return;
if (instance_ == NULL) return;
thread_->requestShutdown_ = true;
thread_->t_.join();
delete instance_;
delete thread_;
}
} // namespace dynamicgraph
} // namespace dynamicgraph
......@@ -14,9 +14,10 @@
#include <dynamic-graph/pool.h>
/*! System includes */
#include <sstream>
#include <stdlib.h>
#include <sstream>
using namespace std;
using namespace dynamicgraph;
using dynamicgraph::command::Command;
......@@ -68,7 +69,7 @@ void Entity::signalRegistration(const SignalArray<int> &signals) {
const string &signame(buffer);
SignalMap::iterator sigkey = signalMap.find(signame);
if (sigkey != signalMap.end()) // key does exist
if (sigkey != signalMap.end()) // key does exist
{
dgERRORF("Key %s already exist in the signalMap.", signame.c_str());
if (sigkey->second != &sig) {
......@@ -87,7 +88,7 @@ void Entity::signalRegistration(const SignalArray<int> &signals) {
void Entity::signalDeregistration(const std::string &signame) {
SignalMap::iterator sigkey = signalMap.find(signame);
if (sigkey == signalMap.end()) // key does not exist
if (sigkey == signalMap.end()) // key does not exist
{
dgERRORF("Key %s does not exist in the signalMap.", signame.c_str());
throw ExceptionFactory(ExceptionFactory::UNREFERED_SIGNAL,
......@@ -105,14 +106,14 @@ std::string Entity::getDocString() const {
return docString;
}
#define __DG_ENTITY_GET_SIGNAL__(ITER_TYPE) \
SignalMap::ITER_TYPE sigkey = signalMap.find(signame); \
if (sigkey == signalMap.end()) /* key does NOT exist */ \
{ \
throw ExceptionFactory(ExceptionFactory::UNREFERED_SIGNAL, \
"The requested signal is not registered", ": %s", \
signame.c_str()); \
} \
#define __DG_ENTITY_GET_SIGNAL__(ITER_TYPE) \
SignalMap::ITER_TYPE sigkey = signalMap.find(signame); \
if (sigkey == signalMap.end()) /* key does NOT exist */ \
{ \
throw ExceptionFactory(ExceptionFactory::UNREFERED_SIGNAL, \
"The requested signal is not registered", ": %s", \
signame.c_str()); \
} \
return *(sigkey->second);
bool Entity::hasSignal(const string &signame) const {
......@@ -185,9 +186,9 @@ const std::string &Entity::getCommandList() const {
/// Add a command to Entity
void Entity::addCommand(const std::string &inName, Command *command) {
if (commandMap.count(inName) != 0) {
DG_THROW ExceptionFactory(ExceptionFactory::OBJECT_CONFLICT,
"Command " + inName +
" already registered in Entity.");
DG_THROW ExceptionFactory(
ExceptionFactory::OBJECT_CONFLICT,
"Command " + inName + " already registered in Entity.");
}
std::pair<const std::string, Command *> item(inName, command);
commandMap.insert(item);
......@@ -200,14 +201,14 @@ std::map<const std::string, Command *> Entity::getNewStyleCommandMap() {
Command *Entity::getNewStyleCommand(const std::string &commandName) {
if (commandMap.count(commandName) != 1) {
DG_THROW ExceptionFactory(ExceptionFactory::UNREFERED_FUNCTION,
"Command <" + commandName +
"> is not registered in Entity.");
DG_THROW ExceptionFactory(
ExceptionFactory::UNREFERED_FUNCTION,
"Command <" + commandName + "> is not registered in Entity.");
}
return commandMap[commandName];
}
void Entity::sendMsg(const std::string &msg, MsgType t,
const std::string &lineId) {
logger_.sendMsg("[" + name + "]" + msg, t, lineId);
logger_.stream(t, lineId) << "[" << name << "]" << msg << '\n';
}
......@@ -2,10 +2,11 @@
// JRL, CNRS/AIST.
//
#include "dynamic-graph/factory.h"
#include <boost/foreach.hpp>
#include "dynamic-graph/debug.h"
#include "dynamic-graph/factory.h"
using namespace std;
using namespace dynamicgraph;
......@@ -39,9 +40,10 @@ void FactoryStorage::registerEntity(const std::string &entname,
"Another entity class already defined with the same name. ",
"(while adding entity class <%s> inside the factory).",
entname.c_str());
dgERRORF("Another entity class already defined with the same name. "
"(while adding entity class <%s> inside the factory).",
entname.c_str());
dgERRORF(
"Another entity class already defined with the same name. "
"(while adding entity class <%s> inside the factory).",
entname.c_str());
} else {
if (!ent) {
// FIXME: we should have a better error code for that.
......@@ -118,4 +120,4 @@ EntityRegisterer::~EntityRegisterer() {
// The global factory.
FactoryStorage *FactoryStorage::instance_ = NULL;
} // end of namespace dynamicgraph.
} // end of namespace dynamicgraph.
......@@ -13,13 +13,15 @@
/* --- DYNAMIC-GRAPH --- */
#include "dynamic-graph/pool.h"
#include "dynamic-graph/debug.h"
#include "dynamic-graph/entity.h"
#include <list>
#include <sstream>
#include <string>
#include <typeinfo>
#include "dynamic-graph/debug.h"
#include "dynamic-graph/entity.h"
using namespace dynamicgraph;
/* --------------------------------------------------------------------- */
......@@ -57,7 +59,7 @@ PoolStorage::~PoolStorage() {
/* --------------------------------------------------------------------- */
void PoolStorage::registerEntity(const std::string &entname, Entity *ent) {
Entities::iterator entkey = entityMap.find(entname);
if (entkey != entityMap.end()) // key does exist
if (entkey != entityMap.end()) // key does exist
{
throw ExceptionFactory(
ExceptionFactory::OBJECT_CONFLICT,
......@@ -72,7 +74,7 @@ void PoolStorage::registerEntity(const std::string &entname, Entity *ent) {
void PoolStorage::deregisterEntity(const std::string &entname) {
Entities::iterator entkey = entityMap.find(entname);
if (entkey == entityMap.end()) // key doesnot exist
if (entkey == entityMap.end()) // key doesnot exist
{
throw ExceptionFactory(ExceptionFactory::OBJECT_CONFLICT,
"Entity not defined yet. ", "Entity name is <%s>.",
......@@ -207,7 +209,7 @@ static bool objectNameParser(std::istringstream &cmdparse, std::string &objName,
char buffer[SIZE];
cmdparse >> std::ws;
cmdparse.getline(buffer, SIZE, '.');
if (!cmdparse.good()) // The callback is not an object method
if (!cmdparse.good()) // The callback is not an object method
return false;
objName = buffer;
......
This diff is collapsed.
......@@ -7,11 +7,12 @@
*
*/
#include <cstdio>
#include <dynamic-graph/debug.h>
#include <dynamic-graph/exception-factory.h>
#include <stdarg.h>
#include <cstdio>
using namespace dynamicgraph;
/* --------------------------------------------------------------------- */
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -5,6 +5,7 @@
#include <dynamic-graph/exception-factory.h>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/pool.h>
#include <sstream>
#define BOOST_TEST_MODULE customEntity
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.