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
Select Git revision

Target

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