v4.14.0 (#9)
This commit is contained in:
committed by
GitHub
parent
86bb9c4968
commit
9bce73eb42
@@ -160,48 +160,40 @@ Expected<ArpTable> ArpTable::create(uint32_t interface_index)
|
||||
return result;
|
||||
}
|
||||
|
||||
hailo_status EthernetUtils::get_interface_from_board_ip(const char *board_ip, char *interface_name, size_t interface_name_length)
|
||||
Expected<std::string> EthernetUtils::get_interface_from_board_ip(const std::string &board_ip)
|
||||
{
|
||||
CHECK_ARG_NOT_NULL(interface_name);
|
||||
CHECK_ARG_NOT_NULL(board_ip);
|
||||
|
||||
auto network_interfaces = NetworkInterface::get_all_interfaces();
|
||||
CHECK_EXPECTED_AS_STATUS(network_interfaces);
|
||||
CHECK_EXPECTED(network_interfaces);
|
||||
|
||||
struct in_addr board_ip_struct{};
|
||||
auto status = Socket::pton(AF_INET, board_ip, &board_ip_struct);
|
||||
CHECK_SUCCESS(status, "Invalid board ip address {}", board_ip);
|
||||
auto status = Socket::pton(AF_INET, board_ip.c_str(), &board_ip_struct);
|
||||
CHECK_SUCCESS_AS_EXPECTED(status, "Invalid board ip address {}", board_ip);
|
||||
|
||||
for (const auto& network_interface : network_interfaces.value()) {
|
||||
auto arp_table = ArpTable::create(network_interface.index());
|
||||
CHECK_EXPECTED_AS_STATUS(arp_table);
|
||||
CHECK_EXPECTED(arp_table);
|
||||
|
||||
const auto mac_address = arp_table->get_mac_address(static_cast<uint32_t>(board_ip_struct.S_un.S_addr));
|
||||
if (mac_address) {
|
||||
(void)strncpy(interface_name, network_interface.friendly_name().c_str(), interface_name_length);
|
||||
return HAILO_SUCCESS;
|
||||
return network_interface.friendly_name();
|
||||
}
|
||||
}
|
||||
|
||||
return HAILO_ETH_INTERFACE_NOT_FOUND;
|
||||
return make_unexpected(HAILO_ETH_INTERFACE_NOT_FOUND);
|
||||
}
|
||||
|
||||
hailo_status EthernetUtils::get_ip_from_interface(const char *interface_name, char *ip, size_t ip_length)
|
||||
Expected<std::string> EthernetUtils::get_ip_from_interface(const std::string &interface_name)
|
||||
{
|
||||
CHECK_ARG_NOT_NULL(interface_name);
|
||||
CHECK_ARG_NOT_NULL(ip);
|
||||
|
||||
auto network_interfaces = NetworkInterface::get_all_interfaces();
|
||||
CHECK_EXPECTED_AS_STATUS(network_interfaces);
|
||||
CHECK_EXPECTED(network_interfaces);
|
||||
|
||||
for (const auto& network_interface : network_interfaces.value()) {
|
||||
if (network_interface.friendly_name() == interface_name) {
|
||||
(void)strncpy(ip, network_interface.ip().c_str(), ip_length);
|
||||
return HAILO_SUCCESS;
|
||||
return network_interface.ip();
|
||||
}
|
||||
}
|
||||
|
||||
return HAILO_ETH_INTERFACE_NOT_FOUND;
|
||||
return make_unexpected(HAILO_ETH_INTERFACE_NOT_FOUND);
|
||||
}
|
||||
|
||||
} /* namespace hailort */
|
||||
|
||||
@@ -164,6 +164,13 @@ hailo_status Filesystem::create_directory(const std::string &dir_path)
|
||||
return HAILO_SUCCESS;
|
||||
}
|
||||
|
||||
hailo_status Filesystem::remove_directory(const std::string &dir_path)
|
||||
{
|
||||
bool was_removed = RemoveDirectoryA(dir_path.c_str());
|
||||
CHECK(was_removed, HAILO_FILE_OPERATION_FAILURE, "Failed to remove directory {}", dir_path);
|
||||
return HAILO_SUCCESS;
|
||||
}
|
||||
|
||||
bool Filesystem::is_path_accesible(const std::string &path)
|
||||
{
|
||||
// The code is based on examples from: https://cpp.hotexamples.com/examples/-/-/AccessCheck/cpp-accesscheck-function-examples.html
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
**/
|
||||
|
||||
#include "common/os_utils.hpp"
|
||||
#include "common/utils.hpp"
|
||||
#include "hailo/hailort.h"
|
||||
|
||||
#include <windows.h>
|
||||
@@ -29,6 +30,54 @@ uint32_t OsUtils::get_curr_pid()
|
||||
return static_cast<uint32_t>(GetCurrentProcessId());
|
||||
}
|
||||
|
||||
bool OsUtils::is_pid_alive(uint32_t pid)
|
||||
{
|
||||
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
|
||||
if (hProcess == NULL) {
|
||||
// Process is not running
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD exitCode;
|
||||
BOOL result = GetExitCodeProcess(hProcess, &exitCode);
|
||||
|
||||
CloseHandle(hProcess);
|
||||
|
||||
if (result && exitCode == STILL_ACTIVE) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void OsUtils::set_current_thread_name(const std::string &name)
|
||||
{
|
||||
(void)name;
|
||||
}
|
||||
|
||||
hailo_status OsUtils::set_current_thread_affinity(uint8_t cpu_index)
|
||||
{
|
||||
const DWORD_PTR affinity_mask = static_cast<DWORD_PTR>(1ULL << cpu_index);
|
||||
CHECK(0 != SetThreadAffinityMask(GetCurrentThread(), affinity_mask), HAILO_INTERNAL_FAILURE,
|
||||
"SetThreadAffinityMask failed. LE={}", GetLastError());
|
||||
|
||||
return HAILO_SUCCESS;
|
||||
}
|
||||
|
||||
static size_t get_page_size_impl()
|
||||
{
|
||||
SYSTEM_INFO system_info{};
|
||||
GetSystemInfo(&system_info);
|
||||
return system_info.dwPageSize;
|
||||
}
|
||||
|
||||
size_t OsUtils::get_page_size()
|
||||
{
|
||||
static const auto page_size = get_page_size_impl();
|
||||
return page_size;
|
||||
}
|
||||
|
||||
CursorAdjustment::CursorAdjustment()
|
||||
{
|
||||
// Enables Vitual Terminal Processing - enables ANSI Escape Sequences on Windows
|
||||
|
||||
Reference in New Issue
Block a user