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.

568 lines
13 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. op.cxx
  5. Abstract:
  6. Routines implementing the Operation object
  7. Author:
  8. Cliff Van Dyke (cliffv) 11-Apr-2001
  9. --*/
  10. #include "pch.hxx"
  11. DWORD
  12. AzpOperationInit(
  13. IN PGENERIC_OBJECT ParentGenericObject,
  14. IN PGENERIC_OBJECT ChildGenericObject
  15. )
  16. /*++
  17. Routine Description:
  18. This routine is a worker routine for AzOperationCreate. It does any object specific
  19. initialization that needs to be done.
  20. On entry, AzGlResource must be locked exclusively.
  21. Arguments:
  22. ParentGenericObject - Specifies the parent object to add the child object onto.
  23. The reference count has been incremented on this object.
  24. ChildGenericObject - Specifies the newly allocated child object.
  25. The reference count has been incremented on this object.
  26. Return Value:
  27. NO_ERROR - The operation was successful
  28. ERROR_NOT_ENOUGH_MEMORY - not enough memory
  29. Other exception status codes
  30. --*/
  31. {
  32. PAZP_OPERATION Operation = (PAZP_OPERATION) ChildGenericObject;
  33. //
  34. // Initialization
  35. //
  36. ASSERT( AzpIsLockedExclusive( &AzGlResource ) );
  37. //
  38. // Sanity check the parent
  39. //
  40. ASSERT( ParentGenericObject->ObjectType == OBJECT_TYPE_APPLICATION );
  41. UNREFERENCED_PARAMETER( ParentGenericObject );
  42. //
  43. // Operations are referenced by "Tasks" and "Roles"
  44. // Let the generic object manager know all of the lists we support
  45. // This is a "back" link so we don't need to define which tasks can reference this operation.
  46. //
  47. ChildGenericObject->GenericObjectLists = &Operation->backTasks;
  48. // Back link to tasks
  49. ObInitObjectList( &Operation->backTasks,
  50. &Operation->backRoles,
  51. TRUE, // Backward link
  52. 0, // No link pair id
  53. NULL,
  54. NULL,
  55. NULL );
  56. // Back link to roles
  57. ObInitObjectList( &Operation->backRoles,
  58. NULL,
  59. TRUE, // Backward link
  60. 0, // No link pair id
  61. NULL,
  62. NULL,
  63. NULL );
  64. return NO_ERROR;
  65. }
  66. VOID
  67. AzpOperationFree(
  68. IN PGENERIC_OBJECT GenericObject
  69. )
  70. /*++
  71. Routine Description:
  72. This routine is a worker routine for Operation object free. It does any object specific
  73. cleanup that needs to be done.
  74. On entry, AzGlResource must be locked exclusively.
  75. Arguments:
  76. GenericObject - Specifies a pointer to the object to be deleted.
  77. Return Value:
  78. None
  79. --*/
  80. {
  81. // PAZP_OPERATION Operation = (PAZP_OPERATION) GenericObject;
  82. UNREFERENCED_PARAMETER( GenericObject );
  83. //
  84. // Initialization
  85. //
  86. ASSERT( AzpIsLockedExclusive( &AzGlResource ) );
  87. //
  88. // Free any local strings
  89. //
  90. }
  91. DWORD
  92. AzpOperationGetProperty(
  93. IN PGENERIC_OBJECT GenericObject,
  94. IN ULONG PropertyId,
  95. OUT PVOID *PropertyValue
  96. )
  97. /*++
  98. Routine Description:
  99. This routine is a worker routine for AzOperationGetProperty. It does any object specific
  100. property gets.
  101. On entry, AzGlResource must be locked shared.
  102. Arguments:
  103. GenericObject - Specifies a pointer to the object to be queried
  104. PropertyId - Specifies which property to return.
  105. PropertyValue - Specifies a pointer to return the property in.
  106. The returned pointer must be freed using AzFreeMemory.
  107. The returned value and type depends in PropertyId. The valid values are:
  108. AZ_PROP_OPERATION_ID PULONG - Operation ID of the operation
  109. Return Value:
  110. Status of the operation
  111. --*/
  112. {
  113. DWORD WinStatus = NO_ERROR;
  114. PAZP_OPERATION Operation = (PAZP_OPERATION) GenericObject;
  115. //
  116. // Initialization
  117. //
  118. ASSERT( AzpIsLockedShared( &AzGlResource ) );
  119. //
  120. // Return any object specific attribute
  121. //
  122. // Return operation id to the caller
  123. //
  124. switch ( PropertyId ) {
  125. case AZ_PROP_OPERATION_ID:
  126. *PropertyValue = AzpGetUlongProperty( Operation->OperationId );
  127. if ( *PropertyValue == NULL ) {
  128. WinStatus = ERROR_NOT_ENOUGH_MEMORY;
  129. }
  130. break;
  131. default:
  132. AzPrint(( AZD_INVPARM, "AzpOperationGetProperty: invalid prop id %ld\n", PropertyId ));
  133. WinStatus = ERROR_INVALID_PARAMETER;
  134. break;
  135. }
  136. return WinStatus;
  137. }
  138. DWORD
  139. AzpOperationSetProperty(
  140. IN PGENERIC_OBJECT GenericObject,
  141. IN ULONG PropertyId,
  142. IN PVOID PropertyValue
  143. )
  144. /*++
  145. Routine Description:
  146. This routine is a worker routine for AzOperationSetProperty. It does any object specific
  147. property sets.
  148. On entry, AzGlResource must be locked exclusive.
  149. Arguments:
  150. GenericObject - Specifies a pointer to the object to be modified
  151. PropertyId - Specifies which property to set.
  152. PropertyValue - Specifies a pointer to the property.
  153. The specified value and type depends in PropertyId. The valid values are:
  154. AZ_PROP_OPERATION_ID PULONG - Operation ID of the operation
  155. Return Value:
  156. Status of the operation
  157. --*/
  158. {
  159. DWORD WinStatus;
  160. PAZP_OPERATION Operation = (PAZP_OPERATION) GenericObject;
  161. //
  162. // Initialization
  163. //
  164. ASSERT( AzpIsLockedExclusive( &AzGlResource ) );
  165. //
  166. // Return any object specific attribute
  167. //
  168. // Return ooperation id to the caller
  169. //
  170. switch ( PropertyId ) {
  171. case AZ_PROP_OPERATION_ID:
  172. WinStatus = AzpCaptureUlong( PropertyValue, &Operation->OperationId );
  173. break;
  174. default:
  175. AzPrint(( AZD_INVPARM, "AzpOperationSetProperty: invalid prop id %ld\n", PropertyId ));
  176. WinStatus = ERROR_INVALID_PARAMETER;
  177. break;
  178. }
  179. return WinStatus;
  180. }
  181. DWORD
  182. WINAPI
  183. AzOperationCreate(
  184. IN AZ_HANDLE ApplicationHandle,
  185. IN LPCWSTR OperationName,
  186. IN DWORD Reserved,
  187. OUT PAZ_HANDLE OperationHandle
  188. )
  189. /*++
  190. Routine Description:
  191. This routine adds an operation into the scope of the specified application.
  192. Arguments:
  193. ApplicationHandle - Specifies a handle to the application.
  194. OperationName - Specifies the name of the operation to add.
  195. Reserved - Reserved. Must by zero.
  196. OperationHandle - Return a handle to the operation.
  197. The caller must close this handle by calling AzCloseHandle.
  198. Return Value:
  199. NO_ERROR - The operation was successful
  200. ERROR_ALREADY_EXISTS - An object by that name already exists
  201. --*/
  202. {
  203. //
  204. // Call the common routine to do most of the work
  205. //
  206. return ObCommonCreateObject(
  207. (PGENERIC_OBJECT) ApplicationHandle,
  208. OBJECT_TYPE_APPLICATION,
  209. &(((PAZP_APPLICATION)ApplicationHandle)->Operations),
  210. OBJECT_TYPE_OPERATION,
  211. OperationName,
  212. Reserved,
  213. (PGENERIC_OBJECT *) OperationHandle );
  214. }
  215. DWORD
  216. WINAPI
  217. AzOperationOpen(
  218. IN AZ_HANDLE ApplicationHandle,
  219. IN LPCWSTR OperationName,
  220. IN DWORD Reserved,
  221. OUT PAZ_HANDLE OperationHandle
  222. )
  223. /*++
  224. Routine Description:
  225. This routine opens an operation into the scope of the specified application.
  226. Arguments:
  227. ApplicationHandle - Specifies a handle to the application.
  228. OperationName - Specifies the name of the operation to open
  229. Reserved - Reserved. Must by zero.
  230. OperationHandle - Return a handle to the operation.
  231. The caller must close this handle by calling AzCloseHandle.
  232. Return Value:
  233. NO_ERROR - The operation was successful
  234. ERROR_NOT_FOUND - There is no operation by that name
  235. --*/
  236. {
  237. //
  238. // Call the common routine to do most of the work
  239. //
  240. return ObCommonOpenObject(
  241. (PGENERIC_OBJECT) ApplicationHandle,
  242. OBJECT_TYPE_APPLICATION,
  243. &(((PAZP_APPLICATION)ApplicationHandle)->Operations),
  244. OBJECT_TYPE_OPERATION,
  245. OperationName,
  246. Reserved,
  247. (PGENERIC_OBJECT *) OperationHandle );
  248. }
  249. DWORD
  250. WINAPI
  251. AzOperationEnum(
  252. IN AZ_HANDLE ApplicationHandle,
  253. IN DWORD Reserved,
  254. IN OUT PULONG EnumerationContext,
  255. OUT PAZ_HANDLE OperationHandle
  256. )
  257. /*++
  258. Routine Description:
  259. Enumerates all of the operations for the specified application.
  260. Arguments:
  261. ApplicationHandle - Specifies a handle to the application.
  262. Reserved - Reserved. Must by zero.
  263. EnumerationContext - Specifies a context indicating the next operation to return
  264. On input for the first call, should point to zero.
  265. On input for subsequent calls, should point to the value returned on the previous call.
  266. On output, returns a value to be passed on the next call.
  267. OperationHandle - Returns a handle to the next operation object.
  268. The caller must close this handle by calling AzCloseHandle.
  269. Return Value:
  270. NO_ERROR - The operation was successful (a handle was returned)
  271. ERROR_NO_MORE_ITEMS - No more items were available for enumeration
  272. --*/
  273. {
  274. //
  275. // Call the common routine to do most of the work
  276. //
  277. return ObCommonEnumObjects(
  278. (PGENERIC_OBJECT) ApplicationHandle,
  279. OBJECT_TYPE_APPLICATION,
  280. &(((PAZP_APPLICATION)ApplicationHandle)->Operations),
  281. EnumerationContext,
  282. Reserved,
  283. (PGENERIC_OBJECT *) OperationHandle );
  284. }
  285. DWORD
  286. WINAPI
  287. AzOperationGetProperty(
  288. IN AZ_HANDLE OperationHandle,
  289. IN ULONG PropertyId,
  290. IN DWORD Reserved,
  291. OUT PVOID *PropertyValue
  292. )
  293. /*++
  294. Routine Description:
  295. Returns the specified property for an operation.
  296. Arguments:
  297. OperationHandle - Specifies a handle to the operation
  298. PropertyId - Specifies which property to return.
  299. Reserved - Reserved. Must by zero.
  300. PropertyValue - Specifies a pointer to return the property in.
  301. The returned pointer must be freed using AzFreeMemory.
  302. The returned value and type depends in PropertyId. The valid values are:
  303. AZ_PROP_NAME LPWSTR - Object name of the object
  304. AZ_PROP_DESCRIPTION LPWSTR - Description of the object
  305. AZ_PROP_OPERATION_ID PULONG - Operation ID of the operation
  306. Return Value:
  307. NO_ERROR - The operation was successful
  308. ERROR_INVALID_PARAMETER - PropertyId isn't valid
  309. --*/
  310. {
  311. //
  312. // Call the common routine to do most of the work
  313. //
  314. return ObCommonGetProperty(
  315. (PGENERIC_OBJECT) OperationHandle,
  316. OBJECT_TYPE_OPERATION,
  317. PropertyId,
  318. Reserved,
  319. PropertyValue );
  320. }
  321. DWORD
  322. WINAPI
  323. AzOperationSetProperty(
  324. IN AZ_HANDLE OperationHandle,
  325. IN ULONG PropertyId,
  326. IN DWORD Reserved,
  327. IN PVOID PropertyValue
  328. )
  329. /*++
  330. Routine Description:
  331. Sets the specified property for an operation.
  332. Arguments:
  333. OperationHandle - Specifies a handle to the operation
  334. PropertyId - Specifies which property to set
  335. Reserved - Reserved. Must by zero.
  336. PropertyValue - Specifies a pointer to the property.
  337. The specified value and type depends in PropertyId. The valid values are:
  338. AZ_PROP_NAME LPWSTR - Object name of the object
  339. AZ_PROP_DESCRIPTION LPWSTR - Description of the object
  340. AZ_PROP_OPERATION_ID PULONG - Operation ID of the operation
  341. Return Value:
  342. NO_ERROR - The operation was successful
  343. ERROR_INVALID_PARAMETER - PropertyId isn't valid
  344. --*/
  345. {
  346. //
  347. // Call the common routine to do most of the work
  348. //
  349. return ObCommonSetProperty(
  350. (PGENERIC_OBJECT) OperationHandle,
  351. OBJECT_TYPE_OPERATION,
  352. PropertyId,
  353. Reserved,
  354. PropertyValue );
  355. }
  356. DWORD
  357. WINAPI
  358. AzOperationDelete(
  359. IN AZ_HANDLE ApplicationHandle,
  360. IN LPCWSTR OperationName,
  361. IN DWORD Reserved
  362. )
  363. /*++
  364. Routine Description:
  365. This routine deletes an operation from the scope of the specified application.
  366. Also deletes any child objects of OperationName.
  367. Arguments:
  368. ApplicationHandle - Specifies a handle to the application.
  369. OperationName - Specifies the name of the operation to delete.
  370. Reserved - Reserved. Must by zero.
  371. Return Value:
  372. NO_ERROR - The operation was successful
  373. ERROR_NOT_FOUND - An object by that name cannot be found
  374. --*/
  375. {
  376. //
  377. // Call the common routine to do most of the work
  378. //
  379. return ObCommonDeleteObject(
  380. (PGENERIC_OBJECT) ApplicationHandle,
  381. OBJECT_TYPE_APPLICATION,
  382. &(((PAZP_APPLICATION)ApplicationHandle)->Operations),
  383. OBJECT_TYPE_OPERATION,
  384. OperationName,
  385. Reserved );
  386. }