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.

132 lines
3.9 KiB

  1. //================================================================================
  2. // Copyright (C) 1997 Microsoft Corporation
  3. // Author: RameshV
  4. // Description: implements the basic structures for options, including class id
  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 <opt.h>
  12. #include <optl.h>
  13. //BeginExport(typedef)
  14. typedef struct _M_ONECLASS_OPTLIST {
  15. DWORD ClassId;
  16. DWORD VendorId;
  17. M_OPTLIST OptList;
  18. } M_ONECLASS_OPTLIST, *PM_ONECLASS_OPTLIST, *LPM_ONECLASS_OPTLIST;
  19. typedef struct _M_OPTCLASS {
  20. ARRAY Array;
  21. } M_OPTCLASS, *PM_OPTCLASS, *LPM_OPTCLASS;
  22. //EndExport(typedef)
  23. //BeginExport(inline)
  24. DWORD _inline
  25. MemOptClassInit(
  26. IN OUT PM_OPTCLASS OptClass
  27. ) {
  28. return MemArrayInit(&OptClass->Array);
  29. }
  30. //EndExport(inline)
  31. //BeginExport(inline)
  32. DWORD _inline
  33. MemOptClassCleanup(
  34. IN OUT PM_OPTCLASS OptClass
  35. ) {
  36. // Bump down refcounts?
  37. return MemArrayCleanup(&OptClass->Array);
  38. }
  39. //EndExport(inline)
  40. //BeginExport(function)
  41. MemOptClassFindClassOptions( // find options for one particular class
  42. IN OUT PM_OPTCLASS OptClass,
  43. IN DWORD ClassId,
  44. IN DWORD VendorId,
  45. OUT PM_OPTLIST *OptList
  46. ) //EndExport(function)
  47. {
  48. ARRAY_LOCATION Location;
  49. PM_ONECLASS_OPTLIST ThisOptList;
  50. DWORD Error;
  51. AssertRet(OptClass && OptList, ERROR_INVALID_PARAMETER);
  52. for( Error = MemArrayInitLoc(&OptClass->Array, &Location)
  53. ; ERROR_FILE_NOT_FOUND != Error ;
  54. Error = MemArrayNextLoc(&OptClass->Array, &Location)
  55. ) {
  56. Require(ERROR_SUCCESS == Error);
  57. Error = MemArrayGetElement(
  58. &OptClass->Array,
  59. &Location,
  60. (LPVOID*)&ThisOptList
  61. );
  62. Require(ERROR_SUCCESS == Error && ThisOptList);
  63. if( ThisOptList->ClassId == ClassId &&
  64. ThisOptList->VendorId == VendorId ) {
  65. *OptList = &ThisOptList->OptList;
  66. return ERROR_SUCCESS;
  67. }
  68. }
  69. *OptList = NULL;
  70. return ERROR_FILE_NOT_FOUND;
  71. }
  72. //BeginExport(function)
  73. DWORD
  74. MemOptClassAddOption(
  75. IN OUT PM_OPTCLASS OptClass,
  76. IN PM_OPTION Opt,
  77. IN DWORD ClassId,
  78. IN DWORD VendorId,
  79. OUT PM_OPTION *DeletedOpt
  80. ) //EndExport(function)
  81. {
  82. DWORD Error;
  83. PM_OPTLIST ThisOptList;
  84. PM_ONECLASS_OPTLIST ThisOneOptList;
  85. AssertRet(OptClass && Opt && DeletedOpt, ERROR_INVALID_PARAMETER);
  86. ThisOneOptList = NULL;
  87. (*DeletedOpt) = NULL;
  88. Error = MemOptClassFindClassOptions(OptClass,ClassId,VendorId,&ThisOptList);
  89. if( ERROR_SUCCESS != Error ) {
  90. ThisOneOptList = MemAlloc(sizeof(*ThisOneOptList));
  91. if( NULL == ThisOneOptList ) return ERROR_NOT_ENOUGH_MEMORY;
  92. // RefCount on ClassId has to go up?
  93. ThisOneOptList->ClassId = ClassId;
  94. ThisOneOptList->VendorId = VendorId;
  95. Error = MemOptListInit(&ThisOneOptList->OptList);
  96. if( ERROR_SUCCESS != Error ) {
  97. MemFree(ThisOneOptList);
  98. return Error;
  99. }
  100. Error = MemArrayAddElement(&OptClass->Array, ThisOneOptList);
  101. if( ERROR_SUCCESS != Error ) {
  102. MemFree(ThisOneOptList);
  103. return Error;
  104. }
  105. ThisOptList = &ThisOneOptList->OptList;
  106. }
  107. Error = MemOptListAddOption(ThisOptList, Opt, DeletedOpt);
  108. return Error;
  109. }
  110. //================================================================================
  111. // end of file
  112. //================================================================================