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_host_class_pima.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _ux_pictbridge_dpshost_input_object_notify_job_status               */
38 /*                                                        PORTABLE C      */
39 /*                                                           6.1.11       */
40 /*                                                                        */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    Chaoqiong Xiao, Microsoft Corporation                               */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This function creates the tag lines of the input object for the     */
48 /*    notification of the job status.                                     */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    pictbridge                            Pictbridge instance           */
53 /*    pima_object_buffer                    Pointer to object buffer      */
54 /*    object_length                         Length of the object          */
55 /*    pima_object_buffer_updated            Updated Address of the object */
56 /*    object_length_updated                 Updated length                */
57 /*                                                                        */
58 /*                                                                        */
59 /*  OUTPUT                                                                */
60 /*                                                                        */
61 /*    Completion Status                                                   */
62 /*                                                                        */
63 /*  CALLS                                                                 */
64 /*                                        _device_status                  */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*                                                                        */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
75 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
76 /*                                            resulting in version 6.1    */
77 /*  04-25-2022     Yajun Xia                Modified comment(s),          */
78 /*                                            internal clean up,          */
79 /*                                            resulting in version 6.1.11 */
80 /*                                                                        */
81 /**************************************************************************/
_ux_pictbridge_dpshost_input_object_notify_job_status(UX_PICTBRIDGE * pictbridge,UCHAR * pima_object_buffer,ULONG object_length,UCHAR ** pima_object_buffer_updated,ULONG * object_length_updated)82 UINT _ux_pictbridge_dpshost_input_object_notify_job_status(UX_PICTBRIDGE *pictbridge,
83                                                  UCHAR *pima_object_buffer,
84                                                  ULONG object_length,
85                                                  UCHAR **pima_object_buffer_updated,
86                                                  ULONG *object_length_updated)
87 {
88 UX_PICTBRIDGE_JOBINFO               *jobinfo;
89 UX_PICTBRIDGE_PRINTINFO             *printinfo;
90 UINT                                 status = UX_SUCCESS;
91 
92     /* Get the jobinfo structure pointer.  */
93     jobinfo = &pictbridge -> ux_pictbridge_jobinfo;
94 
95     /* Get the current printinfo structure.  */
96     printinfo =  jobinfo -> ux_pictbridge_jobinfo_printinfo_current;
97 
98     /* Add the line <notifyJobStatus>  */
99     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_notifyjobstatus,
100                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_LF,
101                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
102     if (status != UX_SUCCESS)
103         return(status);
104 
105     /* Add the line <progress>  */
106     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_progress,
107                                                     UX_PICTBRIDGE_TAG_FLAG_BEGIN,
108                                                     UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
109     if (status != UX_SUCCESS)
110         return(status);
111 
112     /* Insert 001/001 from current page/total pages in the current printjob.  */
113 
114     /* Check length to go.  */
115     object_length += 7;
116     if (object_length > UX_PICTBRIDGE_MAX_PIMA_OBJECT_BUFFER)
117     {
118         status = UX_MEMORY_INSUFFICIENT;
119         return (status);
120     }
121 
122     /* Insert xxx decimal.  */
123     status = _ux_pictbridge_hexa_to_decimal_string(printinfo -> ux_pictbridge_printinfo_current_page, pima_object_buffer, UX_PICTBRIDGE_LEADING_ZERO_ON, 3);
124     if (status != UX_SUCCESS)
125         return(status);
126 
127     /* Update the address of the destination.  */
128     pima_object_buffer += 3;
129 
130     /* Insert the '/' between both pages.  */
131     *pima_object_buffer++ = '/';
132 
133     /* Insert the decimal value of total pages.  */
134     status = _ux_pictbridge_hexa_to_decimal_string(printinfo -> ux_pictbridge_printinfo_total_page, pima_object_buffer, UX_PICTBRIDGE_LEADING_ZERO_ON, 3);
135     if (status != UX_SUCCESS)
136         return(status);
137 
138     /* Update the address.  */
139     pima_object_buffer += 3;
140 
141     /* Add the line </progress>  */
142     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_progress,
143                                                 UX_PICTBRIDGE_TAG_FLAG_END,
144                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
145     if (status != UX_SUCCESS)
146         return(status);
147 
148     /* Add the line <imagesPrinted> xxxxxxxx </imagesPrinted> */
149     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_imagesprinted,
150                                             UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_END | UX_PICTBRIDGE_TAG_FLAG_VARIABLE_DECIMAL_3DIGITS,
151                                             UX_NULL, 0, (VOID *)(ALIGN_TYPE) printinfo -> ux_pictbridge_printinfo_images_printed, &pima_object_buffer, &object_length);
152     if (status != UX_SUCCESS)
153         return(status);
154 
155     /* Add the line </notifyJobStatus>  */
156     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_notifyjobstatus,
157                                                 UX_PICTBRIDGE_TAG_FLAG_END,
158                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
159     if (status != UX_SUCCESS)
160         return(status);
161 
162     /* Update the caller's object position.  */
163     *pima_object_buffer_updated = pima_object_buffer;
164 
165     /* Update the caller's object length .  */
166     *object_length_updated = object_length;
167 
168     /* Return completion status.  */
169     return(UX_SUCCESS);
170 }
171 
172