NamedEvent_WIN32U.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // NamedEvent_WIN32.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/NamedEvent_WIN32U.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_WIN32U.h"
  16. #include "Poco/Error.h"
  17. #include "Poco/Exception.h"
  18. #include "Poco/Format.h"
  19. #include "Poco/UnicodeConverter.h"
  20. namespace Poco {
  21. NamedEventImpl::NamedEventImpl(const std::string& name):
  22. _name(name)
  23. {
  24. UnicodeConverter::toUTF16(_name, _uname);
  25. _event = CreateEventW(NULL, FALSE, FALSE, _uname.c_str());
  26. if (!_event)
  27. {
  28. DWORD dwRetVal = GetLastError();
  29. throw SystemException(format("cannot create named event %s [Error %d: %s]", _name, (int)dwRetVal, Error::getMessage(dwRetVal)));
  30. }
  31. }
  32. NamedEventImpl::~NamedEventImpl()
  33. {
  34. CloseHandle(_event);
  35. }
  36. void NamedEventImpl::setImpl()
  37. {
  38. if (!SetEvent(_event))
  39. throw SystemException("cannot signal named event", _name);
  40. }
  41. void NamedEventImpl::waitImpl()
  42. {
  43. switch (WaitForSingleObject(_event, INFINITE))
  44. {
  45. case WAIT_OBJECT_0:
  46. return;
  47. default:
  48. throw SystemException("wait for named event failed", _name);
  49. }
  50. }
  51. } // namespace Poco