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 /**   Pictbridge Application                                              */
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_pictbridge.h"
29 #include "ux_device_class_pima.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_pictbridge_dpsclient_api_capability             PORTABLE C      */
37 /*                                                           6.1.12       */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function creates the tag lines of the configure_print_service  */
45 /*    request and then output the request to the printer.                 */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    pictbridge                            Pictbridge instance           */
50 /*    capability_code                       What capability to get        */
51 /*    capability_parameter                  Optional parameter            */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    Completion Status                                                   */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _ux_utility_delay_ms                  Delay ms                      */
60 /*    _ux_pictbridge_dps_client_input_object_prepare                      */
61 /*    _ux_system_event_flags_get                                         */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    _ux_pictbridge_dpshost_object_get                                   */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
72 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
73 /*                                            used UX prefix to refer to  */
74 /*                                            TX symbols instead of using */
75 /*                                            them directly,              */
76 /*                                            resulting in version 6.1    */
77 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
78 /*                                            used macros for RTOS calls, */
79 /*                                            resulting in version 6.1.12 */
80 /*                                                                        */
81 /**************************************************************************/
_ux_pictbridge_dpsclient_api_capability(UX_PICTBRIDGE * pictbridge,ULONG capability_code,ULONG capability_parameter)82 UINT _ux_pictbridge_dpsclient_api_capability(UX_PICTBRIDGE *pictbridge, ULONG capability_code,
83                                              ULONG capability_parameter)
84 {
85 UINT                                status;
86 ULONG                               actual_flags;
87 
88     /* Wait for 100 ms to give a chance to the host to send a request before the client can post a Object Added event.  */
89     _ux_utility_delay_ms(100);
90 
91     /* Prepare the object for capability. */
92     status = _ux_pictbridge_dpsclient_input_object_prepare(pictbridge, UX_PICTBRIDGE_OR_GET_CAPABILITY,
93                                                             capability_code, capability_parameter);
94 
95     /* Check status.  */
96     if (status != UX_SUCCESS)
97         return(status);
98 
99     /* We should wait for the host to send a script with the response.  */
100     status =  _ux_system_event_flags_get(&pictbridge -> ux_pictbridge_event_flags_group, UX_PICTBRIDGE_EVENT_FLAG_CAPABILITY,
101                                         UX_AND_CLEAR, &actual_flags, UX_PICTBRIDGE_EVENT_TIMEOUT);
102 
103     /* Check status.  */
104     if (status != UX_SUCCESS)
105         return(UX_EVENT_ERROR);
106 
107     /* Ensure the flag was set.  */
108     if (actual_flags & UX_PICTBRIDGE_EVENT_FLAG_CAPABILITY)
109 
110         /* Return completion status.  */
111         return(UX_SUCCESS);
112 
113     else
114 
115         /* Return completion status.  */
116         return(UX_ERROR);
117 }
118 
119