- more fixes & improvements for pcap2wav windows build
This commit is contained in:
@@ -58,6 +58,21 @@ bool FileHelper::isAbsolute(const std::string& s)
|
||||
return s.front() == '/' || s.front() == '\\';
|
||||
}
|
||||
|
||||
std::string FileHelper::getCurrentDir()
|
||||
{
|
||||
#if defined(TARGET_WIN)
|
||||
return std::string();
|
||||
#endif
|
||||
|
||||
#if defined(TARGET_LINUX) || defined(TARGET_OSX)
|
||||
char buffer[512];
|
||||
if (getcwd(buf, sizeof buf) != nullptr)
|
||||
return buf;
|
||||
else
|
||||
return std::string();
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string FileHelper::addTrailingSlash(const std::string& s)
|
||||
{
|
||||
if (s.empty())
|
||||
|
||||
@@ -15,6 +15,8 @@ public:
|
||||
static std::string gettempname();
|
||||
static bool isAbsolute(const std::string& s);
|
||||
|
||||
static std::string getCurrentDir();
|
||||
|
||||
static std::string addTrailingSlash(const std::string& s);
|
||||
static std::string mergePathes(const std::string& s1, const std::string& s2);
|
||||
};
|
||||
|
||||
@@ -81,6 +81,7 @@ std::string OsProcess::execCommand(const std::string& cmd)
|
||||
|
||||
std::shared_ptr<std::thread> OsProcess::asyncExecCommand(const std::string& cmdline,
|
||||
std::function<void(const std::string& line)> callback,
|
||||
std::function<void(const std::string& reason)> finished_callback,
|
||||
bool& finish_flag)
|
||||
{
|
||||
std::string output;
|
||||
@@ -117,7 +118,8 @@ std::shared_ptr<std::thread> OsProcess::asyncExecCommand(const std::string& cmdl
|
||||
return std::shared_ptr<std::thread>();
|
||||
}
|
||||
|
||||
std::shared_ptr<std::thread> r = std::make_shared<std::thread>([&finish_flag, pi, callback, hPipeRead, hPipeWrite]()
|
||||
std::shared_ptr<std::thread> r = std::make_shared<std::thread>(
|
||||
[&finish_flag, pi, callback, finished_callback, hPipeRead, hPipeWrite]()
|
||||
{
|
||||
char buf[4096]; memset(buf, 0, sizeof buf);
|
||||
for (; !finish_flag ;)
|
||||
@@ -175,7 +177,8 @@ std::shared_ptr<std::thread> OsProcess::asyncExecCommand(const std::string& cmdl
|
||||
}
|
||||
CloseHandle( pi.hProcess );
|
||||
CloseHandle( pi.hThread );
|
||||
|
||||
if (finished_callback)
|
||||
finished_callback(std::string());
|
||||
});
|
||||
|
||||
return r;
|
||||
|
||||
@@ -52,6 +52,16 @@ void ThreadHelper::setName(const std::string &name)
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t ThreadHelper::getCurrentId()
|
||||
{
|
||||
#if defined(TARGET_WIN)
|
||||
return static_cast<uint64_t>(GetCurrentThreadId());
|
||||
#endif
|
||||
|
||||
#if defined(TARGET_LINUX)||defined(TARGET_OSX)
|
||||
return static_cast<uint64_t>(pthread_self());
|
||||
#endif
|
||||
}
|
||||
// ------------------- TimeHelper ---------------
|
||||
using namespace std::chrono;
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ class ThreadHelper
|
||||
{
|
||||
public:
|
||||
static void setName(const std::string& name);
|
||||
static uint64_t getCurrentId();
|
||||
};
|
||||
|
||||
class TimeHelper
|
||||
|
||||
Reference in New Issue
Block a user