ltkc_typeregistry.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 /* Create a new TypeRegistry */
00029 LLRP_tSTypeRegistry *
00030 LLRP_TypeRegistry_construct (void)
00031 {
00032     LLRP_tSTypeRegistry *       pTypeRegistry;
00033 
00034     pTypeRegistry = (LLRP_tSTypeRegistry *) malloc(sizeof *pTypeRegistry);
00035     if(NULL == pTypeRegistry)
00036     {
00037         return pTypeRegistry;
00038     }
00039 
00040     memset(pTypeRegistry, 0, sizeof *pTypeRegistry);
00041 
00042     return pTypeRegistry;
00043 }
00044 
00045 /* Destruct a TypeRegistry */
00046 void
00047 LLRP_TypeRegistry_destruct (
00048   LLRP_tSTypeRegistry *         pTypeRegistry)
00049 {
00050     memset(pTypeRegistry, 0, sizeof *pTypeRegistry);
00051     free(pTypeRegistry);
00052 }
00053 
00054 /* Add a type descriptor to the registry */
00055 LLRP_tResultCode
00056 LLRP_TypeRegistry_enroll (
00057   LLRP_tSTypeRegistry *         pTypeRegistry,
00058   const LLRP_tSTypeDescriptor * pTypeDescriptor)
00059 {
00060     if(NULL == pTypeDescriptor->pVendorDescriptor)
00061     {
00062         if(1023u < pTypeDescriptor->TypeNum)
00063         {
00064             return LLRP_RC_EnrollBadTypeNumber;
00065         }
00066 
00067         /*
00068          * Standard message or parameter
00069          */
00070         if(pTypeDescriptor->bIsMessage)
00071         {
00072             pTypeRegistry->apStdMessageTypeDescriptors[
00073                     pTypeDescriptor->TypeNum] = pTypeDescriptor;
00074         }
00075         else
00076         {
00077             pTypeRegistry->apStdParameterTypeDescriptors[
00078                     pTypeDescriptor->TypeNum] = pTypeDescriptor;
00079         }
00080     }
00081     else
00082     {
00083         /*
00084          * Custom message or parameter
00085          */
00086         if(pTypeDescriptor->bIsMessage)
00087         {
00088             unsigned int        ix;
00089 
00090             ix = pTypeRegistry->nCustMessageTypeDescriptors++;
00091             pTypeRegistry->apCustMessageTypeDescriptors[ix] =
00092                         pTypeDescriptor;
00093         }
00094         else
00095         {
00096             unsigned int        ix;
00097 
00098             ix = pTypeRegistry->nCustParameterTypeDescriptors++;
00099             pTypeRegistry->apCustParameterTypeDescriptors[ix] =
00100                         pTypeDescriptor;
00101         }
00102     }
00103     
00104     return LLRP_RC_OK;
00105 }
00106 
00107 /* Lookup a standard message type descriptor. NULL=>not found */
00108 const LLRP_tSTypeDescriptor *
00109 LLRP_TypeRegistry_lookupMessage (
00110   const LLRP_tSTypeRegistry *   pTypeRegistry,
00111   unsigned int                  MessageTypeNum)
00112 {
00113     if(1023u < MessageTypeNum)
00114     {
00115         return NULL;
00116     }
00117 
00118     return pTypeRegistry->apStdMessageTypeDescriptors[MessageTypeNum];
00119 }
00120 
00121 /* Lookup a standard parameter type descriptor. NULL=>not found */
00122 const LLRP_tSTypeDescriptor *
00123 LLRP_TypeRegistry_lookupParameter (
00124   const LLRP_tSTypeRegistry *   pTypeRegistry,
00125   unsigned int                  ParameterTypeNum)
00126 {
00127     if(1023u < ParameterTypeNum)
00128     {
00129         return NULL;
00130     }
00131 
00132     return pTypeRegistry->apStdParameterTypeDescriptors[ParameterTypeNum];
00133 }
00134 
00135 /* Lookup a custom message type descriptor. NULL=>not found */
00136 const LLRP_tSTypeDescriptor *
00137 LLRP_TypeRegistry_lookupCustomMessage (
00138   const LLRP_tSTypeRegistry *   pTypeRegistry,
00139   unsigned int                  VendorID,
00140   unsigned int                  MessageSubTypeNum)
00141 {
00142     const LLRP_tSTypeDescriptor *pTypeDescriptor;
00143     unsigned int                ix;
00144 
00145     for(ix = 0; ix < pTypeRegistry->nCustMessageTypeDescriptors; ix++)
00146     {
00147         pTypeDescriptor = pTypeRegistry->apCustMessageTypeDescriptors[ix];
00148         if(VendorID == pTypeDescriptor->pVendorDescriptor->VendorID &&
00149            MessageSubTypeNum == pTypeDescriptor->TypeNum)
00150         {
00151             return pTypeDescriptor;
00152         }
00153     }
00154 
00155     return NULL;
00156 }
00157 
00158 /* Lookup a custom parameter type descriptor. NULL=>not found */
00159 const LLRP_tSTypeDescriptor *
00160 LLRP_TypeRegistry_lookupCustomParameter (
00161   const LLRP_tSTypeRegistry *   pTypeRegistry,
00162   unsigned int                  VendorID,
00163   unsigned int                  ParameterSubTypeNum)
00164 {
00165     const LLRP_tSTypeDescriptor *pTypeDescriptor;
00166     unsigned int                ix;
00167 
00168     for(ix = 0; ix < pTypeRegistry->nCustParameterTypeDescriptors; ix++)
00169     {
00170         pTypeDescriptor = pTypeRegistry->apCustParameterTypeDescriptors[ix];
00171         if(VendorID == pTypeDescriptor->pVendorDescriptor->VendorID &&
00172            ParameterSubTypeNum == pTypeDescriptor->TypeNum)
00173         {
00174             return pTypeDescriptor;
00175         }
00176     }
00177 
00178     return NULL;
00179 }
00180 
00181 /* Lookup a type descriptor by name. NULL=>not found */
00182 const LLRP_tSTypeDescriptor *
00183 LLRP_TypeRegistry_lookupByName (
00184   const LLRP_tSTypeRegistry *   pTypeRegistry,
00185   const char *                  pElementName)
00186 {
00187     unsigned int                i;
00188     const LLRP_tSTypeDescriptor *pTypeDescriptor;
00189 
00190     for(i = 0; i < 1024u; i++)
00191     {
00192         pTypeDescriptor = pTypeRegistry->apStdMessageTypeDescriptors[i];
00193         if(NULL == pTypeDescriptor)
00194         {
00195             continue;
00196         }
00197 
00198         if(0 == strcmp(pTypeDescriptor->pName, pElementName))
00199         {
00200             return pTypeDescriptor;
00201         }
00202     }
00203 
00204     for(i = 0; i < 1024u; i++)
00205     {
00206         pTypeDescriptor = pTypeRegistry->apStdParameterTypeDescriptors[i];
00207         if(NULL == pTypeDescriptor)
00208         {
00209             continue;
00210         }
00211 
00212         if(0 == strcmp(pTypeDescriptor->pName, pElementName))
00213         {
00214             return pTypeDescriptor;
00215         }
00216     }
00217 
00218     /* TODO: custom messages */
00219     /* TODO: custom parameters */
00220 
00221     return NULL;
00222 }
00223 


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