ctkDICOMDemoSCUMain.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
  15. #include "dcmtk/dcmnet/scu.h"
  16. // STD includes
  17. #include <cstdlib>
  18. #include <iostream>
  19. #include <fstream>
  20. void print_usage()
  21. {
  22. std::cerr << "Usage: \n";
  23. std::cerr << " ctkDICOMDemoSCU peer port [peerAETitle]\n";
  24. std::cerr << " Issues ECHO request to the given host and given port.\n";
  25. std::cerr << " Optional peerAETitle tells what application entity to address.\n";
  26. return;
  27. }
  28. int main(int argc, char** argv)
  29. {
  30. // Check whether host and port are given
  31. if (argc < 3)
  32. {
  33. print_usage();
  34. return 2;
  35. }
  36. OString host(argv[1]);
  37. unsigned int port = atoi(argv[2]);
  38. OString peerAET;
  39. if (argc > 3)
  40. {
  41. peerAET = argv[3];
  42. }
  43. // Setup SCU
  44. DcmSCU scu;
  45. scu.setPeerHostName(host);
  46. scu.setPeerPort(port);
  47. OFString verificationSOP = UID_VerificationSOPClass;
  48. OFList<OFString> ts;
  49. ts.push_back(UID_LittleEndianExplicitTransferSyntax);
  50. ts.push_back(UID_BigEndianExplicitTransferSyntax);
  51. ts.push_back(UID_LittleEndianImplicitTransferSyntax);
  52. scu.addPresentationContext(verificationSOP, ts);
  53. if (peerAET != "")
  54. {
  55. scu.setPeerAETitle(peerAET);
  56. }
  57. OFCondition result = scu.initNetwork();
  58. if (result.bad())
  59. {
  60. std::cerr << "Error setting up SCU: " << result.text() << "\n";
  61. return 2;
  62. }
  63. // Negotiate association
  64. result = scu.negotiateAssociation();
  65. if (result.bad())
  66. {
  67. std::cerr << "Error negotiating association: " << result.text() << "\n";
  68. return 2;
  69. }
  70. // Issue ECHO request and let scu find presentation context itself (0)
  71. result = scu.sendECHORequest(0);
  72. if (result.bad())
  73. {
  74. std::cerr << "Error issuing ECHO request or received rejecting response: " << result.text() << "\n";
  75. return 2;
  76. }
  77. std::cout << "Successfully sent DICOM Echo to host " << argv[1] << " on port " << argv[2] << "\n";
  78. return 0;
  79. }