nx_metadata_sdk  1.0
Metadata SDK
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
nx::sdk::IRefCountable Class Referenceabstract

#include <i_ref_countable.h>

Inheritance diagram for nx::sdk::IRefCountable:
nx::sdk::Interface< IAction > nx::sdk::Interface< IAttribute > nx::sdk::Interface< IBase > nx::sdk::Interface< IBase, IRefCountable > nx::sdk::Interface< ICodecInfo > nx::sdk::Interface< IDataPacket > nx::sdk::Interface< IDevice > nx::sdk::Interface< IDeviceAgent > nx::sdk::Interface< IDeviceInfo > nx::sdk::Interface< IDeviceManager > nx::sdk::Interface< IDeviceManagerHandler > nx::sdk::Interface< IEngine > nx::sdk::Interface< IEngineInfo > nx::sdk::Interface< IHandler > nx::sdk::Interface< IList< IItem > > nx::sdk::Interface< IList< nx::sdk::analytics::ITimestampedObjectMetadata > > nx::sdk::Interface< IMediaContext > nx::sdk::Interface< IMetadata > nx::sdk::Interface< IMetadataTypes > nx::sdk::Interface< IObjectTrackInfo > nx::sdk::Interface< IPlugin > nx::sdk::Interface< IPluginDiagnosticEvent > nx::sdk::Interface< ISettingsResponse0 > nx::sdk::Interface< ISomeItem > nx::sdk::Interface< IStreamWriter > nx::sdk::Interface< IString > nx::sdk::Interface< IStringList > nx::sdk::Interface< IStringMap > nx::sdk::Interface< ITemplate< IItem > > nx::sdk::Interface< IUtilityProvider0 > nx::sdk::Interface< NewInterface > nx::sdk::Interface< OtherNewInterface >

Classes

struct  InterfaceId
 

Public Member Functions

virtual ~IRefCountable ()=default
 
template<class Interface >
Ptr< InterfacequeryInterface ()
 
template<class Interface >
Ptr< const InterfacequeryInterface () const
 
virtual int addRef () const =0
 
virtual int releaseRef () const =0
 
int refCountThreadUnsafe () const
 

Static Public Member Functions

static auto interfaceId ()
 

Protected Member Functions

virtual IRefCountablequeryInterface (const InterfaceId *id)
 

Static Protected Member Functions

template<int len>
static constexpr const InterfaceIdmakeId (const char(&charArray)[len])
 
template<class TemplateInstance , class TemplateArg , int len>
static const InterfaceIdmakeIdForTemplate (const char(&baseIdCharArray)[len])
 

Detailed Description

Base for all interfaces - abstract classes with only pure-virtual non-overloaded functions, so that an object implementing an interface can be passed by pointer between dynamic libraries compiled using potentially different compilers and their standard libraries. Such abstraction is needed to enable plugins. It is somewhat similar to Microsoft Component Object Model (COM).

Interface methods are allowed to use only C-style input and output types (without STL classes), because on each side of a dynamic library different implementations/versions of STL can be used. The only ABI aspects that interfaces rely upon - size of pointer, and order of methods in a VMT (in the order of declaration, base class methods first). Overloaded methods are not allowed because their order in VMS can be different across compilers. Also dynamic_cast can not be used for such objects, because data structures behind the VMT can be different across compilers.

Interfaces may contain type definitions and non-virtual inline utility methods (they will be compiled by each side independently).

Each object implementing an interface should have an internal reference counter, which, when decremented to zero, triggers object deletion.

To provide dynamic-cast-like behavior, and more generally, the ability to yield objects implementing other interfaces (not necessarily the same object as the one being queried), each object must implement queryInterface() which takes an interface identifier and returns a pointer to the object implementing the requested interface.

General rules for passing objects with reference counting:

NOTE: For binary compatibility with old plugins, the VMT layout of this interface (4 entries - destructor, queryInterface(), addRef(), releaseRef()) should not change, as well as the binary prototypes (arguments and return values) of its entries.

Constructor & Destructor Documentation

◆ ~IRefCountable()

virtual nx::sdk::IRefCountable::~IRefCountable ( )
virtualdefault

VMT #0.

Member Function Documentation

◆ addRef()

virtual int nx::sdk::IRefCountable::addRef ( ) const
pure virtual

VMT #2.

Returns
New reference count.

◆ interfaceId()

static auto nx::sdk::IRefCountable::interfaceId ( )
inlinestatic

Each derived interface is expected to implement such static method with its own string.

◆ makeId()

template<int len>
static constexpr const InterfaceId* nx::sdk::IRefCountable::makeId ( const char(&)  charArray[len])
inlinestaticprotected

Intended to be used in interface(). Can be called only with a string literal.

◆ makeIdForTemplate()

template<class TemplateInstance , class TemplateArg , int len>
static const InterfaceId* nx::sdk::IRefCountable::makeIdForTemplate ( const char(&)  baseIdCharArray[len])
inlinestaticprotected

Makes a compound interface id for interface templates like IList<IItem>. Usage:

static auto interfaceId()
{
return IList::template makeIdForTemplate<IList<IItem>, IItem>("nx::sdk::IList");
}

◆ queryInterface()

virtual IRefCountable* nx::sdk::IRefCountable::queryInterface ( const InterfaceId id)
inlineprotectedvirtual

VMT #1.

Intended to be called indirectly, via queryInterface<Interface>(), hence protected.

Returns
Object that requires releaseRef() by the caller when it no longer needs it, or null if the requested interface is not implemented.

Reimplemented in nx::sdk::ref_countable_ut::NewInterface.

◆ refCountThreadUnsafe()

int nx::sdk::IRefCountable::refCountThreadUnsafe ( ) const
inline

Intended for debug. Is not thread-safe, because does addRef()/releaseRef() pair of calls.

Returns
Reference counter, or 0 if the pointer is null.

◆ releaseRef()

virtual int nx::sdk::IRefCountable::releaseRef ( ) const
pure virtual

VMT #3.

Returns
New reference count, having deleted the object if it reaches zero.

The documentation for this class was generated from the following file: