//-------------------------------------------------------------------------------------------------- le_result_t ni_GetPathForNode ( ni_IteratorRef_t iteratorRef, ///< The iterator object to access. const char* subPathPtr, ///< Optional, can be used to specify a node relative to the ///< current one. char* destBufferPtr, ///< The buffer to copy string data into. size_t bufferMax ///< The maximum size of the string buffer. ) //-------------------------------------------------------------------------------------------------- { LE_ASSERT(iteratorRef != NULL); LE_ASSERT(destBufferPtr != NULL); LE_ASSERT(bufferMax > 0); // Check to see if they're looking for a path to a node relative to the current one. if ( (subPathPtr != NULL) && (strcmp(subPathPtr, "") != 0)) { // Build up a new path based on the existing path. le_pathIter_Ref_t newPathRef = le_pathIter_Clone(iteratorRef->pathIterRef); le_result_t result = le_pathIter_Append(newPathRef, subPathPtr); if (result == LE_OVERFLOW) { tu_TerminateClient(iteratorRef->sessionRef, "Specified path too large."); } else if (result == LE_UNDERFLOW) { tu_TerminateClient(iteratorRef->sessionRef, "Specified path attempts to iterate below root."); } else { result = le_pathIter_GetPath(newPathRef, destBufferPtr, bufferMax); } le_pathIter_Delete(newPathRef); return result; } // Simply return the current path. return le_pathIter_GetPath(iteratorRef->pathIterRef, destBufferPtr, bufferMax); }
static void IteratePath ( le_pathIter_Ref_t iteratorRef, const char* originalPath, const char* nodes[] ) { char fullPath[LARGE_BUFFER_SIZE] = { 0 }; le_pathIter_GetPath(iteratorRef, fullPath, LARGE_BUFFER_SIZE); LE_INFO("Iterating path %s.", fullPath); LE_TEST(strcmp(fullPath, originalPath) == 0); le_pathIter_GoToStart(iteratorRef); ssize_t index = 0; LE_INFO(">>>> Forward Iteration >>>>"); do { char buffer[LARGE_BUFFER_SIZE] = { 0 }; LE_TEST(le_pathIter_GetCurrentNode(iteratorRef, buffer, LARGE_BUFFER_SIZE) != LE_OVERFLOW); LE_INFO("> Found: %s, Expect: %s", buffer, nodes[index]); LE_TEST(strcmp(buffer, nodes[index]) == 0); index++; } while (le_pathIter_GoToNext(iteratorRef) != LE_NOT_FOUND); --index; LE_INFO("<<<< Reverse Iteration <<<<"); le_pathIter_GoToEnd(iteratorRef); do { char buffer[LARGE_BUFFER_SIZE] = { 0 }; LE_TEST(le_pathIter_GetCurrentNode(iteratorRef, buffer, LARGE_BUFFER_SIZE) != LE_OVERFLOW); LE_INFO("< Found: %s, Expect: %s", buffer, nodes[index]); LE_TEST(strcmp(buffer, nodes[index]) == 0); index--; } while (le_pathIter_GoToPrev(iteratorRef) != LE_NOT_FOUND); LE_TEST(index == -1); }
static bool TestPath ( le_pathIter_Ref_t iteratorRef, const char* pathStrPtr ) { char fullPath[LARGE_BUFFER_SIZE] = { 0 }; LE_ASSERT(le_pathIter_GetPath(iteratorRef, fullPath, LARGE_BUFFER_SIZE) == LE_OK); LE_INFO("Compare path, got: '%s', expected: '%s'", fullPath, pathStrPtr); return strcmp(fullPath, pathStrPtr) == 0; }