// 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" #include "log_server.hh" #include /// 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. try { LogServer(*dbBuffer_, "", 2442); } catch(std::exception & ex) { std::cout << ex.what() << std::endl; } // 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_; }