Main Page   Namespace List   Class Hierarchy   Data Structures   File List   Namespace Members   Data Fields   Globals   Related Pages  

DlgEvtHdlr.cpp

Go to the documentation of this file.
00001 /*
00002  * DlgEvtHdlr.cpp
00003  *
00004  * Copyright 2003, MobileSpear Inc. (www.mobilespear.com). All rights reserved.
00005  * Copyright 2003, David Resnick. All rights reserved.
00006  *
00007  * See the file doc\license.txt for the terms of usage and distribution.
00008  */
00009 
00010 #include <bogotel/Portability.h>
00011 #include <bogotel/DlgEvtHdlr.h>
00012 #include <bogotel/BgtErrors.h>
00013 #include <bogotel/util.h>
00014 #include <bogotel/BgtRt.h>
00015 
00016 #include <log4cpp/NDC.hh>
00017 
00018 namespace bogotel {
00019 
00020     CDlgEvtHdlr::CDlgEvtHdlr(ptr_evt_hndlr pHdlr) :
00021     m_pHdlr(pHdlr)
00022     {
00023         m_pThrd = new boost::thread(thread_adapter(&CDlgEvtHdlr::do_thread, this));
00024     }
00025 
00026     CDlgEvtHdlr::~CDlgEvtHdlr()
00027     {
00028         if (m_pThrd) {
00029             // this will cause the event handler to quit
00030             CEvt *pEvt = new CEvt;
00031             pEvt->m_iSysType = CEvt::SysType::DISABLE_HANDLER;
00032             CBgtRt::Instance()->addEvent(pEvt);
00033             m_pThrd->join();
00034             delete m_pThrd;
00035         }
00036 
00037         m_pHdlr = NULL;
00038     }
00039 
00040     void CDlgEvtHdlr::do_thread(void* param)
00041     {
00042         log4cpp::NDC::push("CDlgEvtHdlr");
00043         try {
00044             static_cast<CDlgEvtHdlr*>(param)->run();
00045         } catch(...) {
00046             g_util->log(1, -1, "CDlgEvtHdlr::do_thread_talk: Exception");
00047         }
00048     }
00049  
00050     // Waits for the timer, sending the appropriate event when the timer expires.
00051     // When interrupted, reschedules timer.
00052     void CDlgEvtHdlr::run()
00053     {
00054         // wait for incoming event
00055         long lRemaining;
00056         // some large timeout...
00057         while (CBgtRt::Instance()->waitEvent(86400000, &lRemaining) == resultSUCCESS &&
00058             m_pHdlr) {
00059 
00060             // we have an event -- call event handler with dummy event handle
00063             m_pHdlr(0);
00064         }
00065     }
00066 
00067     bool CDlgEvtHdlr::matchesHandler(ptr_evt_hndlr testPtr)
00068     {
00069         return (testPtr == m_pHdlr);
00070     }
00071 }

Generated on Tue Aug 12 12:41:29 2003 for bogotel by doxygen 1.3. Hosted by SourceForge.net Logo