summaryrefslogtreecommitdiff
path: root/i/marvin/src/log/data_circular_buffer_factory.cc
diff options
context:
space:
mode:
Diffstat (limited to 'i/marvin/src/log/data_circular_buffer_factory.cc')
-rw-r--r--i/marvin/src/log/data_circular_buffer_factory.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/i/marvin/src/log/data_circular_buffer_factory.cc b/i/marvin/src/log/data_circular_buffer_factory.cc
new file mode 100644
index 0000000..231f57b
--- /dev/null
+++ b/i/marvin/src/log/data_circular_buffer_factory.cc
@@ -0,0 +1,61 @@
+// data_circular_buffer_factory.cc
+// marvin - programme du robot 2006. {{{
+//
+// Copyright (C) 2006 Dufour Jérémy
+//
+// Robot APB Team/Efrei 2004.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+#include "data_circular_buffer_factory.hh"
+
+/// Initialisation of static member.
+DataCircularBuffer *DataCircularBufferFactory::dbBuffer_ = 0;
+unsigned DataCircularBufferFactory::refCount_ = 0;
+
+/// Default empty constructor.
+DataCircularBufferFactory::DataCircularBufferFactory (void)
+{
+ refCount_++;
+}
+/// Destructor.
+DataCircularBufferFactory::~DataCircularBufferFactory (void)
+{
+ refCount_--;
+ // End of use ?
+ if (!refCount_ && dbBuffer_)
+ {
+ // XXX Create a server in a try/catch block for removing exception.
+// uint8_t c;
+// while (dbBuffer_-> read (&c, 1))
+// std::cout << c;
+ delete dbBuffer_;
+ dbBuffer_ = 0;
+ }
+}
+
+/// Get a DataCircularBuffer.
+DataCircularBuffer &
+DataCircularBufferFactory::getDataCircularBuffer (void)
+{
+ if (!dbBuffer_)
+ // 100Ko
+ // TODO: config ?
+ dbBuffer_ = new DataCircularBuffer (100000);
+ return *dbBuffer_;
+}