From 5a4f49866307190ab642c7ddd104464c9c2262e1 Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Sun, 28 Dec 2025 03:44:01 -0400 Subject: [PATCH] Libspinscale: Add separate CMake project config --- CMakeLists.txt | 1 - commonLibs/attachmentSupport/CMakeLists.txt | 1 + libspinscale/.gitignore | 4 + libspinscale/CMakeLists.txt | 145 ++++++++++++++++-- libspinscale/cmake/VerifyBoostDynamic.cmake | 63 ++++++++ libspinscale/cmake/spinscaleConfig.cmake.in | 5 + libspinscale/include/boostAsioLinkageFix.h | 25 +++ .../spinscale/asynchronousContinuation.h | 2 +- .../include/spinscale/componentThread.h | 15 +- .../include/spinscale}/marionette.h | 8 +- .../serializedAsynchronousContinuation.h | 2 +- libspinscale/src/component.cpp | 7 +- libspinscale/src/componentThread.cpp | 25 +-- main.cpp | 16 +- smocore/deviceManager/deviceManager.cpp | 18 +-- smocore/marionette/lifetime.cpp | 32 ++-- smocore/marionette/main.cpp | 45 +++--- smocore/marionette/negtrinEvent.cpp | 2 +- smocore/mind.cpp | 6 +- smocore/mindThread.cpp | 4 +- smocore/stimBuffApis/stimBuffApiManager.cpp | 2 +- 21 files changed, 328 insertions(+), 100 deletions(-) create mode 100644 libspinscale/.gitignore create mode 100644 libspinscale/cmake/VerifyBoostDynamic.cmake create mode 100644 libspinscale/cmake/spinscaleConfig.cmake.in create mode 100644 libspinscale/include/boostAsioLinkageFix.h rename {smocore/include/marionette => libspinscale/include/spinscale}/marionette.h (89%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d79d6b7..d808521 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,7 +92,6 @@ configure_file( # Include directories include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_CURRENT_SOURCE_DIR}/libspinscale/include ${CMAKE_CURRENT_SOURCE_DIR}/smocore/include ${CMAKE_CURRENT_BINARY_DIR}/include ) diff --git a/commonLibs/attachmentSupport/CMakeLists.txt b/commonLibs/attachmentSupport/CMakeLists.txt index 1ce5dc2..6244c5b 100644 --- a/commonLibs/attachmentSupport/CMakeLists.txt +++ b/commonLibs/attachmentSupport/CMakeLists.txt @@ -13,6 +13,7 @@ target_include_directories(attachmentSupport PUBLIC target_link_libraries(attachmentSupport PUBLIC Boost::system Boost::log + spinscale ) # Verify Boost dynamic dependencies after build diff --git a/libspinscale/.gitignore b/libspinscale/.gitignore new file mode 100644 index 0000000..3bf77d2 --- /dev/null +++ b/libspinscale/.gitignore @@ -0,0 +1,4 @@ +build-test +b-* +build +b diff --git a/libspinscale/CMakeLists.txt b/libspinscale/CMakeLists.txt index df4bb75..af04caf 100644 --- a/libspinscale/CMakeLists.txt +++ b/libspinscale/CMakeLists.txt @@ -1,3 +1,75 @@ +cmake_minimum_required(VERSION 3.16) +project(libspinscale VERSION 0.1.0 LANGUAGES CXX) + +# Set C++ standard +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Build type +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Debug FORCE) +endif() + +# Compiler flags +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") + +# Debug options - allow parent to override when used as subdirectory +# option() will respect existing cache values, so parent can set them before add_subdirectory() +option(ENABLE_DEBUG_LOCKS "Enable debug features for locking system" OFF) +option(ENABLE_DEBUG_TRACE_CALLABLES + "Enable callable tracing for debugging boost::asio post operations" OFF) + +# Qutex deadlock detection configuration +if(NOT DEFINED DEBUG_QUTEX_DEADLOCK_TIMEOUT_MS) + set(DEBUG_QUTEX_DEADLOCK_TIMEOUT_MS 500 CACHE STRING + "Timeout in milliseconds for deadlock detection in qutex system") +endif() + +if(ENABLE_DEBUG_LOCKS) + # Validate the timeout value + if(NOT DEBUG_QUTEX_DEADLOCK_TIMEOUT_MS OR DEBUG_QUTEX_DEADLOCK_TIMEOUT_MS STREQUAL "") + message(FATAL_ERROR "DEBUG_QUTEX_DEADLOCK_TIMEOUT_MS must be a positive integer > 0") + endif() + + # Convert to integer and validate + math(EXPR timeout_int "${DEBUG_QUTEX_DEADLOCK_TIMEOUT_MS}") + if(timeout_int LESS_EQUAL 0) + message(FATAL_ERROR "DEBUG_QUTEX_DEADLOCK_TIMEOUT_MS must be a positive integer > 0") + endif() +endif() + +# Set config variables for config.h +if(ENABLE_DEBUG_LOCKS) + set(CONFIG_ENABLE_DEBUG_LOCKS TRUE) +endif() + +if(ENABLE_DEBUG_TRACE_CALLABLES) + set(CONFIG_DEBUG_TRACE_CALLABLES TRUE) + # Suppress frame-address warnings when using __builtin_return_address() + # with values above 0 (See callableTracer.h). + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-frame-address") +endif() + +set(CONFIG_DEBUG_QUTEX_DEADLOCK_TIMEOUT_MS ${DEBUG_QUTEX_DEADLOCK_TIMEOUT_MS}) + +# Configure config.h +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/include/config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/include/config.h + @ONLY +) + +# Find dependencies +# Tell CMake we're linking against the shared library (not header-only) +set(Boost_USE_STATIC_LIBS OFF) +set(Boost_USE_HEADER_ONLY OFF) +find_package(Boost REQUIRED COMPONENTS system log) +# Define BOOST_ALL_DYN_LINK project-wide to ensure all Boost libraries use dynamic linking +add_compile_definitions(BOOST_ALL_DYN_LINK) + +find_package(Threads REQUIRED) + +# Create the library add_library(spinscale SHARED src/qutex.cpp src/lockerAndInvokerBase.cpp @@ -12,33 +84,88 @@ if(ENABLE_DEBUG_LOCKS) target_sources(spinscale PRIVATE src/qutexAcquisitionHistoryTracker.cpp) endif() -# Ensure Boost uses dynamic linking (project-wide setting should handle this, -# but being explicit here for clarity) -target_compile_definitions(spinscale PRIVATE BOOST_ALL_DYN_LINK) +# Set compile features target_compile_features(spinscale PUBLIC cxx_std_20) +# Include directories target_include_directories(spinscale PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${PROJECT_BINARY_DIR}/include - ${Boost_INCLUDE_DIRS} + $ + $ + $ ) # Link against required dependencies for shared library # Boost::system is PUBLIC because componentThread.h exposes Boost.Asio types -find_package(Threads REQUIRED) target_link_libraries(spinscale PUBLIC Threads::Threads Boost::system Boost::log ) -# Verify Boost dynamic dependencies after build (only if script exists) +# Verify Boost dynamic dependencies after build +# Prefer parent project's script when used as subdirectory, fall back to our own for standalone builds +set(VERIFY_SCRIPT "") if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/VerifyBoostDynamic.cmake) + set(VERIFY_SCRIPT ${CMAKE_SOURCE_DIR}/cmake/VerifyBoostDynamic.cmake) +elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/VerifyBoostDynamic.cmake) + set(VERIFY_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/cmake/VerifyBoostDynamic.cmake) +endif() + +if(VERIFY_SCRIPT) add_custom_command(TARGET spinscale POST_BUILD COMMAND ${CMAKE_COMMAND} -DVERIFY_FILE="$" - -P ${CMAKE_SOURCE_DIR}/cmake/VerifyBoostDynamic.cmake + -P ${VERIFY_SCRIPT} COMMENT "Verifying Boost dynamic dependencies for spinscale" ) else() message(WARNING "VerifyBoostDynamic.cmake not found - cannot verify Boost dependencies for spinscale") endif() + +# Install rules +install(TARGETS spinscale + EXPORT spinscaleTargets + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin +) + +install(DIRECTORY include/spinscale + DESTINATION include + FILES_MATCHING PATTERN "*.h" +) + +install(FILES include/boostAsioLinkageFix.h + DESTINATION include +) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/config.h + DESTINATION include +) + +# Install CMake config files for find_package() support +install(EXPORT spinscaleTargets + FILE spinscaleTargets.cmake + NAMESPACE spinscale:: + DESTINATION lib/cmake/spinscale +) + +# Create config file for find_package() +include(CMakePackageConfigHelpers) + +configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/spinscaleConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/spinscaleConfig.cmake + INSTALL_DESTINATION lib/cmake/spinscale +) + +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/spinscaleConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/spinscaleConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/spinscaleConfigVersion.cmake + DESTINATION lib/cmake/spinscale +) diff --git a/libspinscale/cmake/VerifyBoostDynamic.cmake b/libspinscale/cmake/VerifyBoostDynamic.cmake new file mode 100644 index 0000000..fd71bf7 --- /dev/null +++ b/libspinscale/cmake/VerifyBoostDynamic.cmake @@ -0,0 +1,63 @@ +# SMO_VERIFY_BOOST_DYNAMIC_DEPENDENCY +# Verifies that a target file (executable or shared library) has Boost libraries +# in its dynamic dependency list via ldd. +# +# Usage as function: +# SMO_VERIFY_BOOST_DYNAMIC_DEPENDENCY() +# +# Usage as script (with -P): +# cmake -DVERIFY_FILE= -P VerifyBoostDynamic.cmake +# +# This function/script: +# 1. Runs ldd on the target file +# 2. Checks for boost libraries in the dependency list +# 3. Reports success or failure with appropriate messages +# +function(SMO_VERIFY_BOOST_DYNAMIC_DEPENDENCY target_file) + _verify_boost_dynamic_dependency("${target_file}") +endfunction() + +# Internal implementation that can be called from script mode or function mode +function(_verify_boost_dynamic_dependency target_file) + if(NOT EXISTS "${target_file}") + message(WARNING "SMO_VERIFY_BOOST_DYNAMIC_DEPENDENCY: Target file '${target_file}' does not exist") + return() + endif() + + # Run ldd on the target file + execute_process( + COMMAND ldd "${target_file}" + OUTPUT_VARIABLE ldd_output + ERROR_VARIABLE ldd_error + RESULT_VARIABLE ldd_result + ) + + if(ldd_result) + message(WARNING "SMO_VERIFY_BOOST_DYNAMIC_DEPENDENCY: Failed to run ldd on '${target_file}': ${ldd_error}") + return() + endif() + + # Check if output contains boost libraries + string(TOLOWER "${ldd_output}" ldd_output_lower) + string(FIND "${ldd_output_lower}" "libboost" boost_found) + + if(boost_found EQUAL -1) + message(STATUS "SMO_VERIFY_BOOST_DYNAMIC_DEPENDENCY: WARNING - No Boost libraries found in dependencies of '${target_file}'") + message(STATUS "ldd output:") + message(STATUS "${ldd_output}") + else() + # Extract boost library lines + string(REGEX MATCHALL "libboost[^\n]*" boost_libs "${ldd_output}") + message(STATUS "SMO_VERIFY_BOOST_DYNAMIC_DEPENDENCY: SUCCESS - Boost libraries found in '${target_file}':") + foreach(boost_lib ${boost_libs}) + string(STRIP "${boost_lib}" boost_lib_stripped) + message(STATUS " ${boost_lib_stripped}") + endforeach() + endif() +endfunction() + +# Script mode: if VERIFY_FILE is defined, run the verification +if(VERIFY_FILE) + _verify_boost_dynamic_dependency("${VERIFY_FILE}") +endif() + diff --git a/libspinscale/cmake/spinscaleConfig.cmake.in b/libspinscale/cmake/spinscaleConfig.cmake.in new file mode 100644 index 0000000..42cde11 --- /dev/null +++ b/libspinscale/cmake/spinscaleConfig.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/spinscaleTargets.cmake") + +check_required_components(spinscale) diff --git a/libspinscale/include/boostAsioLinkageFix.h b/libspinscale/include/boostAsioLinkageFix.h new file mode 100644 index 0000000..8756b5c --- /dev/null +++ b/libspinscale/include/boostAsioLinkageFix.h @@ -0,0 +1,25 @@ +#ifndef BOOST_ASIO_LINKAGE_FIX_H +#define BOOST_ASIO_LINKAGE_FIX_H + +#include +#include +#include + +namespace boost { +namespace asio { +namespace detail { + +/** EXPLANATION: + * Extern declaration of the template instantiation + * This ensures that the .o translation units don't have their + * own copies of `call_stack<>::top_` defined in them. + */ +extern template +tss_ptr::context> +call_stack::top_; + +} // namespace detail +} // namespace asio +} // namespace boost + +#endif // BOOST_ASIO_LINKAGE_FIX_H diff --git a/libspinscale/include/spinscale/asynchronousContinuation.h b/libspinscale/include/spinscale/asynchronousContinuation.h index e907b70..cb7fcee 100644 --- a/libspinscale/include/spinscale/asynchronousContinuation.h +++ b/libspinscale/include/spinscale/asynchronousContinuation.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libspinscale/include/spinscale/componentThread.h b/libspinscale/include/spinscale/componentThread.h index d52add7..39d453c 100644 --- a/libspinscale/include/spinscale/componentThread.h +++ b/libspinscale/include/spinscale/componentThread.h @@ -154,19 +154,14 @@ public: class ThreadLifetimeMgmtOp; }; -} // namespace sscl - -namespace smo { namespace mrntt { -extern std::shared_ptr thread; -} // namespace mrntt -} // namespace smo +extern std::shared_ptr thread; -// Forward declaration for sscl namespace functions and variables +// Forward declaration for marionette thread ID management // Must be after sscl namespace so ThreadId is defined -namespace sscl { -extern sscl::ThreadId marionetteThreadId; -void setMarionetteThreadId(sscl::ThreadId id); +extern ThreadId marionetteThreadId; +void setMarionetteThreadId(ThreadId id); +} // namespace mrntt } #endif // COMPONENT_THREAD_H diff --git a/smocore/include/marionette/marionette.h b/libspinscale/include/spinscale/marionette.h similarity index 89% rename from smocore/include/marionette/marionette.h rename to libspinscale/include/spinscale/marionette.h index 5eb0c7d..b982cee 100644 --- a/smocore/include/marionette/marionette.h +++ b/libspinscale/include/spinscale/marionette.h @@ -6,7 +6,7 @@ #include #include -namespace smo { +namespace sscl { class MarionetteThread; @@ -31,10 +31,12 @@ private: class TerminationEvent; }; +extern std::shared_ptr thread; + extern std::atomic exitCode; void exitMarionetteLoop(); void marionetteFinalizeReqCb(bool success); -extern mrntt::MarionetteComponent mrntt; +extern MarionetteComponent mrntt; } // namespace mrntt @@ -51,6 +53,6 @@ struct CrtCommandLineArgs static void set(int argc, char *argv[], char *envp[]); }; -} // namespace smo +} // namespace sscl #endif // _MARIONETTE_H diff --git a/libspinscale/include/spinscale/serializedAsynchronousContinuation.h b/libspinscale/include/spinscale/serializedAsynchronousContinuation.h index eddd960..2c4b4de 100644 --- a/libspinscale/include/spinscale/serializedAsynchronousContinuation.h +++ b/libspinscale/include/spinscale/serializedAsynchronousContinuation.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libspinscale/src/component.cpp b/libspinscale/src/component.cpp index 6d9c069..988c095 100644 --- a/libspinscale/src/component.cpp +++ b/libspinscale/src/component.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace sscl { @@ -16,9 +16,6 @@ parent(parent) { } -} // namespace sscl - -namespace smo { namespace mrntt { MarionetteComponent::MarionetteComponent( @@ -28,4 +25,4 @@ MarionetteComponent::MarionetteComponent( } } // namespace mrntt -} // namespace smo +} // namespace sscl diff --git a/libspinscale/src/componentThread.cpp b/libspinscale/src/componentThread.cpp index 0f6fbbe..e53163b 100644 --- a/libspinscale/src/componentThread.cpp +++ b/libspinscale/src/componentThread.cpp @@ -8,19 +8,21 @@ #include #include #include -#include -#include +#include +#include namespace sscl { +namespace mrntt { // Global variable to store the marionette thread ID // Default value is 0, but should be set by application code via setMarionetteThreadId() -sscl::ThreadId marionetteThreadId = 0; +ThreadId marionetteThreadId = 0; -void setMarionetteThreadId(sscl::ThreadId id) +void setMarionetteThreadId(ThreadId id) { marionetteThreadId = id; } +} // namespace mrntt } // namespace sscl @@ -28,10 +30,15 @@ namespace sscl { thread_local std::shared_ptr thisComponentThread; +namespace mrntt { +// Global marionette thread instance - defined here but initialized by application +std::shared_ptr thread; +} // namespace mrntt + // Implementation of static method std::shared_ptr ComponentThread::getMrntt() { - return smo::mrntt::thread; + return sscl::mrntt::thread; } void MarionetteThread::initializeTls(void) @@ -180,13 +187,13 @@ void PuppetThread::joltThreadReq( * To obtain a sh_ptr to the target thread, we use the selfPtr parameter * passed in by the caller. */ - if (id == sscl::marionetteThreadId) + if (id == sscl::mrntt::marionetteThreadId) { throw std::runtime_error(std::string(__func__) + ": invoked on mrntt thread"); } - std::shared_ptr mrntt = smo::mrntt::thread; + std::shared_ptr mrntt = sscl::mrntt::thread; auto request = std::make_shared( mrntt, selfPtr, callback); @@ -231,7 +238,7 @@ void PuppetThread::exitThreadReq(Callback callback) void PuppetThread::pauseThreadReq(Callback callback) { - if (id == sscl::marionetteThreadId) + if (id == sscl::mrntt::marionetteThreadId) { throw std::runtime_error(std::string(__func__) + ": invoked on mrntt thread"); @@ -250,7 +257,7 @@ void PuppetThread::pauseThreadReq(Callback callback) void PuppetThread::resumeThreadReq(Callback callback) { - if (id == sscl::marionetteThreadId) + if (id == sscl::mrntt::marionetteThreadId) { throw std::runtime_error(std::string(__func__) + ": invoked on mrntt thread"); diff --git a/main.cpp b/main.cpp index 55e88b0..684976f 100644 --- a/main.cpp +++ b/main.cpp @@ -1,31 +1,31 @@ #include #include #include -#include #include +#include int main(int argc, char *argv[], char *envp[]) { // Set the marionette thread ID before using any ComponentThread functionality - sscl::setMarionetteThreadId(smo::SmoThreadId::MRNTT); + sscl::mrntt::setMarionetteThreadId(smo::SmoThreadId::MRNTT); pthread_setname_np(pthread_self(), "smo:CRT:main"); /* We don't do anything inside of main() * Main merely waits for the marionette thread to exit. */ std::cout << "CRT:" << __func__ << ": about to JOLT Mrntt with cmdline args" << '\n'; - smo::mrntt::thread->getIoService().post( + sscl::mrntt::thread->getIoService().post( [argc, argv, envp]() { std::cout << "Mrntt:" << __func__ << ":JOLTED: setting cmdline args" << '\n'; - smo::CrtCommandLineArgs::set(argc, argv, envp); - smo::mrntt::thread->getIoService().stop(); + sscl::CrtCommandLineArgs::set(argc, argv, envp); + sscl::mrntt::thread->getIoService().stop(); } ); - smo::mrntt::thread->thread.join(); + sscl::mrntt::thread->thread.join(); std::cout << "CRT:" << __func__ << ": Mrntt exited with code '" - << smo::mrntt::exitCode << "'\n"; - return smo::mrntt::exitCode; + << sscl::mrntt::exitCode << "'\n"; + return sscl::mrntt::exitCode; } diff --git a/smocore/deviceManager/deviceManager.cpp b/smocore/deviceManager/deviceManager.cpp index 6906c95..5eb1450 100644 --- a/smocore/deviceManager/deviceManager.cpp +++ b/smocore/deviceManager/deviceManager.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include namespace smo { @@ -304,7 +304,7 @@ void DeviceManager::newDeviceAttachmentSpecInd( }); NewDeviceAttachmentSpecInd::LockerAndInvoker lockvoker( - *request, mrntt::mrntt.thread, + *request, sscl::mrntt::mrntt.thread, std::bind( &NewDeviceAttachmentSpecInd::newDeviceAttachmentSpecInd1_posted, request.get(), request)); @@ -323,7 +323,7 @@ void DeviceManager::removeDeviceAttachmentSpecReq( }); RemoveDeviceAttachmentSpecReq::LockerAndInvoker lockvoker( - *request, mrntt::mrntt.thread, + *request, sscl::mrntt::mrntt.thread, std::bind( &RemoveDeviceAttachmentSpecReq ::removeDeviceAttachmentSpecReq1_posted, @@ -500,7 +500,7 @@ void DeviceManager::attachStimBuffDeviceReq( }); AttachStimBuffDeviceReq::LockerAndInvoker lockvoker( - *request, mrntt::mrntt.thread, + *request, sscl::mrntt::mrntt.thread, std::bind( &AttachStimBuffDeviceReq::attachStimBuffDeviceReq1_posted, request.get(), request)); @@ -535,7 +535,7 @@ void DeviceManager::detachStimBuffDeviceReq( }); DetachStimBuffDeviceReq::LockerAndInvoker lockvoker( - *request, mrntt::mrntt.thread, + *request, sscl::mrntt::mrntt.thread, std::bind( &DetachStimBuffDeviceReq::detachStimBuffDeviceReq1_posted, request.get(), request)); @@ -626,7 +626,7 @@ void DeviceManager::attachAllUnattachedDevicesFromReq( auto request = std::make_shared( specs->size(), specs, caller, std::move(cb)); - mrntt::mrntt.thread->getIoService().post( + sscl::mrntt::mrntt.thread->getIoService().post( STC(std::bind( &AttachAllUnattachedDevicesFromReq ::attachAllUnattachedDevicesFromReq1_posted, @@ -723,7 +723,7 @@ void DeviceManager::attachAllUnattachedDevicesFromKnownListReq( }); AttachAllUnattachedDevicesFromKnownListReq::LockerAndInvoker lockvoker( - *request, mrntt::mrntt.thread, + *request, sscl::mrntt::mrntt.thread, std::bind( &AttachAllUnattachedDevicesFromKnownListReq ::attachAllUnattachedDevicesFromKnownListReq1_posted, @@ -807,7 +807,7 @@ void DeviceManager::detachAllAttachedDeviceRoles( DeviceManager::getInstance().attachedDeviceRoles.size(), caller, std::move(cb)); - mrntt::mrntt.thread->getIoService().post( + sscl::mrntt::mrntt.thread->getIoService().post( STC(std::bind( &DetachAllAttachedDeviceRoles::detachAllAttachedDeviceRoles1_posted, request.get(), request))); @@ -816,7 +816,7 @@ void DeviceManager::detachAllAttachedDeviceRoles( void DeviceManager::initializeDeviceReattacher() { deviceReattacher = std::make_unique( - *this, mrntt::mrntt.thread); + *this, sscl::mrntt::mrntt.thread); deviceReattacher->start(); } diff --git a/smocore/marionette/lifetime.cpp b/smocore/marionette/lifetime.cpp index 587b152..c7c98e1 100644 --- a/smocore/marionette/lifetime.cpp +++ b/smocore/marionette/lifetime.cpp @@ -4,12 +4,12 @@ #include #include #include +#include #include #include #include -#include -namespace smo { +namespace sscl { namespace mrntt { class MarionetteComponent::MrnttLifetimeMgmtOp @@ -33,13 +33,13 @@ public: ) { auto self = sscl::ComponentThread::getSelf(); - if (self->id != SmoThreadId::MRNTT) + if (self->id != smo::SmoThreadId::MRNTT) { throw std::runtime_error(std::string(__func__) + ": Must be executed on Marionette thread"); } - smo::mind::globalMind = std::make_shared(); + smo::mind::globalMind = std::make_shared(); smo::mind::globalMind->initializeReq({context, std::bind( &MrnttLifetimeMgmtOp::initializeReq2, this, context, std::placeholders::_1)}); @@ -58,7 +58,7 @@ public: return; } - device::DeviceManager::getInstance().initializeDeviceReattacher(); + smo::device::DeviceManager::getInstance().initializeDeviceReattacher(); // Call negtrinEventInd on the Director in the final callback smo::mind::globalMind->director.negtrinEventInd(); @@ -71,13 +71,13 @@ public: ) { auto self = sscl::ComponentThread::getSelf(); - if (self->id != SmoThreadId::MRNTT) + if (self->id != smo::SmoThreadId::MRNTT) { throw std::runtime_error(std::string(__func__) + ": Must be executed on Marionette thread"); } - device::DeviceManager::getInstance().finalizeDeviceReattacher(); + smo::device::DeviceManager::getInstance().finalizeDeviceReattacher(); /** FIXME: * It may be necessary to add a delay here to ensure that all in-flight @@ -133,24 +133,24 @@ public: ) { auto self = sscl::ComponentThread::getSelf(); - if (self->id != SmoThreadId::MRNTT) + if (self->id != smo::SmoThreadId::MRNTT) { throw std::runtime_error(std::string(__func__) + ": Must be executed on Marionette thread"); } - mrntt::mrntt.finalizeReq({nullptr, std::bind( - &mrntt::marionetteFinalizeReqCb, + sscl::mrntt::mrntt.finalizeReq({nullptr, std::bind( + &sscl::mrntt::marionetteFinalizeReqCb, std::placeholders::_1)}); } }; -void MarionetteComponent::initializeReq( +void sscl::mrntt::MarionetteComponent::initializeReq( sscl::Callback callback) { auto mrntt = sscl::ComponentThread::getSelf(); - if (mrntt->id != SmoThreadId::MRNTT) + if (mrntt->id != smo::SmoThreadId::MRNTT) { throw std::runtime_error(std::string(__func__) + ": Must be executed on Marionette thread"); @@ -165,12 +165,12 @@ void MarionetteComponent::initializeReq( request.get(), request))); } -void MarionetteComponent::finalizeReq( +void sscl::mrntt::MarionetteComponent::finalizeReq( sscl::Callback callback) { auto mrntt = sscl::ComponentThread::getSelf(); - if (mrntt->id != SmoThreadId::MRNTT) + if (mrntt->id != smo::SmoThreadId::MRNTT) { throw std::runtime_error(std::string(__func__) + ": Must be executed on Marionette thread"); @@ -185,7 +185,7 @@ void MarionetteComponent::finalizeReq( request.get(), request))); } -void MarionetteComponent::exceptionInd() +void sscl::mrntt::MarionetteComponent::exceptionInd() { auto faultyThread = sscl::ComponentThread::getSelf(); auto mrntt = sscl::ComponentThread::getMrntt(); @@ -200,4 +200,4 @@ void MarionetteComponent::exceptionInd() } } // namespace mrntt -} // namespace smo +} // namespace sscl diff --git a/smocore/marionette/main.cpp b/smocore/marionette/main.cpp index d4af030..0796ce2 100644 --- a/smocore/marionette/main.cpp +++ b/smocore/marionette/main.cpp @@ -9,12 +9,16 @@ #include #include #include +#include #include #include -#include #include -namespace smo { +// Define the global marionette thread instance (declared extern in libspinscale) +namespace sscl { +namespace mrntt { +std::shared_ptr thread = std::make_shared(); +} // namespace mrntt CrtCommandLineArgs crtCommandLineArgs(0, nullptr, nullptr); @@ -25,9 +29,6 @@ void CrtCommandLineArgs::set(int argc, char *argv[], char *envp[]) namespace mrntt { std::atomic exitCode; -// Global marionette thread instance -std::shared_ptr thread = - std::make_shared(); MarionetteComponent mrntt(std::static_pointer_cast(thread)); void exitMarionetteLoop() @@ -47,6 +48,10 @@ void marionetteFinalizeReqCb(bool success) std::cout << __func__ << ": Marionette finalized." << '\n'; exitMarionetteLoop(); } +} // namespace mrntt +} // namespace sscl + +namespace smo { void marionetteInitializeReqCb(bool success) { @@ -59,13 +64,11 @@ void marionetteInitializeReqCb(bool success) std::cerr << __func__ << ": Failed to initialize Marionette. Shutting down." << '\n'; - mrntt::mrntt.finalizeReq({nullptr, std::bind( - &mrntt::marionetteFinalizeReqCb, + sscl::mrntt::mrntt.finalizeReq({nullptr, std::bind( + &sscl::mrntt::marionetteFinalizeReqCb, std::placeholders::_1)}); } -} // namespace mrntt - } // namespace smo namespace sscl { @@ -78,7 +81,7 @@ void MarionetteThread::main(MarionetteThread& self) std::cout << __func__ << ": Waiting for command line JOLT" << std::endl; self.getIoService().run(); self.initializeTls(); - smo::mrntt::exitCode = EXIT_SUCCESS; + sscl::mrntt::exitCode = EXIT_SUCCESS; static boost::asio::signal_set signals(self.getIoService(), SIGINT); bool callShutdownSalmanoff = false; @@ -100,8 +103,8 @@ void MarionetteThread::main(MarionetteThread& self) default: break; } - smo::mrntt::mrntt.finalizeReq({nullptr, std::bind( - &smo::mrntt::marionetteFinalizeReqCb, + sscl::mrntt::mrntt.finalizeReq({nullptr, std::bind( + &sscl::mrntt::marionetteFinalizeReqCb, std::placeholders::_1)}); } ); @@ -112,8 +115,8 @@ void MarionetteThread::main(MarionetteThread& self) << std::endl; options.parseArguments( - smo::crtCommandLineArgs.argc, smo::crtCommandLineArgs.argv, - smo::crtCommandLineArgs.envp); + sscl::crtCommandLineArgs.argc, sscl::crtCommandLineArgs.argv, + sscl::crtCommandLineArgs.envp); std::cout << __func__ << ": " << options.stringifyOptions() << std::endl; @@ -144,8 +147,8 @@ void MarionetteThread::main(MarionetteThread& self) callShutdownSalmanoff = true; // Create new Mind instance just before initializeReq - smo::mrntt::mrntt.initializeReq({nullptr, std::bind( - &smo::mrntt::marionetteInitializeReqCb, std::placeholders::_1)}); + sscl::mrntt::mrntt.initializeReq({nullptr, std::bind( + &smo::marionetteInitializeReqCb, std::placeholders::_1)}); std::cout << __func__ << ": Entering event loop" << "\n"; @@ -188,8 +191,8 @@ void MarionetteThread::main(MarionetteThread& self) if (sendExceptionInd) { - smo::mrntt::exitCode = EXIT_FAILURE; - smo::mrntt::mrntt.exceptionInd(); + sscl::mrntt::exitCode = EXIT_FAILURE; + sscl::mrntt::mrntt.exceptionInd(); } } @@ -202,7 +205,7 @@ void MarionetteThread::main(MarionetteThread& self) if (typeid(e) == typeid(OptionsParserError)) { - smo::mrntt::exitCode = EXIT_FAILURE; + sscl::mrntt::exitCode = EXIT_FAILURE; out = &std::cerr; outUsageMsg = std::string(__func__) + ": "; } @@ -213,12 +216,12 @@ void MarionetteThread::main(MarionetteThread& self) { std::cerr << __func__ << ": Exception occurred: " << e.what() << std::endl; - smo::mrntt::exitCode = EXIT_FAILURE; + sscl::mrntt::exitCode = EXIT_FAILURE; } catch (...) { std::cerr << __func__ << ": Unknown exception occurred" << std::endl; - smo::mrntt::exitCode = EXIT_FAILURE; + sscl::mrntt::exitCode = EXIT_FAILURE; } if (callShutdownSalmanoff) { diff --git a/smocore/marionette/negtrinEvent.cpp b/smocore/marionette/negtrinEvent.cpp index 8466edf..6240aff 100644 --- a/smocore/marionette/negtrinEvent.cpp +++ b/smocore/marionette/negtrinEvent.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include namespace smo { diff --git a/smocore/mind.cpp b/smocore/mind.cpp index 0ab8eaf..ad2c979 100644 --- a/smocore/mind.cpp +++ b/smocore/mind.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include namespace smo { @@ -227,7 +227,7 @@ void Mind::initializeReq(sscl::Callback callback) auto request = std::make_shared( *this, caller, callback); - mrntt::mrntt.thread->getIoService().post( + sscl::mrntt::mrntt.thread->getIoService().post( STC(std::bind( &MindLifetimeMgmtOp::initializeReq1_posted, request.get(), request))); @@ -239,7 +239,7 @@ void Mind::finalizeReq(sscl::Callback callback) auto request = std::make_shared( *this, caller, callback); - mrntt::mrntt.thread->getIoService().post( + sscl::mrntt::mrntt.thread->getIoService().post( STC(std::bind( &MindLifetimeMgmtOp::finalizeReq1_posted, request.get(), request))); diff --git a/smocore/mindThread.cpp b/smocore/mindThread.cpp index 5487a53..1bb4b2f 100644 --- a/smocore/mindThread.cpp +++ b/smocore/mindThread.cpp @@ -1,12 +1,12 @@ #include #include -#include +#include namespace smo { void MindThread::handleException() { - mrntt::mrntt.exceptionInd(); + sscl::mrntt::mrntt.exceptionInd(); } } // namespace smo diff --git a/smocore/stimBuffApis/stimBuffApiManager.cpp b/smocore/stimBuffApis/stimBuffApiManager.cpp index 2bcf991..4966c46 100644 --- a/smocore/stimBuffApis/stimBuffApiManager.cpp +++ b/smocore/stimBuffApis/stimBuffApiManager.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include