///////////////////////////////////////////////////////////////////////////////
// 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 _DAI_SESSION_H
#define _DAI_SESSION_H
#include "daiBuildOptions.h"
#include "daiSessionInstance.h"
#include "daiError/daiErrorId.h"
#include "daiError/daiErrorEvent.h"
#include "daiAggr/daiList.h"
#define STL_USING_SET
#include "OdaSTL.h"
#include "TD_PackPush.h"
//DOM-IGNORE-BEGIN
DAI_EXPORT bool oddaiCloseCurrentSession();
//DOM-IGNORE-END
/** \details
Implements the Data Access Interface (DAI) that provides functionality for manipulating data that is defined within the EXPRESS SCHEMA format.
*/
namespace OdDAI {
/** \details
An abstract class that provides an interface of a custom event logger (or a custom error event list flusher).
*/
class IEventCollector
{
public:
/** \details
Destroys the event collector object.
*/
virtual ~IEventCollector() {}
/** \details
A handler method that is called when event recording starts.
This method must be implemented for any class that implements the event logger interface.
*/
virtual void onStartEventRecording() = 0;
/** \details
A handler method that is called when event recording ends.
This method must be implemented for any class that implements the event logger interface.
*/
virtual void onStopEventRecording() = 0;
/** \details
Logs an error event to the error events list (writes error data in the log).
\param functionID [in] A null-terminated string that contains the function name.
\param error [in] An error identifier.
\param descpt [in] A null-terminated string that contains the error description.
*/
virtual void logEvent(const char* functionID, daiErrorId error, const char* descpt) = 0;
/** \details
Logs an error event to the error events list (writes error data in the log).
\param eventToRecord [in] An error event object that contains information to be logged.
*/
virtual void logEvent(const ErrorEventPtr& eventToRecord) = 0;
};
/** \details
A data type that represents a smart pointer to an object of a class derived from the class.
*/
typedef OdSharedPtr EventCollectorPtr;
class Repository;
/** \details
A data type that represents a smart pointer to a object.
*/
typedef OdSmartPtr RepositoryPtr;
class Model;
/** \details
A data type that represents a smart pointer to a object.
*/
typedef OdSmartPtr ModelPtr;
/** \details
A class that implements functionality for working with session data as repositories,
error logging and non-persistent lists.
\remarks
The single current session instance can be created by calling the function,
it can be deleted only by calling the function.
The currently opened session can be accessed by calling the function.
*/
class DAI_EXPORT Session : public SessionInstance
{
public:
//DOM-IGNORE-BEGIN
ODRX_DECLARE_MEMBERS(Session);
//DOM-IGNORE-END
/** \details
Creates a new Session object with default parameters.
*/
Session();
/** \details
Generates a unique name of the .
The method searches a with a specified name within the current session.
If a with the specified name already exists, generates another unique name for the .
\param session [in] A raw pointer to the current session.
\param name [in] An ANSI string that contains the supposed name of the to create within a session.
\returns An ANSI string that contains the name of a that is available to create inside the specified session.
*/
static OdAnsiString generateRepositoryUniqueName(const Session *session, const OdAnsiString &name);
/** \details
Creates an empty with a specified name within the current session.
\param name [in] An ANSI string that contains the name of the to create.
\returns A smart pointer to the newly created .
*/
RepositoryPtr createRepo(const OdAnsiString &name);
/** \details
Creates a new with a specified name within the current session, and opens a specified file as part of the
newly created .
\param fileName [in] An ANSI string that contains the name of the file to open as part of the created .
\param name [in] An ANSI string that contains the name of the to create.
\returns A smart pointer to the newly created .
*/
RepositoryPtr createRepoFromFile(const OdAnsiString &fileName, const OdAnsiString &name = "");
/** \details
Creates a new with a specified name within the current session, and opens a specified bufferred model as part of the
newly created .
\param bufferedModel [in] A raw pointer to the data of the buffered to open as part of the created
\param name [in] An ANSI string that contains the name of the to create.
\returns A smart pointer to the newly created .
*/
RepositoryPtr createRepoFromBuffer(const char* bufferedModel, const OdAnsiString& name = "");
/** \details
Searches for a with a specified name within the current session.
\param name [in] An ANSI string that contains the name of the .
\returns
A smart pointer to the if it was found;
otherwise, the method returns a NULL smart pointer if there is no with the specified name in the current session.
*/
RepositoryPtr findRepo(const OdAnsiString &name) const;
/** \details
Opens a that exists in the current session and was not opened before.
\param repo [out] A smart pointer to the opened .
*/
void openRepo(RepositoryPtr &repo);
/** \details
Closes an opened assigned with the session.
\param repo [out] A smart pointer to the to close.
*/
void closeRepo(RepositoryPtr &repo);
/** \details
Deletes the record from the session container.
\param repo [out] A smart pointer to the to delete.
*/
void deleteRepoRecord(RepositoryPtr &repo);
/** \details
Retrieves the list of recorded error events.
\returns A of smart pointers to .
*/
const OdDAI::List& errors();
/** \details
Writes a record to the error event list.
\param functionID [in] A null-terminated string that contains the function name.
\param error [in] An error identifier.
\param descpt [in] A null-terminated string that contains the error description.
*/
void recordError(const char* functionID, daiErrorId error, const char* descpt);
/** \details
Determines whether the error logging is on or off.
\returns true if the error events recording mode is on; otherwise, the method returns false.
*/
bool isRecordingOn();
/** \details
Activates the error events recording mode.
*/
void startEventRecording();
/** \details
Deactivates the error events recording mode.
*/
void stopEventRecording();
/** \details
Sets an event collector object to handle error events in the runtime.
\param eventCollector [out] A smart pointer to the custom event collector object.
\remarks
When a custom event collector object was set, the default event collector become inactive, therefore the recording of error events is not working.
To restore the default event collector and resume events recording, call this method without a parameter.
*/
void resetEventCollector(const EventCollectorPtr& eventCollector = EventCollectorPtr());
/** \details
Creates an instance of Non-Persistent List (NPL).
\returns A pointer to the created non-persistent list.
*/
NonPersistentList* createNPL();
/** \details
Deletes an instance of Non-Persistent List (NPL).
\param npl [in] A raw pointer to the non-persistent list to be deleted.
*/
void deleteNPL(NonPersistentList *npl);
/** \details
Retrieves the current value of an attribute specified by its name.
\param attrName [in] An ANSI string that contains the attribute name.
\returns Returns the current value of the attribute.
\remarks
The method provides the late binding access to the attribute value by its name.
Attributes of select and aggregate data types are also supported.
*/
virtual OdRxValue getAttr(const char* attrName) const;
//DOM-IGNORE-BEGIN
protected:
class DefaultEventCollector;
private:
mutable OdMutex m_mutex;
//Implementation m_sdaiImplementation;
bool m_recordingActive;
OdDAI::List m_errors;
OdArray m_knownServers;
OdArray m_activeServers;
OdArray m_activeModels;
EventCollectorPtr m_eventCollector;
std::set m_NPLSet;
void appendActiveModel(ModelPtr &pModel);
void removeActiveModel(ModelPtr pModel);
/** \details
Closes current session instance.
\remarks
This method is for internal use only.
*/
void closeSession();
friend DAI_EXPORT bool ::oddaiCloseCurrentSession();
friend class Repository;
friend class Model;
class EventHandler;
};
/** \details
A data type that represents a smart pointer to a object.
*/
typedef OdSmartPtr SessionPtr;
//DOM-IGNORE-END
}
#include "TD_PackPop.h"
#endif // _DAI_SESSION_H