Newer
Older

Olivier Stasse
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2019, Olivier Stasse, LAAS-CNRS.
//
// See LICENSE
#include <iostream>
#define ENABLE_RT_LOG
#include <dynamic-graph/real-time-logger.h>
#include <map>
#include <Python.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/entity.h>
#include <vector>
#include "exception.hh"
#include <boost/shared_ptr.hpp>
typedef boost::shared_ptr<std::ofstream> ofstreamShrPtr;
namespace dynamicgraph {
namespace python {
extern PyObject* dgpyError;
namespace debug {
std::map<std::string, ofstreamShrPtr > mapOfFiles_;
PyObject* addLoggerFileOutputStream (PyObject* /*self*/, PyObject* args)
{
char* filename;
if (!PyArg_ParseTuple(args, "s", &filename))
return NULL;
std::string sfilename(filename);
try {
std::ofstream *aofs = new std::ofstream;
ofstreamShrPtr ofs_shrptr = boost::shared_ptr<std::ofstream>(aofs);
aofs->open(filename,
std::ofstream::out);
dynamicgraph::RealTimeLogger::instance();
dgADD_OSTREAM_TO_RTLOG(*aofs);
dgRTLOG() << "Added " << filename << " as an output stream \n";
mapOfFiles_[sfilename]= ofs_shrptr;
} CATCH_ALL_EXCEPTIONS();
return Py_BuildValue ("");
}
PyObject* closeLoggerFileOutputStream (PyObject* /*self*/, PyObject* /*args */)
{
try {
for (std::map<std::string,ofstreamShrPtr>::iterator
it=mapOfFiles_.begin();
it!=mapOfFiles_.end(); ++it)
{
it->second->close();
}
} CATCH_ALL_EXCEPTIONS();
return Py_BuildValue ("");
}
PyObject* addLoggerCoutOutputStream (PyObject* /*self*/, PyObject* /*args*/)
{
try {
dgADD_OSTREAM_TO_RTLOG(std::cout);
} CATCH_ALL_EXCEPTIONS();
return Py_BuildValue ("");
}
PyObject* realTimeLoggerDestroy (PyObject* /*self*/, PyObject* /*args*/)
{
try {
RealTimeLogger::destroy();
} CATCH_ALL_EXCEPTIONS();
return Py_BuildValue ("");
}
PyObject* realTimeLoggerSpinOnce (PyObject* /*self*/, PyObject* /*args*/)
{
try {
RealTimeLogger::instance().spinOnce();
} CATCH_ALL_EXCEPTIONS();
return Py_BuildValue ("");
}
PyObject* realTimeLoggerInstance (PyObject* /*self*/, PyObject* /*args*/)
{
try {
RealTimeLogger::instance();
} CATCH_ALL_EXCEPTIONS();
return Py_BuildValue ("");
}
} // python
} // namespace debug
} // dynamicgraph