1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** USBX Component */
17 /** */
18 /** Pictbridge Application */
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_pictbridge.h"
30 #include "ux_device_class_pima.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_pictbridge_dpsclient_object_data_get PORTABLE C */
38 /* 6.1.12 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function returns the data of the object. */
46 /* */
47 /* INPUT */
48 /* */
49 /* pima Pima instance associated */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* Completion Status */
54 /* */
55 /* CALLS */
56 /* */
57 /* */
58 /* CALLED BY */
59 /* */
60 /* user application */
61 /* */
62 /* RELEASE HISTORY */
63 /* */
64 /* DATE NAME DESCRIPTION */
65 /* */
66 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
67 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
68 /* verified memset and memcpy */
69 /* cases, used UX prefix to */
70 /* refer to TX symbols instead */
71 /* of using them directly, */
72 /* resulting in version 6.1 */
73 /* 04-25-2022 Yajun Xia Modified comment(s), */
74 /* internal clean up, */
75 /* resulting in version 6.1.11 */
76 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
77 /* used macros for RTOS calls, */
78 /* resulting in version 6.1.12 */
79 /* */
80 /**************************************************************************/
_ux_pictbridge_dpsclient_object_data_get(UX_SLAVE_CLASS_PIMA * pima,ULONG object_handle,UCHAR * object_buffer,ULONG object_offset,ULONG object_length_requested,ULONG * object_actual_length)81 UINT _ux_pictbridge_dpsclient_object_data_get(UX_SLAVE_CLASS_PIMA *pima, ULONG object_handle, UCHAR *object_buffer, ULONG object_offset,
82 ULONG object_length_requested, ULONG *object_actual_length)
83 {
84 UX_PICTBRIDGE *pictbridge;
85 UX_SLAVE_CLASS_PIMA_OBJECT *object_info;
86 UCHAR *pima_object_buffer;
87 ULONG actual_length;
88 UINT status;
89
90 /* Get the pointer to the Pictbridge instance. */
91 pictbridge = (UX_PICTBRIDGE *)pima -> ux_device_class_pima_application;
92
93 /* Check the object handle. If this is handle 1 or 2 , we need to return the XML script object.
94 If the handle is not 1 or 2, this is a JPEG picture or other object to be printed. */
95 if ((object_handle == UX_PICTBRIDGE_OBJECT_HANDLE_HOST_RESPONSE) || (object_handle == UX_PICTBRIDGE_OBJECT_HANDLE_CLIENT_REQUEST))
96 {
97
98 /* Check what XML object is requested. It is either a request script or a response. */
99 if (object_handle == UX_PICTBRIDGE_OBJECT_HANDLE_HOST_RESPONSE)
100 object_info = (UX_SLAVE_CLASS_PIMA_OBJECT *) pictbridge -> ux_pictbridge_object_host;
101 else
102 object_info = (UX_SLAVE_CLASS_PIMA_OBJECT *) pictbridge -> ux_pictbridge_object_client;
103
104 /* Is this the correct handle ? */
105 if (object_info -> ux_device_class_pima_object_handle_id == object_handle)
106 {
107
108 /* Get the pointer to the object buffer. */
109 pima_object_buffer = object_info -> ux_device_class_pima_object_buffer;
110
111 /* Copy the demanded object data portion. */
112 _ux_utility_memory_copy(object_buffer, pima_object_buffer + object_offset, object_length_requested); /* Use case of memcpy is verified. */
113
114 /* Update the length requested. for a demo, we do not do any checking. */
115 *object_actual_length = object_length_requested;
116
117 /* What cycle are we in ? */
118 if (pictbridge -> ux_pictbridge_host_client_state_machine & UX_PICTBRIDGE_STATE_MACHINE_HOST_REQUEST)
119 {
120 /* Check if we are blocking for a client request. */
121 if (pictbridge -> ux_pictbridge_host_client_state_machine & UX_PICTBRIDGE_STATE_MACHINE_CLIENT_REQUEST_PENDING)
122
123 /* Yes we are pending, send an event to release the pending request. */
124 _ux_system_event_flags_set(&pictbridge -> ux_pictbridge_event_flags_group, UX_PICTBRIDGE_EVENT_FLAG_STATE_MACHINE_READY, UX_OR);
125
126 /* Since we are in host request, this indicates we are done with the cycle. */
127 pictbridge -> ux_pictbridge_host_client_state_machine = UX_PICTBRIDGE_STATE_MACHINE_IDLE;
128
129 }
130
131 /* We have copied the requested data. Return OK. */
132 return(UX_SUCCESS);
133 }
134 }
135 else
136 {
137
138 /* Obtain the data from the application jobinfo callback. */
139 status = pictbridge -> ux_pictbridge_jobinfo.ux_pictbridge_jobinfo_object_data_read(pictbridge, object_handle, object_buffer, object_offset,
140 object_length_requested, &actual_length);
141
142 /* Save the length returned. */
143 *object_actual_length = actual_length;
144
145 /* Return the application status. */
146 return(status);
147
148 }
149 /* Could not find the handle. */
150 return(UX_DEVICE_CLASS_PIMA_RC_INVALID_OBJECT_HANDLE);
151 }
152
153