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_get PORTABLE C */ |
36 |
|
|
/* 6.1 */ |
37 |
|
|
/* AUTHOR */ |
38 |
|
|
/* */ |
39 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
40 |
|
|
/* */ |
41 |
|
|
/* DESCRIPTION */ |
42 |
|
|
/* */ |
43 |
|
|
/* This function returns a class instance pointer for a specific */ |
44 |
|
|
/* class. The instance of a class is not contained in the class code */ |
45 |
|
|
/* to reduce the class complexity. Rather, each class instance is */ |
46 |
|
|
/* attached to class container. */ |
47 |
|
|
/* */ |
48 |
|
|
/* INPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* class Pointer to class */ |
51 |
|
|
/* class_index Index of class */ |
52 |
|
|
/* class_instance Destination of class instance */ |
53 |
|
|
/* pointer */ |
54 |
|
|
/* */ |
55 |
|
|
/* OUTPUT */ |
56 |
|
|
/* */ |
57 |
|
|
/* Completion Status */ |
58 |
|
|
/* */ |
59 |
|
|
/* CALLS */ |
60 |
|
|
/* */ |
61 |
|
|
/* None */ |
62 |
|
|
/* */ |
63 |
|
|
/* CALLED BY */ |
64 |
|
|
/* */ |
65 |
|
|
/* Application */ |
66 |
|
|
/* USBX Components */ |
67 |
|
|
/* */ |
68 |
|
|
/* RELEASE HISTORY */ |
69 |
|
|
/* */ |
70 |
|
|
/* DATE NAME DESCRIPTION */ |
71 |
|
|
/* */ |
72 |
|
|
/* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ |
73 |
|
|
/* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ |
74 |
|
|
/* resulting in version 6.1 */ |
75 |
|
|
/* */ |
76 |
|
|
/**************************************************************************/ |
77 |
|
12081070 |
UINT _ux_host_stack_class_instance_get(UX_HOST_CLASS *host_class, UINT class_index, VOID **class_instance) |
78 |
|
|
{ |
79 |
|
|
|
80 |
|
|
VOID **current_class_instance; |
81 |
|
|
|
82 |
|
|
|
83 |
|
|
/* Start with the first class instance attached to the class container. */ |
84 |
|
12081070 |
current_class_instance = host_class -> ux_host_class_first_instance; |
85 |
|
|
|
86 |
|
|
/* Check if there are any instances attached. */ |
87 |
✓✓ |
12081070 |
if(current_class_instance == UX_NULL) |
88 |
|
|
{ |
89 |
|
|
|
90 |
|
12077093 |
return(UX_HOST_CLASS_INSTANCE_UNKNOWN); |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
/* Traverse the list of the class instances until we found the right one. */ |
94 |
✓✓ |
3998 |
while (class_index-- != 0) |
95 |
|
|
{ |
96 |
|
|
|
97 |
|
|
/* Points to the next class instance. */ |
98 |
|
900 |
current_class_instance = *current_class_instance; |
99 |
|
|
|
100 |
|
|
/* Check if we have reached the end of the list of the class instances. */ |
101 |
✓✓ |
900 |
if (current_class_instance == UX_NULL) |
102 |
|
|
{ |
103 |
|
|
|
104 |
|
879 |
return(UX_HOST_CLASS_INSTANCE_UNKNOWN); |
105 |
|
|
} |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
/* Update the class instance pointer from the caller. */ |
109 |
|
3098 |
*class_instance = current_class_instance; |
110 |
|
|
|
111 |
|
|
/* Return successful completion. */ |
112 |
|
3098 |
return(UX_SUCCESS); |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
|
116 |
|
|
/**************************************************************************/ |
117 |
|
|
/* */ |
118 |
|
|
/* FUNCTION RELEASE */ |
119 |
|
|
/* */ |
120 |
|
|
/* _uxe_host_stack_class_instance_get PORTABLE C */ |
121 |
|
|
/* 6.3.0 */ |
122 |
|
|
/* AUTHOR */ |
123 |
|
|
/* */ |
124 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
125 |
|
|
/* */ |
126 |
|
|
/* DESCRIPTION */ |
127 |
|
|
/* */ |
128 |
|
|
/* This function checks errors in host stack class get function call. */ |
129 |
|
|
/* */ |
130 |
|
|
/* INPUT */ |
131 |
|
|
/* */ |
132 |
|
|
/* class Pointer to class */ |
133 |
|
|
/* class_index Index of class */ |
134 |
|
|
/* class_instance Destination of class instance */ |
135 |
|
|
/* pointer */ |
136 |
|
|
/* */ |
137 |
|
|
/* OUTPUT */ |
138 |
|
|
/* */ |
139 |
|
|
/* None */ |
140 |
|
|
/* */ |
141 |
|
|
/* CALLS */ |
142 |
|
|
/* */ |
143 |
|
|
/* _ux_host_stack_class_instance_get Host stack class instance get */ |
144 |
|
|
/* */ |
145 |
|
|
/* CALLED BY */ |
146 |
|
|
/* */ |
147 |
|
|
/* Application */ |
148 |
|
|
/* */ |
149 |
|
|
/* RELEASE HISTORY */ |
150 |
|
|
/* */ |
151 |
|
|
/* DATE NAME DESCRIPTION */ |
152 |
|
|
/* */ |
153 |
|
|
/* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ |
154 |
|
|
/* */ |
155 |
|
|
/**************************************************************************/ |
156 |
|
|
UINT _uxe_host_stack_class_instance_get(UX_HOST_CLASS *host_class, UINT class_index, VOID **class_instance) |
157 |
|
|
{ |
158 |
|
|
|
159 |
|
|
/* Sanity check. */ |
160 |
|
|
if ((host_class == UX_NULL) || (class_instance == UX_NULL)) |
161 |
|
|
return(UX_INVALID_PARAMETER); |
162 |
|
|
|
163 |
|
|
/* Invoke class instance get function. */ |
164 |
|
|
return(_ux_host_stack_class_instance_get(host_class, class_index, class_instance)); |
165 |
|
|
} |