File: AssociationParameters.cpp

package info (click to toggle)
odil 0.13.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,476 kB
  • sloc: cpp: 55,982; python: 3,947; javascript: 460; xml: 182; makefile: 99; sh: 36
file content (257 lines) | stat: -rw-r--r-- 9,420 bytes parent folder | download | duplicates (4)
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*************************************************************************
 * odil - Copyright (C) Universite de Strasbourg
 * Distributed under the terms of the CeCILL-B license, as published by
 * the CEA-CNRS-INRIA. Refer to the LICENSE file or to
 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
 * for details.
 ************************************************************************/

#include <algorithm>
#include <memory>

#include <pybind11/pybind11.h>
#include <pybind11/operators.h>

#include "odil/AssociationParameters.h"

#include "opaque_types.h"
#include "type_casters.h"

namespace
{

odil::AssociationParameters::PresentationContext
presentation_context_constructor(
    uint8_t id, std::string const & abstract_syntax,
    pybind11::sequence transfer_syntaxes,
    odil::AssociationParameters::PresentationContext::Role role)
{

    std::vector<std::string> transfer_syntaxes_cpp(
        pybind11::len(transfer_syntaxes));
    std::transform(
        transfer_syntaxes.begin(), transfer_syntaxes.end(),
        transfer_syntaxes_cpp.begin(),
        [](pybind11::handle const & item) {
            return item.cast<std::string>();
        });
    return odil::AssociationParameters::PresentationContext(
        id, abstract_syntax, transfer_syntaxes_cpp, role);
}

odil::AssociationParameters::PresentationContext
presentation_context_simplified_constructor(
    std::string const & abstract_syntax,
    pybind11::sequence transfer_syntaxes,
    odil::AssociationParameters::PresentationContext::Role role)
{

    std::vector<std::string> transfer_syntaxes_cpp(len(transfer_syntaxes));
    std::transform(
        transfer_syntaxes.begin(), transfer_syntaxes.end(),
        transfer_syntaxes_cpp.begin(),
        [](pybind11::handle const & item) {
            return item.cast<std::string>();
        });
    return odil::AssociationParameters::PresentationContext(
        abstract_syntax, transfer_syntaxes_cpp, role);
}

pybind11::list
get_presentation_contexts(odil::AssociationParameters const & parameters)
{
    pybind11::list presentation_contexts_python;
    for(auto const & presentation_context: parameters.get_presentation_contexts())
    {
        presentation_contexts_python.append(presentation_context);
    }

    return presentation_contexts_python;
}

odil::AssociationParameters &
set_presentation_contexts(
    odil::AssociationParameters & parameters,
    pybind11::sequence const & presentation_contexts)
{
    std::vector<odil::AssociationParameters::PresentationContext> 
        presentation_contexts_cpp;
    presentation_contexts_cpp.reserve(pybind11::len(presentation_contexts));
    for(pybind11::handle const & item: presentation_contexts)
    {
        presentation_contexts_cpp.push_back(
            item.cast<odil::AssociationParameters::PresentationContext>());
    }
    parameters.set_presentation_contexts(presentation_contexts_cpp);
    
    return parameters;
}

}

void wrap_AssociationParameters(pybind11::module & m)
{
    using namespace pybind11;
    using namespace pybind11::literals;
    using namespace odil;

    auto association_parameters_scope =
        class_<AssociationParameters>(m, "AssociationParameters")
        .def(init<>())
        // TODO Construct from PDU
        .def(
            "get_called_ae_title",
            &AssociationParameters::get_called_ae_title,
            return_value_policy::copy)
        .def(
            "set_called_ae_title",
            &AssociationParameters::set_called_ae_title,
            return_value_policy::copy)
        .def(
            "get_calling_ae_title",
            &AssociationParameters::get_calling_ae_title,
            return_value_policy::copy)
        .def(
            "set_calling_ae_title",
            &AssociationParameters::set_calling_ae_title,
            return_value_policy::reference_internal)
        .def("get_presentation_contexts", &get_presentation_contexts)
        .def(
            "set_presentation_contexts", &set_presentation_contexts,
            return_value_policy::reference_internal)
        .def(
            "get_user_identity", &AssociationParameters::get_user_identity,
            return_value_policy::reference_internal)
        .def(
            "set_user_identity_to_none",
            &AssociationParameters::set_user_identity_to_none,
            return_value_policy::reference_internal)
        .def(
            "set_user_identity_to_username",
            &AssociationParameters::set_user_identity_to_username,
            return_value_policy::reference_internal)
        .def(
            "set_user_identity_to_username_and_password",
            &AssociationParameters::set_user_identity_to_username_and_password,
            return_value_policy::reference_internal)
        .def(
            "set_user_identity_to_kerberos",
            &AssociationParameters::set_user_identity_to_kerberos,
            return_value_policy::reference_internal)
        .def(
            "set_user_identity_to_saml",
            &AssociationParameters::set_user_identity_to_saml,
            return_value_policy::reference_internal)
        .def("get_maximum_length", &AssociationParameters::get_maximum_length)
        .def(
            "set_maximum_length",
            &AssociationParameters::set_maximum_length,
            return_value_policy::reference_internal)
    ;

    {
        auto presentation_context_scope =
            class_<AssociationParameters::PresentationContext>(
                association_parameters_scope, "PresentationContext");

        enum_<AssociationParameters::PresentationContext::Result>(
                presentation_context_scope, "Result")
            .value(
                "Acceptance",
                AssociationParameters::PresentationContext::Result::Acceptance
            )
            .value(
                "UserRejection",
                AssociationParameters::PresentationContext::Result::UserRejection
            )
            .value(
                "NoReason",
                AssociationParameters::PresentationContext::Result::NoReason
            )
            .value(
                "AbstractSyntaxNotSupported",
                AssociationParameters::PresentationContext::Result::AbstractSyntaxNotSupported
            )
            .value(
                "TransferSyntaxesNotSupported",
                AssociationParameters::PresentationContext::Result::TransferSyntaxesNotSupported
            )
        ;
        
        enum_<AssociationParameters::PresentationContext::Role>(
                presentation_context_scope, "Role")
            .value(
                "Unspecified",
                AssociationParameters::PresentationContext::Role::Unspecified
            )
            .value("None", AssociationParameters::PresentationContext::Role::None)
            .value("SCU", AssociationParameters::PresentationContext::Role::SCU)
            .value("SCP", AssociationParameters::PresentationContext::Role::SCP)
            .value("Both", AssociationParameters::PresentationContext::Role::Both)
        ;

        // WARNING using STL conversion
        // (https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html)
        // conflicts with opaque types required to avoid copying data set values
        presentation_context_scope
            .def(init(&presentation_context_constructor))
            .def(init(&presentation_context_simplified_constructor))
            .def_readwrite(
                "id",
                &AssociationParameters::PresentationContext::id
            )
            .def_readwrite(
                "abstract_syntax",
                &AssociationParameters::PresentationContext::abstract_syntax
            )
            .def_readwrite(
                "transfer_syntaxes",
                &AssociationParameters::PresentationContext::transfer_syntaxes
            )
            .def_readwrite(
                "role", &AssociationParameters::PresentationContext::role
            )
            .def_readwrite(
                "result",
                &AssociationParameters::PresentationContext::result
            )
            .def(self == self)
        ;


    }

    {
        auto user_identity_scope =
            class_<AssociationParameters::UserIdentity>(
                association_parameters_scope, "UserIdentity")
            .def(init<>())
            .def_readwrite(
                "type", &AssociationParameters::UserIdentity::type
            )
            .def_readwrite(
                "primary_field", 
                &AssociationParameters::UserIdentity::primary_field
            )
            .def_readwrite(
                "secondary_field", 
                &AssociationParameters::UserIdentity::secondary_field
            )
            .def(self == self)
        ;

        enum_<AssociationParameters::UserIdentity::Type>(user_identity_scope, "Type")
            .value("None", AssociationParameters::UserIdentity::Type::None)
            .value(
                "Username", AssociationParameters::UserIdentity::Type::Username
            )
            .value(
                "UsernameAndPassword", 
                AssociationParameters::UserIdentity::Type::UsernameAndPassword
            )
            .value(
                "Kerberos", AssociationParameters::UserIdentity::Type::Kerberos)
            .value("SAML", AssociationParameters::UserIdentity::Type::SAML)
        ;
    }
}