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.

429 lines
10 KiB

  1. //***************************************************************************
  2. //
  3. // File:
  4. //
  5. // Module: MS SNMP Provider
  6. //
  7. // Purpose:
  8. //
  9. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. #ifndef _ENUM_H_
  13. #define _ENUM_H_
  14. /*InterfaceGarbageCollector makes it easier to use the interface
  15. *by remembering to release them when you fall out of scope. The is
  16. *useful when you are using an IMosProvider and have lots of points
  17. *of failure; you can just give up and let the wrapper clean up for
  18. *you.
  19. */
  20. template<class TYPE, class ARG_TYPE>
  21. class EnumObjectArray : public CObject
  22. {
  23. private:
  24. BOOL threadSafe ;
  25. #ifdef IMPLEMENTED_AS_SEPERATE_PROCESS
  26. CMutex *criticalSection ;
  27. #else
  28. CCriticalSection *criticalSection ;
  29. #endif
  30. CArray <TYPE, ARG_TYPE> carray ;
  31. protected:
  32. public:
  33. EnumObjectArray ( BOOL threadSafe = FALSE ) ;
  34. virtual ~EnumObjectArray () ;
  35. int GetSize () const ;
  36. int GetUpperBound() const ;
  37. void SetSize (int newSize, int nGrowBy=-1) ;
  38. //FreeExtra not implemented
  39. void RemoveAll () ;
  40. TYPE GetAt(int index) const;
  41. // Not implemented void SetAt(TYPE key, ARG_TYPE newValue) ;
  42. TYPE& ElementAt(int nIndex);
  43. //GetData not implemented
  44. //SetAtGrow not implemented
  45. int Add(ARG_TYPE newElement);
  46. //Append not implemented
  47. //Copy not implemented
  48. void InsertAt(int nIndex, ARG_TYPE newElement, int nCount=1);
  49. void RemoveAt(int nIndex, int nCount= 1);
  50. TYPE& operator[](TYPE key) ;
  51. } ;
  52. template <class TYPE, class ARG_TYPE>
  53. EnumObjectArray <TYPE, ARG_TYPE> :: EnumObjectArray ( BOOL threadSafeArg )
  54. : threadSafe ( threadSafeArg ) , criticalSection ( NULL )
  55. {
  56. if (threadSafeArg)
  57. {
  58. #ifdef IMPLEMENTED_AS_SEPERATE_PROCESS
  59. criticalSection = new CMutex(FALSE,SMIR_ENUMOBJECT_MUTEX);
  60. #else
  61. criticalSection = new CCriticalSection;
  62. #endif
  63. }
  64. }
  65. template<class TYPE, class ARG_TYPE>
  66. EnumObjectArray <TYPE, ARG_TYPE> :: ~EnumObjectArray ()
  67. {
  68. int iSize = GetSize();
  69. for(int iLoop=0; iLoop<iSize; iLoop++)
  70. {
  71. IUnknown *pTUnknown=(IUnknown *)GetAt(iLoop);
  72. if(NULL!=pTUnknown)
  73. pTUnknown->Release();
  74. }
  75. if (threadSafe)
  76. {
  77. delete criticalSection;
  78. }
  79. }
  80. template<class TYPE, class ARG_TYPE>
  81. int EnumObjectArray <TYPE, ARG_TYPE> :: GetSize() const
  82. {
  83. if ( threadSafe )
  84. {
  85. criticalSection->Lock () ;
  86. int count = carray.GetSize () ;
  87. criticalSection->Unlock () ;
  88. return count ;
  89. }
  90. else
  91. {
  92. return carray.GetSize () ;
  93. }
  94. }
  95. template<class TYPE, class ARG_TYPE>
  96. int EnumObjectArray <TYPE, ARG_TYPE> :: GetUpperBound() const
  97. {
  98. if ( threadSafe )
  99. {
  100. criticalSection->Lock () ;
  101. int count = carray.GetUpperBound () ;
  102. criticalSection->Unlock () ;
  103. return count ;
  104. }
  105. else
  106. {
  107. return carray.GetUpperBound () ;
  108. }
  109. }
  110. template<class TYPE, class ARG_TYPE>
  111. void EnumObjectArray <TYPE, ARG_TYPE> :: SetSize(int newSize, int nGrowBy)
  112. {
  113. if ( threadSafe )
  114. {
  115. criticalSection->Lock () ;
  116. carray.SetSize (newSize, nGrowBy) ;
  117. criticalSection->Unlock () ;
  118. }
  119. else
  120. {
  121. carray.SetSize (newSize, nGrowBy) ;
  122. }
  123. }
  124. template<class TYPE, class ARG_TYPE>
  125. void EnumObjectArray <TYPE, ARG_TYPE> :: RemoveAll()
  126. {
  127. if ( threadSafe )
  128. {
  129. criticalSection->Lock () ;
  130. carray.RemoveAll () ;
  131. criticalSection->Unlock () ;
  132. }
  133. else
  134. {
  135. carray.RemoveAll () ;
  136. }
  137. }
  138. template<class TYPE, class ARG_TYPE>
  139. TYPE EnumObjectArray <TYPE, ARG_TYPE> :: GetAt(int nIndex) const
  140. {
  141. if ( threadSafe )
  142. {
  143. criticalSection->Lock () ;
  144. TYPE count = carray.GetAt (nIndex) ;
  145. criticalSection->Unlock () ;
  146. return count ;
  147. }
  148. else
  149. {
  150. return carray.GetAt(nIndex) ;
  151. }
  152. }
  153. template<class TYPE, class ARG_TYPE>
  154. TYPE& EnumObjectArray <TYPE, ARG_TYPE> :: ElementAt(int nIndex)
  155. {
  156. if ( threadSafe )
  157. {
  158. criticalSection->Lock () ;
  159. TYPE *count = carray.ElementAt (nIndex) ;
  160. criticalSection->Unlock () ;
  161. return count ;
  162. }
  163. else
  164. {
  165. return carray.ElementAt(nIndex) ;
  166. }
  167. }
  168. template<class TYPE, class ARG_TYPE>
  169. int EnumObjectArray <TYPE, ARG_TYPE> :: Add(ARG_TYPE newElement)
  170. {
  171. if ( threadSafe )
  172. {
  173. criticalSection->Lock () ;
  174. int nIndex = carray.Add (newElement) ;
  175. criticalSection->Unlock () ;
  176. return nIndex ;
  177. }
  178. else
  179. {
  180. return carray.Add(newElement) ;
  181. }
  182. }
  183. template<class TYPE, class ARG_TYPE>
  184. void EnumObjectArray <TYPE, ARG_TYPE> :: InsertAt(int nIndex, ARG_TYPE newElement, int nCount)
  185. {
  186. if ( threadSafe )
  187. {
  188. criticalSection->Lock () ;
  189. carray.InsertAt (nIndex, newElement, nCount) ;
  190. criticalSection->Unlock () ;
  191. }
  192. else
  193. {
  194. carray.InsertAt( nIndex, newElement, nCount) ;
  195. }
  196. }
  197. template<class TYPE, class ARG_TYPE>
  198. void EnumObjectArray <TYPE, ARG_TYPE> :: RemoveAt(int nIndex, int nCount)
  199. {
  200. if ( threadSafe )
  201. {
  202. criticalSection->Lock () ;
  203. carray.RemoveAt (nIndex, nCount) ;
  204. criticalSection->Unlock () ;
  205. }
  206. else
  207. {
  208. carray.RemoveAt( nIndex, nCount) ;
  209. }
  210. }
  211. template<class TYPE, class ARG_TYPE>
  212. TYPE& EnumObjectArray <TYPE,ARG_TYPE> :: operator[](TYPE key)
  213. {
  214. if ( threadSafe )
  215. {
  216. criticalSection->Lock () ;
  217. VALUE &value = carray.operator [] ( key ) ;
  218. criticalSection->Unlock () ;
  219. return value ;
  220. }
  221. else
  222. {
  223. return carray.operator [] ( key ) ;
  224. }
  225. }
  226. class CEnumSmirMod : public IEnumModule
  227. {
  228. protected:
  229. //reference count
  230. LONG m_cRef;
  231. int m_Index;
  232. EnumObjectArray <ISmirModHandle *, ISmirModHandle *> m_IHandleArray;
  233. public:
  234. //IUnknown members
  235. STDMETHODIMP QueryInterface(IN REFIID,OUT PPVOID);
  236. STDMETHODIMP_(ULONG) AddRef();
  237. STDMETHODIMP_(ULONG) Release();
  238. //enum members
  239. STDMETHODIMP Next(IN ULONG celt,OUT ISmirModHandle **phModule,OUT ULONG * pceltFetched);
  240. STDMETHODIMP Skip(IN ULONG celt);
  241. STDMETHODIMP Reset();
  242. STDMETHODIMP Clone(OUT IEnumModule **ppenum);
  243. CEnumSmirMod( CSmir *a_Smir );
  244. CEnumSmirMod(IN IEnumModule *pSmirMod);
  245. virtual ~CEnumSmirMod();
  246. private:
  247. //private copy constructors to prevent bcopy
  248. CEnumSmirMod(CEnumSmirMod&);
  249. const CEnumSmirMod& operator=(CEnumSmirMod &);
  250. };
  251. class CEnumSmirGroup : public IEnumGroup
  252. {
  253. protected:
  254. //reference count
  255. LONG m_cRef;
  256. int m_Index;
  257. EnumObjectArray <ISmirGroupHandle *, ISmirGroupHandle *> m_IHandleArray;
  258. public:
  259. //IUnknown members
  260. STDMETHODIMP QueryInterface(IN REFIID,OUT PPVOID);
  261. STDMETHODIMP_(ULONG) AddRef();
  262. STDMETHODIMP_(ULONG) Release();
  263. //enum members
  264. STDMETHODIMP Next(IN ULONG celt,OUT ISmirGroupHandle **phModule,OUT ULONG * pceltFetched);
  265. STDMETHODIMP Skip(IN ULONG celt);
  266. STDMETHODIMP Reset();
  267. STDMETHODIMP Clone(OUT IEnumGroup **ppenum);
  268. CEnumSmirGroup( IN CSmir *a_Smir , IN ISmirModHandle *hModule=NULL);
  269. CEnumSmirGroup(IN IEnumGroup *pSmirGroup);
  270. virtual ~CEnumSmirGroup();
  271. private:
  272. //private copy constructors to prevent bcopy
  273. CEnumSmirGroup(CEnumSmirGroup&);
  274. const CEnumSmirGroup& operator=(CEnumSmirGroup &);
  275. };
  276. class CEnumSmirClass : public IEnumClass
  277. {
  278. protected:
  279. //reference count
  280. LONG m_cRef;
  281. int m_Index;
  282. EnumObjectArray <ISmirClassHandle *, ISmirClassHandle *> m_IHandleArray;
  283. public:
  284. //IUnknown members
  285. STDMETHODIMP QueryInterface(IN REFIID,OUT PPVOID);
  286. STDMETHODIMP_(ULONG) AddRef();
  287. STDMETHODIMP_(ULONG) Release();
  288. //enum members
  289. STDMETHODIMP Next(IN ULONG celt,OUT ISmirClassHandle **phModule,OUT ULONG * pceltFetched);
  290. STDMETHODIMP Skip(IN ULONG celt);
  291. STDMETHODIMP Reset();
  292. STDMETHODIMP Clone(OUT IEnumClass **ppenum);
  293. CEnumSmirClass ( CSmir *a_Smir , IN ISmirDatabase *pSmir = NULL , DWORD dwCookie = 0 ) ;
  294. CEnumSmirClass ( CSmir *a_Smir , IN ISmirDatabase *pSmir , IN ISmirGroupHandle *hGroup , DWORD dwCookie = 0 ) ;
  295. CEnumSmirClass ( CSmir *a_Smir , IN ISmirDatabase *pSmir , IN ISmirModHandle *hModule , DWORD dwCookie = 0 ) ;
  296. CEnumSmirClass ( IN IEnumClass *pSmirClass ) ;
  297. virtual ~CEnumSmirClass(){};
  298. private:
  299. //private copy constructors to prevent bcopy
  300. CEnumSmirClass(CEnumSmirClass&);
  301. const CEnumSmirClass& operator=(CEnumSmirClass &);
  302. };
  303. class CEnumNotificationClass : public IEnumNotificationClass
  304. {
  305. protected:
  306. //reference count
  307. LONG m_cRef;
  308. int m_Index;
  309. EnumObjectArray <ISmirNotificationClassHandle *, ISmirNotificationClassHandle *> m_IHandleArray;
  310. public:
  311. //IUnknown members
  312. STDMETHODIMP QueryInterface(IN REFIID,OUT PPVOID);
  313. STDMETHODIMP_(ULONG) AddRef();
  314. STDMETHODIMP_(ULONG) Release();
  315. //enum members
  316. STDMETHODIMP Next(IN ULONG celt,OUT ISmirNotificationClassHandle **phClass,OUT ULONG * pceltFetched);
  317. STDMETHODIMP Skip(IN ULONG celt);
  318. STDMETHODIMP Reset();
  319. STDMETHODIMP Clone(OUT IEnumNotificationClass **ppenum);
  320. CEnumNotificationClass ( IN CSmir *a_Smir , IN ISmirDatabase *pSmir=NULL, DWORD dwCookie=0);
  321. CEnumNotificationClass ( IN CSmir *a_Smir , IN ISmirDatabase *pSmir, IN ISmirModHandle *hModule, DWORD dwCookie=0);
  322. CEnumNotificationClass ( IN IEnumNotificationClass *pSmirClass);
  323. virtual ~CEnumNotificationClass(){};
  324. private:
  325. //private copy constructors to prevent bcopy
  326. CEnumNotificationClass(CEnumNotificationClass&);
  327. const CEnumNotificationClass& operator=(CEnumNotificationClass &);
  328. };
  329. class CEnumExtNotificationClass : public IEnumExtNotificationClass
  330. {
  331. protected:
  332. //reference count
  333. LONG m_cRef;
  334. int m_Index;
  335. EnumObjectArray <ISmirExtNotificationClassHandle *, ISmirExtNotificationClassHandle *> m_IHandleArray;
  336. public:
  337. //IUnknown members
  338. STDMETHODIMP QueryInterface(IN REFIID,OUT PPVOID);
  339. STDMETHODIMP_(ULONG) AddRef();
  340. STDMETHODIMP_(ULONG) Release();
  341. //enum members
  342. STDMETHODIMP Next(IN ULONG celt,OUT ISmirExtNotificationClassHandle **phClass,OUT ULONG * pceltFetched);
  343. STDMETHODIMP Skip(IN ULONG celt);
  344. STDMETHODIMP Reset();
  345. STDMETHODIMP Clone(OUT IEnumExtNotificationClass **ppenum);
  346. CEnumExtNotificationClass( IN CSmir *a_Smir , IN ISmirDatabase *pSmir=NULL, DWORD dwCookie=0);
  347. CEnumExtNotificationClass( IN CSmir *a_Smir , IN ISmirDatabase *pSmir, IN ISmirModHandle *hModule, DWORD dwCookie=0);
  348. CEnumExtNotificationClass( IN IEnumExtNotificationClass *pSmirClass);
  349. virtual ~CEnumExtNotificationClass(){};
  350. private:
  351. //private copy constructors to prevent bcopy
  352. CEnumExtNotificationClass(CEnumExtNotificationClass&);
  353. const CEnumExtNotificationClass& operator=(CEnumExtNotificationClass &);
  354. };
  355. #endif