summaryrefslogtreecommitdiff
path: root/i/marvin/src/log/data_circular_buffer_factory.cc
blob: 231f57b442f9bee8be743663163cf086da513ad1 (plain)
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
// 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_;
}