Source code of Windows XP (NT5)
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.

358 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. svcobj.cpp
  5. Abstract:
  6. Service 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(CService, CCmdTarget)
  20. BEGIN_MESSAGE_MAP(CService, CCmdTarget)
  21. //{{AFX_MSG_MAP(CService)
  22. //}}AFX_MSG_MAP
  23. END_MESSAGE_MAP()
  24. BEGIN_DISPATCH_MAP(CService, CCmdTarget)
  25. //{{AFX_DISPATCH_MAP(CService)
  26. DISP_PROPERTY_EX(CService, "Application", GetApplication, SetNotSupported, VT_DISPATCH)
  27. DISP_PROPERTY_EX(CService, "Name", GetName, SetNotSupported, VT_BSTR)
  28. DISP_PROPERTY_EX(CService, "Parent", GetParent, SetNotSupported, VT_DISPATCH)
  29. DISP_PROPERTY_EX(CService, "PerServerLimit", GetPerServerLimit, SetNotSupported, VT_I4)
  30. DISP_PROPERTY_EX(CService, "IsPerServer", IsPerServer, SetNotSupported, VT_BOOL)
  31. DISP_PROPERTY_EX(CService, "IsReadOnly", IsReadOnly, SetNotSupported, VT_BOOL)
  32. DISP_PROPERTY_EX(CService, "DisplayName", GetDisplayName, SetNotSupported, VT_BSTR)
  33. DISP_DEFVALUE(CService, "Name")
  34. //}}AFX_DISPATCH_MAP
  35. END_DISPATCH_MAP()
  36. CService::CService(
  37. CCmdTarget* pParent,
  38. LPCTSTR pName,
  39. LPCTSTR pDisplayName,
  40. BOOL bIsPerServer,
  41. BOOL bIsReadOnly,
  42. long lPerServerLimit
  43. )
  44. /*++
  45. Routine Description:
  46. Constructor for service object.
  47. Arguments:
  48. pParent - creator of object.
  49. pName - name of service.
  50. pDisplayName - display name of service.
  51. bIsPerServer - true if service per server.
  52. bIsReadOnly - true if service read only.
  53. lPerServerLimit - per server limit.
  54. Return Values:
  55. None.
  56. --*/
  57. {
  58. EnableAutomation();
  59. #ifdef ENABLE_PARENT_CHECK
  60. ASSERT(pParent && pParent->IsKindOf(RUNTIME_CLASS(CServer)));
  61. #endif // ENABLE_PARENT_CHECK
  62. m_pParent = pParent;
  63. ASSERT(pName && *pName);
  64. ASSERT(pDisplayName && *pDisplayName);
  65. m_strName = pName;
  66. m_strDisplayName = pDisplayName;
  67. m_bIsPerServer = bIsPerServer;
  68. m_bIsReadOnly = bIsReadOnly;
  69. m_lPerServerLimit = lPerServerLimit;
  70. }
  71. CService::~CService()
  72. /*++
  73. Routine Description:
  74. Destructor for service object.
  75. Arguments:
  76. None.
  77. Return Values:
  78. None.
  79. --*/
  80. {
  81. //
  82. // Nothing to do here...
  83. //
  84. }
  85. void CService::OnFinalRelease()
  86. /*++
  87. Routine Description:
  88. When the last reference for an automation object is released
  89. OnFinalRelease is called. This implementation deletes object.
  90. Arguments:
  91. None.
  92. Return Values:
  93. None.
  94. --*/
  95. {
  96. delete this;
  97. }
  98. LPDISPATCH CService::GetApplication()
  99. /*++
  100. Routine Description:
  101. Returns the application object.
  102. Arguments:
  103. None.
  104. Return Values:
  105. VT_DISPATCH.
  106. --*/
  107. {
  108. return theApp.GetAppIDispatch();
  109. }
  110. BSTR CService::GetDisplayName()
  111. /*++
  112. Routine Description:
  113. Returns the display name of the service.
  114. Arguments:
  115. None.
  116. Return Values:
  117. VT_BSTR.
  118. --*/
  119. {
  120. return m_strDisplayName.AllocSysString();
  121. }
  122. BSTR CService::GetName()
  123. /*++
  124. Routine Description:
  125. Returns the name of the service.
  126. Arguments:
  127. None.
  128. Return Values:
  129. VT_BSTR.
  130. --*/
  131. {
  132. return m_strName.AllocSysString();
  133. }
  134. LPDISPATCH CService::GetParent()
  135. /*++
  136. Routine Description:
  137. Returns the parent of the object.
  138. Arguments:
  139. None.
  140. Return Values:
  141. VT_DISPATCH.
  142. --*/
  143. {
  144. return m_pParent ? m_pParent->GetIDispatch(TRUE) : NULL;
  145. }
  146. long CService::GetPerServerLimit()
  147. /*++
  148. Routine Description:
  149. Returns the number of clients allowed to use the service at any
  150. one time under per server licensing mode.
  151. Arguments:
  152. None.
  153. Return Values:
  154. VT_I4.
  155. --*/
  156. {
  157. return m_lPerServerLimit;
  158. }
  159. BOOL CService::IsPerServer()
  160. /*++
  161. Routine Description:
  162. Returns true if service is in per server licensing mode.
  163. Arguments:
  164. None.
  165. Return Values:
  166. VT_BOOL.
  167. --*/
  168. {
  169. return m_bIsPerServer;
  170. }
  171. BOOL CService::IsReadOnly()
  172. /*++
  173. Routine Description:
  174. Returns true if service allows changing of it's licensing mode.
  175. Arguments:
  176. None.
  177. Return Values:
  178. VT_BOOL.
  179. --*/
  180. {
  181. return m_bIsReadOnly;
  182. }
  183. #ifdef CONFIG_THROUGH_REGISTRY
  184. HKEY CService::GetRegKey()
  185. /*++
  186. Routine Description:
  187. Returns registry key for service.
  188. Arguments:
  189. None.
  190. Return Values:
  191. HKEY or nul.
  192. --*/
  193. {
  194. HKEY hkeyLicense = NULL;
  195. HKEY hkeyService = NULL;
  196. LONG Status = ERROR_BADKEY;
  197. ASSERT(m_pParent && m_pParent->IsKindOf(RUNTIME_CLASS(CServer)));
  198. if (hkeyLicense = ((CServer*)m_pParent)->m_hkeyLicense)
  199. {
  200. Status = RegOpenKeyEx(
  201. hkeyLicense,
  202. MKSTR(m_strName),
  203. 0, // dwReserved
  204. KEY_ALL_ACCESS,
  205. &hkeyService
  206. );
  207. }
  208. LlsSetLastStatus(Status);
  209. return (Status == ERROR_SUCCESS) ? hkeyService : NULL;
  210. }
  211. #endif