added cutting support for multiple [file-N] segments, re #3

This commit is contained in:
darkeye 2007-02-25 15:16:23 +00:00
parent 1a8f07de82
commit ed22b57ef0
3 changed files with 30 additions and 14 deletions

View File

@ -317,7 +317,7 @@ DarkIce :: configIceCast ( const Config & config,
localDumpName = Util::fileAddDate(localDumpName);
}
localDumpFile = new FileSink( localDumpName);
localDumpFile = new FileSink( stream, localDumpName);
if ( !localDumpFile->exists() ) {
if ( !localDumpFile->create() ) {
reportEvent( 1, "can't create local dump file",
@ -519,7 +519,7 @@ DarkIce :: configIceCast2 ( const Config & config,
localDumpName = Util::fileAddDate(localDumpName);
}
localDumpFile = new FileSink( localDumpName);
localDumpFile = new FileSink( stream, localDumpName);
if ( !localDumpFile->exists() ) {
if ( !localDumpFile->create() ) {
reportEvent( 1, "can't create local dump file",
@ -762,7 +762,7 @@ DarkIce :: configShoutCast ( const Config & config,
localDumpName = Util::fileAddDate(localDumpName);
}
localDumpFile = new FileSink( localDumpName);
localDumpFile = new FileSink( stream, localDumpName);
if ( !localDumpFile->exists() ) {
if ( !localDumpFile->create() ) {
reportEvent( 1, "can't create local dump file",
@ -907,7 +907,7 @@ DarkIce :: configFileCast ( const Config & config )
// go on and create the things
// the underlying file
FileSink * targetFile = new FileSink( targetFileName);
FileSink * targetFile = new FileSink( stream, targetFileName);
if ( !targetFile->exists() ) {
if ( !targetFile->create() ) {
throw Exception( __FILE__, __LINE__,

View File

@ -118,8 +118,10 @@ static const char fileid[] = "$Id$";
* Initialize the object
*----------------------------------------------------------------------------*/
void
FileSink :: init ( const char * name ) throw ( Exception )
FileSink :: init ( const char * configName,
const char * name ) throw ( Exception )
{
this->configName = Util::strDup(configName);
fileName = Util::strDup(name);
fileDescriptor = 0;
}
@ -147,7 +149,7 @@ FileSink :: FileSink ( const FileSink & fs ) throw ( Exception )
{
int fd;
init( fs.fileName);
init( fs.configName, fs.fileName);
if ( (fd = fs.fileDescriptor ? dup( fs.fileDescriptor) : 0) == -1 ) {
strip();
@ -174,7 +176,7 @@ FileSink :: operator= ( const FileSink & fs ) throw ( Exception )
/* then build up */
Sink::operator=( fs );
init( fs.fileName);
init( fs.configName, fs.fileName);
if ( (fd = fs.fileDescriptor ? dup( fs.fileDescriptor) : 0) == -1 ) {
strip();
@ -311,7 +313,9 @@ FileSink :: write ( const void * buf,
/*------------------------------------------------------------------------------
* Get the file name to where to move the data saved so far.
* The trick is to read the file name from a file named
* /tmp/darkice.$PID , where $PID is the current process id
* /tmp/darkice.$configName.$PID , where:
* - $configName is the name of the configuration section for this file sink
* - $PID is the current process id
*----------------------------------------------------------------------------*/
std::string
FileSink :: getArchiveFileName ( void ) throw ( Exception )
@ -319,7 +323,7 @@ FileSink :: getArchiveFileName ( void ) throw ( Exception )
pid_t pid = getpid();
std::stringstream metaFileName;
metaFileName << "/tmp/darkice." << pid;
metaFileName << "/tmp/darkice." << configName << "." << pid;
std::ifstream ifs(metaFileName.str().c_str());
if (!ifs.good()) {

View File

@ -58,6 +58,12 @@ class FileSink : public Sink, public virtual Reporter
{
private:
/**
* The name of the configuration related to
* this file sink. something like "file-0" or "file-2".
*/
char * configName;
/**
* Name of the file represented by the FileSink.
*/
@ -66,11 +72,14 @@ class FileSink : public Sink, public virtual Reporter
/**
* Initialize the object.
*
* @param configName the name of the configuration related to
* this file sink. something like "file-0" or "file-2".
* @param name name of the file to be represented by the object.
* @exception Exception
*/
void
init ( const char * name ) throw ( Exception );
init ( const char * configName,
const char * name ) throw ( Exception );
/**
* De-initialize the object.
@ -115,13 +124,16 @@ class FileSink : public Sink, public virtual Reporter
/**
* Constructor by a file name.
*
* @param configName the name of the configuration related to
* this file sink. something like "file-0" or "file-2".
* @param name name of the file to be represented by the object.
* @exception Exception
*/
inline
FileSink( const char * name ) throw ( Exception )
FileSink( const char * configName,
const char * name ) throw ( Exception )
{
init( name);
init( configName, name);
}
/**