#pragma once
namespace Rimage { namespace Rapid { namespace Impl {
class InternClientSession;
class WinSubclasser;
}}}
namespace Rimage { namespace Rapid { namespace Api {
class Connection;
class ISessionStatusListener;
class IJobStatusListener;
class IXmlModifyListener;
class ServerAlert;
class ImageOnlyJob;
class ProductionOnlyJob;
class ImageAndRecordJob;
///
/// Working with the Rapid API starts with initiating a client session with the Rimage system.
/// The ClientSession class is the base class for all sessions. It exposes methods that are common to all types
/// of sessions, such as job creation, enumerating over jobs, servers, and alerts, and setting job and session listeners.
///
///
/// An application maintains a reference to one and only one session object.
///
///
/// This class is never instantiated by the caller directly. Call the static method SingleConnectionSession.GetInstance()
/// to get an instance of a session.
///
///
/// Rimage Corporation, Copyright (c) 2007
///
class SIMPLECLIENT_API ClientSession
{
public:
// No public constructor
virtual ~ClientSession();
///
/// Connects to the Rimage messaging server.
///
///
/// A connection has to be established prior to submitting jobs.
///
/// An ID string that uniquely identifies the client application.
/// Computer name hosting the messaging server. Defaulted to "localhost".
/// The port messaging server is listening on. Defaulted to "4664".
/// A pointer to a new Connection object if successful, otherwise a RimageException is thrown.
/// Thrown when host or port are invalid, or the connection cannot be established.
virtual Connection* Connect(LPCTSTR clientId, LPCTSTR host=NULL, LPCTSTR port=NULL);
///
/// Creates an ImageOnlyJob object or one of its subclasses. The jobType has to be between ImageOnlyJobType and UserImageOnlyJobTypeLast.
///
/// Identifies the specific Image Only job type.
/// A pointer to a new ImageOnlyJob object if successful, otherwise a RimageException is thrown.
/// Thrown when jobType is out of range.
ImageOnlyJob* CreateImageOnlyJob(JobType jobType);
///
/// Creates a ProductionOnlyJob object or one of its subclasses. The jobType should be between ProductionOnlyJobType and UserProductionOnlyJobTypeLast.
///
/// Identifies the specific Production Only job type.
/// A pointer to a new ProductionOnlyJob object if successful, otherwise RimageException is thrown.
/// Thrown when jobType is out of range.
ProductionOnlyJob* CreateProductionOnlyJob(JobType jobType);
///
/// Creates an ImageAndRecordJob object or one of its subclasses. The jobType should be between ImageAndRecordJobType and UserImageAndRecordJobTypeLast.
///
/// Identifies the specific Image and Record job type.
/// A pointer to a new ImageAndRecordJob object if successful, otherwise RimageException is thrown.
/// Thrown when jobType is out of range.
ImageAndRecordJob* CreateImageAndRecordJob(JobType jobType);
///
/// Initializes a JobIterator object to enable enumeration over created Job objects.
///
/// Reference to the JobIterator object to initialize.
/// void
void InitJobIterator(JobIterator &iter);
///
/// Retrieves a specific Job object which has been created by the API.
///
/// ID of the job to retrieve.
/// A pointer to the Job object if sucessful, otherwise NULL.
Job* GetCreatedJob(LPCTSTR jobId);
///
/// Cancels a submitted job.
///
/// The ID of the job to cancel.
/// void
/// Thrown in case the job with the given ID does not exist.
void CancelJob(LPCTSTR jobId);
///
/// Sets session listener for asynchronously receiving system-wide events, such as server state changes and server alerts.
///
/// An object of a class that implements the ISessionStatusListener interface.
/// A flag to indicate if the caller intends to have the listener called
/// in the main UI thread of the client application, defaulted to UITrue. For non-UI applications, this
/// should always be UIFalse.
/// void
/// Thrown when callbackType is true but no UI thread is found in the application.
void SetSessionStatusListener(ISessionStatusListener *statusListener, CallbackOnMainUIThread callbackType=UITrue);
///
/// Sets session listener for asynchronously receiving system-wide events, such as server state changes and server alerts.
///
/// An object of a class that implements the ISessionStatusListener interface.
/// The thread ID that the caller intends to have the listener called in.
/// The thread should be a UI thread.
/// void
/// Thrown when callbackUIThreadId is an invalid thread ID or the thread does not
/// have a UI window attached.
void SetSessionStatusListener(ISessionStatusListener *statusListener, DWORD callbackUIThreadId);
///
/// Sets the default job listener for asynchronously receiving job progress statuses.
///
///
/// A job listener can also be set with the specific job object.
///
/// An object of a class that implements the IJobStatusListener interface.
/// A flag to indicate if the caller intends to have the listener called
/// in the main UI thread of the client application, defaulted to UITrue. For non-UI applications, this
/// should always be UIFalse.
///
/// void
/// Thrown when callbackType is true but no UI thread is found in the application.
void SetDefaultJobListener(IJobStatusListener *statusListener, CallbackOnMainUIThread callbackType=UITrue);
///
/// Sets the default job listener for asynchronously receiving job progress statuses.
///
///
/// A job listener can also be set with the specific job object.
///
/// An object of a class that implements the IJobStatusListener interface.
/// The thread ID that the caller intends to have the listener called in.
/// The thread should be a UI thread.
/// void
/// Thrown when callbackUIThreadId is an invalid thread ID or the thread does not
/// have a UI Window attached.
void SetDefaultJobListener(IJobStatusListener *statusListener, DWORD callbackUIThreadId);
///
/// Returns the session status listener.
///
/// Pointer to an object which implements ISessionStatusListener if one was set, NULL otherwise.
ISessionStatusListener* GetSessionStatusListener();
///
/// Removes the session status listener to stop recieving session related events.
///
///
/// It is not necessary to call this
/// method at the end of a client session, the system will call this automatically.
///
/// void
/// Thrown in case of an internal problem.
void RemoveSessionStatusListener();
///
/// Returns the default job status listener.
///
/// Pointer to an object which implements IJobStatusListener if one was set, NULL otherwise.
IJobStatusListener* GetDefaultJobListener();
///
/// Removes the default job status listener to stop recieving job statuses.
///
///
/// It is not necessary to call this
/// method at the end of a client session, the system will call this automatically.
///
/// void
/// Thrown in case of an internal problem.
void RemoveDefaultJobListener();
///
/// Sets the listener for modifying XML strings before they are sent to servers.
///
void SetXmlModifyListener(IXmlModifyListener *pXmlModifyListener);
///
/// Removes the listener for modifying XML if it was set.
///
void RemoveXmlModifyListener();
///
/// Sets a user defined Job factory. This method is optional unless you are creating new Job types.
///
///
/// Rapid API uses an internal job factory for Rimage predefined job types.
///
/// An object of a class that implements the IJobFactory interface.
/// void
void SetUserJobFactory(IJobFactory *jobFactory);
///
/// Returns the user defined Job factory.
///
/// Pointer to an object which implements IJobFactory if one was set, NULL otherwise.
IJobFactory* GetUserJobFactory();
///
/// Removes the user defined Job factory if one has been set by calling SetUserJobFactory().
///
///
/// Rapid API does not delete the user defined IJobFactory object, it just removes it from its list.
///
/// void
void RemoveUserJobFactory();
///
/// Sets a user defined XML writer factory. This method is optional unless you are altering the way XML
/// orders are generated. Rapid API uses an internal XML writer factory for Rimage predefined XML writers.
///
/// An object of a class that implements the IXmlWriterFactory interface.
/// void
void SetUserXmlWriterFactory(IXmlWriterFactory *xmlWriterFactory);
///
/// Returns the user defined XML writer factory.
///
/// Pointer to an object which implements IXmlWriterFactory if one was set, NULL otherwise.
IXmlWriterFactory* GetUserXmlWriterFactory();
///
/// Removes the user defined IXmlWriterFactory object if one has been set by calling SetUserXmlWriterFactory().
///
/// Rapid API does not delete the user specified IXmlWriterFactory object, it just removes it from its list.
///
///
/// void
void RemoveUserXmlWriterFactory();
///
/// Initializes a ServerIterator object to enable enumeration over all Server objects in the system.
///
/// Reference to the ServerIterator object to initialize.
/// void
void InitServerIterator(ServerIterator& iter);
///
/// Retrieves a specific server object with the given connection ID and server ID.
///
/// Connection ID for the intended server. This identifies the connection this server is active on, obtained by calling Connection.GetConnectionId().
/// Server ID for the intended server.
/// A pointer to a Server object if successful, NULL if no server exists for
/// the given connection ID and server ID.
/// Thrown if the server ID and/or connection ID is invalid.
Server* GetServer(LPCTSTR connectionId, LPCTSTR serverId);
///
/// Removes offline Server objects from Rapid APIs internal lists.
///
///
/// Main reason for calling this method is to free application's memory.
///
/// void
void RemoveOfflineServers();
///
/// Initializes a ServerAlertIterator object to enable enumeration over all ServerAlert objects in the system.
///
/// Reference to the ServerAlertIterator object to initialize.
/// void
void InitServerAlertIterator(ServerAlertIterator &iter);
///
/// Retrieves a specific ServerAlert object with the given server ID and alert ID.
///
/// Server ID for the server this alert is for.
/// Alert ID for the specific server alert.
/// A pointer to a ServerAlert object if successful, NULL if no such ServerAlert exists
/// for the given server ID and alert ID.
/// Thrown if the server ID and/or alert ID is invalid.
ServerAlert* GetServerAlert(LPCTSTR serverId, LPCTSTR alertId);
///
/// Removes acknowledged, or not active, ServerAlert objects from Rapid APIs internal lists.
///
///
/// Main reason for calling this method is to free application's memory.
///
/// void
void RemoveAcknowledgedServerAlerts();
///
/// Removes a specific Job from Rapid APIs internal lists.
///
///
/// This method does nothing if the job with the ID does not exist.
///
/// ID of the Job to remove.
/// true if job was removed, false otherwise
/// Thrown if the job is submitted or in process.
bool RemoveJob(LPCTSTR jobId);
///
/// Removes all finished jobs from Rapid APIs internal lists.
///
///
/// This method does not remove jobs that are created but have never been submitted.
///
/// void
void RemoveFinishedJobs();
///
/// Optionally sets a directory where information about durable jobs is stored.
///
///
/// A default directory is used if this method is never called.
///
void SetDurableJobDirectory(LPCTSTR szDurableJobDir);
///
/// Gets the directory where information about durable jobs is stored.
///
/// Full path to the durable job directory.
LPCTSTR GetDurableJobDirectory();
///
/// Recovers all previously in process jobs, for all open connections.
///
///
/// This method recovers job statuses for jobs that were in process when the caller application
/// either shutdown or disconnected.
///
/// If the iterator is provided, it contains the list of recovered Job IDs
/// Total number of jobs recovered for all connections.
virtual int RecoverDurableJobs(StringIterator *jobIdList = NULL) = 0;
///
/// Disconnects from the messaging server this session is connected to.
///
/// Thrown in case of an internal or a network problem.
/// void
virtual void Disconnect() = 0;
///
/// Returns the string form of the specific server related enum values.
///
/// An enum value related to Server class.
/// The corresponding string name of the enum value.
/// Thrown when the enumValue is out of rangne.
static LPCTSTR EnumToString(int enumValue);
///
/// Setting comments into the XML strings generated by RAPID. If set, the string will be placed
/// right after the XML start and before the RAPID default comment.
///
/// Comment to add.
void SetXmlOriginatorComment(LPCTSTR szComment);
protected:
ClientSession(bool bSingleConnSession);
// For internal use
static ClientSession *GetCurrSession();
Rimage::Rapid::Impl::InternClientSession *GetInternSession() ;
Job* CreateJob(JobType jobType);
private:
IJobFactory *m_pDefaultJobFactory;
IJobFactory *m_pUserJobFactory;
Rimage::Rapid::Impl::InternClientSession *m_pInternSession;
DWORD m_dwJobIDCounter;
// Either an instance of SingleConnectionSession or MultpleConnectionSession;
static ClientSession *gpCurrentClientSession;
friend class Rimage::Rapid::Impl::ConnectionImpl;
friend class Rimage::Rapid::Impl::WinSubclasser;
};
}}}