00001 /* 00002 * Copyright (c) 2011 Jan Vesely 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 00009 * - Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * - Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * - The name of the author may not be used to endorse or promote products 00015 * derived from this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00019 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00020 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00022 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00026 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 */ 00034 #include "utils/malloc32.h" 00035 #include "hcd_endpoint.h" 00036 00042 static void hcd_ep_toggle_set(void *hcd_ep, int toggle) 00043 { 00044 hcd_endpoint_t *instance = hcd_ep; 00045 assert(instance); 00046 assert(instance->ed); 00047 ed_toggle_set(instance->ed, toggle); 00048 } 00049 /*----------------------------------------------------------------------------*/ 00055 static int hcd_ep_toggle_get(void *hcd_ep) 00056 { 00057 hcd_endpoint_t *instance = hcd_ep; 00058 assert(instance); 00059 assert(instance->ed); 00060 return ed_toggle_get(instance->ed); 00061 } 00062 /*----------------------------------------------------------------------------*/ 00068 hcd_endpoint_t * hcd_endpoint_assign(endpoint_t *ep) 00069 { 00070 assert(ep); 00071 hcd_endpoint_t *hcd_ep = malloc(sizeof(hcd_endpoint_t)); 00072 if (hcd_ep == NULL) 00073 return NULL; 00074 00075 hcd_ep->ed = malloc32(sizeof(ed_t)); 00076 if (hcd_ep->ed == NULL) { 00077 free(hcd_ep); 00078 return NULL; 00079 } 00080 00081 hcd_ep->td = malloc32(sizeof(td_t)); 00082 if (hcd_ep->td == NULL) { 00083 free32(hcd_ep->ed); 00084 free(hcd_ep); 00085 return NULL; 00086 } 00087 00088 ed_init(hcd_ep->ed, ep); 00089 ed_set_td(hcd_ep->ed, hcd_ep->td); 00090 endpoint_set_hc_data(ep, hcd_ep, hcd_ep_toggle_get, hcd_ep_toggle_set); 00091 00092 return hcd_ep; 00093 } 00094 /*----------------------------------------------------------------------------*/ 00099 void hcd_endpoint_clear(endpoint_t *ep) 00100 { 00101 assert(ep); 00102 hcd_endpoint_t *hcd_ep = ep->hc_data.data; 00103 assert(hcd_ep); 00104 free32(hcd_ep->ed); 00105 free32(hcd_ep->td); 00106 free(hcd_ep); 00107 }