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.

142 lines
4.5 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. #include "optclass.h"
  14. //BeginExport(function)
  15. MemOptClassFindClassOptions( // find options for one particular class
  16. IN OUT PM_OPTCLASS OptClass,
  17. IN DWORD ClassId,
  18. IN DWORD VendorId,
  19. OUT PM_OPTLIST *OptList
  20. ) //EndExport(function)
  21. {
  22. ARRAY_LOCATION Location;
  23. PM_ONECLASS_OPTLIST ThisOptList;
  24. DWORD Error;
  25. AssertRet(OptClass && OptList, ERROR_INVALID_PARAMETER);
  26. for( Error = MemArrayInitLoc(&OptClass->Array, &Location)
  27. ; ERROR_FILE_NOT_FOUND != Error ;
  28. Error = MemArrayNextLoc(&OptClass->Array, &Location)
  29. ) {
  30. Require(ERROR_SUCCESS == Error);
  31. Error = MemArrayGetElement(
  32. &OptClass->Array,
  33. &Location,
  34. (LPVOID*)&ThisOptList
  35. );
  36. Require(ERROR_SUCCESS == Error && ThisOptList);
  37. if( ThisOptList->ClassId == ClassId &&
  38. ThisOptList->VendorId == VendorId ) {
  39. *OptList = &ThisOptList->OptList;
  40. return ERROR_SUCCESS;
  41. }
  42. }
  43. *OptList = NULL;
  44. return ERROR_FILE_NOT_FOUND;
  45. } // MemOptClassFindClassOptions()
  46. //BeginExport(function)
  47. DWORD
  48. MemOptClassAddOption(
  49. IN OUT PM_OPTCLASS OptClass,
  50. IN PM_OPTION Opt,
  51. IN DWORD ClassId,
  52. IN DWORD VendorId,
  53. OUT PM_OPTION *DeletedOpt,
  54. IN ULONG UniqId
  55. ) //EndExport(function)
  56. {
  57. DWORD Error;
  58. PM_OPTLIST ThisOptList;
  59. PM_ONECLASS_OPTLIST ThisOneOptList;
  60. AssertRet(OptClass && Opt && DeletedOpt, ERROR_INVALID_PARAMETER);
  61. ThisOneOptList = NULL;
  62. (*DeletedOpt) = NULL;
  63. Error = MemOptClassFindClassOptions(OptClass,ClassId,VendorId,&ThisOptList);
  64. if( ERROR_SUCCESS != Error ) {
  65. ThisOneOptList = MemAlloc(sizeof(*ThisOneOptList));
  66. if( NULL == ThisOneOptList ) return ERROR_NOT_ENOUGH_MEMORY;
  67. // RefCount on ClassId has to go up?
  68. ThisOneOptList->ClassId = ClassId;
  69. ThisOneOptList->VendorId = VendorId;
  70. Error = MemOptListInit(&ThisOneOptList->OptList);
  71. if( ERROR_SUCCESS != Error ) {
  72. MemFree(ThisOneOptList);
  73. return Error;
  74. }
  75. // ThisOneOptList->UniqId = UniqId;
  76. Error = MemArrayAddElement(&OptClass->Array, ThisOneOptList);
  77. if( ERROR_SUCCESS != Error ) {
  78. MemFree(ThisOneOptList);
  79. return Error;
  80. }
  81. ThisOptList = &ThisOneOptList->OptList;
  82. } // if
  83. Opt->UniqId = UniqId;
  84. Error = MemOptListAddOption(ThisOptList, Opt, DeletedOpt);
  85. return Error;
  86. } // MemOptClassAddOption()
  87. // Delete all the options in this optclass
  88. DWORD
  89. MemOptClassDelClass (
  90. IN PM_OPTCLASS OptClass
  91. )
  92. {
  93. DWORD Error;
  94. ARRAY_LOCATION Loc;
  95. PM_ONECLASS_OPTLIST OptClassList;
  96. AssertRet( OptClass, ERROR_INVALID_PARAMETER );
  97. Error = MemArrayInitLoc( &OptClass->Array, &Loc );
  98. while (( MemArraySize( &OptClass->Array ) > 0 ) &&
  99. ( ERROR_FILE_NOT_FOUND != Error )) {
  100. Require( ERROR_SUCCESS == Error );
  101. Error = MemArrayGetElement( &OptClass->Array, &Loc,
  102. ( LPVOID * ) &OptClassList );
  103. Require( ERROR_SUCCESS == Error );
  104. Error = MemOptListDelList( &OptClassList->OptList );
  105. if ( ERROR_SUCCESS != Error ) {
  106. return Error;
  107. }
  108. Error = MemArrayDelElement( &OptClass->Array, &Loc,
  109. ( LPVOID * ) &OptClassList );
  110. Require( ERROR_SUCCESS == Error && OptClassList );
  111. } // while
  112. if ( ERROR_FILE_NOT_FOUND == Error ) {
  113. Error = ERROR_SUCCESS;
  114. }
  115. return Error;
  116. } // MemOptClassDelClass()
  117. //================================================================================
  118. // end of file
  119. //================================================================================