solarpowerlog trunk
/home/tobi/workspace/solarpowerlog/src/Connections/factories/IConnectFactory.cpp
Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  solarpowerlog
00003  Copyright (C) 2009  Tobias Frost
00004 
00005  This file is part of solarpowerlog.
00006 
00007  Solarpowerlog is free software; However, it is dual-licenced
00008  as described in the file "COPYING".
00009 
00010  For this file (IConnectFactory.cpp), the license terms are:
00011 
00012  You can redistribute it and/or modify it under the terms of the GNU
00013  General Public License as published by the Free Software Foundation; either
00014  version 3 of the License, or (at your option) any later version.
00015 
00016  This program is distributed in the hope that it will be useful, but
00017  WITHOUT ANY WARRANTY; without even the implied warranty of
00018  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  Lesser General Public License for more details.
00020 
00021  You should have received a copy of the GNU Library General Public
00022  License along with this proramm; if not, see
00023  <http://www.gnu.org/licenses/>.
00024  ----------------------------------------------------------------------------
00025  */
00026 
00033 #ifdef HAVE_CONFIG_H
00034 #include "config.h"
00035 #include "porting.h"
00036 #endif
00037 
00038 #include "configuration/Registry.h"
00039 #include "configuration/CConfigHelper.h"
00040 #include "Connections/factories/IConnectFactory.h"
00041 #include "Connections/CConnectDummy.h"
00042 
00043 #include <libconfig.h++>
00044 
00045 #ifdef HAVE_COMMS_ASIOTCPIO
00046 #include "Connections/CConnectTCPAsio.h"
00047 #endif
00048 
00049 #ifdef HAVE_COMMS_ASIOSERIAL
00050 #include "Connections/CConnectSerialAsio.h"
00051 #endif
00052 
00053 #ifdef HAVE_COMMS_SHAREDCONNECTION
00054 #include "Connections/CSharedConnection.h"
00055 #endif
00056 
00057 using namespace std;
00058 
00065 IConnect * IConnectFactory::Factory( const string &configurationpath )
00066 {
00067      string type = "";
00068      CConfigHelper cfghelper(configurationpath);
00069      cfghelper.GetConfig("comms",type);
00070 
00071 #ifdef HAVE_COMMS_ASIOTCPIO
00072      if (type == "TCP/IP") {
00073           return new CConnectTCPAsio(configurationpath);
00074      }
00075 #endif
00076 #ifdef HAVE_COMMS_ASIOSERIAL
00077      if (type == "RS2xx") {
00078           return new CConnectSerialAsio(configurationpath);
00079      }
00080 #endif
00081 #ifdef HAVE_COMMS_SHAREDCONNECTION
00082      if (type == "SharedConnection") {
00083           return new CSharedConnection(configurationpath);
00084      }
00085 #endif
00086 
00087      return new CConnectDummy(configurationpath);
00088 }
00089