PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
ups_watch_scp.h
Go to the documentation of this file.
1
16#ifndef PACS_SERVICES_UPS_WATCH_SCP_HPP
17#define PACS_SERVICES_UPS_WATCH_SCP_HPP
18
19#include "../scp_service.h"
20
21#include <atomic>
22#include <functional>
23
24namespace kcenon::pacs::services {
25
26// =============================================================================
27// SOP Class UID
28// =============================================================================
29
31inline constexpr std::string_view ups_watch_sop_class_uid =
32 "1.2.840.10008.5.1.4.34.6.2";
33
34// =============================================================================
35// Well-Known SOP Instance UID
36// =============================================================================
37
40inline constexpr std::string_view ups_global_subscription_instance_uid =
41 "1.2.840.10008.5.1.4.34.5";
42
43// =============================================================================
44// N-ACTION Type Constants for UPS Watch
45// =============================================================================
46
48inline constexpr uint16_t ups_watch_action_subscribe = 3;
49
51inline constexpr uint16_t ups_watch_action_unsubscribe = 4;
52
54inline constexpr uint16_t ups_watch_action_suspend_global = 5;
55
56// =============================================================================
57// N-EVENT-REPORT Event Type Constants
58// =============================================================================
59
61inline constexpr uint16_t ups_event_state_report = 1;
62
64inline constexpr uint16_t ups_event_cancel_requested = 2;
65
67inline constexpr uint16_t ups_event_progress_report = 3;
68
70inline constexpr uint16_t ups_event_scp_status_change = 4;
71
72// =============================================================================
73// Handler Types
74// =============================================================================
75
87using ups_subscribe_handler = std::function<network::Result<std::monostate>(
88 const std::string& subscriber_ae,
89 const std::string& workitem_uid,
90 bool deletion_lock)>;
91
102using ups_unsubscribe_handler = std::function<network::Result<std::monostate>(
103 const std::string& subscriber_ae,
104 const std::string& workitem_uid)>;
105
115using ups_get_subscribers_handler = std::function<
117 const std::string& workitem_uid)>;
118
131using ups_event_callback = std::function<void(
132 const std::string& subscriber_ae,
133 uint16_t event_type_id,
134 const std::string& workitem_uid,
135 const core::dicom_dataset& event_info)>;
136
137// =============================================================================
138// UPS Watch SCP Class
139// =============================================================================
140
174class ups_watch_scp final : public scp_service {
175public:
176 // =========================================================================
177 // Construction
178 // =========================================================================
179
185 explicit ups_watch_scp(std::shared_ptr<di::ILogger> logger = nullptr);
186
187 ~ups_watch_scp() override = default;
188
189 // =========================================================================
190 // Configuration
191 // =========================================================================
192
197
198 // =========================================================================
199 // scp_service Interface Implementation
200 // =========================================================================
201
202 [[nodiscard]] std::vector<std::string> supported_sop_classes() const override;
203
206 uint8_t context_id,
207 const network::dimse::dimse_message& request) override;
208
209 [[nodiscard]] std::string_view service_name() const noexcept override;
210
211 // =========================================================================
212 // Event Notification
213 // =========================================================================
214
224 void notify_state_change(const std::string& workitem_uid,
225 const std::string& new_state);
226
233 void notify_cancel_requested(const std::string& workitem_uid,
234 const std::string& reason);
235
242 void notify_progress(const std::string& workitem_uid,
243 int progress_percent);
244
245 // =========================================================================
246 // Statistics
247 // =========================================================================
248
249 [[nodiscard]] size_t subscriptions_created() const noexcept;
250 [[nodiscard]] size_t subscriptions_removed() const noexcept;
251 [[nodiscard]] size_t events_sent() const noexcept;
252
253 void reset_statistics() noexcept;
254
255private:
256 // =========================================================================
257 // Private Implementation
258 // =========================================================================
259
260 [[nodiscard]] network::Result<std::monostate> handle_n_action(
261 network::association& assoc,
262 uint8_t context_id,
263 const network::dimse::dimse_message& request);
264
265 [[nodiscard]] network::Result<std::monostate> handle_subscribe(
266 network::association& assoc,
267 uint8_t context_id,
268 uint16_t message_id,
269 const std::string& sop_instance_uid);
270
271 [[nodiscard]] network::Result<std::monostate> handle_unsubscribe(
272 network::association& assoc,
273 uint8_t context_id,
274 uint16_t message_id,
275 const std::string& sop_instance_uid);
276
277 [[nodiscard]] network::Result<std::monostate> handle_suspend_global(
278 network::association& assoc,
279 uint8_t context_id,
280 uint16_t message_id);
281
282 [[nodiscard]] network::Result<std::monostate> send_n_action_response(
283 network::association& assoc,
284 uint8_t context_id,
285 uint16_t message_id,
286 const std::string& sop_instance_uid,
287 uint16_t action_type_id,
288 network::dimse::status_code status);
289
290 void dispatch_event(uint16_t event_type_id,
291 const std::string& workitem_uid,
292 const core::dicom_dataset& event_info);
293
294 // =========================================================================
295 // Member Variables
296 // =========================================================================
297
302
303 std::atomic<size_t> subscriptions_created_{0};
304 std::atomic<size_t> subscriptions_removed_{0};
305 std::atomic<size_t> events_sent_{0};
306};
307
308} // namespace kcenon::pacs::services
309
310#endif // PACS_SERVICES_UPS_WATCH_SCP_HPP
const std::shared_ptr< di::ILogger > & logger() const noexcept
Get the current logger instance.
Definition scp_service.h:93
UPS Watch SCP service for subscription and event notification.
ups_unsubscribe_handler unsubscribe_handler_
std::atomic< size_t > subscriptions_removed_
void set_subscribe_handler(ups_subscribe_handler handler)
void dispatch_event(uint16_t event_type_id, const std::string &workitem_uid, const core::dicom_dataset &event_info)
ups_watch_scp(std::shared_ptr< di::ILogger > logger=nullptr)
Construct UPS Watch SCP with optional logger.
std::string_view service_name() const noexcept override
Get the service name for logging/debugging.
void notify_state_change(const std::string &workitem_uid, const std::string &new_state)
Notify subscribers of a workitem state change.
void notify_cancel_requested(const std::string &workitem_uid, const std::string &reason)
Notify subscribers of a cancel request.
network::Result< std::monostate > handle_suspend_global(network::association &assoc, uint8_t context_id, uint16_t message_id)
ups_get_subscribers_handler get_subscribers_handler_
void notify_progress(const std::string &workitem_uid, int progress_percent)
Notify subscribers of progress update.
std::atomic< size_t > subscriptions_created_
ups_subscribe_handler subscribe_handler_
network::Result< std::monostate > handle_subscribe(network::association &assoc, uint8_t context_id, uint16_t message_id, const std::string &sop_instance_uid)
network::Result< std::monostate > send_n_action_response(network::association &assoc, uint8_t context_id, uint16_t message_id, const std::string &sop_instance_uid, uint16_t action_type_id, network::dimse::status_code status)
network::Result< std::monostate > handle_n_action(network::association &assoc, uint8_t context_id, const network::dimse::dimse_message &request)
size_t subscriptions_created() const noexcept
network::Result< std::monostate > handle_message(network::association &assoc, uint8_t context_id, const network::dimse::dimse_message &request) override
Handle an incoming DIMSE message.
void set_event_callback(ups_event_callback callback)
size_t subscriptions_removed() const noexcept
void set_unsubscribe_handler(ups_unsubscribe_handler handler)
network::Result< std::monostate > handle_unsubscribe(network::association &assoc, uint8_t context_id, uint16_t message_id, const std::string &sop_instance_uid)
void set_get_subscribers_handler(ups_get_subscribers_handler handler)
std::vector< std::string > supported_sop_classes() const override
Get the list of SOP Class UIDs supported by this service.
constexpr uint16_t ups_event_scp_status_change
Event Type 4: SCP Status Change — SCP going down/restarting.
std::function< network::Result< std::monostate >( const std::string &subscriber_ae, const std::string &workitem_uid, bool deletion_lock)> ups_subscribe_handler
Subscribe handler function type.
constexpr uint16_t ups_event_state_report
Event Type 1: UPS State Report — workitem state changed.
constexpr uint16_t ups_event_progress_report
Event Type 3: UPS Progress Report — progress percentage update.
constexpr std::string_view ups_watch_sop_class_uid
UPS Watch SOP Class UID (PS3.4 Table CC.2-1)
std::function< network::Result< std::monostate >( const std::string &subscriber_ae, const std::string &workitem_uid)> ups_unsubscribe_handler
Unsubscribe handler function type.
constexpr uint16_t ups_watch_action_suspend_global
N-ACTION Type 5: Suspend Global Subscription (PS3.4 CC.2.3.5)
constexpr std::string_view ups_global_subscription_instance_uid
UPS Global Subscription SOP Instance UID Used as the SOP Instance UID for global (non-workitem-specif...
constexpr uint16_t ups_event_cancel_requested
Event Type 2: UPS Cancel Requested — performer should stop processing.
std::function< network::Result< std::vector< std::string > >( const std::string &workitem_uid)> ups_get_subscribers_handler
Get subscribers handler function type.
std::function< void( const std::string &subscriber_ae, uint16_t event_type_id, const std::string &workitem_uid, const core::dicom_dataset &event_info)> ups_event_callback
Event notification callback type.
constexpr uint16_t ups_watch_action_unsubscribe
N-ACTION Type 4: Unsubscribe from Receiving UPS Event Reports (PS3.4 CC.2.3.4)
constexpr uint16_t ups_watch_action_subscribe
N-ACTION Type 3: Subscribe to Receive UPS Event Reports (PS3.4 CC.2.3.3)
Base class for DICOM SCP (Service Class Provider) services.