Mercurial > hg > orthanc
comparison OrthancServer/DicomProtocol/DicomServer.cpp @ 1680:4113a9a668b1
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 06 Oct 2015 13:36:09 +0200 |
parents | d3ba98d6b6e9 |
children | ee4367497d0d |
comparison
equal
deleted
inserted
replaced
1679:15acdb19d520 | 1680:4113a9a668b1 |
---|---|
56 | 56 |
57 //std::set< | 57 //std::set< |
58 }; | 58 }; |
59 | 59 |
60 | 60 |
61 void DicomServer::ServerThread(DicomServer* server) | 61 void DicomServer::ServerThread(DicomServer* server, |
62 { | 62 T_ASC_Network *network) |
63 /* initialize network, i.e. create an instance of T_ASC_Network*. */ | 63 { |
64 T_ASC_Network *net; | |
65 OFCondition cond = ASC_initializeNetwork | |
66 (NET_ACCEPTOR, OFstatic_cast(int, server->port_), /*opt_acse_timeout*/ 30, &net); | |
67 if (cond.bad()) | |
68 { | |
69 LOG(ERROR) << "cannot create network: " << cond.text(); | |
70 throw OrthancException(ErrorCode_DicomPortInUse); | |
71 } | |
72 | |
73 LOG(INFO) << "DICOM server started"; | 64 LOG(INFO) << "DICOM server started"; |
74 | |
75 server->started_ = true; | |
76 | 65 |
77 while (server->continue_) | 66 while (server->continue_) |
78 { | 67 { |
79 /* receive an association and acknowledge or reject it. If the association was */ | 68 /* receive an association and acknowledge or reject it. If the association was */ |
80 /* acknowledged, offer corresponding services and invoke one or more if required. */ | 69 /* acknowledged, offer corresponding services and invoke one or more if required. */ |
81 std::auto_ptr<Internals::CommandDispatcher> dispatcher(Internals::AcceptAssociation(*server, net)); | 70 std::auto_ptr<Internals::CommandDispatcher> dispatcher(Internals::AcceptAssociation(*server, network)); |
82 | 71 |
83 if (dispatcher.get() != NULL) | 72 try |
84 { | 73 { |
85 if (server->isThreaded_) | 74 if (dispatcher.get() != NULL) |
86 { | 75 { |
87 server->bagOfDispatchers_.Add(dispatcher.release()); | 76 if (server->isThreaded_) |
88 } | 77 { |
89 else | 78 server->bagOfDispatchers_.Add(dispatcher.release()); |
90 { | 79 } |
91 IRunnableBySteps::RunUntilDone(*dispatcher); | 80 else |
81 { | |
82 IRunnableBySteps::RunUntilDone(*dispatcher); | |
83 } | |
92 } | 84 } |
93 } | 85 } |
86 catch (OrthancException& e) | |
87 { | |
88 LOG(ERROR) << "Exception in the DICOM server thread: " << e.What(); | |
89 } | |
94 } | 90 } |
95 | 91 |
96 LOG(INFO) << "DICOM server stopping"; | 92 LOG(INFO) << "DICOM server stopping"; |
97 | 93 |
98 if (server->isThreaded_) | 94 if (server->isThreaded_) |
100 server->bagOfDispatchers_.StopAll(); | 96 server->bagOfDispatchers_.StopAll(); |
101 } | 97 } |
102 | 98 |
103 /* drop the network, i.e. free memory of T_ASC_Network* structure. This call */ | 99 /* drop the network, i.e. free memory of T_ASC_Network* structure. This call */ |
104 /* is the counterpart of ASC_initializeNetwork(...) which was called above. */ | 100 /* is the counterpart of ASC_initializeNetwork(...) which was called above. */ |
105 cond = ASC_dropNetwork(&net); | 101 OFCondition cond = ASC_dropNetwork(&network); |
106 if (cond.bad()) | 102 if (cond.bad()) |
107 { | 103 { |
108 LOG(ERROR) << "Error while dropping the network: " << cond.text(); | 104 LOG(ERROR) << "Error while dropping the network: " << cond.text(); |
109 } | 105 } |
110 } | 106 } |
111 | 107 |
112 | 108 |
113 DicomServer::DicomServer() : | 109 DicomServer::DicomServer() : |
114 pimpl_(new PImpl), | 110 pimpl_(new PImpl), |
115 aet_("ANY-SCP") | 111 aet_("ANY-SCP") |
120 storeRequestHandlerFactory_ = NULL; | 116 storeRequestHandlerFactory_ = NULL; |
121 applicationEntityFilter_ = NULL; | 117 applicationEntityFilter_ = NULL; |
122 checkCalledAet_ = true; | 118 checkCalledAet_ = true; |
123 clientTimeout_ = 30; | 119 clientTimeout_ = 30; |
124 isThreaded_ = true; | 120 isThreaded_ = true; |
125 continue_ = false; | 121 continue_ = true; |
126 started_ = false; | |
127 } | 122 } |
128 | 123 |
129 DicomServer::~DicomServer() | 124 DicomServer::~DicomServer() |
130 { | 125 { |
131 if (continue_) | 126 if (continue_) |
306 } | 301 } |
307 | 302 |
308 void DicomServer::Start() | 303 void DicomServer::Start() |
309 { | 304 { |
310 Stop(); | 305 Stop(); |
306 | |
307 /* initialize network, i.e. create an instance of T_ASC_Network*. */ | |
308 T_ASC_Network *network; | |
309 OFCondition cond = ASC_initializeNetwork | |
310 (NET_ACCEPTOR, OFstatic_cast(int, port_), /*opt_acse_timeout*/ 30, &network); | |
311 if (cond.bad()) | |
312 { | |
313 LOG(ERROR) << "cannot create network: " << cond.text(); | |
314 throw OrthancException(ErrorCode_DicomPortInUse); | |
315 } | |
316 | |
311 continue_ = true; | 317 continue_ = true; |
312 started_ = false; | 318 pimpl_->thread_ = boost::thread(ServerThread, this, network); |
313 pimpl_->thread_ = boost::thread(ServerThread, this); | |
314 | |
315 while (!started_) | |
316 { | |
317 Toolbox::USleep(50000); // Wait 50ms | |
318 } | |
319 } | 319 } |
320 | 320 |
321 | 321 |
322 void DicomServer::Stop() | 322 void DicomServer::Stop() |
323 { | 323 { |