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.

431 lines
9.1 KiB

  1. //
  2. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  3. //
  4. #ifndef SIMC_GROUP_H
  5. #define SIMC_GROUP_H
  6. /*
  7. * This file contains the SIMCScalar, SIMCTable and SIMCObjectGroup classes
  8. * Please read the "compiler requirements specification" for definitions of
  9. * "object group", "named node" etc., since object groups are fabricated
  10. * for MIB modules (both V1 and V2) as per the rules in that document.
  11. *
  12. */
  13. /*
  14. * This is a scalar MIB object.
  15. */
  16. class SIMCScalar
  17. {
  18. // A pointer to the symbol in a module, that represents this
  19. // object
  20. SIMCSymbol *symbol;
  21. // The "clean" oid value of this scalar object. Note that
  22. // and "unclean" value may be obtained by calling the
  23. // function SIMCModule.IsObjectIdentifierValue(), on the module
  24. // that defined this symbol.
  25. SIMCCleanOidValue *value;
  26. public:
  27. SIMCScalar(SIMCSymbol *s, SIMCCleanOidValue *v)
  28. : symbol(s), value(v)
  29. {}
  30. SIMCScalar()
  31. : symbol(NULL), value(NULL)
  32. {}
  33. ~SIMCScalar()
  34. {
  35. if(value)
  36. delete value;
  37. }
  38. friend ostream& operator << (ostream& outStream, const SIMCScalar& obj);
  39. SIMCSymbol *GetSymbol() const
  40. {
  41. return symbol;
  42. }
  43. void SetSymbol(SIMCSymbol *s)
  44. {
  45. symbol = s;
  46. }
  47. SIMCCleanOidValue *GetOidValue() const
  48. {
  49. return value;
  50. }
  51. void SetOidValue(SIMCCleanOidValue *v)
  52. {
  53. value = v;
  54. }
  55. };
  56. typedef CList<SIMCScalar *,SIMCScalar *> SIMCScalarMembers;
  57. /*
  58. * This class represents a MIB table object
  59. */
  60. class SIMCTable
  61. {
  62. // A pointer to a symbol that represents this MIB object in a module
  63. // Example : ifTable
  64. SIMCSymbol *tableSymbol;
  65. // ... and its clean OID value
  66. SIMCCleanOidValue *tableValue;
  67. // The symbol or object that represents the row of the table
  68. // Example : ifEntry
  69. SIMCSymbol *rowSymbol;
  70. // ... and its clean OID value
  71. SIMCCleanOidValue *rowValue;
  72. // A list of the columns of the table
  73. SIMCScalarMembers *columnMembers;
  74. SIMCTable *augmentedTable; // If any, in SNMPv2 SMI
  75. public:
  76. SIMCTable(SIMCSymbol *ts, SIMCCleanOidValue *tv, SIMCSymbol *rs, SIMCCleanOidValue *rv,
  77. SIMCScalarMembers *cm)
  78. : tableSymbol(ts), tableValue(tv), rowSymbol(rs), rowValue(rv), columnMembers(cm),
  79. augmentedTable(NULL)
  80. {}
  81. SIMCTable()
  82. : tableSymbol(NULL), tableValue(NULL), rowSymbol(NULL),
  83. rowValue(NULL), columnMembers(NULL), augmentedTable(NULL)
  84. {}
  85. ~SIMCTable()
  86. {
  87. if(tableValue)
  88. delete tableValue;
  89. if(rowValue)
  90. delete rowValue;
  91. if(columnMembers)
  92. {
  93. SIMCScalar *nextScalar;
  94. while(!columnMembers->IsEmpty() )
  95. {
  96. nextScalar = columnMembers->RemoveHead();
  97. delete nextScalar;
  98. }
  99. delete columnMembers;
  100. }
  101. }
  102. friend ostream& operator << (ostream& outStream, const SIMCTable& obj);
  103. SIMCSymbol *GetTableSymbol() const
  104. {
  105. return tableSymbol;
  106. }
  107. void SetTableSymbol(SIMCSymbol *ts)
  108. {
  109. tableSymbol = ts;
  110. }
  111. SIMCCleanOidValue *GetTableOidValue() const
  112. {
  113. return tableValue;
  114. }
  115. void SetTableOidValue(SIMCCleanOidValue *tv)
  116. {
  117. tableValue = tv;
  118. }
  119. SIMCSymbol *GetRowSymbol() const
  120. {
  121. return rowSymbol;
  122. }
  123. void SetRowSymbol(SIMCSymbol *rs)
  124. {
  125. rowSymbol = rs;
  126. }
  127. SIMCCleanOidValue *GetRowOidValue() const
  128. {
  129. return rowValue;
  130. }
  131. void SetRowOidValue(SIMCCleanOidValue *rv)
  132. {
  133. rowValue = rv;
  134. }
  135. SIMCScalarMembers *GetColumnMembers() const
  136. {
  137. return columnMembers;
  138. }
  139. SIMCScalar *GetColumnMember(SIMCSymbol *columnSymbol) const;
  140. void AddColumnMember(SIMCScalar *cm)
  141. {
  142. if(!columnMembers)
  143. columnMembers = new SIMCScalarMembers;
  144. columnMembers->AddTail(cm);
  145. }
  146. BOOL IsColumnMember(const SIMCSymbol *symbol) const;
  147. long GetColumnCount() const
  148. {
  149. if(columnMembers)
  150. return columnMembers->GetCount();
  151. else
  152. return 0;
  153. }
  154. SIMCTable *GetAugmentedTable() const
  155. {
  156. return augmentedTable;
  157. }
  158. void SetAugmentedTable(SIMCTable *ts)
  159. {
  160. augmentedTable = ts;
  161. }
  162. const char * const GetTableDescription() const;
  163. const char * const GetRowDescription() const;
  164. };
  165. typedef CList<SIMCTable *, SIMCTable *> SIMCTableMembers;
  166. // For generating a name for the object group, in case of the V1 SMI
  167. #define OBJ_GROUP_FABRICATION_SUFFIX "V1ObjectGroup"
  168. #define OBJ_GROUP_FABRICATION_SUFFIX_LEN 13
  169. // And finally the object group itself. Please read the "compiler requirements
  170. // specification" for a definitions of "object group", "named node" etc.
  171. class SIMCObjectGroup
  172. {
  173. public:
  174. enum ObjectGroupStatusType
  175. {
  176. STATUS_INVALID, // Not used,
  177. STATUS_CURRENT,
  178. STATUS_DEPRECATED,
  179. STATUS_OBSOLETE
  180. };
  181. private:
  182. // Various clauses of the object group
  183. char *objectGroupName;
  184. char *description;
  185. char *reference;
  186. SIMCSymbol *namedNode;
  187. SIMCCleanOidValue *namedNodeValue;
  188. SIMCScalarMembers *scalars;
  189. SIMCTableMembers *tables;
  190. ObjectGroupStatusType status;
  191. static const char * const StatusStringsTable[3];
  192. public:
  193. SIMCObjectGroup(SIMCSymbol *n, SIMCCleanOidValue *nv, SIMCScalarMembers *sm, SIMCTableMembers *tm,
  194. ObjectGroupStatusType s, const char * descriptionV, const char *referenceV)
  195. : namedNode(n), namedNodeValue(nv), scalars(sm), tables(tm), status(s)
  196. {
  197. objectGroupName = NewString(strlen(n->GetSymbolName()) +
  198. OBJ_GROUP_FABRICATION_SUFFIX_LEN + 1);
  199. strcpy(objectGroupName, n->GetSymbolName());
  200. strcat(objectGroupName, OBJ_GROUP_FABRICATION_SUFFIX);
  201. description = NewString(descriptionV);
  202. reference = NewString(referenceV);
  203. }
  204. SIMCObjectGroup()
  205. : namedNode(NULL), namedNodeValue(NULL), scalars(NULL), tables(NULL),
  206. status(STATUS_CURRENT), objectGroupName(NULL), description(NULL),
  207. reference(NULL)
  208. {}
  209. ~SIMCObjectGroup()
  210. {
  211. if(objectGroupName)
  212. delete [] objectGroupName;
  213. if(description)
  214. delete [] description;
  215. if(reference)
  216. delete [] reference;
  217. if(scalars)
  218. {
  219. SIMCScalar *nextScalar;
  220. while(!scalars->IsEmpty() )
  221. {
  222. nextScalar = scalars->RemoveHead();
  223. delete nextScalar;
  224. }
  225. delete scalars;
  226. }
  227. if(tables)
  228. {
  229. SIMCTable *nextTable;
  230. while(!tables->IsEmpty() )
  231. {
  232. nextTable = tables->RemoveHead();
  233. delete nextTable;
  234. }
  235. delete tables;
  236. }
  237. if(namedNodeValue) delete namedNodeValue;
  238. }
  239. friend ostream& operator << (ostream& outStream, const SIMCObjectGroup& obj);
  240. SIMCSymbol *GetNamedNode() const
  241. {
  242. return namedNode;
  243. }
  244. void SetNamedNode(SIMCSymbol *nn)
  245. {
  246. namedNode = nn;
  247. if(objectGroupName)
  248. delete [] objectGroupName;
  249. objectGroupName = NewString(strlen(nn->GetSymbolName()) +
  250. OBJ_GROUP_FABRICATION_SUFFIX_LEN + 1);
  251. strcpy(objectGroupName, nn->GetSymbolName());
  252. strcat(objectGroupName, OBJ_GROUP_FABRICATION_SUFFIX);
  253. }
  254. const char * const GetObjectGroupName() const
  255. {
  256. return objectGroupName;
  257. }
  258. const char * const GetDescription() const
  259. {
  260. return description;
  261. }
  262. void SetDescription(const char * const descriptionV)
  263. {
  264. if(description)
  265. delete [] description;
  266. description = NewString(descriptionV);
  267. }
  268. const char * const GetReference() const
  269. {
  270. return reference;
  271. }
  272. void SetReference(const char * const referenceV)
  273. {
  274. if(reference)
  275. delete [] reference;
  276. reference = NewString(referenceV);
  277. }
  278. SIMCCleanOidValue *GetGroupValue() const
  279. {
  280. return namedNodeValue;
  281. }
  282. void SetGroupValue(SIMCCleanOidValue *val)
  283. {
  284. namedNodeValue = val;
  285. }
  286. SIMCScalarMembers *GetScalarMembers() const
  287. {
  288. return scalars;
  289. }
  290. void AddScalar(SIMCScalar *s)
  291. {
  292. if(!scalars)
  293. scalars = new SIMCScalarMembers;
  294. scalars->AddTail(s);
  295. }
  296. long GetScalarCount() const
  297. {
  298. if(scalars)
  299. return scalars->GetCount();
  300. else
  301. return 0;
  302. }
  303. SIMCTableMembers *GetTableMembers() const
  304. {
  305. return tables;
  306. }
  307. void AddTable(SIMCTable *t)
  308. {
  309. if(!tables)
  310. tables = new SIMCTableMembers;
  311. tables->AddTail(t);
  312. }
  313. long GetTableCount() const
  314. {
  315. if(tables)
  316. return tables->GetCount();
  317. else
  318. return 0;
  319. }
  320. ObjectGroupStatusType GetStatus() const
  321. {
  322. return status;
  323. }
  324. void SetStatus(ObjectGroupStatusType s)
  325. {
  326. status = s;
  327. }
  328. const char * const GetStatusString() const
  329. {
  330. switch(status)
  331. {
  332. case STATUS_CURRENT:
  333. return StatusStringsTable[STATUS_CURRENT-1];
  334. case STATUS_DEPRECATED:
  335. return StatusStringsTable[STATUS_DEPRECATED-1];
  336. case STATUS_OBSOLETE:
  337. return StatusStringsTable[STATUS_OBSOLETE-1];
  338. default:
  339. return NULL;
  340. }
  341. return NULL;
  342. }
  343. SIMCScalar *GetScalar(SIMCSymbol *objectSymbol) const;
  344. SIMCTable *GetTable(SIMCSymbol *objectSymbol) const;
  345. BOOL ObjectsInModule(const SIMCModule *theModule) const;
  346. };
  347. #ifndef SIMC_GROUP_LIST
  348. #define SIMC_GROUP_LIST
  349. typedef CList<SIMCObjectGroup *, SIMCObjectGroup*> SIMCGroupList;
  350. ostream& operator << (ostream& outStream, const SIMCGroupList& obj);
  351. #endif
  352. #endif