21 #include <boost/bind.hpp> 33 OutStringStream::OutStringStream()
34 :
std::ostringstream(), buffer(0), index(0), bufferSize(0), full(false) {
52 buffer =
new char[
static_cast<size_t>(size)];
59 std::streamsize towrite =
static_cast<std::streamsize
>(size);
65 memcpy(
buffer +
index, data, static_cast<size_t>(towrite));
96 "Trash the current content of the buffers, without saving it.");
116 const std::string &givenname) {
119 if (givenname.length()) {
126 dgDEBUG(5) <<
"Sig <" << sig.
getName() <<
">: new file " << filename << endl;
127 std::ofstream *newfile =
new std::ofstream(filename.c_str());
128 if (!newfile->good()) {
132 "Could not open file " + filename +
" for signal " + signame,
"");
134 dgDEBUG(5) <<
"Newfile:" << (
void *)newfile << endl;
136 dgDEBUG(5) <<
"Creating Outstringstream" << endl;
142 files.push_back(newbuffer);
149 std::lock_guard<std::mutex> files_lock(
files_mtx);
151 FileList::iterator iter =
files.begin();
152 HardFileList::iterator hardIter =
hardFiles.begin();
154 while (
files.end() != iter) {
155 dgDEBUG(25) <<
"Close the files." << endl;
157 std::stringstream *file =
dynamic_cast<stringstream *
>(*iter);
158 std::ofstream *hardFile = *hardIter;
160 (*hardFile) << flush;
169 dgDEBUG(25) <<
"Clear the lists." << endl;
179 FileList::iterator iter =
files.begin();
180 HardFileList::iterator hardIter =
hardFiles.begin();
182 while (
files.end() != iter) {
184 std::ostream *os = *iter;
193 "The buffer is not open",
"");
196 std::ofstream &hardFile = **hardIter;
197 if (!hardFile.good()) {
199 "The file is not open",
"");
202 if ((hardFile.good()) && (NULL != file)) {
203 file->
dump(hardFile);
217 for (FileList::iterator iter =
files.begin();
files.end() != iter; ++iter) {
225 "The buffer is not open",
"");
238 dgDEBUG(45) <<
"Empty file [" << file.tellp() <<
"] <" << file.str().c_str()
242 file.
addData(file.str().c_str(), file.tellp());
243 dgDEBUG(35) <<
"Write data [" << file.tellp() <<
"] <" << file.str().c_str()
250 "The buffer is not open",
"");
262 os << CLASS_NAME <<
" " <<
name <<
" [mode=" << (
play ?
"play" :
"pause")
264 <<
" - Dep list: " << endl;
266 FileList::const_iterator iterFile =
files.begin();
271 os <<
" -> " << (*iter)->getName();
275 const std::streamsize PRECISION = os.precision();
276 const std::streamsize SIZE = file->
index;
277 const std::streamsize MSIZE = file->
bufferSize;
278 unsigned int dec = 0;
279 std::string unit =
"";
280 if ((SIZE >> 30) || (MSIZE >> 30)) {
283 }
else if ((SIZE >> 20) || (MSIZE >> 20)) {
286 }
else if ((SIZE >> 10) || (MSIZE >> 10)) {
290 os <<
"[" << std::setw(1) << std::setprecision(1)
291 << (((double)SIZE + 0.0) / (1 << dec)) << unit <<
"/" 292 << std::setprecision(2) << (((double)MSIZE + 0.0) / (1 << dec)) << unit
294 if (file->
full) os <<
"(FULL)";
295 os.precision(PRECISION);
TracerRealTime(const std::string &n)
std::string docDirectGetter(const std::string &name, const std::string &type)
CommandVoid0< E > * makeCommandVoid0(E &entity, boost::function< void(void)> function, const std::string &docString)
DG_TRACERREALTIME_DLLAPI friend std::ostream & operator<<(std::ostream &os, const TracerRealTime &t)
bool addData(const char *data, const std::streamoff &size)
DirectGetter< E, T > * makeDirectGetter(E &entity, T *ptr, const std::string &docString)
#define dgDEBUGOUT(level)
Stream for the tracer real-time.
#define dgDEBUGINOUT(level)
dynamicgraph::SignalArray_const< double > sig
Main class of the tracer real-time plug-in.
virtual void openFile(const SignalBase< int > &sig, const std::string &filename)
std::string docCommandVoid0(const std::string &doc)
void dump(std::ostream &os)
const std::string & getName() const
std::string shortName() const
virtual void closeFiles()
void resize(const std::streamsize &size)
Abstract root class for all dynamic-graph exceptions.
std::streamsize bufferSize
void display(std::ostream &os) const
Display information on the entity inside the output stream os.
Tracer plug-in main class.
SignalList toTraceSignals
virtual void recordSignal(std::ostream &os, const SignalBase< int > &sig)
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(TracerRealTime, "TracerRealTime")
Exceptions raised when an error related to traces happen.
void addCommand(const std::string &name, command::Command *command)
Add a command to Entity.
virtual void recordSignal(std::ostream &os, const SignalBase< int > &sig)
std::string docDirectSetter(const std::string &name, const std::string &type)
#define dgDEBUGIN(level)
VP_DEBUG.
DirectSetter< E, T > * makeDirectSetter(E &entity, T *ptr, const std::string &docString)