Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Abstract:
  4. @doc
  5. @module Writer.cpp | Implementation of Writer
  6. @end
  7. Author:
  8. Adi Oltean [aoltean] 08/18/1999
  9. TBD:
  10. Add comments.
  11. Revision History:
  12. Name Date Comments
  13. aoltean 08/18/1999 Created
  14. aoltean 09/22/1999 Making console output clearer
  15. mikejohn 09/19/2000 176860: Added calling convention methods where missing
  16. --*/
  17. /////////////////////////////////////////////////////////////////////////////
  18. // Defines
  19. // C4290: C++ Exception Specification ignored
  20. #pragma warning(disable:4290)
  21. // warning C4511: 'CVssCOMApplication' : copy constructor could not be generated
  22. #pragma warning(disable:4511)
  23. // warning C4127: conditional expression is constant
  24. #pragma warning(disable:4127)
  25. /////////////////////////////////////////////////////////////////////////////
  26. // Includes
  27. #include <wtypes.h>
  28. #include <stddef.h>
  29. #include <oleauto.h>
  30. #include <stdio.h>
  31. #include "vs_assert.hxx"
  32. #include "vss.h"
  33. #include "vsevent.h"
  34. #include "vswriter.h"
  35. #include "tsub.h"
  36. /////////////////////////////////////////////////////////////////////////////
  37. // constants
  38. const WCHAR g_wszTSubApplicationName[] = L"TSub";
  39. /////////////////////////////////////////////////////////////////////////////
  40. // globals
  41. DWORD g_dwMainThreadId = 0;
  42. VSS_ID s_WRITERID =
  43. {
  44. 0xac510e8c, 0x6bef, 0x4c78,
  45. 0x86, 0xb7, 0xcb, 0x99, 0xcd, 0x93, 0x45, 0x6c
  46. };
  47. LPCWSTR s_WRITERNAME = L"TESTWRITER";
  48. CVssTSubWriter::CVssTSubWriter()
  49. {
  50. Initialize
  51. (
  52. s_WRITERID,
  53. s_WRITERNAME,
  54. VSS_UT_USERDATA,
  55. VSS_ST_OTHER,
  56. VSS_APP_FRONT_END,
  57. 60 * 1000 * 10
  58. ); // Timeout - ten minutes
  59. }
  60. /////////////////////////////////////////////////////////////////////////////
  61. // class CVssTSubWriter
  62. bool STDMETHODCALLTYPE CVssTSubWriter::OnPrepareSnapshot()
  63. {
  64. wprintf( L"OnPrepare\n\t#volumes = %ld\n", GetCurrentVolumeCount() );
  65. for(UINT nIndex = 0; nIndex < GetCurrentVolumeCount(); nIndex++)
  66. wprintf( L"\tVolume no. %ld: %s\n", nIndex, GetCurrentVolumeArray()[nIndex]);
  67. WCHAR wszPwd[MAX_PATH];
  68. DWORD dwChars = GetCurrentDirectoryW( MAX_PATH, wszPwd);
  69. bool bPwdIsAffected = IsPathAffected( wszPwd );
  70. if (dwChars > 0)
  71. wprintf( L"Current directory %s is affected by snapshot? %s\n\n",
  72. wszPwd, bPwdIsAffected? L"Yes": L"No");
  73. return true;
  74. }
  75. bool STDMETHODCALLTYPE CVssTSubWriter::OnFreeze()
  76. {
  77. wprintf
  78. (
  79. L"OnFreeze\n\tmy level = %d\n\n",
  80. GetCurrentLevel()
  81. );
  82. return true;
  83. }
  84. bool STDMETHODCALLTYPE CVssTSubWriter::OnThaw()
  85. {
  86. wprintf( L"OnThaw\n\n");
  87. return true;
  88. }
  89. bool STDMETHODCALLTYPE CVssTSubWriter::OnAbort()
  90. {
  91. wprintf( L"OnAbort\n\n");
  92. return true;
  93. }
  94. /////////////////////////////////////////////////////////////////////////////
  95. // Control-C handler routine
  96. BOOL WINAPI CtrlC_HandlerRoutine(
  97. IN DWORD /* dwType */
  98. )
  99. {
  100. // End the message loop
  101. if (g_dwMainThreadId != 0)
  102. PostThreadMessage(g_dwMainThreadId, WM_QUIT, 0, 0);
  103. // Mark that the break was handled.
  104. return TRUE;
  105. }
  106. /////////////////////////////////////////////////////////////////////////////
  107. // WinMain
  108. extern "C" int __cdecl wmain(HINSTANCE /*hInstance*/,
  109. HINSTANCE /*hPrevInstance*/, LPTSTR /*lpCmdLine*/, int /*nShowCmd*/)
  110. {
  111. int nRet = 0;
  112. try
  113. {
  114. // Preparing the CTRL-C handling routine - only for testing...
  115. g_dwMainThreadId = GetCurrentThreadId();
  116. ::SetConsoleCtrlHandler(CtrlC_HandlerRoutine, TRUE);
  117. // Initialize COM library
  118. HRESULT hr = CoInitialize(NULL);
  119. if (FAILED(hr))
  120. {
  121. _ASSERTE(FALSE && "Failure in initializing the COM library");
  122. throw hr;
  123. }
  124. // Declare a CVssTSubWriter instance
  125. CVssTSubWriter *pInstance = new CVssTSubWriter;
  126. if (pInstance == NULL)
  127. throw E_OUTOFMEMORY;
  128. // Subscribe the object.
  129. pInstance->Subscribe();
  130. // message loop - need for STA server
  131. MSG msg;
  132. while (GetMessage(&msg, 0, 0, 0))
  133. DispatchMessage(&msg);
  134. // Subscribe the object.
  135. pInstance->Unsubscribe();
  136. delete pInstance;
  137. // Uninitialize COM library
  138. CoUninitialize();
  139. }
  140. catch(...)
  141. {
  142. _ASSERTE(FALSE && "Unexpected exception");
  143. }
  144. return nRet;
  145. }