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.

252 lines
7.5 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. MPCConfig.cpp
  5. Abstract:
  6. This file contains the implementation of the MPCConfig class,
  7. the configuration repository for the UploadLibrary.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 04/15/99
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. /////////////////////////////////////////////////////////////////////////////
  14. #define MINIMUM_WAKEUP (1)
  15. #define MAXIMUM_WAKEUP (24*60*60)
  16. #define MINIMUM_WAITBETWEENJOBS (1)
  17. #define MAXIMUM_WAITBETWEENJOBS (60*60)
  18. #define MINIMUM_BANDWIDTHUSAGE (1)
  19. #define MAXIMUM_BANDWIDTHUSAGE (100)
  20. #define MINIMUM_REQUESTTIMEOUT ( 5)
  21. #define MAXIMUM_REQUESTTIMEOUT (2*60)
  22. #define MINIMUM_PACKET_SIZE (256)
  23. #define MAXIMUM_PACKET_SIZE (256*1024)
  24. /////////////////////////////////////////////////////////////////////////////
  25. CMPCConfig::CMPCConfig()
  26. {
  27. __ULT_FUNC_ENTRY( "CMPCConfig::CMPCConfig" );
  28. m_szQueueLocation = L"%TEMP%\\QUEUE\\"; // MPC::wstring m_QueueLocation;
  29. m_dwQueueSize = 10*1024*1024; // DWORD m_QueueSize;
  30. //
  31. m_dwTiming_WakeUp = 30*60; // DWORD m_Timing_WakeUp;
  32. m_dwTiming_WaitBetweenJobs = 30; // DWORD m_Timing_WaitBetweenJobs;
  33. m_dwTiming_BandwidthUsage = 20; // DWORD m_Timing_BandwidthUsage;
  34. m_dwTiming_RequestTimeout = 20; // DWORD m_Timing_RequestTimeout;
  35. //
  36. // Map m_ConnectionTypes;
  37. }
  38. /////////////////////////////////////////////////////////////////////////////
  39. HRESULT CMPCConfig::Load( /*[in] */ const MPC::wstring& szConfigFile ,
  40. /*[out]*/ bool& fLoaded )
  41. {
  42. __ULT_FUNC_ENTRY( "CMPCConfig::Load" );
  43. USES_CONVERSION;
  44. HRESULT hr;
  45. MPC::XmlUtil xml;
  46. CComPtr<IXMLDOMNodeList> xdnlList;
  47. CComPtr<IXMLDOMNode> xdnNode;
  48. MPC::wstring szValue;
  49. long lValue;
  50. bool fFound;
  51. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.Load( szConfigFile.c_str(), L"UPLOADLIBRARYCONFIG", fLoaded ));
  52. if(fLoaded == false)
  53. {
  54. // Something went wrong, probably missing section or invalid format.
  55. xml.DumpError();
  56. __MPC_SET_ERROR_AND_EXIT(hr, S_OK);
  57. }
  58. //
  59. // Parse QUEUE settings.
  60. //
  61. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( L"./QUEUE", L"LOCATION", szValue, fFound ));
  62. if(fFound)
  63. {
  64. m_szQueueLocation = szValue.c_str();
  65. }
  66. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( L"./QUEUE", L"SIZE", szValue, fFound ));
  67. if(fFound)
  68. {
  69. MPC::ConvertSizeUnit( szValue, m_dwQueueSize );
  70. }
  71. //
  72. // Parse TIMING settings.
  73. //
  74. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( L"./TIMING/WAKEUP", L"TIME", szValue, fFound ));
  75. if(fFound)
  76. {
  77. MPC::ConvertTimeUnit( szValue, m_dwTiming_WakeUp );
  78. if(m_dwTiming_WakeUp < MINIMUM_WAKEUP) m_dwTiming_WakeUp = MINIMUM_WAKEUP;
  79. if(m_dwTiming_WakeUp > MAXIMUM_WAKEUP) m_dwTiming_WakeUp = MAXIMUM_WAKEUP;
  80. }
  81. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( L"./TIMING/WAITBETWEENJOBS", L"TIME", szValue, fFound ));
  82. if(fFound)
  83. {
  84. MPC::ConvertTimeUnit( szValue, m_dwTiming_WaitBetweenJobs );
  85. if(m_dwTiming_WaitBetweenJobs < MINIMUM_WAITBETWEENJOBS) m_dwTiming_WaitBetweenJobs = MINIMUM_WAITBETWEENJOBS;
  86. if(m_dwTiming_WaitBetweenJobs > MAXIMUM_WAITBETWEENJOBS) m_dwTiming_WaitBetweenJobs = MAXIMUM_WAITBETWEENJOBS;
  87. }
  88. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( L"./TIMING/BANDWIDTHUSAGE", L"PERCENTAGE", lValue, fFound ));
  89. if(fFound)
  90. {
  91. m_dwTiming_BandwidthUsage = lValue;
  92. if(m_dwTiming_BandwidthUsage < MINIMUM_BANDWIDTHUSAGE) m_dwTiming_BandwidthUsage = MINIMUM_BANDWIDTHUSAGE;
  93. if(m_dwTiming_BandwidthUsage > MAXIMUM_BANDWIDTHUSAGE) m_dwTiming_BandwidthUsage = MAXIMUM_BANDWIDTHUSAGE;
  94. }
  95. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( L"./TIMING/REQUESTTIMEOUT", L"TIME", szValue, fFound ));
  96. if(fFound)
  97. {
  98. MPC::ConvertTimeUnit( szValue, m_dwTiming_RequestTimeout );
  99. if(m_dwTiming_RequestTimeout < MINIMUM_REQUESTTIMEOUT) m_dwTiming_RequestTimeout = MINIMUM_REQUESTTIMEOUT;
  100. if(m_dwTiming_RequestTimeout > MAXIMUM_REQUESTTIMEOUT) m_dwTiming_RequestTimeout = MAXIMUM_REQUESTTIMEOUT;
  101. }
  102. //
  103. // Parse PACKETS settings.
  104. //
  105. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetNodes( L"./PACKETS/CONNECTIONTYPE", &xdnlList ));
  106. for(;SUCCEEDED(hr = xdnlList->nextNode( &xdnNode )) && xdnNode != NULL; xdnNode = NULL)
  107. {
  108. DWORD dwSize;
  109. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( NULL, L"SIZE", szValue, fFound, xdnNode ));
  110. if(fFound == false) continue;
  111. MPC::ConvertSizeUnit( szValue, dwSize );
  112. if(dwSize < MINIMUM_PACKET_SIZE) dwSize = MINIMUM_PACKET_SIZE;
  113. if(dwSize > MAXIMUM_PACKET_SIZE) dwSize = MAXIMUM_PACKET_SIZE;
  114. __MPC_EXIT_IF_METHOD_FAILS(hr, xml.GetAttribute( NULL, L"SPEED", szValue, fFound, xdnNode ));
  115. if(fFound == false) continue;
  116. m_mConnectionTypes[szValue] = dwSize;
  117. }
  118. hr = S_OK;
  119. __ULT_FUNC_CLEANUP;
  120. __ULT_FUNC_EXIT(hr);
  121. }
  122. /////////////////////////////////////////////////////////////////////////////
  123. MPC::wstring CMPCConfig::get_QueueLocation()
  124. {
  125. __ULT_FUNC_ENTRY( "CMPCConfig::get_QueueLocation" );
  126. MPC::wstring szRes = m_szQueueLocation;
  127. int dwLen;
  128. MPC::SubstituteEnvVariables( szRes );
  129. if((dwLen = szRes.length()) > 0)
  130. {
  131. if(szRes[dwLen-1] != L'\\') szRes += L'\\';
  132. }
  133. __ULT_FUNC_EXIT(szRes);
  134. }
  135. DWORD CMPCConfig::get_QueueSize()
  136. {
  137. __ULT_FUNC_ENTRY( "CMPCConfig::get_QueueSize" );
  138. DWORD dwRes = m_dwQueueSize;
  139. __ULT_FUNC_EXIT(dwRes);
  140. }
  141. DWORD CMPCConfig::get_Timing_WakeUp()
  142. {
  143. __ULT_FUNC_ENTRY( "CMPCConfig::get_Timing_WakeUp" );
  144. DWORD dwRes = m_dwTiming_WakeUp;
  145. __ULT_FUNC_EXIT(dwRes);
  146. }
  147. DWORD CMPCConfig::get_Timing_WaitBetweenJobs()
  148. {
  149. __ULT_FUNC_ENTRY( "CMPCConfig::get_Timing_WaitBetweenJobs" );
  150. DWORD dwRes = m_dwTiming_WaitBetweenJobs;
  151. __ULT_FUNC_EXIT(dwRes);
  152. }
  153. DWORD CMPCConfig::get_Timing_BandwidthUsage()
  154. {
  155. __ULT_FUNC_ENTRY( "CMPCConfig::get_Timing_BandwidthUsage" );
  156. DWORD dwRes = m_dwTiming_BandwidthUsage;
  157. //
  158. // Percent of bandwidth cannot be zero...
  159. //
  160. if(dwRes == 0) dwRes = 1;
  161. __ULT_FUNC_EXIT(dwRes);
  162. }
  163. DWORD CMPCConfig::get_Timing_RequestTimeout()
  164. {
  165. __ULT_FUNC_ENTRY( "CMPCConfig::get_Timing_RequestTimeout" );
  166. DWORD dwRes = m_dwTiming_RequestTimeout;
  167. __ULT_FUNC_EXIT(dwRes);
  168. }
  169. DWORD CMPCConfig::get_PacketSize( /*[in]*/ const MPC::wstring& szConnectionType )
  170. {
  171. __ULT_FUNC_ENTRY( "CMPCConfig::get_PacketSize" );
  172. DWORD dwRes = MINIMUM_PACKET_SIZE;
  173. for(IterConst it = m_mConnectionTypes.begin(); it != m_mConnectionTypes.end(); it++)
  174. {
  175. if((*it).first == szConnectionType)
  176. {
  177. dwRes = (*it).second;
  178. break;
  179. }
  180. }
  181. __ULT_FUNC_EXIT(dwRes);
  182. }