/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef __TNW_DB_EXCHANGE_PE_H__ #define __TNW_DB_EXCHANGE_PE_H__ #include "RxObject.h" #include "NwExport.h" #include #include #include "Exchange/NwExchangeParams.h" class OdNwDatabase; /** \details This template class is a specialization of the OdSmartPtr class for OdNwDatabase object pointers. */ typedef OdSmartPtr OdNwDatabasePtr; /// Job identifier type. using NwJobId = OdUInt32; /** \details Contains job execution status definitions. */ enum class NwExchangeJobStatus { /** Job is queued for execution. */ kQueued, /** Job is currently running. */ kRunning, /** Job completed successfully. */ kDone, /** Job failed during execution. */ kFailed, /** Job was canceled. */ kCanceled }; /** \details Result of an exchange operation, containing either a database pointer or error message. */ struct NwExchangeResult { std::variant m_res; ///< Result variant: database on success, error message on failure. }; /** \details Task launcher function type alias for asynchronous execution of exchange operations. Accepts a work function and returns a future containing the exchange result. */ using NwTaskLauncher = std::function(std::function)>; /** \details Work factory function type alias for exchange operations with progress tracking. Accepts a progress counter and cancellation token, returns the exchange result. */ using NwWorkFactory = std::function*, NwCancelToken*)>; /** \details This class manages asynchronous exchange operations on a BimNv database. It provides job lifecycle management, status tracking, and cancellation support. */ class NWDBEXPORT OdNwExchangeJobManagerBase : public OdRxObject { //DOM-IGNORE-BEGIN ODRX_DECLARE_MEMBERS(OdNwExchangeJobManagerBase); //DOM-IGNORE-END public: /** \details Default constructor. Creates a new OdNwExchangeJobManagerBase object. */ OdNwExchangeJobManagerBase() = default; /** \details Virtual destructor. Frees allocated resources. */ virtual ~OdNwExchangeJobManagerBase() = default; /** \details Start an asynchronous conversion operation on a database. \param params [in] Conversion parameters. \returns Job ID for tracking the operation (0 indicates failure). */ virtual NwJobId startConvert2(const NwExchangeConvertParams& params) = 0; /** \details Start an asynchronous import operation from an external file. \param sPath2Ext [in] Path to the external file to import. \param params [in] Conversion parameters. \returns Job ID for tracking the operation (0 indicates failure). */ virtual NwJobId startImportFrom(const OdString& sPath2Ext, const NwExchangeConvertParams& params) = 0; /** \details Query the status of a running job. \param jobId [in] Job identifier obtained from startConvert2 or startImportFrom. \param out [out] Output result (optional, can be null). Valid only for done/failed status. \param pProgress_out [out] Progress percentage (optional, can be null). Range: 0-100. \returns Current job status. \remarks Returned status can be one of the following: Name Description NwExchangeJobStatus::kQueued Job is queued for execution NwExchangeJobStatus::kRunning Job is currently running NwExchangeJobStatus::kDone Job completed successfully NwExchangeJobStatus::kFailed Job failed during execution NwExchangeJobStatus::kCanceled Job was canceled
*/ virtual NwExchangeJobStatus query(NwJobId jobId, NwExchangeResult* out = nullptr, int* pProgress_out = nullptr) = 0; /** \details Request cancellation of a running job. \param jobId [in] Job identifier to cancel. */ virtual void cancel(NwJobId jobId) = 0; /** \details Gets the database associated with this job manager. \returns Pointer to the OdNwDatabase object. */ virtual OdNwDatabase* getDatabase() = 0; /** \details Gets the task launcher used by this job manager for asynchronous execution. \returns Task launcher function object. */ virtual NwTaskLauncher getTaskLauncher() = 0; /** \details Registers a new job and launches it using the provided work factory. \param type [in] Exchange operation type. \param workFactory [in] Work factory function for the job execution. \returns Job ID for tracking the operation (0 indicates failure). \remarks The type parameter can be one of the following: Name Description NwExchangeType::kUnknown Unknown or unspecified exchange type NwExchangeType::kNw2Ifc Navisworks to IFC format conversion NwExchangeType::kNw2Vsfx Navisworks to VSFX format conversion
*/ virtual NwJobId registerJobAndLaunch(NwExchangeType type, NwWorkFactory workFactory) = 0; }; /** \details This template class is a specialization of the OdSmartPtr class for OdNwExchangeJobManagerBase object pointers. */ typedef OdSmartPtr OdNwExchangeJobManagerBasePtr; /** \details Default task launcher implementation using std::async for asynchronous execution. \param task [in] Work function to execute asynchronously. \returns Future object containing the exchange result. */ inline std::future defaultTaskLauncher(std::function task) { return std::async(std::launch::async, std::move(task)); } /** \details This class represents a protocol extension for managing database exchange operations. Implementations provide factory methods for creating job managers that handle conversions and imports. */ class NWDBEXPORT OdNwAbstractDBExchangePE : public OdRxObject { //DOM-IGNORE-BEGIN ODRX_DECLARE_MEMBERS(OdNwAbstractDBExchangePE); //DOM-IGNORE-END public: /** \details Default constructor. Creates a new OdNwAbstractDBExchangePE object. */ OdNwAbstractDBExchangePE() = default; /** \details Virtual destructor. Frees allocated resources. */ virtual ~OdNwAbstractDBExchangePE() = default; /** \details Creates a job manager for handling exchange operations on the specified database. \param pDb [in] Pointer to the database for exchange operations. \param launcher [in] Task launcher for asynchronous execution (defaults to defaultTaskLauncher). \returns Smart pointer to the created job manager. */ virtual OdNwExchangeJobManagerBasePtr createJobManager(OdNwDatabase* pDb, NwTaskLauncher launcher = defaultTaskLauncher) = 0; }; /** \details This template class is a specialization of the OdSmartPtr class for OdNwAbstractDBExchangePE object pointers. */ typedef OdSmartPtr OdNwAbstractDBExchangePEPtr; #endif //__TNW_DB_EXCHANGE_PE_H__