LTKCPP-- LLRP Toolkit C Plus Plus Library
|
00001 /* 00002 ***************************************************************************** 00003 * * 00004 * IMPINJ CONFIDENTIAL AND PROPRIETARY * 00005 * * 00006 * This source code is the sole property of Impinj, Inc. Reproduction or * 00007 * utilization of this source code in whole or in part is forbidden without * 00008 * the prior written consent of Impinj, Inc. * 00009 * * 00010 * (c) Copyright Impinj, Inc. 2007,2008. All rights reserved. * 00011 * * 00012 *****************************************************************************/ 00013 #ifndef __LTKCPP_CONNECTION_H__ 00014 #define __LTKCPP_CONNECTION_H__ 00015 00016 // Forward declaration for OpenSSL's BIO object. 00017 struct bio_st; 00018 00027 namespace LLRP 00028 { 00029 00059 class CConnection 00060 { 00061 public: 00062 CConnection ( 00063 const CTypeRegistry * pTypeRegistry, 00064 unsigned int nBufferSize); 00065 00066 ~CConnection (void); 00067 00068 int 00069 openConnectionToReader ( 00070 const char * pReaderHostName); 00071 00072 int 00073 openSecureConnectionToReader(const char* pReaderHostName); 00074 00075 const char * 00076 getConnectError (void); 00077 00078 int 00079 closeConnectionToReader (void); 00080 00081 CMessage * 00082 transact ( 00083 CMessage * pSendMessage, 00084 int nMaxMS); 00085 00086 const CErrorDetails * 00087 getTransactError (void); 00088 00089 EResultCode 00090 sendMessage ( 00091 CMessage * pMessage); 00092 00093 const CErrorDetails * 00094 getSendError (void); 00095 00096 CMessage * 00097 recvMessage ( 00098 int nMaxMS); 00099 00100 CMessage * 00101 recvResponse ( 00102 int nMaxMS, 00103 const CTypeDescriptor * pResponseType, 00104 llrp_u32_t ResponseMessageID); 00105 00106 const CErrorDetails * 00107 getRecvError (void); 00108 00109 private: 00110 enum E_LLRP_CONNECTION_TYPE 00111 { 00112 E_LLRP_CONNECTION_TYPE_UNSECURE, 00113 E_LLRP_CONNECTION_TYPE_SSL 00114 }; 00115 00117 struct bio_st * m_pBio; 00118 00120 const char * m_pConnectErrorStr; 00121 00123 const CTypeRegistry * m_pTypeRegistry; 00124 00126 std::list<CMessage *> m_listInputQueue; 00127 00129 unsigned int m_nBufferSize; 00130 00132 struct RecvState 00133 { 00135 llrp_byte_t * pBuffer; 00136 00138 unsigned int nBuffer; 00139 00143 int bFrameValid; 00144 00146 CFrameExtract FrameExtract; 00147 00149 CErrorDetails ErrorDetails; 00150 } m_Recv; 00151 00153 struct SendState 00154 { 00156 llrp_byte_t * pBuffer; 00157 00159 unsigned int nBuffer; 00160 00162 CErrorDetails ErrorDetails; 00163 } m_Send; 00164 00165 private: 00166 // These functions are a no-op on Linux, always returning 0. On Windows, it 00167 // loads/unloads the Winsock DLL and returns 0 if successful, otherwise it returns 00168 // the error code provided by Winsock. 00169 int initializeWinsock(); 00170 int shutdownWinsock(); 00171 00172 int initializeSslBio(bio_st** ppBio); 00173 int openSocketConnection(const char* pkzReaderHostName, const char* pkzPort, unsigned long* phSocket); 00174 int openConnectionToReader(const char* pReaderHostName, E_LLRP_CONNECTION_TYPE eType); 00175 00176 EResultCode 00177 recvAdvance ( 00178 int nMaxMS, 00179 time_t timeLimit); 00180 00181 time_t 00182 calculateTimeLimit ( 00183 int nMaxMS); 00184 00185 void initializeOpenSSL(); 00186 }; 00187 00188 }; /* namespace LLRP */ 00189 00190 #endif // __LTKCPP_CONNECTION_H__