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.

335 lines
8.6 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 00
  5. *
  6. * File: mtnode.inl
  7. *
  8. * Contents:
  9. *
  10. * History: 8-Mar-2000 jeffro Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #pragma once
  14. //_____________________________________________________________________________
  15. //
  16. // Inlines for class: CMTNode
  17. //_____________________________________________________________________________
  18. //
  19. inline USHORT CMTNode::AddRef()
  20. {
  21. return (++m_cRef);
  22. }
  23. inline USHORT CMTNode::Release()
  24. {
  25. // Note: The return value from this is important
  26. // as a return value of zero is interpreted as
  27. // object destroyed.
  28. ASSERT(m_cRef > 0);
  29. --m_cRef;
  30. if (m_cRef == 0)
  31. {
  32. delete this;
  33. return 0;
  34. }
  35. return m_cRef;
  36. }
  37. inline PMTNODE CMTNode::GetChild()
  38. {
  39. if (!WasExpandedAtLeastOnce())
  40. Expand();
  41. return Child();
  42. }
  43. inline CMTSnapInNode* CMTNode::GetStaticParent(void)
  44. {
  45. CMTNode* p = this;
  46. while (!p->IsStaticNode())
  47. p = p->Parent();
  48. ASSERT(p != NULL);
  49. CMTSnapInNode* pMTSnapInNode = dynamic_cast<CMTSnapInNode*>(p);
  50. ASSERT (pMTSnapInNode != NULL);
  51. return pMTSnapInNode;
  52. }
  53. inline void CMTNode::CreatePathList(CHMTNODEList& path)
  54. {
  55. CMTNode* pMTNode = this;
  56. for (; pMTNode != NULL; pMTNode = pMTNode->Parent())
  57. path.AddHead(ToHandle(pMTNode));
  58. }
  59. inline CMTNode* CMTNode::Find(MTNODEID id)
  60. {
  61. CMTNode* pStartNode = this; // this is to avoid traversing the tree above the initial node passed
  62. CMTNode* pNode = this;
  63. while ( pNode->GetID() != id )
  64. {
  65. if ( NULL != pNode->Child() )
  66. {
  67. // dive down to the lowest child
  68. pNode = pNode->Child();
  69. }
  70. else
  71. {
  72. // get to the next sub-branch
  73. // ( but first - climb up till you get to the junction )
  74. while ( NULL == pNode->Next() )
  75. {
  76. pNode = pNode->Parent();
  77. // if there are no more nodes - we are done ( search failed )
  78. // ... or if we looked thru all children and siblings [ this
  79. // mostly for compatibility - CMTNode::Find is never used else than
  80. // from topmost node].
  81. if ( (NULL == pNode) || (pNode == pStartNode->Parent()) )
  82. return NULL;
  83. }
  84. pNode = pNode->Next();
  85. }
  86. }
  87. return pNode;
  88. }
  89. inline CMTNode* CMTNode::GetLastChild()
  90. {
  91. CMTNode* pMTNode = Child();
  92. if (pMTNode == NULL)
  93. return NULL;
  94. while (pMTNode->Next() != NULL)
  95. {
  96. pMTNode = pMTNode->Next();
  97. }
  98. return pMTNode;
  99. }
  100. inline wchar_t* CMTNode::GetViewStorageName(wchar_t* name, int idView)
  101. {
  102. ASSERT(name != NULL);
  103. _ltow(idView, name, 36);
  104. return name;
  105. }
  106. /***************************************************************************\
  107. *
  108. * METHOD: CMTNode::GetViewIdFromStorageName
  109. *
  110. * PURPOSE: function reconstructs view id from the component storage name
  111. * in structured storage based console. This is opposit to what
  112. * GetViewStorageName [above] does.
  113. *
  114. * PARAMETERS:
  115. * const wchar_t* name [in] name of storage element
  116. *
  117. * RETURNS:
  118. * int - view id
  119. *
  120. \***************************************************************************/
  121. inline int CMTNode::GetViewIdFromStorageName(const wchar_t* name)
  122. {
  123. ASSERT(name != NULL);
  124. if (name == NULL)
  125. return 0;
  126. wchar_t *stop = NULL;
  127. return wcstol( name, &stop, 36/*base*/ );
  128. }
  129. inline SC CMTNode::ScGetComponentStreamName(wchar_t* szName, int cchName, const CLSID& clsid)
  130. {
  131. DECLARE_SC(sc, TEXT("CMTNode::ScGetComponentStreamName"));
  132. sc = ScCheckPointers(szName, &clsid);
  133. if(sc)
  134. return sc;
  135. // the return value is ALWAYS less than 40 characters (even if we use base 10). Expect the buffer to
  136. // be conservatively at least that long.
  137. if(cchName < 40)
  138. return (sc = E_INVALIDARG).ToHr();
  139. wchar_t* pName = szName;
  140. const long* pl = reinterpret_cast<const long*>(&clsid);
  141. for (int i = 0; i < 4; i++)
  142. {
  143. _ltow(*pl++, pName, 36);
  144. pName += wcslen(pName);
  145. }
  146. return sc;
  147. }
  148. inline SC CMTNode::ScGetComponentStorageName(wchar_t* szName, int cchName, const CLSID& clsid)
  149. {
  150. return ScGetComponentStreamName(szName, cchName, clsid);
  151. }
  152. inline void CMTNode::_SetFlag(ENUM_FLAGS flag, BOOL bSet)
  153. {
  154. ASSERT((flag & (flag-1)) == 0);
  155. if (bSet == TRUE)
  156. m_usFlags |= flag;
  157. else
  158. m_usFlags &= ~flag;
  159. }
  160. inline const CLSID& CMTNode::GetPrimarySnapInCLSID(void)
  161. {
  162. if (m_pPrimaryComponentData == NULL)
  163. return (GUID_NULL);
  164. CSnapIn* const pSnapIn = m_pPrimaryComponentData->GetSnapIn();
  165. if (pSnapIn == NULL)
  166. return (GUID_NULL);
  167. return pSnapIn->GetSnapInCLSID();
  168. }
  169. inline HRESULT CMTNode::GetNodeType(GUID* pGuid)
  170. {
  171. HRESULT hr = m_pPrimaryComponentData->GetNodeType(GetUserParam(), pGuid);
  172. CHECK_HRESULT(hr);
  173. return hr;
  174. }
  175. inline HRESULT CMTNode::OnRename(long fRename, LPOLESTR pszNewName)
  176. {
  177. IDataObjectPtr spDataObject;
  178. HRESULT hr = QueryDataObject(CCT_SCOPE, &spDataObject);
  179. if (FAILED(hr))
  180. return hr;
  181. hr = m_pPrimaryComponentData->Notify(spDataObject,
  182. MMCN_RENAME, fRename, reinterpret_cast<LPARAM>(pszNewName));
  183. CHECK_HRESULT(hr);
  184. return hr;
  185. }
  186. inline HRESULT CMTNode::QueryDataObject(DATA_OBJECT_TYPES type,
  187. LPDATAOBJECT* ppdtobj)
  188. {
  189. if (ppdtobj == NULL)
  190. return (E_INVALIDARG);
  191. *ppdtobj = NULL; // init
  192. CMTSnapInNode* pMTSINode = GetStaticParent();
  193. CComponentData* pCCD = pMTSINode->GetComponentData(GetPrimarySnapInCLSID());
  194. if (pCCD == NULL)
  195. return E_FAIL;
  196. HRESULT hr = pCCD->QueryDataObject(GetUserParam(),
  197. type, ppdtobj);
  198. CHECK_HRESULT(hr);
  199. return hr;
  200. }
  201. inline COMPONENTID CMTNode::GetPrimaryComponentID()
  202. {
  203. return m_pPrimaryComponentData->GetComponentID();
  204. }
  205. inline int CMTNode::GetDynExtCLSID ( LPCLSID *ppCLSID )
  206. {
  207. ASSERT(ppCLSID != NULL);
  208. *ppCLSID = m_arrayDynExtCLSID.GetData();
  209. return m_arrayDynExtCLSID.GetSize();
  210. }
  211. inline void CMTNode::SetNoPrimaryChildren(BOOL bState)
  212. {
  213. if (bState)
  214. m_usExpandFlags |= FLAG_NO_CHILDREN_FROM_PRIMARY;
  215. else
  216. m_usExpandFlags &= ~FLAG_NO_CHILDREN_FROM_PRIMARY;
  217. }
  218. //____________________________________________________________________________
  219. //
  220. // Class: CComponentData Inlines
  221. //____________________________________________________________________________
  222. //
  223. inline HRESULT CComponentData::QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject)
  224. {
  225. DECLARE_SC (sc, _T("CComponentData::QueryDataObject"));
  226. sc = ScCheckPointers (m_spIComponentData, E_FAIL);
  227. if (sc)
  228. return (sc.ToHr());
  229. ASSERT(type != CCT_RESULT);
  230. return ((sc = m_spIComponentData->QueryDataObject(cookie, type, ppDataObject)).ToHr());
  231. }
  232. inline HRESULT CComponentData::GetDisplayInfo(SCOPEDATAITEM* pScopeDataItem)
  233. {
  234. DECLARE_SC (sc, _T("CComponentData::GetDisplayInfo"));
  235. sc = ScCheckPointers (m_spIComponentData, E_FAIL);
  236. if (sc)
  237. return (sc.ToHr());
  238. return ((sc = m_spIComponentData->GetDisplayInfo(pScopeDataItem)).ToHr());
  239. }
  240. inline HRESULT CComponentData::GetNodeType(MMC_COOKIE cookie, GUID* pGuid)
  241. {
  242. IDataObjectPtr spdtobj;
  243. HRESULT hr = QueryDataObject(cookie, CCT_SCOPE, &spdtobj);
  244. if (SUCCEEDED(hr))
  245. hr = ExtractObjectTypeGUID(spdtobj, pGuid);
  246. return hr;
  247. }
  248. //____________________________________________________________________________
  249. //
  250. // Class: CMTSnapInNode Inlines
  251. //____________________________________________________________________________
  252. //
  253. inline CComponentData* CMTSnapInNode::GetComponentData(const CLSID& clsid)
  254. {
  255. for (int i=0; i < m_ComponentDataArray.size(); i++)
  256. {
  257. if (m_ComponentDataArray[i] != NULL &&
  258. IsEqualCLSID(clsid, m_ComponentDataArray[i]->GetCLSID()) == TRUE)
  259. return m_ComponentDataArray[i];
  260. }
  261. return NULL;
  262. }
  263. inline CComponentData* CMTSnapInNode::GetComponentData(COMPONENTID nID)
  264. {
  265. if (nID < m_ComponentDataArray.size())
  266. return m_ComponentDataArray[nID];
  267. return NULL;
  268. }
  269. inline COMPONENTID CMTSnapInNode::AddComponentDataToArray(CComponentData* pCCD)
  270. {
  271. m_ComponentDataArray.push_back(pCCD);
  272. int nID = m_ComponentDataArray.size() -1;
  273. pCCD->SetComponentID(nID);
  274. return nID;
  275. }