Skip to content

Commit

Permalink
Test for linking asio manager, incomplete not working
Browse files Browse the repository at this point in the history
  • Loading branch information
itsafuu committed Jan 25, 2024
1 parent b9d3d6a commit d9f9436
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
8 changes: 8 additions & 0 deletions build/CommonBuildParameters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ set(xxhash_DIR "${_THIRDPARTY_BUILD_DIR}/xxhash/lib/cmake/xxhash")
find_package(xxhash CONFIG REQUIRED)
include_directories(${xxhash_INCLUDE_DIR})

# --------------------------------------------------------
# Set config of AsyncIOManager
set(AsyncIOManager_INCLUDE_DIR "${_THIRDPARTY_BUILD_DIR}/AsyncIOManager/include")
set(AsyncIOManager_LIBRARY_DIR "${_THIRDPARTY_BUILD_DIR}/AsyncIOManager/lib")
set(AsyncIOManager_DIR "${_THIRDPARTY_BUILD_DIR}/AsyncIOManager/lib/cmake/AsyncIOManager")
find_package(AsyncIOManager CONFIG REQUIRED)
include_directories(${AsyncIOManager_INCLUDE_DIR})

# --------------------------------------------------------
include_directories(
Expand Down Expand Up @@ -299,6 +306,7 @@ endif ()
if (BUILD_EXAMPLES)
add_subdirectory(${PROJECT_ROOT}/example ${CMAKE_BINARY_DIR}/example)
endif ()
add_subdirectory(${PROJECT_ROOT}/example/AsyncFile ${CMAKE_BINARY_DIR}/example/AsyncFile)

install(
EXPORT supergeniusTargets
Expand Down
5 changes: 5 additions & 0 deletions example/AsyncFile/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#add_subdirectory(application)
FILE(GLOB MNN_LIBS "${MNN_LIBRARY_DIR}/*")
add_executable(MNNExample MNNExample.cpp)
target_link_libraries(MNNExample PRIVATE AsyncIOManager)
include_directories(../include)
138 changes: 138 additions & 0 deletions example/AsyncFile/MNNExample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
//#define BOOST_ASIO_HAS_IO_URING 1 //Linux
//#define BOOST_ASIO_DISABLE_EPOLL 0 //Maybe linux?
#include <iostream>
#include <string>
#include <vector>
#include "Singleton.hpp"
#include "FileManager.hpp"
//#include "MNNLoader.hpp"
//#include "IPFSLoader.hpp"
//#include "HTTPLoader.hpp"
//#include "SFTPLoader.hpp"
//#include "WSLoader.hpp"
#include "URLStringUtil.h"
#include <libp2p/injector/host_injector.hpp>


/**
* This program is example to loading MNN model file
*/
//#define IPFS_FILE_PATH_NAME "ipfs://example.mnn"
#define FILE_PATH_NAME "file://../test/1.mnn"
#define FILE_SAVE_NAME "file://test.mnn"
void loadhandler(boost::system::error_code ec, std::size_t n, std::vector<char>& buffer) {
if (!ec) {
std::cout << "Received data: ";
std::cout << std::endl;
std::cout << "Handler Out Size:" << n << std::endl;
}
else {
std::cerr << "Error in async_read: " << ec.message() << std::endl;
}
}


int main(int argc, char **argv)
{
std::string file_name = "";
std::vector<string> file_names(0);
std::cout << "argcount" << argc << std::endl;
if (argc < 2)
{
std::cout << argv[0] << " [MNN extension file]" << std::endl;
std::cout << "E.g:" << std::endl;
std::cout << "\t " << argv[0] << " file://../test/1.mnn" << std::endl;
return 1;
}
else
{
file_name = std::string(argv[1]);
for (int i = 1; i < argc; i++)
{
std::cout << "file: " << argv[i] << std::endl;
file_names.push_back(argv[i]);
}
}
// return 1;
// this should all be moved to GTest
// Break out the URL prefix, file path, and extension.
std::string url_prefix;
std::string file_path;
std::string extension;
std::string http_host;
std::string http_path;

getURLComponents(
"https://www.example.com/test.jpg",
url_prefix, file_path, extension);
//Print the results.
//cout << "urlPrefix: " << url_prefix << endl;
//cout << "filePath: " << file_path << endl;
//cout << "extension: " << extension << endl;
//parseHTTPUrl(file_path, http_host, http_path);
//std::cout << "http host:" << http_host << std::endl;
//std::cout << "http path:" << http_path << std::endl;

// getURLComponents("file://./test.mnn", url_prefix, file_path, extension);
// Print the results.
// cout << "urlPrefix: " << url_prefix << endl;
//cout << "filePath: " << file_path << endl;
//cout << "extension: " << extension << endl;

// getURLComponents("ipfs://really/long/path/to/a/file/testme.jpg",
// url_prefix, file_path, extension);
// Print the results.
//cout << "urlPrefix: " << url_prefix << endl;
//cout << "filePath: " << file_path << endl;
//cout << "extension: " << extension << endl;
std::cout << "hmm" << std::endl;


// test plugins
if (file_name.empty())
{
file_name = FILE_PATH_NAME;
}

//auto ioc = std::make_shared<boost::asio::io_context>();

auto injector = libp2p::injector::makeHostInjector();
auto ioc = injector.create<std::shared_ptr<boost::asio::io_context>>();

// Create a work guard to keep the io_context alive
boost::asio::io_context::executor_type executor = ioc->get_executor();
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> workGuard(executor);

auto dummyCallback = [](std::shared_ptr<boost::asio::io_context>, std::shared_ptr<std::vector<char>>, bool parse, bool save) {
// Do nothing
};
for (int i = 0; i < file_names.size(); i++)
{
std::cout << "LoadASync: " << file_names[i] << std::endl;
auto data = FileManager::GetInstance().LoadASync(file_names[i], true, true, ioc, dummyCallback, [](const int& status)
{
std::cout << "status: " << status << std::endl;
});
//FileManager::GetInstance().IncrementOutstandingOperations();

//std::cout << "LoadFile: " << file_names[i] << std::endl;
//auto data = FileManager::GetInstance().LoadFile(file_names[i], false);

//std::cout << "LoadFile with Parse: " << file_names[i] << std::endl;
//data = FileManager::GetInstance().LoadFile(file_names[i], true);
//std::cout << "ParseFile: " << std::endl;
//FileManager::GetInstance().ParseData("mnn", data);
//std::cout << "SaveFile: Save to " << FILE_SAVE_NAME;
//FileManager::GetInstance().SaveFile(FILE_SAVE_NAME, data);
//std::cout << std::endl;
//boost::asio::post(ioc, postload);
}
//std::thread([ioc]() {
// ioc->run();
// }).detach();
ioc->reset();
ioc->run();

return 0;
}

0 comments on commit d9f9436

Please sign in to comment.