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.

233 lines
6.7 KiB

  1. /*
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. lease.h
  5. Abstract:
  6. Definition of the CMdhcpLeaseInfo class
  7. Author:
  8. */
  9. #ifndef _MDHCP_COM_WRAPPER_LEASE_H_
  10. #define _MDHCP_COM_WRAPPER_LEASE_H_
  11. /////////////////////////////////////////////////////////////////////////////
  12. /////////////////////////////////////////////////////////////////////////////
  13. // Includes
  14. /////////////////////////////////////////////////////////////////////////////
  15. /////////////////////////////////////////////////////////////////////////////
  16. #if _MSC_VER >= 1000
  17. #pragma once
  18. #endif // _MSC_VER >= 1000
  19. /////////////////////////////////////////////////////////////////////////////
  20. /////////////////////////////////////////////////////////////////////////////
  21. // Non-class-member helper functions
  22. /////////////////////////////////////////////////////////////////////////////
  23. /////////////////////////////////////////////////////////////////////////////
  24. // helper functions for date conversions
  25. HRESULT DateToLeaseTime(DATE date, LONG * pLeaseTime);
  26. HRESULT LeaseTimeToDate(time_t leaseTime, DATE * pDate);
  27. /////////////////////////////////////////////////////////////////////////////
  28. /////////////////////////////////////////////////////////////////////////////
  29. // Custom critical section / locking stuff
  30. /////////////////////////////////////////////////////////////////////////////
  31. /////////////////////////////////////////////////////////////////////////////
  32. class CCritSection
  33. {
  34. private:
  35. CRITICAL_SECTION m_CritSec;
  36. BOOL bInitialized;
  37. public:
  38. CCritSection() :
  39. bInitialized( FALSE )
  40. {
  41. }
  42. ~CCritSection()
  43. {
  44. if( bInitialized )
  45. {
  46. DeleteCriticalSection(&m_CritSec);
  47. }
  48. }
  49. HRESULT Initialize()
  50. {
  51. if( bInitialized )
  52. {
  53. // Already initialized
  54. _ASSERT( FALSE );
  55. return S_OK;
  56. }
  57. //
  58. // We have to initialize the critical section
  59. //
  60. try
  61. {
  62. InitializeCriticalSection(&m_CritSec);
  63. }
  64. catch(...)
  65. {
  66. // Wrong
  67. return E_OUTOFMEMORY;
  68. }
  69. bInitialized = TRUE;
  70. return S_OK;
  71. }
  72. void Lock()
  73. {
  74. EnterCriticalSection(&m_CritSec);
  75. }
  76. BOOL TryLock()
  77. {
  78. return TryEnterCriticalSection(&m_CritSec);
  79. }
  80. void Unlock()
  81. {
  82. LeaveCriticalSection(&m_CritSec);
  83. }
  84. };
  85. /////////////////////////////////////////////////////////////////////////////
  86. /////////////////////////////////////////////////////////////////////////////
  87. // CMDhcpLeaseInfo
  88. /////////////////////////////////////////////////////////////////////////////
  89. /////////////////////////////////////////////////////////////////////////////
  90. class CMDhcpLeaseInfo :
  91. public CComDualImpl<IMcastLeaseInfo, &IID_IMcastLeaseInfo, &LIBID_McastLib>,
  92. public CComObjectRootEx<CComObjectThreadModel>,
  93. public CObjectSafeImpl
  94. {
  95. /////////////////////////////////////////////////////////////////////////
  96. // Private data members
  97. /////////////////////////////////////////////////////////////////////////
  98. private:
  99. // For synchronization -- defined above.
  100. CCritSection m_CriticalSection;
  101. // This is actually a variable length structure, so we must allocate it
  102. // dynamically.
  103. MCAST_LEASE_INFO * m_pLease;
  104. BOOL m_fGotTtl; // TRUE if TTL is meaningful
  105. long m_lTtl; // the TTL for this lease (from scope info!)
  106. // We also contain request ID info. The clientUID field is dynamically
  107. // allocated and must be released on destruction.
  108. MCAST_CLIENT_UID m_RequestID;
  109. // Pointer to the free threaded marshaler.
  110. IUnknown * m_pFTM;
  111. // locally allocated lease -- by default this is false
  112. BOOL m_fLocal;
  113. /////////////////////////////////////////////////////////////////////////
  114. // Private implementation
  115. /////////////////////////////////////////////////////////////////////////
  116. private:
  117. HRESULT MakeBstrArray(BSTR ** ppbszArray);
  118. HRESULT put_RequestID(BSTR pRequestID);
  119. /////////////////////////////////////////////////////////////////////////
  120. // Public methods not belonging to any interface
  121. /////////////////////////////////////////////////////////////////////////
  122. public:
  123. CMDhcpLeaseInfo (void);
  124. HRESULT FinalConstruct (void);
  125. void FinalRelease (void);
  126. ~CMDhcpLeaseInfo(void);
  127. // init with values obtained from CreateLeaseInfo
  128. HRESULT Initialize(
  129. DATE LeaseStartTime,
  130. DATE LeaseStopTime,
  131. DWORD dwNumAddresses,
  132. LPWSTR * ppAddresses,
  133. LPWSTR pRequestID,
  134. LPWSTR pServerAddress
  135. );
  136. // wrap a struct returned from the C API
  137. HRESULT Wrap(
  138. MCAST_LEASE_INFO * pLease,
  139. MCAST_CLIENT_UID * pRequestID,
  140. BOOL fGotTtl,
  141. long lTtl
  142. );
  143. HRESULT GetStruct(
  144. MCAST_LEASE_INFO ** ppLease
  145. );
  146. HRESULT GetRequestIDBuffer(
  147. long lBufferSize,
  148. BYTE * pBuffer
  149. );
  150. HRESULT GetLocal(
  151. BOOL * pfLocal
  152. );
  153. HRESULT SetLocal(
  154. BOOL fLocal
  155. );
  156. /////////////////////////////////////////////////////////////////////////
  157. // General COM stuff
  158. /////////////////////////////////////////////////////////////////////////
  159. public:
  160. BEGIN_COM_MAP(CMDhcpLeaseInfo)
  161. COM_INTERFACE_ENTRY(IDispatch)
  162. COM_INTERFACE_ENTRY(IMcastLeaseInfo)
  163. COM_INTERFACE_ENTRY(IObjectSafety)
  164. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pFTM)
  165. END_COM_MAP()
  166. DECLARE_GET_CONTROLLING_UNKNOWN()
  167. //////////////////////////////////////////////////////////////////////////
  168. // IMcastLeaseInfo interface
  169. //////////////////////////////////////////////////////////////////////////
  170. public:
  171. STDMETHOD (get_RequestID) (BSTR * ppRequestID);
  172. STDMETHOD (get_LeaseStartTime) (DATE * pTime);
  173. STDMETHOD (put_LeaseStartTime) (DATE time);
  174. STDMETHOD (get_LeaseStopTime) (DATE * pTime);
  175. STDMETHOD (put_LeaseStopTime) (DATE time);
  176. STDMETHOD (get_AddressCount) (long * pCount);
  177. STDMETHOD (get_ServerAddress) (BSTR * ppAddress);
  178. STDMETHOD (get_TTL) (long * pTTL);
  179. STDMETHOD (get_Addresses) (VARIANT * pVariant);
  180. STDMETHOD (EnumerateAddresses) (IEnumBstr ** ppEnumAddresses);
  181. };
  182. #endif // _MDHCP_COM_WRAPPER_LEASE_H_
  183. // eof