GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_host_stack_class_instance_get.c Lines: 10 14 71.4 %
Date: 2026-03-06 18:57:10 Branches: 6 10 60.0 %

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