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.

295 lines
9.0 KiB

  1. // TuningSpace.h : Declaration of the CTuningSpace
  2. // Copyright (c) Microsoft Corporation 1999.
  3. #ifndef TUNINGSPACEIMPL_H
  4. #define TUNINGSPACEIMPL_H
  5. #include <tuner.h>
  6. #include "componenttypes.h"
  7. namespace BDATuningModel {
  8. const int MAX_DEFAULT_PREFERRED_COMPONENT_TYPES = 64;
  9. template<class T,
  10. class TuneRequestType,
  11. class MostDerived = ITuningSpace,
  12. LPCGUID iid = &__uuidof(MostDerived),
  13. LPCGUID LibID = &LIBID_TunerLib,
  14. WORD wMajor = 1,
  15. WORD wMinor = 0,
  16. class tihclass = CComTypeInfoHolder
  17. > class ATL_NO_VTABLE ITuningSpaceImpl :
  18. public IPersistPropertyBagImpl<T>,
  19. public IDispatchImpl<MostDerived, iid, LibID, wMajor, wMinor, tihclass>
  20. {
  21. public:
  22. ITuningSpaceImpl() {}
  23. virtual ~ITuningSpaceImpl() {}
  24. typedef ITuningSpaceImpl<T, TuneRequestType, MostDerived, iid, LibID, wMajor, wMinor, tihclass> thistype;
  25. typedef CComQIPtr<ILocator> PQLocator;
  26. BEGIN_PROP_MAP(thistype)
  27. PROP_DATA_ENTRY("Name", m_UniqueName.m_str, VT_BSTR)
  28. PROP_DATA_ENTRY("Description", m_FriendlyName.m_str, VT_BSTR)
  29. PROP_DATA_ENTRY("Network Type", m_NetworkType.m_str, VT_BSTR)
  30. PROP_DATA_QI_ENTRY("Default Component Types", m_DefaultPreferredComponents.p, __uuidof(IComponentTypes))
  31. PROP_DATA_ENTRY("Frequency Mapping", m_FrequencyMapping.m_str, VT_BSTR_BLOB)
  32. PROP_DATA_QI_ENTRY("Default Locator", m_DefaultLocator.p, __uuidof(ILocator))
  33. END_PROPERTY_MAP()
  34. // note: don't put a com map in an impl. it will override the derived classes
  35. // and script clients will get only get type info for the base class methods .
  36. // only provide a com map in the most derived class representing the actual coclass
  37. CComBSTR m_UniqueName;
  38. CComBSTR m_FriendlyName;
  39. CComBSTR m_FrequencyMapping;
  40. CComBSTR m_NetworkType;
  41. PQComponentTypes m_DefaultPreferredComponents;
  42. PQLocator m_DefaultLocator;
  43. // ITuningSpace
  44. STDMETHOD(get_UniqueName)(/* [out, retval] */ BSTR *pName){
  45. if (!pName) {
  46. return E_POINTER;
  47. }
  48. ATL_LOCKT();
  49. return m_UniqueName.CopyTo(pName);
  50. }
  51. STDMETHOD(put_UniqueName)(/* [in] */ BSTR Name){
  52. CHECKBSTRLIMIT(Name);
  53. ATL_LOCKT();
  54. m_UniqueName = Name;
  55. MARK_DIRTY(T);
  56. return NOERROR;
  57. }
  58. STDMETHOD(get_FriendlyName)(/* [out, retval] */ BSTR *pName){
  59. if (!pName) {
  60. return E_POINTER;
  61. }
  62. ATL_LOCKT();
  63. return m_FriendlyName.CopyTo(pName);
  64. }
  65. STDMETHOD(put_FriendlyName)(/* [in] */ BSTR Name){
  66. CHECKBSTRLIMIT(Name);
  67. ATL_LOCKT();
  68. m_FriendlyName = Name;
  69. MARK_DIRTY(T);
  70. return NOERROR;
  71. }
  72. STDMETHOD(get_CLSID)(/* [out, retval] */ BSTR *pbstrCLSID){
  73. if (!pbstrCLSID) {
  74. return E_POINTER;
  75. }
  76. try {
  77. GUID2 g;
  78. HRESULT hr = GetClassID(&g);
  79. if (FAILED(hr)) {
  80. return hr;
  81. }
  82. ATL_LOCKT();
  83. *pbstrCLSID = g.GetBSTR();
  84. return NOERROR;
  85. } CATCHCOM();
  86. }
  87. STDMETHOD(get_NetworkType)(/* [out, retval] */ BSTR *pNetworkTypeGuid){
  88. if (!pNetworkTypeGuid) {
  89. return E_POINTER;
  90. }
  91. try {
  92. GUID2 g;
  93. HRESULT hr = get__NetworkType(&g);
  94. if (FAILED(hr)) {
  95. return hr;
  96. }
  97. *pNetworkTypeGuid = g.GetBSTR();
  98. return NOERROR;
  99. } CATCHCOM();
  100. }
  101. // should be network provider clsid
  102. STDMETHOD(put_NetworkType)(/* [in] */ BSTR NetworkTypeGuid){
  103. try {
  104. GUID2 g(NetworkTypeGuid);
  105. return put__NetworkType(g);
  106. } CATCHCOM();
  107. }
  108. STDMETHOD(get__NetworkType)(/* [out, retval] */ GUID* pNetworkTypeGuid){
  109. if (!pNetworkTypeGuid) {
  110. return E_POINTER;
  111. }
  112. try {
  113. ATL_LOCKT();
  114. GUID2 g(m_NetworkType);
  115. memcpy(pNetworkTypeGuid, &g, sizeof(GUID));
  116. return NOERROR;
  117. } CATCHCOM();
  118. }
  119. STDMETHOD(put__NetworkType)(/* [out, retval] */ REFCLSID pNetworkTypeGuid){
  120. try {
  121. GUID2 g(pNetworkTypeGuid);
  122. ATL_LOCKT();
  123. // NOTE: the network type guid is the clsid for the network provider filter
  124. // for this type of this tuning space. since we're only allowing
  125. // ourselves to run from trusted zones we can assume that this clsid is also
  126. // trustworthy. however, if we do more security review and decide to enable
  127. // use of the tuning model from the internet zone then this is no longer safe.
  128. // in this case, we need to get IInternetHostSecurityManager from IE and
  129. // call ProcessURLAction(URLACTION_ACTIVEX_RUN) and make sure we get back
  130. // URLPOLICY_ALLOW. otherwise, we're bypassing IE's list of known bad
  131. // objects.
  132. // see ericli's complete guide to script security part I on http://pgm/wsh
  133. // for more details.
  134. m_NetworkType = g.GetBSTR();
  135. MARK_DIRTY(T);
  136. return NOERROR;
  137. } CATCHCOM();
  138. }
  139. STDMETHOD(EnumCategoryGUIDs)(/* [out, retval] */ IEnumGUID **ppEnum){
  140. return E_NOTIMPL;
  141. }
  142. STDMETHOD(EnumDeviceMonikers)(/* [out, retval] */ IEnumMoniker **ppEnum){
  143. return E_NOTIMPL;
  144. }
  145. STDMETHOD(get_DefaultPreferredComponentTypes)(/* [out, retval] */ IComponentTypes** ppComponentTypes){
  146. if (!ppComponentTypes) {
  147. return E_POINTER;
  148. }
  149. ATL_LOCKT();
  150. m_DefaultPreferredComponents.CopyTo(ppComponentTypes);
  151. return NOERROR;
  152. }
  153. STDMETHOD(put_DefaultPreferredComponentTypes)(/* [in] */ IComponentTypes* pNewComponentTypes){
  154. try {
  155. HRESULT hr = NOERROR;
  156. PQComponentTypes pct;
  157. if (pNewComponentTypes) {
  158. long lCount = 0;
  159. hr = pNewComponentTypes->get_Count(&lCount);
  160. if (FAILED(hr) || lCount > MAX_DEFAULT_PREFERRED_COMPONENT_TYPES) {
  161. return E_INVALIDARG;
  162. }
  163. hr = pNewComponentTypes->Clone(&pct);
  164. }
  165. if (SUCCEEDED(hr)) {
  166. ATL_LOCKT();
  167. m_DefaultPreferredComponents = pct;
  168. MARK_DIRTY(T);
  169. }
  170. return hr;
  171. } CATCHCOM();
  172. }
  173. STDMETHOD(CreateTuneRequest)(/* [out, retval] */ ITuneRequest **ppTuneRequest){
  174. if (!ppTuneRequest) {
  175. return E_POINTER;
  176. }
  177. TuneRequestType *pt = NULL;
  178. try {
  179. pt = new CComObject<TuneRequestType>;
  180. if (!pt) {
  181. return E_OUTOFMEMORY;
  182. }
  183. ATL_LOCKT();
  184. HRESULT hr = Clone(&pt->m_TS);
  185. if (FAILED(hr)) {
  186. delete pt;
  187. return hr;
  188. }
  189. pt->AddRef();
  190. *ppTuneRequest = pt;
  191. return NOERROR;
  192. } CATCHCOM_CLEANUP(delete pt);
  193. }
  194. STDMETHOD(get_FrequencyMapping)(/* [out, retval] */ BSTR *pMap){
  195. if(!pMap){
  196. return E_POINTER;
  197. }
  198. ATL_LOCKT();
  199. return m_FrequencyMapping.CopyTo(pMap);
  200. }
  201. STDMETHOD(put_FrequencyMapping)(/* [in] */ BSTR Map){
  202. CHECKBSTRLIMIT(Map);
  203. ATL_LOCKT();
  204. m_FrequencyMapping = &Map;
  205. MARK_DIRTY(T);
  206. return NOERROR;
  207. }
  208. STDMETHOD(get_DefaultLocator)(/* [out, retval] */ ILocator** ppLocator){
  209. if (!ppLocator) {
  210. return E_POINTER;
  211. }
  212. ATL_LOCKT();
  213. m_DefaultLocator.CopyTo(ppLocator);
  214. return NOERROR;
  215. }
  216. STDMETHOD(put_DefaultLocator)(/* [in] */ ILocator* NewLocator){
  217. try {
  218. ATL_LOCKT();
  219. PQLocator pl;
  220. HRESULT hr = NOERROR;
  221. if (NewLocator) {
  222. hr = NewLocator->Clone(&pl);
  223. }
  224. if (SUCCEEDED(hr)) {
  225. m_DefaultLocator = pl;
  226. MARK_DIRTY(T);
  227. }
  228. return hr;
  229. } CATCHCOM();
  230. }
  231. STDMETHOD(Clone) (ITuningSpace **ppTR) {
  232. T* pt = NULL;
  233. try {
  234. if (!ppTR) {
  235. return E_POINTER;
  236. }
  237. ATL_LOCKT();
  238. pt = static_cast<T*>(new CComObject<T>);
  239. if (!pt) {
  240. return E_OUTOFMEMORY;
  241. }
  242. pt->m_UniqueName = m_UniqueName;
  243. pt->m_FriendlyName = m_FriendlyName;
  244. pt->m_NetworkType = m_NetworkType;
  245. if (m_DefaultPreferredComponents) {
  246. ASSERT(!pt->m_DefaultPreferredComponents);
  247. HRESULT hr = m_DefaultPreferredComponents->Clone(&pt->m_DefaultPreferredComponents);
  248. if (FAILED(hr)) {
  249. delete pt;
  250. return hr;
  251. }
  252. }
  253. pt->m_FrequencyMapping = m_FrequencyMapping;
  254. if (m_DefaultLocator) {
  255. ASSERT(!pt->m_DefaultLocator);
  256. HRESULT hr = m_DefaultLocator->Clone(&pt->m_DefaultLocator);
  257. if (FAILED(hr)) {
  258. delete pt;
  259. return hr;
  260. }
  261. }
  262. pt->m_bRequiresSave = true;
  263. pt->AddRef();
  264. *ppTR = pt;
  265. return NOERROR;
  266. } CATCHCOM_CLEANUP(delete pt);
  267. }
  268. };
  269. }; //namespace
  270. #endif // TUNINGSPACEIMPL_H
  271. // end of file -- tuningspaceimpl.h