File: PeerFixtureBase.h

package info (click to toggle)
odil 0.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 5,092 kB
  • sloc: cpp: 54,080; python: 3,896; xml: 182; makefile: 94
file content (61 lines) | stat: -rw-r--r-- 1,720 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
#ifndef _b21e8d37_0125_4d64_84aa_f91d9d96612b
#define _b21e8d37_0125_4d64_84aa_f91d9d96612b

#include <cstdint>
#include <cstdlib>
#include <string>
#include <vector>

#include <boost/lexical_cast.hpp>

#include "odil/Association.h"
#include "odil/AssociationParameters.h"

/// @brief Base class for fixtures of requiring a working association.
class PeerFixtureBase
{
public:
    typedef
        odil::AssociationParameters::PresentationContext PresentationContext;
    odil::Association association;

    PeerFixtureBase(std::vector<PresentationContext> const & contexts)
    {
        this->association.set_peer_host(
            this->get_environment_variable("ODIL_PEER_HOST_NAME"));
        this->association.set_peer_port(
            this->get_environment_variable<uint16_t>("ODIL_PEER_PORT"));
        this->association.update_parameters()
            .set_calling_ae_title(
                this->get_environment_variable("ODIL_OWN_AET"))
            .set_called_ae_title(
                this->get_environment_variable("ODIL_PEER_AET"))
            .set_presentation_contexts(contexts);

        this->association.associate();
    }

    ~PeerFixtureBase()
    {
        this->association.release();
    }

    static std::string get_environment_variable(std::string const & name)
    {
        char* value = getenv(name.c_str());
        if(value == NULL)
        {
            BOOST_FAIL(name + " is not defined");
        }
        return value;
    }

    template<typename T>
    static T get_environment_variable(std::string const & name)
    {
        return boost::lexical_cast<T>(
            PeerFixtureBase::get_environment_variable(name));
    }
};

#endif // _b21e8d37_0125_4d64_84aa_f91d9d96612b