OSB_LIB::CdrStorage Class Reference

Inheritance diagram for OSB_LIB::CdrStorage:

Inheritance graph
[legend]
List of all members.

Detailed Description

Base class to handle CDR output of OSB modules.

This class defines the methods needed to store CDRs in the database, in one or more files or a combination of both.
The critical requirement is that all changes must be synchronized; it's all or nothing:
If anything goes wrong while processing an input stream, all modified files must be restored to their original status and all database transactions rolled-back.
In the moment where the database transactions are commited, all output files must reflect the committed status, they must not change afterwards.

When processing an input stream the application is expected to call the member functions in the following order:

beginStream()
Prepare the output for a new input stream.
The application should commit the database transactions after having called the function for all CDR storage instances.

push()
Call this member whenever the application has generated a CDR.
A concrete storage class may buffer the CDR or write to a temporary file.

prepareWrite()
Prepares to write the CDR to after all CDR of the input stream are processed.

writeCdrFiles()
Flushes all buffered CDR to the output file(s).

storeCdrs()
Saves all necessary information to the database and renames all output files to their final name.

endStream()
Call after database transactions from storeCdrs() have been commited.
All backup files are removed.

undoChanges()
Call whenever an error occurs during processing, but not after the transactions from storeCdrs() have been commited.
All modified files are restored to their original status and temporary output is deleted.

Todo:
If a concrete class stores the CDR in a database table, then it will buffer the CDR in push(). However if the buffer gets too big, there might a need to flush the buffer's content, i.e., to write the CDR to the database.
For such a behavior we'd need an OSB_DB::Session as parameter for push() or some kind of callback function.

Definition at line 123 of file cdrstorage.h.

Public Member Functions

Handling of generated CDRs
See class description for the expected sequence of calls.

Protected Member Functions

Copy construction and assignment:
In general the derived classes will not support copying and assignment; however for this class's point-of-view there no need to prevent it.

Classes


Constructor & Destructor Documentation

OSB_LIB::CdrStorage::CdrStorage (  ) 

Empty default constructor.

virtual OSB_LIB::CdrStorage::~CdrStorage (  )  [virtual]

Empty destructor.

OSB_LIB::CdrStorage::CdrStorage ( const CdrStorage  )  [protected]

Empty copy constructor.


Member Function Documentation

virtual OsbError OSB_LIB::CdrStorage::beginStream ( const OSB_DB::Session session,
const RecordStreamInfo input 
) [pure virtual]

Prepare to process a new batch of CDR records.

Parameters:
session Database session to use.
input Information about the input record stream being processed.
Exceptions:
StreamPending (see StreamPending).
Returns:
An OsbError with the appropriate information.
Its boolean operator returns false (no error) in case of success.

Implemented in OSB_LIB::FileCdrStorage.

virtual OsbError OSB_LIB::CdrStorage::endStream (  )  [pure virtual]

Finalize the processing of an input stream.

The function is called after the database transactions from storeCdrs() have been committed.

Derived classes typically remove backup files in this member.

Implemented in OSB_LIB::FileCdrStorage.

CdrStorage& OSB_LIB::CdrStorage::operator= ( const CdrStorage  )  [protected]

Empty assignment operator.

virtual OsbError OSB_LIB::CdrStorage::prepareWrite ( OSB_DB::Session session  )  [pure virtual]

Prepare to write the CDRs into files.

Parameters:
session Database session that can be used to mark the CDR files as being changed.
Derived classes must commit their transactions.
Note:
Before calling this function, the application should make sure that there's no pending transaction on session.

Implemented in OSB_LIB::FileCdrStorage.

virtual bool OSB_LIB::CdrStorage::push ( const Cdr cdr,
OsbError error 
) [pure virtual]

Add a CDR to the result set.

Parameters:
cdr CDR to add.
error Gets error information, it should not contain an error when calling this function.
Exceptions:
OsbException if a fatal error occurred.
Returns:
true in case of success, else false and error contains the appropriate information.
Note:
For performance reason OsbError is taken as non-const argument.

Implemented in OSB_LIB::FileCdrStorage.

virtual OsbError OSB_LIB::CdrStorage::storeCdrs ( const OSB_DB::Session session,
CdrList errors 
) [pure virtual]

Maintain the database and rename files to final name.

Parameters:
session Database session to use.
errors List to store CDRs that can not be stored.
Returns:
An OsbError with the appropriate information in case of severe error.
Note:
If the storage of individual CDR files the function returns success.

Implemented in OSB_LIB::FileCdrStorage.

virtual bool OSB_LIB::CdrStorage::undoChanges ( OSB_DB::Session session  )  [pure virtual]

Undo all changes on the CDR files and database.

Parameters:
session Database session to undo and commit the previous transactions (beginStream(), prepareWrite()).
Returns:
true in case of success, else false.
The function should not be called after endStream().
Derived classes must protect their data consistency by maintaining an appropriate flag.

Before the function is called, all database transactions made in storeCdrs() have been rolled-back.

The undo operation must proceed as much as possible!
This means the function should not throw (unless there's a real emergency), instead appropriate errors should be written to OSB_LIB::Log.

Implemented in OSB_LIB::FileCdrStorage.

virtual OsbError OSB_LIB::CdrStorage::writeCdrFiles (  )  [pure virtual]

Write the CDRs to file(s).

Returns:
An OsbError with the appropriate information.
Its boolean operator returns false (no error) in case of success.

Implemented in OSB_LIB::FileCdrStorage.


The documentation for this class was generated from the following file:
Generated on Sat Sep 2 14:15:15 2006 for OSB Library by  doxygen 1.4.7