00001 /* 00002 * Copyright (C) 2003-2009 Olivier Boudeville 00003 * 00004 * This file is part of the Ceylan library. 00005 * 00006 * The Ceylan library is free software: you can redistribute it and/or modify 00007 * it under the terms of either the GNU Lesser General Public License or 00008 * the GNU General Public License, as they are published by the Free Software 00009 * Foundation, either version 3 of these Licenses, or (at your option) 00010 * any later version. 00011 * 00012 * The Ceylan library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License and the GNU General Public License 00016 * for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License and the GNU General Public License along with the Ceylan library. 00020 * If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * Author: Olivier Boudeville (olivier.boudeville@esperide.com) 00023 * 00024 */ 00025 00026 00027 #include "CeylanController.h" 00028 00029 00030 #include "CeylanModel.h" // for Ceylan::Model 00031 00032 #include "CeylanLogPlug.h" // for LogPlug 00033 #include "CeylanOperators.h" // for Ceylan::toString 00034 00035 #ifdef CEYLAN_USES_CONFIG_H 00036 #include "CeylanConfig.h" // for CEYLAN_DEBUG_EVENTS 00037 #endif // CEYLAN_USES_CONFIG_H 00038 00039 #include <list> 00040 00041 00042 00043 using std::string ; 00044 using std::list ; 00045 00046 00047 using namespace Ceylan ; 00048 using namespace Ceylan::Log ; 00049 00050 00051 00052 Controller::Controller() : 00053 CallableEventSource() 00054 { 00055 00056 } 00057 00058 00059 00060 Controller::Controller( Model & model ) : 00061 CallableEventSource() 00062 { 00063 00064 model.subscribeTo( * this ) ; 00065 00066 } 00067 00068 00069 00070 Controller::~Controller() throw() 00071 { 00072 00073 // Input device not owned. 00074 00075 #if CEYLAN_DEBUG_EVENTS 00076 LogPlug::debug( "Deleting Controller " + toString() ) ; 00077 #endif // CEYLAN_DEBUG_EVENTS 00078 00079 } 00080 00081 00082 00083 const string Controller::toString( Ceylan::VerbosityLevels level ) const 00084 { 00085 00086 if ( _listeners.empty() ) 00087 return "MVC Controller has currently no model subscribed" ; 00088 00089 return "MVC Controller has currently " 00090 + Ceylan::toString( static_cast<Ceylan::Uint32>( _listeners.size() ) ) 00091 + " model(s) subscribed" ; 00092 00093 } 00094