File: pacs_configuration_initializer.cpp

package info (click to toggle)
sight 25.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 42,184 kB
  • sloc: cpp: 289,476; xml: 17,257; ansic: 9,878; python: 1,379; sh: 144; makefile: 33
file content (208 lines) | stat: -rw-r--r-- 8,598 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/************************************************************************
 *
 * Copyright (C) 2009-2024 IRCAD France
 * Copyright (C) 2012-2020 IHU Strasbourg
 *
 * This file is part of Sight.
 *
 * Sight is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Sight is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Sight. If not, see <https://www.gnu.org/licenses/>.
 *
 ***********************************************************************/

#include "pacs_configuration_initializer.hpp"

#include <data/map.hpp>
#include <data/string.hpp>

#include <service/macros.hpp>
#include <service/registry.hpp>

#include <ui/__/preferences.hpp>

#include <utility>

namespace sight::module::io::dimse
{

static const std::string LOCAL_APPLICATION_TITLE("localApplicationTitle");
static const std::string PACS_HOST_NAME("pacsHostName");
static const std::string PACS_APPLICATION_TITLE("pacsApplicationTitle");
static const std::string PACS_APPLICATION_PORT("pacsApplicationPort");
static const std::string MOVE_APPLICATION_TITLE("moveApplicationTitle");
static const std::string MOVE_APPLICATION_PORT("moveApplicationPort");
static const std::string RETRIEVE_METHOD("retrieveMethod");

//------------------------------------------------------------------------------

pacs_configuration_initializer::pacs_configuration_initializer() noexcept =
    default;

//------------------------------------------------------------------------------

pacs_configuration_initializer::~pacs_configuration_initializer() noexcept =
    default;

//------------------------------------------------------------------------------

std::string pacs_configuration_initializer::get_key(const std::string& _sub_key) const noexcept
{
    return m_preference_key + "." + _sub_key;
}

//------------------------------------------------------------------------------

void pacs_configuration_initializer::configuring()
{
    const config_t config_tree = this->get_config();
    const auto config          = config_tree.get_child("config.<xmlattr>");

    // Local application title.
    m_scu_app_entity_title = config.get<std::string>(LOCAL_APPLICATION_TITLE);

    // Pacs host name.
    m_scp_host_name = config.get<std::string>(PACS_HOST_NAME);

    // Pacs application title.
    m_scp_app_entity_title = config.get<std::string>(PACS_APPLICATION_TITLE);

    // Pacs port.
    const auto pacs_application_port = config.get<std::string>(PACS_APPLICATION_PORT);
    m_scp_port = static_cast<decltype(m_scp_port)>(std::stoi(pacs_application_port));

    // Retrieve Method.
    const auto retrieve_method = config.get<std::string>(RETRIEVE_METHOD);
    m_retrieve_method = (retrieve_method == "MOVE")
                        ? (sight::io::dimse::data::pacs_configuration::retrieve_method::move)
                        : (sight::io::dimse::data::pacs_configuration::retrieve_method::get);

    // Move application title.
    m_move_app_entity_title = config.get<std::string>(MOVE_APPLICATION_TITLE);

    // Move application port.
    const auto move_application_port = config.get<std::string>(MOVE_APPLICATION_PORT);
    m_move_port = static_cast<decltype(m_move_port)>(std::stoi(move_application_port));

    // Preference Key.
    m_preference_key = config.get<std::string>("preferenceKey", m_preference_key);
}

//------------------------------------------------------------------------------

void pacs_configuration_initializer::starting()
{
    const auto pacs_configuration = m_config.lock();
    SIGHT_ASSERT("inout '" << CONFIG_INOUT << "' does not exist.", pacs_configuration);

    // Set information from xml and update PacsConfiguration.
    if(!m_preference_key.empty())
    {
        try
        {
            ui::preferences preferences;

            m_scu_app_entity_title  = preferences.get(get_key(LOCAL_APPLICATION_TITLE), m_scu_app_entity_title);
            m_scp_host_name         = preferences.get(get_key(PACS_HOST_NAME), m_scp_host_name);
            m_scp_app_entity_title  = preferences.get(get_key(PACS_APPLICATION_TITLE), m_scp_app_entity_title);
            m_scp_port              = preferences.get(get_key(PACS_APPLICATION_PORT), m_scp_port);
            m_move_app_entity_title = preferences.get(get_key(MOVE_APPLICATION_TITLE), m_move_app_entity_title);
            m_move_port             = preferences.get(get_key(MOVE_APPLICATION_PORT), m_move_port);
            m_retrieve_method       = static_cast<sight::io::dimse::data::pacs_configuration::retrieve_method>(
                preferences.get(get_key(RETRIEVE_METHOD), static_cast<int>(m_retrieve_method))
            );
        }
        catch(const ui::preferences_disabled& /*e*/)
        {
            // Nothing to do..
        }
    }

    pacs_configuration->set_local_application_title(m_scu_app_entity_title);
    pacs_configuration->set_pacs_host_name(m_scp_host_name);
    pacs_configuration->set_pacs_application_title(m_scp_app_entity_title);
    pacs_configuration->set_pacs_application_port(m_scp_port);
    pacs_configuration->set_move_application_title(m_move_app_entity_title);
    pacs_configuration->set_move_application_port(m_move_port);
    pacs_configuration->set_retrieve_method(m_retrieve_method);
}

//------------------------------------------------------------------------------

service::connections_t pacs_configuration_initializer::auto_connections() const
{
    service::connections_t connections;

    connections.push(
        CONFIG_INOUT,
        sight::io::dimse::data::pacs_configuration::MODIFIED_SIG,
        service::slots::UPDATE
    );

    return connections;
}

//------------------------------------------------------------------------------

void pacs_configuration_initializer::updating()
{
    const auto pacs_configuration = m_config.lock();
    SIGHT_ASSERT("inout '" << CONFIG_INOUT << "' does not exist.", pacs_configuration);

    // Check if the user has changed the Pacs configuration and update the local var
    if(pacs_configuration->get_local_application_title() != m_scu_app_entity_title
       || pacs_configuration->get_pacs_host_name() != m_scp_host_name
       || pacs_configuration->get_pacs_application_title() != m_scp_app_entity_title
       || pacs_configuration->get_pacs_application_port() != m_scp_port
       || pacs_configuration->get_move_application_title() != m_move_app_entity_title
       || pacs_configuration->get_move_application_port() != m_move_port
       || pacs_configuration->get_retrieve_method() != m_retrieve_method)
    {
        m_scu_app_entity_title  = pacs_configuration->get_local_application_title();
        m_scp_host_name         = pacs_configuration->get_pacs_host_name();
        m_scp_app_entity_title  = pacs_configuration->get_pacs_application_title();
        m_scp_port              = pacs_configuration->get_pacs_application_port();
        m_move_app_entity_title = pacs_configuration->get_move_application_title();
        m_move_port             = pacs_configuration->get_move_application_port();
        m_retrieve_method       = pacs_configuration->get_retrieve_method();
    }

    // If a preference key is set, save the local var to the preferences
    if(!m_preference_key.empty())
    {
        try
        {
            ui::preferences preferences;

            preferences.put(get_key(LOCAL_APPLICATION_TITLE), m_scu_app_entity_title);
            preferences.put(get_key(PACS_HOST_NAME), m_scp_host_name);
            preferences.put(get_key(PACS_APPLICATION_TITLE), m_scp_app_entity_title);
            preferences.put(get_key(PACS_APPLICATION_PORT), m_scp_port);
            preferences.put(get_key(MOVE_APPLICATION_TITLE), m_move_app_entity_title);
            preferences.put(get_key(MOVE_APPLICATION_PORT), m_move_port);
            preferences.put(get_key(RETRIEVE_METHOD), static_cast<int>(m_retrieve_method));
        }
        catch(const ui::preferences_disabled& /*e*/)
        {
            // Nothing to do..
        }
    }
}

//------------------------------------------------------------------------------

void pacs_configuration_initializer::stopping()
{
    this->updating();
}

} // namespace sight::module::io::dimse