CRioMMTopics Class Reference

#include <RioMMTopics.h>

Inherits CRioMMObject.

Public Member Functions

 CRioMMTopics (char *, unsigned int, RioBlock, struct timeval, RioMMInterface *)
 ~CRioMMTopics ()
int GetTopics (RioAccess, CRioStream *)
void Play ()
void Stop ()
void Pause ()
void FastRewind ()
void FastForward ()
void GoTo (unsigned int)
int init ()
RioBlock GetCurrentPosition ()
RioBlock GetTotalPositions ()
void setRio (RioMMInterface *)
RioMMInterfacegetRio ()
void setDomTree (QDomDocument *)
QDomDocument * getDomTree ()

Private Attributes

RioFileTopicsFile
QDomDocument * domTree
RioMMInterfacerio

Detailed Description

Definition at line 40 of file RioMMTopics.h.


Constructor & Destructor Documentation

CRioMMTopics::CRioMMTopics ( char *  TopicsName,
unsigned int  blocksize,
RioBlock  numBuffers,
struct timeval  RTT_average,
RioMMInterface rio_interface 
)

Definition at line 32 of file RioMMTopics.cpp.

00036     : CRioMMObject( TopicsName, blocksize, numBuffers , RTT_average )
00037 {
00038     setRio( rio_interface );
00039     TopicsFile   = NULL;
00040 }

CRioMMTopics::~CRioMMTopics (  ) 

Definition at line 183 of file RioMMTopics.cpp.

00184 {
00185     if( TopicsFile )
00186     {
00187         delete TopicsFile;
00188         TopicsFile = NULL;
00189     }
00190 }


Member Function Documentation

void CRioMMTopics::FastForward ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 171 of file RioMMTopics.cpp.

00171 {}

void CRioMMTopics::FastRewind ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 170 of file RioMMTopics.cpp.

00170 {}

RioBlock CRioMMTopics::GetCurrentPosition ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 174 of file RioMMTopics.cpp.

00174 { return 0; }

QDomDocument * CRioMMTopics::getDomTree (  ) 

Definition at line 178 of file RioMMTopics.cpp.

00178 { return domTree; }

RioMMInterface * CRioMMTopics::getRio (  ) 

Definition at line 181 of file RioMMTopics.cpp.

00181 { return rio; }

int CRioMMTopics::GetTopics ( RioAccess  Access,
CRioStream Stream 
)

Definition at line 42 of file RioMMTopics.cpp.

00043 {
00044     int rc;
00045     char tempdir[MAXPATHSIZE] = "RIOxmlXXXXXX";
00046     char tempfilename[MAXPATHSIZE];
00047 
00048     TopicsFile = new RioFile( MMObjectName, BlockSize );
00049     RioFile *DTDFile = new RioFile( "/etc/dtd/index.dtd", BlockSize );
00050 
00051     rc = TopicsFile->Open( Access, Stream );
00052     if( rc < 0 )
00053     {
00054         return rc;
00055     }
00056 
00057     rc = DTDFile->Open( Access, Stream );
00058     if( rc < 0 )
00059     {
00060         sendMsg( QString( "RioMMTopics" ), QString( "DTD file not found " ) +
00061                  QString( "at server.\nIndex file will not be loaded." ),
00062                  getRio() );
00063         // Fechando os objetos que foram abertos
00064         TopicsFile->Close();        
00065         return rc;
00066     }
00067 
00068     //Cria��o de um diret�rio tempor�rio para armazenar o DTD e o �ndice, pois 
00069     //de outra forma dois clientes concorrentes poderiam sobreescrever o arquivo
00070     //index.dtd. O nome do arquivo DTD n�o pode ser trocado pois fica dentro do
00071     //arquivo de �ndice
00072     if( RIOmktemp( tempdir ) == false )
00073     {
00074         RioErr << "[RioMMTopics]: Cannot create directory " << tempdir << endl;
00075         // Fechando os objetos que foram abertos
00076         TopicsFile->Close();        
00077         delete DTDFile;        
00078         return 0;
00079     }
00080 
00081     mkdir( tempdir, 0700 );
00082 
00083     strcpy( tempfilename, tempdir );
00084     strcat( tempfilename, "/topics.index" );
00085     TopicsFile->Download( tempfilename );
00086 
00087     strcpy( tempfilename, tempdir );
00088     strcat( tempfilename, "/index.dtd" );
00089     DTDFile->Download( tempfilename );
00090     setDomTree( new QDomDocument );
00091 
00092     QFile opmlFile( TopicsFile->GetLocalFilename() );
00093 
00094     QFile dtdLocalFile( DTDFile->GetLocalFilename() );
00095 
00096     //Parsing the xml file against the dtd
00097     xmlDoValidityCheckingDefaultValue = 1;
00098     xmlDocPtr doc = xmlParseFile( TopicsFile->GetLocalFilename() );
00099 
00100     xmlValidCtxt cvp;
00101     cvp.userData = NULL;
00102     cvp.error    = (xmlValidityErrorFunc) donothing;
00103     cvp.warning  = (xmlValidityWarningFunc) donothing;
00104 
00105     if( !xmlValidateDocumentFinal( &cvp, doc ) ||
00106         !xmlValidateDocument( &cvp, doc )
00107       )
00108     {
00109         sendMsg( QString( "RioMMTopics" ),
00110                  QString( "Invalid index file according to DTD.\n") +
00111                  QString( "It will not be loaded." ), getRio() );
00112         opmlFile.close();
00113         opmlFile.remove();
00114         dtdLocalFile.remove();
00115         rmdir( tempdir );
00116         // Fechando os objetos que foram abertos
00117         TopicsFile->Close();        
00118         delete DTDFile;        
00119         return 0;
00120     }
00121     xmlXIncludeProcess( doc );
00122     xmlFreeDoc( doc );
00123     xmlCleanupParser();
00124     xmlMemoryDump();
00125 
00126     if( !opmlFile.open( IO_ReadOnly ) )
00127     {
00128         RioErr << "[RioMMTopics]: Cannot open topics file." << endl;
00129         opmlFile.close();
00130         opmlFile.remove();
00131         dtdLocalFile.remove();
00132         rmdir( tempdir );
00133         // Fechando os objetos que foram abertos
00134         TopicsFile->Close();        
00135         delete DTDFile;        
00136         return 0;
00137     }
00138     if( !getDomTree()->setContent( &opmlFile ) )
00139     {
00140         RioErr << "[RioMMTopics]: Parsing error for index file." << endl;
00141         opmlFile.close();
00142         opmlFile.remove();
00143         dtdLocalFile.remove();
00144         rmdir( tempdir );
00145         // Fechando os objetos que foram abertos
00146         TopicsFile->Close();        
00147         delete DTDFile;        
00148         return 0;
00149     }
00150     opmlFile.close();
00151     opmlFile.remove();
00152     dtdLocalFile.remove();
00153     rmdir( tempdir );
00154 
00155     /* disparando o evento de cria��o do �ndice na interface */
00156     QCustomEvent *event = new QCustomEvent( (QEvent::Type)(QEvent::User + 3),
00157                                             getDomTree() );
00158     QApplication::postEvent( getRio(), event );
00159 
00160     // Fechando os objetos que foram abertos
00161     TopicsFile->Close();        
00162     delete DTDFile;        
00163           
00164     return 1;
00165 }

RioBlock CRioMMTopics::GetTotalPositions ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 175 of file RioMMTopics.cpp.

00175 { return 0; }

void CRioMMTopics::GoTo ( unsigned  int  ) 

Definition at line 172 of file RioMMTopics.cpp.

00172 {}

int CRioMMTopics::init ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 173 of file RioMMTopics.cpp.

00173 { return 0;}

void CRioMMTopics::Pause ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 169 of file RioMMTopics.cpp.

00169 {}

void CRioMMTopics::Play ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 167 of file RioMMTopics.cpp.

00167 {}

void CRioMMTopics::setDomTree ( QDomDocument *  d  ) 

Definition at line 177 of file RioMMTopics.cpp.

00177 { domTree = d; }

void CRioMMTopics::setRio ( RioMMInterface r  ) 

Definition at line 180 of file RioMMTopics.cpp.

00180 { rio = r; }

void CRioMMTopics::Stop ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 168 of file RioMMTopics.cpp.

00168 {}


Field Documentation

QDomDocument* CRioMMTopics::domTree [private]

Definition at line 45 of file RioMMTopics.h.

Definition at line 46 of file RioMMTopics.h.

Definition at line 44 of file RioMMTopics.h.


The documentation for this class was generated from the following files:
Generated on Wed Jul 4 16:03:32 2012 for RIO by  doxygen 1.6.3