CObjectManager Class Reference

#include <ObjectManager.h>

Public Member Functions

 CObjectManager (CRioTCP *TCPconnection)
 ~CObjectManager ()
HRESULT Close (const ObjectHandle Handle)
HRESULT GetSize (const ObjectHandle Handle, RioObjectSize *Size)
HRESULT SetSize (const ObjectHandle Handle, const RioObjectSize Size, char *md5sum)
HRESULT GetType (const ObjectHandle Handle, short *Type)
HRESULT GetnBlocks (const ObjectHandle Handle, RioBlock *nBlocks)
HRESULT NextObject (ObjectHandle Handle, int *IsDirectory, int BufferSize, signed char *ObjectName)
HRESULT GetVideoRate (const ObjectHandle Handle, unsigned int *VideoRate)
 GetVideoRate retorna a taxa de transmissao (em Kbps) do video.
HRESULT SetVideoRate (const ObjectHandle Handle, const unsigned int VideoRate)
 SetVideoRate altera a taxa de transmissao (em Kbps) do video.
HRESULT ReallocBlocks (const ObjectHandle Handle, const RioBlock Block)
 Funcao usada para realocar os blocos fisicos do bloco logico passado como parametro.
 CObjectManager ()
 ~CObjectManager ()
int Reset ()
int Stop ()
int Start ()
int Format ()
int GetBlockMap (ObjectHandle Handle, RioBlock First, RioBlock nBlocks, RioDiskBlock *blocks)
int GetnBlocks (ObjectHandle Handle, RioBlock *nBlocks)
int GetType (ObjectHandle Handle, short *Type)
int GetSize (ObjectHandle Handle, RioObjectSize *Size)
int SetSize (ObjectHandle Handle, RioObjectSize Size)
int Close (ObjectHandle Handle)
int Open (char *ObjectPath, RioAccess Access, RioObject **Object)
int Delete (char *ObjectPath)
int Rename (char *OldPath, char *NewPath)
int Create (char *Path, short Type)
int Initialize (ObjectManagerConfig *Config)
int GetBlockSize (unsigned int *BlockSize)
int GetObjectInfo (char *ObjectName, ObjectInfo *ObjectInfo)
int ExistDirectory (char *Path)
int FirstObject (char *DirectoryPath, RioDirectory **Directory, int *IsDirectory, int BufferSize, char *ObjectName)

Static Public Member Functions

static int StrToPath (const char *Str, char *PathName, const int MaxSize)

Private Member Functions

int createdirectory (char *name)
int RemoveDirectory (char *DirectoryName)
int RemoveObject (char *ObjectName)
int SetDefaultPermissions (char *name)
int PathToFile (const char *Path, char *FileName, const int MaxSize)

Private Attributes

CRioTCPm_TCPconnection
ofstream m_log
int m_MaxReplications
int m_UseReplications
bool m_initialized
bool m_started
char * m_FileRoot
unsigned int m_BlockSize
ObjMapMgrm_ObjMapMgr
DiskMgrm_DiskMgr
CUserManagerm_UserManager

Friends

class RioDirectory

Detailed Description

Definition at line 25 of file interface/ObjectManager.h.


Constructor & Destructor Documentation

CObjectManager::CObjectManager ( CRioTCP TCPconnection  ) 

Definition at line 45 of file interface/ObjectManager.cpp.

00046 {
00047     m_TCPconnection = TCPconnection;
00048 }

CObjectManager::~CObjectManager (  ) 

Definition at line 50 of file interface/ObjectManager.cpp.

00051 {
00052 }

CObjectManager::CObjectManager (  ) 

Definition at line 82 of file server/ObjectManager.cpp.

00083 {
00084     // m_log does not need to be initialized.
00085     m_MaxReplications = 0;
00086     m_UseReplications = 0;
00087     m_initialized     = false;
00088     m_started         = false;
00089     m_FileRoot        = NULL;
00090     m_BlockSize       = 0;
00091     m_ObjMapMgr       = NULL;
00092     m_DiskMgr         = NULL;
00093     m_UserManager     = NULL;
00094     
00095     #ifdef USE_GRID
00096     // Cria��o dos mutexes usados para a implementa��o da cache.
00097     pthread_mutex_init( &m_mutex_filelist, NULL );
00098     pthread_mutex_init( &m_mutex_gridcopy, NULL );
00099     // Inicializa��o dos ponteiros para a lista de arquivos na cache.
00100     m_StartListFiles = NULL;
00101     m_NextSearchFile = NULL;
00102     #endif
00103    
00104 }

CObjectManager::~CObjectManager (  ) 

Member Function Documentation

int CObjectManager::Close ( ObjectHandle  Handle  ) 
HRESULT CObjectManager::Close ( const ObjectHandle  Handle  ) 

Definition at line 55 of file interface/ObjectManager.cpp.

00056 {
00057     char          *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) );
00058     char          *Result;
00059     unsigned int  ParameterSize;
00060     unsigned int  ResultSize;
00061     HRESULT        status;
00062 
00063     if( Parameter == NULL )
00064     {
00065         RioErr << "malloc error Close:" << strerror(errno) << endl;
00066         free( Parameter );
00067 
00068         return ERROR_RIOPROXY + ERROR_MEMORY;
00069     }
00070 
00071     memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) );
00072 
00073     ParameterSize = 2*MAX_LONG_STRING_SIZE;
00074     // Check if Parameter buffer is large enough
00075     if( ParameterSize > ( unsigned int ) MaxTCPDataSize )
00076     {
00077         free( Parameter );
00078 
00079         return ERROR_RIOPROXY + ERROR_CALL_MESSAGE_OVERFLOW;
00080     }
00081 
00082     int offset = 0;
00083 
00084     // Set parameters on asii buffer
00085     // Set Object Handle
00086     SetLong( Parameter, Handle.Version, &offset );
00087     SetLong( Parameter, Handle.Index, &offset );
00088 
00089     // Update Parameter size to actual size (previously was maximum
00090     //possible size)
00091     ParameterSize = offset;
00092 
00093     // Call remote method
00094     status = m_TCPconnection->Call( RioClassObjectManager,
00095                                     RioMethodObjectManagerClose,
00096                                     ParameterSize,
00097                                     Parameter,
00098                                     &ResultSize,
00099                                     &Result );
00100 
00101     // check if call failed
00102     if( FAILED( status ))
00103     {
00104         if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) )
00105             status = ERROR_RIOPROXY + ERROR_MEMORY;
00106         if( Result != NULL )
00107             free( Result );
00108         free( Parameter );
00109 
00110         return status;
00111     }
00112 
00113     offset = 0;
00114     // Get results from result buffer
00115     // Get method return value
00116     if( !GetLong( Result, ResultSize, &status, &offset ) )
00117     {
00118         free( Parameter );
00119         free( Result );
00120 
00121         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00122     }
00123 
00124     free( Parameter );
00125     free( Result );
00126 
00127     return status;
00128 }

int CObjectManager::Create ( char *  Path,
short  Type 
)

Definition at line 290 of file server/ObjectManager.cpp.

00291 {
00292     int  rc;
00293     char name[ 2*MaxPathSize+1 ];
00294 
00295     #ifdef USE_GRID
00296     // Estrutura usada para obter o tempo de �ltimo acesso do arquivo.
00297     struct stat FileStat;
00298     #endif
00299 
00300     *name = '\0';
00301 
00302     if( ( rc = PathToFile( Path, name, sizeof( name ) ) ) )
00303         return rc;
00304 
00305     switch( Type )
00306     {
00307         case ObjectInfo::FILE_TYPE_DIRECTORY:
00308             rc = createdirectory( name );
00309             if( rc )
00310                 return rc;
00311             break;
00312 
00313         case ObjectInfo::FILE_TYPE_DATA:
00314             rc = m_ObjMapMgr->createobject( name );
00315 
00316             if( rc )
00317                 return rc;
00318 
00319             #ifdef USE_GRID
00320             // Obs: o que fazer se o arquivo for criado, e a coloca��o deste
00321             // arquivo na lista falhar?
00322 
00323             // Remove a refer�ncia anterior ao arquivo (caso estejamos
00324             // sobreescrevendo o arquivo). Ignoramos o erro, se este ocorrer,
00325             // pois o �nico erro poss�vel � o do arquivo n�o estar na lista (n�o
00326             // estamos fazendo uma sobreescri��o do arquivo).
00327             RemoveFile( Path );
00328             // Adiciona o novo arquivo criado � lista de arquivos.
00329             rc = stat( name, &FileStat );
00330 
00331             if( rc )
00332             {
00333                 // Devemos remover o arquivo se o stat falhar? Ou devemos
00334                 // colocar um tempo qualquer (como o tempo atual)?
00335                 unlink( name );
00336                 return ERROR_OBJECTMANAGER + ERROR_UNEXPECTED;
00337             }
00338 
00339             // Insere o arquivo na lista com os arquivos da cache.
00340             rc = InsertFile( Path, FileStat.st_atime );
00341 
00342             if( rc )
00343             {
00344                 // Devemos remover o arquivo se o InsertFile falhar? Se n�o
00345                 // fizermos isso, o arquivo somente poder� ser removido da
00346                 // cache se reiniciarmos o servidor.
00347                 unlink( name );
00348                 return ERROR_OBJECTMANAGER + ERROR_UNEXPECTED;
00349             }
00350 
00351             // Usada para depurar o c�digo.
00352             PrintFileList();
00353 
00354             #endif
00355 
00356             break;
00357 
00358         default:
00359             return ERROR_OBJECTMANAGER + ERROR_INVALID_OBJECT_TYPE;
00360     }
00361 
00362     // ### set default permissions here (if needed)
00363     return S_OK;
00364 }

int CObjectManager::createdirectory ( char *  name  )  [private]

Definition at line 368 of file server/ObjectManager.cpp.

00369 {
00370     int  error = 0;
00371     int status;
00372 
00373     status = mkdir( name, 0700 );
00374 
00375     if( status )
00376         error = errno;
00377 
00378     if( status )
00379     {
00380         switch( error )
00381         {
00382             case EEXIST:
00383                 return ERROR_OBJECTMANAGER + ERROR_OBJECT_EXISTS;
00384 
00385             case ENOENT:
00386             case ENAMETOOLONG:
00387             case ENOTDIR:
00388                 return ERROR_OBJECTMANAGER + ERROR_INVALID_OBJECTNAME;
00389         }
00390     }
00391 
00392     return S_OK;
00393 }

int CObjectManager::Delete ( char *  ObjectPath  ) 

Definition at line 460 of file server/ObjectManager.cpp.

00461 {
00462     int         rc;
00463     struct stat mystat;
00464     char        name[ 2 *MaxPathSize+1 ];
00465 
00466     *name = '\0';
00467 
00468     if( ( rc = PathToFile( ObjectPath, name, sizeof( name ) ) ) )
00469         return rc;
00470 
00471     rc = stat( name, &mystat );
00472     if( rc )
00473     {
00474         #ifdef RIO_DEBUG2
00475         if( m_log.is_open() )
00476             m_log << "Could not find file " << name << endl;
00477         #endif
00478 
00479         return ERROR_OBJECTMANAGER + ERROR_INVALID_OBJECTNAME;
00480     }
00481 
00482     if( S_ISDIR( mystat.st_mode ) )
00483     {
00484         #ifdef RIO_DEBUG2
00485         if( m_log.is_open() )
00486             m_log << "Delete directory " << name << endl;
00487         #endif
00488 
00489         return RemoveDirectory( name );
00490     }
00491     else
00492         if( S_ISREG( mystat.st_mode ) )
00493         {
00494             #ifdef RIO_DEBUG2
00495             if( m_log.is_open() )
00496                 m_log << "Delete object " << name << endl;
00497             #endif
00498 
00499             #ifdef USE_GRID
00500             // Implementa��o para renover os arquivos na cache.
00501             rc = RemoveObject( name );
00502 
00503             if( rc ) 
00504                 return rc; // O que devemos fazer se o arquivo foi deletado? 
00505                            // Teremos um arquivo na lista inexistente na cache.
00506 
00507             // Remove o arquivo da lista com os arquivos da cache.
00508             rc = RemoveFile( ObjectPath );
00509 
00510             if( rc )
00511                 return rc; // O �nico erro � o arquivo n�o estar na lista.
00512 
00513             // Usada para depurar o c�digo.
00514             PrintFileList();
00515             return S_OK;
00516             #else 
00517             return RemoveObject( name );
00518             #endif
00519         }
00520 
00521     return ERROR_OBJECTMANAGER + ERROR_INVALID_OBJECTNAME;
00522 }

int CObjectManager::ExistDirectory ( char *  Path  ) 

Definition at line 814 of file server/ObjectManager.cpp.

00815 {
00816     int rc;
00817     struct stat mystat;
00818     char name[ 2*MaxPathSize+1 ];
00819     *name = '\0';
00820 
00821     if( ( rc = PathToFile( ObjectName, name, sizeof( name ) ) ) )
00822         return rc;
00823 
00824     rc = stat( name, &mystat );
00825     if( ( rc == 0 ) && ( S_ISDIR( mystat.st_mode ) ) )
00826         return S_OK;
00827 
00828     return ERROR_OBJECTMANAGER + ERROR_INVALID_OBJECTNAME;
00829 }

int CObjectManager::FirstObject ( char *  DirectoryPath,
RioDirectory **  Directory,
int *  IsDirectory,
int  BufferSize,
char *  ObjectName 
)

Definition at line 945 of file server/ObjectManager.cpp.

00948 {
00949     int rc = 0;
00950 
00951     RioDirectory *op = new RioDirectory( this );
00952     if( op == 0 )
00953         return ERROR_OBJECTMANAGER + ERROR_MEMORY;
00954 
00955     if( ( rc = PathToFile( DirectoryPath, op->o_DirectoryName,
00956                            sizeof( op->o_DirectoryName ) ) ) )
00957         return rc;
00958 
00959     // ### Mutex to lock changes to RIO directories?? (future).
00960     // {would be inside of opendir/readdir routines?}.
00961 
00962     // Get first file.
00963     op->o_dir = opendir( op->o_DirectoryName );
00964     if( op->o_dir == NULL )
00965     {
00966         // Error on opendir (as directory can't be empty!).
00967         int error = errno;
00968         delete op;
00969         if( error == ENOENT )
00970             return ERROR_OBJECTMANAGER + ERROR_INVALID_DIRECTORYNAME;
00971     }
00972 
00973     *Directory = op;
00974 
00975     // Now just use NextObject to get 1st entry in directory.
00976     return op->NextObject( IsDirectory, BufferSize, ObjectName );
00977 }

int CObjectManager::Format (  ) 
int CObjectManager::GetBlockMap ( ObjectHandle  Handle,
RioBlock  First,
RioBlock  nBlocks,
RioDiskBlock blocks 
)
int CObjectManager::GetBlockSize ( unsigned int *  BlockSize  ) 
int CObjectManager::GetnBlocks ( ObjectHandle  Handle,
RioBlock nBlocks 
)
HRESULT CObjectManager::GetnBlocks ( const ObjectHandle  Handle,
RioBlock nBlocks 
)

Definition at line 409 of file interface/ObjectManager.cpp.

00411 {
00412     char          *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) );
00413     char          *Result;
00414     unsigned int  ParameterSize;
00415     unsigned int  ResultSize;
00416     HRESULT        status;
00417 
00418     if( Parameter == NULL )
00419     {
00420         RioErr << "malloc error GetnBlocks:" << strerror(errno) << endl;
00421         free( Parameter );
00422 
00423         return ERROR_RIOPROXY + ERROR_MEMORY;
00424     }
00425 
00426     memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) );
00427 
00428     ParameterSize = 2*MAX_LONG_STRING_SIZE;
00429     // Check if Parameter buffer is large enough
00430     if( ParameterSize > (unsigned int) MaxTCPDataSize )
00431     {
00432         free( Parameter );
00433 
00434         return ERROR_RIOPROXY + ERROR_CALL_MESSAGE_OVERFLOW;
00435     }
00436 
00437     int offset = 0;
00438 
00439     // Set parameters on asii buffer
00440     // Set Object Handle
00441     SetLong(Parameter,Handle.Version,&offset);
00442     SetLong(Parameter,Handle.Index,&offset);
00443 
00444     // Update Parameter size to actual size
00445     // (previously was maximum possible size)
00446     ParameterSize = offset;
00447 
00448     // Call remote method
00449     status = m_TCPconnection->Call( RioClassObjectManager,
00450                                     RioMethodObjectManagerGetnBlocks,
00451                                     ParameterSize,
00452                                     Parameter,
00453                                     &ResultSize,
00454                                     &Result );
00455 
00456     // check if call failed
00457     if( FAILED( status ) )
00458     {
00459         if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) )
00460             status = ERROR_RIOPROXY + ERROR_MEMORY;
00461         if( Result != NULL )
00462             free( Result );
00463         free( Parameter );
00464 
00465         return status;
00466     }
00467 
00468     offset = 0;
00469     // Get results from result buffer
00470     // Get method return value
00471     if( !GetLong( Result, ResultSize, &status, &offset ) )
00472     {
00473         free( Parameter );
00474         free( Result );
00475 
00476         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00477     }
00478     // Get number of blocks
00479     if( !GetULong( Result, ResultSize, nBlocks, &offset ) )
00480     {
00481         free( Parameter );
00482         free( Result );
00483 
00484         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00485     }
00486 
00487     free( Parameter );
00488     free( Result );
00489 
00490     return status;
00491 }

int CObjectManager::GetObjectInfo ( char *  ObjectName,
ObjectInfo ObjectInfo 
)

Definition at line 801 of file server/ObjectManager.cpp.

00802 {
00803     int rc;
00804     char name [ 2*MaxPathSize+1 ];
00805     *name = '\0';
00806 
00807     if( ( rc = PathToFile( ObjectName, name, sizeof( name ) ) ) )
00808         return rc;
00809 
00810     return m_ObjMapMgr->GetObjectInfo( name, ObjectInfo );
00811 }

int CObjectManager::GetSize ( ObjectHandle  Handle,
RioObjectSize Size 
)
HRESULT CObjectManager::GetSize ( const ObjectHandle  Handle,
RioObjectSize Size 
)

Definition at line 131 of file interface/ObjectManager.cpp.

00133 {
00134     char          *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) );
00135     char          *Result;
00136     unsigned int  ParameterSize;
00137     unsigned int  ResultSize;
00138     HRESULT        status;
00139 
00140     if( Parameter == NULL )
00141     {
00142         RioErr << "malloc error GetSize:" << strerror(errno) << endl;
00143         free( Parameter );
00144 
00145         return ERROR_RIOPROXY + ERROR_MEMORY;
00146     }
00147 
00148     memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) );
00149 
00150     ParameterSize = 2*MAX_LONG_STRING_SIZE;
00151     // Check if Parameter buffer is large enough
00152     if( ParameterSize > ( unsigned int ) MaxTCPDataSize )
00153     {
00154         free( Parameter );
00155 
00156         return ERROR_RIOPROXY + ERROR_CALL_MESSAGE_OVERFLOW;
00157     }
00158 
00159     int offset = 0;
00160 
00161     // Set parameters on asii buffer
00162     // Set Object Handle
00163     SetLong( Parameter, Handle.Version, &offset );
00164     SetLong( Parameter, Handle.Index, &offset );
00165 
00166     // Update Parameter size to actual size
00167     // (previously was maximum possible size)
00168     ParameterSize = offset;
00169 
00170     // Set Maximum result size (Size of buffer)
00171     // Call remote method
00172     status = m_TCPconnection->Call( RioClassObjectManager,
00173                                     RioMethodObjectManagerGetSize,
00174                                     ParameterSize,
00175                                     Parameter,
00176                                     &ResultSize,
00177                                     &Result );
00178 
00179     // check if call failed
00180     if( FAILED( status ) )
00181     {
00182         if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) )
00183             status = ERROR_RIOPROXY + ERROR_MEMORY;
00184         if( Result != NULL )
00185             free( Result );
00186         free( Parameter );
00187 
00188         return status;
00189     }
00190 
00191     offset = 0;
00192     // Get results from result buffer
00193     // Get method return value
00194     if( !GetLong( Result, ResultSize, &status, &offset ) )
00195     {
00196         free( Parameter );
00197         free( Result );
00198 
00199         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00200     }
00201     // Get Object Size
00202     unsigned int highpart;
00203     unsigned int lowpart;
00204     if( !GetULong( Result, ResultSize, &highpart, &offset ) )
00205     {
00206         free( Parameter );
00207         free( Result );
00208 
00209         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00210     }
00211     if( !GetULong( Result, ResultSize, &lowpart, &offset ) )
00212     {
00213         free( Parameter );
00214         free( Result );
00215 
00216         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00217     }
00218     *Size = ((( RioObjectSize ) highpart ) << 32 ) | lowpart ;
00219 
00220     free( Parameter );
00221     free( Result );
00222 
00223     return status;
00224 }

int CObjectManager::GetType ( ObjectHandle  Handle,
short *  Type 
)
HRESULT CObjectManager::GetType ( const ObjectHandle  Handle,
short *  Type 
)

Definition at line 321 of file interface/ObjectManager.cpp.

00323 {
00324     char          *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) );
00325     char          *Result;
00326     unsigned int  ParameterSize;
00327     unsigned int  ResultSize;
00328     HRESULT        status;
00329 
00330     if( Parameter == NULL )
00331     {
00332         RioErr << "malloc error GetType:" << strerror(errno) << endl;
00333         free( Parameter );
00334 
00335         return ERROR_RIOPROXY + ERROR_MEMORY;
00336     }
00337 
00338     memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) );
00339 
00340     ParameterSize = 2*MAX_LONG_STRING_SIZE;
00341     // Check if Parameter buffer is large enough
00342     if( ParameterSize > (unsigned int) MaxTCPDataSize )
00343     {
00344         free( Parameter );
00345 
00346         return ERROR_RIOPROXY + ERROR_CALL_MESSAGE_OVERFLOW;
00347     }
00348 
00349     int offset = 0;
00350 
00351     // Set parameters on asii buffer
00352     // Set Object Handle
00353     SetLong( Parameter, Handle.Version, &offset );
00354     SetLong( Parameter, Handle.Index, &offset );
00355 
00356     // Update Parameter size to actual size
00357     // (previously was maximum possible size)
00358     ParameterSize = offset;
00359 
00360     // Call remote method
00361     status = m_TCPconnection->Call( RioClassObjectManager,
00362                                     RioMethodObjectManagerGetType,
00363                                     ParameterSize,
00364                                     Parameter,
00365                                     &ResultSize,
00366                                     &Result );
00367 
00368     // check if call failed
00369     if( FAILED( status ) )
00370     {
00371         if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) )
00372             status = ERROR_RIOPROXY + ERROR_MEMORY;
00373         if( Result != NULL )
00374             free( Result );
00375         free( Parameter );
00376 
00377         return status;
00378     }
00379 
00380     offset = 0;
00381     // Get results from result buffer
00382     // Get method return value
00383     if( !GetLong( Result, ResultSize, &status, &offset ) )
00384     {
00385         free( Parameter );
00386         free( Result );
00387 
00388         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00389     }
00390     // Get Type
00391     short shortvalue;
00392     if( !GetShort( Result, ResultSize, &shortvalue, &offset ) )
00393     {
00394         free( Parameter );
00395         free( Result );
00396 
00397         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00398     }
00399 
00400     *Type = shortvalue ;
00401 
00402     free( Parameter );
00403     free( Result );
00404 
00405     return status;
00406 }

HRESULT CObjectManager::GetVideoRate ( const ObjectHandle  Handle,
unsigned int *  VideoRate 
)

GetVideoRate retorna a taxa de transmissao (em Kbps) do video.

Parameters:
Handle identificador do objeto cuja taxa de transmissao desejamos obter.
VideoRate ponteiro para o inteiro nao sinalizado que armazenara a taxa de transmissao do video.
Returns:
erro se nao foi possivel chamar o metodo ou se algum erro ocorreu ao executar o metodo.

Definition at line 604 of file interface/ObjectManager.cpp.

00606 {
00607     char          *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) );
00608     char          *Result;
00609     unsigned int  ParameterSize;
00610     unsigned int  ResultSize;
00611     HRESULT        status;
00612 
00613     if( Parameter == NULL )
00614     {
00615         RioErr << "malloc error GetVideoRate:" << strerror(errno) << endl;
00616         free( Parameter );
00617 
00618         return ERROR_RIOPROXY + ERROR_MEMORY;
00619     }
00620 
00621     memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) );
00622 
00623     ParameterSize = 2*MAX_LONG_STRING_SIZE;
00624     // Check if Parameter buffer is large enough
00625     if( ParameterSize > ( unsigned int ) MaxTCPDataSize )
00626     {
00627         free( Parameter );
00628 
00629         return ERROR_RIOPROXY + ERROR_CALL_MESSAGE_OVERFLOW;
00630     }
00631 
00632     int offset = 0;
00633 
00634     // Set parameters on asii buffer
00635     // Set Object Handle
00636     SetLong( Parameter, Handle.Version, &offset );
00637     SetLong( Parameter, Handle.Index, &offset );
00638 
00639     // Update Parameter size to actual size
00640     // (previously was maximum possible size)
00641     ParameterSize = offset;
00642 
00643     // Call remote method
00644     status = m_TCPconnection->Call( RioClassObjectManager,
00645                                     RioMethodObjectManagerGetVideoRate,
00646                                     ParameterSize,
00647                                     Parameter,
00648                                     &ResultSize,
00649                                     &Result );
00650 
00651     // check if call failed
00652     if( FAILED( status ) )
00653     {
00654         if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) )
00655             status = ERROR_RIOPROXY + ERROR_MEMORY;
00656         if( Result != NULL )
00657             free( Result );
00658         free( Parameter );
00659 
00660         return status;
00661     }
00662 
00663     offset = 0;
00664     // Get results from result buffer
00665     // Get method return value
00666     if( !GetLong( Result, ResultSize, &status, &offset ) )
00667     {
00668         free( Parameter );
00669         free( Result );
00670 
00671         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00672     }
00673     if( !GetULong( Result, ResultSize, VideoRate, &offset ) )
00674     {
00675         free( Parameter );
00676         free( Result );
00677 
00678         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00679     }
00680 
00681     free( Parameter );
00682     free( Result );
00683 
00684     return status;
00685 }

int CObjectManager::Initialize ( ObjectManagerConfig Config  ) 

Definition at line 148 of file server/ObjectManager.cpp.

00149 {
00150     int result;
00151 
00152     if( Config->GenerateLogs )
00153     {
00154         // Variavel usada para compor os nome do arquivo com o log.
00155         char LogFileName[ MaxPathSize ];
00156         // Compoe o nome do arquivo com o log.
00157         strcpy( LogFileName, Config->LogsDirectory );
00158         strcat( LogFileName, LOGFILE );
00159         m_log.open( LogFileName );
00160         if( !m_log.is_open() )
00161             return ERROR_OBJECTMANAGER + ERROR_LOGFILE ;
00162     }
00163 
00164     if( m_initialized )
00165     {
00166         if( m_log.is_open() )
00167             m_log << "Initialize(): Tried to initialize component "
00168                   << " already initialized" << endl;
00169         return ERROR_OBJECTMANAGER + ERROR_INITIALIZED;
00170     }
00171 
00172     if( ( strlen( Config->FileRoot ) + 1 ) > MaxPathSize )
00173     {
00174         if( m_log.is_open() )
00175             m_log << "CObjectManager::Initialize(). FileRoot name size too "
00176                   << "large: " << Config->FileRoot << " ("
00177                   << strlen( Config->FileRoot ) << ")" << endl;
00178         return ERROR_OBJECTMANAGER + ERROR_LARGE_ROOTNAME;
00179     }
00180 
00181     m_FileRoot = new char[ strlen( Config->FileRoot ) + 1 ];
00182     strcpy( m_FileRoot, Config->FileRoot );
00183 
00184     m_BlockSize       = Config->BlockSize;
00185     m_MaxReplications = Config->MaxReplications;
00186     m_UseReplications = Config->UseReplications;
00187     m_DiskMgr         = Config->c_DiskMgr;
00188     m_UserManager     = Config->UserManager;
00189 
00190     m_ObjMapMgr = new ObjMapMgr;
00191     if( m_ObjMapMgr == 0 )
00192     {
00193         if( m_log.is_open() ) 
00194             m_log << "CObjectManager::Initialize() new ObjMapMgr failed." 
00195                   << endl;
00196         return ERROR_OBJECTMANAGER + ERROR_MEMORY;
00197     }
00198 
00199     // Intialize Object Map Manager.
00200     result = m_ObjMapMgr->Initialize( Config->MaxNhandle, m_BlockSize,
00201                                       m_MaxReplications, m_UseReplications,
00202                                       m_DiskMgr, &m_log );
00203     if( FAILED( result ) )
00204         return result;
00205 
00206     #ifdef USE_GRID
00207     // Cria a lista com os arquivos do servidor, ordenada pelo tempo do �ltimo
00208     // acesso (usada pela funcionalidade de cache).
00209     result = CreateFileList();
00210 
00211     if( result != 0 )
00212     {
00213         if( m_log.is_open() )
00214             m_log << "CObjectManager::Initialize() CreateFileList failed."
00215                   << endl;
00216         return result;
00217     }
00218 
00219     // Usada para depurar o c�digo.
00220     PrintFileList();
00221     #endif
00222 
00223     m_initialized = true;
00224 
00225     return S_OK;
00226 }

HRESULT CObjectManager::NextObject ( ObjectHandle  Handle,
int *  IsDirectory,
int  BufferSize,
signed char *  ObjectName 
)

Definition at line 494 of file interface/ObjectManager.cpp.

00496 {
00497     char          *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) );
00498     char          *Result;
00499     unsigned int  ParameterSize;
00500     unsigned int  ResultSize;
00501     HRESULT        status;
00502 
00503     if( Parameter == NULL )
00504     {
00505         RioErr << "malloc error NextObject:" << strerror(errno) << endl;
00506         free( Parameter );
00507 
00508         return ERROR_RIOPROXY + ERROR_MEMORY;
00509     }
00510 
00511     memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) );
00512 
00513     ParameterSize = 3*MAX_LONG_STRING_SIZE;
00514 
00515     // Check if Parameter buffer is large enough
00516     if( ParameterSize > (unsigned int) MaxTCPDataSize )
00517     {
00518         free( Parameter );
00519 
00520         return ERROR_RIOPROXY + ERROR_CALL_MESSAGE_OVERFLOW;
00521     }
00522 
00523     int          offset = 0;
00524     // Set parameters on asii buffer
00525     // Set Object Handle
00526     SetLong( Parameter, Handle.Version, &offset );
00527     SetLong( Parameter, Handle.Index, &offset );
00528     // Set Buffer size
00529     SetLong( Parameter, BufferSize, &offset );
00530 
00531     // Update Parameter size to actual size
00532     // (previously was maximum possible size)
00533     ParameterSize = offset;
00534 
00535     // Call remote method
00536     status = m_TCPconnection->Call( RioClassObjectManager,
00537                                     RioMethodObjectManagerNextObject,
00538                                     ParameterSize,
00539                                     Parameter,
00540                                     &ResultSize,
00541                                     &Result );
00542 
00543     // check if call failed
00544     if( FAILED (status) )
00545     {
00546         if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) )
00547             status = ERROR_RIOPROXY + ERROR_MEMORY;
00548         if( Result != NULL )
00549             free( Result );
00550         free( Parameter );
00551 
00552         return status;
00553     }
00554 
00555     offset = 0;
00556     // Get results from result buffer
00557     // Get method return value
00558     if( !GetLong( Result, ResultSize, &status, &offset ) )
00559     {
00560         free( Parameter );
00561         free( Result );
00562 
00563         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00564     }
00565 
00566     // Get Directory flag
00567     if( !GetLong( Result, ResultSize, IsDirectory, &offset ) )
00568     {
00569         free( Parameter );
00570         free( Result );
00571 
00572         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00573     }
00574 
00575     // Get Object name
00576     char* str;
00577     if( !GetString( Result, ResultSize, &str, &offset ) )
00578     {
00579         free( Parameter );
00580         free( Result );
00581 
00582         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00583     }
00584 
00585     if(status == S_OK)
00586     {
00587         strcpy( (char *)ObjectName, str );
00588     }
00589 
00590     free( Parameter );
00591     free( Result );
00592 
00593     return status;
00594 }

int CObjectManager::Open ( char *  ObjectPath,
RioAccess  Access,
RioObject **  Object 
)

Definition at line 572 of file server/ObjectManager.cpp.

00574 {
00575     int  rc;
00576     char name[ 2*MaxPathSize+1 ];
00577 
00578     #ifdef USE_GRID
00579     // Vari�veis usadas pela implementa��o da GRID (cache).
00580     // Vari�vel usada para determinar os nomes dos outros arquivos associados a
00581     // um arquivo .mpg (nome no sistema de arquivos do Servidor RIO).
00582     char AuxObjectName[ 2*MaxPathSize+1 ]; 
00583     // Vari�vel usada para determinar os nomes dos outros arquivos associados a
00584     // um arquivo .mpg (nome no sistema de arquivos do sistema operacional, a
00585     // partir do diret�rio do Servidor RIO. Em geral, � o nome anterior com o
00586     // prefixo ''FileRoot/'').
00587     char AuxName[ 2*MaxPathSize+1 ];
00588     // Extens�es dos arquivos associados a um arquivo mpg (isto �, um arquivo
00589     // com um video de uma aula.
00590     // Obs: todas as extens�es est�o presentes? Ou alguma est� faltando?
00591     char *ObjectExtensions[ MAX_OBJECT_EXTENSIONS ] = { ".tgif", ".zip",
00592                                                         ".index", ".keyword",
00593                                                         ".xml"};
00594     RioObject    *AuxObject = NULL;
00595     unsigned int  rca;
00596     unsigned int  i;
00597     #endif
00598 
00599     *name = '\0';
00600 
00601     if( ( rc = PathToFile( ObjectName, name, sizeof( name ) ) ) )
00602         return rc;
00603 
00604     #ifdef USE_GRID
00605     // Obt�m o mutex para bloquear o acesso � lista com os arquivos da cache.
00606     pthread_mutex_lock( &m_mutex_filelist );
00607 
00608     rc = m_ObjMapMgr->Open( name, Access, Object );
00609 
00610     if( rc )
00611     {
00612         // Libera o acesso exclusivo � lista com os arquivos da cache.
00613         pthread_mutex_unlock( &m_mutex_filelist );
00614 
00615         // Obt�m o mutex para garantir que somente um arquivo � copiado da
00616         // GRID por vez.
00617         pthread_mutex_lock( &m_mutex_gridcopy );
00618 
00619         // Verifica se o arquivo j� foi copiado (pois a thread pode ter ficado
00620         // bloqueada no mutex esperando para poder fazer a copia, e uma outra
00621         // thread j� poderia ter copiado este arquivo para a cache).
00622         rc = m_ObjMapMgr->Open( name, Access, Object );
00623 
00624         if( rc )
00625         {
00626             // Tenta copiar o arquivo da GRID. Se o arquivo n�o foi copiado
00627             // com sucesso, o erro ocorrer� ao tentarmos reabrir o arquivo.
00628             CopyGridFile( ObjectName );
00629             // Tenta abrir o arquivo .mpg que acabou de ser copiado.
00630             // Obt�m novamente o acesso exclusivo � lista com os arquivos da
00631             // cache.
00632             pthread_mutex_lock( &m_mutex_filelist );
00633 
00634             // Tenta primeiramente abrir o objeto.
00635             if( m_log.is_open() )
00636                 m_log << "CObjectManager::Open tentando abrir o arquivo "
00637                       << name << " associado ao objeto " << ObjectName << endl;
00638             rc = m_ObjMapMgr->Open( name, Access, Object );
00639 
00640             if( rc )
00641             {   
00642                 // Se isso ocorrer, houve algum erro ao copiar o arquivo da
00643                 // GRID.
00644                 pthread_mutex_unlock( &m_mutex_filelist );
00645                 pthread_mutex_unlock( &m_mutex_gridcopy );
00646                 return rc;
00647             }
00648 
00649             // Incrementa o contador de refer�ncias ao arquivo que foi aberto
00650             // na lista com os arquivos que est�o na cache.
00651             rc = IncrementOpenFileCounter( ObjectName );
00652             // Libera o acesso exclusivo � lista  com os arquivos da cache.
00653             pthread_mutex_unlock( &m_mutex_filelist );
00654             // Imprime a nova lista (depura��o).
00655             PrintFileList();
00656 
00657             if( rc )
00658             {
00659                 // O que devemos fazer neste caso? O nome do arquivo n�o existe
00660                 // na lista. Optei por retornar um c�digo de erro e destruir o
00661                 // objeto criado.
00662                 delete Object;
00663                 pthread_mutex_unlock( &m_mutex_gridcopy );
00664                 return rc;
00665             }
00666 
00667             // Verifica o tipo do arquivo, e se for um v�deo (sufixo .mpg),
00668             // tenta copiar os arquivos associados a este video.
00669             if( ( strlen( ObjectName ) >= 4 ) && 
00670                 ( strcmp( &ObjectName[ strlen( ObjectName )-4 ], ".mpg" ) 
00671                           == 0) )
00672             {
00673 
00674                 if( m_log.is_open() )
00675                     m_log << "CObjectManager:: o arquivo " << ObjectName
00676                           << " e .mpg. Baixando os arquivos relacionados a "
00677                           << "ele." << endl;
00678 
00679                 // Se for um arquivo terminado em .mpg.
00680                 for( i = 0; i < MAX_OBJECT_EXTENSIONS; i++ )
00681                 {
00682                     // Obt�m os nomes dos objetos.
00683                     strncpy( AuxObjectName, ObjectName,
00684                              strlen( ObjectName )-4 );
00685 
00686                     // Adiciona o caractere nulo ao final da string (o strncpy)
00687                     // n�o faz isso.
00688                     AuxObjectName[ strlen( ObjectName )-4 ] = 0;
00689 
00690                     strcat( AuxObjectName, ObjectExtensions[ i ] );
00691                     *AuxName = '\0'; // Cria uma string vazia 
00692 
00693                     if( (rca = PathToFile( AuxObjectName, AuxName,
00694                                            sizeof( AuxName ) ) ) )
00695                     {
00696 
00697                         if( m_log.is_open() )
00698                             m_log << "CObjectManager::Open nao foi possivel "
00699                                   << "converter o nome " << AuxObjectName 
00700                                   << " (erro " << rca << ")" << endl;
00701                     }
00702                     else // else do if( (rca = PathToFile( AuxObjectName, Au...
00703                     {
00704 
00705                         // Tenta primeiramente abrir o objeto.
00706                         if( m_log.is_open() )
00707                             m_log << "CObjectManager::Open tentando abrir o "
00708                                   << "arquivo " << AuxName << " associado ao "
00709                                   << "arquivo " << name << endl;
00710 
00711                         rca = m_ObjMapMgr->Open( AuxName, Access, &AuxObject );
00712 
00713                         if( rca )
00714                         {
00715                             // Se n�o tivermos sucesso, supomos que o arquivo
00716                             // n�o esta na cache, e o copiamos da GRID.
00717                             CopyGridFile( AuxObjectName );
00718                         }
00719                         else
00720                         {
00721                             // Se conseguimos abrir o arquivo, devemos
00722                             // simplesmente deletar o objeto temporario.
00723                             delete AuxObject;
00724                         }
00725 
00726                     } // fim do else do if( (rca = PathToFile( AuxObjectNam..
00727 
00728                 } // fim do for (i = 0; i < MAX_OBJECT_EXTENSIONS; i++)
00729 
00730             }
00731             else // else do if ((strlen(ObjectName) >= 4) && ...
00732             {
00733 
00734                 if( m_log.is_open() )
00735                     m_log << "CObjectManager:: o arquivo " << ObjectName
00736                           << " nao e um .mpg. " << endl;
00737 
00738             }
00739 
00740             // Libera o mutex para garantir que somente um arquivo � copiado da
00741             // GRID por vez.
00742             pthread_mutex_unlock( &m_mutex_gridcopy );
00743         }
00744         else // else do segundo comando if( rc )
00745         { 
00746             // Como o arquivo j� foi copiado, devemos simplesmente liberar o
00747             // mutex de c�pia.
00748             pthread_mutex_unlock( &m_mutex_gridcopy );
00749             // Obt�m novamente o acesso exclusivo � lista com os arquivos da
00750             // cache.
00751             pthread_mutex_lock( &m_mutex_filelist );
00752             // Incrementa o contador de refer�ncias ao arquivo que foi aberto
00753             // na lista com os arquivos que est�o na cache.
00754             rc = IncrementOpenFileCounter( ObjectName );
00755             // Libera o acesso exclusivo � lista  lista com os arquivos da
00756             // cache.
00757             pthread_mutex_unlock( &m_mutex_filelist );
00758             // Imprime a nova lista (depura��o).
00759             PrintFileList();
00760 
00761             if( rc )
00762             {
00763                 // O que devemos fazer neste caso? O nome do arquivo n�o existe
00764                 // na lista. Optei por retornar um c�digo de erro e destruir o
00765                 // objeto criado.
00766                 delete Object;
00767                 return rc;
00768             }
00769 
00770         } // fim do else do segundo comando if( rc )
00771 
00772     }
00773     else // else do primeiro comando if( rc )
00774     {
00775         // Incrementa o contador de refer�ncias ao arquivo que foi aberto na
00776         // lista com os arquivos que est�o na cache.
00777         rc = IncrementOpenFileCounter( ObjectName );
00778         // Libera o acesso exclusivo � lista com os arquivos da cache.
00779         pthread_mutex_unlock( &m_mutex_filelist );
00780         // Imprime a nova lista (depura��o).
00781         PrintFileList();
00782 
00783         if( rc )
00784         {
00785             // O que devemos fazer neste caso? O nome do arquivo n�o existe na
00786             // lista. Optei por retornar um c�digo de erro e destruir o objeto
00787             // criado.
00788             delete Object;
00789             return rc;
00790         }
00791 
00792     } // fim do else do primeiro comando if( rc )
00793 
00794     return S_OK;
00795     #else
00796     return m_ObjMapMgr->Open( name, Access, Object );
00797     #endif
00798 }

int CObjectManager::PathToFile ( const char *  Path,
char *  FileName,
const int  MaxSize 
) [private]

Definition at line 837 of file server/ObjectManager.cpp.

00839 {
00840     int len = strlen( Path );
00841 
00842     if( ( len + strlen( m_FileRoot ) + 2 )  > ( unsigned ) MaxSize )
00843         return ERROR_PATHNAME_TOOLARGE;
00844 
00845     if( len == 0 )
00846     {
00847         strcpy( FileName, m_FileRoot );
00848         return S_OK;
00849     }
00850 
00851     strcpy( FileName, m_FileRoot );
00852     strcat( FileName, "/" );
00853     strcat( FileName, Path );
00854 
00855     return S_OK;
00856 }

HRESULT CObjectManager::ReallocBlocks ( const ObjectHandle  Handle,
const RioBlock  Block 
)

Funcao usada para realocar os blocos fisicos do bloco logico passado como parametro.

Parameters:
Block identificadao do bloco logico.
Returns:
S_OK se a realocacao foi feita com sucesso ou um valor diferente de S_OK se algum erro ocorreu.

Definition at line 776 of file interface/ObjectManager.cpp.

00778 {
00779     char          *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) );
00780     char          *Result;
00781     unsigned int  ParameterSize;
00782     unsigned int  ResultSize;
00783     HRESULT        status;
00784 
00785     if( Parameter == NULL )
00786     {
00787         RioErr << "malloc error ReallocBlocks:" << strerror(errno) << endl;
00788         free( Parameter );
00789 
00790         return ERROR_RIOPROXY + ERROR_MEMORY;
00791     }
00792 
00793     memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) );
00794 
00795     ParameterSize = 2 * MAX_LONG_STRING_SIZE + MAX_ULONG_STRING_SIZE;
00796     // Check if Parameter buffer is large enough
00797     if( ParameterSize > (unsigned int) MaxTCPDataSize )
00798     {
00799         free( Parameter );
00800 
00801         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00802     }
00803 
00804     int offset = 0;
00805 
00806     // Set parameters on asii buffer
00807     // Set Object Handle
00808     SetLong( Parameter, Handle.Version, &offset );
00809     SetLong( Parameter, Handle.Index, &offset );
00810     // Set Block
00811     SetULong( Parameter, ( unsigned int ) Block, &offset );
00812 
00813     // Update Parameter size to actual size
00814     // (previously was maximum possible size)
00815     ParameterSize = offset;
00816 
00817     // Call remote method
00818     status = m_TCPconnection->Call( RioClassObjectManager,
00819                                     RioMethodObjectManagerReallocBlocks,
00820                                     ParameterSize,
00821                                     Parameter,
00822                                     &ResultSize,
00823                                     &Result );
00824 
00825     // check if call failed
00826     if( FAILED( status ) )
00827     {
00828         if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) )
00829             status = ERROR_RIOPROXY + ERROR_MEMORY;
00830         if( Result != NULL )
00831             free( Result );
00832         free( Parameter );
00833 
00834         return status;
00835     }
00836 
00837     offset = 0;
00838     // Get results from result buffer
00839     // Get method return value
00840     if( !GetLong( Result, ResultSize, &status, &offset ) )
00841     {
00842         free( Parameter );
00843         free( Result );
00844 
00845         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00846     }
00847 
00848     free( Parameter );
00849     free( Result );
00850 
00851     return status;
00852 }

int CObjectManager::RemoveDirectory ( char *  DirectoryName  )  [private]

Definition at line 525 of file server/ObjectManager.cpp.

00526 {
00527     // ### Need some metadata mutex?
00528     int status;
00529     status = rmdir( DirectoryName );
00530 
00531     if( !status )
00532     {
00533         #ifdef RIO_DEBUG2
00534         if( m_log.is_open() )
00535             m_log << "Delete directory success"<< endl;
00536         #endif
00537 
00538         return S_OK;
00539     }
00540     else
00541     {
00542         #ifdef RIO_DEBUG2
00543         if( m_log.is_open() )
00544             m_log << "Delete directory failed"<< endl;
00545         #endif
00546 
00547         return ERROR_OBJECTMANAGER + ERROR_OBJECT_REMOVE_FAILED;
00548     }
00549 }

int CObjectManager::RemoveObject ( char *  ObjectName  )  [private]

Definition at line 552 of file server/ObjectManager.cpp.

00553 {
00554     RioObject *Object;
00555     int        rc;
00556 
00557     // ### Need some metadata mutex?
00558     rc = m_ObjMapMgr->Open( ObjectName, RIO_READ_ACCESS | RIO_WRITE_ACCESS,
00559                             &Object );
00560 
00561     if( FAILED( rc ) )
00562         return rc;
00563 
00564     rc = Object->MarkDelete();
00565 
00566     delete Object;    // ### But don't get rc on delete.
00567 
00568     return rc;
00569 }

int CObjectManager::Rename ( char *  OldPath,
char *  NewPath 
)

Definition at line 404 of file server/ObjectManager.cpp.

00405 {
00406     int  rc;
00407     int  error;
00408     char oldname[ 2*MaxPathSize+1 ];
00409     char newname[ 2*MaxPathSize+1 ];
00410 
00411     *oldname = '\0';
00412     *newname = '\0';
00413 
00414     if( ( rc = PathToFile( OldPath, oldname, sizeof( oldname ) ) ) )
00415         return rc;
00416 
00417     if( ( rc = PathToFile( NewPath, newname, sizeof( newname ) ) ) )
00418         return rc;
00419 
00420     if( ( rc = rename( oldname, newname ) ) != 0 )
00421         error = errno;
00422 
00423     #ifdef USE_GRID
00424     // Implementa��o para renomear os arquivos na cache.
00425     if( !rc )
00426     {
00427         // Renomeia o arquivo na lista com os arquivos da cache.
00428         rc = RenameFile( OldPath, NewPath );
00429         
00430         if( rc )
00431         {
00432             // Devemos renomear novamente o arquivo, para garantir a
00433             // consist�ncia?
00434             rename( newname, oldname );
00435             // Este erro � o adequado?
00436             return ERROR_OBJECTMANAGER + ERROR_OBJECT_OPEN_FAILED; 
00437         }
00438         
00439         // Usada para depurar o c�digo.
00440         PrintFileList();
00441         return S_OK;
00442     }
00443     #else
00444     if( !rc )
00445         return S_OK;
00446     #endif
00447     else
00448     {
00449         //### Needs better error return values (?)
00450         //      if(error == ERROR_ALREADY_EXISTS)
00451         //       return ERROR_OBJECTMANAGER + ERROR_OBJECT_EXISTS;
00452         //      if(error == ERROR_INVALID_NAME)
00453         //       return ERROR_OBJECTMANAGER + ERROR_INVALID_OBJECTNAME;
00454         return ERROR_OBJECTMANAGER + ERROR_OBJECT_OPEN_FAILED;
00455     }
00456 }

int CObjectManager::Reset ( void   ) 

Definition at line 130 of file server/ObjectManager.cpp.

00131 {
00132     m_BlockSize   = 0;
00133     m_initialized = false;
00134     m_started     = false;
00135 
00136     if( m_FileRoot != NULL ) 
00137         delete[] m_FileRoot;
00138     m_FileRoot = 0;
00139 
00140     // Remove o objeto m_ObjMapMgr.
00141     if( m_ObjMapMgr != NULL )
00142         delete m_ObjMapMgr;
00143     m_ObjMapMgr = NULL;
00144 
00145     return S_OK;
00146 }

int CObjectManager::SetDefaultPermissions ( char *  name  )  [private]

Definition at line 397 of file server/ObjectManager.cpp.

00398 {
00399     return S_OK;
00400 }

int CObjectManager::SetSize ( ObjectHandle  Handle,
RioObjectSize  Size 
)
HRESULT CObjectManager::SetSize ( const ObjectHandle  Handle,
const RioObjectSize  Size,
char *  md5sum 
)

Definition at line 227 of file interface/ObjectManager.cpp.

00230 {
00231     char          *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) );
00232     char          *Result;
00233     unsigned int  ParameterSize;
00234     unsigned int  ResultSize;
00235     HRESULT        status;
00236 
00237     if( Parameter == NULL )
00238     {
00239         RioErr << "malloc error SetSize:" << strerror(errno) << endl;
00240         free( Parameter );
00241 
00242         return ERROR_RIOPROXY + ERROR_MEMORY;
00243     }
00244 
00245     memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) );
00246 
00247     ParameterSize = 2*MAX_LONG_STRING_SIZE +
00248                     2*MAX_ULONG_STRING_SIZE +
00249                     strlen( md5sum );
00250 
00251     // Check if Parameter buffer is large enough
00252     if( ParameterSize > (unsigned int) MaxTCPDataSize )
00253     {
00254         free( Parameter );
00255 
00256         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00257     }
00258 
00259     int offset = 0;
00260 
00261     // Set parameters on asii buffer
00262 
00263     // Set Object Handle
00264     SetLong( Parameter, Handle.Version, &offset );
00265     SetLong( Parameter, Handle.Index, &offset );
00266     // Set Object Size
00267     unsigned int highpart = (unsigned int) ((Size >> 32) & 0xffffffff);
00268     unsigned int lowpart = (unsigned int)(Size & 0xffffffff);
00269     SetULong( Parameter, highpart, &offset );
00270     SetULong( Parameter, lowpart, &offset );
00271 
00272     if( md5sum == NULL )
00273         SetString( Parameter, "0", &offset ); //NULL md5sum's are used for
00274                                               //directories, and represented by 
00275                                               //a single 0
00276     else 
00277         SetString( Parameter, md5sum, &offset );
00278 
00279     // Update Parameter size to actual size
00280     // (previously was maximum possible size)
00281     ParameterSize = offset;
00282 
00283     // Call remote method
00284     status = m_TCPconnection->Call( RioClassObjectManager,
00285                                     RioMethodObjectManagerSetSize,
00286                                     ParameterSize,
00287                                     Parameter,
00288                                     &ResultSize,
00289                                     &Result );
00290 
00291     // check if call failed
00292     if( FAILED( status ) )
00293     {
00294         if( Result != NULL )
00295             free( Result );
00296         if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) )
00297             status = ERROR_RIOPROXY + ERROR_MEMORY;
00298         free( Parameter );
00299 
00300         return status;
00301     }
00302 
00303     offset = 0;
00304     // Get results from result buffer
00305     // Get method return value
00306     if( !GetLong( Result, ResultSize, &status, &offset ) )
00307     {
00308         free( Parameter );
00309         free( Result );
00310 
00311         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00312     }
00313 
00314     free( Parameter );
00315     free( Result );
00316 
00317     return status;
00318 }

HRESULT CObjectManager::SetVideoRate ( const ObjectHandle  Handle,
const unsigned int  VideoRate 
)

SetVideoRate altera a taxa de transmissao (em Kbps) do video.

Parameters:
Handle identificador do objeto cuja taxa de transmissao desejamos alterar.
VideoRate nova taxa de transmissao do video.
Returns:
erro se nao foi possivel chamar o metodo ou se algum erro ocorreu ao executar o metodo.

Definition at line 691 of file interface/ObjectManager.cpp.

00693 {
00694     char          *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) );
00695     char          *Result;
00696     unsigned int  ParameterSize;
00697     unsigned int  ResultSize;
00698     HRESULT        status;
00699 
00700     if( Parameter == NULL )
00701     {
00702         RioErr << "malloc error SetVideoRate:" << strerror(errno) << endl;
00703         free( Parameter );
00704 
00705         return ERROR_RIOPROXY + ERROR_MEMORY;
00706     }
00707 
00708     memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) );
00709 
00710     ParameterSize = 2*MAX_LONG_STRING_SIZE + MAX_ULONG_STRING_SIZE;
00711     // Check if Parameter buffer is large enough
00712     if( ParameterSize > (unsigned int) MaxTCPDataSize )
00713     {
00714         free( Parameter );
00715 
00716         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00717     }
00718 
00719     int offset = 0;
00720 
00721     // Set parameters on asii buffer
00722     // Set Object Handle
00723     SetLong( Parameter, Handle.Version, &offset );
00724     SetLong( Parameter, Handle.Index, &offset );
00725     // Set Object transmission rate.
00726     SetULong( Parameter, VideoRate, &offset );
00727 
00728     // Update Parameter size to actual size
00729     // (previously was maximum possible size)
00730     ParameterSize = offset;
00731 
00732     // Call remote method
00733     status = m_TCPconnection->Call( RioClassObjectManager,
00734                                     RioMethodObjectManagerSetVideoRate,
00735                                     ParameterSize,
00736                                     Parameter,
00737                                     &ResultSize,
00738                                     &Result );
00739 
00740     // check if call failed
00741     if( FAILED( status ) )
00742     {
00743         if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) )
00744             status = ERROR_RIOPROXY + ERROR_MEMORY;
00745         if( Result != NULL )
00746             free( Result );
00747         free( Parameter );
00748 
00749         return status;
00750     }
00751 
00752     offset = 0;
00753     // Get results from result buffer
00754     // Get method return value
00755     if( !GetLong( Result, ResultSize, &status, &offset ) )
00756     {
00757         free( Parameter );
00758         free( Result );
00759 
00760         return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00761     }
00762 
00763     free( Parameter );
00764     free( Result );
00765 
00766     return status;
00767 }

int CObjectManager::Start ( void   ) 

Definition at line 228 of file server/ObjectManager.cpp.

00229 {
00230     HRESULT result;
00231 
00232     // Make sure we are initialized.
00233     if( !m_initialized )
00234     {
00235         if( m_log.is_open() )
00236             m_log << "Start(): Component not initiallized" << endl;
00237 
00238         return ERROR_OBJECTMANAGER + ERROR_NOT_INITIALIZED;
00239     }
00240 
00241     // Make sure we are not started.
00242     if( m_started )
00243     {
00244         if( m_log.is_open() )
00245             m_log << "Start(): Component already started" << endl;
00246 
00247         return( ERROR_OBJECTMANAGER + ERROR_STARTED );
00248     }
00249 
00250     // Start Object Map Manager.
00251     result = m_ObjMapMgr->Start();
00252     if( FAILED( result ) )
00253         return result;
00254 
00255     m_started = true;
00256 
00257     return S_OK;
00258 }

int CObjectManager::Stop ( void   ) 

Definition at line 261 of file server/ObjectManager.cpp.

00262 {
00263     int result;
00264 
00265     // Make sure we are started.
00266     if( !m_started )
00267     {
00268         if( m_log.is_open() )
00269             m_log << "Stop(): Component not started" << endl;
00270 
00271         return( ERROR_OBJECTMANAGER + ERROR_NOT_STARTED );
00272     }
00273 
00274     // Handle table can fail to stop if the table is still in use.
00275     result = m_ObjMapMgr->Stop();
00276     if( FAILED( result ) )
00277         return result;
00278 
00279     m_started = false;
00280 
00281     return S_OK;
00282 }

int CObjectManager::StrToPath ( const char *  Str,
char *  PathName,
const int  MaxSize 
) [static]

Definition at line 860 of file server/ObjectManager.cpp.

00862 {
00863     const char *si;
00864     const char *dirs;
00865     char       *so;
00866     char       *sl;
00867     int         len;
00868     char        FullPathName[ MaxPathSize + 10 ];
00869     *FullPathName = '\0';
00870 
00871     *PathName = '\0'; // Default if return false.
00872 
00873     //if( *Str == '\0' ) // Empty path
00874    //   return ERROR_OBJECTMANAGER + ERROR_PATHNAME_BADSYNTAX;
00875 
00876     dirs = Str;
00877     so = FullPathName;
00878     sl = so + MaxPathSize; // String limit.
00879     while( *dirs != '\0' )
00880     {
00881         while( *dirs == '/' )
00882             dirs++; // Eat "/"s before name.
00883         // Find end of this directory in input string.
00884         for( si = dirs; *si != '\0' && *si != '/'; si++ )
00885             ;
00886         // Check if this is "." or "..".
00887         len = si - dirs;
00888 
00889         if( len == 0 )
00890         {
00891             dirs = si; // Nao copia nenhum subcaminho neste caso.
00892         }
00893         else
00894             if( ( len == 1 ) && ( *dirs == '.' ) )
00895                 dirs = si; // Eat "." directory.
00896             else
00897                 if( ( len == 2 ) && ( dirs[ 0 ] == '.' ) && 
00898                     ( dirs[ 1 ] == '.' ) )
00899                 {
00900                     dirs = si; // Will process ..
00901                     // Back up output one directory
00902                     if( so <= FullPathName )
00903                         // Less than null path
00904                         return ERROR_OBJECTMANAGER + ERROR_PATHNAME_BADSYNTAX;
00905                     do
00906                     {
00907                         so--;
00908                     }while( ( so >= FullPathName ) && ( *so != '/' ) );
00909 
00910                     // Se o cd .. for feito no home deve voltar para o "/".
00911                     if( so < FullPathName )
00912                     {
00913                         so++;
00914                         if( strcmp( so, FullPathName ) == 0 )
00915                         {
00916                             FullPathName[ 0 ] = '\0';
00917                         }
00918                         so--;
00919                     }
00920                 }
00921                 else
00922                 {
00923                     // Copy directory to output string.
00924                     if( so != FullPathName )
00925                         *so++ = '/';
00926                     if( ( so+len ) > sl )
00927                         return ERROR_OBJECTMANAGER + ERROR_PATHNAME_TOOLARGE;
00928                     memcpy( so, dirs, len );
00929                     so += len;
00930                     dirs += len;
00931                 }
00932     }
00933     *so++ = '\0';
00934 
00935     if( ( so - FullPathName ) > MaxSize )
00936         return ERROR_OBJECTMANAGER + ERROR_PATHNAME_TOOLARGE;
00937 
00938     strcpy( PathName, FullPathName );
00939 
00940     return S_OK;
00941 }


Friends And Related Function Documentation

friend class RioDirectory [friend]

Definition at line 369 of file server/ObjectManager.h.


Field Documentation

unsigned int CObjectManager::m_BlockSize [private]

Definition at line 134 of file server/ObjectManager.h.

Definition at line 136 of file server/ObjectManager.h.

char* CObjectManager::m_FileRoot [private]

Definition at line 133 of file server/ObjectManager.h.

Definition at line 131 of file server/ObjectManager.h.

ofstream CObjectManager::m_log [private]

Definition at line 128 of file server/ObjectManager.h.

Definition at line 129 of file server/ObjectManager.h.

Definition at line 135 of file server/ObjectManager.h.

bool CObjectManager::m_started [private]

Definition at line 132 of file server/ObjectManager.h.

Definition at line 80 of file interface/ObjectManager.h.

Definition at line 130 of file server/ObjectManager.h.

Definition at line 137 of file server/ObjectManager.h.


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