int CMyApplication::run ( char * pReaderHostName) { CTypeRegistry * pTypeRegistry; CConnection * pConn; int rc; /* * Allocate the type registry. This is needed * by the connection to decode. */ pTypeRegistry = getTheTypeRegistry(); if(NULL == pTypeRegistry) { printf("ERROR: getTheTypeRegistry failed\n"); return -1; } /* * Construct a connection (LLRP::CConnection). * Using a 32kb max frame size for send/recv. * The connection object is ready for business * but not actually connected to the reader yet. */ pConn = new CConnection(pTypeRegistry, 32u*1024u); if(NULL == pConn) { printf("ERROR: new CConnection failed\n"); return -2; } /* * Open the connection to the reader */ if(m_Verbose) { printf("INFO: Connecting to %s....\n", pReaderHostName); } rc = pConn->openConnectionToReader(pReaderHostName); if(0 != rc) { printf("ERROR: connect: %s (%d)\n", pConn->getConnectError(), rc); delete pConn; return -3; } /* * Record the pointer to the connection object so other * routines can use it. */ m_pConnectionToReader = pConn; if(m_Verbose) { printf("INFO: Connected, checking status....\n"); } /* * Commence the sequence and check for errors as we go. * See comments for each routine for details. * Each routine prints messages. */ rc = 1; if(0 == checkConnectionStatus()) { rc = 2; if(0 == scrubConfiguration()) { rc = 3; if(0 == addROSpec()) { rc = 4; if(0 == enableROSpec()) { int i; rc = 5; for(i = 1; i <= 5; i++) { printf("INFO: Starting run %d ================\n", i); if(0 != startROSpec()) { /* already tattled */ break; } if(0 != awaitAndPrintReport()) { /* already tattled */ break; } } if(5 == i) { rc = 0; } } } /* * After we're done, try to leave the reader * in a clean state for next use. This is best * effort and no checking of the result is done. */ if(m_Verbose) { printf("INFO: Clean up reader configuration...\n"); } scrubConfiguration(); } } if(m_Verbose) { printf("INFO: Finished\n"); } /* * Close the connection and release its resources */ pConn->closeConnectionToReader(); delete pConn; /* * Done with the registry. */ delete pTypeRegistry; /* * When we get here all allocated memory should have been deallocated. */ return rc; }