Show
Ignore:
Timestamp:
01/30/10 13:18:29 (6 months ago)
Author:
trichards
Message:

Refactored the Event framework so that I_Event is created in EventService? instead of EventQueue?.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Core/branches/0075_TR_SCRIPTING/Event/src/Event.cpp

    r3308 r3330  
    3434 
    3535#include "EventQueue.hpp" 
     36#include "EventService.hpp" 
    3637 
    3738#include <Zen/Core/Scripting/forward_declarations.hpp> 
     
    4445namespace Event { 
    4546//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
    46 Event_impl::Event_impl(EventQueue& _queue) 
    47 :   m_queue(_queue) 
     47Event_impl::Event_impl(EventService& _service) 
     48:   m_service(_service) 
    4849,   m_connections() 
    4950,   m_pMutex(Threading::MutexFactory::create()) 
     
    114115Event_impl::getScriptModule() 
    115116{ 
    116     return m_queue.getScriptModule(); 
     117    return m_service.getScriptModule(); 
    117118} 
    118119 
    119120//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
    120121I_Connection& 
    121 Event_impl::connect(pAction_type _pAction) 
     122Event_impl::connect(pAction_type _pAction, I_EventQueue* _pQueue) 
    122123{ 
    123124    pConnection_type pConnection = new Connection_type(this, _pAction); 
    124125 
    125126    Threading::CriticalSection guard(m_pMutex); 
     127 
    126128    m_connections.push_back(pConnection); 
     129    if (_pQueue) 
     130    { 
     131        EventQueue* pQueue = dynamic_cast<EventQueue*>(_pQueue); 
     132 
     133        if (pQueue) 
     134        { 
     135            m_queues.insert(pQueue); 
     136        } 
     137    } 
     138    else 
     139    { 
     140        // Dispatch to the default queue. 
     141        m_queues.insert(dynamic_cast<EventQueue*>(&m_service.getEventQueue("default"))); 
     142    } 
    127143 
    128144    return *pConnection; 
     
    133149Event_impl::disconnect(Connection_impl* _pConnection) 
    134150{ 
     151    // TODO Keep a refrence count for the queues and 
     152    // when the last connection is disconnected for a 
     153    // given queue, remove it from the set. 
     154 
    135155    Threading::CriticalSection guard(m_pMutex); 
    136156 
     
    146166Event_impl::fireEvent(boost::any _argument) 
    147167{ 
    148     m_queue.queueEvent(this, _argument); 
     168    Threading::CriticalSection guard(m_pMutex); 
     169 
     170    for(Queues_type::iterator iter = m_queues.begin(); iter != m_queues.end(); iter++) 
     171    { 
     172        (*iter)->queueEvent(this, _argument); 
     173    }     
    149174} 
    150175 
     
    182207Event_impl::connectScript(boost::any _scriptObject, boost::any _scriptFunction) 
    183208{ 
    184     ScriptAction* pRawAction = new ScriptAction(m_queue.getScriptObject()->getModule(), 
     209    ScriptAction* pRawAction = new ScriptAction(m_service.getScriptObject()->getModule(), 
    185210        _scriptObject, _scriptFunction); 
    186211 
    187212    pAction_type pAction(pRawAction, boost::bind(&Event_impl::destroyScriptAction, this, _1)); 
    188     return connect(pAction); 
     213 
     214    return connect(pAction, &m_service.getEventQueue("script")); 
    189215} 
    190216