Source code of Windows XP (NT5)
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.

151 lines
4.4 KiB

  1. //================================================================================
  2. // Copyright (C) 1997 Microsoft Corporation
  3. // Author: RameshV
  4. // Description: implements the basic structures for storing complete option configuration info
  5. // ThreadSafe: no
  6. // Locks: none
  7. // Please read stdinfo.txt for programming style.
  8. //================================================================================
  9. #include <mm.h>
  10. #include <array.h>
  11. #include <optdefl.h>
  12. //BeginExport(typedef)
  13. typedef struct _M_OPTCLASSDEFL_ONE {
  14. DWORD ClassId;
  15. DWORD VendorId;
  16. M_OPTDEFLIST OptDefList;
  17. } M_OPTCLASSDEFL_ONE, *PM_OPTCLASSDEFL_ONE;
  18. typedef struct _M_OPTCLASSDEFLIST {
  19. ARRAY Array;
  20. } M_OPTCLASSDEFLIST, *PM_OPTCLASSDEFLIST, *LPM_OPTCLASSDEFLIST;
  21. //EndExport(typedef)
  22. //BeginExport(inline)
  23. DWORD _inline
  24. MemOptClassDefListInit(
  25. IN OUT PM_OPTCLASSDEFLIST OptClassDefList
  26. ) {
  27. return MemArrayInit(&OptClassDefList->Array);
  28. }
  29. //EndExport(inline)
  30. //BeginExport(inline)
  31. DWORD _inline
  32. MemOptClassDefListCleanup(
  33. IN OUT PM_OPTCLASSDEFLIST OptClassDefList
  34. ) {
  35. // Bump down class Id refcount?
  36. return MemArrayCleanup(&OptClassDefList->Array);
  37. }
  38. //EndExport(inline)
  39. //BeginExport(function)
  40. DWORD
  41. MemOptClassDefListFindOptDefList(
  42. IN OUT PM_OPTCLASSDEFLIST OptClassDefList,
  43. IN DWORD ClassId,
  44. IN DWORD VendorId,
  45. OUT PM_OPTDEFLIST *OptDefList
  46. ) //EndExport(function)
  47. {
  48. ARRAY_LOCATION Location;
  49. DWORD Error;
  50. PM_OPTCLASSDEFL_ONE OneClassDefList;
  51. AssertRet(OptClassDefList && OptDefList, ERROR_INVALID_PARAMETER);
  52. *OptDefList = NULL;
  53. for( Error = MemArrayInitLoc(&OptClassDefList->Array, &Location)
  54. ; ERROR_FILE_NOT_FOUND != Error ;
  55. Error = MemArrayNextLoc(&OptClassDefList->Array, &Location)
  56. ) {
  57. Require(ERROR_SUCCESS == Error );
  58. Error = MemArrayGetElement(
  59. &OptClassDefList->Array,
  60. &Location,
  61. (LPVOID*)&OneClassDefList
  62. );
  63. Require(ERROR_SUCCESS == Error && OneClassDefList);
  64. if( OneClassDefList->ClassId == ClassId &&
  65. OneClassDefList->VendorId == VendorId ) {
  66. *OptDefList = &OneClassDefList->OptDefList;
  67. return ERROR_SUCCESS;
  68. }
  69. }
  70. return ERROR_FILE_NOT_FOUND;
  71. }
  72. //BeginExport(function)
  73. DWORD
  74. MemOptClassDefListAddOptDef(
  75. IN OUT PM_OPTCLASSDEFLIST OptClassDefList,
  76. IN DWORD ClassId,
  77. IN DWORD VendorId,
  78. IN DWORD OptId,
  79. IN DWORD Type,
  80. IN LPWSTR Name,
  81. IN LPWSTR Comment,
  82. IN LPBYTE OptVal,
  83. IN DWORD OptLen
  84. ) //EndExport(function)
  85. {
  86. DWORD Error;
  87. PM_OPTCLASSDEFL_ONE OneClassDefList;
  88. PM_OPTDEFLIST OptDefList;
  89. AssertRet(OptClassDefList, ERROR_INVALID_PARAMETER);
  90. OneClassDefList = NULL;
  91. Error = MemOptClassDefListFindOptDefList(
  92. OptClassDefList,
  93. ClassId,
  94. VendorId,
  95. &OptDefList
  96. );
  97. if( ERROR_SUCCESS != Error ) {
  98. Require(ERROR_FILE_NOT_FOUND == Error);
  99. OneClassDefList = MemAlloc(sizeof(*OneClassDefList));
  100. if( NULL == OneClassDefList) return ERROR_NOT_ENOUGH_MEMORY;
  101. // RefCount on ClassId needs to be bumped up?
  102. OneClassDefList->ClassId = ClassId;
  103. OneClassDefList->VendorId = VendorId;
  104. Error = MemOptDefListInit(&OneClassDefList->OptDefList);
  105. if( ERROR_SUCCESS != Error ) {
  106. MemFree(OneClassDefList);
  107. return Error;
  108. }
  109. Error = MemArrayAddElement(&OptClassDefList->Array, OneClassDefList);
  110. if( ERROR_SUCCESS != Error) {
  111. MemFree(OneClassDefList);
  112. return Error;
  113. }
  114. OptDefList = &OneClassDefList->OptDefList;
  115. }
  116. Error = MemOptDefListAddOptDef(
  117. OptDefList,
  118. OptId,
  119. Type,
  120. Name,
  121. Comment,
  122. OptVal,
  123. OptLen
  124. );
  125. return Error;
  126. }
  127. //================================================================================
  128. // end of file
  129. //================================================================================