Libspinscale: Add separate CMake project config

This commit is contained in:
2025-12-28 03:44:01 -04:00
parent 7acdfcc337
commit 5a4f498663
21 changed files with 328 additions and 100 deletions
-1
View File
@@ -92,7 +92,6 @@ configure_file(
# Include directories # Include directories
include_directories( include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/libspinscale/include
${CMAKE_CURRENT_SOURCE_DIR}/smocore/include ${CMAKE_CURRENT_SOURCE_DIR}/smocore/include
${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include
) )
@@ -13,6 +13,7 @@ target_include_directories(attachmentSupport PUBLIC
target_link_libraries(attachmentSupport PUBLIC target_link_libraries(attachmentSupport PUBLIC
Boost::system Boost::system
Boost::log Boost::log
spinscale
) )
# Verify Boost dynamic dependencies after build # Verify Boost dynamic dependencies after build
+4
View File
@@ -0,0 +1,4 @@
build-test
b-*
build
b
+136 -9
View File
@@ -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 add_library(spinscale SHARED
src/qutex.cpp src/qutex.cpp
src/lockerAndInvokerBase.cpp src/lockerAndInvokerBase.cpp
@@ -12,33 +84,88 @@ if(ENABLE_DEBUG_LOCKS)
target_sources(spinscale PRIVATE src/qutexAcquisitionHistoryTracker.cpp) target_sources(spinscale PRIVATE src/qutexAcquisitionHistoryTracker.cpp)
endif() endif()
# Ensure Boost uses dynamic linking (project-wide setting should handle this, # Set compile features
# but being explicit here for clarity)
target_compile_definitions(spinscale PRIVATE BOOST_ALL_DYN_LINK)
target_compile_features(spinscale PUBLIC cxx_std_20) target_compile_features(spinscale PUBLIC cxx_std_20)
# Include directories
target_include_directories(spinscale PUBLIC target_include_directories(spinscale PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
${PROJECT_BINARY_DIR}/include $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
${Boost_INCLUDE_DIRS} $<INSTALL_INTERFACE:include>
) )
# Link against required dependencies for shared library # Link against required dependencies for shared library
# Boost::system is PUBLIC because componentThread.h exposes Boost.Asio types # Boost::system is PUBLIC because componentThread.h exposes Boost.Asio types
find_package(Threads REQUIRED)
target_link_libraries(spinscale PUBLIC target_link_libraries(spinscale PUBLIC
Threads::Threads Threads::Threads
Boost::system Boost::system
Boost::log 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) 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 add_custom_command(TARGET spinscale POST_BUILD
COMMAND ${CMAKE_COMMAND} -DVERIFY_FILE="$<TARGET_FILE:spinscale>" COMMAND ${CMAKE_COMMAND} -DVERIFY_FILE="$<TARGET_FILE:spinscale>"
-P ${CMAKE_SOURCE_DIR}/cmake/VerifyBoostDynamic.cmake -P ${VERIFY_SCRIPT}
COMMENT "Verifying Boost dynamic dependencies for spinscale" COMMENT "Verifying Boost dynamic dependencies for spinscale"
) )
else() else()
message(WARNING "VerifyBoostDynamic.cmake not found - cannot verify Boost dependencies for spinscale") message(WARNING "VerifyBoostDynamic.cmake not found - cannot verify Boost dependencies for spinscale")
endif() 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
)
@@ -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(<target_file>)
#
# Usage as script (with -P):
# cmake -DVERIFY_FILE=<target_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()
@@ -0,0 +1,5 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/spinscaleTargets.cmake")
check_required_components(spinscale)
@@ -0,0 +1,25 @@
#ifndef BOOST_ASIO_LINKAGE_FIX_H
#define BOOST_ASIO_LINKAGE_FIX_H
#include <boost/asio/detail/call_stack.hpp>
#include <boost/asio/detail/thread_context.hpp>
#include <boost/asio/detail/tss_ptr.hpp>
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<call_stack<thread_context, thread_info_base>::context>
call_stack<thread_context, thread_info_base>::top_;
} // namespace detail
} // namespace asio
} // namespace boost
#endif // BOOST_ASIO_LINKAGE_FIX_H
@@ -4,7 +4,7 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <exception> #include <exception>
#include <componentThread.h> #include <spinscale/componentThread.h>
#include <spinscale/callback.h> #include <spinscale/callback.h>
#include <spinscale/callableTracer.h> #include <spinscale/callableTracer.h>
#include <spinscale/asynchronousContinuationChainLink.h> #include <spinscale/asynchronousContinuationChainLink.h>
@@ -154,19 +154,14 @@ public:
class ThreadLifetimeMgmtOp; class ThreadLifetimeMgmtOp;
}; };
} // namespace sscl
namespace smo {
namespace mrntt { namespace mrntt {
extern std::shared_ptr<sscl::MarionetteThread> thread; extern std::shared_ptr<MarionetteThread> thread;
} // namespace mrntt
} // namespace smo
// Forward declaration for sscl namespace functions and variables // Forward declaration for marionette thread ID management
// Must be after sscl namespace so ThreadId is defined // Must be after sscl namespace so ThreadId is defined
namespace sscl { extern ThreadId marionetteThreadId;
extern sscl::ThreadId marionetteThreadId; void setMarionetteThreadId(ThreadId id);
void setMarionetteThreadId(sscl::ThreadId id); } // namespace mrntt
} }
#endif // COMPONENT_THREAD_H #endif // COMPONENT_THREAD_H
@@ -6,7 +6,7 @@
#include <memory> #include <memory>
#include <spinscale/component.h> #include <spinscale/component.h>
namespace smo { namespace sscl {
class MarionetteThread; class MarionetteThread;
@@ -31,10 +31,12 @@ private:
class TerminationEvent; class TerminationEvent;
}; };
extern std::shared_ptr<sscl::MarionetteThread> thread;
extern std::atomic<int> exitCode; extern std::atomic<int> exitCode;
void exitMarionetteLoop(); void exitMarionetteLoop();
void marionetteFinalizeReqCb(bool success); void marionetteFinalizeReqCb(bool success);
extern mrntt::MarionetteComponent mrntt; extern MarionetteComponent mrntt;
} // namespace mrntt } // namespace mrntt
@@ -51,6 +53,6 @@ struct CrtCommandLineArgs
static void set(int argc, char *argv[], char *envp[]); static void set(int argc, char *argv[], char *envp[]);
}; };
} // namespace smo } // namespace sscl
#endif // _MARIONETTE_H #endif // _MARIONETTE_H
@@ -7,7 +7,7 @@
#include <chrono> #include <chrono>
#include <iostream> #include <iostream>
#include <optional> #include <optional>
#include <componentThread.h> #include <spinscale/componentThread.h>
#include <spinscale/lockSet.h> #include <spinscale/lockSet.h>
#include <spinscale/asynchronousContinuation.h> #include <spinscale/asynchronousContinuation.h>
#include <spinscale/lockerAndInvokerBase.h> #include <spinscale/lockerAndInvokerBase.h>
+2 -5
View File
@@ -1,6 +1,6 @@
#include <spinscale/component.h> #include <spinscale/component.h>
#include <spinscale/puppetApplication.h> #include <spinscale/puppetApplication.h>
#include <marionette/marionette.h> #include <spinscale/marionette.h>
namespace sscl { namespace sscl {
@@ -16,9 +16,6 @@ parent(parent)
{ {
} }
} // namespace sscl
namespace smo {
namespace mrntt { namespace mrntt {
MarionetteComponent::MarionetteComponent( MarionetteComponent::MarionetteComponent(
@@ -28,4 +25,4 @@ MarionetteComponent::MarionetteComponent(
} }
} // namespace mrntt } // namespace mrntt
} // namespace smo } // namespace sscl
+16 -9
View File
@@ -8,19 +8,21 @@
#include <spinscale/asynchronousContinuation.h> #include <spinscale/asynchronousContinuation.h>
#include <spinscale/callback.h> #include <spinscale/callback.h>
#include <spinscale/callableTracer.h> #include <spinscale/callableTracer.h>
#include <componentThread.h> #include <spinscale/componentThread.h>
#include <marionette/marionette.h> #include <spinscale/marionette.h>
namespace sscl { namespace sscl {
namespace mrntt {
// Global variable to store the marionette thread ID // Global variable to store the marionette thread ID
// Default value is 0, but should be set by application code via setMarionetteThreadId() // 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; marionetteThreadId = id;
} }
} // namespace mrntt
} // namespace sscl } // namespace sscl
@@ -28,10 +30,15 @@ namespace sscl {
thread_local std::shared_ptr<ComponentThread> thisComponentThread; thread_local std::shared_ptr<ComponentThread> thisComponentThread;
namespace mrntt {
// Global marionette thread instance - defined here but initialized by application
std::shared_ptr<MarionetteThread> thread;
} // namespace mrntt
// Implementation of static method // Implementation of static method
std::shared_ptr<MarionetteThread> ComponentThread::getMrntt() std::shared_ptr<MarionetteThread> ComponentThread::getMrntt()
{ {
return smo::mrntt::thread; return sscl::mrntt::thread;
} }
void MarionetteThread::initializeTls(void) 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 * To obtain a sh_ptr to the target thread, we use the selfPtr parameter
* passed in by the caller. * passed in by the caller.
*/ */
if (id == sscl::marionetteThreadId) if (id == sscl::mrntt::marionetteThreadId)
{ {
throw std::runtime_error(std::string(__func__) throw std::runtime_error(std::string(__func__)
+ ": invoked on mrntt thread"); + ": invoked on mrntt thread");
} }
std::shared_ptr<MarionetteThread> mrntt = smo::mrntt::thread; std::shared_ptr<MarionetteThread> mrntt = sscl::mrntt::thread;
auto request = std::make_shared<ThreadLifetimeMgmtOp>( auto request = std::make_shared<ThreadLifetimeMgmtOp>(
mrntt, selfPtr, callback); mrntt, selfPtr, callback);
@@ -231,7 +238,7 @@ void PuppetThread::exitThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback)
void PuppetThread::pauseThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback) void PuppetThread::pauseThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback)
{ {
if (id == sscl::marionetteThreadId) if (id == sscl::mrntt::marionetteThreadId)
{ {
throw std::runtime_error(std::string(__func__) throw std::runtime_error(std::string(__func__)
+ ": invoked on mrntt thread"); + ": invoked on mrntt thread");
@@ -250,7 +257,7 @@ void PuppetThread::pauseThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback)
void PuppetThread::resumeThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback) void PuppetThread::resumeThreadReq(Callback<threadLifetimeMgmtOpCbFn> callback)
{ {
if (id == sscl::marionetteThreadId) if (id == sscl::mrntt::marionetteThreadId)
{ {
throw std::runtime_error(std::string(__func__) throw std::runtime_error(std::string(__func__)
+ ": invoked on mrntt thread"); + ": invoked on mrntt thread");
+8 -8
View File
@@ -1,31 +1,31 @@
#include <iostream> #include <iostream>
#include <pthread.h> #include <pthread.h>
#include <componentThread.h> #include <componentThread.h>
#include <marionette/marionette.h>
#include <spinscale/componentThread.h> #include <spinscale/componentThread.h>
#include <spinscale/marionette.h>
int main(int argc, char *argv[], char *envp[]) int main(int argc, char *argv[], char *envp[])
{ {
// Set the marionette thread ID before using any ComponentThread functionality // 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"); pthread_setname_np(pthread_self(), "smo:CRT:main");
/* We don't do anything inside of main() /* We don't do anything inside of main()
* Main merely waits for the marionette thread to exit. * Main merely waits for the marionette thread to exit.
*/ */
std::cout << "CRT:" << __func__ << ": about to JOLT Mrntt with cmdline args" std::cout << "CRT:" << __func__ << ": about to JOLT Mrntt with cmdline args"
<< '\n'; << '\n';
smo::mrntt::thread->getIoService().post( sscl::mrntt::thread->getIoService().post(
[argc, argv, envp]() [argc, argv, envp]()
{ {
std::cout << "Mrntt:" << __func__ << ":JOLTED: setting cmdline args" std::cout << "Mrntt:" << __func__ << ":JOLTED: setting cmdline args"
<< '\n'; << '\n';
smo::CrtCommandLineArgs::set(argc, argv, envp); sscl::CrtCommandLineArgs::set(argc, argv, envp);
smo::mrntt::thread->getIoService().stop(); sscl::mrntt::thread->getIoService().stop();
} }
); );
smo::mrntt::thread->thread.join(); sscl::mrntt::thread->thread.join();
std::cout << "CRT:" << __func__ << ": Mrntt exited with code '" std::cout << "CRT:" << __func__ << ": Mrntt exited with code '"
<< smo::mrntt::exitCode << "'\n"; << sscl::mrntt::exitCode << "'\n";
return smo::mrntt::exitCode; return sscl::mrntt::exitCode;
} }
+9 -9
View File
@@ -14,7 +14,7 @@
#include <deviceManager/deviceManager.h> #include <deviceManager/deviceManager.h>
#include <deviceManager/deviceReattacher.h> #include <deviceManager/deviceReattacher.h>
#include <stimBuffApis/stimBuffApiManager.h> #include <stimBuffApis/stimBuffApiManager.h>
#include <marionette/marionette.h> #include <spinscale/marionette.h>
#include <mind.h> #include <mind.h>
namespace smo { namespace smo {
@@ -304,7 +304,7 @@ void DeviceManager::newDeviceAttachmentSpecInd(
}); });
NewDeviceAttachmentSpecInd::LockerAndInvoker lockvoker( NewDeviceAttachmentSpecInd::LockerAndInvoker lockvoker(
*request, mrntt::mrntt.thread, *request, sscl::mrntt::mrntt.thread,
std::bind( std::bind(
&NewDeviceAttachmentSpecInd::newDeviceAttachmentSpecInd1_posted, &NewDeviceAttachmentSpecInd::newDeviceAttachmentSpecInd1_posted,
request.get(), request)); request.get(), request));
@@ -323,7 +323,7 @@ void DeviceManager::removeDeviceAttachmentSpecReq(
}); });
RemoveDeviceAttachmentSpecReq::LockerAndInvoker lockvoker( RemoveDeviceAttachmentSpecReq::LockerAndInvoker lockvoker(
*request, mrntt::mrntt.thread, *request, sscl::mrntt::mrntt.thread,
std::bind( std::bind(
&RemoveDeviceAttachmentSpecReq &RemoveDeviceAttachmentSpecReq
::removeDeviceAttachmentSpecReq1_posted, ::removeDeviceAttachmentSpecReq1_posted,
@@ -500,7 +500,7 @@ void DeviceManager::attachStimBuffDeviceReq(
}); });
AttachStimBuffDeviceReq::LockerAndInvoker lockvoker( AttachStimBuffDeviceReq::LockerAndInvoker lockvoker(
*request, mrntt::mrntt.thread, *request, sscl::mrntt::mrntt.thread,
std::bind( std::bind(
&AttachStimBuffDeviceReq::attachStimBuffDeviceReq1_posted, &AttachStimBuffDeviceReq::attachStimBuffDeviceReq1_posted,
request.get(), request)); request.get(), request));
@@ -535,7 +535,7 @@ void DeviceManager::detachStimBuffDeviceReq(
}); });
DetachStimBuffDeviceReq::LockerAndInvoker lockvoker( DetachStimBuffDeviceReq::LockerAndInvoker lockvoker(
*request, mrntt::mrntt.thread, *request, sscl::mrntt::mrntt.thread,
std::bind( std::bind(
&DetachStimBuffDeviceReq::detachStimBuffDeviceReq1_posted, &DetachStimBuffDeviceReq::detachStimBuffDeviceReq1_posted,
request.get(), request)); request.get(), request));
@@ -626,7 +626,7 @@ void DeviceManager::attachAllUnattachedDevicesFromReq(
auto request = std::make_shared<AttachAllUnattachedDevicesFromReq>( auto request = std::make_shared<AttachAllUnattachedDevicesFromReq>(
specs->size(), specs, caller, std::move(cb)); specs->size(), specs, caller, std::move(cb));
mrntt::mrntt.thread->getIoService().post( sscl::mrntt::mrntt.thread->getIoService().post(
STC(std::bind( STC(std::bind(
&AttachAllUnattachedDevicesFromReq &AttachAllUnattachedDevicesFromReq
::attachAllUnattachedDevicesFromReq1_posted, ::attachAllUnattachedDevicesFromReq1_posted,
@@ -723,7 +723,7 @@ void DeviceManager::attachAllUnattachedDevicesFromKnownListReq(
}); });
AttachAllUnattachedDevicesFromKnownListReq::LockerAndInvoker lockvoker( AttachAllUnattachedDevicesFromKnownListReq::LockerAndInvoker lockvoker(
*request, mrntt::mrntt.thread, *request, sscl::mrntt::mrntt.thread,
std::bind( std::bind(
&AttachAllUnattachedDevicesFromKnownListReq &AttachAllUnattachedDevicesFromKnownListReq
::attachAllUnattachedDevicesFromKnownListReq1_posted, ::attachAllUnattachedDevicesFromKnownListReq1_posted,
@@ -807,7 +807,7 @@ void DeviceManager::detachAllAttachedDeviceRoles(
DeviceManager::getInstance().attachedDeviceRoles.size(), DeviceManager::getInstance().attachedDeviceRoles.size(),
caller, std::move(cb)); caller, std::move(cb));
mrntt::mrntt.thread->getIoService().post( sscl::mrntt::mrntt.thread->getIoService().post(
STC(std::bind( STC(std::bind(
&DetachAllAttachedDeviceRoles::detachAllAttachedDeviceRoles1_posted, &DetachAllAttachedDeviceRoles::detachAllAttachedDeviceRoles1_posted,
request.get(), request))); request.get(), request)));
@@ -816,7 +816,7 @@ void DeviceManager::detachAllAttachedDeviceRoles(
void DeviceManager::initializeDeviceReattacher() void DeviceManager::initializeDeviceReattacher()
{ {
deviceReattacher = std::make_unique<DeviceReattacher>( deviceReattacher = std::make_unique<DeviceReattacher>(
*this, mrntt::mrntt.thread); *this, sscl::mrntt::mrntt.thread);
deviceReattacher->start(); deviceReattacher->start();
} }
+16 -16
View File
@@ -4,12 +4,12 @@
#include <spinscale/callback.h> #include <spinscale/callback.h>
#include <spinscale/callableTracer.h> #include <spinscale/callableTracer.h>
#include <spinscale/component.h> #include <spinscale/component.h>
#include <spinscale/marionette.h>
#include <componentThread.h> #include <componentThread.h>
#include <deviceManager/deviceManager.h> #include <deviceManager/deviceManager.h>
#include <mindManager/mindManager.h> #include <mindManager/mindManager.h>
#include <marionette/marionette.h>
namespace smo { namespace sscl {
namespace mrntt { namespace mrntt {
class MarionetteComponent::MrnttLifetimeMgmtOp class MarionetteComponent::MrnttLifetimeMgmtOp
@@ -33,13 +33,13 @@ public:
) )
{ {
auto self = sscl::ComponentThread::getSelf(); auto self = sscl::ComponentThread::getSelf();
if (self->id != SmoThreadId::MRNTT) if (self->id != smo::SmoThreadId::MRNTT)
{ {
throw std::runtime_error(std::string(__func__) throw std::runtime_error(std::string(__func__)
+ ": Must be executed on Marionette thread"); + ": Must be executed on Marionette thread");
} }
smo::mind::globalMind = std::make_shared<Mind>(); smo::mind::globalMind = std::make_shared<smo::Mind>();
smo::mind::globalMind->initializeReq({context, std::bind( smo::mind::globalMind->initializeReq({context, std::bind(
&MrnttLifetimeMgmtOp::initializeReq2, &MrnttLifetimeMgmtOp::initializeReq2,
this, context, std::placeholders::_1)}); this, context, std::placeholders::_1)});
@@ -58,7 +58,7 @@ public:
return; return;
} }
device::DeviceManager::getInstance().initializeDeviceReattacher(); smo::device::DeviceManager::getInstance().initializeDeviceReattacher();
// Call negtrinEventInd on the Director in the final callback // Call negtrinEventInd on the Director in the final callback
smo::mind::globalMind->director.negtrinEventInd(); smo::mind::globalMind->director.negtrinEventInd();
@@ -71,13 +71,13 @@ public:
) )
{ {
auto self = sscl::ComponentThread::getSelf(); auto self = sscl::ComponentThread::getSelf();
if (self->id != SmoThreadId::MRNTT) if (self->id != smo::SmoThreadId::MRNTT)
{ {
throw std::runtime_error(std::string(__func__) throw std::runtime_error(std::string(__func__)
+ ": Must be executed on Marionette thread"); + ": Must be executed on Marionette thread");
} }
device::DeviceManager::getInstance().finalizeDeviceReattacher(); smo::device::DeviceManager::getInstance().finalizeDeviceReattacher();
/** FIXME: /** FIXME:
* It may be necessary to add a delay here to ensure that all in-flight * 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(); auto self = sscl::ComponentThread::getSelf();
if (self->id != SmoThreadId::MRNTT) if (self->id != smo::SmoThreadId::MRNTT)
{ {
throw std::runtime_error(std::string(__func__) throw std::runtime_error(std::string(__func__)
+ ": Must be executed on Marionette thread"); + ": Must be executed on Marionette thread");
} }
mrntt::mrntt.finalizeReq({nullptr, std::bind( sscl::mrntt::mrntt.finalizeReq({nullptr, std::bind(
&mrntt::marionetteFinalizeReqCb, &sscl::mrntt::marionetteFinalizeReqCb,
std::placeholders::_1)}); std::placeholders::_1)});
} }
}; };
void MarionetteComponent::initializeReq( void sscl::mrntt::MarionetteComponent::initializeReq(
sscl::Callback<mrnttLifetimeMgmtOpCbFn> callback) sscl::Callback<mrnttLifetimeMgmtOpCbFn> callback)
{ {
auto mrntt = sscl::ComponentThread::getSelf(); auto mrntt = sscl::ComponentThread::getSelf();
if (mrntt->id != SmoThreadId::MRNTT) if (mrntt->id != smo::SmoThreadId::MRNTT)
{ {
throw std::runtime_error(std::string(__func__) throw std::runtime_error(std::string(__func__)
+ ": Must be executed on Marionette thread"); + ": Must be executed on Marionette thread");
@@ -165,12 +165,12 @@ void MarionetteComponent::initializeReq(
request.get(), request))); request.get(), request)));
} }
void MarionetteComponent::finalizeReq( void sscl::mrntt::MarionetteComponent::finalizeReq(
sscl::Callback<mrnttLifetimeMgmtOpCbFn> callback) sscl::Callback<mrnttLifetimeMgmtOpCbFn> callback)
{ {
auto mrntt = sscl::ComponentThread::getSelf(); auto mrntt = sscl::ComponentThread::getSelf();
if (mrntt->id != SmoThreadId::MRNTT) if (mrntt->id != smo::SmoThreadId::MRNTT)
{ {
throw std::runtime_error(std::string(__func__) throw std::runtime_error(std::string(__func__)
+ ": Must be executed on Marionette thread"); + ": Must be executed on Marionette thread");
@@ -185,7 +185,7 @@ void MarionetteComponent::finalizeReq(
request.get(), request))); request.get(), request)));
} }
void MarionetteComponent::exceptionInd() void sscl::mrntt::MarionetteComponent::exceptionInd()
{ {
auto faultyThread = sscl::ComponentThread::getSelf(); auto faultyThread = sscl::ComponentThread::getSelf();
auto mrntt = sscl::ComponentThread::getMrntt(); auto mrntt = sscl::ComponentThread::getMrntt();
@@ -200,4 +200,4 @@ void MarionetteComponent::exceptionInd()
} }
} // namespace mrntt } // namespace mrntt
} // namespace smo } // namespace sscl
+24 -21
View File
@@ -9,12 +9,16 @@
#include <boost/asio/signal_set.hpp> #include <boost/asio/signal_set.hpp>
#include <spinscale/asynchronousBridge.h> #include <spinscale/asynchronousBridge.h>
#include <spinscale/componentThread.h> #include <spinscale/componentThread.h>
#include <spinscale/marionette.h>
#include <componentThread.h> #include <componentThread.h>
#include <mindManager/mindManager.h> #include <mindManager/mindManager.h>
#include <marionette/marionette.h>
#include <salmanoff.h> #include <salmanoff.h>
namespace smo { // Define the global marionette thread instance (declared extern in libspinscale)
namespace sscl {
namespace mrntt {
std::shared_ptr<MarionetteThread> thread = std::make_shared<MarionetteThread>();
} // namespace mrntt
CrtCommandLineArgs crtCommandLineArgs(0, nullptr, nullptr); CrtCommandLineArgs crtCommandLineArgs(0, nullptr, nullptr);
@@ -25,9 +29,6 @@ void CrtCommandLineArgs::set(int argc, char *argv[], char *envp[])
namespace mrntt { namespace mrntt {
std::atomic<int> exitCode; std::atomic<int> exitCode;
// Global marionette thread instance
std::shared_ptr<sscl::MarionetteThread> thread =
std::make_shared<sscl::MarionetteThread>();
MarionetteComponent mrntt(std::static_pointer_cast<sscl::ComponentThread>(thread)); MarionetteComponent mrntt(std::static_pointer_cast<sscl::ComponentThread>(thread));
void exitMarionetteLoop() void exitMarionetteLoop()
@@ -47,6 +48,10 @@ void marionetteFinalizeReqCb(bool success)
std::cout << __func__ << ": Marionette finalized." << '\n'; std::cout << __func__ << ": Marionette finalized." << '\n';
exitMarionetteLoop(); exitMarionetteLoop();
} }
} // namespace mrntt
} // namespace sscl
namespace smo {
void marionetteInitializeReqCb(bool success) void marionetteInitializeReqCb(bool success)
{ {
@@ -59,13 +64,11 @@ void marionetteInitializeReqCb(bool success)
std::cerr << __func__ << ": Failed to initialize Marionette. Shutting down." std::cerr << __func__ << ": Failed to initialize Marionette. Shutting down."
<< '\n'; << '\n';
mrntt::mrntt.finalizeReq({nullptr, std::bind( sscl::mrntt::mrntt.finalizeReq({nullptr, std::bind(
&mrntt::marionetteFinalizeReqCb, &sscl::mrntt::marionetteFinalizeReqCb,
std::placeholders::_1)}); std::placeholders::_1)});
} }
} // namespace mrntt
} // namespace smo } // namespace smo
namespace sscl { namespace sscl {
@@ -78,7 +81,7 @@ void MarionetteThread::main(MarionetteThread& self)
std::cout << __func__ << ": Waiting for command line JOLT" << std::endl; std::cout << __func__ << ": Waiting for command line JOLT" << std::endl;
self.getIoService().run(); self.getIoService().run();
self.initializeTls(); self.initializeTls();
smo::mrntt::exitCode = EXIT_SUCCESS; sscl::mrntt::exitCode = EXIT_SUCCESS;
static boost::asio::signal_set signals(self.getIoService(), SIGINT); static boost::asio::signal_set signals(self.getIoService(), SIGINT);
bool callShutdownSalmanoff = false; bool callShutdownSalmanoff = false;
@@ -100,8 +103,8 @@ void MarionetteThread::main(MarionetteThread& self)
default: default:
break; break;
} }
smo::mrntt::mrntt.finalizeReq({nullptr, std::bind( sscl::mrntt::mrntt.finalizeReq({nullptr, std::bind(
&smo::mrntt::marionetteFinalizeReqCb, &sscl::mrntt::marionetteFinalizeReqCb,
std::placeholders::_1)}); std::placeholders::_1)});
} }
); );
@@ -112,8 +115,8 @@ void MarionetteThread::main(MarionetteThread& self)
<< std::endl; << std::endl;
options.parseArguments( options.parseArguments(
smo::crtCommandLineArgs.argc, smo::crtCommandLineArgs.argv, sscl::crtCommandLineArgs.argc, sscl::crtCommandLineArgs.argv,
smo::crtCommandLineArgs.envp); sscl::crtCommandLineArgs.envp);
std::cout << __func__ << ": " << options.stringifyOptions() std::cout << __func__ << ": " << options.stringifyOptions()
<< std::endl; << std::endl;
@@ -144,8 +147,8 @@ void MarionetteThread::main(MarionetteThread& self)
callShutdownSalmanoff = true; callShutdownSalmanoff = true;
// Create new Mind instance just before initializeReq // Create new Mind instance just before initializeReq
smo::mrntt::mrntt.initializeReq({nullptr, std::bind( sscl::mrntt::mrntt.initializeReq({nullptr, std::bind(
&smo::mrntt::marionetteInitializeReqCb, std::placeholders::_1)}); &smo::marionetteInitializeReqCb, std::placeholders::_1)});
std::cout << __func__ << ": Entering event loop" << "\n"; std::cout << __func__ << ": Entering event loop" << "\n";
@@ -188,8 +191,8 @@ void MarionetteThread::main(MarionetteThread& self)
if (sendExceptionInd) if (sendExceptionInd)
{ {
smo::mrntt::exitCode = EXIT_FAILURE; sscl::mrntt::exitCode = EXIT_FAILURE;
smo::mrntt::mrntt.exceptionInd(); sscl::mrntt::mrntt.exceptionInd();
} }
} }
@@ -202,7 +205,7 @@ void MarionetteThread::main(MarionetteThread& self)
if (typeid(e) == typeid(OptionsParserError)) if (typeid(e) == typeid(OptionsParserError))
{ {
smo::mrntt::exitCode = EXIT_FAILURE; sscl::mrntt::exitCode = EXIT_FAILURE;
out = &std::cerr; out = &std::cerr;
outUsageMsg = std::string(__func__) + ": "; outUsageMsg = std::string(__func__) + ": ";
} }
@@ -213,12 +216,12 @@ void MarionetteThread::main(MarionetteThread& self)
{ {
std::cerr << __func__ << ": Exception occurred: " << e.what() std::cerr << __func__ << ": Exception occurred: " << e.what()
<< std::endl; << std::endl;
smo::mrntt::exitCode = EXIT_FAILURE; sscl::mrntt::exitCode = EXIT_FAILURE;
} }
catch (...) catch (...)
{ {
std::cerr << __func__ << ": Unknown exception occurred" << std::endl; std::cerr << __func__ << ": Unknown exception occurred" << std::endl;
smo::mrntt::exitCode = EXIT_FAILURE; sscl::mrntt::exitCode = EXIT_FAILURE;
} }
if (callShutdownSalmanoff) { if (callShutdownSalmanoff) {
+1 -1
View File
@@ -1,7 +1,7 @@
#include <iostream> #include <iostream>
#include <spinscale/component.h> #include <spinscale/component.h>
#include <nonNeutralQualia.h> #include <nonNeutralQualia.h>
#include <marionette/marionette.h> #include <spinscale/marionette.h>
namespace smo { namespace smo {
+3 -3
View File
@@ -9,7 +9,7 @@
#include <director/director.h> #include <director/director.h>
#include <simulator/simulator.h> #include <simulator/simulator.h>
#include <stimBuffApis/stimBuffApiManager.h> #include <stimBuffApis/stimBuffApiManager.h>
#include <marionette/marionette.h> #include <spinscale/marionette.h>
namespace smo { namespace smo {
@@ -227,7 +227,7 @@ void Mind::initializeReq(sscl::Callback<mindLifetimeMgmtOpCbFn> callback)
auto request = std::make_shared<MindLifetimeMgmtOp>( auto request = std::make_shared<MindLifetimeMgmtOp>(
*this, caller, callback); *this, caller, callback);
mrntt::mrntt.thread->getIoService().post( sscl::mrntt::mrntt.thread->getIoService().post(
STC(std::bind( STC(std::bind(
&MindLifetimeMgmtOp::initializeReq1_posted, &MindLifetimeMgmtOp::initializeReq1_posted,
request.get(), request))); request.get(), request)));
@@ -239,7 +239,7 @@ void Mind::finalizeReq(sscl::Callback<mindLifetimeMgmtOpCbFn> callback)
auto request = std::make_shared<MindLifetimeMgmtOp>( auto request = std::make_shared<MindLifetimeMgmtOp>(
*this, caller, callback); *this, caller, callback);
mrntt::mrntt.thread->getIoService().post( sscl::mrntt::mrntt.thread->getIoService().post(
STC(std::bind( STC(std::bind(
&MindLifetimeMgmtOp::finalizeReq1_posted, &MindLifetimeMgmtOp::finalizeReq1_posted,
request.get(), request))); request.get(), request)));
+2 -2
View File
@@ -1,12 +1,12 @@
#include <componentThread.h> #include <componentThread.h>
#include <mindThread.h> #include <mindThread.h>
#include <marionette/marionette.h> #include <spinscale/marionette.h>
namespace smo { namespace smo {
void MindThread::handleException() void MindThread::handleException()
{ {
mrntt::mrntt.exceptionInd(); sscl::mrntt::mrntt.exceptionInd();
} }
} // namespace smo } // namespace smo
+1 -1
View File
@@ -12,7 +12,7 @@
#include <user/senseApiDesc.h> #include <user/senseApiDesc.h>
#include <mind.h> #include <mind.h>
#include <deviceManager/deviceManager.h> #include <deviceManager/deviceManager.h>
#include <marionette/marionette.h> #include <spinscale/marionette.h>
#include <computeManager/computeManager.h> #include <computeManager/computeManager.h>