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.

235 lines
7.3 KiB

  1. /*---------------------------------------------------------------------------
  2. File: VSet.h
  3. Comments: Class definition for CVSet, which implements the IVarSet interface.
  4. (c) Copyright 1995-1999, Mission Critical Software, Inc., All Rights Reserved
  5. Proprietary and confidential to Mission Critical Software, Inc.
  6. REVISION LOG ENTRY
  7. Revision By: Christy Boles
  8. Revised on 11/19/98 19:44:31
  9. ---------------------------------------------------------------------------
  10. */
  11. // VSet.h : Declaration of the CVSet
  12. #ifndef __VSET_H_
  13. #define __VSET_H_
  14. #include "resource.h" // main symbols
  15. #ifdef STRIPPED_VARSET
  16. #include "NoMcs.h"
  17. #else
  18. #include "Mcs.h"
  19. #endif
  20. #include "VarData.h"
  21. #define VARSET_RESTRICT_NOCHANGEDATA (0x00000001)
  22. #define VARSET_RESTRICT_NOCHANGEPROPS (0x00000002)
  23. #define VARSET_RESTRICT_ALL (0x00000003)
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CVSet
  26. class ATL_NO_VTABLE CVSet :
  27. public CComObjectRootEx<CComMultiThreadModel>,
  28. public CComCoClass<CVSet, &CLSID_VarSet>,
  29. public ISupportErrorInfoImpl<&IID_IVarSet>,
  30. #ifdef STRIPPED_VARSET
  31. public IDispatchImpl<IVarSet, &IID_IVarSet, &LIBID_MCSVARSETMINLib>,
  32. #else
  33. public IDispatchImpl<IVarSet, &IID_IVarSet, &LIBID_MCSVARSETLib>,
  34. #endif
  35. public IPersistStorageImpl<CVSet>,
  36. public IPersistStreamInit,
  37. public IPersistStream,
  38. public IMarshal
  39. {
  40. public:
  41. CVSet()
  42. {
  43. m_data = new CVarData;
  44. m_pUnkMarshaler = NULL;
  45. m_nItems = 0;
  46. m_bLoaded = FALSE;
  47. m_parent = NULL;
  48. m_Restrictions = 0;
  49. m_ImmutableRestrictions = 0;
  50. InitProperties();
  51. }
  52. ~CVSet()
  53. {
  54. if ( m_parent )
  55. {
  56. m_parent->Release();
  57. }
  58. else
  59. {
  60. Clear();
  61. delete m_data;
  62. }
  63. }
  64. DECLARE_REGISTRY_RESOURCEID(IDR_VSET)
  65. DECLARE_GET_CONTROLLING_UNKNOWN()
  66. DECLARE_PROTECT_FINAL_CONSTRUCT()
  67. BEGIN_COM_MAP(CVSet)
  68. COM_INTERFACE_ENTRY(IVarSet)
  69. COM_INTERFACE_ENTRY_IMPL(IPersistStorage)
  70. COM_INTERFACE_ENTRY(IPersistStreamInit)
  71. COM_INTERFACE_ENTRY(IPersistStream)
  72. COM_INTERFACE_ENTRY(IMarshal)
  73. COM_INTERFACE_ENTRY(IDispatch)
  74. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  75. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  76. END_COM_MAP()
  77. HRESULT FinalConstruct()
  78. {
  79. return CoCreateFreeThreadedMarshaler(
  80. GetControllingUnknown(), &m_pUnkMarshaler.p);
  81. }
  82. void FinalRelease()
  83. {
  84. m_pUnkMarshaler.Release();
  85. }
  86. CComPtr<IUnknown> m_pUnkMarshaler;
  87. // IVSet
  88. public:
  89. STDMETHOD(get)(/* [in] */BSTR property,/* [retval][out] */VARIANT * value);
  90. STDMETHOD(put)(/* [in] */BSTR property,/* [in] */VARIANT value);
  91. STDMETHOD(putObject)(/* [in] */BSTR property,/* [in] */VARIANT value);
  92. STDMETHOD(Clear)();
  93. // Enum methods
  94. STDMETHOD(get__NewEnum)(/* [retval][out] */IUnknown** retval);
  95. STDMETHOD(getItems)(/* [in] */BSTR basepoint,
  96. /* [in] */BSTR startAfter,
  97. /* [in] */BOOL bRecursive,
  98. /* [in] */ULONG bSize,
  99. /* [out] */SAFEARRAY ** keys,
  100. /* [out] */SAFEARRAY ** values,
  101. /* [out][in] */LONG * nReturned);
  102. STDMETHOD(getItems2)(/* [in] */VARIANT basepoint,
  103. /* [in] */VARIANT startAfter,
  104. /* [in] */VARIANT bRecursive,
  105. /* [in] */VARIANT bSize,
  106. /* [out] */VARIANT * keys,
  107. /* [out] */VARIANT * values,
  108. /* [out][in] */VARIANT * nReturned);
  109. // properties
  110. STDMETHOD(get_NumChildren)(/* [in] */BSTR parentKey,/* [out,retval] */long*count);
  111. STDMETHOD(get_Count)(/* [retval][out] */long* retval);
  112. STDMETHOD(get_CaseSensitive)(/* [retval][out] */BOOL * isCaseSensitive);
  113. STDMETHOD(put_CaseSensitive)( /* [in] */BOOL newVal);
  114. STDMETHOD(get_Indexed)(/* [out, retval]*/ BOOL *pVal);
  115. STDMETHOD(put_Indexed)(/* [in] */ BOOL newVal);
  116. STDMETHOD(get_AllowRehashing)(/* [out, retval]*/ BOOL *pVal);
  117. STDMETHOD(put_AllowRehashing)(/* [in] */ BOOL newVal);
  118. STDMETHOD(DumpToFile)( /* [in] */ BSTR filename);
  119. STDMETHOD(ImportSubTree)(/*[in] */ BSTR key, /* [in] */ IVarSet * pVarSet);
  120. STDMETHOD(getReference)( /* [in] */ BSTR key, /* [out,retval] */IVarSet** cookie);
  121. STDMETHOD(get_Restrictions)(/* [out,retval] */ DWORD * restrictions);
  122. STDMETHOD(put_Restrictions)(/* [in] */ DWORD newRestrictions);
  123. protected:
  124. CComAutoCriticalSection m_cs;
  125. LONG m_nItems;
  126. // Properties
  127. BOOL m_CaseSensitive;
  128. BOOL m_Indexed;
  129. BOOL m_AllowRehashing;
  130. BOOL m_bNeedToSave;
  131. BOOL m_bLoaded;
  132. IVarSet * m_parent;
  133. CVarData * m_data;
  134. CComBSTR m_prefix;
  135. DWORD m_Restrictions;
  136. DWORD m_ImmutableRestrictions;
  137. // Helper functions
  138. void BuildVariantKeyArray(CString prefix,CMapStringToVar * map,CComVariant * pVars,int * offset);
  139. void BuildVariantKeyValueArray(CString prefix,CString startAfter,CMapStringToVar * map,
  140. SAFEARRAY * keys,SAFEARRAY * pVars,int * offset,int maxOffset, BOOL bRecurse);
  141. CVarData * GetItem(CString str,BOOL addToMap = FALSE, CVarData * starting = NULL);
  142. void InitProperties()
  143. {
  144. m_CaseSensitive = TRUE;
  145. m_Indexed = TRUE;
  146. m_AllowRehashing = TRUE;
  147. m_bNeedToSave = TRUE;
  148. }
  149. void SetData(IVarSet * parent,CVarData * data,DWORD restrictions)
  150. {
  151. if ( m_parent )
  152. {
  153. m_parent->Release();
  154. m_parent = NULL;
  155. }
  156. if (m_data)
  157. {
  158. delete m_data;
  159. }
  160. m_data = data;
  161. m_parent = parent;
  162. m_bNeedToSave = TRUE;
  163. m_Indexed = m_data->IsIndexed();
  164. m_CaseSensitive = m_data->IsCaseSensitive();
  165. m_nItems = m_data->CountItems();
  166. m_Restrictions = restrictions;
  167. m_ImmutableRestrictions = restrictions;
  168. if ( ! m_data->HasData() )
  169. {
  170. // Don't count the root key "" if it does not have a value.
  171. m_nItems--;
  172. }
  173. }
  174. // IPersistStorage
  175. public:
  176. STDMETHOD(GetClassID)(CLSID __RPC_FAR *pClassID);
  177. STDMETHOD(IsDirty)();
  178. STDMETHOD(Load)(LPSTREAM pStm);
  179. STDMETHOD(Save)(LPSTREAM pStm,BOOL fClearDirty);
  180. STDMETHOD(GetSizeMax)(ULARGE_INTEGER __RPC_FAR *pCbSize);
  181. STDMETHOD(InitNew)();
  182. // IMarshal
  183. public:
  184. STDMETHODIMP GetUnmarshalClass(REFIID riid, void *pv, DWORD dwDestContext, void *pvDestContext, DWORD mshlflags, CLSID *pCid);
  185. STDMETHODIMP GetMarshalSizeMax(REFIID riid, void *pv, DWORD dwDestContext, void *pvDestContext, DWORD mshlflags, DWORD *pSize);
  186. STDMETHODIMP MarshalInterface(IStream *pStm, REFIID riid, void *pv, DWORD dwDestContext, void *pvDestCtx, DWORD mshlflags);
  187. STDMETHODIMP UnmarshalInterface(IStream *pStm, REFIID riid, void **ppv);
  188. STDMETHODIMP ReleaseMarshalData(IStream *pStm);
  189. STDMETHODIMP DisconnectObject(DWORD dwReserved);
  190. };
  191. #endif //__VSET_H_