LTKCPP-- LLRP Toolkit C Plus Plus Library
ltkcpp_typeregistry.cpp
1 
2 /*
3  *****************************************************************************
4  * *
5  * IMPINJ CONFIDENTIAL AND PROPRIETARY *
6  * *
7  * This source code is the sole property of Impinj, Inc. Reproduction or *
8  * utilization of this source code in whole or in part is forbidden without *
9  * the prior written consent of Impinj, Inc. *
10  * *
11  * (c) Copyright Impinj, Inc. 2007,2008. All rights reserved. *
12  * *
13  *****************************************************************************/
14 
15 
16 #include "ltkcpp_platform.h"
17 #include "ltkcpp_base.h"
18 
19 
20 namespace LLRP
21 {
22 
23 CTypeRegistry::CTypeRegistry (void)
24 {
27 
30 }
31 
32 CTypeRegistry::~CTypeRegistry (void)
33 {
34 }
35 
38  const CTypeDescriptor * pTypeDescriptor)
39 {
40  if(NULL == pTypeDescriptor->m_pVendorDescriptor)
41  {
42  if(1023u < pTypeDescriptor->m_TypeNum)
43  {
45  }
46 
47  /*
48  * Standard message or parameter
49  */
50  if(pTypeDescriptor->m_bIsMessage)
51  {
52  m_apStdMessageTypeDescriptors[pTypeDescriptor->m_TypeNum] =
53  pTypeDescriptor;
54  }
55  else
56  {
57  m_apStdParameterTypeDescriptors[pTypeDescriptor->m_TypeNum] =
58  pTypeDescriptor;
59  }
60  }
61  else
62  {
63  /*
64  * Custom messages or parameter
65  */
66  if(pTypeDescriptor->m_bIsMessage)
67  {
68  m_listCustomMessageTypeDescriptors.push_back(pTypeDescriptor);
69  }
70  else
71  {
72  m_listCustomParameterTypeDescriptors.push_back(pTypeDescriptor);
73  }
74  }
75 
76  return RC_OK;
77 }
78 
79 const CTypeDescriptor *
81  unsigned int MessageTypeNum) const
82 {
83  if(1023u < MessageTypeNum)
84  {
85  return NULL;
86  }
87 
88  return m_apStdMessageTypeDescriptors[MessageTypeNum];
89 }
90 
91 const CTypeDescriptor *
93  unsigned int ParameterTypeNum) const
94 {
95  if(1023u < ParameterTypeNum)
96  {
97  /* throw exception? */
98  return NULL;
99  }
100 
101  return m_apStdParameterTypeDescriptors[ParameterTypeNum];
102 }
103 
104 const CTypeDescriptor *
106  unsigned int VendorID,
107  unsigned int MessageSubTypeNum) const
108 {
109  for (
110  std::list<const CTypeDescriptor *>::const_iterator elem =
113  elem++)
114  {
115  const CTypeDescriptor * pTypeDescriptor;
116  pTypeDescriptor = *elem;
117  if(VendorID == pTypeDescriptor->m_pVendorDescriptor->m_VendorID &&
118  MessageSubTypeNum == pTypeDescriptor->m_TypeNum)
119  {
120  return pTypeDescriptor;
121  }
122  }
123 
124  return NULL;
125 }
126 
127 const CTypeDescriptor *
129  unsigned int VendorID,
130  unsigned int ParameterSubTypeNum) const
131 {
132  for (
133  std::list<const CTypeDescriptor *>::const_iterator elem =
136  elem++)
137  {
138  const CTypeDescriptor * pTypeDescriptor;
139  pTypeDescriptor = *elem;
140  if(VendorID == pTypeDescriptor->m_pVendorDescriptor->m_VendorID &&
141  ParameterSubTypeNum == pTypeDescriptor->m_TypeNum)
142  {
143  return pTypeDescriptor;
144  }
145  }
146 
147  return NULL;
148 }
149 
150 /* look up the type descriptor*/
151 const CTypeDescriptor *
152 CTypeRegistry::lookupByName (
153  char * pName) const
154 {
155  unsigned int i;
156  const CTypeDescriptor * pTypeDescriptor;
157 
158  for(i = 0; i < 1024u; i++)
159  {
160  pTypeDescriptor = m_apStdMessageTypeDescriptors[i];
161  if(NULL == pTypeDescriptor)
162  {
163  continue;
164  }
165 
166  if(0 == strcmp(pTypeDescriptor->m_pName, pName))
167  {
168  return pTypeDescriptor;
169  }
170  }
171 
172  for(i = 0; i < 1024u; i++)
173  {
174  pTypeDescriptor = m_apStdParameterTypeDescriptors[i];
175  if(NULL == pTypeDescriptor)
176  {
177  continue;
178  }
179 
180  if(0 == strcmp(pTypeDescriptor->m_pName, pName))
181  {
182  return pTypeDescriptor;
183  }
184  }
185 
186  for (
187  std::list<const CTypeDescriptor *>::const_iterator elem =
190  elem++)
191  {
192  const CTypeDescriptor * pTypeDescriptor;
193  pTypeDescriptor = *elem;
194  if(0 == strcmp(pTypeDescriptor->m_pName, pName))
195  {
196  return pTypeDescriptor;
197  }
198  }
199 
200  for (
201  std::list<const CTypeDescriptor *>::const_iterator elem =
204  elem++)
205  {
206  const CTypeDescriptor * pTypeDescriptor;
207  pTypeDescriptor = *elem;
208  if(0 == strcmp(pTypeDescriptor->m_pName, pName))
209  {
210  return pTypeDescriptor;
211  }
212  }
213  return NULL;
214 }
215 
216 }; /* namespace LLRP */
217 
EResultCode enroll(const CTypeDescriptor *pTypeDescriptor)
Add a type descriptor to the registry.
const CTypeDescriptor * m_apStdMessageTypeDescriptors[1024u]
Standard messages subscripted by type number.
Definition: ltkcpp_base.h:889
const CTypeDescriptor * m_apStdParameterTypeDescriptors[1024u]
Standard parameters subscripted by type number.
Definition: ltkcpp_base.h:891
Based type descriptions for the LTKCPP library.
llrp_u32_t m_TypeNum
Type number or, for custom, subtype number.
Definition: ltkcpp_base.h:772
EResultCode
Error result codes for LTK operations.
Definition: ltkcpp_base.h:583
const CTypeDescriptor * lookupMessage(unsigned int MessageTypeNum) const
Lookup a standard message type descriptor. NULL=>not found.
std::list< const CTypeDescriptor * > m_listCustomParameterTypeDescriptors
List of custom parameters types.
Definition: ltkcpp_base.h:895
Based types for the LKTCPP library.
const CTypeDescriptor * lookupParameter(unsigned int ParameterTypeNum) const
Lookup a standard parameter type descriptor. NULL=>not found.
const CVendorDescriptor * m_pVendorDescriptor
NULL=>standard LLRP, !NULL=>Vendor (PEN) of custom message or parameter.
Definition: ltkcpp_base.h:766
llrp_u32_t m_VendorID
Vendor PEN of a custom message or parameter.
Definition: ltkcpp_base.h:692
const CTypeDescriptor * lookupCustomParameter(unsigned int VendorID, unsigned int ParameterSubTypeNum) const
Lookup a custom parameter type descriptor. NULL=>not found.
char * m_pName
String name of parameter/message type (e.g. "ROSpec")
Definition: ltkcpp_base.h:762
std::list< const CTypeDescriptor * > m_listCustomMessageTypeDescriptors
List of custom message types.
Definition: ltkcpp_base.h:893
const CTypeDescriptor * lookupCustomMessage(unsigned int VendorID, unsigned int MessageSubTypeNum) const
Lookup a custom message type descriptor. NULL=>not found.
Definition: ltkcpp.h:45
llrp_bool_t m_bIsMessage
TRUE for a message type, FALSE for a parameter type.
Definition: ltkcpp_base.h:759
Describes a message or parameter type.
Definition: ltkcpp_base.h:755