-
Notifications
You must be signed in to change notification settings - Fork 194
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
Showing
15 changed files
with
209 additions
and
18 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
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,49 @@ | ||
#include "ExecArgConverter.h" | ||
|
||
#include "MaaFramework/MaaAPI.h" | ||
#include "Utils/ImageIo.h" | ||
#include "Utils/Logger.h" | ||
#include "Utils/Time.hpp" | ||
|
||
MAA_TOOLKIT_NS_BEGIN | ||
|
||
ExecArgConverter::~ExecArgConverter() | ||
{ | ||
for (const auto& image : images_) { | ||
std::filesystem::remove(image); | ||
} | ||
} | ||
|
||
std::string ExecArgConverter::sync_context_to_arg(MaaSyncContextHandle sync_context) | ||
{ | ||
std::string uuid = std::to_string(reinterpret_cast<uintptr_t>(sync_context)); | ||
sync_contexts_.insert_or_assign(uuid, sync_context); | ||
return uuid; | ||
} | ||
|
||
std::string ExecArgConverter::image_to_arg(ImageTransferMode mode, const cv::Mat& image) | ||
{ | ||
switch (mode) { | ||
case ImageTransferMode::FileIO: { | ||
auto path = std::filesystem::temp_directory_path() / now_filestem() / ".png"; | ||
imwrite(path, image); | ||
images_.push_back(path); | ||
return path_to_crt_string(path); | ||
} | ||
default: | ||
LogError << "not implemented"; | ||
return {}; | ||
} | ||
} | ||
|
||
MaaSyncContextHandle ExecArgConverter::arg_to_sync_context(const std::string& arg) const | ||
{ | ||
auto it = sync_contexts_.find(arg); | ||
if (it == sync_contexts_.end()) { | ||
LogError << "sync context not found"; | ||
return nullptr; | ||
} | ||
return it->second; | ||
} | ||
|
||
MAA_TOOLKIT_NS_END |
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,30 @@ | ||
#pragma once | ||
|
||
#include "Conf/Conf.h" | ||
|
||
#include <filesystem> | ||
#include <map> | ||
|
||
#include "ExecAgentType.h" | ||
#include "MaaFramework/MaaDef.h" | ||
#include "Utils/NoWarningCVMat.hpp" | ||
|
||
MAA_TOOLKIT_NS_BEGIN | ||
|
||
class ExecArgConverter | ||
{ | ||
public: | ||
~ExecArgConverter(); | ||
|
||
public: | ||
std::string sync_context_to_arg(MaaSyncContextHandle sync_context); | ||
std::string image_to_arg(ImageTransferMode mode, const cv::Mat& image); | ||
|
||
MaaSyncContextHandle arg_to_sync_context(const std::string& arg) const; | ||
|
||
private: | ||
std::map<std::string, MaaSyncContextHandle> sync_contexts_; | ||
std::vector<std::filesystem::path> images_; | ||
}; | ||
|
||
MAA_TOOLKIT_NS_END |
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
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