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.

308 lines
7.5 KiB

  1. //
  2. // Copyright (c) 1997-2002 Microsoft Corporation, All Rights Reserved
  3. //
  4. #ifndef NOTIFICATION_GROUP
  5. #define NOTIFICATION_GROUP
  6. #include <autoptr.h>
  7. // This encapsulates one of the following:
  8. // A V2 NOTIFICATION-TYPE invocation or
  9. // A NOTIFICATION-TYPE fabricated from a V1 TRAP-TYPE invocation
  10. class SIMCNotificationElement
  11. {
  12. // A pointer to the symbol in a module, that represents this
  13. // NOTIFICATION-TYPE
  14. SIMCSymbol *symbol;
  15. // The "clean" oid value of this NOTIFICATION-TYPE. Note that
  16. // and "unclean" value may be obtained by calling the
  17. // function SIMCModule.IsObjectIdentifierValue(), on the module
  18. // that defined this symbol.
  19. SIMCCleanOidValue *value;
  20. // Indicates whether this was fabricated from a TRAP-TYPE
  21. BOOL _fabricatedFromTrapType;
  22. // These 2 fields are valid only if fabricatedFromTrapType is true
  23. int _specificId;
  24. SIMCCleanOidValue *_enterpriseOid;
  25. public:
  26. SIMCNotificationElement(SIMCSymbol *s, SIMCCleanOidValue *v,
  27. BOOL fabricatedFromTrapType = FALSE)
  28. : symbol(s), value(v), _fabricatedFromTrapType(fabricatedFromTrapType)
  29. {
  30. // Set the specificId and the enterpriseOid fields
  31. _enterpriseOid = new SIMCCleanOidValue;
  32. wmilib::auto_ptr<SIMCCleanOidValue> _enterpriseOid_Guard ( _enterpriseOid ) ;
  33. _specificId = 0;
  34. if(fabricatedFromTrapType)
  35. {
  36. if(v->GetCount() >= 3)
  37. {
  38. POSITION lastPosition = v->GetHeadPosition();
  39. POSITION lastMinusOnePosition = NULL;
  40. POSITION lastMinusTwoPosition = NULL;
  41. while(lastPosition)
  42. {
  43. lastMinusTwoPosition = lastMinusOnePosition;
  44. lastMinusOnePosition = lastPosition;
  45. _specificId = v->GetNext(lastPosition);
  46. _enterpriseOid->AddTail(_specificId);
  47. }
  48. _enterpriseOid->RemoveTail();
  49. _enterpriseOid->RemoveTail();
  50. }
  51. }
  52. //
  53. // dismiss as we succeeded construction
  54. // without exception being raisen
  55. // so destructor will take care of cleanup
  56. //
  57. _enterpriseOid_Guard.release () ;
  58. }
  59. SIMCNotificationElement()
  60. : symbol(NULL), value(NULL)
  61. {}
  62. ~SIMCNotificationElement()
  63. {
  64. delete value;
  65. delete _enterpriseOid;
  66. }
  67. friend ostream& operator << (ostream& outStream, const SIMCNotificationElement& obj);
  68. SIMCSymbol *GetSymbol() const
  69. {
  70. return symbol;
  71. }
  72. void SetSymbol(SIMCSymbol *s)
  73. {
  74. symbol = s;
  75. }
  76. SIMCCleanOidValue *GetOidValue() const
  77. {
  78. return value;
  79. }
  80. void SetOidValue(SIMCCleanOidValue *v)
  81. {
  82. value = v;
  83. }
  84. BOOL IsFabricatedFromTrapType() const
  85. {
  86. return _fabricatedFromTrapType;
  87. }
  88. // This is valid only if IsFabricatedFromTrapType() returns TRUE
  89. int GetSpecificId() const
  90. {
  91. return _specificId;
  92. }
  93. // This is valid only if IsFabricatedFromTrapType() returns TRUE
  94. SIMCCleanOidValue * GetEnterpriseOid() const
  95. {
  96. return _enterpriseOid;
  97. }
  98. };
  99. typedef CList<SIMCNotificationElement *, SIMCNotificationElement *> SIMCNotificationList;
  100. // And finally the notification group itself.
  101. class SIMCNotificationGroup
  102. {
  103. public:
  104. enum NotificationGroupStatusType
  105. {
  106. STATUS_INVALID, // Not used,
  107. STATUS_CURRENT,
  108. STATUS_DEPRECATED,
  109. STATUS_OBSOLETE
  110. };
  111. // For generating a name for the notification group, in case of the V1 SMI
  112. static const char *const NOTIFICATION_GROUP_FABRICATION_SUFFIX;
  113. static const int NOTIFICATION_GROUP_FABRICATION_SUFFIX_LEN;
  114. private:
  115. // Various clauses of the notification group
  116. char *notificationGroupName;
  117. char *description;
  118. char *reference;
  119. SIMCSymbol *enterpriseNode;
  120. SIMCCleanOidValue *enterpriseNodeValue;
  121. SIMCNotificationList *notifications;
  122. NotificationGroupStatusType status;
  123. static const char * const StatusStringsTable[3];
  124. public:
  125. SIMCNotificationGroup(SIMCSymbol *n, SIMCCleanOidValue *nv,
  126. NotificationGroupStatusType s, const char * descriptionV,
  127. const char *referenceV, SIMCNotificationList *notificationsV)
  128. : enterpriseNode(n), enterpriseNodeValue(nv), status(s),
  129. notifications(notificationsV)
  130. {
  131. notificationGroupName = NewString(strlen(n->GetSymbolName()) +
  132. NOTIFICATION_GROUP_FABRICATION_SUFFIX_LEN + 1);
  133. strcpy(notificationGroupName, n->GetSymbolName());
  134. strcat(notificationGroupName, NOTIFICATION_GROUP_FABRICATION_SUFFIX);
  135. description = NewString(descriptionV);
  136. reference = NewString(referenceV);
  137. }
  138. SIMCNotificationGroup()
  139. : enterpriseNode(NULL), enterpriseNodeValue(NULL), notifications(NULL),
  140. status(STATUS_CURRENT), notificationGroupName(NULL), description(NULL),
  141. reference(NULL)
  142. {}
  143. ~SIMCNotificationGroup()
  144. {
  145. delete [] notificationGroupName;
  146. delete [] description;
  147. delete [] reference;
  148. if(notifications)
  149. {
  150. SIMCNotificationElement *nextElement;
  151. while(!notifications->IsEmpty() )
  152. {
  153. nextElement = notifications->RemoveHead();
  154. delete nextElement;
  155. }
  156. delete notifications;
  157. }
  158. if(enterpriseNodeValue) delete enterpriseNodeValue;
  159. }
  160. friend ostream& operator << (ostream& outStream, const SIMCNotificationGroup& obj);
  161. SIMCSymbol *GetEnterpriseNode() const
  162. {
  163. return enterpriseNode;
  164. }
  165. void SetEnterpriseNode(SIMCSymbol *nn)
  166. {
  167. enterpriseNode = nn;
  168. if(notificationGroupName)
  169. delete [] notificationGroupName;
  170. notificationGroupName = NewString(strlen(nn->GetSymbolName()) +
  171. NOTIFICATION_GROUP_FABRICATION_SUFFIX_LEN + 1);
  172. strcpy(notificationGroupName, nn->GetSymbolName());
  173. strcat(notificationGroupName, NOTIFICATION_GROUP_FABRICATION_SUFFIX);
  174. }
  175. const char * const GetNotificationGroupName() const
  176. {
  177. return notificationGroupName;
  178. }
  179. const char * const GetDescription() const
  180. {
  181. return description;
  182. }
  183. void SetDescription(const char * const descriptionV)
  184. {
  185. delete [] description;
  186. description = NewString(descriptionV);
  187. }
  188. const char * const GetReference() const
  189. {
  190. return reference;
  191. }
  192. void SetReference(const char * const referenceV)
  193. {
  194. delete [] reference;
  195. reference = NewString(referenceV);
  196. }
  197. SIMCCleanOidValue *GetGroupValue() const
  198. {
  199. return enterpriseNodeValue;
  200. }
  201. void SetGroupValue(SIMCCleanOidValue *val)
  202. {
  203. enterpriseNodeValue = val;
  204. }
  205. SIMCNotificationList *GetNotifications() const
  206. {
  207. return notifications;
  208. }
  209. void AddNotification(SIMCNotificationElement *s)
  210. {
  211. if(!notifications)
  212. notifications = new SIMCNotificationList();
  213. notifications->AddTail(s);
  214. }
  215. long GetNotificationCount() const
  216. {
  217. if(notifications)
  218. return notifications->GetCount();
  219. else
  220. return 0;
  221. }
  222. NotificationGroupStatusType GetStatus() const
  223. {
  224. return status;
  225. }
  226. void SetStatus(NotificationGroupStatusType s)
  227. {
  228. status = s;
  229. }
  230. const char * const GetStatusString() const
  231. {
  232. switch(status)
  233. {
  234. case STATUS_CURRENT:
  235. return StatusStringsTable[STATUS_CURRENT-1];
  236. case STATUS_DEPRECATED:
  237. return StatusStringsTable[STATUS_DEPRECATED-1];
  238. case STATUS_OBSOLETE:
  239. return StatusStringsTable[STATUS_OBSOLETE-1];
  240. default:
  241. return NULL;
  242. }
  243. return NULL;
  244. }
  245. };
  246. typedef CList<SIMCNotificationGroup *, SIMCNotificationGroup*> SIMCNotificationGroupList;
  247. class SIMCModuleNotificationGroups
  248. {
  249. SIMCNotificationGroupList theList;
  250. public:
  251. BOOL AddNotification(SIMCSymbol *notificationSymbol);
  252. const SIMCNotificationGroupList *GetNotificationGroupList() const;
  253. };
  254. #endif