CRioMMKeywords Class Reference

#include <RioMMKeywords.h>

Inherits CRioMMObject.

Public Member Functions

 CRioMMKeywords (char *, unsigned int, RioBlock, struct timeval, RioMMInterface *)
 ~CRioMMKeywords ()
int GetKeywords (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

RioFileKeywordsFile
QDomDocument * domTree
RioMMInterfacerio

Detailed Description

Definition at line 37 of file RioMMKeywords.h.


Constructor & Destructor Documentation

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

Definition at line 28 of file RioMMKeywords.cpp.

00031     : CRioMMObject( KeywordsName, blocksize, numBuffers , RTT_average )
00032 {
00033     setRio( rio_interface );
00034     KeywordsFile = NULL;
00035 }

CRioMMKeywords::~CRioMMKeywords (  ) 

Definition at line 233 of file RioMMKeywords.cpp.

00234 {
00235     if( KeywordsFile )
00236     {
00237         delete KeywordsFile;
00238         KeywordsFile = NULL;
00239     }
00240 }


Member Function Documentation

void CRioMMKeywords::FastForward ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 190 of file RioMMKeywords.cpp.

00191 {
00192 }

void CRioMMKeywords::FastRewind ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 186 of file RioMMKeywords.cpp.

00187 {
00188 }

RioBlock CRioMMKeywords::GetCurrentPosition ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 203 of file RioMMKeywords.cpp.

00204 {
00205     return 0;
00206 }

QDomDocument * CRioMMKeywords::getDomTree (  ) 

Definition at line 218 of file RioMMKeywords.cpp.

00219 {
00220     return domTree;
00221 }

int CRioMMKeywords::GetKeywords ( RioAccess  Access,
CRioStream Stream 
)

Definition at line 37 of file RioMMKeywords.cpp.

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

RioMMInterface * CRioMMKeywords::getRio (  ) 

Definition at line 228 of file RioMMKeywords.cpp.

00229 {
00230     return rio;
00231 }

RioBlock CRioMMKeywords::GetTotalPositions ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 208 of file RioMMKeywords.cpp.

00209 {
00210     return 0;
00211 }

void CRioMMKeywords::GoTo ( unsigned  int  ) 

Definition at line 194 of file RioMMKeywords.cpp.

00195 {
00196 }

int CRioMMKeywords::init ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 198 of file RioMMKeywords.cpp.

00199 {
00200     return 0;
00201 }

void CRioMMKeywords::Pause ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 182 of file RioMMKeywords.cpp.

00183 {
00184 }

void CRioMMKeywords::Play ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 174 of file RioMMKeywords.cpp.

00175 {
00176 }

void CRioMMKeywords::setDomTree ( QDomDocument *  d  ) 

Definition at line 213 of file RioMMKeywords.cpp.

00214 {
00215     domTree = d;
00216 }

void CRioMMKeywords::setRio ( RioMMInterface r  ) 

Definition at line 223 of file RioMMKeywords.cpp.

00224 {
00225     rio = r;
00226 }

void CRioMMKeywords::Stop ( void   )  [virtual]

Implements CRioMMObject.

Definition at line 178 of file RioMMKeywords.cpp.

00179 {
00180 }


Field Documentation

QDomDocument* CRioMMKeywords::domTree [private]

Definition at line 43 of file RioMMKeywords.h.

Definition at line 41 of file RioMMKeywords.h.

Definition at line 45 of file RioMMKeywords.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