Switch to unified view

a b/src/bincimapmime/iofactory.cc
1
/*-*-mode:c++-*-*/
2
/*  --------------------------------------------------------------------
3
 *  Filename:
4
 *    src/iofactory.cc
5
 *  
6
 *  Description:
7
 *    Implementation of the IOFactory class.
8
 *  --------------------------------------------------------------------
9
 *  Copyright 2002, 2003 Andreas Aardal Hanssen
10
 *
11
 *  This program is free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  This program is distributed in the hope that it will be useful,
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 *  GNU General Public License for more details.
20
 *
21
 *  You should have received a copy of the GNU General Public License
22
 *  along with this program; if not, write to the Free Software
23
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
24
 *  --------------------------------------------------------------------
25
 */
26
#include "iofactory.h"
27
#include "iodevice.h"
28
29
using namespace ::Binc;
30
using namespace ::std;
31
32
//------------------------------------------------------------------------
33
IOFactory::IOFactory(void)
34
{
35
}
36
37
//------------------------------------------------------------------------
38
IOFactory::~IOFactory(void)
39
{
40
}
41
42
//------------------------------------------------------------------------
43
IOFactory &IOFactory::getInstance(void)
44
{
45
  static IOFactory ioFactory;
46
  return ioFactory;
47
}
48
49
//------------------------------------------------------------------------
50
void IOFactory::addDevice(IODevice *dev)
51
{
52
  IODevice *ioDevice = IOFactory::getInstance().devices[dev->service()];
53
54
  // FIXME: Delete correct object. Now, only IODevice's destructor is
55
  // called, and only IODevice's memory is freed.
56
  if (ioDevice)
57
    delete ioDevice;
58
59
  IOFactory::getInstance().devices[dev->service()] = dev;
60
}
61
62
//------------------------------------------------------------------------
63
IODevice &IOFactory::getClient(void)
64
{
65
  static IODevice nulDevice;
66
67
  IOFactory &ioFactory = IOFactory::getInstance();
68
69
  if (ioFactory.devices.find("client") != ioFactory.devices.end())
70
    return *ioFactory.devices["client"];
71
72
  return nulDevice;
73
}
74
75
//------------------------------------------------------------------------
76
IODevice &IOFactory::getLogger(void)
77
{
78
  static IODevice nulDevice;
79
80
  IOFactory &ioFactory = IOFactory::getInstance();
81
82
  if (ioFactory.devices.find("log") != ioFactory.devices.end())
83
    return *ioFactory.devices["log"];
84
  return nulDevice;
85
}