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_input_start_job                            */
38 /*                                                        PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Chaoqiong Xiao, Microsoft Corporation                               */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function creates the tag lines of the start job                */
47 /*    request.                                                            */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    pictbridge                            Pictbridge instance           */
52 /*    pima_object_buffer                    Pointer to object buffer      */
53 /*    object_length                         Length of the object          */
54 /*    pima_object_buffer_updated            Updated Address of the object */
55 /*    object_length_updated                 Updated length                */
56 /*                                                                        */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    Completion Status                                                   */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    _ux_pictbridge_dpsclient_input_object_prepare                       */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
74 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_ux_pictbridge_dpsclient_input_object_startjob(UX_PICTBRIDGE * pictbridge,ULONG input_subcode,ULONG input_parameter,UCHAR * pima_object_buffer,ULONG object_length,UCHAR ** pima_object_buffer_updated,ULONG * object_length_updated)78 UINT _ux_pictbridge_dpsclient_input_object_startjob(UX_PICTBRIDGE *pictbridge,
79                             ULONG input_subcode,
80                             ULONG input_parameter,
81                             UCHAR *pima_object_buffer,
82                             ULONG object_length,
83                             UCHAR **pima_object_buffer_updated,
84                             ULONG *object_length_updated)
85 {
86 
87 UINT                        status;
88 UX_PICTBRIDGE_JOBINFO       *jobinfo;
89 UX_PICTBRIDGE_PRINTINFO     *printinfo;
90 
91     UX_PARAMETER_NOT_USED(input_subcode);
92     UX_PARAMETER_NOT_USED(input_parameter);
93 
94     /* We can start a new job. Fill in the JobConfig and PrintInfo structures. */
95     jobinfo = &pictbridge -> ux_pictbridge_jobinfo;
96     printinfo = jobinfo -> ux_pictbridge_jobinfo_printinfo_start;
97 
98     /* Add the line <startJob>  */
99     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_startjob,
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 <jobConfig>  */
106     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_jobconfig,
107                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_LF,
108                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
109     if (status != UX_SUCCESS)
110         return(status);
111 
112     /* Add the line <quality> xxxxxxxx </quality> */
113     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_quality,
114                                             UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_END | UX_PICTBRIDGE_TAG_FLAG_VARIABLE_HEXA,
115                                             UX_NULL, 0, (VOID *)(ALIGN_TYPE) jobinfo -> ux_pictbridge_jobinfo_quality, &pima_object_buffer, &object_length);
116     if (status != UX_SUCCESS)
117         return(status);
118 
119     /* Add the line <paperType> xxxxxxxx </paperType> */
120     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_papertype,
121                                             UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_END | UX_PICTBRIDGE_TAG_FLAG_VARIABLE_HEXA,
122                                             UX_NULL, 0, (VOID *)(ALIGN_TYPE) jobinfo -> ux_pictbridge_jobinfo_papertype, &pima_object_buffer, &object_length);
123     if (status != UX_SUCCESS)
124         return(status);
125 
126     /* Add the line <paperSize> xxxxxxxx </paperSize> */
127     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_papersize,
128                                             UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_END | UX_PICTBRIDGE_TAG_FLAG_VARIABLE_HEXA,
129                                             UX_NULL, 0, (VOID *)(ALIGN_TYPE) jobinfo -> ux_pictbridge_jobinfo_papersize, &pima_object_buffer, &object_length);
130     if (status != UX_SUCCESS)
131         return(status);
132 
133     /* Add the line <fileType> xxxxxxxx </fileType> */
134     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_filetype,
135                                             UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_END | UX_PICTBRIDGE_TAG_FLAG_VARIABLE_HEXA,
136                                             UX_NULL, 0, (VOID *)(ALIGN_TYPE) jobinfo -> ux_pictbridge_jobinfo_filetype, &pima_object_buffer, &object_length);
137     if (status != UX_SUCCESS)
138         return(status);
139 
140     /* Add the line <datePrint> xxxxxxxx </datePrint> */
141     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_dateprint,
142                                             UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_END | UX_PICTBRIDGE_TAG_FLAG_VARIABLE_HEXA,
143                                             UX_NULL, 0, (VOID *)(ALIGN_TYPE) jobinfo -> ux_pictbridge_jobinfo_dateprint, &pima_object_buffer, &object_length);
144     if (status != UX_SUCCESS)
145         return(status);
146 
147     /* Add the line <fileNamePrint> xxxxxxxx </fileNamePrint> */
148     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_filenameprint,
149                                             UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_END | UX_PICTBRIDGE_TAG_FLAG_VARIABLE_HEXA,
150                                             UX_NULL, 0, (VOID *)(ALIGN_TYPE) jobinfo -> ux_pictbridge_jobinfo_filenameprint, &pima_object_buffer, &object_length);
151     if (status != UX_SUCCESS)
152         return(status);
153 
154     /* Add the line <imageOptimize> xxxxxxxx </imageOptimize> */
155     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_imageoptimize,
156                                             UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_END | UX_PICTBRIDGE_TAG_FLAG_VARIABLE_HEXA,
157                                             UX_NULL, 0, (VOID *)(ALIGN_TYPE) jobinfo -> ux_pictbridge_jobinfo_imageoptimize, &pima_object_buffer, &object_length);
158     if (status != UX_SUCCESS)
159         return(status);
160 
161     /* Add the line <layout> xxxxxxxx </layout> */
162     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_layout,
163                                             UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_END | UX_PICTBRIDGE_TAG_FLAG_VARIABLE_HEXA,
164                                             UX_NULL, 0, (VOID *)(ALIGN_TYPE) jobinfo -> ux_pictbridge_jobinfo_layout, &pima_object_buffer, &object_length);
165     if (status != UX_SUCCESS)
166         return(status);
167 
168     /* Add the line </jobConfig>  */
169     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_jobconfig,
170                                                 UX_PICTBRIDGE_TAG_FLAG_END,
171                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
172     if (status != UX_SUCCESS)
173         return(status);
174 
175     /* Add all the printInfo.  */
176     while (printinfo != UX_NULL)
177     {
178 
179         /* Add the line <printInfo>  */
180         status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_printinfo,
181                                                     UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_LF,
182                                                     UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
183         if (status != UX_SUCCESS)
184             return(status);
185 
186         /* Add the line <fileID> xxxxxxxx </fileID> */
187         status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_fileid,
188                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_END | UX_PICTBRIDGE_TAG_FLAG_VARIABLE_HEXA,
189                                                 UX_NULL, 0, (VOID *)(ALIGN_TYPE) printinfo -> ux_pictbridge_printinfo_fileid,
190                                                 &pima_object_buffer, &object_length);
191         if (status != UX_SUCCESS)
192             return(status);
193 
194         /* Check if there is filename string.  */
195         if (printinfo -> ux_pictbridge_printinfo_filename[0] != '\0')
196         {
197 
198             /* Add the line <fileName> xxxxxxxx </fileName> */
199             status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_filename,
200                                                     UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_END | UX_PICTBRIDGE_TAG_FLAG_VARIABLE_STRING,
201                                                     UX_NULL, 0, (VOID *) printinfo -> ux_pictbridge_printinfo_filename,
202                                                     &pima_object_buffer, &object_length);
203             if (status != UX_SUCCESS)
204                 return(status);
205         }
206 
207         /* Check if there is date string.  */
208         if (printinfo -> ux_pictbridge_printinfo_date[0] != '\0')
209         {
210 
211             /* Add the line <date> xxxxxxxx </date> */
212             status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_date,
213                                                     UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_END | UX_PICTBRIDGE_TAG_FLAG_VARIABLE_STRING,
214                                                     UX_NULL, 0, (VOID *) printinfo -> ux_pictbridge_printinfo_date,
215                                                     &pima_object_buffer, &object_length);
216             if (status != UX_SUCCESS)
217                 return(status);
218         }
219 
220         /* Add the line </printInfo>  */
221         status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_printinfo,
222                                                     UX_PICTBRIDGE_TAG_FLAG_END,
223                                                     UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
224         if (status != UX_SUCCESS)
225             return(status);
226 
227         /* Go to next print info.  */
228         printinfo = printinfo -> ux_pictbridge_printinfo_next;
229     }
230 
231     /* Add the line </startJob>  */
232     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_startjob,
233                                                 UX_PICTBRIDGE_TAG_FLAG_END,
234                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
235     if (status != UX_SUCCESS)
236         return(status);
237 
238     /* Update the caller's object position.  */
239     *pima_object_buffer_updated = pima_object_buffer;
240 
241     /* Update the caller's object length .  */
242     *object_length_updated = object_length;
243 
244     /* Return completion status.  */
245     return(UX_SUCCESS);
246 }
247 
248