changed: update version strings for beta4
[xbmc.git] / xbmc / utils / Event.cpp
blobc0b7fbc008399f26d3db04a0dd43702dfc156ff4
1 /*
2 * XBMC Media Center
3 * Copyright (c) 2002 Frodo
4 * Portions Copyright (c) by the authors of ffmpeg and xvid
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "Event.h"
22 #include "log.h"
24 //////////////////////////////////////////////////////////////////////
25 // Construction/Destruction
26 //////////////////////////////////////////////////////////////////////
28 CEvent::CEvent(bool manual)
30 if(manual)
31 m_hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
32 else
33 m_hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
36 CEvent::CEvent(const CEvent& src)
38 if(DuplicateHandle( GetCurrentProcess()
39 , src.m_hEvent
40 , GetCurrentProcess()
41 , &m_hEvent
42 , 0
43 , TRUE
44 , DUPLICATE_SAME_ACCESS ))
46 CLog::Log(LOGERROR, "CEvent - failed to duplicate handle");
47 m_hEvent = INVALID_HANDLE_VALUE;
51 CEvent::~CEvent()
53 CloseHandle(m_hEvent);
56 CEvent& CEvent::operator=(const CEvent& src)
58 CloseHandle(m_hEvent);
60 if(DuplicateHandle( GetCurrentProcess()
61 , src.m_hEvent
62 , GetCurrentProcess()
63 , &m_hEvent
64 , 0
65 , TRUE
66 , DUPLICATE_SAME_ACCESS ))
68 CLog::Log(LOGERROR, "CEvent - failed to duplicate handle");
69 m_hEvent = INVALID_HANDLE_VALUE;
71 return *this;
75 void CEvent::Wait()
77 if (m_hEvent)
79 WaitForSingleObject(m_hEvent, INFINITE);
83 void CEvent::Set()
85 if (m_hEvent) SetEvent(m_hEvent);
88 void CEvent::Reset()
91 if (m_hEvent) ResetEvent(m_hEvent);
94 HANDLE CEvent::GetHandle()
96 return m_hEvent;
99 bool CEvent::WaitMSec(unsigned int milliSeconds)
102 if (m_hEvent)
104 DWORD dwResult = WaitForSingleObject(m_hEvent, milliSeconds);
105 if (dwResult == WAIT_OBJECT_0) return true;
107 return false;