-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Pelanek
committed
Jun 13, 2024
1 parent
455a1b2
commit dbacce2
Showing
4 changed files
with
123 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* @file | ||
* @author Daniel Pelanek <xpeland00@vutbr.cz> | ||
* @brief | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#include <telemetry.hpp> | ||
#include <appFs.hpp> | ||
|
||
// example help | ||
#include <string> | ||
#include <iostream> | ||
|
||
void traverseDir(std::shared_ptr<telemetry::Directory>& dir, int depth) { | ||
// Using utils to check if a directory is a root directory | ||
if(telemetry::utils::isRootDirectory(dir->getFullPath())) { | ||
std::cout << "start\n"; | ||
} | ||
|
||
// looping through files and dirs in directory | ||
// listEntries returns their names as string | ||
for(auto node_name : dir->listEntries()) { | ||
auto node = dir->getEntry(node_name); | ||
|
||
std::cout << std::string(depth * 4, ' ') << node_name << "\n"; | ||
|
||
// Using utils to check if a node is a directory | ||
if(telemetry::utils::isDirectory(node)) { | ||
// dynamic_pointer_cast is needed to get a file or dir from node | ||
auto newDir = std::dynamic_pointer_cast<telemetry::Directory>(node); | ||
traverseDir(newDir, depth + 1); | ||
|
||
// Using utils to check if a node is a file | ||
} else if(telemetry::utils::isFile(node)) { | ||
auto file = std::dynamic_pointer_cast<telemetry::File>(node); | ||
|
||
// Manually reading file content | ||
try { | ||
std::cout << telemetry::contentToString(file->read()); | ||
} catch(std::exception& ex) { | ||
std::cout << ex.what() << "\n"; | ||
} | ||
} | ||
} | ||
} | ||
|
||
int main() { | ||
// Same as basic example | ||
std::shared_ptr<telemetry::Directory> telemetryRootNode; | ||
telemetryRootNode = telemetry::Directory::create(); | ||
|
||
std::string fusePath = "fusedir"; | ||
|
||
telemetry::appFs::AppFsFuse fuse = telemetry::appFs::AppFsFuse(telemetryRootNode, fusePath); | ||
fuse.start(); | ||
|
||
// Let's create a more complex dir structure | ||
telemetry::FileOps const emptyFileOps | ||
= {nullptr, nullptr}; | ||
|
||
auto file1 = telemetryRootNode->addFile("file1", emptyFileOps); | ||
auto file2 = telemetryRootNode->addFile("file2", emptyFileOps); | ||
auto dir1 = telemetryRootNode->addDir("dir1"); | ||
|
||
auto file3 = dir1->addFile("file3", emptyFileOps); | ||
auto dir2 = dir1->addDir("dir2"); | ||
auto dir3 = dir1->addDir("dir3"); | ||
|
||
const int nFiles = 5; | ||
for(int index = 0; index < nFiles; index++) { | ||
auto file = dir2->addFile("file" + std::to_string(index + 4), emptyFileOps); | ||
} | ||
|
||
auto file9 = dir3->addFile("file9", emptyFileOps); | ||
|
||
// And now traverse the directory with the use of telemetry utils | ||
traverseDir(telemetryRootNode, 0); | ||
|
||
// Utils can also give you a node from path | ||
auto node = telemetry::utils::getNodeFromPath(telemetryRootNode, "/dir1/dir2/file5"); | ||
} |