00001 00002 #include "Core/precomp.h" 00003 #include <list> 00004 00005 #include "API/Core/System/keep_alive.h" 00006 #include "API/Core/System/system.h" 00007 #include "API/Core/System/event_listener.h" 00008 00009 std::list<CL_KeepAlive*> keep_alives; 00010 00011 CL_KeepAlive::CL_KeepAlive() 00012 { 00013 keep_alives.push_back(this); 00014 } 00015 00016 CL_KeepAlive::~CL_KeepAlive() 00017 { 00018 keep_alives.remove(this); 00019 } 00020 00021 void CL_System::keep_alive() 00022 { 00023 for ( 00024 std::list<CL_KeepAlive*>::iterator it = keep_alives.begin(); 00025 it != keep_alives.end(); 00026 it++) 00027 { 00028 (*it)->keep_alive(); 00029 } 00030 } 00031 00032 void CL_System::keep_alive(int millis) 00033 { 00034 CL_EventListener events; 00035 keep_alive(events, millis); 00036 } 00037 00038 bool CL_System::keep_alive(CL_EventListener &events, int timeout) 00039 { 00040 // TODO: Add triggers for keep alive objects. 00041 00042 if (timeout == -1) 00043 { 00044 do CL_System::keep_alive(); while (!events.wait(10)); 00045 00046 return true; 00047 } 00048 else 00049 { 00050 while (timeout > 0) 00051 { 00052 CL_System::keep_alive(); 00053 if (events.wait(timeout > 10 ? 10 : timeout)) return true; 00054 timeout -= 10; 00055 } 00056 00057 return false; 00058 } 00059 }
1.2.6 written by Dimitri van Heesch,
© 1997-2001