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.

275 lines
7.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. mofgen.h
  5. Abstract:
  6. This include file contains the definition for the CMofGen class
  7. Author:
  8. Mohit Srivastava 28-Nov-00
  9. Revision History:
  10. --*/
  11. #ifndef _mofgen_h_
  12. #define _mofgen_h_
  13. extern LPCWSTR g_wszIIsProvider; // defined in iisprov.h
  14. #include <wbemcli.h>
  15. struct CimTypeStringMapping
  16. {
  17. CIMTYPE cimtype;
  18. LPCWSTR wszString;
  19. LPCWSTR wszFormatString;
  20. };
  21. static CimTypeStringMapping CimTypeStringMappingData[] =
  22. {
  23. { CIM_SINT8, L"sint8" , L"%d" },
  24. { CIM_UINT8, L"uint8" , L"%d" },
  25. { CIM_SINT16, L"sint16" , L"%hd" },
  26. { CIM_UINT16, L"uint16" , L"%hu" },
  27. { CIM_SINT32, L"sint32" , L"%d" },
  28. { CIM_UINT32, L"uint32" , L"%u" },
  29. { CIM_SINT64, L"sint64" , L"%I64d" },
  30. { CIM_UINT64, L"uint64" , L"%I64u" },
  31. { CIM_REAL32, L"real32" , L"%f" },
  32. { CIM_REAL64, L"real64" , L"%f" },
  33. { CIM_BOOLEAN, L"boolean" , NULL },
  34. { CIM_STRING, L"string" , L"\"%s\"" },
  35. { CIM_DATETIME, L"datetime" , NULL },
  36. { CIM_REFERENCE, L"reference", NULL },
  37. { CIM_CHAR16, L"char16" , NULL },
  38. { CIM_OBJECT, L"object" , NULL },
  39. { 0, NULL , NULL }
  40. };
  41. class CMofGenUtils
  42. {
  43. public:
  44. static CimTypeStringMapping* LookupCimType(
  45. CIMTYPE cimtype)
  46. {
  47. for(ULONG i = 0; CimTypeStringMappingData[i].wszString != NULL; i++)
  48. {
  49. if(cimtype == CimTypeStringMappingData[i].cimtype)
  50. {
  51. return &CimTypeStringMappingData[i];
  52. }
  53. }
  54. return NULL;
  55. }
  56. };
  57. class CMofGen
  58. {
  59. public:
  60. CMofGen() : m_pFile(NULL),
  61. m_wszHeaderFileName(NULL),
  62. m_wszFooterFileName(NULL),
  63. m_wszOutFileName(NULL),
  64. m_wszTemp(NULL),
  65. m_cchTemp(0)
  66. {
  67. }
  68. virtual ~CMofGen()
  69. {
  70. if(m_pFile != NULL)
  71. {
  72. fclose(m_pFile);
  73. }
  74. delete [] m_wszTemp;
  75. }
  76. bool ParseCmdLine (int argc, wchar_t **argv);
  77. void PrintUsage (wchar_t **argv);
  78. HRESULT Push();
  79. LPWSTR GetOutFileName()
  80. {
  81. return m_wszOutFileName;
  82. }
  83. private:
  84. //
  85. // File handle to output file
  86. //
  87. FILE* m_pFile;
  88. LPWSTR m_wszHeaderFileName;
  89. LPWSTR m_wszFooterFileName;
  90. LPWSTR m_wszOutFileName;
  91. LPWSTR m_wszTemp;
  92. ULONG m_cchTemp;
  93. HRESULT GenerateEscapedString(LPCWSTR i_wsz);
  94. HRESULT PushProperties(
  95. WMI_CLASS* i_pElement);
  96. HRESULT PushMethods(
  97. WMI_CLASS* i_pElement);
  98. HRESULT PushAssociationComponent(
  99. LPWSTR i_wszComp,
  100. LPWSTR i_wszClass);
  101. HRESULT PushFormattedMultiSz();
  102. HRESULT PushFile(
  103. LPWSTR i_wszFile);
  104. template <class T>
  105. HRESULT PushClasses(CHashTable<T>* i_phashTable,
  106. bool bAssoc)
  107. {
  108. DBG_ASSERT(i_phashTable != NULL);
  109. DBG_ASSERT(m_pFile != NULL);
  110. HRESULT hr = S_OK;
  111. //
  112. // Vars needed for iteration
  113. //
  114. CHashTable<T>::Record* pRec = NULL;
  115. LPWSTR wszParentClass = NULL;
  116. LPWSTR wszDescription = NULL;
  117. int iError = 0;
  118. //
  119. // Walk thru classes
  120. //
  121. ULONG iShipped;
  122. CHashTable<T>::iterator iter;
  123. CHashTable<T>::iterator iterEnd = i_phashTable->end();
  124. for (iter = i_phashTable->begin(); iter != iterEnd; ++iter)
  125. {
  126. pRec = iter.Record();
  127. iShipped = bAssoc ?
  128. ((WMI_ASSOCIATION*)(pRec->m_data))->dwExtended :
  129. ((WMI_CLASS*)(pRec->m_data))->dwExtended;
  130. if(iShipped == SHIPPED_TO_MOF)
  131. {
  132. if(!bAssoc)
  133. {
  134. wszParentClass = ((WMI_CLASS*)(pRec->m_data))->pszParentClass;
  135. wszDescription = ((WMI_CLASS*)(pRec->m_data))->pszDescription;
  136. }
  137. else
  138. {
  139. wszParentClass = ((WMI_ASSOCIATION*)(pRec->m_data))->pszParentClass;
  140. // wszDescription = ((WMI_ASSOCIATION*)(pRec->m_data))->pszDescription;
  141. }
  142. iError = fwprintf(m_pFile, L"[dynamic : ToInstance,provider(\"%s\"),Locale(1033)", g_wszIIsProvider);
  143. if(iError < 0)
  144. {
  145. hr = E_FAIL;
  146. goto exit;
  147. }
  148. if(wszDescription != NULL)
  149. {
  150. iError = fwprintf(m_pFile, L",Description(\"%s\")", wszDescription);
  151. if(iError < 0)
  152. {
  153. hr = E_FAIL;
  154. goto exit;
  155. }
  156. }
  157. iError = fwprintf(m_pFile, L"]\n");
  158. if(iError < 0)
  159. {
  160. hr = E_FAIL;
  161. goto exit;
  162. }
  163. iError = fwprintf(m_pFile, L"class %s : %s\n", pRec->m_wszKey, wszParentClass);
  164. if(iError < 0)
  165. {
  166. hr = E_FAIL;
  167. goto exit;
  168. }
  169. iError = fwprintf(m_pFile, L"{\n");
  170. if(iError < 0)
  171. {
  172. hr = E_FAIL;
  173. goto exit;
  174. }
  175. if(!bAssoc)
  176. {
  177. bool bPutNameProperty = true;
  178. for(ULONG j = 0; g_awszParentClassWithNamePK[j] != NULL; j++)
  179. {
  180. //
  181. // Deliberate ==
  182. //
  183. if(g_awszParentClassWithNamePK[j] == ((WMI_CLASS *)(pRec->m_data))->pszParentClass)
  184. {
  185. bPutNameProperty = false;
  186. }
  187. }
  188. if( bPutNameProperty )
  189. {
  190. iError = fwprintf(m_pFile, L"\t[Key] string Name;\n");
  191. if(iError < 0)
  192. {
  193. hr = E_FAIL;
  194. goto exit;
  195. }
  196. }
  197. hr = PushProperties((WMI_CLASS *)(pRec->m_data));
  198. if(FAILED(hr))
  199. {
  200. goto exit;
  201. }
  202. hr = PushMethods((WMI_CLASS *)(pRec->m_data));
  203. if(FAILED(hr))
  204. {
  205. goto exit;
  206. }
  207. }
  208. else
  209. {
  210. hr = PushAssociationComponent(
  211. ((WMI_ASSOCIATION *)(pRec->m_data))->pType->pszLeft,
  212. ((WMI_ASSOCIATION *)(pRec->m_data))->pcLeft->pszClassName);
  213. if(FAILED(hr))
  214. {
  215. goto exit;
  216. }
  217. hr = PushAssociationComponent(
  218. ((WMI_ASSOCIATION *)(pRec->m_data))->pType->pszRight,
  219. ((WMI_ASSOCIATION *)(pRec->m_data))->pcRight->pszClassName);
  220. if(FAILED(hr))
  221. {
  222. goto exit;
  223. }
  224. }
  225. iError = fwprintf(m_pFile, L"};\n\n");
  226. if(iError < 0)
  227. {
  228. hr = E_FAIL;
  229. goto exit;
  230. }
  231. }
  232. }
  233. exit:
  234. return hr;
  235. }
  236. };
  237. #endif // _mofgen_h_