dcmtkpp
Message.h
1 /*************************************************************************
2  * dcmtkpp - Copyright (C) Universite de Strasbourg
3  * Distributed under the terms of the CeCILL-B license, as published by
4  * the CEA-CNRS-INRIA. Refer to the LICENSE file or to
5  * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
6  * for details.
7  ************************************************************************/
8 
9 #ifndef _dcfa5213_ad7e_4194_8b4b_e630aa0df2e8
10 #define _dcfa5213_ad7e_4194_8b4b_e630aa0df2e8
11 
12 #include "dcmtkpp/DataSet.h"
13 #include "dcmtkpp/registry.h"
14 #include "dcmtkpp/Value.h"
15 
16 namespace dcmtkpp
17 {
18 
19 #define DCMTKPP_MESSAGE_MANDATORY_FIELD_MACRO(name, tag, TValueType, function) \
20  \
21  TValueType const & get_##name() const \
22  { \
23  auto const & data = this->_command_set.function(tag); \
24  if(data.empty()) \
25  { \
26  throw Exception("Empty element"); \
27  } \
28  return data[0]; \
29  } \
30  \
31  void set_##name(TValueType const & value) \
32  { \
33  if(!this->_command_set.has(tag)) \
34  { \
35  this->_command_set.add(tag); \
36  } \
37  this->_command_set.function(tag) = { value }; \
38  }
39 
40 #define DCMTKPP_MESSAGE_OPTIONAL_FIELD_MACRO(name, tag, TValueType, function) \
41  DCMTKPP_MESSAGE_MANDATORY_FIELD_MACRO(name, tag, TValueType, function) \
42  bool has_##name() const \
43  { \
44  return this->_command_set.has(tag);; \
45  } \
46  void delete_##name() \
47  { \
48  this->_command_set.remove(tag); \
49  }
50 
51 #define DCMTKPP_MESSAGE_SET_OPTIONAL_FIELD_MACRO(dataset, name, tag, function) \
52  if(dataset.has(tag)) \
53  { \
54  this->set_##name(dataset.function(tag, 0)); \
55  }
56 
57 #define DCMTKPP_MESSAGE_MANDATORY_FIELD_INTEGER_MACRO(name, tag) \
58  DCMTKPP_MESSAGE_MANDATORY_FIELD_MACRO(name, tag, Value::Integer, as_int)
59 
60 #define DCMTKPP_MESSAGE_MANDATORY_FIELD_STRING_MACRO(name, tag) \
61  DCMTKPP_MESSAGE_MANDATORY_FIELD_MACRO(name, tag, Value::String, as_string)
62 
63 #define DCMTKPP_MESSAGE_OPTIONAL_FIELD_INTEGER_MACRO(name, tag) \
64  DCMTKPP_MESSAGE_OPTIONAL_FIELD_MACRO(name, tag, Value::Integer, as_int)
65 
66 #define DCMTKPP_MESSAGE_OPTIONAL_FIELD_STRING_MACRO(name, tag) \
67  DCMTKPP_MESSAGE_OPTIONAL_FIELD_MACRO(name, tag, Value::String, as_string)
68 
72 class Message
73 {
74 public:
75  struct Command
76  {
77  enum Type
78  {
79  C_STORE_RQ = 0x0001,
80  C_STORE_RSP = 0x8001,
81 
82  C_FIND_RQ = 0x0020,
83  C_FIND_RSP = 0x8020,
84 
85  C_CANCEL_RQ = 0x0FFF,
86 
87  C_GET_RQ = 0x0010,
88  C_GET_RSP = 0x8010,
89 
90  C_MOVE_RQ = 0x0021,
91  C_MOVE_RSP = 0x8021,
92 
93  C_ECHO_RQ = 0x0030,
94  C_ECHO_RSP = 0x8030,
95 
96  N_EVENT_REPORT_RQ = 0x0100,
97  N_EVENT_REPORT_RSP = 0x8100,
98 
99  N_GET_RQ = 0x0110,
100  N_GET_RSP = 0x8110,
101 
102  N_SET_RQ = 0x0120,
103  N_SET_RSP = 0x8120,
104 
105  N_ACTION_RQ = 0x0130,
106  N_ACTION_RSP = 0x8130,
107 
108  N_CREATE_RQ = 0x0140,
109  N_CREATE_RSP = 0x8140,
110 
111  N_DELETE_RQ = 0x0150,
112  N_DELETE_RSP = 0x8150,
113  };
114  };
115 
116  struct Priority
117  {
118  enum Type
119  {
120  LOW = 0x0002,
121  MEDIUM = 0x0000,
122  HIGH = 0x0001,
123  };
124  };
125 
126  struct DataSetType
127  {
128  enum Type
129  {
130  PRESENT = 0x0000,
131  ABSENT = 0x0101,
132  };
133  };
134 
136  Message();
137 
139  Message(DataSet const & command_set);
140 
142  Message(DataSet const & command_set, DataSet const & data_set);
143 
145  virtual ~Message();
146 
148  DataSet const & get_command_set() const;
149 
151  bool has_data_set() const;
152 
157  DataSet const & get_data_set() const;
158 
160  void set_data_set(DataSet const & data_set);
161 
163  void delete_data_set();
164 
165  DCMTKPP_MESSAGE_MANDATORY_FIELD_INTEGER_MACRO(
166  command_field, registry::CommandField)
167 
168 protected:
171 
174 };
175 
176 }
177 
178 #endif // _dcfa5213_ad7e_4194_8b4b_e630aa0df2e8
DataSet _command_set
Command set of the message.
Definition: Message.h:170
Definition: Association.cpp:22
void set_data_set(DataSet const &data_set)
Set the data set of the message.
Definition: Message.cpp:80
DataSet const & get_data_set() const
Return the data set of the message, raise an exception if no data set is present. ...
Definition: Message.cpp:69
Definition: Message.h:126
Definition: Message.h:75
Definition: Message.h:116
DataSet _data_set
Data set of the message.
Definition: Message.h:173
bool has_data_set() const
Test whether as data set is present in the message.
Definition: Message.cpp:62
DataSet const & get_command_set() const
Return the command set of the message.
Definition: Message.cpp:55
DICOM Data set.
Definition: DataSet.h:66
virtual ~Message()
Destructor;.
Definition: Message.cpp:48
Base class for all DIMSE messages.
Definition: Message.h:72
void delete_data_set()
Delete the data set in this message.
Definition: Message.cpp:88
Message()
Create a message with an empty command set and an empty data set.
Definition: Message.cpp:20