Files
UnrealEngineUWP/Engine/Source/Developer/Windows/LiveCodingServer/Private/External/LC_ChangeNotification.cpp
ben marsh cf183af67c Integrating live coding feature (aka Live++) into UE4.
Allows fast iteration of C++ changes without restarting the application. To use, select the "Live Coding (Experimental)" mode from the drop down menu next to the editor's compile button, or type "LiveCoding" into the console for a monolithic build. Press Ctrl+Alt+F11 to find changes and compile.

Changes vs standalone Live++ version:

* UBT is used to execute builds. This allows standard UE4 adaptive unity mode, allows us to reuse object files when we do regular builds, supports using any build executor allowed by UBT (XGE, SNDBS, etc..).
* Adding new source files is supported.
* Custom visualizer for FNames is supported via a weakly linked symbol in a static library (Engine/Extras/NatvisHelpers).
* Settings are exposed in the editor's project settings dialog.
* Standalone application has been rewritten as a Slate app ("LiveCodingConsole"). There is an additional option to start the program as hidden, where it will not be visible until Ctrl+Alt+F11 is hit. Similarly, closing the window will hide it instead of closing the application.
* Does not require a standalone licensed version of Live++.

Known issues:

* Does not currently support class layout changes / object reinstancing

#rb none
[FYI] Marc.Audy, Stefan.Boberg, Nick.Penwarden
#jira

#ROBOMERGE-SOURCE: CL 5304722 in //UE4/Release-4.22/...
#ROBOMERGE-BOT: RELEASE (Release-4.22 -> Main)

[CL 5309051 by ben marsh in Main branch]
2019-03-05 18:49:25 -05:00

101 lines
2.0 KiB
C++

// Copyright 2011-2019 Molecular Matters GmbH, all rights reserved.
#include "LC_ChangeNotification.h"
#include "LC_Logging.h"
#include "Windows/WindowsHWrapper.h"
ChangeNotification::ChangeNotification(void)
: m_handle(INVALID_HANDLE_VALUE)
{
}
ChangeNotification::~ChangeNotification(void)
{
Destroy();
}
void ChangeNotification::Create(const wchar_t* path)
{
m_handle = ::FindFirstChangeNotificationW(path, Windows::TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE);
if (m_handle == INVALID_HANDLE_VALUE)
{
const DWORD error = ::GetLastError();
LC_ERROR_USER("Cannot create change notification for path %S. Error: 0x%X", path, error);
}
}
void ChangeNotification::Destroy(void)
{
if (m_handle != INVALID_HANDLE_VALUE)
{
::FindCloseChangeNotification(m_handle);
m_handle = INVALID_HANDLE_VALUE;
}
}
bool ChangeNotification::Check(unsigned int timeoutMs)
{
if (m_handle == INVALID_HANDLE_VALUE)
{
// change notification is not active
return false;
}
// check whether there was any change at all.
// if there was, repeatedly wait for other notifications or until the timeout has been reached.
bool hasChange = WaitForNotification(0u);
const bool hadAtLeastOneChange = hasChange;
while (hasChange)
{
::FindNextChangeNotification(m_handle);
hasChange = WaitForNotification(timeoutMs);
}
return hadAtLeastOneChange;
}
bool ChangeNotification::CheckOnce(void)
{
if (m_handle == INVALID_HANDLE_VALUE)
{
// change notification is not active
return false;
}
// check whether there was any change at all.
const bool hasChange = WaitForNotification(0u);
return hasChange;
}
void ChangeNotification::CheckNext(unsigned int timeoutMs)
{
bool hasChange = true;
while (hasChange)
{
::FindNextChangeNotification(m_handle);
hasChange = WaitForNotification(timeoutMs);
}
}
bool ChangeNotification::WaitForNotification(unsigned int timeoutMs)
{
const DWORD waitStatus = ::WaitForSingleObject(m_handle, timeoutMs);
switch (waitStatus)
{
case WAIT_OBJECT_0:
return true;
default:
return false;
}
}