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.

305 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. statobj.cpp
  5. Abstract:
  6. Statistic object implementation.
  7. Author:
  8. Don Ryan (donryan) 04-Jan-1995
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #include "stdafx.h"
  14. #include "llsmgr.h"
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char BASED_CODE THIS_FILE[] = __FILE__;
  18. #endif
  19. IMPLEMENT_DYNCREATE(CStatistic, CCmdTarget)
  20. BEGIN_MESSAGE_MAP(CStatistic, CCmdTarget)
  21. //{{AFX_MSG_MAP(CStatistic)
  22. // NOTE - the ClassWizard will add and remove mapping macros here.
  23. //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25. BEGIN_DISPATCH_MAP(CStatistic, CCmdTarget)
  26. //{{AFX_DISPATCH_MAP(CStatistic)
  27. DISP_PROPERTY_EX(CStatistic, "Application", GetApplication, SetNotSupported, VT_DISPATCH)
  28. DISP_PROPERTY_EX(CStatistic, "LastUsed", GetLastUsed, SetNotSupported, VT_DATE)
  29. DISP_PROPERTY_EX(CStatistic, "Parent", GetParent, SetNotSupported, VT_DISPATCH)
  30. DISP_PROPERTY_EX(CStatistic, "TotalUsed", GetTotalUsed, SetNotSupported, VT_I4)
  31. DISP_PROPERTY_EX(CStatistic, "EntryName", GetEntryName, SetNotSupported, VT_BSTR)
  32. DISP_DEFVALUE(CStatistic, "EntryName")
  33. //}}AFX_DISPATCH_MAP
  34. END_DISPATCH_MAP()
  35. CStatistic::CStatistic(
  36. CCmdTarget* pParent,
  37. LPCTSTR pEntry,
  38. DWORD dwFlags,
  39. long lLastUsed,
  40. long lTotalUsed
  41. )
  42. /*++
  43. Routine Description:
  44. Constructor for statistic object.
  45. Arguments:
  46. pParent - creator of object.
  47. pEntry - user or server product.
  48. dwFlags - details about license.
  49. lLastUsed - date user last used product.
  50. lTotalUsed - total times user used product.
  51. Return Values:
  52. None.
  53. --*/
  54. {
  55. EnableAutomation();
  56. #ifdef ENABLE_PARENT_CHECK
  57. ASSERT(pParent &&
  58. (pParent->IsKindOf(RUNTIME_CLASS(CUser)) ||
  59. pParent->IsKindOf(RUNTIME_CLASS(CProduct))));
  60. #endif // ENABLE_PARENT_CHECK
  61. m_pParent = pParent;
  62. ASSERT(pEntry && *pEntry);
  63. m_strEntry = pEntry;
  64. m_lLastUsed = lLastUsed;
  65. m_lTotalUsed = lTotalUsed;
  66. m_bIsValid = dwFlags & LLS_FLAG_LICENSED;
  67. }
  68. CStatistic::~CStatistic()
  69. /*++
  70. Routine Description:
  71. Destructor for statistic object.
  72. Arguments:
  73. None.
  74. Return Values:
  75. None.
  76. --*/
  77. {
  78. //
  79. // Nothing to do here.
  80. //
  81. }
  82. void CStatistic::OnFinalRelease()
  83. /*++
  84. Routine Description:
  85. When the last reference for an automation object is released
  86. OnFinalRelease is called. This implementation deletes object.
  87. Arguments:
  88. None.
  89. Return Values:
  90. None.
  91. --*/
  92. {
  93. delete this;
  94. }
  95. LPDISPATCH CStatistic::GetApplication()
  96. /*++
  97. Routine Description:
  98. Returns the application object.
  99. Arguments:
  100. None.
  101. Return Values:
  102. VT_DISPATCH.
  103. --*/
  104. {
  105. return theApp.GetAppIDispatch();
  106. }
  107. BSTR CStatistic::GetEntryName()
  108. /*++
  109. Routine Description:
  110. Returns the name of user or server product.
  111. Arguments:
  112. None.
  113. Return Values:
  114. VT_BSTR.
  115. --*/
  116. {
  117. return m_strEntry.AllocSysString();
  118. }
  119. DATE CStatistic::GetLastUsed()
  120. /*++
  121. Routine Description:
  122. Returns the date the user last used the server product.
  123. Arguments:
  124. None.
  125. Return Values:
  126. VT_DATE.
  127. --*/
  128. {
  129. return SecondsSince1980ToDate(m_lLastUsed);
  130. }
  131. BSTR CStatistic::GetLastUsedString()
  132. /*++
  133. Routine Description:
  134. Returns the date last used as a string.
  135. Arguments:
  136. None.
  137. Return Values:
  138. VT_BSTR.
  139. --*/
  140. {
  141. VARIANT vaIn;
  142. VARIANT vaOut;
  143. VariantInit(&vaIn);
  144. VariantInit(&vaOut);
  145. vaIn.vt = VT_DATE;
  146. vaIn.date = SecondsSince1980ToDate(m_lLastUsed);
  147. BSTR bstrDate = NULL;
  148. if (SUCCEEDED(VariantChangeType(&vaOut, &vaIn, 0, VT_BSTR)))
  149. {
  150. bstrDate = vaOut.bstrVal;
  151. }
  152. return bstrDate;
  153. }
  154. LPDISPATCH CStatistic::GetParent()
  155. /*++
  156. Routine Description:
  157. Returns the parent of the object.
  158. Arguments:
  159. None.
  160. Return Values:
  161. VT_DISPATCH.
  162. --*/
  163. {
  164. return m_pParent ? m_pParent->GetIDispatch(TRUE) : NULL;
  165. }
  166. long CStatistic::GetTotalUsed()
  167. /*++
  168. Routine Description:
  169. Returns total number of times client used product.
  170. Arguments:
  171. None.
  172. Return Values:
  173. VT_I4.
  174. --*/
  175. {
  176. return m_lTotalUsed;
  177. }