Skip to content

File ManagedImageEventHandler.h

File List > SpinnakerNET > ManagedImageEventHandler.h

Go to the documentation of this file

//=============================================================================
// Copyright (c) 2026 FLIR Integrated Imaging Solutions, Inc. All Rights Reserved.
//
// This software is the confidential and proprietary information of FLIR
// Integrated Imaging Solutions, Inc. ("Confidential Information"). You
// shall not disclose such Confidential Information and shall use it only in
// accordance with the terms of the license agreement you entered into
// with FLIR Integrated Imaging Solutions, Inc. (FLIR)
//
// FLIR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
// SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE, OR NON-INFRINGEMENT. FLIR SHALL NOT BE LIABLE FOR ANY DAMAGES
// SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
// THIS SOFTWARE OR ITS DERIVATIVES.
//=============================================================================

#ifndef FLIR_SPINNAKER_MANAGED_IMAGE_EVENT_HANDLER_H
#define FLIR_SPINNAKER_MANAGED_IMAGE_EVENT_HANDLER_H

#include "ManagedEventHandler.h"
#include "ImageEventHandler.h"
#include "ManagedImage.h"
#include <vcclr.h>

using namespace ::System;

namespace SpinnakerNET
{
    // forward declaration
    ref class ManagedImageEventHandler;

    // Intermediate delegate and function pointer for ManagedImageEventHandler
    delegate void OnImageEventDelegate(Spinnaker::ImagePtr image);
    typedef void(__stdcall *OnImageEventNative)(Spinnaker::ImagePtr image);

    class ImageEventRedirector : public Spinnaker::ImageEventHandler
    {
        public:
            ImageEventRedirector(OnImageEventDelegate^ eventDelegate)
            {
                m_onImageEventDelegate = eventDelegate;
                m_onImageEventNative = (OnImageEventNative)Marshal::GetFunctionPointerForDelegate(m_onImageEventDelegate).ToPointer();
            }

        protected:
            virtual void OnImageEvent(Spinnaker::ImagePtr image);

        private:
            gcroot<OnImageEventDelegate^> m_onImageEventDelegate;
            OnImageEventNative m_onImageEventNative;
    };

    // Managed abstract Image event base class
    // The event callbacks, ie.  On<Event>() functions will be called via the internal
    // CallOn<Event>() calls.
    public ref class ManagedImageEventHandler abstract : public ManagedEventHandler
    {
        public:
            ManagedImageEventHandler();
            ~ManagedImageEventHandler();
            !ManagedImageEventHandler();

        protected:
            // Empty body so user can override only the one's they need
            virtual void OnImageEvent(ManagedImage^ /*image*/){};

internal:
            void CallOnImageEvent(Spinnaker::ImagePtr image);
    };
}

#endif // FLIR_SPINNAKER_MANAGED_IMAGE_EVENT_HANDLER_H