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