OSB_LIB::CdrIoImpl Class Reference

Inheritance diagram for OSB_LIB::CdrIoImpl:

Inheritance graph
[legend]
Collaboration diagram for OSB_LIB::CdrIoImpl:

Collaboration graph
[legend]
List of all members.

Detailed Description

This object is responsible to store and retrieve call details records from file system.

This class is responsible to store the Cdr that belongs to a network partner balance sheet to file system (writing them to CDR file(s) in the corresponding balance page directory structure).

Definition at line 75 of file cdrioimpl.h.

Public Member Functions

Private Types

Private Member Functions

Private Attributes

Static Private Attributes


Member Typedef Documentation

typedef std::map<Date, CdrList> OSB_LIB::CdrIoImpl::CdrGroups [private]

Container to hold cdrs by date.

Definition at line 116 of file cdrioimpl.h.

typedef std::set<std::string> OSB_LIB::CdrIoImpl::PathList [private]

STL container to store changed CDR files.

Definition at line 118 of file cdrioimpl.h.


Constructor & Destructor Documentation

OSB_LIB::CdrIoImpl::CdrIoImpl ( const Id< BsPage > &  pageId  ) 

Constructor with id of supported balance page.


Member Function Documentation

std::auto_ptr<CdrIo> OSB_LIB::CdrIoImpl::clone (  )  const [virtual]

Virtual copy constructor.

Implements OSB_LIB::CdrIo.

bool OSB_LIB::CdrIoImpl::commitChanges (  )  [virtual]

Remove backup CDR files.

Returns:
true in case of success, else false.
Note:
This member function should not throw if an error occurs. The changes in the database have been commited and the operation should proceed as much as possible.
Instead any errors are written to log.

Implements OSB_LIB::CdrIo.

void OSB_LIB::CdrIoImpl::copyFile ( const std::string &  from,
const std::string &  to 
) [private]

Make a copy of a file.

Parameters:
from Path name of source file.
to Path name of target file.
Exceptions:
OsbException for any error:
  • target file exists
  • error opening source file
  • error opening target file
  • error reading from source file
  • error writing to source file

size_t OSB_LIB::CdrIoImpl::getCdrFiles ( const std::string &  dirName,
PathList dest 
) [private]

Get all CDR files.

Parameters:
dirName Name of directory to search (recursivly).
dest Gets the list of CDR files.
Exceptions:
OsbException if the page directory exists but can not accessed.
Returns:
The number of CDR files or -1 in case of an error (as from ScanDir::scan()).

size_t OSB_LIB::CdrIoImpl::getSubDirs ( const std::string &  dirName,
PathList dest 
) [private]

Get all subdirectories.

Parameters:
dirName Name of directory to search (recursivly).
dest Gets the list of subdirectories.
Exceptions:
OsbException if the page directory exists but can not accessed.
Returns:
The number of CDR files or -1 in case of an error (as from ScanDir::scan()).

void OSB_LIB::CdrIoImpl::groupCdrsByDate ( CdrGroups dest,
const CdrList src 
) [private]

Group cdrs by date.

The function groups the list of cdrs by date so that inserting these cdrs into the file system would be faster since the directory structure of these cdrs are stored by date.

Parameters:
dest Gets the list of CDRs grouped by date.
src The list of CDRs to be grouped.

std::string OSB_LIB::CdrIoImpl::mkFilename ( long  n  )  const [private]

Create filename (without extension) from a number.

Parameters:
n Number to use.
Returns:
A character string with minimum 4 characters, left padded with '0'. It does not end with an extension.

void OSB_LIB::CdrIoImpl::moveFileAway ( const std::string &  path  )  [private]

Rename an obsolete backup file.

Parameters:
path Path of backup file.
Exceptions:
OsbException if rename() fails.
The function renames the file path by appending an integer counter.

Note:
If the backup file path does not exist, the function returns immediately without error.

std::string OSB_LIB::CdrIoImpl::newCdrFile ( const std::string &  dirName,
size_t  numFiles 
) const [private]

Create a new CDR file.

Parameters:
dirName Directory in which to create the CDR file, it must exist.
numFiles Number of CDR files in dirName.
Exceptions:
OsbException if the creation of the CDR file fails.
Returns:
The path of the new CDR file.
The function increments numFiles until no CDR file with the corresponding name exists.
Then it creates the file in binary write mode and returns its path.

FILE* OSB_LIB::CdrIoImpl::openOutputFile ( std::string &  path,
bool  mkBackup 
) [private]

Open the last regular CDR file, creating a backup.

Parameters:
path On input: Directory to use. The function appends a trailing / if needed.
On output: Path to the opened CDR file (if the function returns successful).
mkBackup Flag if backup copies of modified files must be created.
Exceptions:
OsbException in case of any error:
  • CDR directory of page does not exist or can not be created.
  • CDR directory of page can not be opened.
  • Error while creating a new CDR file.
  • Error during creation of backup file.
Returns:
Pointer to the regular CDR file, opened in binary append mode.
The function determines the last regular CDR file in the directory dirName, creates a backup copy of this file and opens it in append mode. If no regular CDR file exists in dirName, an empty backup file is created.

std::string OSB_LIB::CdrIoImpl::pageDir (  )  const [private]

Base directroy of the balance page.

Returns:
baseDir_ + '/' + pageId() + '/'.

const Id<BsPage>& OSB_LIB::CdrIoImpl::pageId (  )  const [virtual]

Id of the supported balance page.

Implements OSB_LIB::CdrIo.

void OSB_LIB::CdrIoImpl::prepareWrite (  )  [virtual]

Prepare the CDR files for writing.

Exceptions:
OsbException for any error encountered.

Implements OSB_LIB::CdrIo.

void OSB_LIB::CdrIoImpl::read ( CdrList dest,
const std::string &  path 
) [private]

Read all CDRs from a file.

Parameters:
dest STL-container to store the CDR records.
path Path of input file.
Exceptions:
OsbException 
  • if path can not be opened
  • in case of an ASN.1 decoding error.

void OSB_LIB::CdrIoImpl::read ( CdrList dest  )  [virtual]

Retrieve the call details records of a balance page.

Parameters:
dest STL-container to store the CDR records.
Exceptions:
OsbException for any error encountered.

Implements OSB_LIB::CdrIo.

bool OSB_LIB::CdrIoImpl::remove (  )  [virtual]

Remove related CDR files and directories from file system.

This function deletes all regular CDR files and, if empty, the directories below and including baseDir_.

Remarks:
The function does not stop if removal of CDR file fails, but continue to remove as many CDR files as possible.
Returns:
False if a regular CDR file cannnot be removed else true.

Implements OSB_LIB::CdrIo.

bool OSB_LIB::CdrIoImpl::removeChangedFile ( const std::string &  path  )  [private]

Remove a changed CDR file.

Parameters:
path Path of file to remove.
Returns:
true if successful, false if an error occurred:
  • path does not exist,
  • path can not be removed.

bool OSB_LIB::CdrIoImpl::removeChangedFiles (  )  [private]

Remove all changed CDR files.

Returns:
true in case of success, false if one or more errors occurred.
Calls removeChangedFile() for every entry in changedFiles_.

Note:
The function is called from undoChanges() and therefore must not throw.

std::string OSB_LIB::CdrIoImpl::renameCdrFile ( const std::string &  filePath,
const std::string &  extTo 
) [private]

Rename a CDR file to its backup.

Parameters:
filePath Path of CDR file.
extTo Extension of backup file.
Exceptions:
OsbException 
  • if the backup file exists.
  • if std::rename fails.
Returns:
The path of the backup file.

void OSB_LIB::CdrIoImpl::replace ( const CdrList newCdrs,
Asn1Writer writer 
) [virtual]

Replace CDRs on the file system.

Parameters:
newCdrs STL container with new CDRs.
writer ASN.1 writer to use.
Exceptions:
OsbException for any error encountered.

Implements OSB_LIB::CdrIo.

bool OSB_LIB::CdrIoImpl::restoreCdrFile ( const std::string &  path  )  [private]

Recover a CDR file.

Parameters:
path Name of the file to recover, it must end with extBak_ or extRpl_.
Returns:
true in case of success, else false.
The recovery logic is as follows:

bool OSB_LIB::CdrIoImpl::restoreCdrFiles (  )  [private]

Restore all changed CDR files.

Returns:
true in case of success, false if one or more errors occurred.
Attention:
This function must be called after removeChangedFiles(). Restoring a file will fail if the (changed) CDR file still exists.
Calls removeChangedFile() for every entry in changedFiles_.

Note:
The function is called from undoChanges() and therefore must not throw.

bool OSB_LIB::CdrIoImpl::undoChanges (  )  [virtual]

Undo a previous call to write() or replace().

Returns:
true in case of success, else false.
Note:
This member function should not throw if an error occurs, because the recovery operation should proceed as much as possible. Instead any errors are written to log.

Implements OSB_LIB::CdrIo.

void OSB_LIB::CdrIoImpl::write ( const CdrList cdrs,
Asn1Writer writer,
bool  mkBackup 
) [private]

Write the CDRs to the file system.

Parameters:
cdrs List of CDRs to write.
writer ASN.1 writer to use.
mkBackup Flag if backup copies of modified files must be created.
Exceptions:
OsbException in case of any error.

void OSB_LIB::CdrIoImpl::write ( const CdrList cdrs,
Asn1Writer writer 
) [virtual]

Write CDRs to the file system.

Parameters:
cdrs List of call details records to write.
writer ASN.1 writer to use.
Exceptions:
OsbException for any error encountered.
Note:
Missing directories are created as needed.

Implements OSB_LIB::CdrIo.


Member Data Documentation

PathList OSB_LIB::CdrIoImpl::changedFiles_ [private]

List of changed CDR files, with extension.

Definition at line 378 of file cdrioimpl.h.

const std::string OSB_LIB::CdrIoImpl::extBak_ [static, private]

Extension for the backup CDR files.

Definition at line 368 of file cdrioimpl.h.

const std::string OSB_LIB::CdrIoImpl::extCdr_ [static, private]

Extension for the original CDR files.

Definition at line 370 of file cdrioimpl.h.

const std::string OSB_LIB::CdrIoImpl::extRpl_ [static, private]

Extension for replaced CDR files.

Definition at line 372 of file cdrioimpl.h.

Id<BsPage> OSB_LIB::CdrIoImpl::pageId_ [private]

Id of supported balance page.

Definition at line 376 of file cdrioimpl.h.

PathList OSB_LIB::CdrIoImpl::recoverFiles_ [private]

List of backup CDR files, with extension.

Definition at line 380 of file cdrioimpl.h.


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