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
00031 #include "stdafx.h"
00032 #else
00033
00034 #include <strings.h>
00035 #include "RioUnix.h"
00036 #endif
00037
00038 #include "RioProxy.h"
00039 #include "RioError.h"
00040 #include "DataConversion.h"
00041 #include "ObjectManager.h"
00042
00043
00044
00045 CObjectManager::CObjectManager( CRioTCP* TCPconnection )
00046 {
00047 m_TCPconnection = TCPconnection;
00048 }
00049
00050 CObjectManager::~CObjectManager()
00051 {
00052 }
00053
00054
00055 HRESULT CObjectManager::Close( const ObjectHandle Handle )
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
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
00085
00086 SetLong( Parameter, Handle.Version, &offset );
00087 SetLong( Parameter, Handle.Index, &offset );
00088
00089
00090
00091 ParameterSize = offset;
00092
00093
00094 status = m_TCPconnection->Call( RioClassObjectManager,
00095 RioMethodObjectManagerClose,
00096 ParameterSize,
00097 Parameter,
00098 &ResultSize,
00099 &Result );
00100
00101
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
00115
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 }
00129
00130
00131 HRESULT CObjectManager::GetSize( const ObjectHandle Handle,
00132 RioObjectSize *Size )
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
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
00162
00163 SetLong( Parameter, Handle.Version, &offset );
00164 SetLong( Parameter, Handle.Index, &offset );
00165
00166
00167
00168 ParameterSize = offset;
00169
00170
00171
00172 status = m_TCPconnection->Call( RioClassObjectManager,
00173 RioMethodObjectManagerGetSize,
00174 ParameterSize,
00175 Parameter,
00176 &ResultSize,
00177 &Result );
00178
00179
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
00193
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
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 }
00225
00226
00227 HRESULT CObjectManager::SetSize(const ObjectHandle Handle,
00228 const RioObjectSize Size,
00229 char *md5sum )
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
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
00262
00263
00264 SetLong( Parameter, Handle.Version, &offset );
00265 SetLong( Parameter, Handle.Index, &offset );
00266
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 );
00274
00275
00276 else
00277 SetString( Parameter, md5sum, &offset );
00278
00279
00280
00281 ParameterSize = offset;
00282
00283
00284 status = m_TCPconnection->Call( RioClassObjectManager,
00285 RioMethodObjectManagerSetSize,
00286 ParameterSize,
00287 Parameter,
00288 &ResultSize,
00289 &Result );
00290
00291
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
00305
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 }
00319
00320
00321 HRESULT CObjectManager::GetType(const ObjectHandle Handle,
00322 short* Type)
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
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
00352
00353 SetLong( Parameter, Handle.Version, &offset );
00354 SetLong( Parameter, Handle.Index, &offset );
00355
00356
00357
00358 ParameterSize = offset;
00359
00360
00361 status = m_TCPconnection->Call( RioClassObjectManager,
00362 RioMethodObjectManagerGetType,
00363 ParameterSize,
00364 Parameter,
00365 &ResultSize,
00366 &Result );
00367
00368
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
00382
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
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 }
00407
00408
00409 HRESULT CObjectManager::GetnBlocks(const ObjectHandle Handle,
00410 RioBlock* nBlocks)
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
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
00440
00441 SetLong(Parameter,Handle.Version,&offset);
00442 SetLong(Parameter,Handle.Index,&offset);
00443
00444
00445
00446 ParameterSize = offset;
00447
00448
00449 status = m_TCPconnection->Call( RioClassObjectManager,
00450 RioMethodObjectManagerGetnBlocks,
00451 ParameterSize,
00452 Parameter,
00453 &ResultSize,
00454 &Result );
00455
00456
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
00470
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
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 }
00492
00493
00494 HRESULT CObjectManager::NextObject( ObjectHandle Handle, int* IsDirectory,
00495 int BufferSize, signed char* ObjectName )
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
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
00525
00526 SetLong( Parameter, Handle.Version, &offset );
00527 SetLong( Parameter, Handle.Index, &offset );
00528
00529 SetLong( Parameter, BufferSize, &offset );
00530
00531
00532
00533 ParameterSize = offset;
00534
00535
00536 status = m_TCPconnection->Call( RioClassObjectManager,
00537 RioMethodObjectManagerNextObject,
00538 ParameterSize,
00539 Parameter,
00540 &ResultSize,
00541 &Result );
00542
00543
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
00557
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
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
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 }
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604 HRESULT CObjectManager::GetVideoRate( const ObjectHandle Handle,
00605 unsigned int *VideoRate )
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
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
00635
00636 SetLong( Parameter, Handle.Version, &offset );
00637 SetLong( Parameter, Handle.Index, &offset );
00638
00639
00640
00641 ParameterSize = offset;
00642
00643
00644 status = m_TCPconnection->Call( RioClassObjectManager,
00645 RioMethodObjectManagerGetVideoRate,
00646 ParameterSize,
00647 Parameter,
00648 &ResultSize,
00649 &Result );
00650
00651
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
00665
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 }
00686
00687
00688
00689
00690
00691 HRESULT CObjectManager::SetVideoRate( const ObjectHandle Handle,
00692 const unsigned int VideoRate )
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
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
00722
00723 SetLong( Parameter, Handle.Version, &offset );
00724 SetLong( Parameter, Handle.Index, &offset );
00725
00726 SetULong( Parameter, VideoRate, &offset );
00727
00728
00729
00730 ParameterSize = offset;
00731
00732
00733 status = m_TCPconnection->Call( RioClassObjectManager,
00734 RioMethodObjectManagerSetVideoRate,
00735 ParameterSize,
00736 Parameter,
00737 &ResultSize,
00738 &Result );
00739
00740
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
00754
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 }
00768
00769
00770
00771
00772
00773
00774
00775
00776 HRESULT CObjectManager::ReallocBlocks( const ObjectHandle Handle,
00777 const RioBlock Block )
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
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
00807
00808 SetLong( Parameter, Handle.Version, &offset );
00809 SetLong( Parameter, Handle.Index, &offset );
00810
00811 SetULong( Parameter, ( unsigned int ) Block, &offset );
00812
00813
00814
00815 ParameterSize = offset;
00816
00817
00818 status = m_TCPconnection->Call( RioClassObjectManager,
00819 RioMethodObjectManagerReallocBlocks,
00820 ParameterSize,
00821 Parameter,
00822 &ResultSize,
00823 &Result );
00824
00825
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
00839
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 }
00853