00001 /**************************************************************** 00002 * 00003 * Copyright (c) 2011 00004 * All rights reserved. 00005 * 00006 * Hochschule Bonn-Rhein-Sieg 00007 * University of Applied Sciences 00008 * Computer Science Department 00009 * 00010 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00011 * 00012 * Author: 00013 * Jan Paulus, Nico Hochgeschwender, Michael Reckhaus, Azamat Shakhimardanov 00014 * Supervised by: 00015 * Gerhard K. Kraetzschmar 00016 * 00017 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00018 * 00019 * This sofware is published under a dual-license: GNU Lesser General Public 00020 * License LGPL 2.1 and BSD license. The dual-license implies that users of this 00021 * code may choose which terms they prefer. 00022 * 00023 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00024 * 00025 * Redistribution and use in source and binary forms, with or without 00026 * modification, are permitted provided that the following conditions are met: 00027 * 00028 * * Redistributions of source code must retain the above copyright 00029 * notice, this list of conditions and the following disclaimer. 00030 * * Redistributions in binary form must reproduce the above copyright 00031 * notice, this list of conditions and the following disclaimer in the 00032 * documentation and/or other materials provided with the distribution. 00033 * * Neither the name of the Hochschule Bonn-Rhein-Sieg nor the names of its 00034 * contributors may be used to endorse or promote products derived from 00035 * this software without specific prior written permission. 00036 * 00037 * This program is free software: you can redistribute it and/or modify 00038 * it under the terms of the GNU Lesser General Public License LGPL as 00039 * published by the Free Software Foundation, either version 2.1 of the 00040 * License, or (at your option) any later version or the BSD license. 00041 * 00042 * This program is distributed in the hope that it will be useful, 00043 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00044 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00045 * GNU Lesser General Public License LGPL and the BSD license for more details. 00046 * 00047 * You should have received a copy of the GNU Lesser General Public 00048 * License LGPL and BSD license along with this program. 00049 * 00050 ****************************************************************/ 00051 #include <youbot_driver/youbot/EthercatMaster.hpp> 00052 00053 namespace youbot 00054 { 00055 00056 EthercatMasterInterface* EthercatMaster::instance = 0; 00061 EthercatMasterInterface& EthercatMaster::getInstance(const std::string configFile, const std::string configFilePath, 00062 const bool ethercatMasterWithThread) 00063 { 00064 // Bouml preserved body begin 000E61F1 00065 if (instance == 0) 00066 { 00067 if (ethercatMasterWithThread) 00068 { 00069 instance = new EthercatMasterWithThread(configFile, configFilePath); 00070 } 00071 else 00072 { 00073 instance = new EthercatMasterWithoutThread(configFile, configFilePath); 00074 } 00075 } 00076 return *instance; 00077 // Bouml preserved body end 000E61F1 00078 } 00079 00080 EthercatMasterInterface& EthercatMaster::getInstance() 00081 { 00082 char* configLocation = getenv("YOUBOT_CONFIG_FOLDER_LOCATION"); 00083 if (configLocation == NULL) 00084 throw std::runtime_error( 00085 "EthercatMaster.cpp::getInstance(): Could not find environment variable YOUBOT_CONFIG_FOLDER_LOCATION"); 00086 return EthercatMaster::getInstance("youbot-ethercat.cfg", configLocation); 00087 } 00088 00090 void EthercatMaster::destroy() 00091 { 00092 // Bouml preserved body begin 000E6271 00093 if (instance != 0) 00094 { 00095 delete instance; 00096 instance = 0; 00097 } 00098 // Bouml preserved body end 000E6271 00099 } 00100 00101 } // namespace youbot