ltkc_element.c
Go to the documentation of this file.
00001 
00002 /*
00003  ***************************************************************************
00004  *  Copyright 2007,2008 Impinj, Inc.
00005  *
00006  *  Licensed under the Apache License, Version 2.0 (the "License");
00007  *  you may not use this file except in compliance with the License.
00008  *  You may obtain a copy of the License at
00009  *
00010  *      http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  *  Unless required by applicable law or agreed to in writing, software
00013  *  distributed under the License is distributed on an "AS IS" BASIS,
00014  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  *  See the License for the specific language governing permissions and
00016  *  limitations under the License.
00017  *
00018  ***************************************************************************
00019  */
00020 
00021 
00022 #include "ltkc_platform.h"
00023 #include "ltkc_base.h"
00024 
00025 
00026 
00027 
00028 LLRP_tSElement *
00029 LLRP_Element_construct (
00030   const LLRP_tSTypeDescriptor *  pTypeDescriptor)
00031 {
00032     LLRP_tSElement *            pElement;
00033 
00034     pElement = malloc(pTypeDescriptor->nSizeBytes);
00035     if(NULL != pElement)
00036     {
00037         memset(pElement, 0, pTypeDescriptor->nSizeBytes);
00038 
00039         pElement->pType = pTypeDescriptor;
00040     }
00041 
00042     return pElement;
00043 }
00044 
00045 void
00046 LLRP_Element_destruct (
00047   LLRP_tSElement *              pElement)
00048 {
00049     if(NULL != pElement)
00050     {
00051         pElement->pType->pfDestruct(pElement);
00052     }
00053 }
00054 
00055 void
00056 LLRP_Element_finalDestruct (
00057   LLRP_tSElement *              pElement)
00058 {
00059     LLRP_Element_clearSubParameterAllList(pElement);
00060     memset(pElement, 0xAA, pElement->pType->nSizeBytes);
00061     free(pElement);
00062 }
00063 
00064 void
00065 LLRP_Element_addSubParameterToAllList (
00066   LLRP_tSElement *              pElement,
00067   LLRP_tSParameter *            pParameter)
00068 {
00069     LLRP_tSParameter **         ppParameter;
00070     LLRP_tSParameter *          pNextParameter;
00071 
00072     for(
00073         ppParameter = &pElement->listAllSubParameters;
00074         NULL != *ppParameter;
00075         ppParameter = &pNextParameter->pNextAllSubParameters)
00076     {
00077         pNextParameter = *ppParameter;
00078     }
00079 
00080     pParameter->pNextAllSubParameters = NULL;
00081     *ppParameter = pParameter;
00082 }
00083 
00084 void
00085 LLRP_Element_removeSubParameterFromAllList (
00086   LLRP_tSElement *              pElement,
00087   LLRP_tSParameter *            pParameter)
00088 {
00089     LLRP_tSParameter **         ppParameter;
00090     LLRP_tSParameter *          pNextParameter;
00091 
00092     for(
00093         ppParameter = &pElement->listAllSubParameters;
00094         NULL != *ppParameter;
00095         )
00096     {
00097         pNextParameter = *ppParameter;
00098         if(pNextParameter == pParameter)
00099         {
00100             *ppParameter = pNextParameter->pNextAllSubParameters;
00101         }
00102         else
00103         {
00104             ppParameter = &pNextParameter->pNextAllSubParameters;
00105         }
00106     }
00107 
00108     pParameter->pNextAllSubParameters = NULL;
00109 }
00110 
00111 void
00112 LLRP_Element_clearSubParameterAllList (
00113   LLRP_tSElement *              pElement)
00114 {
00115     LLRP_tSParameter *          pParameter;
00116 
00117     while(NULL != (pParameter = pElement->listAllSubParameters))
00118     {
00119         pElement->listAllSubParameters =
00120                 pParameter->pNextAllSubParameters;
00121         LLRP_Element_destruct(&pParameter->elementHdr);
00122     }
00123 }
00124 
00125 void
00126 LLRP_Element_setSubParameterPtr (
00127   LLRP_tSElement *              pElement,
00128   LLRP_tSParameter **           ppPtr,
00129   LLRP_tSParameter *            pValue)
00130 {
00131     if(NULL != *ppPtr)
00132     {
00133         LLRP_Element_removeSubParameterFromAllList(pElement, *ppPtr);
00134         LLRP_Element_destruct((LLRP_tSElement *) *ppPtr);
00135     }
00136     *ppPtr = pValue;
00137     if(NULL != *ppPtr)
00138     {
00139         LLRP_Element_addSubParameterToAllList(pElement, *ppPtr);
00140     }
00141 }
00142 
00143 void
00144 LLRP_Element_addToSubParameterList (
00145   LLRP_tSElement *              pElement,
00146   LLRP_tSParameter **           ppListHead,
00147   LLRP_tSParameter *            pValue)
00148 {
00149     LLRP_tSParameter **         ppCur = ppListHead;
00150 
00151     if(NULL != pValue)
00152     {
00153         while(NULL != *ppCur)
00154         {
00155             ppCur = &(*ppCur)->pNextSubParameter;
00156         }
00157         pValue->pNextSubParameter = NULL;
00158         *ppCur = pValue;
00159 
00160         LLRP_Element_addSubParameterToAllList(pElement, pValue);
00161     }
00162 }
00163 
00164 void
00165 LLRP_Element_attachToSubParameterList (
00166   LLRP_tSParameter **           ppListHead,
00167   LLRP_tSParameter *            pValue)
00168 {
00169     LLRP_tSParameter **         ppCur = ppListHead;
00170 
00171     if(NULL != pValue)
00172     {
00173         while(NULL != *ppCur)
00174         {
00175             ppCur = &(*ppCur)->pNextSubParameter;
00176         }
00177         pValue->pNextSubParameter = NULL;
00178         *ppCur = pValue;
00179     }
00180 }
00181 
00182 void
00183 LLRP_Element_clearSubParameterList (
00184   LLRP_tSElement *              pElement,
00185   LLRP_tSParameter **           ppListHead)
00186 {
00187     LLRP_tSParameter **         ppCur = ppListHead;
00188     LLRP_tSParameter *          pValue;
00189 
00190     while (NULL != (pValue = *ppCur))
00191     {
00192         *ppCur = pValue->pNextSubParameter;
00193 
00194         LLRP_Element_removeSubParameterFromAllList(pElement, pValue);
00195         LLRP_Element_destruct((LLRP_tSElement *) pValue);
00196     }
00197 }
00198 
00199 int
00200 LLRP_Element_walk (
00201   const LLRP_tSElement *          pElement,
00202   int                           (*pFunc)(
00203                                   const LLRP_tSElement *    pElement,
00204                                   void *                    pArg),
00205   void *                        pArg,
00206   int                           iDepth,
00207   int                           nMaxDepth)
00208  {
00209     LLRP_tSParameter *          pParameter;
00210     int                         rc;
00211 
00212     rc = (*pFunc)(pElement, pArg);
00213     if(0 != rc)
00214     {
00215         return rc;
00216     }
00217 
00218     if(iDepth >= nMaxDepth)
00219     {
00220         return 0;
00221     }
00222 
00223     for(pParameter = pElement->listAllSubParameters;
00224         NULL != pParameter;
00225         pParameter = pParameter->pNextAllSubParameters)
00226     {
00227         rc = LLRP_Element_walk(&pParameter->elementHdr,
00228                 pFunc, pArg, iDepth+1, nMaxDepth);
00229         if(0 != rc)
00230         {
00231             return rc;
00232         }
00233     }
00234 
00235     return 0;
00236 }
00237 
00238 void
00239 LLRP_Message_setMessageID (
00240   LLRP_tSMessage *              pMessage,
00241   llrp_u32_t                    MessageID)
00242 {
00243     pMessage->MessageID = MessageID;
00244 }
00245 
00246 llrp_bool_t
00247 LLRP_Parameter_isAllowedIn (
00248   LLRP_tSParameter *            pParameter,
00249   const LLRP_tSTypeDescriptor * pEnclosingTypeDescriptor)
00250 {
00251     const LLRP_tSTypeDescriptor *pType;
00252 
00253     pType = pParameter->elementHdr.pType;
00254 
00255     if(NULL == pType->pfIsAllowedIn)
00256     {
00257         return FALSE;
00258     }
00259 
00260     return (*pType->pfIsAllowedIn)(pEnclosingTypeDescriptor);
00261 }
00262 
00263 llrp_bool_t
00264 LLRP_Parameter_isAllowedExtension (
00265   LLRP_tSParameter *            pParameter,
00266   const LLRP_tSTypeDescriptor * pEnclosingTypeDescriptor)
00267 {
00268     const LLRP_tSTypeDescriptor *pType;
00269 
00270     pType = pParameter->elementHdr.pType;
00271 
00272     /*
00273      * If it is a generic Custom parameter allow it.
00274      */
00275     if(!pType->bIsMessage && NULL == pType->pVendorDescriptor &&
00276        1023u == pType->TypeNum)
00277     {
00278         return TRUE;
00279     }
00280 
00281     /*
00282      * If it is some kind of custom parameter allow it.
00283      */
00284     if(!pType->bIsMessage && NULL != pType->pVendorDescriptor)
00285     {
00286         return TRUE;
00287     }
00288 
00289     /*
00290      * At this point checking specifically if it is allowed
00291      * is perfunctory.
00292      */
00293     return LLRP_Parameter_isAllowedIn(pParameter, pEnclosingTypeDescriptor);
00294 }


thingmagic_rfid
Author(s): Brian Bingham
autogenerated on Thu May 16 2019 03:01:23