1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** USBX Component */
16 /** */
17 /** Host Stack */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22
23 /* Include necessary system files. */
24
25 #define UX_SOURCE_CODE
26
27 #include "ux_api.h"
28 #include "ux_host_stack.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _ux_host_stack_class_instance_destroy PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function destroys a class instance for a class container. */
44 /* */
45 /* INPUT */
46 /* */
47 /* class Pointer to class */
48 /* class_instance Pointer to class instance */
49 /* */
50 /* OUTPUT */
51 /* */
52 /* Completion Status */
53 /* */
54 /* CALLS */
55 /* */
56 /* None */
57 /* */
58 /* CALLED BY */
59 /* */
60 /* Application */
61 /* USBX Components */
62 /* */
63 /* RELEASE HISTORY */
64 /* */
65 /* DATE NAME DESCRIPTION */
66 /* */
67 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
68 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
69 /* resulting in version 6.1 */
70 /* */
71 /**************************************************************************/
_ux_host_stack_class_instance_destroy(UX_HOST_CLASS * host_class,VOID * class_instance)72 UINT _ux_host_stack_class_instance_destroy(UX_HOST_CLASS *host_class, VOID *class_instance)
73 {
74
75 VOID **current_class_instance;
76 VOID **next_class_instance;
77
78 /* If trace is enabled, insert this event into the trace buffer. */
79 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_CLASS_INSTANCE_DESTROY, host_class, class_instance, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
80
81 /* If trace is enabled, register this object. */
82 UX_TRACE_OBJECT_UNREGISTER(class_instance);
83
84 /* Get the pointer to the instance pointed by the instance to destroy. */
85 next_class_instance = class_instance;
86 next_class_instance = *next_class_instance;
87
88 /* Start with the first class instance attached to the class container. */
89 current_class_instance = host_class -> ux_host_class_first_instance;
90
91 /* Check if there are any instances attached. */
92 if (current_class_instance == UX_NULL)
93 {
94
95 /* Error trap. */
96 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_HOST_CLASS_INSTANCE_UNKNOWN);
97
98 /* If trace is enabled, insert this event into the trace buffer. */
99 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, class_instance, 0, 0, UX_TRACE_ERRORS, 0, 0)
100
101 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
102 }
103
104 /* The first instance is a special case because it is attached to the class
105 container. */
106 if (current_class_instance == class_instance)
107 {
108
109 /* Point to next class instance. */
110 host_class -> ux_host_class_first_instance = next_class_instance;
111
112 /* Return success. */
113 return(UX_SUCCESS);
114 }
115
116 /* Traverse the list of the class instances until we found the right one. */
117 while (*current_class_instance != UX_NULL)
118 {
119
120 /* Check to see if this class is the one we need to destroy. */
121 if(*current_class_instance == class_instance)
122 {
123
124 /* Point to next class instance. */
125 *current_class_instance = next_class_instance;
126
127 /* Return success. */
128 return(UX_SUCCESS);
129 }
130
131 /* Points to the next class instance. */
132 current_class_instance = *current_class_instance;
133 }
134
135 /* Error trap. */
136 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_HOST_CLASS_INSTANCE_UNKNOWN);
137
138 /* If trace is enabled, insert this event into the trace buffer. */
139 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, class_instance, 0, 0, UX_TRACE_ERRORS, 0, 0)
140
141 /* Return error to caller. */
142 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
143 }
144
145