Skip to content

Commit

Permalink
PR #11830 from noacoohen:create rsutils-os.cpp, rsutils-os.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Nir-Az committed May 23, 2023
2 parents 0be8984 + 6b68a8f commit 6fc74d6
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 44 deletions.
3 changes: 2 additions & 1 deletion common/device-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "imgui-fonts-monofont.hpp"

#include "os.h"
#include <rsutils/os/os.h>
#include "viewer.h"
#include "on-chip-calib.h"
#include "subdevice-model.h"
Expand Down Expand Up @@ -122,7 +123,7 @@ namespace rs2
ss << "| | |\n";
ss << "|---|---|\n";
ss << "|**librealsense**|" << api_version_to_string(rs2_get_api_version(&e)) << (is_debug() ? " DEBUG" : " RELEASE") << "|\n";
ss << "|**OS**|" << get_os_name() << "|\n";
ss << "|**OS**|" << rsutils::os::get_os_name() << "|\n";

for (auto& dm : devices)
{
Expand Down
17 changes: 0 additions & 17 deletions common/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,23 +361,6 @@ Some auxillary functionalities might be affected. Please report this message if
return j == prefix.end();
}
std::string get_os_name()
{
#ifdef _WIN32
return "Windows";
#else
#ifdef __APPLE__
return "Mac OS";
#else
#ifdef __linux__
return "Linux";
#else
return "Unknown";
#endif
#endif
#endif
}
bool is_debug()
{
#ifndef NDEBUG
Expand Down
2 changes: 0 additions & 2 deletions common/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,5 @@ namespace rs2

std::string url_encode(const std::string &value);

std::string get_os_name();

bool is_debug();
}
26 changes: 3 additions & 23 deletions common/sw-update/versions-db-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "json.hpp"
#include "versions-db-manager.h"
#include <types.h>
#include <rsutils/os/os.h>

namespace rs2
{
Expand All @@ -17,27 +18,6 @@ namespace rs2
using json = nlohmann::json;
using namespace http;

// Get current platform
constexpr const char* PLATFORM =

#ifdef _WIN64
"Windows amd64";
#elif _WIN32
"Windows x86";
#elif __linux__
#ifdef __arm__
"Linux arm";
#else
"Linux amd64";
#endif
#elif __APPLE__
"Mac OS";
#elif __ANDROID__
"Linux arm";
#else
"";
#endif

query_status_type versions_db_manager::query_versions(const std::string &device_name, component_part_type component, const update_policy_type policy, version& out_version)
{
// Load server versions info on first access
Expand All @@ -47,7 +27,7 @@ namespace rs2
return DB_LOAD_FAILURE;
}

std::string platform(PLATFORM);
std::string platform = rsutils::os::get_platform_name();

std::string up_str(to_string(policy));
std::string comp_str(to_string(component));
Expand Down Expand Up @@ -77,7 +57,7 @@ namespace rs2
// Check if server versions are loaded
if (!_server_versions_loaded) return false;

std::string platform = PLATFORM;
std::string platform = rsutils::os::get_platform_name();

std::string component_str(to_string(component));

Expand Down
3 changes: 2 additions & 1 deletion common/windows-app-bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <csignal>

#include "os.h"
#include <rsutils/os/os.h>
#include "metadata-helper.h"
#include "rendering.h"
#include <rsutils/string/windows.h>
Expand Down Expand Up @@ -98,7 +99,7 @@ void report_error(std::string error)
ss << "| | |\n";
ss << "|---|---|\n";
ss << "|**librealsense**|" << rs2::api_version_to_string(rs2_get_api_version(&e)) << (rs2::is_debug() ? " DEBUG" : " RELEASE") << "|\n";
ss << "|**OS**|" << rs2::get_os_name() << "|\n\n";
ss << "|**OS**|" << rsutils::os::get_os_name() << "|\n\n";
ss << "Intel RealSense Viewer / Depth Quality Tool has crashed with the following error message:\n";
ss << "```\n";
ss << error;
Expand Down
15 changes: 15 additions & 0 deletions third-party/rsutils/include/rsutils/os/os.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2023 Intel Corporation. All Rights Reserved.

#pragma once
#include <string>

namespace rsutils
{
namespace os
{
std::string get_os_name();
std::string get_platform_name();

}
}
51 changes: 51 additions & 0 deletions third-party/rsutils/src/os.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2023 Intel Corporation. All Rights Reserved.

#include <rsutils/os/os.h>

namespace rsutils
{
namespace os
{
std::string get_os_name()
{
#ifdef _WIN32
return "Windows";
#else
#ifdef __APPLE__
return "Mac OS";
#else
#ifdef __linux__
return "Linux";
#else
return "Unknown";
#endif
#endif
#endif
}

std::string get_platform_name()
{
#ifdef _WIN64
return "Windows amd64";
#elif _WIN32
return "Windows x86";
#elif __linux__
#ifdef __arm__
return "Linux arm";
#else
return "Linux amd64";
#endif
#elif __APPLE__
return "Mac OS";
#elif __ANDROID__
return "Linux arm";
#else
return "";
#endif

}

}
}

0 comments on commit 6fc74d6

Please sign in to comment.