00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <stdio.h>
00025 #include <string.h>
00026 #include <errno.h>
00027
00028 #ifdef WINDOWS
00029
00030 #include "stdafx.h"
00031 #else
00032 #include <strings.h>
00033 #include "RioUnix.h"
00034 #endif
00035
00036 #include "RioProxy.h"
00037 #include "RioError.h"
00038 #include "DataConversion.h"
00039
00040 #include "StreamManager.h"
00041
00042
00043 CStreamManager::CStreamManager(CRioTCP* TCPconnection)
00044 {
00045 m_TCPconnection = TCPconnection;
00046 }
00047
00048 CStreamManager::~CStreamManager()
00049 {
00050 }
00051
00052
00053 HRESULT CStreamManager::Close(const RioStreamId Stream)
00054 {
00055 char *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) );
00056 char *Result;
00057 unsigned int ParameterSize;
00058 unsigned int ResultSize;
00059 HRESULT status;
00060
00061 if( Parameter == NULL )
00062 {
00063 RioErr << "malloc error Close:" << strerror(errno) << endl;
00064 free( Parameter );
00065
00066 return ERROR_RIOPROXY + ERROR_MEMORY;
00067 }
00068
00069 memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) );
00070
00071 ParameterSize = 2*MAX_LONG_STRING_SIZE;
00072
00073 if(ParameterSize > (unsigned int) MaxTCPDataSize)
00074 {
00075 free( Parameter );
00076
00077 return ERROR_RIOPROXY + ERROR_CALL_MESSAGE_OVERFLOW;
00078 }
00079
00080 int offset = 0;
00081
00082
00083
00084 SetLong(Parameter,Stream.Version,&offset);
00085 SetLong(Parameter,Stream.Index,&offset);
00086
00087
00088
00089 ParameterSize = offset;
00090
00091
00092 status = m_TCPconnection->Call(RioClassStreamManager,
00093 RioMethodStreamManagerClose,
00094 ParameterSize,
00095 Parameter,
00096 &ResultSize,
00097 &Result);
00098
00099
00100 if( FAILED( status ) )
00101 {
00102 if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) )
00103 status = ERROR_RIOPROXY + ERROR_MEMORY;
00104 free( Parameter );
00105 if( Result != NULL )
00106 free( Result );
00107
00108 return status;
00109 }
00110
00111 offset = 0;
00112
00113
00114 if(!GetLong(Result,ResultSize,&status,&offset))
00115 {
00116 free( Parameter );
00117 free( Result );
00118
00119 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00120 }
00121
00122 free( Parameter );
00123 free( Result );
00124
00125 return status;
00126 }
00127
00128
00129 HRESULT CStreamManager::OpenObject( const RioStreamId Stream,
00130 const char* ObjectName,
00131 const RioAccess Access,
00132 ObjectHandle *Handle)
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 OpenObject:" << 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 strlen(ObjectName) + 1 +
00152 MAX_ULONG_STRING_SIZE;
00153
00154 if(ParameterSize > (unsigned int) MaxTCPDataSize)
00155 {
00156 free( Parameter );
00157
00158 return ERROR_RIOPROXY + ERROR_CALL_MESSAGE_OVERFLOW;
00159 }
00160
00161 int offset = 0;
00162
00163
00164
00165 SetLong(Parameter,Stream.Version,&offset);
00166 SetLong(Parameter,Stream.Index,&offset);
00167
00168 SetString(Parameter,ObjectName,&offset);
00169
00170 SetULong(Parameter,Access,&offset);
00171
00172
00173
00174 ParameterSize = offset;
00175
00176 #ifdef RIO_DEBUG2
00177 RioErr << "RioMethodStreamManagerOpenObject "
00178 << RioMethodStreamManagerOpenObject << endl;
00179 #endif // RIO_DEBUG2
00180
00181
00182 status = m_TCPconnection->Call(RioClassStreamManager,
00183 RioMethodStreamManagerOpenObject,
00184 ParameterSize,
00185 Parameter,
00186 &ResultSize,
00187 &Result);
00188
00189 if(FAILED (status))
00190 {
00191 if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) )
00192 status = ERROR_RIOPROXY + ERROR_MEMORY;
00193 free( Parameter );
00194 if( Result != NULL )
00195 free( Result );
00196
00197 return status;
00198 }
00199
00200 offset = 0;
00201
00202
00203 if(!GetLong(Result,ResultSize,&status,&offset))
00204 {
00205 free( Parameter );
00206 free( Result );
00207
00208 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00209 }
00210
00211 if(!GetLong(Result,ResultSize,&(Handle->Version),&offset))
00212 {
00213 free( Parameter );
00214 free( Result );
00215
00216 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00217 }
00218 if(!GetLong(Result,ResultSize,&(Handle->Index),&offset))
00219 {
00220 free( Parameter );
00221 free( Result );
00222
00223 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00224 }
00225
00226 free( Parameter );
00227 free( Result );
00228
00229 return status;
00230 }
00231
00232
00233
00234 #ifdef WINDOWS
00235
00236 HRESULT CStreamManager::OpenObject( const RioStreamId Stream,
00237 const char* ObjectName,
00238 const RioAccess Access,
00239 struct _SYSTEMTIME RTT_average,
00240 int BufferSize,
00241 ObjectHandle *Handle,
00242 RioObjectSize *Size,
00243 int *m_FlagRequests,
00244 int *m_PID)
00245 #else
00246
00247 HRESULT CStreamManager::OpenObject( const RioStreamId Stream,
00248 const char* ObjectName,
00249 const RioAccess Access,
00250 struct timeval RTT_average,
00251 int BufferSize,
00252 ObjectHandle *Handle,
00253 RioObjectSize *Size,
00254 int *m_FlagRequests,
00255 int *m_PID)
00256 #endif
00257
00258 {
00259 char *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) );
00260 char *Result;
00261 unsigned int ParameterSize;
00262 unsigned int ResultSize;
00263 HRESULT status;
00264
00265 if( Parameter == NULL )
00266 {
00267 RioErr << "malloc error OpenObject:" << strerror(errno) << endl;
00268 free( Parameter );
00269
00270 return ERROR_RIOPROXY + ERROR_MEMORY;
00271 }
00272
00273 memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) );
00274
00275 ParameterSize = 5 * MAX_LONG_STRING_SIZE +
00276 strlen(ObjectName) + 1 +
00277 MAX_ULONG_STRING_SIZE;
00278
00279 if(ParameterSize > (unsigned int) MaxTCPDataSize)
00280 {
00281 free( Parameter );
00282
00283 return ERROR_RIOPROXY + ERROR_CALL_MESSAGE_OVERFLOW;
00284 }
00285
00286 int offset = 0;
00287
00288
00289
00290 SetLong(Parameter,Stream.Version,&offset);
00291 SetLong(Parameter,Stream.Index,&offset);
00292
00293 SetString(Parameter,ObjectName,&offset);
00294
00295 SetULong(Parameter,Access,&offset);
00296
00297
00298 #ifdef WINDOWS
00299
00300 SetLong(Parameter,RTT_average.wSecond,&offset);
00301 SetLong(Parameter,RTT_average.wMilliseconds,&offset);
00302 #else
00303
00304 SetLong(Parameter,RTT_average.tv_sec,&offset);
00305 SetLong(Parameter,RTT_average.tv_usec,&offset);
00306 #endif
00307
00308
00309
00310 SetLong(Parameter,BufferSize,&offset);
00311
00312
00313
00314 ParameterSize = offset;
00315
00316
00317 status = m_TCPconnection->Call(RioClassStreamManager,
00318 RioMethodStreamManagerOpenObjectSubmitToCAC,
00319 ParameterSize,
00320 Parameter,
00321 &ResultSize,
00322 &Result);
00323
00324
00325 if(FAILED (status))
00326 {
00327 if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) )
00328 status = ERROR_RIOPROXY + ERROR_MEMORY;
00329 free( Parameter );
00330 if( Result != NULL )
00331 free( Result );
00332
00333 return status;
00334 }
00335
00336 offset = 0;
00337
00338
00339 if(!GetLong(Result,ResultSize,&status,&offset))
00340 {
00341 free( Parameter );
00342 free( Result );
00343
00344 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00345 }
00346
00347 if(!GetLong(Result,ResultSize,&(Handle->Version),&offset))
00348 {
00349 free( Parameter );
00350 free( Result );
00351
00352 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00353 }
00354 if(!GetLong(Result,ResultSize,&(Handle->Index),&offset))
00355 {
00356 free( Parameter );
00357 free( Result );
00358
00359 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00360 }
00361
00362 unsigned int highpart;
00363 unsigned int lowpart;
00364 if( !GetULong( Result,ResultSize,&highpart,&offset ))
00365 {
00366 free( Parameter );
00367 free( Result );
00368
00369 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00370 }
00371 if( !GetULong( Result,ResultSize,&lowpart,&offset ))
00372 {
00373 free( Parameter );
00374 free( Result );
00375
00376 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00377 }
00378 *Size = ((( RioObjectSize ) highpart ) << 32 ) | lowpart ;
00379
00380 if(!GetLong(Result,ResultSize,m_FlagRequests,&offset))
00381 {
00382 free( Parameter );
00383 free( Result );
00384
00385 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00386 }
00387
00388
00389
00390
00391
00392
00393
00394 if( *m_FlagRequests != 2 )
00395 {
00396 if(!GetLong(Result,ResultSize,m_PID,&offset))
00397 {
00398 free( Parameter );
00399 free( Result );
00400
00401 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00402 }
00403 }
00404
00405 free( Parameter );
00406 free( Result );
00407
00408 return status;
00409 }
00410
00411
00412 HRESULT CStreamManager::CanStart( const RioStreamId Stream )
00413 {
00414 char *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) );
00415 char *Result;
00416 unsigned int ParameterSize;
00417 unsigned int ResultSize;
00418 HRESULT status;
00419
00420 if( Parameter == NULL )
00421 {
00422 RioErr << "malloc error CanStart:" << strerror(errno) << endl;
00423 free( Parameter );
00424
00425 return ERROR_RIOPROXY + ERROR_MEMORY;
00426 }
00427
00428 memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) );
00429
00430 ParameterSize = 2 * MAX_LONG_STRING_SIZE;
00431
00432
00433 if(ParameterSize > (unsigned int) MaxTCPDataSize)
00434 {
00435 free( Parameter );
00436
00437 return ERROR_RIOPROXY + ERROR_CALL_MESSAGE_OVERFLOW;
00438 }
00439
00440 int offset = 0;
00441
00442
00443
00444 SetLong(Parameter,Stream.Version,&offset);
00445 SetLong(Parameter,Stream.Index,&offset);
00446
00447
00448
00449 ParameterSize = offset;
00450
00451
00452
00453
00454
00455 status = m_TCPconnection->Call(RioClassStreamManager,
00456 RioMethodStreamManagerClientCanStart,
00457 ParameterSize,
00458 Parameter,
00459 &ResultSize,
00460 &Result);
00461
00462
00463 if(FAILED (status))
00464 {
00465 if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) )
00466 status = ERROR_RIOPROXY + ERROR_MEMORY;
00467 free( Parameter );
00468 if( Result != NULL )
00469 free( Result );
00470
00471 return status;
00472 }
00473
00474 offset = 0;
00475
00476
00477 if(!GetLong(Result,ResultSize,&status,&offset))
00478 {
00479 free( Parameter );
00480 free( Result );
00481
00482 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00483 }
00484
00485 free( Parameter );
00486 free( Result );
00487
00488 return status;
00489 }
00490
00491
00492 HRESULT CStreamManager::MaxRequests( const RioStreamId Stream )
00493 {
00494 char *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) );
00495 char *Result;
00496 unsigned int ParameterSize;
00497 unsigned int ResultSize;
00498 HRESULT status;
00499
00500 if( Parameter == NULL )
00501 {
00502 RioErr << "malloc error MaxRequests:" << strerror(errno) << endl;
00503 free( Parameter );
00504
00505 return ERROR_RIOPROXY + ERROR_MEMORY;
00506 }
00507
00508 memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) );
00509
00510 ParameterSize = 2 * MAX_LONG_STRING_SIZE;
00511
00512
00513 if(ParameterSize > (unsigned int) MaxTCPDataSize)
00514 {
00515 free( Parameter );
00516
00517 return ERROR_RIOPROXY + ERROR_CALL_MESSAGE_OVERFLOW;
00518 }
00519
00520 int offset = 0;
00521
00522
00523
00524 SetLong(Parameter,Stream.Version,&offset);
00525 SetLong(Parameter,Stream.Index,&offset);
00526
00527
00528
00529 ParameterSize = offset;
00530
00531
00532 status = m_TCPconnection->Call(RioClassStreamManager,
00533 RioMethodStreamManagerMaxRequests,
00534 ParameterSize,
00535 Parameter,
00536 &ResultSize,
00537 &Result);
00538
00539
00540 if( FAILED(status) )
00541 {
00542 if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) )
00543 status = ERROR_RIOPROXY + ERROR_MEMORY;
00544 free( Parameter );
00545 if( Result != NULL )
00546 free( Result );
00547
00548 return status;
00549 }
00550
00551 offset = 0;
00552
00553
00554 if( !GetLong( Result, ResultSize, &status, &offset ) )
00555 {
00556 free( Parameter );
00557 free( Result );
00558
00559 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT;
00560 }
00561
00562 free( Parameter );
00563 free( Result );
00564
00565 return status;
00566 }