diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2021-02-02 16:56:57 -0600 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2021-02-04 22:16:10 -0600 |
| commit | bb7d4bdc09d0b52a65b8cf3b5ae629f385fc8011 (patch) | |
| tree | 6d144200ff008c8e8f1f74a51475c54b95f04912 /src/engine/userexperience.cpp | |
| parent | cc5fe7c79aad14819df1b4cb134884b80a945141 (diff) | |
| download | wix-bb7d4bdc09d0b52a65b8cf3b5ae629f385fc8011.tar.gz wix-bb7d4bdc09d0b52a65b8cf3b5ae629f385fc8011.tar.bz2 wix-bb7d4bdc09d0b52a65b8cf3b5ae629f385fc8011.zip | |
Clean up synchronization between the engine and the BA.
Diffstat (limited to 'src/engine/userexperience.cpp')
| -rw-r--r-- | src/engine/userexperience.cpp | 83 |
1 files changed, 44 insertions, 39 deletions
diff --git a/src/engine/userexperience.cpp b/src/engine/userexperience.cpp index ea8b8a19..3a36cab6 100644 --- a/src/engine/userexperience.cpp +++ b/src/engine/userexperience.cpp | |||
| @@ -24,6 +24,13 @@ static HRESULT SendBAMessage( | |||
| 24 | __inout LPVOID pvResults | 24 | __inout LPVOID pvResults |
| 25 | ); | 25 | ); |
| 26 | 26 | ||
| 27 | static HRESULT SendBAMessageFromInactiveEngine( | ||
| 28 | __in BURN_USER_EXPERIENCE* pUserExperience, | ||
| 29 | __in BOOTSTRAPPER_APPLICATION_MESSAGE message, | ||
| 30 | __in const LPVOID pvArgs, | ||
| 31 | __inout LPVOID pvResults | ||
| 32 | ); | ||
| 33 | |||
| 27 | 34 | ||
| 28 | // function definitions | 35 | // function definitions |
| 29 | 36 | ||
| @@ -230,51 +237,31 @@ extern "C" int UserExperienceSendError( | |||
| 230 | return nResult; | 237 | return nResult; |
| 231 | } | 238 | } |
| 232 | 239 | ||
| 233 | extern "C" HRESULT UserExperienceActivateEngine( | 240 | extern "C" void UserExperienceActivateEngine( |
| 234 | __in BURN_USER_EXPERIENCE* pUserExperience, | 241 | __in BURN_USER_EXPERIENCE* pUserExperience |
| 235 | __out_opt BOOL* pfActivated | ||
| 236 | ) | 242 | ) |
| 237 | { | 243 | { |
| 238 | HRESULT hr = S_OK; | ||
| 239 | BOOL fActivated; | ||
| 240 | |||
| 241 | ::EnterCriticalSection(&pUserExperience->csEngineActive); | 244 | ::EnterCriticalSection(&pUserExperience->csEngineActive); |
| 242 | if (InterlockedCompareExchange(reinterpret_cast<LONG*>(&pUserExperience->fEngineActive), TRUE, FALSE)) | 245 | AssertSz(!pUserExperience->fEngineActive, "Engine should have been deactivated before activating it."); |
| 243 | { | 246 | pUserExperience->fEngineActive = TRUE; |
| 244 | AssertSz(FALSE, "Engine should have been deactivated before activating it."); | ||
| 245 | |||
| 246 | fActivated = FALSE; | ||
| 247 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_STATE); | ||
| 248 | } | ||
| 249 | else | ||
| 250 | { | ||
| 251 | fActivated = TRUE; | ||
| 252 | } | ||
| 253 | ::LeaveCriticalSection(&pUserExperience->csEngineActive); | 247 | ::LeaveCriticalSection(&pUserExperience->csEngineActive); |
| 254 | |||
| 255 | if (pfActivated) | ||
| 256 | { | ||
| 257 | *pfActivated = fActivated; | ||
| 258 | } | ||
| 259 | ExitOnRootFailure(hr, "Engine active cannot be changed because it was already in that state."); | ||
| 260 | |||
| 261 | LExit: | ||
| 262 | return hr; | ||
| 263 | } | 248 | } |
| 264 | 249 | ||
| 265 | extern "C" void UserExperienceDeactivateEngine( | 250 | extern "C" void UserExperienceDeactivateEngine( |
| 266 | __in BURN_USER_EXPERIENCE* pUserExperience | 251 | __in BURN_USER_EXPERIENCE* pUserExperience |
| 267 | ) | 252 | ) |
| 268 | { | 253 | { |
| 269 | BOOL fActive = InterlockedExchange(reinterpret_cast<LONG*>(&pUserExperience->fEngineActive), FALSE); | 254 | ::EnterCriticalSection(&pUserExperience->csEngineActive); |
| 270 | fActive = fActive; // prevents warning in "ship" build. | 255 | AssertSz(pUserExperience->fEngineActive, "Engine should have been active before deactivating it."); |
| 271 | AssertSz(fActive, "Engine should have be active before deactivating it."); | 256 | pUserExperience->fEngineActive = FALSE; |
| 257 | ::LeaveCriticalSection(&pUserExperience->csEngineActive); | ||
| 272 | } | 258 | } |
| 273 | 259 | ||
| 274 | extern "C" HRESULT UserExperienceEnsureEngineInactive( | 260 | extern "C" HRESULT UserExperienceEnsureEngineInactive( |
| 275 | __in BURN_USER_EXPERIENCE* pUserExperience | 261 | __in BURN_USER_EXPERIENCE* pUserExperience |
| 276 | ) | 262 | ) |
| 277 | { | 263 | { |
| 264 | // Make a slight optimization here by ignoring the critical section, because all callers should have needed to enter it for their operation anyway. | ||
| 278 | HRESULT hr = pUserExperience->fEngineActive ? HRESULT_FROM_WIN32(ERROR_BUSY) : S_OK; | 265 | HRESULT hr = pUserExperience->fEngineActive ? HRESULT_FROM_WIN32(ERROR_BUSY) : S_OK; |
| 279 | ExitOnRootFailure(hr, "Engine is active, cannot proceed."); | 266 | ExitOnRootFailure(hr, "Engine is active, cannot proceed."); |
| 280 | 267 | ||
| @@ -346,7 +333,7 @@ EXTERN_C BAAPI UserExperienceOnApplyComplete( | |||
| 346 | results.cbSize = sizeof(results); | 333 | results.cbSize = sizeof(results); |
| 347 | results.action = *pAction; | 334 | results.action = *pAction; |
| 348 | 335 | ||
| 349 | hr = SendBAMessage(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONAPPLYCOMPLETE, &args, &results); | 336 | hr = SendBAMessageFromInactiveEngine(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONAPPLYCOMPLETE, &args, &results); |
| 350 | ExitOnFailure(hr, "BA OnApplyComplete failed."); | 337 | ExitOnFailure(hr, "BA OnApplyComplete failed."); |
| 351 | 338 | ||
| 352 | *pAction = results.action; | 339 | *pAction = results.action; |
| @@ -761,7 +748,7 @@ EXTERN_C BAAPI UserExperienceOnDetectComplete( | |||
| 761 | 748 | ||
| 762 | results.cbSize = sizeof(results); | 749 | results.cbSize = sizeof(results); |
| 763 | 750 | ||
| 764 | hr = SendBAMessage(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTCOMPLETE, &args, &results); | 751 | hr = SendBAMessageFromInactiveEngine(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTCOMPLETE, &args, &results); |
| 765 | ExitOnFailure(hr, "BA OnDetectComplete failed."); | 752 | ExitOnFailure(hr, "BA OnDetectComplete failed."); |
| 766 | 753 | ||
| 767 | LExit: | 754 | LExit: |
| @@ -990,7 +977,7 @@ LExit: | |||
| 990 | 977 | ||
| 991 | EXTERN_C BAAPI UserExperienceOnDetectUpdate( | 978 | EXTERN_C BAAPI UserExperienceOnDetectUpdate( |
| 992 | __in BURN_USER_EXPERIENCE* pUserExperience, | 979 | __in BURN_USER_EXPERIENCE* pUserExperience, |
| 993 | __in_z LPCWSTR wzUpdateLocation, | 980 | __in_z_opt LPCWSTR wzUpdateLocation, |
| 994 | __in DWORD64 dw64Size, | 981 | __in DWORD64 dw64Size, |
| 995 | __in VERUTIL_VERSION* pVersion, | 982 | __in VERUTIL_VERSION* pVersion, |
| 996 | __in_z_opt LPCWSTR wzTitle, | 983 | __in_z_opt LPCWSTR wzTitle, |
| @@ -1016,7 +1003,7 @@ EXTERN_C BAAPI UserExperienceOnDetectUpdate( | |||
| 1016 | results.cbSize = sizeof(results); | 1003 | results.cbSize = sizeof(results); |
| 1017 | results.fStopProcessingUpdates = *pfStopProcessingUpdates; | 1004 | results.fStopProcessingUpdates = *pfStopProcessingUpdates; |
| 1018 | 1005 | ||
| 1019 | hr = SendBAMessage(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTUPDATE, &args, &results); | 1006 | hr = SendBAMessageFromInactiveEngine(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTUPDATE, &args, &results); |
| 1020 | ExitOnFailure(hr, "BA OnDetectUpdate failed."); | 1007 | ExitOnFailure(hr, "BA OnDetectUpdate failed."); |
| 1021 | 1008 | ||
| 1022 | if (results.fCancel) | 1009 | if (results.fCancel) |
| @@ -1045,7 +1032,7 @@ EXTERN_C BAAPI UserExperienceOnDetectUpdateBegin( | |||
| 1045 | results.cbSize = sizeof(results); | 1032 | results.cbSize = sizeof(results); |
| 1046 | results.fSkip = *pfSkip; | 1033 | results.fSkip = *pfSkip; |
| 1047 | 1034 | ||
| 1048 | hr = SendBAMessage(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTUPDATEBEGIN, &args, &results); | 1035 | hr = SendBAMessageFromInactiveEngine(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTUPDATEBEGIN, &args, &results); |
| 1049 | ExitOnFailure(hr, "BA OnDetectUpdateBegin failed."); | 1036 | ExitOnFailure(hr, "BA OnDetectUpdateBegin failed."); |
| 1050 | 1037 | ||
| 1051 | if (results.fCancel) | 1038 | if (results.fCancel) |
| @@ -1074,7 +1061,7 @@ EXTERN_C BAAPI UserExperienceOnDetectUpdateComplete( | |||
| 1074 | results.cbSize = sizeof(results); | 1061 | results.cbSize = sizeof(results); |
| 1075 | results.fIgnoreError = *pfIgnoreError; | 1062 | results.fIgnoreError = *pfIgnoreError; |
| 1076 | 1063 | ||
| 1077 | hr = SendBAMessage(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTUPDATECOMPLETE, &args, &results); | 1064 | hr = SendBAMessageFromInactiveEngine(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONDETECTUPDATECOMPLETE, &args, &results); |
| 1078 | ExitOnFailure(hr, "BA OnDetectUpdateComplete failed."); | 1065 | ExitOnFailure(hr, "BA OnDetectUpdateComplete failed."); |
| 1079 | 1066 | ||
| 1080 | if (FAILED(hrStatus)) | 1067 | if (FAILED(hrStatus)) |
| @@ -1124,7 +1111,7 @@ EXTERN_C BAAPI UserExperienceOnElevateComplete( | |||
| 1124 | 1111 | ||
| 1125 | results.cbSize = sizeof(results); | 1112 | results.cbSize = sizeof(results); |
| 1126 | 1113 | ||
| 1127 | hr = SendBAMessage(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONELEVATECOMPLETE, &args, &results); | 1114 | hr = SendBAMessageFromInactiveEngine(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONELEVATECOMPLETE, &args, &results); |
| 1128 | ExitOnFailure(hr, "BA OnElevateComplete failed."); | 1115 | ExitOnFailure(hr, "BA OnElevateComplete failed."); |
| 1129 | 1116 | ||
| 1130 | LExit: | 1117 | LExit: |
| @@ -1452,7 +1439,7 @@ EXTERN_C BAAPI UserExperienceOnLaunchApprovedExeComplete( | |||
| 1452 | 1439 | ||
| 1453 | results.cbSize = sizeof(results); | 1440 | results.cbSize = sizeof(results); |
| 1454 | 1441 | ||
| 1455 | hr = SendBAMessage(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONLAUNCHAPPROVEDEXECOMPLETE, &args, &results); | 1442 | hr = SendBAMessageFromInactiveEngine(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONLAUNCHAPPROVEDEXECOMPLETE, &args, &results); |
| 1456 | ExitOnFailure(hr, "BA OnLaunchApprovedExeComplete failed."); | 1443 | ExitOnFailure(hr, "BA OnLaunchApprovedExeComplete failed."); |
| 1457 | 1444 | ||
| 1458 | LExit: | 1445 | LExit: |
| @@ -1571,7 +1558,7 @@ EXTERN_C BAAPI UserExperienceOnPlanComplete( | |||
| 1571 | 1558 | ||
| 1572 | results.cbSize = sizeof(results); | 1559 | results.cbSize = sizeof(results); |
| 1573 | 1560 | ||
| 1574 | hr = SendBAMessage(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANCOMPLETE, &args, &results); | 1561 | hr = SendBAMessageFromInactiveEngine(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANCOMPLETE, &args, &results); |
| 1575 | ExitOnFailure(hr, "BA OnPlanComplete failed."); | 1562 | ExitOnFailure(hr, "BA OnPlanComplete failed."); |
| 1576 | 1563 | ||
| 1577 | LExit: | 1564 | LExit: |
| @@ -1831,7 +1818,7 @@ EXTERN_C BAAPI UserExperienceOnResolveSource( | |||
| 1831 | results.cbSize = sizeof(results); | 1818 | results.cbSize = sizeof(results); |
| 1832 | results.action = *pAction; | 1819 | results.action = *pAction; |
| 1833 | 1820 | ||
| 1834 | hr = SendBAMessage(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONRESOLVESOURCE, &args, &results); | 1821 | hr = SendBAMessageFromInactiveEngine(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONRESOLVESOURCE, &args, &results); |
| 1835 | ExitOnFailure(hr, "BA OnResolveSource failed."); | 1822 | ExitOnFailure(hr, "BA OnResolveSource failed."); |
| 1836 | 1823 | ||
| 1837 | if (results.fCancel) | 1824 | if (results.fCancel) |
| @@ -2317,3 +2304,21 @@ static HRESULT SendBAMessage( | |||
| 2317 | 2304 | ||
| 2318 | return hr; | 2305 | return hr; |
| 2319 | } | 2306 | } |
| 2307 | |||
| 2308 | static HRESULT SendBAMessageFromInactiveEngine( | ||
| 2309 | __in BURN_USER_EXPERIENCE* pUserExperience, | ||
| 2310 | __in BOOTSTRAPPER_APPLICATION_MESSAGE message, | ||
| 2311 | __in const LPVOID pvArgs, | ||
| 2312 | __inout LPVOID pvResults | ||
| 2313 | ) | ||
| 2314 | { | ||
| 2315 | HRESULT hr = S_OK; | ||
| 2316 | |||
| 2317 | UserExperienceDeactivateEngine(pUserExperience); | ||
| 2318 | |||
| 2319 | hr = SendBAMessage(pUserExperience, message, pvArgs, pvResults); | ||
| 2320 | |||
| 2321 | UserExperienceActivateEngine(pUserExperience); | ||
| 2322 | |||
| 2323 | return hr; | ||
| 2324 | } | ||
