Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ function(export_mpf_lib targetName)
install(EXPORT ${targetName}Config DESTINATION lib/cmake/${targetName} EXPORT_LINK_INTERFACE_LIBRARIES)
endfunction()

add_subdirectory(internal)
include_directories(internal/include)

add_subdirectory(interface)
include_directories(interface/include)

Expand Down
8 changes: 4 additions & 4 deletions detection/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ set(SOURCE_FILES
)

add_library(mpfDetectionComponentApi SHARED ${SOURCE_FILES})
target_link_libraries(mpfDetectionComponentApi mpfComponentInterface ${OpenCV_LIBS})


target_link_libraries(
mpfDetectionComponentApi
PUBLIC mpfComponentInterface ${OpenCV_LIBS}
PRIVATE mpfInternalObjLib)

export_mpf_lib(mpfDetectionComponentApi)


add_subdirectory(test)

2 changes: 2 additions & 0 deletions detection/api/src/MPFVideoCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "IntervalFrameFilter.h"
#include "KeyFrameFilter.h"
#include "MPFDetectionException.h"
#include "MPFBreaker.h"

#include "MPFVideoCapture.h"

Expand Down Expand Up @@ -207,6 +208,7 @@ namespace MPF { namespace COMPONENT {


bool MPFVideoCapture::Read(cv::Mat &frame) {
MPFBreaker::check();
int originalPosBeforeRead = framePosition_;
if (frameFilter_->IsPastEndOfSegment(originalPosBeforeRead)) {
frame.release();
Expand Down
48 changes: 48 additions & 0 deletions internal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#############################################################################
# NOTICE #
# #
# This software (or technical data) was produced for the U.S. Government #
# under contract, and is subject to the Rights in Data-General Clause #
# 52.227-14, Alt. IV (DEC 2007). #
# #
# Copyright 2026 The MITRE Corporation. All Rights Reserved. #
#############################################################################

#############################################################################
# Copyright 2026 The MITRE Corporation #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#############################################################################

cmake_minimum_required(VERSION 3.6)
project(openmpf-internal)

set(CMAKE_CXX_STANDARD 17)

include_directories(include)

set(SOURCE_FILES
include/MPFBreaker.h
src/MPFBreaker.cpp)

add_library(mpfInternalObjLib OBJECT ${SOURCE_FILES})

# Position-independent code is required because MPFBreaker uses a global variable that should be
# shared with any library linking to this one.
set_target_properties(mpfInternalObjLib PROPERTIES
INTERFACE_POSITION_INDEPENDENT_CODE ON
POSITION_INDEPENDENT_CODE ON)

add_library(mpfInternal SHARED $<TARGET_OBJECTS:mpfInternalObjLib>)

export_mpf_lib(mpfInternal)
44 changes: 44 additions & 0 deletions internal/include/MPFBreaker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/******************************************************************************
* NOTICE *
* *
* This software (or technical data) was produced for the U.S. Government *
* under contract, and is subject to the Rights in Data-General Clause *
* 52.227-14, Alt. IV (DEC 2007). *
* *
* Copyright 2026 The MITRE Corporation. All Rights Reserved. *
******************************************************************************/

/******************************************************************************
* Copyright 2026 The MITRE Corporation *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
******************************************************************************/

#pragma once

#include <stdexcept>

namespace MPF::COMPONENT {

class StopRequestedException : public std::runtime_error {
public:
using std::runtime_error::runtime_error;
};


namespace MPFBreaker {
void requestStop();

void check();
}
} // namespace MPF::COMPONENT
74 changes: 74 additions & 0 deletions internal/src/MPFBreaker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/******************************************************************************
* NOTICE *
* *
* This software (or technical data) was produced for the U.S. Government *
* under contract, and is subject to the Rights in Data-General Clause *
* 52.227-14, Alt. IV (DEC 2007). *
* *
* Copyright 2026 The MITRE Corporation. All Rights Reserved. *
******************************************************************************/

/******************************************************************************
* Copyright 2026 The MITRE Corporation *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
******************************************************************************/

#include "MPFBreaker.h"

#include <atomic>
#include <iostream>
#include <string>
#include <exception>

namespace MPF::COMPONENT {
namespace {
std::atomic<bool> STOP_REQUESTED{false};
}


void MPFBreaker::requestStop() {
std::cerr << "MPFBreaker: Setting stop requested flag to true.\n";
STOP_REQUESTED.store(true, std::memory_order::memory_order_release);
}


void MPFBreaker::check() {
if (!STOP_REQUESTED.load(std::memory_order::memory_order_acquire)) {
return;
}

std::cerr << "MPFBreaker: The stop requested flag was set to true. "
"Throwing StopRequestedException.\n";
auto e_ptr = std::current_exception();
if (!e_ptr) {
throw StopRequestedException{"Stop requested."};
}

try {
std::rethrow_exception(e_ptr);
}
catch (const StopRequestedException&) {
throw;
}
catch (const std::exception& e) {
throw StopRequestedException{
std::string{"Stop requested. Suppressed the following exception: "}
+ e.what()};
}
catch (...) {
throw StopRequestedException{
"Stop requested. Suppressed a thrown non-exception object."};
}
}
} // namespace MPF::COMPONENT