LTKCPP-- LLRP Toolkit C Plus Plus Library
|
00001 00002 /* 00003 ***************************************************************************** 00004 * * 00005 * IMPINJ CONFIDENTIAL AND PROPRIETARY * 00006 * * 00007 * This source code is the sole property of Impinj, Inc. Reproduction or * 00008 * utilization of this source code in whole or in part is forbidden without * 00009 * the prior written consent of Impinj, Inc. * 00010 * * 00011 * (c) Copyright Impinj, Inc. 2007,2010. All rights reserved. * 00012 * * 00013 *****************************************************************************/ 00014 00015 00028 /* forward declare these so we don't need to include the 00029 ** whole XML header files here. Make sure they are out 00030 ** of the namespace and extern C since they need to 00031 ** match the C types later */ 00032 extern "C" 00033 { 00034 struct _xmlNode; 00035 struct _xmlDoc; 00036 } 00037 00038 namespace LLRP 00039 { 00040 class CXMLTextEncoder; 00041 class CXMLTextEncoderStream; 00042 class CXMLTextDecoder; 00043 class CXMLTextDecoderStream; 00044 00045 class CXMLTextEncoder : public CEncoder 00046 { 00047 friend class CXMLTextEncoderStream; 00048 00049 private: 00050 char * m_pBuffer; 00051 int m_nBuffer; 00052 int m_iNext; 00053 00054 public: 00055 int m_bOverflow; 00056 00057 public: 00058 CXMLTextEncoder ( 00059 char * pBuffer, 00060 int nBuffer); 00061 00062 ~CXMLTextEncoder (void); 00063 00064 void 00065 encodeElement ( 00066 const CElement * pElement); 00067 }; 00068 00069 class CXMLTextDecoder : public CDecoder 00070 { 00071 friend class CXMLTextDecoderStream; 00072 00073 private: 00074 struct _xmlDoc * m_pDoc; 00075 struct _xmlNode * m_pxmlNodeTree; 00076 00077 public: 00078 CXMLTextDecoder ( 00079 const CTypeRegistry * pTypeRegistry, 00080 char * pBuffer, 00081 int nBuffer); 00082 00083 CXMLTextDecoder ( 00084 const CTypeRegistry * pTypeRegistry, 00085 struct _xmlNode * pNodeTree); 00086 00087 00088 CXMLTextDecoder ( 00089 const CTypeRegistry * pTypeRegistry, 00090 char * fname); 00091 00092 ~CXMLTextDecoder (void); 00093 00094 CMessage * 00095 decodeMessage (void); 00096 00124 static void 00125 cleanupParser(void); 00126 00127 }; 00128 00129 class CXMLTextEncoderStream : public CEncoderStream 00130 { 00131 friend class CXMLTextEncoder; 00132 00133 public: 00134 void 00135 putRequiredSubParameter ( 00136 const CParameter * pParameter, 00137 const CTypeDescriptor * pRefType); 00138 00139 void 00140 putOptionalSubParameter ( 00141 const CParameter * pParameter, 00142 const CTypeDescriptor * pRefType); 00143 00144 void 00145 putRequiredSubParameterList ( 00146 const tListOfParameters * pParameterList, 00147 const CTypeDescriptor * pRefType); 00148 00149 void 00150 putOptionalSubParameterList ( 00151 const tListOfParameters * pParameterList, 00152 const CTypeDescriptor * pRefType); 00153 00154 /* 00155 * 8-bit types 00156 */ 00157 00158 void 00159 put_u8 ( 00160 llrp_u8_t Value, 00161 const CFieldDescriptor * pFieldDescriptor); 00162 00163 void 00164 put_s8 ( 00165 llrp_s8_t Value, 00166 const CFieldDescriptor * pFieldDescriptor); 00167 00168 void 00169 put_u8v ( 00170 llrp_u8v_t Value, 00171 const CFieldDescriptor * pFieldDescriptor); 00172 00173 void 00174 put_s8v ( 00175 llrp_s8v_t Value, 00176 const CFieldDescriptor * pFieldDescriptor); 00177 00178 /* 00179 * 16-bit types 00180 */ 00181 00182 void 00183 put_u16 ( 00184 llrp_u16_t Value, 00185 const CFieldDescriptor * pFieldDescriptor); 00186 00187 void 00188 put_s16 ( 00189 llrp_s16_t Value, 00190 const CFieldDescriptor * pFieldDescriptor); 00191 00192 void 00193 put_u16v ( 00194 llrp_u16v_t Value, 00195 const CFieldDescriptor * pFieldDescriptor); 00196 00197 void 00198 put_s16v ( 00199 llrp_s16v_t Value, 00200 const CFieldDescriptor * pFieldDescriptor); 00201 00202 /* 00203 * 32-bit types 00204 */ 00205 00206 void 00207 put_u32 ( 00208 llrp_u32_t Value, 00209 const CFieldDescriptor * pFieldDescriptor); 00210 00211 void 00212 put_s32 ( 00213 llrp_s32_t Value, 00214 const CFieldDescriptor * pFieldDescriptor); 00215 00216 void 00217 put_u32v ( 00218 llrp_u32v_t Value, 00219 const CFieldDescriptor * pFieldDescriptor); 00220 00221 void 00222 put_s32v ( 00223 llrp_s32v_t Value, 00224 const CFieldDescriptor * pFieldDescriptor); 00225 00226 /* 00227 * 64-bit types 00228 */ 00229 00230 void 00231 put_u64 ( 00232 llrp_u64_t Value, 00233 const CFieldDescriptor * pFieldDescriptor); 00234 00235 void 00236 put_s64 ( 00237 llrp_s64_t Value, 00238 const CFieldDescriptor * pFieldDescriptor); 00239 00240 void 00241 put_u64v ( 00242 llrp_u64v_t Value, 00243 const CFieldDescriptor * pFieldDescriptor); 00244 00245 void 00246 put_s64v ( 00247 llrp_s64v_t Value, 00248 const CFieldDescriptor * pFieldDescriptor); 00249 00250 /* 00251 * Special types 00252 */ 00253 00254 void 00255 put_u1 ( 00256 llrp_u1_t Value, 00257 const CFieldDescriptor * pFieldDescriptor); 00258 00259 void 00260 put_u1v ( 00261 llrp_u1v_t Value, 00262 const CFieldDescriptor * pFieldDescriptor); 00263 00264 void 00265 put_u2 ( 00266 llrp_u2_t Value, 00267 const CFieldDescriptor * pFieldDescriptor); 00268 00269 void 00270 put_u96 ( 00271 llrp_u96_t Value, 00272 const CFieldDescriptor * pFieldDescriptor); 00273 00274 void 00275 put_utf8v ( 00276 llrp_utf8v_t Value, 00277 const CFieldDescriptor * pFieldDescriptor); 00278 00279 void 00280 put_bytesToEnd ( 00281 llrp_bytesToEnd_t Value, 00282 const CFieldDescriptor * pFieldDescriptor); 00283 00284 /* 00285 * Enumerated types of various sizes 00286 */ 00287 00288 void 00289 put_e1 ( 00290 int eValue, 00291 const CFieldDescriptor * pFieldDescriptor); 00292 00293 void 00294 put_e2 ( 00295 int eValue, 00296 const CFieldDescriptor * pFieldDescriptor); 00297 00298 void 00299 put_e8 ( 00300 int eValue, 00301 const CFieldDescriptor * pFieldDescriptor); 00302 00303 void 00304 put_e16 ( 00305 int eValue, 00306 const CFieldDescriptor * pFieldDescriptor); 00307 00308 void 00309 put_e32 ( 00310 int eValue, 00311 const CFieldDescriptor * pFieldDescriptor); 00312 00313 void 00314 put_e8v ( 00315 llrp_u8v_t Value, 00316 const CFieldDescriptor * pFieldDescriptor); 00317 00318 /* 00319 * Reserved types are some number of bits 00320 */ 00321 00322 void 00323 put_reserved ( 00324 unsigned int nBits); 00325 00326 private: 00327 CXMLTextEncoderStream ( 00328 CXMLTextEncoder * pEncoder); 00329 00330 CXMLTextEncoderStream ( 00331 CXMLTextEncoderStream * pEnclosingEncoderStream); 00332 00333 CXMLTextEncoder * m_pEncoder; 00334 CXMLTextEncoderStream * m_pEnclosingEncoderStream; 00335 const CTypeDescriptor * m_pRefType; 00336 unsigned int m_nDepth; 00337 00338 void 00339 putElement ( 00340 const CElement * pElement); 00341 00342 void 00343 put_enum ( 00344 int eValue, 00345 const CFieldDescriptor * pFieldDescriptor); 00346 00347 void 00348 indent(int delta = 0); 00349 00350 void 00351 appendOpenTag ( 00352 const char * pName); 00353 00354 void 00355 appendCloseTag ( 00356 const char * pName); 00357 00358 void 00359 appendPrefixedTagName ( 00360 const char * pName); 00361 00362 void 00363 appendFormat ( 00364 char * pFmtStr, 00365 ...); 00366 00367 }; 00368 00369 class CXMLTextDecoderStream : public CDecoderStream 00370 { 00371 friend class CXMLTextDecoder; 00372 00373 private: 00374 CXMLTextDecoderStream ( 00375 CXMLTextDecoder * pDecoder); 00376 00377 CXMLTextDecoderStream ( 00378 CXMLTextDecoderStream * pEnclosingDecoderStream); 00379 00380 public: 00381 00382 CElement * 00383 decodeElement ( 00384 int bAllowMessage, 00385 int bSkipBlanks); 00386 /* 00387 * 8-bit types 00388 */ 00389 00391 llrp_u8_t 00392 get_u8 ( 00393 const CFieldDescriptor * pFieldDesc); 00394 00396 llrp_s8_t 00397 get_s8 ( 00398 const CFieldDescriptor * pFieldDesc); 00399 00401 llrp_u8v_t 00402 get_u8v ( 00403 const CFieldDescriptor * pFieldDesc); 00404 00406 llrp_s8v_t 00407 get_s8v ( 00408 const CFieldDescriptor * pFieldDesc); 00409 00410 /* 00411 * 16-bit types 00412 */ 00413 00415 llrp_u16_t 00416 get_u16 ( 00417 const CFieldDescriptor * pFieldDesc); 00418 00420 llrp_s16_t 00421 get_s16 ( 00422 const CFieldDescriptor * pFieldDesc); 00423 00425 llrp_u16v_t 00426 get_u16v ( 00427 const CFieldDescriptor * pFieldDesc); 00428 00430 llrp_s16v_t 00431 get_s16v ( 00432 const CFieldDescriptor * pFieldDesc); 00433 00434 /* 00435 * 32-bit types 00436 */ 00437 00439 llrp_u32_t 00440 get_u32 ( 00441 const CFieldDescriptor * pFieldDesc); 00442 00444 llrp_s32_t 00445 get_s32 ( 00446 const CFieldDescriptor * pFieldDesc); 00447 00449 llrp_u32v_t 00450 get_u32v ( 00451 const CFieldDescriptor * pFieldDesc); 00452 00454 llrp_s32v_t 00455 get_s32v ( 00456 const CFieldDescriptor * pFieldDesc); 00457 00458 /* 00459 * 64-bit types 00460 */ 00461 00463 llrp_u64_t 00464 get_u64 ( 00465 const CFieldDescriptor * pFieldDesc); 00466 00468 llrp_s64_t 00469 get_s64 ( 00470 const CFieldDescriptor * pFieldDesc); 00471 00473 llrp_u64v_t 00474 get_u64v ( 00475 const CFieldDescriptor * pFieldDesc); 00476 00478 llrp_s64v_t 00479 get_s64v ( 00480 const CFieldDescriptor * pFieldDesc); 00481 00482 /* 00483 * Special types 00484 */ 00485 00487 llrp_u1_t 00488 get_u1 ( 00489 const CFieldDescriptor * pFieldDesc); 00490 00492 llrp_u1v_t 00493 get_u1v ( 00494 const CFieldDescriptor * pFieldDesc); 00495 00497 llrp_u2_t 00498 get_u2 ( 00499 const CFieldDescriptor * pFieldDesc); 00500 00502 llrp_u96_t 00503 get_u96 ( 00504 const CFieldDescriptor * pFieldDesc); 00505 00507 llrp_utf8v_t 00508 get_utf8v ( 00509 const CFieldDescriptor * pFieldDesc); 00510 00512 llrp_bytesToEnd_t 00513 get_bytesToEnd ( 00514 const CFieldDescriptor * pFieldDesc); 00515 00516 /* 00517 * Enumerated types of various sizes 00518 */ 00519 00521 int 00522 get_e1 ( 00523 const CFieldDescriptor * pFieldDesc); 00524 00526 int 00527 get_e2 ( 00528 const CFieldDescriptor * pFieldDesc); 00529 00531 int 00532 get_e8 ( 00533 const CFieldDescriptor * pFieldDesc); 00534 00536 int 00537 get_e16 ( 00538 const CFieldDescriptor * pFieldDesc); 00539 00541 int 00542 get_e32 ( 00543 const CFieldDescriptor * pFieldDesc); 00544 00546 llrp_u8v_t 00547 get_e8v ( 00548 const CFieldDescriptor * pFieldDesc); 00549 00550 /* 00551 * Reserved means some number of bits 00552 */ 00553 /* @brief skips a number of reserved bits and discards during the encode/decode process */ 00554 void 00555 get_reserved ( 00556 unsigned int nBits); 00557 00558 private: 00559 CXMLTextDecoder * m_pDecoder; 00560 CXMLTextDecoderStream * m_pEnclosingDecoderStream; 00561 const CTypeDescriptor * m_pRefType; 00562 struct _xmlNode * m_pTargetNode; 00563 struct _xmlNode * m_pCurrentChildNode; 00564 struct _xmlNode * m_pLastFieldNode; 00565 00566 llrp_bool_t 00567 verifyVectorAllocation ( 00568 const void * pValue, 00569 const CFieldDescriptor * pFieldDescriptor); 00570 00571 static int 00572 isInsignificantNode ( 00573 struct _xmlNode * pnode); 00574 00575 /* some class member field helpers */ 00576 int 00577 getFieldStringPtr( 00578 const CFieldDescriptor * pFieldDescriptor, 00579 const llrp_u8_t ** pbuf, 00580 const llrp_u8_t ** pend); 00581 00582 llrp_s64v_t 00583 getSpacedVectorField ( 00584 const CFieldDescriptor * pFieldDescriptor, 00585 llrp_s64_t minValue, 00586 llrp_s64_t maxValue); 00587 00588 llrp_s64v_t 00589 getFixedVectorField ( 00590 const CFieldDescriptor * pFieldDescriptor, 00591 unsigned int vectorSize, 00592 llrp_s64_t minValue, 00593 llrp_s64_t maxValue); 00594 00595 llrp_s64_t 00596 getIntegerField ( 00597 const CFieldDescriptor * pFieldDescriptor, 00598 llrp_s64_t minValue, 00599 llrp_s64_t maxValue); 00600 00601 llrp_s64_t getInteger( 00602 const CFieldDescriptor * pFieldDescriptor, 00603 const llrp_u8_t * pbuf, 00604 const llrp_u8_t * pend, 00605 CErrorDetails *pError, 00606 llrp_s64_t minValue, 00607 llrp_s64_t maxValue); 00608 00609 /* static string helpers */ 00610 00611 static const llrp_u8_t * 00612 getSingleU1( 00613 const llrp_u8_t * pbuf, 00614 const llrp_u8_t * pend, 00615 llrp_s64_t * pValue); 00616 00617 static const llrp_u8_t * 00618 getSingleEnum( 00619 const CFieldDescriptor * pFieldDescriptor, 00620 const llrp_u8_t * pbuf, 00621 const llrp_u8_t * pend, 00622 llrp_s64_t * pValue); 00623 00624 static const llrp_u8_t * 00625 getSingleDecimal( 00626 const llrp_u8_t * pbuf, 00627 const llrp_u8_t * pend, 00628 llrp_s64_t * pValue); 00629 00630 static const llrp_u8_t * 00631 getSingleHexidecimal( 00632 const llrp_u8_t * pbuf, 00633 const llrp_u8_t * pend, 00634 llrp_s64_t * pValue); 00635 00636 static int 00637 cleanString( 00638 const llrp_u8_t ** ppbuf, 00639 const llrp_u8_t ** ppend); 00640 00641 static const llrp_u8_t * 00642 getSingleTimestamp( 00643 const llrp_u8_t * pbuf, 00644 const llrp_u8_t * pend, 00645 llrp_s64_t * pValue); 00646 00647 static llrp_u16_t 00648 countElements( 00649 const char * pval, 00650 int nval); 00651 00652 private: 00653 static const llrp_s64_t MAX_U8 = ((1ull << 8u) - 1u); 00654 static const llrp_s64_t MIN_U8 = 0ull; 00655 static const llrp_s64_t MAX_S8 = ((1ull << 7u) - 1u); 00656 static const llrp_s64_t MIN_S8 = (-1ll - MAX_S8); 00657 00658 static const llrp_s64_t MAX_U16 = ((1ull << 16u) - 1u); 00659 static const llrp_s64_t MIN_U16 = 0ull; 00660 static const llrp_s64_t MAX_S16 = ((1ull << 15u) - 1u); 00661 static const llrp_s64_t MIN_S16 = (-1ll - MAX_S16); 00662 00663 static const llrp_s64_t MAX_U32 = ((1ull << 32u) - 1u); 00664 static const llrp_s64_t MIN_U32 = 0ull; 00665 static const llrp_s64_t MAX_S32 = ((1ull << 31u) - 1u); 00666 static const llrp_s64_t MIN_S32 = (-1ll - MAX_S32); 00667 00668 static const llrp_s64_t MAX_U64 = ((1ull << 63u) - 1u); // one bit lost 00669 static const llrp_s64_t MIN_U64 = 0ull; 00670 static const llrp_s64_t MAX_S64 = ((1ull << 63u) - 1u); 00671 static const llrp_s64_t MIN_S64 = (-1ll - MAX_S64); 00672 00673 }; 00674 00675 };