00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "PLStreamManager.h"
00019
00020
00021
00022 #if defined(RIO_DEBUG2) || defined(RIO_EMUL)
00023 const char* const LOGFILE = "RIOPLStreamManager.log";
00024 #endif
00025
00026
00027
00028 PLStreamManager::PLStreamManager( char *LogsDirectory )
00029 {
00030 #ifdef RIO_DEBUG1
00031 RioErr << "### [PLStreamManager - Constructor] Start" << endl;
00032 #endif
00033
00034 #if defined(RIO_DEBUG2) || defined(RIO_EMUL)
00035
00036 char LogFileName[ MaxPathSize ];
00037
00038 strcpy( LogFileName, LogsDirectory );
00039 strcat( LogFileName, LOGFILE );
00040 m_log.open( LogFileName );
00041 #endif
00042
00043 #ifdef RIO_DEBUG1
00044 RioErr << "### [PLStreamManager - Constructor] Finish" << endl;
00045 #endif
00046 }
00047
00048 PLStreamManager::~PLStreamManager()
00049 {
00050 #ifdef RIO_DEBUG1
00051 RioErr << "### [PLStreamManager - Destructor] Start" << endl;
00052 #endif
00053
00054 #if defined(RIO_DEBUG2) || defined(RIO_EMUL)
00055 m_log.close();
00056 #endif
00057
00058 #ifdef RIO_DEBUG1
00059 RioErr << "### [PLStreamManager - Destructor] Finish" << endl;
00060 #endif
00061 }
00062
00063
00064 HRESULT PLStreamManager::OpenStreamRioServer( RioStreamTraffic Traffic,
00065 unsigned int *ResultSize,
00066 CRioStream *StreamRioServer,
00067 CRioSession *SessionRioServer,
00068 int *maxrequests )
00069 {
00070 #ifdef RIO_DEBUG1
00071 RioErr << "### [PLStreamManager - OpenStreamRioServer] Start" << endl;
00072 #endif
00073
00074 HRESULT hresult;
00075 unsigned int Size;
00076
00077 *maxrequests = 0;
00078
00079 #if defined(RIO_DEBUG2) || defined(RIO_EMUL)
00080 m_log << myInfo() << " Abrindo Stream" << endl;
00081 #endif
00082
00083 hresult = StreamRioServer->Open( &Traffic, SessionRioServer );
00084 if( FAILED( hresult ) )
00085 {
00086 #if defined(RIO_DEBUG2) || defined(RIO_EMUL)
00087 m_log << myInfo() << " Stream nao pode ser aberta: "
00088 << GetErrorDescription( hresult ) << endl;
00089 #endif
00090
00091 RioErr << "[OpenStreamRioServer] Error "
00092 << GetErrorDescription( hresult ) << endl;
00093
00094 #ifdef RIO_DEBUG1
00095 RioErr << "### [PLStreamManager - OpenStreamRioServer] Finish 1" << endl;
00096 #endif
00097
00098 return ( hresult );
00099 }
00100
00101 #if defined(RIO_DEBUG2) || defined(RIO_EMUL)
00102 m_log << " OK" << endl;
00103 m_log << "[PLStreamManager]: Max Requests ";
00104 #endif
00105
00106 int nMaxReq = StreamRioServer->MaxRequests();
00107 if( nMaxReq < 0 )
00108 {
00109 RioErr << "[OpenStreamRioServer] nMaxReq negativo. " << endl;
00110
00111 #ifdef RIO_DEBUG1
00112 RioErr << "### [PLStreamManager - OpenStreamRioServer] Finish 2" << endl;
00113 #endif
00114
00115 return ERROR_PLCONNECTIONMANAGER + ERROR_MAX_STREAM_REQUESTS;
00116 }
00117 else
00118 {
00119 *maxrequests = nMaxReq;
00120 }
00121
00122 #if defined(RIO_DEBUG2) || defined(RIO_EMUL)
00123 m_log << " OK" << endl;
00124 m_log << "[PLStreamManager]: Maxrequests=" << nMaxReq << endl;
00125 #endif
00126
00127
00128 Size = 3 * MAX_LONG_STRING_SIZE;
00129 if( Size > *ResultSize )
00130 {
00131 #ifdef RIO_DEBUG1
00132 RioErr << "### [PLStreamManager - OpenStreamRioServer] Finish 3" << endl;
00133 #endif
00134
00135 #if defined(RIO_DEBUG2) || defined(RIO_EMUL)
00136 m_log << "[PLStreamManager]: Error: Message overflow." << endl;
00137 #endif
00138
00139 return ERROR_PLCONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
00140 }
00141
00142 #ifdef RIO_DEBUG1
00143 RioErr << "### [PLStreamManager - OpenStreamRioServer] Finish 4" << endl;
00144 #endif
00145
00146 return( 0 );
00147 }
00148
00149
00150 HRESULT PLStreamManager::CloseStreamRioServer( unsigned int *ResultSize,
00151 CRioStream *StreamRioServer )
00152 {
00153 #ifdef RIO_DEBUG1
00154 RioErr << "### [PLStreamManager - CloseStreamRioServer] Start" << endl;
00155 #endif
00156
00157 unsigned int Size;
00158
00159
00160 HRESULT hresult = StreamRioServer->Close();
00161
00162 #if defined(RIO_DEBUG2) || defined(RIO_EMUL)
00163 m_log << "OK" << endl;
00164 #endif
00165
00166
00167 Size = MAX_LONG_STRING_SIZE;
00168 if( Size > *ResultSize )
00169 {
00170 #ifdef RIO_DEBUG1
00171 RioErr << "### [PLStreamManager - CloseStreamRioServer] Finish 1" << endl;
00172 #endif
00173
00174 return ERROR_PLCONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
00175 }
00176
00177 #ifdef RIO_DEBUG1
00178 RioErr << "### [PLStreamManager - CloseStreamRioServer] Finish 2" << endl;
00179 #endif
00180
00181 return( hresult );
00182 }
00183
00184
00185
00186 HRESULT PLStreamManager::Open( char* ObjectName,
00187 RioAccess Access,
00188 CRioStream *StreamRioServer,
00189 CRioObject *ObjectRioServer)
00190 {
00191 #ifdef RIO_DEBUG1
00192 RioErr << "### [PLStreamManager - Open] Start" << endl;
00193 #endif
00194
00195 HRESULT hresult;
00196
00197 hresult = ObjectRioServer->Open(ObjectName, Access, StreamRioServer);
00198
00199 if( FAILED( hresult ) )
00200 {
00201 #if defined(RIO_DEBUG2) || defined(RIO_EMUL)
00202 m_log << " Failed" << endl;
00203 #endif
00204
00205 #ifdef RIO_DEBUG1
00206 RioErr << "### [PLStreamManager - Open] Finish 1" << endl;
00207 #endif
00208
00209 return ERROR_PLCONNECTIONMANAGER + ERROR_STREAM_NOT_OPENED;
00210 }
00211
00212 #if defined(RIO_DEBUG2) || defined(RIO_EMUL)
00213 m_log << " OK" << endl;
00214 #endif
00215
00216 #ifdef RIO_DEBUG1
00217 RioErr << "### [PLStreamManager - Open] Finish 2" << endl;
00218 #endif
00219
00220 return ( hresult );
00221 }
00222
00223
00224 HRESULT PLStreamManager::OpenCAC( char* ObjectName,
00225 RioAccess Access,
00226 struct timeval average_RTT,
00227 int BufferSize,
00228 CRioStream *StreamRioServer,
00229 unsigned int* ResultSize,
00230 CRioObject *ObjectRioServer)
00231 {
00232 #ifdef RIO_DEBUG1
00233 RioErr << "### [PLStreamManager - OpenCAC] Start" << endl;
00234 #endif
00235
00236 HRESULT hresult;
00237
00238 hresult = ObjectRioServer->Open( ObjectName, Access, average_RTT,
00239 BufferSize, StreamRioServer, m_log);
00240
00241 if( FAILED( hresult ) )
00242 {
00243 #if defined(RIO_DEBUG2) || defined(RIO_EMUL)
00244 m_log << " Failed" << endl;
00245 #endif
00246
00247 #ifdef RIO_DEBUG1
00248 RioErr << "### [PLStreamManager - OpenCAC] Finish 1" << endl;
00249 #endif
00250
00251 return ERROR_PLCONNECTIONMANAGER + ERROR_CAC_STREAM_NOT_OPENED;
00252 }
00253
00254 #if defined(RIO_DEBUG2) || defined(RIO_EMUL)
00255 m_log << " OK" << endl;
00256 #endif
00257
00258 #ifdef RIO_DEBUG1
00259 RioErr << "### [PLStreamManager - OpenCAC] Finish 2" << endl;
00260 #endif
00261
00262 return ( hresult );
00263 }
00264
00265
00266 HRESULT PLStreamManager::CanStart(CRioStream *StreamRioServer,
00267 unsigned int* ResultSize )
00268 {
00269 #ifdef RIO_DEBUG1
00270 RioErr << "### [PLStreamManager - CanStart] Start" << endl;
00271 #endif
00272
00273 unsigned int Size;
00274 int hresult = StreamRioServer->CanStart();
00275
00276
00277 Size = MAX_LONG_STRING_SIZE;
00278 if( Size > *ResultSize )
00279 {
00280 #ifdef RIO_DEBUG1
00281 RioErr << "### [PLStreamManager - CanStart] Finish 1" << endl;
00282 #endif
00283
00284 return ERROR_PLCONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
00285 }
00286
00287 #ifdef RIO_DEBUG1
00288 RioErr << "### [PLStreamManager - CanStart] Finish 2" << endl;
00289 #endif
00290
00291 return ( hresult );
00292 }