Rhino C++ API  8.14
Public Member Functions | Static Public Member Functions | List of all members
ON_Terminator Class Reference

#include <opennurbs_terminator.h>

Public Member Functions

 ON_Terminator ()
 
 ~ON_Terminator ()
 
bool AllowDefaultCancellationHandling (void) const
 
ON__UINT_PTR CallbackContext () const
 
ON__UINT_PTR CallbackFunction () const
 
void RequestTermination ()
 
void SetAllowDefaultCancellationHandling (bool bAllow)
 
void SetTerminationQueryCallbackFunction (bool(*callback_function)(ON__UINT_PTR context), ON__UINT_PTR callback_context)
 
void SetThreadId (ON__UINT_PTR thread_id)
 
ON__UINT_PTR ThreadId () const
 

Static Public Member Functions

static void RequestTermination (ON_Terminator *terminator)
 
static bool TerminationRequested (ON_Terminator *terminator)
 
static bool TerminationRequestedExpert (ON_Terminator *terminator, ON__UINT64 callback_delta)
 

Detailed Description

Copyright (c) 1993-2022 Robert McNeel & Associates. All rights reserved. OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert McNeel & Associates.

THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.

For complete openNURBS copyright information see http://www.opennurbs.org.

Constructor & Destructor Documentation

◆ ON_Terminator()

ON_Terminator::ON_Terminator ( )

◆ ~ON_Terminator()

ON_Terminator::~ON_Terminator ( )

Member Function Documentation

◆ AllowDefaultCancellationHandling()

bool ON_Terminator::AllowDefaultCancellationHandling ( void  ) const

Description: returns true if default cancellation processing is allowed, otherwise false. See SetAllowDefaultCancellationHandling

◆ CallbackContext()

ON__UINT_PTR ON_Terminator::CallbackContext ( ) const

◆ CallbackFunction()

ON__UINT_PTR ON_Terminator::CallbackFunction ( ) const

◆ RequestTermination() [1/2]

void ON_Terminator::RequestTermination ( )

Description: Sets m_bTerminationRequested = true. All future calls to TerminationRequested(this) will return true.

◆ RequestTermination() [2/2]

static void ON_Terminator::RequestTermination ( ON_Terminator terminator)
static

Description: If terminator is not nullptr, sets terminator->m_bTerminationRequested = true. If terminator is not nullptr, all future calls to TerminationRequested(terminator) will return true. Parameters: terminator - [in] (can be nullptr) Remarks: This is convenience function and is identical to the code

if (nullptr != terminator) terminator->RequestTermination();

◆ SetAllowDefaultCancellationHandling()

void ON_Terminator::SetAllowDefaultCancellationHandling ( bool  bAllow)

Description: If bAllow is true, the worker thread cancellation handling (escape key presses etc) will cause RequestTermination to be called. If bAllow is false, cancellation must be implemented through the callback function, otherwise all cancellation will be disabled. Parameters: bAllow - [in] (see above)

◆ SetTerminationQueryCallbackFunction()

void ON_Terminator::SetTerminationQueryCallbackFunction ( bool(*)(ON__UINT_PTR context)  callback_function,
ON__UINT_PTR  callback_context 
)

Description: Set the function that is called when a calculation wants to determine if the calculation should stop or continue. Parameters: callback_function - [in] The function that is called when a calculation wants to determine if the calculation should stop or continue. If this callback function returns true, the calculation will terminate as soon as possible. If this callback function returns false, the calculation will continue. The calculation thread calls in this callback function. The callback function should do something that is fast and simple. Parameters passed to the callback function: context - [in] the value of callback_context. Example: bool bStopCalculation = false;

bool StopCalculation( ON__UINT_PTR context ) { if ( 0 != context ) { const bool* p = (const bool*)context; if ( *p ) return true; ///< terminate calculation as soon as possible } return false; ///< continue calculation }

...

ON_Terminator terminator; terminator.SetTerminationQueryCallbackFunction(StopCalculation,(ON__UINT_PTR)(&bStopCalculation)); ... Pass &terminator to a calculation and then set bStopCalculation = true to terminate it. The calculation will generally be running in another thread, but can be in the same thread if it is structured to pump windows messages or something similar.

◆ SetThreadId()

void ON_Terminator::SetThreadId ( ON__UINT_PTR  thread_id)

◆ TerminationRequested()

static bool ON_Terminator::TerminationRequested ( ON_Terminator terminator)
static

Description: A calculation calls ON_Terminator::TerminationRequested(terminator) to determine if it should continue or quit. Parameters: terminator - [in] A pointer to an ON_Terminator or null pointer. Returns: True if the calculation should terminate as soon as possible. False if the calculation should continue. Example:
void MyLongCalculation( ..., ON_Terminator* terminator, ...) { for ( i = 0; i < count; i++ ) { if ( ON_Terminator::TerminationRequested(terminator) ) break; ... } }

◆ TerminationRequestedExpert()

static bool ON_Terminator::TerminationRequestedExpert ( ON_Terminator terminator,
ON__UINT64  callback_delta 
)
static

Description: An expert user function to determine if a calculation should continue.
Parameters: terminator - [in] A pointer to an ON_Terminator or null pointer. callback_delta - [in] Minimum amount of time to delay between calls to the registered callback function in clock() time units. 0 will omit making any call to the registered function. ON_Terminator::TerminationRequested( terminator ) uses a value of callback_delta = CLOCKS_PER_SEC/10 meaning a maximum of 10 callbacks per second. Returns: True if the calculation should terminate as soon as possible. False if the calculation should continue. Remarks: In general, call the ON_Terminator::TerminationRequested( terminator ).

◆ ThreadId()

ON__UINT_PTR ON_Terminator::ThreadId ( ) const