summaryrefslogtreecommitdiff
path: root/common/usbx_pictbridge/src/ux_pictbridge_dpsclient_object_info_send.c
blob: 45a67f1654b290cfdbf626de5efdfaf667e88c18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2026-present Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** USBX Component                                                        */
/**                                                                       */
/**   Pictbridge Application                                              */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/


/* Include necessary system files.  */

#define UX_SOURCE_CODE

#include "ux_api.h"
#include "ux_pictbridge.h"
#include "ux_device_class_pima.h"


/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _ux_pictbridge_dpsclient_object_info_send           PORTABLE C      */
/*                                                           6.1.12       */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Chaoqiong Xiao, Microsoft Corporation                               */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    Receive the info data set of a new object to be stored.             */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    pima                                   Pima instance associated     */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    Completion Status                                                   */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    user application                                                    */
/*                                                                        */
/**************************************************************************/
UINT  _ux_pictbridge_dpsclient_object_info_send(UX_SLAVE_CLASS_PIMA *pima, UX_SLAVE_CLASS_PIMA_OBJECT *object,
                                                ULONG storage_id,
                                                ULONG parent_object_handle,
                                                ULONG *object_handle)
{
UX_PICTBRIDGE                   *pictbridge;
UX_SLAVE_CLASS_PIMA_OBJECT      *object_info;
UCHAR                           string_discovery_name[UX_PICTBRIDGE_MAX_FILE_NAME_SIZE + 1]; /* +1 for null-terminator */
UINT                            length, length1;

    UX_PARAMETER_NOT_USED(storage_id);
    UX_PARAMETER_NOT_USED(parent_object_handle);

    /* Get the pointer to the Pictbridge instance.  */
    pictbridge = (UX_PICTBRIDGE *)pima -> ux_device_class_pima_application;

    /* We only have one object.  */
    object_info = (UX_SLAVE_CLASS_PIMA_OBJECT *) pictbridge -> ux_pictbridge_object_host;

     /* Copy the demanded object info set.  */
    _ux_utility_memory_copy(object_info, object, UX_SLAVE_CLASS_PIMA_OBJECT_DATA_LENGTH); /* Use case of memcpy is verified. */

    /* Store the object handle.  In Pictbridge we only receive XML scripts so the handle is hardwired to 1.  */
    object_info -> ux_device_class_pima_object_handle_id = 1;
    *object_handle =  1;

    /* Check state machine. If we are in discovery pending mode, check file name of this object.  */
    if (pictbridge -> ux_pictbridge_discovery_state == UX_PICTBRIDGE_DPSCLIENT_DISCOVERY_PENDING)
    {

        /* We are in the discovery mode. Check for file name. It must match HDISCVRY.DPS in Unicode mode.  */
        /* Check if this is a script.  */
        if (object_info -> ux_device_class_pima_object_format == UX_DEVICE_CLASS_PIMA_OFC_SCRIPT)
        {

            /* Yes this is a script. We need to search for the HDISCVRY.DPS file name.
               Get the file name length (with null-terminator).  */
            length1 = (UINT)(*object_info -> ux_device_class_pima_object_filename);

            /* Now, compare it to the HDISCVRY.DPS file name.  Check length first.  */
            if (length1 <= UX_PICTBRIDGE_MAX_FILE_NAME_SIZE)
            {

                /* Invalidate length, on error it's untouched.  */
                length = UX_PICTBRIDGE_MAX_FILE_NAME_SIZE + 1;
                _ux_utility_string_length_check(_ux_pictbridge_hdiscovery_name, &length, UX_PICTBRIDGE_MAX_FILE_NAME_SIZE);
                if ((length + 1) == length1)
                {

                    /* Get the file name in a ascii format (with null-terminator). */
                    _ux_utility_unicode_to_string(object_info -> ux_device_class_pima_object_filename, string_discovery_name);

                    /* So far, the length of name of the files are the same.
                    Compare names now (since length is same just compare without null-terminator). */
                    if (_ux_utility_memory_compare(_ux_pictbridge_hdiscovery_name, string_discovery_name,
                                                    length) ==  UX_SUCCESS)
                    {

                        /* We are done with discovery of the printer. We can now send notifications when the camera wants to print an object.  */
                        pictbridge -> ux_pictbridge_discovery_state = UX_PICTBRIDGE_DPSCLIENT_DISCOVERY_COMPLETE;

                        /* Set an event flag if the application is listening.  */
                        _ux_system_event_flags_set(&pictbridge -> ux_pictbridge_event_flags_group, UX_PICTBRIDGE_EVENT_FLAG_DISCOVERY, UX_OR);

                        /* There is no object during the discovery cycle.  */
                        return(UX_SUCCESS);
                    }
                }
            }
        }
    }

    /* What cycle are we in ? */
    if (pictbridge -> ux_pictbridge_host_client_state_machine == UX_PICTBRIDGE_STATE_MACHINE_IDLE)

        /* Since we are in idle state, we must have received a request from the host.  */
        pictbridge -> ux_pictbridge_host_client_state_machine = UX_PICTBRIDGE_STATE_MACHINE_HOST_REQUEST;


    /* We have copied the requested data. Return OK.  */
    return(UX_SUCCESS);
}