OpenCores
URL https://opencores.org/ocsvn/funbase_ip_library/funbase_ip_library/trunk

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.swp.api/] [openmcapi/] [1.0/] [libmcapi/] [mcapi/] [mcapi_cancel.c] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
/*
2
 * Copyright (c) 2010, Mentor Graphics Corporation
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 *    this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
11
 *    this list of conditions and the following disclaimer in the documentation
12
 *    and/or other materials provided with the distribution.
13
 * 3. Neither the name of the <ORGANIZATION> nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
 * POSSIBILITY OF SUCH DAMAGE.
28
 */
29
 
30
 
31
 
32
#include <openmcapi.h>
33
 
34
/*************************************************************************
35
*
36
*   FUNCTION
37
*
38
*       mcapi_cancel
39
*
40
*   DESCRIPTION
41
*
42
*       Blocking API routine to cancel an outstanding non-blocking
43
*       operation.  Any pending calls to mcapi_wait() or mcapi_wait_any()
44
*       for the specific operation will also be canceled.
45
*
46
*   INPUTS
47
*
48
*       *request                A pointer to the request structure filled
49
*                               in by the specific operation being canceled.
50
*       *mcapi_status           A pointer to memory that will be filled in
51
*                               with the status of the call.
52
*
53
*   OUTPUTS
54
*
55
*       None.
56
*
57
*************************************************************************/
58
void mcapi_cancel(mcapi_request_t *request, mcapi_status_t *mcapi_status)
59
{
60
    mcapi_request_t     *req_ptr;
61
    MCAPI_GLOBAL_DATA   *node_data;
62
    MCAPI_ENDPOINT      *endp_ptr;
63
    mcapi_port_t        port_id;
64
    mcapi_node_t        node_id;
65
    mcapi_status_t      local_status;
66
 
67
    /* Validate the mcapi_status input parameter. */
68
    if (mcapi_status)
69
    {
70
        /* Validate request. */
71
        if (request)
72
        {
73
            /* Get the lock. */
74
            mcapi_lock_node_data();
75
 
76
            /* Get a pointer to the global node list. */
77
            node_data = mcapi_get_node_data();
78
 
79
            /* Get a pointer to a request structure matching this one. */
80
            req_ptr =
81
                mcapi_find_request(request, &node_data->mcapi_local_req_queue);
82
 
83
            /* At least one request was found. */
84
            if (req_ptr)
85
            {
86
                *mcapi_status = MCAPI_SUCCESS;
87
 
88
                /* There could be other tasks suspended on the same request.
89
                 * Find each one and resume.
90
                 */
91
                while (req_ptr)
92
                {
93
                    /* If the status is pending, cancel the operation. */
94
                    if (req_ptr->mcapi_status == MCAPI_PENDING)
95
                    {
96
                        /* If this is a get endpoint request for a foreign
97
                         * endpoint.
98
                         */
99
                        if ( (req_ptr->mcapi_type == MCAPI_REQ_CREATED) &&
100
                             (req_ptr->mcapi_target_node_id != MCAPI_Node_ID) )
101
                        {
102
                            /* Set the status to canceled. */
103
                            req_ptr->mcapi_status = MCAPI_ERR_REQUEST_CANCELLED;
104
 
105
                            /* Cancel the outstanding operation. */
106
                            mcapi_tx_response(node_data, req_ptr);
107
                        }
108
 
109
                        else
110
                        {
111
                            switch (req_ptr->mcapi_type)
112
                            {
113
                                /* Cancel the attempt at opening the receive / send
114
                                 * side of the connection.
115
                                 */
116
                                case MCAPI_REQ_RX_OPEN:
117
                                case MCAPI_REQ_TX_OPEN:
118
 
119
                                    /* Get a pointer to the local endpoint. */
120
                                    endp_ptr =
121
                                        mcapi_decode_local_endpoint(node_data, &node_id,
122
                                                                    &port_id,
123
                                                                    request->mcapi_target_endp,
124
                                                                    &local_status);
125
 
126
                                    if (endp_ptr)
127
                                    {
128
                                        /* Set the disconnected flag. */
129
                                        endp_ptr->mcapi_state =
130
                                            (MCAPI_ENDP_DISCONNECTED | MCAPI_ENDP_OPEN);
131
 
132
                                        /* Clear the channel type. */
133
                                        endp_ptr->mcapi_chan_type = 0;
134
                                    }
135
 
136
                                    break;
137
 
138
                                default:
139
 
140
                                    break;
141
                            }
142
                        }
143
                    }
144
 
145
                    /* Resume the request. */
146
                    mcapi_resume(node_data, req_ptr, MCAPI_ERR_REQUEST_CANCELLED);
147
 
148
                    /* Find another matching request. */
149
                    req_ptr =
150
                        mcapi_find_request(request, &node_data->mcapi_local_req_queue);
151
                }
152
            }
153
 
154
            /* If no matching request was found, return an error. */
155
            else
156
            {
157
                /* If the request that was passed in is pending, set
158
                 * the status to canceled.
159
                 */
160
                if (request->mcapi_status == MCAPI_PENDING)
161
                {
162
                    request->mcapi_status = MCAPI_ERR_REQUEST_CANCELLED;
163
 
164
                    /* This request structure does not get stored on
165
                     * the node's request list.
166
                     */
167
                    *mcapi_status = MCAPI_SUCCESS;
168
                }
169
 
170
                else
171
                {
172
                    *mcapi_status = MCAPI_ERR_REQUEST_INVALID;
173
                }
174
            }
175
 
176
            /* Release the lock. */
177
            mcapi_unlock_node_data();
178
        }
179
 
180
        /* Request is not valid. */
181
        else
182
        {
183
            *mcapi_status = MCAPI_ERR_REQUEST_INVALID;
184
        }
185
    }
186
 
187
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.