Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

SubjectImpl.cpp

Go to the documentation of this file.
00001 /***************** <Tweek heading BEGIN do not edit this line> ****************
00002  * Tweek
00003  *
00004  * -----------------------------------------------------------------
00005  * File:          $RCSfile: SubjectImpl.cpp,v $
00006  * Date modified: $Date: 2003/08/03 00:08:28 $
00007  * Version:       $Revision: 1.14 $
00008  * -----------------------------------------------------------------
00009  ***************** <Tweek heading END do not edit this line> *****************/
00010 
00011 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00012  *
00013  * VR Juggler is (C) Copyright 1998-2003 by Iowa State University
00014  *
00015  * Original Authors:
00016  *   Allen Bierbaum, Christopher Just,
00017  *   Patrick Hartling, Kevin Meinert,
00018  *   Carolina Cruz-Neira, Albert Baker
00019  *
00020  * This library is free software; you can redistribute it and/or
00021  * modify it under the terms of the GNU Library General Public
00022  * License as published by the Free Software Foundation; either
00023  * version 2 of the License, or (at your option) any later version.
00024  *
00025  * This library is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00028  * Library General Public License for more details.
00029  *
00030  * You should have received a copy of the GNU Library General Public
00031  * License along with this library; if not, write to the
00032  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00033  * Boston, MA 02111-1307, USA.
00034  *
00035  *************** <auto-copyright.pl END do not edit this line> ***************/
00036 
00037 #include <tweek/tweekConfig.h>
00038 
00039 #include <algorithm>
00040 
00041 #include <vpr/Sync/Mutex.h>
00042 #include <vpr/Util/Debug.h>
00043 
00044 #include <tweek/Util/Debug.h>
00045 #include <tweek/CORBA/SubjectImpl.h>
00046 
00047 
00048 namespace tweek
00049 {
00050 
00051 void SubjectImpl::attach (Observer_ptr o)
00052 {
00053    vpr::Guard<vpr::Mutex> guard(m_observers_mutex);
00054    vprDEBUG(tweekDBG_CORBA, vprDBG_STATE_LVL) << "Attaching observer\n"
00055                                               << vprDEBUG_FLUSH;
00056    m_observers.push_back(Observer::_duplicate(o));
00057 }
00058 
00059 template<class T>
00060 struct RemovePred
00061 {
00062    RemovePred (T o)
00063    {
00064       obj = o;
00065    }
00066 
00067    bool operator() (T thingy)
00068    {
00069       return obj->_is_equivalent(thingy);
00070    }
00071 
00072    T obj;
00073 };
00074 
00075 void SubjectImpl::detach (Observer_ptr o)
00076 {
00077    vpr::Guard<vpr::Mutex> guard(m_observers_mutex);
00078    observer_vec_t::iterator i;
00079 
00080    i = std::remove_if(m_observers.begin(), m_observers.end(),
00081                       RemovePred<Observer_ptr>(o));
00082 
00083    if ( i != m_observers.end() )
00084    {
00085       vprDEBUG(tweekDBG_CORBA, vprDBG_STATE_LVL) << "Removing observer\n"
00086                                                  << vprDEBUG_FLUSH;
00087    }
00088 
00089    m_observers.erase(i, m_observers.end());
00090 }
00091 
00092 void SubjectImpl::notify ()
00093 {
00094    vpr::Guard<vpr::Mutex> guard(m_observers_mutex);
00095    observer_vec_t::iterator i;
00096 
00097    vprDEBUG(tweekDBG_CORBA, vprDBG_STATE_LVL) << "Notifying observers\n"
00098                                               << vprDEBUG_FLUSH;
00099 
00100    for ( i = m_observers.begin(); i != m_observers.end(); i++ )
00101    {
00102       (*i)->update();
00103    }
00104 
00105    vprDEBUG(tweekDBG_CORBA, vprDBG_STATE_LVL) << "Done notifying observers\n"
00106                                               << vprDEBUG_FLUSH;
00107 }
00108 
00109 // ============================================================================
00110 // Protected methods follow.
00111 // ============================================================================
00112 
00113 SubjectImpl::SubjectImpl(const SubjectImpl& s)
00114    :
00115 #ifdef OMNIORB_VER
00116      omniServant(s)
00117    , tweek::_impl_Subject(s)
00118    ,
00119 #endif
00120      PortableServer::ServantBase(s)
00121    , POA_tweek::Subject(s)
00122    , PortableServer::RefCountServantBase(s)
00123 {
00124    /* Do nothing. */ ;
00125 }
00126 
00127 } // End of tweek namespace

Generated on Sun May 2 14:41:03 2004 for Tweek by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002