cgma
CubitObserver.cpp
Go to the documentation of this file.
00001 #include "CubitObserver.hpp"
00002 #include "CubitObservable.hpp"
00003 #include "CubitEvent.hpp"
00004 #include "AppUtil.hpp"
00005 
00006 CubitObserver::CubitObserver()
00007 {
00008   observableCount = 0;
00009 }
00010 
00011 CubitObserver::~CubitObserver()
00012 {
00013   assert(observableCount == 0);
00014 }
00015 
00016 CubitStatus CubitObserver::register_observable(CubitObservable *observable)
00017 {
00018   if (observable == NULL)
00019     return CUBIT_FAILURE;
00020 
00021     //- add this observer to the observable's list, and if successful,
00022     //- increment the observable count
00023   CubitStatus success = observable->add_observer(this);
00024   
00025   if (success == CUBIT_SUCCESS)
00026     observableCount++;
00027   
00028   return success;
00029 }
00030 
00031 CubitStatus CubitObserver::unregister_observable(CubitObservable *observable)
00032 {
00033   if (observable == NULL)
00034     return CUBIT_FAILURE;
00035 
00036     //- remove this observer from the observable's list, and if successful,
00037     //- decrement the observable count
00038   CubitStatus success = CUBIT_SUCCESS;
00039 
00040     //- only call the remove function on the observable if we're not being called
00041     //- from the observable
00042   success = observable->remove_observer(this);
00043 
00044   if (success == CUBIT_SUCCESS)
00045     observableCount--;
00046   
00047   return success;
00048 }
00049 
00050 CubitStatus CubitObserver::register_observer(CubitObserver* obs)
00051 {
00052     AppUtil::instance()->event_dispatcher().add_observer(obs);
00053     return CUBIT_SUCCESS;
00054 }
00055 
00056 CubitStatus CubitObserver::unregister_observer(CubitObserver* obs)
00057 {
00058     AppUtil::instance()->event_dispatcher().remove_observer(obs);
00059     return CUBIT_SUCCESS;
00060 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines