Changeset 2983 for box/trunk/lib
- Timestamp:
- 27/08/2011 15:06:46 (9 months ago)
- Location:
- box/trunk/lib
- Files:
-
- 11 edited
- 2 moved
-
backupclient/BackupClientRestore.cpp (modified) (2 diffs)
-
backupstore (modified) (1 prop)
-
backupstore/BackupCommands.cpp (modified) (30 diffs)
-
backupstore/BackupStoreContext.cpp (modified) (1 diff)
-
backupstore/BackupStoreContext.h (modified) (4 diffs)
-
backupstore/BackupStoreFile.h (modified) (2 diffs)
-
backupstore/Makefile.extra (modified) (1 diff)
-
backupstore/backupprotocol.txt (modified) (2 diffs)
-
server/Message.cpp (moved) (moved from box/trunk/lib/server/ProtocolObject.cpp) (10 diffs)
-
server/Message.h (moved) (moved from box/trunk/lib/server/ProtocolObject.h) (3 diffs)
-
server/Protocol.cpp (modified) (9 diffs)
-
server/Protocol.h (modified) (7 diffs)
-
server/makeprotocol.pl.in (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/lib/backupclient/BackupClientRestore.cpp
r2828 r2983 23 23 24 24 #include "BackupClientRestore.h" 25 #include "autogen_BackupProtocol Client.h"25 #include "autogen_BackupProtocol.h" 26 26 #include "CommonException.h" 27 27 #include "BackupClientFileAttributes.h" … … 444 444 rConnection.QueryListDirectory( 445 445 DirectoryID, 446 Params.RestoreDeleted?(BackupProtocol ClientListDirectory::Flags_Deleted):(BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING),447 BackupProtocol ClientListDirectory::Flags_OldVersion | (Params.RestoreDeleted?(0):(BackupProtocolClientListDirectory::Flags_Deleted)),446 Params.RestoreDeleted?(BackupProtocolListDirectory::Flags_Deleted):(BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING), 447 BackupProtocolListDirectory::Flags_OldVersion | (Params.RestoreDeleted?(0):(BackupProtocolListDirectory::Flags_Deleted)), 448 448 true /* want attributes */); 449 449 -
box/trunk/lib/backupstore
- Property svn:ignore
-
old new 1 1 Makefile 2 autogen_*
-
- Property svn:ignore
-
box/trunk/lib/backupstore/BackupCommands.cpp
r2945 r2983 13 13 #include <sstream> 14 14 15 #include "autogen_BackupProtocol Server.h"15 #include "autogen_BackupProtocol.h" 16 16 #include "autogen_RaidFileException.h" 17 17 #include "BackupConstants.h" … … 32 32 33 33 #define PROTOCOL_ERROR(code) \ 34 std::auto_ptr< ProtocolObject>(new BackupProtocolServerError( \35 BackupProtocol ServerError::ErrorType, \36 BackupProtocol ServerError::code));34 std::auto_ptr<BackupProtocolMessage>(new BackupProtocolError( \ 35 BackupProtocolError::ErrorType, \ 36 BackupProtocolError::code)); 37 37 38 38 #define CHECK_PHASE(phase) \ … … 51 51 // 52 52 // Function 53 // Name: BackupProtocol ServerVersion::DoCommand(Protocol &, BackupStoreContext &)53 // Name: BackupProtocolVersion::DoCommand(Protocol &, BackupStoreContext &) 54 54 // Purpose: Return the current version, or an error if the requested version isn't allowed 55 55 // Created: 2003/08/20 56 56 // 57 57 // -------------------------------------------------------------------------- 58 std::auto_ptr< ProtocolObject> BackupProtocolServerVersion::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)58 std::auto_ptr<BackupProtocolMessage> BackupProtocolVersion::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 59 59 { 60 60 CHECK_PHASE(Phase_Version) … … 70 70 71 71 // Return our version 72 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerVersion(BACKUP_STORE_SERVER_VERSION));73 } 74 75 // -------------------------------------------------------------------------- 76 // 77 // Function 78 // Name: BackupProtocol ServerLogin::DoCommand(Protocol &, BackupStoreContext &)72 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolVersion(BACKUP_STORE_SERVER_VERSION)); 73 } 74 75 // -------------------------------------------------------------------------- 76 // 77 // Function 78 // Name: BackupProtocolLogin::DoCommand(Protocol &, BackupStoreContext &) 79 79 // Purpose: Return the current version, or an error if the requested version isn't allowed 80 80 // Created: 2003/08/20 81 81 // 82 82 // -------------------------------------------------------------------------- 83 std::auto_ptr< ProtocolObject> BackupProtocolServerLogin::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)83 std::auto_ptr<BackupProtocolMessage> BackupProtocolLogin::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 84 84 { 85 85 CHECK_PHASE(Phase_Login) … … 139 139 140 140 // Return success 141 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerLoginConfirmed(clientStoreMarker, blocksUsed, blocksSoftLimit, blocksHardLimit));142 } 143 144 // -------------------------------------------------------------------------- 145 // 146 // Function 147 // Name: BackupProtocol ServerFinished::DoCommand(Protocol &, BackupStoreContext &)141 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolLoginConfirmed(clientStoreMarker, blocksUsed, blocksSoftLimit, blocksHardLimit)); 142 } 143 144 // -------------------------------------------------------------------------- 145 // 146 // Function 147 // Name: BackupProtocolFinished::DoCommand(Protocol &, BackupStoreContext &) 148 148 // Purpose: Marks end of conversation (Protocol framework handles this) 149 149 // Created: 2003/08/20 150 150 // 151 151 // -------------------------------------------------------------------------- 152 std::auto_ptr< ProtocolObject> BackupProtocolServerFinished::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)152 std::auto_ptr<BackupProtocolMessage> BackupProtocolFinished::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 153 153 { 154 154 BOX_NOTICE("Session finished for Client ID " << … … 159 159 160 160 // can be called in any phase 161 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerFinished);162 } 163 164 165 // -------------------------------------------------------------------------- 166 // 167 // Function 168 // Name: BackupProtocol ServerListDirectory::DoCommand(Protocol &, BackupStoreContext &)161 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolFinished); 162 } 163 164 165 // -------------------------------------------------------------------------- 166 // 167 // Function 168 // Name: BackupProtocolListDirectory::DoCommand(Protocol &, BackupStoreContext &) 169 169 // Purpose: Command to list a directory 170 170 // Created: 2003/09/02 171 171 // 172 172 // -------------------------------------------------------------------------- 173 std::auto_ptr< ProtocolObject> BackupProtocolServerListDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)173 std::auto_ptr<BackupProtocolMessage> BackupProtocolListDirectory::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 174 174 { 175 175 CHECK_PHASE(Phase_Commands) … … 201 201 rProtocol.SendStreamAfterCommand(stream.release()); 202 202 203 return std::auto_ptr< ProtocolObject>(204 new BackupProtocolS erverSuccess(mObjectID));205 } 206 207 // -------------------------------------------------------------------------- 208 // 209 // Function 210 // Name: BackupProtocolS erverStoreFile::DoCommand(Protocol &, BackupStoreContext &)203 return std::auto_ptr<BackupProtocolMessage>( 204 new BackupProtocolSuccess(mObjectID)); 205 } 206 207 // -------------------------------------------------------------------------- 208 // 209 // Function 210 // Name: BackupProtocolStoreFile::DoCommand(Protocol &, BackupStoreContext &) 211 211 // Purpose: Command to store a file on the server 212 212 // Created: 2003/09/02 213 213 // 214 214 // -------------------------------------------------------------------------- 215 std::auto_ptr< ProtocolObject> BackupProtocolServerStoreFile::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)215 std::auto_ptr<BackupProtocolMessage> BackupProtocolStoreFile::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 216 216 { 217 217 CHECK_PHASE(Phase_Commands) 218 218 CHECK_WRITEABLE_SESSION 219 219 220 std::auto_ptr< ProtocolObject> hookResult =220 std::auto_ptr<BackupProtocolMessage> hookResult = 221 221 rContext.StartCommandHook(*this); 222 222 if(hookResult.get()) … … 264 264 265 265 // Tell the caller what the file was 266 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerSuccess(id));267 } 268 269 270 271 272 // -------------------------------------------------------------------------- 273 // 274 // Function 275 // Name: BackupProtocol ServerGetObject::DoCommand(Protocol &, BackupStoreContext &)266 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(id)); 267 } 268 269 270 271 272 // -------------------------------------------------------------------------- 273 // 274 // Function 275 // Name: BackupProtocolGetObject::DoCommand(Protocol &, BackupStoreContext &) 276 276 // Purpose: Command to get an arbitary object from the server 277 277 // Created: 2003/09/03 278 278 // 279 279 // -------------------------------------------------------------------------- 280 std::auto_ptr< ProtocolObject> BackupProtocolServerGetObject::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)280 std::auto_ptr<BackupProtocolMessage> BackupProtocolGetObject::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 281 281 { 282 282 CHECK_PHASE(Phase_Commands) … … 285 285 if(!rContext.ObjectExists(mObjectID)) 286 286 { 287 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerSuccess(NoObject));287 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(NoObject)); 288 288 } 289 289 … … 295 295 296 296 // Tell the caller what the file was 297 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerSuccess(mObjectID));298 } 299 300 // -------------------------------------------------------------------------- 301 // 302 // Function 303 // Name: BackupProtocol ServerGetFile::DoCommand(Protocol &, BackupStoreContext &)297 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); 298 } 299 300 // -------------------------------------------------------------------------- 301 // 302 // Function 303 // Name: BackupProtocolGetFile::DoCommand(Protocol &, BackupStoreContext &) 304 304 // Purpose: Command to get an file object from the server -- may have to do a bit of 305 305 // work to get the object. … … 307 307 // 308 308 // -------------------------------------------------------------------------- 309 std::auto_ptr< ProtocolObject> BackupProtocolServerGetFile::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)309 std::auto_ptr<BackupProtocolMessage> BackupProtocolGetFile::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 310 310 { 311 311 CHECK_PHASE(Phase_Commands) … … 461 461 462 462 // Tell the caller what the file was 463 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerSuccess(mObjectID));464 } 465 466 467 // -------------------------------------------------------------------------- 468 // 469 // Function 470 // Name: BackupProtocol ServerCreateDirectory::DoCommand(Protocol &, BackupStoreContext &)463 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); 464 } 465 466 467 // -------------------------------------------------------------------------- 468 // 469 // Function 470 // Name: BackupProtocolCreateDirectory::DoCommand(Protocol &, BackupStoreContext &) 471 471 // Purpose: Create directory command 472 472 // Created: 2003/09/04 473 473 // 474 474 // -------------------------------------------------------------------------- 475 std::auto_ptr< ProtocolObject> BackupProtocolServerCreateDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)475 std::auto_ptr<BackupProtocolMessage> BackupProtocolCreateDirectory::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 476 476 { 477 477 CHECK_PHASE(Phase_Commands) … … 501 501 502 502 // Tell the caller what the file was 503 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerSuccess(id));504 } 505 506 507 508 // -------------------------------------------------------------------------- 509 // 510 // Function 511 // Name: BackupProtocol ServerChangeDirAttributes::DoCommand(Protocol &, BackupStoreContext &)503 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(id)); 504 } 505 506 507 508 // -------------------------------------------------------------------------- 509 // 510 // Function 511 // Name: BackupProtocolChangeDirAttributes::DoCommand(Protocol &, BackupStoreContext &) 512 512 // Purpose: Change attributes on directory 513 513 // Created: 2003/09/06 514 514 // 515 515 // -------------------------------------------------------------------------- 516 std::auto_ptr< ProtocolObject> BackupProtocolServerChangeDirAttributes::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)516 std::auto_ptr<BackupProtocolMessage> BackupProtocolChangeDirAttributes::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 517 517 { 518 518 CHECK_PHASE(Phase_Commands) … … 530 530 531 531 // Tell the caller what the file was 532 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerSuccess(mObjectID));533 } 534 535 536 // -------------------------------------------------------------------------- 537 // 538 // Function 539 // Name: BackupProtocolSe rverSetReplacementFileAttributes::DoCommand(Protocol &, BackupStoreContext &)532 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); 533 } 534 535 536 // -------------------------------------------------------------------------- 537 // 538 // Function 539 // Name: BackupProtocolSetReplacementFileAttributes::DoCommand(Protocol &, BackupStoreContext &) 540 540 // Purpose: Change attributes on directory 541 541 // Created: 2003/09/06 542 542 // 543 543 // -------------------------------------------------------------------------- 544 std::auto_ptr< ProtocolObject> BackupProtocolServerSetReplacementFileAttributes::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)544 std::auto_ptr<BackupProtocolMessage> BackupProtocolSetReplacementFileAttributes::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 545 545 { 546 546 CHECK_PHASE(Phase_Commands) … … 563 563 564 564 // Tell the caller what the file was 565 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerSuccess(objectID));566 } 567 568 569 570 // -------------------------------------------------------------------------- 571 // 572 // Function 573 // Name: BackupProtocol ServerDeleteFile::DoCommand(BackupProtocolServer&, BackupStoreContext &)565 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(objectID)); 566 } 567 568 569 570 // -------------------------------------------------------------------------- 571 // 572 // Function 573 // Name: BackupProtocolDeleteFile::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) 574 574 // Purpose: Delete a file 575 575 // Created: 2003/10/21 576 576 // 577 577 // -------------------------------------------------------------------------- 578 std::auto_ptr< ProtocolObject> BackupProtocolServerDeleteFile::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)578 std::auto_ptr<BackupProtocolMessage> BackupProtocolDeleteFile::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 579 579 { 580 580 CHECK_PHASE(Phase_Commands) … … 586 586 587 587 // return the object ID or zero for not found 588 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerSuccess(objectID));589 } 590 591 592 // -------------------------------------------------------------------------- 593 // 594 // Function 595 // Name: BackupProtocol ServerUndeleteFile::DoCommand(596 // BackupProtocol Server&, BackupStoreContext &)588 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(objectID)); 589 } 590 591 592 // -------------------------------------------------------------------------- 593 // 594 // Function 595 // Name: BackupProtocolUndeleteFile::DoCommand( 596 // BackupProtocolBase &, BackupStoreContext &) 597 597 // Purpose: Undelete a file 598 598 // Created: 2008-09-12 599 599 // 600 600 // -------------------------------------------------------------------------- 601 std::auto_ptr< ProtocolObject> BackupProtocolServerUndeleteFile::DoCommand(602 BackupProtocol Server &rProtocol, BackupStoreContext &rContext)601 std::auto_ptr<BackupProtocolMessage> BackupProtocolUndeleteFile::DoCommand( 602 BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 603 603 { 604 604 CHECK_PHASE(Phase_Commands) … … 609 609 610 610 // return the object ID or zero for not found 611 return std::auto_ptr< ProtocolObject>(612 new BackupProtocolS erverSuccess(result ? mObjectID : 0));613 } 614 615 616 // -------------------------------------------------------------------------- 617 // 618 // Function 619 // Name: BackupProtocol ServerDeleteDirectory::DoCommand(BackupProtocolServer&, BackupStoreContext &)611 return std::auto_ptr<BackupProtocolMessage>( 612 new BackupProtocolSuccess(result ? mObjectID : 0)); 613 } 614 615 616 // -------------------------------------------------------------------------- 617 // 618 // Function 619 // Name: BackupProtocolDeleteDirectory::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) 620 620 // Purpose: Delete a directory 621 621 // Created: 2003/10/21 622 622 // 623 623 // -------------------------------------------------------------------------- 624 std::auto_ptr< ProtocolObject> BackupProtocolServerDeleteDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)624 std::auto_ptr<BackupProtocolMessage> BackupProtocolDeleteDirectory::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 625 625 { 626 626 CHECK_PHASE(Phase_Commands) … … 649 649 650 650 // return the object ID 651 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerSuccess(mObjectID));652 } 653 654 655 // -------------------------------------------------------------------------- 656 // 657 // Function 658 // Name: BackupProtocol ServerUndeleteDirectory::DoCommand(BackupProtocolServer&, BackupStoreContext &)651 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); 652 } 653 654 655 // -------------------------------------------------------------------------- 656 // 657 // Function 658 // Name: BackupProtocolUndeleteDirectory::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) 659 659 // Purpose: Undelete a directory 660 660 // Created: 23/11/03 661 661 // 662 662 // -------------------------------------------------------------------------- 663 std::auto_ptr< ProtocolObject> BackupProtocolServerUndeleteDirectory::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)663 std::auto_ptr<BackupProtocolMessage> BackupProtocolUndeleteDirectory::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 664 664 { 665 665 CHECK_PHASE(Phase_Commands) … … 676 676 677 677 // return the object ID 678 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerSuccess(mObjectID));679 } 680 681 // -------------------------------------------------------------------------- 682 // 683 // Function 684 // Name: BackupProtocolSe rverSetClientStoreMarker::DoCommand(BackupProtocolServer&, BackupStoreContext &)678 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); 679 } 680 681 // -------------------------------------------------------------------------- 682 // 683 // Function 684 // Name: BackupProtocolSetClientStoreMarker::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) 685 685 // Purpose: Command to set the client's store marker 686 686 // Created: 2003/10/29 687 687 // 688 688 // -------------------------------------------------------------------------- 689 std::auto_ptr< ProtocolObject> BackupProtocolServerSetClientStoreMarker::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)689 std::auto_ptr<BackupProtocolMessage> BackupProtocolSetClientStoreMarker::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 690 690 { 691 691 CHECK_PHASE(Phase_Commands) … … 696 696 697 697 // return store marker set 698 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerSuccess(mClientStoreMarker));699 } 700 701 702 // -------------------------------------------------------------------------- 703 // 704 // Function 705 // Name: BackupProtocol ServerMoveObject::DoCommand(BackupProtocolServer&, BackupStoreContext &)698 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mClientStoreMarker)); 699 } 700 701 702 // -------------------------------------------------------------------------- 703 // 704 // Function 705 // Name: BackupProtocolMoveObject::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) 706 706 // Purpose: Command to move an object from one directory to another 707 707 // Created: 2003/11/12 708 708 // 709 709 // -------------------------------------------------------------------------- 710 std::auto_ptr< ProtocolObject> BackupProtocolServerMoveObject::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)710 std::auto_ptr<BackupProtocolMessage> BackupProtocolMoveObject::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 711 711 { 712 712 CHECK_PHASE(Phase_Commands) … … 737 737 738 738 // Return the object ID 739 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerSuccess(mObjectID));740 } 741 742 743 // -------------------------------------------------------------------------- 744 // 745 // Function 746 // Name: BackupProtocol ServerGetObjectName::DoCommand(BackupProtocolServer&, BackupStoreContext &)739 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); 740 } 741 742 743 // -------------------------------------------------------------------------- 744 // 745 // Function 746 // Name: BackupProtocolGetObjectName::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) 747 747 // Purpose: Command to find the name of an object 748 748 // Created: 12/11/03 749 749 // 750 750 // -------------------------------------------------------------------------- 751 std::auto_ptr< ProtocolObject> BackupProtocolServerGetObjectName::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)751 std::auto_ptr<BackupProtocolMessage> BackupProtocolGetObjectName::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 752 752 { 753 753 CHECK_PHASE(Phase_Commands) … … 772 772 if(!rContext.ObjectExists(dirID, BackupStoreContext::ObjectExists_Directory)) 773 773 { 774 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerObjectName(BackupProtocolServerObjectName::NumNameElements_ObjectDoesntExist, 0, 0, 0));774 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolObjectName(BackupProtocolObjectName::NumNameElements_ObjectDoesntExist, 0, 0, 0)); 775 775 } 776 776 … … 787 787 { 788 788 // Abort! 789 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerObjectName(BackupProtocolServerObjectName::NumNameElements_ObjectDoesntExist, 0, 0, 0));789 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolObjectName(BackupProtocolObjectName::NumNameElements_ObjectDoesntExist, 0, 0, 0)); 790 790 } 791 791 … … 827 827 828 828 // Make reply 829 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerObjectName(numNameElements, modTime, attrModHash, objectFlags));830 } 831 832 833 834 // -------------------------------------------------------------------------- 835 // 836 // Function 837 // Name: BackupProtocol ServerGetBlockIndexByID::DoCommand(BackupProtocolServer&, BackupStoreContext &)829 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolObjectName(numNameElements, modTime, attrModHash, objectFlags)); 830 } 831 832 833 834 // -------------------------------------------------------------------------- 835 // 836 // Function 837 // Name: BackupProtocolGetBlockIndexByID::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) 838 838 // Purpose: Get the block index from a file, by ID 839 839 // Created: 19/1/04 840 840 // 841 841 // -------------------------------------------------------------------------- 842 std::auto_ptr< ProtocolObject> BackupProtocolServerGetBlockIndexByID::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)842 std::auto_ptr<BackupProtocolMessage> BackupProtocolGetBlockIndexByID::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 843 843 { 844 844 CHECK_PHASE(Phase_Commands) … … 854 854 855 855 // Return the object ID 856 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerSuccess(mObjectID));857 } 858 859 860 // -------------------------------------------------------------------------- 861 // 862 // Function 863 // Name: BackupProtocol ServerGetBlockIndexByName::DoCommand(BackupProtocolServer&, BackupStoreContext &)856 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); 857 } 858 859 860 // -------------------------------------------------------------------------- 861 // 862 // Function 863 // Name: BackupProtocolGetBlockIndexByName::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) 864 864 // Purpose: Get the block index from a file, by name within a directory 865 865 // Created: 19/1/04 866 866 // 867 867 // -------------------------------------------------------------------------- 868 std::auto_ptr< ProtocolObject> BackupProtocolServerGetBlockIndexByName::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)868 std::auto_ptr<BackupProtocolMessage> BackupProtocolGetBlockIndexByName::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 869 869 { 870 870 CHECK_PHASE(Phase_Commands) … … 893 893 { 894 894 // No... return a zero object ID 895 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerSuccess(0));895 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(0)); 896 896 } 897 897 … … 906 906 907 907 // Return the object ID 908 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerSuccess(objectID));909 } 910 911 912 // -------------------------------------------------------------------------- 913 // 914 // Function 915 // Name: BackupProtocol ServerGetAccountUsage::DoCommand(BackupProtocolServer&, BackupStoreContext &)908 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(objectID)); 909 } 910 911 912 // -------------------------------------------------------------------------- 913 // 914 // Function 915 // Name: BackupProtocolGetAccountUsage::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) 916 916 // Purpose: Return the amount of disc space used 917 917 // Created: 19/4/04 918 918 // 919 919 // -------------------------------------------------------------------------- 920 std::auto_ptr< ProtocolObject> BackupProtocolServerGetAccountUsage::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)920 std::auto_ptr<BackupProtocolMessage> BackupProtocolGetAccountUsage::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 921 921 { 922 922 CHECK_PHASE(Phase_Commands) … … 930 930 931 931 // Return info 932 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerAccountUsage(932 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolAccountUsage( 933 933 rinfo.GetBlocksUsed(), 934 934 rinfo.GetBlocksInOldFiles(), … … 944 944 // 945 945 // Function 946 // Name: BackupProtocol ServerGetIsAlive::DoCommand(BackupProtocolServer&, BackupStoreContext &)946 // Name: BackupProtocolGetIsAlive::DoCommand(BackupProtocolReplyable &, BackupStoreContext &) 947 947 // Purpose: Return the amount of disc space used 948 948 // Created: 19/4/04 949 949 // 950 950 // -------------------------------------------------------------------------- 951 std::auto_ptr< ProtocolObject> BackupProtocolServerGetIsAlive::DoCommand(BackupProtocolServer &rProtocol, BackupStoreContext &rContext)951 std::auto_ptr<BackupProtocolMessage> BackupProtocolGetIsAlive::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const 952 952 { 953 953 CHECK_PHASE(Phase_Commands) … … 956 956 // NOOP 957 957 // 958 return std::auto_ptr< ProtocolObject>(new BackupProtocolServerIsAlive());959 } 958 return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolIsAlive()); 959 } -
box/trunk/lib/backupstore/BackupStoreContext.cpp
r2945 r2983 28 28 #include "StoreStructure.h" 29 29 30 class BackupStoreDaemon;31 32 30 #include "MemLeakFindOn.h" 31 33 32 34 33 // Maximum number of directories to keep in the cache -
box/trunk/lib/backupstore/BackupStoreContext.h
r2945 r2983 17 17 #include "BackupStoreRefCountDatabase.h" 18 18 #include "NamedLock.h" 19 #include " ProtocolObject.h"19 #include "Message.h" 20 20 #include "Utils.h" 21 21 22 22 class BackupStoreDirectory; 23 23 class BackupStoreFilename; 24 class BackupStoreDaemon;25 24 class BackupStoreInfo; 26 25 class IOStream; 27 class BackupProtocol Object;26 class BackupProtocolMessage; 28 27 class StreamableMemBlock; 29 28 … … 162 161 { 163 162 public: 164 virtual std::auto_ptr< ProtocolObject> StartCommand(BackupProtocolObject&165 rCommand) = 0;163 virtual std::auto_ptr<BackupProtocolMessage> 164 StartCommand(const BackupProtocolMessage& rCommand) = 0; 166 165 virtual ~TestHook() { } 167 166 }; … … 170 169 mpTestHook = &rTestHook; 171 170 } 172 std::auto_ptr<ProtocolObject> StartCommandHook(BackupProtocolObject& rCommand) 171 std::auto_ptr<BackupProtocolMessage> 172 StartCommandHook(const BackupProtocolMessage& rCommand) 173 173 { 174 174 if(mpTestHook) … … 176 176 return mpTestHook->StartCommand(rCommand); 177 177 } 178 return std::auto_ptr< ProtocolObject>();178 return std::auto_ptr<BackupProtocolMessage>(); 179 179 } 180 180 -
box/trunk/lib/backupstore/BackupStoreFile.h
r2945 r2983 19 19 #include "IOStream.h" 20 20 #include "ReadLoggingStream.h" 21 #include "RunStatusProvider.h"22 21 23 22 typedef struct … … 27 26 int64_t mTotalFileStreamSize; 28 27 } BackupStoreFileStats; 28 29 class RunStatusProvider; 29 30 30 31 // Uncomment to disable backwards compatibility -
box/trunk/lib/backupstore/Makefile.extra
r2945 r2983 1 2 1 MAKEPROTOCOL = ../../lib/server/makeprotocol.pl 3 2 4 GEN_CMD_CLI = $(MAKEPROTOCOL) Client backupprotocol.txt 5 GEN_CMD_SRV = $(MAKEPROTOCOL) Server backupprotocol.txt 3 GEN_CMD = $(MAKEPROTOCOL) backupprotocol.txt 6 4 7 5 # AUTOGEN SEEDING 8 autogen_BackupProtocol Client.cpp autogen_BackupProtocolClient.h: $(MAKEPROTOCOL) backupprotocol.txt9 $(_PERL) $(GEN_CMD _CLI)6 autogen_BackupProtocol.cpp autogen_BackupProtocol.h: $(MAKEPROTOCOL) backupprotocol.txt 7 $(_PERL) $(GEN_CMD) 10 8 11 # AUTOGEN SEEDING12 autogen_BackupProtocolServer.cpp autogen_BackupProtocolServer.h: $(MAKEPROTOCOL) backupprotocol.txt13 $(_PERL) $(GEN_CMD_SRV)14 9 15 10 MAKEEXCEPTION = ../../lib/common/makeexception.pl -
box/trunk/lib/backupstore/backupprotocol.txt
r2945 r2983 7 7 ServerContextClass BackupStoreContext BackupStoreContext.h 8 8 9 ClientType Filename BackupStoreFilenameClear BackupStoreFilenameClear.h 10 ServerType Filename BackupStoreFilename BackupStoreFilename.h 9 AddType Filename BackupStoreFilenameClear BackupStoreFilenameClear.h 11 10 12 11 ImplementLog Server syslog … … 14 13 ImplementLog Client file 15 14 16 LogTypeToText Client Filename \"%s\" VAR.GetClearFilename().c_str()15 LogTypeToText Filename "%s" VAR.GetClearFilenameIfPossible("OPAQUE").c_str() 17 16 18 17 BEGIN_OBJECTS -
box/trunk/lib/server/Message.cpp
r217 r2983 2 2 // 3 3 // File 4 // Name: ProtocolObject.h4 // Name: Message.h 5 5 // Purpose: Protocol object base class 6 6 // Created: 2003/08/19 … … 9 9 10 10 #include "Box.h" 11 #include " ProtocolObject.h"11 #include "Message.h" 12 12 #include "CommonException.h" 13 13 … … 17 17 // 18 18 // Function 19 // Name: ProtocolObject::ProtocolObject()19 // Name: Message::Message() 20 20 // Purpose: Default constructor 21 21 // Created: 2003/08/19 22 22 // 23 23 // -------------------------------------------------------------------------- 24 ProtocolObject::ProtocolObject()24 Message::Message() 25 25 { 26 26 } … … 29 29 // 30 30 // Function 31 // Name: ProtocolObject::ProtocolObject()31 // Name: Message::Message() 32 32 // Purpose: Destructor 33 33 // Created: 2003/08/19 34 34 // 35 35 // -------------------------------------------------------------------------- 36 ProtocolObject::~ProtocolObject()36 Message::~Message() 37 37 { 38 38 } … … 41 41 // 42 42 // Function 43 // Name: ProtocolObject::ProtocolObject()43 // Name: Message::Message() 44 44 // Purpose: Copy constructor 45 45 // Created: 2003/08/19 46 46 // 47 47 // -------------------------------------------------------------------------- 48 ProtocolObject::ProtocolObject(const ProtocolObject&rToCopy)48 Message::Message(const Message &rToCopy) 49 49 { 50 50 } … … 53 53 // 54 54 // Function 55 // Name: ProtocolObject::IsError(int &, int &)55 // Name: Message::IsError(int &, int &) 56 56 // Purpose: Does this represent an error, and if so, what is the type and subtype? 57 57 // Created: 2003/08/19 58 58 // 59 59 // -------------------------------------------------------------------------- 60 bool ProtocolObject::IsError(int &rTypeOut, int &rSubTypeOut) const60 bool Message::IsError(int &rTypeOut, int &rSubTypeOut) const 61 61 { 62 62 return false; … … 66 66 // 67 67 // Function 68 // Name: ProtocolObject::IsConversationEnd()68 // Name: Message::IsConversationEnd() 69 69 // Purpose: Does this command end the conversation? 70 70 // Created: 2003/08/19 71 71 // 72 72 // -------------------------------------------------------------------------- 73 bool ProtocolObject::IsConversationEnd() const73 bool Message::IsConversationEnd() const 74 74 { 75 75 return false; … … 80 80 // 81 81 // Function 82 // Name: ProtocolObject::GetType()82 // Name: Message::GetType() 83 83 // Purpose: Return type of the object 84 84 // Created: 2003/08/19 85 85 // 86 86 // -------------------------------------------------------------------------- 87 int ProtocolObject::GetType() const87 int Message::GetType() const 88 88 { 89 89 // This isn't implemented in the base class! … … 95 95 // 96 96 // Function 97 // Name: ProtocolObject::SetPropertiesFromStreamData(Protocol &)97 // Name: Message::SetPropertiesFromStreamData(Protocol &) 98 98 // Purpose: Set the properties of the object from the stream data ready in the Protocol object 99 99 // Created: 2003/08/19 100 100 // 101 101 // -------------------------------------------------------------------------- 102 void ProtocolObject::SetPropertiesFromStreamData(Protocol &rProtocol)102 void Message::SetPropertiesFromStreamData(Protocol &rProtocol) 103 103 { 104 104 // This isn't implemented in the base class! … … 111 111 // 112 112 // Function 113 // Name: ProtocolObject::WritePropertiesToStreamData(Protocol &)113 // Name: Message::WritePropertiesToStreamData(Protocol &) 114 114 // Purpose: Write the properties of the object into the stream data in the Protocol object 115 115 // Created: 2003/08/19 116 116 // 117 117 // -------------------------------------------------------------------------- 118 void ProtocolObject::WritePropertiesToStreamData(Protocol &rProtocol) const118 void Message::WritePropertiesToStreamData(Protocol &rProtocol) const 119 119 { 120 120 // This isn't implemented in the base class! -
box/trunk/lib/server/Message.h
r217 r2983 2 2 // 3 3 // File 4 // Name: ProtocolObject.h4 // Name: Message.h 5 5 // Purpose: Protocol object base class 6 6 // Created: 2003/08/19 … … 11 11 #define PROTOCOLOBJECT__H 12 12 13 #include <memory> 14 13 15 class Protocol; 16 class ProtocolContext; 14 17 15 18 // -------------------------------------------------------------------------- 16 19 // 17 20 // Class 18 // Name: ProtocolObject21 // Name: Message 19 22 // Purpose: Basic object representation of objects to pass through a Protocol session 20 23 // Created: 2003/08/19 21 24 // 22 25 // -------------------------------------------------------------------------- 23 class ProtocolObject26 class Message 24 27 { 25 28 public: 26 ProtocolObject();27 virtual ~ ProtocolObject();28 ProtocolObject(const ProtocolObject&rToCopy);29 Message(); 30 virtual ~Message(); 31 Message(const Message &rToCopy); 29 32 30 33 // Info about this object … … 36 39 virtual void SetPropertiesFromStreamData(Protocol &rProtocol); 37 40 virtual void WritePropertiesToStreamData(Protocol &rProtocol) const; 41 42 virtual void LogSysLog(const char *Action) const { } 43 virtual void LogFile(const char *Action, FILE *file) const { } 38 44 }; 45 46 /* 47 class Reply; 48 49 class Request : public Message 50 { 51 public: 52 Request() { } 53 virtual ~Request() { } 54 Request(const Request &rToCopy) { } 55 virtual std::auto_ptr<Reply> DoCommand(Protocol &rProtocol, 56 ProtocolContext &rContext) = 0; 57 }; 58 59 class Reply : public Message 60 { 61 public: 62 Reply() { } 63 virtual ~Reply() { } 64 Reply(const Reply &rToCopy) { } 65 }; 66 */ 39 67 40 68 #endif // PROTOCOLOBJECT__H -
box/trunk/lib/server/Protocol.cpp
r2415 r2983 12 12 #include <sys/types.h> 13 13 14 #include <stdlib.h> 15 #include <string.h> 14 #include <cstdlib> 15 #include <cstring> 16 #include <cstdio> 16 17 17 18 #include <new> … … 45 46 // -------------------------------------------------------------------------- 46 47 Protocol::Protocol(IOStream &rStream) 47 : mrStream(rStream),48 mHandshakeDone(false),49 mMaxObjectSize(PROTOCOL_DEFAULT_MAXOBJSIZE),50 mTimeout(PROTOCOL_DEFAULT_TIMEOUT),51 mpBuffer(0),52 mBufferSize(0),53 mReadOffset(-1),54 mWriteOffset(-1),55 mValidDataSize(-1),56 mLastErrorType(NoError),57 mLastErrorSubType(NoError) 48 : mrStream(rStream), 49 mHandshakeDone(false), 50 mMaxObjectSize(PROTOCOL_DEFAULT_MAXOBJSIZE), 51 mTimeout(PROTOCOL_DEFAULT_TIMEOUT), 52 mpBuffer(0), 53 mBufferSize(0), 54 mReadOffset(-1), 55 mWriteOffset(-1), 56 mValidDataSize(-1), 57 mLogToSysLog(false), 58 mLogToFile(NULL) 58 59 { 59 60 BOX_TRACE("Send block allocation size is " << … … 77 78 mpBuffer = 0; 78 79 } 79 }80 81 82 // --------------------------------------------------------------------------83 //84 // Function85 // Name: Protocol::GetLastError(int &, int &)86 // Purpose: Returns true if there was an error, and type and subtype if there was.87 // Created: 2003/08/1988 //89 // --------------------------------------------------------------------------90 bool Protocol::GetLastError(int &rTypeOut, int &rSubTypeOut)91 {92 if(mLastErrorType == NoError)93 {94 // no error.95 return false;96 }97 98 // Return type and subtype in args99 rTypeOut = mLastErrorType;100 rSubTypeOut = mLastErrorSubType;101 102 // and unset them103 mLastErrorType = NoError;104 mLastErrorSubType = NoError;105 106 return true;107 80 } 108 81 … … 128 101 ::memset(&hsSend, 0, sizeof(hsSend)); 129 102 // Copy in ident string 130 ::strncpy(hsSend.mIdent, Get IdentString(), sizeof(hsSend.mIdent));103 ::strncpy(hsSend.mIdent, GetProtocolIdentString(), sizeof(hsSend.mIdent)); 131 104 132 105 // Send it … … 201 174 // 202 175 // -------------------------------------------------------------------------- 203 std::auto_ptr< ProtocolObject> Protocol::Receive()176 std::auto_ptr<Message> Protocol::ReceiveInternal() 204 177 { 205 178 // Get object header … … 221 194 222 195 // Create a blank object 223 std::auto_ptr< ProtocolObject> obj(MakeProtocolObject(ntohl(objHeader.mObjType)));196 std::auto_ptr<Message> obj(MakeMessage(ntohl(objHeader.mObjType))); 224 197 225 198 // Make sure memory is allocated to read it into … … 273 246 // 274 247 // -------------------------------------------------------------------------- 275 void Protocol::Send (const ProtocolObject&rObject)248 void Protocol::SendInternal(const Message &rObject) 276 249 { 277 250 // Check usage … … 855 828 void Protocol::InformStreamReceiving(u_int32_t Size) 856 829 { 857 // Do nothing 830 if(GetLogToSysLog()) 831 { 832 if(Size == Protocol::ProtocolStream_SizeUncertain) 833 { 834 BOX_TRACE("Receiving stream, size uncertain"); 835 } 836 else 837 { 838 BOX_TRACE("Receiving stream, size " << Size); 839 } 840 } 841 842 if(GetLogToFile()) 843 { 844 ::fprintf(GetLogToFile(), 845 (Size == Protocol::ProtocolStream_SizeUncertain) 846 ? "Receiving stream, size uncertain\n" 847 : "Receiving stream, size %d\n", Size); 848 ::fflush(GetLogToFile()); 849 } 858 850 } 859 851 … … 868 860 void Protocol::InformStreamSending(u_int32_t Size) 869 861 { 870 // Do nothing 862 if(GetLogToSysLog()) 863 { 864 if(Size == Protocol::ProtocolStream_SizeUncertain) 865 { 866 BOX_TRACE("Sending stream, size uncertain"); 867 } 868 else 869 { 870 BOX_TRACE("Sending stream, size " << Size); 871 } 872 } 873 874 if(GetLogToFile()) 875 { 876 ::fprintf(GetLogToFile(), 877 (Size == Protocol::ProtocolStream_SizeUncertain) 878 ? "Sending stream, size uncertain\n" 879 : "Sending stream, size %d\n", Size); 880 ::fflush(GetLogToFile()); 881 } 871 882 } 872 883 -
box/trunk/lib/server/Protocol.h
r217 r2983 13 13 #include <sys/types.h> 14 14 15 class IOStream;16 #include "ProtocolObject.h"17 15 #include <memory> 18 16 #include <vector> 19 17 #include <string> 18 19 #include "Message.h" 20 21 class IOStream; 20 22 21 23 // default timeout is 15 minutes … … 41 43 Protocol(const Protocol &rToCopy); 42 44 45 protected: 46 // Unsafe to make public, as they may allow sending objects 47 // from a different protocol. The derived class prevents this. 48 std::auto_ptr<Message> ReceiveInternal(); 49 void SendInternal(const Message &rObject); 50 43 51 public: 44 52 void Handshake(); 45 std::auto_ptr<ProtocolObject> Receive();46 void Send(const ProtocolObject &rObject);47 48 53 std::auto_ptr<IOStream> ReceiveStream(); 49 54 void SendStream(IOStream &rStream); … … 55 60 }; 56 61 57 bool GetLastError(int &rTypeOut, int &rSubTypeOut);58 59 62 // -------------------------------------------------------------------------- 60 63 // … … 88 91 void SetMaxObjectSize(unsigned int NewMaxObjSize) {mMaxObjectSize = NewMaxObjSize;} 89 92 90 // For ProtocolObjectderived classes93 // For Message derived classes 91 94 void Read(void *Buffer, int Size); 92 95 void Read(std::string &rOut, int Size); … … 169 172 ProtocolStream_SizeUncertain = 0xffffffff 170 173 }; 171 172 protected: 173 virtual std::auto_ptr<ProtocolObject> MakeProtocolObject(int ObjType) = 0; 174 virtual const char *GetIdentString() = 0; 175 void SetError(int Type, int SubType) {mLastErrorType = Type; mLastErrorSubType = SubType;} 174 bool GetLogToSysLog() { return mLogToSysLog; } 175 FILE *GetLogToFile() { return mLogToFile; } 176 void SetLogToSysLog(bool Log = false) {mLogToSysLog = Log;} 177 void SetLogToFile(FILE *File = 0) {mLogToFile = File;} 178 179 protected: 180 virtual std::auto_ptr<Message> MakeMessage(int ObjType) = 0; 181 virtual const char *GetProtocolIdentString() = 0; 182 176 183 void CheckAndReadHdr(void *hdr); // don't use type here to avoid dependency 177 184 … … 184 191 int SendStreamSendBlock(uint8_t *Block, int BytesInBlock); 185 192 186 private:187 193 IOStream &mrStream; 188 194 bool mHandshakeDone; … … 194 200 int mWriteOffset; 195 201 int mValidDataSize; 196 int mLastErrorType;197 int mLastErrorSubType;202 bool mLogToSysLog; 203 FILE *mLogToFile; 198 204 }; 199 205 206 class ProtocolContext 207 { 208 }; 209 200 210 #endif // PROTOCOL__H 201 211 -
box/trunk/lib/server/makeprotocol.pl.in
r2371 r2983 31 31 ); 32 32 33 34 35 my ($type, $file) = @ARGV; 36 37 if($type ne 'Server' && $type ne 'Client') 38 { 39 die "Neither Server or Client is specified on command line\n"; 40 } 33 if (@ARGV != 1) 34 { 35 die "Usage: $0 <protocol-txt-file>\n"; 36 } 37 38 my ($file) = @ARGV; 41 39 42 40 open IN, $file or die "Can't open input file $file\n"; 43 41 44 print "Making $typeprotocol classes from $file...\n";42 print "Making protocol classes from $file...\n"; 45 43 46 44 my @extra_header_files; 47 48 my $implement_syslog = 0;49 my $implement_filelog = 0;50 45 51 46 # read attributes … … 60 55 my ($k,$v) = split /\s+/,$l,2; 61 56 62 if($k eq 'ClientType') 63 { 64 add_type($v) if $type eq 'Client'; 65 } 66 elsif($k eq 'ServerType') 67 { 68 add_type($v) if $type eq 'Server'; 57 if($k eq 'AddType') 58 { 59 add_type($v); 69 60 } 70 61 elsif($k eq 'ImplementLog') 71 62 { 72 my ($log_if_type,$log_type) = split /\s+/,$v; 73 if($type eq $log_if_type) 74 { 75 if($log_type eq 'syslog') 76 { 77 $implement_syslog = 1; 78 } 79 elsif($log_type eq 'file') 80 { 81 $implement_filelog = 1; 82 } 83 else 84 { 85 printf("ERROR: Unknown log type for implementation: $log_type\n"); 86 exit(1); 87 } 88 } 63 # Always implement logging 89 64 } 90 65 elsif($k eq 'LogTypeToText') 91 66 { 92 my ($log_if_type,$type_name,$printf_format,$arg_template) = split /\s+/,$v; 93 if($type eq $log_if_type) 94 { 95 $log_display_types{$type_name} = [$printf_format,$arg_template] 96 } 67 my ($type_name,$printf_format,$arg_template) = split /\s+/,$v; 68 $log_display_types{$type_name} = [$printf_format,$arg_template] 97 69 } 98 70 else … … 170 142 171 143 # open files 172 my $h_filename = 'autogen_'.$protocol_name.'Protocol '.$type.'.h';173 open CPP,'>autogen_'.$protocol_name.'Protocol '.$type.'.cpp';144 my $h_filename = 'autogen_'.$protocol_name.'Protocol.h'; 145 open CPP,'>autogen_'.$protocol_name.'Protocol.cpp'; 174 146 open H,">$h_filename"; 147 148 my $guardname = uc 'AUTOGEN_'.$protocol_name.'Protocol_H'; 175 149 176 150 print CPP <<__E; … … 184 158 #include "$h_filename" 185 159 #include "IOStream.h" 186 187 __E 188 189 if($implement_syslog) 190 { 191 print H <<EOF; 160 __E 161 162 print H <<__E; 163 // Auto-generated file -- do not edit 164 165 #ifndef $guardname 166 #define $guardname 167 168 #include <cstdio> 169 #include <list> 170 192 171 #ifndef WIN32 193 172 #include <syslog.h> 194 173 #endif 195 EOF196 }197 198 199 my $guardname = uc 'AUTOGEN_'.$protocol_name.'Protocol'.$type.'_H';200 print H <<__E;201 202 // Auto-generated file -- do not edit203 204 #ifndef $guardname205 #define $guardname206 174 207 175 #include "Protocol.h" 208 #include " ProtocolObject.h"176 #include "Message.h" 209 177 #include "ServerException.h" 210 178 211 179 class IOStream; 212 180 213 __E 214 215 if($implement_filelog) 216 { 217 print H qq~#include <stdio.h>\n~; 218 } 181 182 __E 219 183 220 184 # extra headers 221 185 for(@extra_header_files) 222 186 { 223 print H qq~#include "$_"\n~ 224 } 225 print H "\n"; 226 227 if($type eq 'Server') 228 { 229 # need utils file for the server 230 print H '#include "Utils.h"',"\n\n" 231 } 232 233 234 my $derive_objects_from = 'ProtocolObject'; 187 print H qq@#include "$_"\n@; 188 } 189 190 print H <<__E; 191 192 // need utils file for the server 193 #include "Utils.h" 194 195 __E 196 197 my $message_base_class = "${protocol_name}ProtocolMessage"; 235 198 my $objects_extra_h = ''; 236 199 my $objects_extra_cpp = ''; 237 if($type eq 'Server') 238 { 239 # define the context 240 print H "class $context_class;\n\n"; 241 print CPP "#include \"$context_class_inc\"\n\n"; 242 243 # change class we derive the objects from 244 $derive_objects_from = $protocol_name.'ProtocolObject'; 245 246 $objects_extra_h = <<__E; 247 virtual std::auto_ptr<ProtocolObject> DoCommand(${protocol_name}ProtocolServer &rProtocol, $context_class &rContext); 248 __E 249 $objects_extra_cpp = <<__E; 250 std::auto_ptr<ProtocolObject> ${derive_objects_from}::DoCommand(${protocol_name}ProtocolServer &rProtocol, $context_class &rContext) 200 201 # define the context 202 print H "class $context_class;\n\n"; 203 print CPP <<__E; 204 #include "$context_class_inc" 205 #include "MemLeakFindOn.h" 206 __E 207 208 my $request_base_class = "${protocol_name}ProtocolRequest"; 209 my $reply_base_class = "${protocol_name}ProtocolReply"; 210 # the abstract protocol interface 211 my $protocol_base_class = $protocol_name."ProtocolBase"; 212 my $replyable_base_class = $protocol_name."ProtocolReplyable"; 213 214 print H <<__E; 215 class $protocol_base_class; 216 class $replyable_base_class; 217 class $reply_base_class; 218 219 class $message_base_class : public Message 220 { 221 public: 222 virtual std::auto_ptr<$message_base_class> DoCommand($replyable_base_class &rProtocol, 223 $context_class &rContext) const; 224 }; 225 226 class $reply_base_class 227 { 228 }; 229 230 class $request_base_class 231 { 232 }; 233 234 __E 235 236 print CPP <<__E; 237 std::auto_ptr<$message_base_class> $message_base_class\::DoCommand($replyable_base_class &rProtocol, 238 $context_class &rContext) const 251 239 { 252 240 THROW_EXCEPTION(ConnectionException, Conn_Protocol_TriedToExecuteReplyCommand) 253 241 } 254 242 __E 255 } 256 257 print CPP qq~#include "MemLeakFindOn.h"\n~; 258 259 if($type eq 'Client' && ($implement_syslog || $implement_filelog)) 260 { 261 # change class we derive the objects from 262 $derive_objects_from = $protocol_name.'ProtocolObjectCl'; 263 } 264 if($implement_syslog) 265 { 266 $objects_extra_h .= <<__E; 267 virtual void LogSysLog(const char *Action) const = 0; 268 __E 269 } 270 if($implement_filelog) 271 { 272 $objects_extra_h .= <<__E; 273 virtual void LogFile(const char *Action, FILE *file) const = 0; 274 __E 275 } 276 277 if($derive_objects_from ne 'ProtocolObject') 278 { 279 # output a definition for the protocol object derived class 243 244 my %cmd_class; 245 246 # output the classes 247 foreach my $cmd (@cmd_list) 248 { 249 my @cmd_base_classes = ($message_base_class); 250 251 if(obj_is_type($cmd, 'Command')) 252 { 253 push @cmd_base_classes, $request_base_class; 254 } 255 256 if(obj_is_type($cmd, 'Reply')) 257 { 258 push @cmd_base_classes, $reply_base_class; 259 } 260 261 my $cmd_base_class = join(", ", map {"public $_"} @cmd_base_classes); 262 my $cmd_class = $protocol_name."ProtocolClient".$cmd; 263 $cmd_class{$cmd} = $cmd_class; 264 280 265 print H <<__E; 281 class ${protocol_name}ProtocolServer; 282 283 class $derive_objects_from : public ProtocolObject 266 class $cmd_class : $cmd_base_class 284 267 { 285 268 public: 286 $derive_objects_from(); 287 virtual ~$derive_objects_from(); 288 $derive_objects_from(const $derive_objects_from &rToCopy); 289 290 $objects_extra_h 291 }; 292 __E 293 294 # and some cpp definitions 295 print CPP <<__E; 296 ${derive_objects_from}::${derive_objects_from}() 297 { 298 } 299 ${derive_objects_from}::~${derive_objects_from}() 300 { 301 } 302 ${derive_objects_from}::${derive_objects_from}(const $derive_objects_from &rToCopy) 303 { 304 } 305 $objects_extra_cpp 306 __E 307 } 308 309 310 311 my $classname_base = $protocol_name.'Protocol'.$type; 312 313 # output the classes 314 for my $cmd (@cmd_list) 315 { 316 print H <<__E; 317 class $classname_base$cmd : public $derive_objects_from 318 { 319 public: 320 $classname_base$cmd(); 321 $classname_base$cmd(const $classname_base$cmd &rToCopy); 322 ~$classname_base$cmd(); 269 $cmd_class(); 270 $cmd_class(const $cmd_class &rToCopy); 271 ~$cmd_class(); 323 272 int GetType() const; 324 273 enum … … 327 276 }; 328 277 __E 278 329 279 # constants 330 280 if(exists $cmd_constants{$cmd}) … … 334 284 print H "\n\t};\n"; 335 285 } 286 336 287 # flags 337 288 if(obj_is_type($cmd,'EndsConversation')) … … 339 290 print H "\tbool IsConversationEnd() const;\n"; 340 291 } 292 341 293 if(obj_is_type($cmd,'IsError')) 342 294 { … … 344 296 print H "\tstd::string GetMessage() const;\n"; 345 297 } 346 if($type eq 'Server' && obj_is_type($cmd, 'Command')) 347 { 348 print H "\tstd::auto_ptr<ProtocolObject> DoCommand(${protocol_name}ProtocolServer &rProtocol, $context_class &rContext); // IMPLEMENT THIS\n" 298 299 if(obj_is_type($cmd, 'Command')) 300 { 301 print H <<__E; 302 std::auto_ptr<$message_base_class> DoCommand($replyable_base_class &rProtocol, 303 $context_class &rContext) const; // IMPLEMENT THIS\n 304 __E 349 305 } 350 306 351 307 # want to be able to read from streams? 352 my $read_from_streams = (obj_is_type($cmd,'Command') && $type eq 'Server') || (obj_is_type($cmd,'Reply') && $type eq 'Client');353 my $write_to_streams = (obj_is_type($cmd,'Command') && $type eq 'Client') || (obj_is_type($cmd,'Reply') && $type eq 'Server');354 355 if($read_from_streams)356 { 357 print H "\tvoid SetPropertiesFromStreamData(Protocol &rProtocol);\n";308 print H "\tvoid SetPropertiesFromStreamData(Protocol &rProtocol);\n"; 309 310 # write Get functions 311 for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) 312 { 313 my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); 358 314 359 # write Get functions 315 print H "\t".translate_type_to_arg_type($ty)." Get$nm() {return m$nm;}\n"; 316 } 317 318 my $param_con_args = ''; 319 # extra constructor? 320 if($#{$cmd_contents{$cmd}} >= 0) 321 { 322 my @a; 360 323 for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) 361 324 { 362 325 my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); 363 364 print H "\t".translate_type_to_arg_type($ty)." Get$nm() {return m$nm;}\n"; 365 } 366 } 367 my $param_con_args = ''; 368 if($write_to_streams) 369 { 370 # extra constructor? 371 if($#{$cmd_contents{$cmd}} >= 0) 372 { 373 my @a; 374 for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) 375 { 376 my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); 377 378 push @a,translate_type_to_arg_type($ty)." $nm"; 379 } 380 $param_con_args = join(', ',@a); 381 print H "\t$classname_base$cmd(".$param_con_args.");\n"; 382 } 383 print H "\tvoid WritePropertiesToStreamData(Protocol &rProtocol) const;\n"; 384 # set functions 385 for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) 386 { 387 my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); 388 389 print H "\tvoid Set$nm(".translate_type_to_arg_type($ty)." $nm) {m$nm = $nm;}\n"; 390 } 391 } 392 393 if($implement_syslog) 394 { 395 print H "\tvirtual void LogSysLog(const char *Action) const;\n"; 396 } 397 if($implement_filelog) 398 { 399 print H "\tvirtual void LogFile(const char *Action, FILE *file) const;\n"; 400 } 401 326 327 push @a,translate_type_to_arg_type($ty)." $nm"; 328 } 329 $param_con_args = join(', ',@a); 330 print H "\t$cmd_class(".$param_con_args.");\n"; 331 } 332 print H "\tvoid WritePropertiesToStreamData(Protocol &rProtocol) const;\n"; 333 # set functions 334 for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) 335 { 336 my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); 337 338 print H "\tvoid Set$nm(".translate_type_to_arg_type($ty)." $nm) {m$nm = $nm;}\n"; 339 } 340 341 print H "\tvirtual void LogSysLog(const char *Action) const;\n"; 342 print H "\tvirtual void LogFile(const char *Action, FILE *file) const;\n"; 402 343 403 344 # write member variables and setup for cpp file … … 433 374 $param_con_vars = "\n\t: ".$param_con_vars if $param_con_vars ne ''; 434 375 435 my $class = "$classname_base$cmd".'::';436 376 print CPP <<__E; 437 $c lass$classname_base$cmd()$def_con_vars438 { 439 } 440 $c lass$classname_base$cmd(const $classname_base$cmd&rToCopy)$copy_con_vars441 { 442 } 443 $c lass~$classname_base$cmd()444 { 445 } 446 int $ {class}GetType() const377 $cmd_class\::$cmd_class()$def_con_vars 378 { 379 } 380 $cmd_class\::$cmd_class(const $cmd_class &rToCopy)$copy_con_vars 381 { 382 } 383 $cmd_class\::~$cmd_class() 384 { 385 } 386 int $cmd_class\::GetType() const 447 387 { 448 388 return $cmd_id{$cmd}; 449 389 } 450 390 __E 451 if($read_from_streams) 452 { 453 print CPP "void ${class}SetPropertiesFromStreamData(Protocol &rProtocol)\n{\n"; 454 for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) 455 { 456 my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); 457 if($ty =~ m/\Avector/) 458 { 459 print CPP "\trProtocol.ReadVector(m$nm);\n"; 460 } 461 else 462 { 463 print CPP "\trProtocol.Read(m$nm);\n"; 464 } 465 } 466 print CPP "}\n"; 467 } 468 if($write_to_streams) 469 { 470 # implement extra constructor? 471 if($param_con_vars ne '') 472 { 473 print CPP "$class$classname_base$cmd($param_con_args)$param_con_vars\n{\n}\n"; 474 } 475 print CPP "void ${class}WritePropertiesToStreamData(Protocol &rProtocol) const\n{\n"; 476 for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) 477 { 478 my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); 479 if($ty =~ m/\Avector/) 480 { 481 print CPP "\trProtocol.WriteVector(m$nm);\n"; 482 } 483 else 484 { 485 print CPP "\trProtocol.Write(m$nm);\n"; 486 } 487 } 488 print CPP "}\n"; 489 } 391 print CPP "void $cmd_class\::SetPropertiesFromStreamData(Protocol &rProtocol)\n{\n"; 392 for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) 393 { 394 my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); 395 if($ty =~ m/\Avector/) 396 { 397 print CPP "\trProtocol.ReadVector(m$nm);\n"; 398 } 399 else 400 { 401 print CPP "\trProtocol.Read(m$nm);\n"; 402 } 403 } 404 print CPP "}\n"; 405 406 # implement extra constructor? 407 if($param_con_vars ne '') 408 { 409 print CPP "$cmd_class\::$cmd_class($param_con_args)$param_con_vars\n{\n}\n"; 410 } 411 print CPP "void $cmd_class\::WritePropertiesToStreamData(Protocol &rProtocol) const\n{\n"; 412 for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) 413 { 414 my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); 415 if($ty =~ m/\Avector/) 416 { 417 print CPP "\trProtocol.WriteVector(m$nm);\n"; 418 } 419 else 420 { 421 print CPP "\trProtocol.Write(m$nm);\n"; 422 } 423 } 424 print CPP "}\n"; 425 490 426 if(obj_is_type($cmd,'EndsConversation')) 491 427 { 492 print CPP "bool ${class}IsConversationEnd() const\n{\n\treturn true;\n}\n"; 493 } 428 print CPP "bool $cmd_class\::IsConversationEnd() const\n{\n\treturn true;\n}\n"; 429 } 430 494 431 if(obj_is_type($cmd,'IsError')) 495 432 { … … 497 434 my ($mem_type,$mem_subtype) = split /,/,obj_get_type_params($cmd,'IsError'); 498 435 print CPP <<__E; 499 bool $ {class}IsError(int &rTypeOut, int &rSubTypeOut) const436 bool $cmd_class\::IsError(int &rTypeOut, int &rSubTypeOut) const 500 437 { 501 438 rTypeOut = m$mem_type; … … 503 440 return true; 504 441 } 505 std::string $ {class}GetMessage() const442 std::string $cmd_class\::GetMessage() const 506 443 { 507 444 switch(m$mem_subtype) … … 527 464 } 528 465 529 if($implement_syslog) 530 { 531 my ($log) = make_log_strings_framework($cmd); 532 print CPP <<__E; 533 void ${class}LogSysLog(const char *Action) const 466 my ($log) = make_log_strings_framework($cmd); 467 print CPP <<__E; 468 void $cmd_class\::LogSysLog(const char *Action) const 534 469 { 535 470 BOX_TRACE($log); 536 471 } 537 __E 538 } 539 if($implement_filelog) 540 { 541 my ($log) = make_log_strings_framework($cmd); 542 print CPP <<__E; 543 void ${class}LogFile(const char *Action, FILE *File) const 472 void $cmd_class\::LogFile(const char *Action, FILE *File) const 544 473 { 545 474 std::ostringstream oss; … … 549 478 } 550 479 __E 551 } 552 } 553 554 # finally, the protocol object itself 480 } 481 482 my $error_class = $protocol_name."ProtocolError"; 483 484 # the abstract protocol interface 555 485 print H <<__E; 556 class $ classname_base : public Protocol486 class $protocol_base_class 557 487 { 558 488 public: 559 $classname_base(IOStream &rStream); 560 virtual ~$classname_base(); 561 562 std::auto_ptr<$derive_objects_from> Receive(); 563 void Send(const ${derive_objects_from} &rObject); 564 __E 565 if($implement_syslog) 566 { 567 print H "\tvoid SetLogToSysLog(bool Log = false) {mLogToSysLog = Log;}\n"; 568 } 569 if($implement_filelog) 570 { 571 print H "\tvoid SetLogToFile(FILE *File = 0) {mLogToFile = File;}\n"; 572 } 573 if($type eq 'Server') 574 { 575 # need to put in the conversation function 576 print H "\tvoid DoServer($context_class &rContext);\n\n"; 577 # and the send vector thing 578 print H "\tvoid SendStreamAfterCommand(IOStream *pStream);\n\n"; 579 } 580 if($type eq 'Client') 581 { 582 # add plain object taking query functions 583 my $with_params; 489 $protocol_base_class(); 490 virtual ~$protocol_base_class(); 491 virtual const char *GetIdentString(); 492 bool GetLastError(int &rTypeOut, int &rSubTypeOut); 493 494 protected: 495 void CheckReply(const std::string& requestCommand, 496 const $message_base_class &rReply, int expectedType); 497 void SetLastError(int Type, int SubType) 498 { 499 mLastErrorType = Type; 500 mLastErrorSubType = SubType; 501 } 502 503 private: 504 $protocol_base_class(const $protocol_base_class &rToCopy); /* do not call */ 505 int mLastErrorType; 506 int mLastErrorSubType; 507 }; 508 509 class $replyable_base_class : public virtual $protocol_base_class 510 { 511 public: 512 $replyable_base_class(); 513 virtual ~$replyable_base_class(); 514 515 /* 516 virtual std::auto_ptr<$message_base_class> Receive() = 0; 517 virtual void Send(const ${message_base_class} &rObject) = 0; 518 */ 519 520 virtual std::auto_ptr<IOStream> ReceiveStream() = 0; 521 virtual int GetTimeout() = 0; 522 void SendStreamAfterCommand(IOStream *pStream); 523 524 protected: 525 std::list<IOStream*> mStreamsToSend; 526 void DeleteStreamsToSend(); 527 528 private: 529 $replyable_base_class(const $replyable_base_class &rToCopy); /* do not call */ 530 }; 531 532 __E 533 534 print CPP <<__E; 535 $protocol_base_class\::$protocol_base_class() 536 : mLastErrorType(Protocol::NoError), 537 mLastErrorSubType(Protocol::NoError) 538 { } 539 540 $protocol_base_class\::~$protocol_base_class() 541 { } 542 543 const char *$protocol_base_class\::GetIdentString() 544 { 545 return "$ident_string"; 546 } 547 548 $replyable_base_class\::$replyable_base_class() 549 { } 550 551 $replyable_base_class\::~$replyable_base_class() 552 { } 553 554 void $replyable_base_class\::SendStreamAfterCommand(IOStream *pStream) 555 { 556 ASSERT(pStream != NULL); 557 mStreamsToSend.push_back(pStream); 558 } 559 560 void $replyable_base_class\::DeleteStreamsToSend() 561 { 562 for(std::list<IOStream*>::iterator i(mStreamsToSend.begin()); i != mStreamsToSend.end(); ++i) 563 { 564 delete (*i); 565 } 566 mStreamsToSend.clear(); 567 } 568 569 void $protocol_base_class\::CheckReply(const std::string& requestCommand, 570 const $message_base_class &rReply, int expectedType) 571 { 572 if(rReply.GetType() == expectedType) 573 { 574 // Correct response, do nothing 575 } 576 else 577 { 578 // Set protocol error 579 int type, subType; 580 581 if(rReply.IsError(type, subType)) 582 { 583 SetLastError(type, subType); 584 BOX_WARNING(requestCommand << " command failed: " 585 "received error " << 586 (($error_class&)rReply).GetMessage()); 587 } 588 else 589 { 590 SetLastError(Protocol::UnknownError, Protocol::UnknownError); 591 BOX_WARNING(requestCommand << " command failed: " 592 "received unexpected response type " << 593 rReply.GetType()); 594 } 595 596 // Throw an exception 597 THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnexpectedReply) 598 } 599 } 600 601 // -------------------------------------------------------------------------- 602 // 603 // Function 604 // Name: Protocol::GetLastError(int &, int &) 605 // Purpose: Returns true if there was an error, and type and subtype if there was. 606 // Created: 2003/08/19 607 // 608 // -------------------------------------------------------------------------- 609 bool $protocol_base_class\::GetLastError(int &rTypeOut, int &rSubTypeOut) 610 { 611 if(mLastErrorType == Protocol::NoError) 612 { 613 // no error. 614 return false; 615 } 616 617 // Return type and subtype in args 618 rTypeOut = mLastErrorType; 619 rSubTypeOut = mLastErrorSubType; 620 621 // and unset them 622 mLastErrorType = Protocol::NoError; 623 mLastErrorSubType = Protocol::NoError; 624 625 return true; 626 } 627 628 __E 629 630 # the callable protocol interface (implemented by Client and Local classes) 631 # with Query methods that don't take a context parameter 632 my $callable_base_class = $protocol_name."ProtocolCallable"; 633 print H <<__E; 634 class $callable_base_class : public virtual $protocol_base_class 635 { 636 public: 637 virtual std::auto_ptr<IOStream> ReceiveStream() = 0; 638 virtual int GetTimeout() = 0; 639 __E 640 641 # add plain object taking query functions 642 my $with_params; 643 for my $cmd (@cmd_list) 644 { 645 if(obj_is_type($cmd,'Command')) 646 { 647 my $has_stream = obj_is_type($cmd,'StreamWithCommand'); 648 my $argextra = $has_stream?', IOStream &rStream':''; 649 my $queryextra = $has_stream?', rStream':''; 650 my $request_class = $cmd_class{$cmd}; 651 my $reply_class = $cmd_class{obj_get_type_params($cmd,'Command')}; 652 653 print H "\tvirtual std::auto_ptr<$reply_class> Query(const $request_class &rQuery$argextra) = 0;\n"; 654 my @a; 655 my @na; 656 for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) 657 { 658 my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); 659 push @a,translate_type_to_arg_type($ty)." $nm"; 660 push @na,"$nm"; 661 } 662 my $ar = join(', ',@a); 663 my $nar = join(', ',@na); 664 $nar = "($nar)" if $nar ne ''; 665 666 $with_params .= <<__E; 667 inline std::auto_ptr<$reply_class> Query$cmd($ar$argextra) 668 { 669 $request_class send$nar; 670 return Query(send$queryextra); 671 } 672 __E 673 } 674 } 675 676 # quick hack to correct bad argument lists for commands with zero parameters but with streams 677 $with_params =~ s/\(, /(/g; 678 679 print H <<__E; 680 681 $with_params 682 }; 683 __E 684 685 # standard remote protocol objects 686 foreach my $type ('Client', 'Server', 'Local') 687 { 688 my $writing_client = ($type eq 'Client'); 689 my $writing_server = ($type eq 'Server'); 690 my $writing_local = ($type eq 'Local'); 691 692 my $server_or_client_class = $protocol_name."Protocol".$type; 693 my @base_classes; 694 695 if (not $writing_client) 696 { 697 push @base_classes, $replyable_base_class; 698 } 699 if (not $writing_server) 700 { 701 push @base_classes, $callable_base_class; 702 } 703 if (not $writing_local) 704 { 705 push @base_classes, "Protocol"; 706 } 707 708 my $base_classes_str = join(", ", map {"public $_"} @base_classes); 709 710 print H <<__E; 711 class $server_or_client_class : $base_classes_str 712 { 713 public: 714 __E 715 716 if($writing_local) 717 { 718 print H <<__E; 719 $server_or_client_class($context_class &rContext); 720 __E 721 } 722 else 723 { 724 print H <<__E; 725 $server_or_client_class(IOStream &rStream); 726 std::auto_ptr<$message_base_class> Receive(); 727 void Send(const $message_base_class &rObject); 728 __E 729 } 730 731 print H <<__E; 732 virtual ~$server_or_client_class(); 733 __E 734 735 if($writing_server) 736 { 737 # need to put in the conversation function 738 print H <<__E; 739 void DoServer($context_class &rContext); 740 741 __E 742 } 743 744 if($writing_client or $writing_local) 745 { 746 # add plain object taking query functions 747 for my $cmd (@cmd_list) 748 { 749 if(obj_is_type($cmd,'Command')) 750 { 751 my $has_stream = obj_is_type($cmd,'StreamWithCommand'); 752 my $argextra = $has_stream?', IOStream &rStream':''; 753 my $queryextra = $has_stream?', rStream':''; 754 my $request_class = $cmd_class{$cmd}; 755 my $reply_class = $cmd_class{obj_get_type_params($cmd,'Command')}; 756 print H "\tstd::auto_ptr<$reply_class> Query(const $request_class &rQuery$argextra);\n"; 757 } 758 } 759 } 760 761 if($writing_local) 762 { 763 print H <<__E; 764 private: 765 $context_class &mrContext; 766 __E 767 } 768 769 print H <<__E; 770 771 protected: 772 virtual std::auto_ptr<Message> MakeMessage(int ObjType); 773 774 __E 775 776 if($writing_local) 777 { 778 print H <<__E; 779 virtual void InformStreamReceiving(u_int32_t Size) { } 780 virtual void InformStreamSending(u_int32_t Size) { } 781 782 public: 783 virtual std::auto_ptr<IOStream> ReceiveStream() 784 { 785 std::auto_ptr<IOStream> apStream(mStreamsToSend.front()); 786 mStreamsToSend.pop_front(); 787 return apStream; 788 } 789 __E 790 } 791 else 792 { 793 print H <<__E; 794 virtual void InformStreamReceiving(u_int32_t Size) 795 { 796 this->Protocol::InformStreamReceiving(Size); 797 } 798 virtual void InformStreamSending(u_int32_t Size) 799 { 800 this->Protocol::InformStreamSending(Size); 801 } 802 803 public: 804 virtual std::auto_ptr<IOStream> ReceiveStream() 805 { 806 return this->Protocol::ReceiveStream(); 807 } 808 __E 809 } 810 811 print H <<__E; 812 virtual const char *GetProtocolIdentString() 813 { 814 return GetIdentString(); 815 } 816 __E 817 818 if($writing_local) 819 { 820 print H <<__E; 821 virtual int GetTimeout() 822 { 823 return IOStream::TimeOutInfinite; 824 } 825 __E 826 } 827 else 828 { 829 print H <<__E; 830 virtual int GetTimeout() 831 { 832 return this->Protocol::GetTimeout(); 833 } 834 __E 835 } 836 837 print H <<__E; 838 /* 839 virtual void Handshake() 840 { 841 this->Protocol::Handshake(); 842 } 843 virtual bool GetLastError(int &rTypeOut, int &rSubTypeOut) 844 { 845 return this->Protocol::GetLastError(rTypeOut, rSubTypeOut); 846 } 847 */ 848 849 private: 850 $server_or_client_class(const $server_or_client_class &rToCopy); /* no copies */ 851 }; 852 853 __E 854 855 my $destructor_extra = ($writing_server) ? "\n\tDeleteStreamsToSend();" 856 : ''; 857 858 if($writing_local) 859 { 860 print CPP <<__E; 861 $server_or_client_class\::$server_or_client_class($context_class &rContext) 862 : mrContext(rContext) 863 { } 864 __E 865 } 866 else 867 { 868 print CPP <<__E; 869 $server_or_client_class\::$server_or_client_class(IOStream &rStream) 870 : Protocol(rStream) 871 { } 872 __E 873 } 874 875 print CPP <<__E; 876 $server_or_client_class\::~$server_or_client_class() 877 {$destructor_extra 878 } 879 __E 880 881 # write receive and send functions 882 print CPP <<__E; 883 std::auto_ptr<Message> $server_or_client_class\::MakeMessage(int ObjType) 884 { 885 switch(ObjType) 886 { 887 __E 888 889 # do objects within this 584 890 for my $cmd (@cmd_list) 585 891 { 586 if(obj_is_type($cmd,'Command')) 587 { 588 my $has_stream = obj_is_type($cmd,'StreamWithCommand'); 589 my $argextra = $has_stream?', IOStream &rStream':''; 590 my $queryextra = $has_stream?', rStream':''; 591 my $reply = obj_get_type_params($cmd,'Command'); 592 print H "\tstd::auto_ptr<$classname_base$reply> Query(const $classname_base$cmd &rQuery$argextra);\n"; 593 my @a; 594 my @na; 595 for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) 596 { 597 my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); 598 push @a,translate_type_to_arg_type($ty)." $nm"; 599 push @na,"$nm"; 600 } 601 my $ar = join(', ',@a); 602 my $nar = join(', ',@na); 603 $nar = "($nar)" if $nar ne ''; 604 605 $with_params .= "\tinline std::auto_ptr<$classname_base$reply> Query$cmd($ar$argextra)\n\t{\n"; 606 $with_params .= "\t\t$classname_base$cmd send$nar;\n"; 607 $with_params .= "\t\treturn Query(send$queryextra);\n"; 608 $with_params .= "\t}\n"; 609 } 610 } 611 # quick hack to correct bad argument lists for commands with zero paramters but with streams 612 $with_params =~ s/\(, /(/g; 613 print H "\n",$with_params,"\n"; 614 } 615 print H <<__E; 616 private: 617 $classname_base(const $classname_base &rToCopy); 618 __E 619 if($type eq 'Server') 620 { 621 # need to put the streams to send vector 622 print H "\tstd::vector<IOStream*> mStreamsToSend;\n\tvoid DeleteStreamsToSend();\n"; 623 } 624 625 if($implement_filelog || $implement_syslog) 626 { 627 print H <<__E; 628 virtual void InformStreamReceiving(u_int32_t Size); 629 virtual void InformStreamSending(u_int32_t Size); 630 __E 631 } 632 633 if($implement_syslog) 634 { 635 print H "private:\n\tbool mLogToSysLog;\n"; 636 } 637 if($implement_filelog) 638 { 639 print H "private:\n\tFILE *mLogToFile;\n"; 640 } 641 print H <<__E; 642 643 protected: 644 virtual std::auto_ptr<ProtocolObject> MakeProtocolObject(int ObjType); 645 virtual const char *GetIdentString(); 646 }; 647 648 __E 649 650 my $constructor_extra = ''; 651 $constructor_extra .= ', mLogToSysLog(false)' if $implement_syslog; 652 $constructor_extra .= ', mLogToFile(0)' if $implement_filelog; 653 654 my $destructor_extra = ($type eq 'Server')?"\n\tDeleteStreamsToSend();":''; 655 656 my $prefix = $classname_base.'::'; 657 print CPP <<__E; 658 $prefix$classname_base(IOStream &rStream) 659 : Protocol(rStream)$constructor_extra 660 { 661 } 662 $prefix~$classname_base() 663 {$destructor_extra 664 } 665 const char *${prefix}GetIdentString() 666 { 667 return "$ident_string"; 668 } 669 std::auto_ptr<ProtocolObject> ${prefix}MakeProtocolObject(int ObjType) 670 { 671 switch(ObjType) 672 { 673 __E 674 675 # do objects within this 676 for my $cmd (@cmd_list) 677 { 892 print CPP <<__E; 893 case $cmd_id{$cmd}: 894 return std::auto_ptr<Message>(new $cmd_class{$cmd}()); 895 break; 896 __E 897 } 898 678 899 print CPP <<__E; 679 case $cmd_id{$cmd}:680 return std::auto_ptr<ProtocolObject>(new $classname_base$cmd);681 break;682 __E683 }684 685 print CPP <<__E;686 900 default: 687 901 THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnknownCommandRecieved) … … 689 903 } 690 904 __E 691 # write receive and send functions 692 print CPP <<__E; 693 std::auto_ptr<$derive_objects_from> ${prefix}Receive() 694 { 695 std::auto_ptr<${derive_objects_from}> preply((${derive_objects_from}*)(Protocol::Receive().release())); 696 697 __E 698 if($implement_syslog) 905 906 if(not $writing_local) 699 907 { 700 908 print CPP <<__E; 701 if(mLogToSysLog) 909 std::auto_ptr<$message_base_class> $server_or_client_class\::Receive() 910 { 911 std::auto_ptr<$message_base_class> preply(($message_base_class *) 912 Protocol::ReceiveInternal().release()); 913 914 if(GetLogToSysLog()) 702 915 { 703 916 preply->LogSysLog("Receive"); 704 917 } 705 __E 706 } 707 if($implement_filelog) 918 919 if(GetLogToFile() != 0) 920 { 921 preply->LogFile("Receive", GetLogToFile()); 922 } 923 924 return preply; 925 } 926 927 void $server_or_client_class\::Send(const $message_base_class &rObject) 928 { 929 if(GetLogToSysLog()) 930 { 931 rObject.LogSysLog("Send"); 932 } 933 934 if(GetLogToFile() != 0) 935 { 936 rObject.LogFile("Send", GetLogToFile()); 937 } 938 939 Protocol::SendInternal(rObject); 940 } 941 942 __E 943 } 944 945 # write server function? 946 if($writing_server) 708 947 { 709 948 print CPP <<__E; 710 if(mLogToFile != 0) 711 { 712 preply->LogFile("Receive", mLogToFile); 713 } 714 __E 715 } 716 print CPP <<__E; 717 718 return preply; 719 } 720 721 void ${prefix}Send(const ${derive_objects_from} &rObject) 722 { 723 __E 724 if($implement_syslog) 725 { 726 print CPP <<__E; 727 if(mLogToSysLog) 728 { 729 rObject.LogSysLog("Send"); 730 } 731 __E 732 } 733 if($implement_filelog) 734 { 735 print CPP <<__E; 736 if(mLogToFile != 0) 737 { 738 rObject.LogFile("Send", mLogToFile); 739 } 740 __E 741 } 742 743 print CPP <<__E; 744 Protocol::Send(rObject); 745 } 746 747 __E 748 # write server function? 749 if($type eq 'Server') 750 { 751 print CPP <<__E; 752 void ${prefix}DoServer($context_class &rContext) 949 void $server_or_client_class\::DoServer($context_class &rContext) 753 950 { 754 951 // Handshake with client … … 760 957 { 761 958 // Get an object from the conversation 762 std::auto_ptr<$ {derive_objects_from}> pobj(Receive());959 std::auto_ptr<$message_base_class> pobj = Receive(); 763 960 764 961 // Run the command 765 std::auto_ptr<$ {derive_objects_from}> preply((${derive_objects_from}*)(pobj->DoCommand(*this, rContext).release()));962 std::auto_ptr<$message_base_class> preply = pobj->DoCommand(*this, rContext); 766 963 767 964 // Send the reply 768 Send(* (preply.get()));965 Send(*preply); 769 966 770 967 // Send any streams 771 for(unsigned int s = 0; s < mStreamsToSend.size(); s++) 772 { 773 // Send the streams 774 SendStream(*mStreamsToSend[s]); 775 } 968 for(std::list<IOStream*>::iterator 969 i = mStreamsToSend.begin(); 970 i != mStreamsToSend.end(); ++i) 971 { 972 SendStream(**i); 973 } 974 776 975 // Delete these streams 777 976 DeleteStreamsToSend(); … … 785 984 } 786 985 787 void ${prefix}SendStreamAfterCommand(IOStream *pStream) 788 { 789 ASSERT(pStream != NULL); 790 mStreamsToSend.push_back(pStream); 791 } 792 793 void ${prefix}DeleteStreamsToSend() 794 { 795 for(std::vector<IOStream*>::iterator i(mStreamsToSend.begin()); i != mStreamsToSend.end(); ++i) 796 { 797 delete (*i); 798 } 799 mStreamsToSend.clear(); 800 } 801 802 __E 803 } 804 805 # write logging functions? 806 if($implement_filelog || $implement_syslog) 807 { 808 my ($fR,$fS); 809 810 if($implement_syslog) 811 { 812 $fR .= <<__E; 813 if(mLogToSysLog) 814 { 815 if(Size==Protocol::ProtocolStream_SizeUncertain) 816 { 817 BOX_TRACE("Receiving stream, size uncertain"); 818 } 819 else 820 { 821 BOX_TRACE("Receiving stream, size " << Size); 822 } 823 } 824 __E 825 826 $fS .= <<__E; 827 if(mLogToSysLog) 828 { 829 if(Size==Protocol::ProtocolStream_SizeUncertain) 830 { 831 BOX_TRACE("Sending stream, size uncertain"); 832 } 833 else 834 { 835 BOX_TRACE("Sending stream, size " << Size); 836 } 837 } 838 __E 839 } 840 841 if($implement_filelog) 842 { 843 $fR .= <<__E; 844 if(mLogToFile) 845 { 846 ::fprintf(mLogToFile, 847 (Size==Protocol::ProtocolStream_SizeUncertain) 848 ?"Receiving stream, size uncertain\\n" 849 :"Receiving stream, size %d\\n", Size); 850 ::fflush(mLogToFile); 851 } 852 __E 853 $fS .= <<__E; 854 if(mLogToFile) 855 { 856 ::fprintf(mLogToFile, 857 (Size==Protocol::ProtocolStream_SizeUncertain) 858 ?"Sending stream, size uncertain\\n" 859 :"Sending stream, size %d\\n", Size); 860 ::fflush(mLogToFile); 861 } 862 __E 863 } 864 865 print CPP <<__E; 866 867 void ${prefix}InformStreamReceiving(u_int32_t Size) 868 { 869 $fR} 870 871 void ${prefix}InformStreamSending(u_int32_t Size) 872 { 873 $fS} 874 875 __E 876 } 877 878 879 # write client Query functions? 880 if($type eq 'Client') 881 { 882 for my $cmd (@cmd_list) 883 { 884 if(obj_is_type($cmd,'Command')) 885 { 886 my $reply = obj_get_type_params($cmd,'Command'); 887 my $reply_id = $cmd_id{$reply}; 888 my $has_stream = obj_is_type($cmd,'StreamWithCommand'); 889 my $argextra = $has_stream?', IOStream &rStream':''; 890 my $send_stream_extra = ''; 891 if($has_stream) 986 __E 987 } 988 989 # write client Query functions? 990 if($writing_client or $writing_local) 991 { 992 for my $cmd (@cmd_list) 993 { 994 if(obj_is_type($cmd,'Command')) 892 995 { 893 $send_stream_extra = <<__E; 894 996 my $request_class = $cmd_class{$cmd}; 997 my $reply_msg = obj_get_type_params($cmd,'Command'); 998 my $reply_class = $cmd_class{$reply_msg}; 999 my $reply_id = $cmd_id{$reply_msg}; 1000 my $has_stream = obj_is_type($cmd,'StreamWithCommand'); 1001 my $argextra = $has_stream?', IOStream &rStream':''; 1002 my $send_stream_extra = ''; 1003 my $send_stream_method = $writing_client ? "SendStream" 1004 : "SendStreamAfterCommand"; 1005 1006 if($writing_client) 1007 { 1008 if($has_stream) 1009 { 1010 $send_stream_extra = <<__E; 895 1011 // Send stream after the command 896 1012 SendStream(rStream); 897 1013 __E 898 } 899 print CPP <<__E; 900 std::auto_ptr<$classname_base$reply> ${classname_base}::Query(const $classname_base$cmd &rQuery$argextra) 1014 } 1015 1016 print CPP <<__E; 1017 std::auto_ptr<$reply_class> $server_or_client_class\::Query(const $request_class &rQuery$argextra) 901 1018 { 902 1019 // Send query 903 1020 Send(rQuery); 904 1021 $send_stream_extra 1022 905 1023 // Wait for the reply 906 std::auto_ptr<${derive_objects_from}> preply(Receive().release()); 907 908 if(preply->GetType() == $reply_id) 909 { 910 // Correct response 911 return std::auto_ptr<$classname_base$reply>(($classname_base$reply*)preply.release()); 912 } 913 else 914 { 915 // Set protocol error 916 int type, subType; 917 if(preply->IsError(type, subType)) 918 { 919 SetError(type, subType); 920 BOX_WARNING("$cmd command failed: received error " << 921 ((${classname_base}Error&)*preply).GetMessage()); 922 } 923 else 924 { 925 SetError(Protocol::UnknownError, Protocol::UnknownError); 926 BOX_WARNING("$cmd command failed: received " 927 "unexpected response type " << 928 preply->GetType()); 929 } 930 931 // Throw an exception 932 THROW_EXCEPTION(ConnectionException, Conn_Protocol_UnexpectedReply) 933 } 934 } 935 __E 936 } 937 } 938 } 939 940 1024 std::auto_ptr<$message_base_class> preply = Receive(); 1025 1026 CheckReply("$cmd", *preply, $reply_id); 1027 1028 // Correct response, if no exception thrown by CheckReply 1029 return std::auto_ptr<$reply_class>(($reply_class *)preply.release()); 1030 } 1031 __E 1032 } 1033 elsif($writing_local) 1034 { 1035 if($has_stream) 1036 { 1037 $send_stream_extra = <<__E; 1038 // Send stream after the command 1039 SendStreamAfterCommand(&rStream); 1040 __E 1041 } 1042 1043 print CPP <<__E; 1044 std::auto_ptr<$reply_class> $server_or_client_class\::Query(const $request_class &rQuery$argextra) 1045 { 1046 // Send query 1047 $send_stream_extra 1048 std::auto_ptr<$message_base_class> preply = rQuery.DoCommand(*this, mrContext); 1049 1050 CheckReply("$cmd", *preply, $reply_id); 1051 1052 // Correct response, if no exception thrown by CheckReply 1053 return std::auto_ptr<$reply_class>(($reply_class *)preply.release()); 1054 } 1055 __E 1056 } 1057 } 1058 } 1059 } 1060 } 941 1061 942 1062 print H <<__E; … … 949 1069 close CPP; 950 1070 951 952 sub obj_is_type 1071 sub obj_is_type ($$) 953 1072 { 954 1073 my ($c,$ty) = @_; … … 1004 1123 } 1005 1124 1006 sub make_log_strings 1125 sub make_log_strings_framework 1007 1126 { 1008 1127 my ($cmd) = @_; 1009 1128 1010 my @ str;1011 my @arg; 1129 my @args; 1130 1012 1131 for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) 1013 1132 { … … 1020 1139 $arg =~ s/VAR/m$nm/g; 1021 1140 1022 if ($format eq "0x%llx" and $target_windows) 1023 { 1024 $format = "0x%I64x"; 1025 $arg = "(uint64_t)$arg"; 1026 } 1027 1028 push @str,$format; 1029 push @arg,$arg; 1030 } 1031 else 1032 { 1033 # is opaque 1034 push @str,'OPAQUE'; 1035 } 1036 } 1037 return ($cmd.'('.join(',',@str).')', join(',','',@arg)); 1038 } 1039 1040 sub make_log_strings_framework 1041 { 1042 my ($cmd) = @_; 1043 1044 my @args; 1045 1046 for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2) 1047 { 1048 my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]); 1049 1050 if(exists $log_display_types{$ty}) 1051 { 1052 # need to translate it 1053 my ($format,$arg) = @{$log_display_types{$ty}}; 1054 $arg =~ s/VAR/m$nm/g; 1055 1056 if ($format eq '\\"%s\\"') 1141 if ($format eq '"%s"') 1057 1142 { 1058 1143 $arg = "\"\\\"\" << $arg << \"\\\"\""; … … 1091 1176 } 1092 1177 1093
Note: See TracChangeset
for help on using the changeset viewer.
