Changeset 2956

Show
Ignore:
Timestamp:
04/27/06 17:10:41 (3 years ago)
Author:
madcat
Message:

Object now exposes 'objectUpdated' signal.
Disable Object notifications on startup/shutdown (as before), but enable them when entering main application loop.
Disable object notifications temporary when doing many object updates (optimization).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • hydranode/hnbase/fwd.h

    r2942 r2956  
    9191}; 
    9292 
     93/** 
     94 * Object events, propangated up the object hierarchy, and passed to event 
     95 * handler 
     96 */ 
     97enum ObjectEvent { 
     98        OBJ_MODIFIED = 0x01, //!< This object's data has been modified 
     99        OBJ_ADDED,           //!< An object has been added to this container 
     100        OBJ_REMOVED,         //!< An object has been removed from this container 
     101        OBJ_DESTROY          //!< This object has been destroyed 
     102}; 
     103 
    93104#endif 
  • hydranode/hnbase/object.cpp

    r2942 r2956  
    6767// have parent remove us. 
    6868Object::~Object() { 
    69         notify(m_id, OBJ_DESTROY); 
     69        notify(this, OBJ_DESTROY); 
    7070        if (m_parent) { 
    7171                m_parent->delChild(this); 
     
    191191                ); 
    192192        } 
    193         notify(child->m_id, OBJ_ADDED); 
     193        notify(child, OBJ_ADDED); 
    194194        // Virtual function call 
    195195        onChildAdded(child->m_id); 
     
    218218                m_children = 0; 
    219219        } 
    220         notify(child->m_id, OBJ_REMOVED); 
     220        notify(child, OBJ_REMOVED); 
    221221        // Virtual function call 
    222222        onChildRemoved(child->m_id); 
     
    224224 
    225225// Notifications 
    226 void Object::notify(ObjectId source, ObjectEvent event) { 
     226void Object::notify(Object* source, ObjectEvent event) { 
     227        if (s_notify) { 
     228                objectNotify(source, event); 
     229        } 
    227230        if (m_parent && s_notify) { 
    228231                m_parent->notify(source, event); 
     
    231234 
    232235void Object::notify(ObjectEvent event) { 
    233         notify(getId(), event); 
     236        notify(this, event); 
    234237} 
    235238 
  • hydranode/hnbase/object.h

    r2942 r2956  
    114114#include <hnbase/osdep.h> 
    115115#include <hnbase/event.h> 
     116#include <hnbase/fwd.h> 
    116117#include <map> 
    117118#include <string> 
     
    119120#include <stdexcept> 
    120121#include <boost/noncopyable.hpp> 
     122#include <boost/signals.hpp> 
    121123 
    122124//! Object identifiers are 32-bit unsigned integers 
    123125typedef uint32_t ObjectId; 
    124  
    125 //! Object events, propangated up the object hierarchy, and passed to event 
    126 //! handler 
    127 enum ObjectEvent { 
    128         OBJ_MODIFIED = 0x01, //!< This object's data has been modified 
    129         OBJ_ADDED,           //!< An object has been added to this container 
    130         OBJ_REMOVED,         //!< An object has been removed from this container 
    131         OBJ_DESTROY          //!< This object has been destroyed 
    132 }; 
    133126 
    134127/** 
     
    217210        //@} 
    218211 
     212        /** 
     213         * This signal is emitted whenever this object, or any object beneath 
     214         * it is changed, added or removed. The name for this signal has been 
     215         * chosen to avoid collisions with (possible) derived object variables, 
     216         * since this is public. 
     217         */ 
     218        boost::signal<void (Object*, ObjectEvent)> objectNotify; 
     219 
    219220        //! Static accessors for locating an object with a specific identifier 
    220221        //! from the entire hierarchy. May return null if the object could not 
     
    374375         * parent objects. 
    375376         * 
    376          * @param source        Event source object identifier 
     377         * @param source        Event source object 
    377378         * @param event         Event type 
    378379         */ 
    379         void notify(ObjectId source, ObjectEvent event); 
     380        void notify(Object *source, ObjectEvent event); 
    380381 
    381382        /** 
    382383         * More convenient function for derived classes - no need to pass 
    383          * source id, and event type has convenient default value. 
     384         * source, and event type has convenient default value. 
    384385         */ 
    385386        void notify(ObjectEvent event = OBJ_MODIFIED); 
  • hydranode/hncore/ed2k/serverlist.cpp

    r2948 r2956  
    906906        } 
    907907 
     908        Object::disableNotify(); // optimization 
    908909        // prevent's ping-time showing enormously large pings 
    909910        if (!(*it)->pingInProgress()) { 
     
    924925        (*it)->setLowIdUsers(packet.getLowIdUsers()); 
    925926        (*it)->setFailedCount(0); 
     927        Object::enableNotify(); 
     928        (*it)->notify(); 
    926929 
    927930        boost::format fmt( 
  • hydranode/hncore/hydranode.cpp

    r2888 r2956  
    8282 
    8383        logMsg("Initializing Hydranode Core..."); 
     84        Object::disableNotify(); 
    8485 
    8586        logMsg(" * Initializing Configuration..."); 
     
    117118        Utils::timedCallback(this, &Hydranode::saveSettings, SAVE_INTERVAL); 
    118119        m_running = true; 
     120        Object::enableNotify(); 
    119121        logMsg("Hydranode Core is up and running."); 
    120122} 
     
    135137int Hydranode::cleanUp() { 
    136138        logMsg("Exiting Hydranode Core..."); 
     139        Object::disableNotify(); 
    137140 
    138141        ModManager::instance().onExit();