NamedEvent_WIN32.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // NamedEvent_WIN32.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/NamedEvent_WIN32.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Processes
  8. // Module: NamedEvent
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/NamedEvent_WIN32.h"
  16. #include "Poco/Error.h"
  17. #include "Poco/Exception.h"
  18. #include "Poco/Format.h"
  19. namespace Poco {
  20. NamedEventImpl::NamedEventImpl(const std::string& name):
  21. _name(name)
  22. {
  23. _event = CreateEventA(NULL, FALSE, FALSE, _name.c_str());
  24. if (!_event)
  25. {
  26. DWORD dwRetVal = GetLastError();
  27. throw SystemException(format("cannot create named event %s [Error %d: %s]", _name, (int)dwRetVal, Error::getMessage(dwRetVal)));
  28. }
  29. }
  30. NamedEventImpl::~NamedEventImpl()
  31. {
  32. CloseHandle(_event);
  33. }
  34. void NamedEventImpl::setImpl()
  35. {
  36. if (!SetEvent(_event))
  37. throw SystemException("cannot signal named event", _name);
  38. }
  39. void NamedEventImpl::waitImpl()
  40. {
  41. switch (WaitForSingleObject(_event, INFINITE))
  42. {
  43. case WAIT_OBJECT_0:
  44. return;
  45. default:
  46. throw SystemException("wait for named event failed", _name);
  47. }
  48. }
  49. } // namespace Poco