Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

ltkcpp_typeregistry.cpp

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 "ltkcpp_platform.h"
00023 #include "ltkcpp_base.h"
00024 
00025 
00026 namespace LLRP
00027 {
00028 
00029 CTypeRegistry::CTypeRegistry (void)
00030 {
00031     memset(m_apStdMessageTypeDescriptors, 0,
00032         sizeof m_apStdMessageTypeDescriptors);
00033 
00034     memset(m_apStdParameterTypeDescriptors, 0,
00035         sizeof m_apStdParameterTypeDescriptors);
00036 }
00037 
00038 CTypeRegistry::~CTypeRegistry (void)
00039 {
00040 }
00041 
00042 EResultCode
00043 CTypeRegistry::enroll (
00044   const CTypeDescriptor *       pTypeDescriptor)
00045 {
00046     if(NULL == pTypeDescriptor->m_pVendorDescriptor)
00047     {
00048         if(1023u < pTypeDescriptor->m_TypeNum)
00049         {
00050             return RC_EnrollBadTypeNumber;
00051         }
00052 
00053         /*
00054          * Standard message or parameter
00055          */
00056         if(pTypeDescriptor->m_bIsMessage)
00057         {
00058             m_apStdMessageTypeDescriptors[pTypeDescriptor->m_TypeNum] =
00059                 pTypeDescriptor;
00060         }
00061         else
00062         {
00063             m_apStdParameterTypeDescriptors[pTypeDescriptor->m_TypeNum] =
00064                 pTypeDescriptor;
00065         }
00066     }
00067     else
00068     {
00069         /*
00070          * Custom messages or parameter
00071          */
00072         if(pTypeDescriptor->m_bIsMessage)
00073         {
00074             m_listCustomMessageTypeDescriptors.push_back(pTypeDescriptor);
00075         }
00076         else
00077         {
00078             m_listCustomParameterTypeDescriptors.push_back(pTypeDescriptor);
00079         }
00080     }
00081 
00082     return RC_OK;
00083 }
00084 
00085 const CTypeDescriptor *
00086 CTypeRegistry::lookupMessage (
00087   unsigned int                  MessageTypeNum) const
00088 {
00089     if(1023u < MessageTypeNum)
00090     {
00091         return NULL;
00092     }
00093 
00094     return m_apStdMessageTypeDescriptors[MessageTypeNum];
00095 }
00096 
00097 const CTypeDescriptor *
00098 CTypeRegistry::lookupParameter (
00099   unsigned int                  ParameterTypeNum) const
00100 {
00101     if(1023u < ParameterTypeNum)
00102     {
00103         /* throw exception? */
00104         return NULL;
00105     }
00106 
00107     return m_apStdParameterTypeDescriptors[ParameterTypeNum];
00108 }
00109 
00110 const CTypeDescriptor *
00111 CTypeRegistry::lookupCustomMessage (
00112   unsigned int                  VendorID,
00113   unsigned int                  MessageSubTypeNum) const
00114 {
00115     for (
00116         std::list<const CTypeDescriptor *>::const_iterator elem =
00117                             m_listCustomMessageTypeDescriptors.begin();
00118         elem != m_listCustomMessageTypeDescriptors.end();
00119         elem++)
00120     {
00121         const CTypeDescriptor * pTypeDescriptor;
00122         pTypeDescriptor = *elem;
00123         if(VendorID == pTypeDescriptor->m_pVendorDescriptor->m_VendorID &&
00124            MessageSubTypeNum == pTypeDescriptor->m_TypeNum)
00125         {
00126             return pTypeDescriptor;
00127         }
00128     }
00129 
00130     return NULL;
00131 }
00132 
00133 const CTypeDescriptor *
00134 CTypeRegistry::lookupCustomParameter (
00135   unsigned int                  VendorID,
00136   unsigned int                  ParameterSubTypeNum) const
00137 {
00138     for (
00139         std::list<const CTypeDescriptor *>::const_iterator elem = 
00140                             m_listCustomParameterTypeDescriptors.begin();
00141         elem != m_listCustomParameterTypeDescriptors.end();
00142         elem++)
00143     {
00144         const CTypeDescriptor * pTypeDescriptor;
00145         pTypeDescriptor = *elem;
00146         if(VendorID == pTypeDescriptor->m_pVendorDescriptor->m_VendorID &&
00147            ParameterSubTypeNum == pTypeDescriptor->m_TypeNum)
00148         {
00149             return pTypeDescriptor;
00150         }
00151     }
00152 
00153     return NULL;
00154 }
00155 
00156 
00157 }; /* namespace LLRP */
00158 

Generated on Wed Nov 26 12:27:45 2008 for LTKCPP-- LLRP Toolkit C Plus Plus Library by  doxygen 1.3.9.1