Precommit (#1)

* first commit

* cleanup
This commit is contained in:
tompzf
2025-11-04 13:28:06 +01:00
committed by GitHub
parent dba45dc636
commit 6ed4b1534e
898 changed files with 256340 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
# Define project
project(manifest_util VERSION 1.0 LANGUAGES CXX)
# Define target
add_library(manifest_util SHARED
"manifest_util.h"
"manifest_util.cpp")
if (WIN32)
target_link_libraries(manifest_util ${CMAKE_THREAD_LIBS_INIT} Rpcrt4.lib)
elseif(UNIX)
target_link_libraries(manifest_util rt ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()
target_link_options(manifest_util PRIVATE)
target_include_directories(manifest_util PRIVATE ./include/)
set_target_properties(manifest_util PROPERTIES PREFIX "")
set_target_properties(manifest_util PROPERTIES SUFFIX ".sdv")
# Build dependencies
add_dependencies(manifest_util CompileCoreIDL)
# Appending the service in the service list
set(SDV_Service_List ${SDV_Service_List} manifest_util PARENT_SCOPE)

View File

@@ -0,0 +1,70 @@
#include "manifest_util.h"
#include <string>
#include <filesystem>
#ifdef _WIN32
#pragma push_macro("interface")
#undef interface
#pragma push_macro("GetObject")
#undef GetObject
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <WinSock2.h>
#include <Windows.h>
#elif defined __unix__
#else
#error OS is not supported!
#endif
sdv::u8string CManifestUtil::ReadModuleManifest(/*in*/ const sdv::u8string& ssModule)
{
sdv::u8string ssManifest;
std::filesystem::path pathModule(static_cast<std::string>(ssModule));
if (!std::filesystem::exists(pathModule)) return ssManifest;
// Load the module
#ifdef _WIN32
sdv::core::TModuleID tModuleID = reinterpret_cast<sdv::core::TModuleID>(LoadLibrary(pathModule.native().c_str()));
#elif defined __unix__
sdv::core::TModuleID tModuleID = reinterpret_cast<sdv::core::TModuleID>(dlopen(pathModule.native().c_str(), RTLD_LAZY));
#else
#error OS not supported!
#endif
if (!tModuleID) return ssManifest;
// Check whether the module exposes the necessary functions
using TFNHasActiveObjects = bool();
using TFNGetModuleFactory = sdv::IInterfaceAccess*(uint32_t);
using TFNGetManifest = const char*();
#ifdef _WIN32
std::function<TFNGetModuleFactory> fnGetFactory = reinterpret_cast<TFNGetModuleFactory*>(GetProcAddress(reinterpret_cast<HMODULE>(tModuleID), "GetModuleFactory"));
std::function<TFNHasActiveObjects> fnActiveObjects = reinterpret_cast<TFNHasActiveObjects*>(GetProcAddress(reinterpret_cast<HMODULE>(tModuleID), "HasActiveObjects"));
std::function<TFNGetManifest> fnGetManifest = reinterpret_cast<TFNGetManifest*>(GetProcAddress(reinterpret_cast<HMODULE>(tModuleID), "GetManifest"));
#elif defined __unix__
std::function<TFNGetModuleFactory> fnGetFactory = reinterpret_cast<TFNGetModuleFactory*>(dlsym(reinterpret_cast<void*>(tModuleID), "GetModuleFactory"));
std::function<TFNHasActiveObjects> fnActiveObjects = reinterpret_cast<TFNHasActiveObjects*>(dlsym(reinterpret_cast<void*>(tModuleID), "HasActiveObjects"));
std::function<TFNGetManifest> fnGetManifest = reinterpret_cast<TFNGetManifest*>(dlsym(reinterpret_cast<void*>(tModuleID), "GetManifest"));
#else
#error OS not supported!
#endif
// Check for functions and the correct version
if (fnGetFactory && fnActiveObjects && fnGetManifest && fnGetManifest())
ssManifest = fnGetManifest();
// Release the library
#ifdef _WIN32
FreeLibrary(reinterpret_cast<HMODULE>(tModuleID));
#elif defined __unix__
dlclose(reinterpret_cast<void*>(tModuleID));
#else
#error OS not supported!
#endif
// Return the manifest
return ssManifest;
}

View File

@@ -0,0 +1,46 @@
/**
* @file process_control.h
* @author Sudipta Babu Durjoy FRD DISS21 (mailto:sudipta.durjoy@zf.com)
* @brief
* @version 1.0
* @date 2023-10-23
*
* @copyright Copyright ZF Friedrichshafen AG (c) 2023
*
*/
#ifndef MANIFEST_UTIL_H
#define MANIFEST_UTIL_H
#include <interfaces/config.h>
#include <support/component_impl.h>
/**
* @brief Manifest helper utility class.
* @details The manifest helper utility component allows extracting module information from the module. To do this, it needs to
* load the module and access one of the functions. Since several modules are designed to run in an isolated context, loading
* the module and extracting the manifest should also occur in an isolated context (hence as a separate utility and not part of
* the core).
*/
class CManifestUtil : public sdv::CSdvObject, public sdv::helper::IModuleManifestHelper
{
public:
BEGIN_SDV_INTERFACE_MAP()
SDV_INTERFACE_ENTRY(sdv::helper::IModuleManifestHelper)
END_SDV_INTERFACE_MAP()
// Object declarations
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Utility)
DECLARE_OBJECT_CLASS_NAME("ManifestHelperUtility")
/**
* @brief Read the module manifest. Overload of sdv::helper::IModuleManifestHelper::ReadModuleManifest.
* @param[in] ssModule Path to the module file.
* @return The module manifest if available. Otherwise an empty string.
*/
virtual sdv::u8string ReadModuleManifest(/*in*/ const sdv::u8string& ssModule) override;
};
DEFINE_SDV_OBJECT(CManifestUtil)
#endif // !define MANIFEST_UTIL_H