summaryrefslogtreecommitdiff
path: root/TAO/tao/Transport_Selection_Guard.cpp
blob: cd79ab92d66c6b1de34d60e1bbe160df6c3de758 (plain)
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
// -*- C++ -*-
#include "tao/Transport_Selection_Guard.h"
#include "tao/TSS_Resources.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

namespace TAO
{
  Transport_Selection_Guard*
  Transport_Selection_Guard::current (TAO_ORB_Core* core, size_t tss_slot_id)
  {
    // @NOTE: (Iliyan) Started making this method aware of the core
    // and the tss slot that correspond to the "current" transport,
    // influenced by a general design preference to keep things
    // local. The idea was to make the current TSG part of the TSS
    // storage for a specific ORB Core, as opposed to using the global
    // TSS Resources. However, it really doesn't offer any benefit to
    // store a Transport pointer locally, for each ORB. There is
    // always only one current Transport per thread. Period. The
    // number of ORB Core instances in existence does not change that
    // fact, so keeping a separate pointer would have been an
    // over-kill.
    ACE_UNUSED_ARG (core);
    ACE_UNUSED_ARG (tss_slot_id);

#if TAO_HAS_TRANSPORT_CURRENT == 1
    return TAO_TSS_Resources::instance ()->tsg_;
#else  /* TAO_HAS_TRANSPORT_CURRENT != 1 */
    return 0;
#endif  /* TAO_HAS_TRANSPORT_CURRENT == 1 */
  }

  /// Ctor
  Transport_Selection_Guard::Transport_Selection_Guard (TAO_Transport* t)
    :
#if TAO_HAS_TRANSPORT_CURRENT == 1
    prev_ (TAO_TSS_Resources::instance ()->tsg_) ,
#endif  /* TAO_HAS_TRANSPORT_CURRENT == 1 */
    curr_ (t)
  {
#if TAO_HAS_TRANSPORT_CURRENT == 1
    TAO_TSS_Resources::instance ()->tsg_ = this;
#endif  /* TAO_HAS_TRANSPORT_CURRENT == 1 */
  }

  /// Dtor
  Transport_Selection_Guard::~Transport_Selection_Guard ()
  {
#if TAO_HAS_TRANSPORT_CURRENT == 1
    TAO_TSS_Resources::instance ()->tsg_ = prev_;
    this->prev_ = nullptr;
#endif  /* TAO_HAS_TRANSPORT_CURRENT == 1 */
    this->curr_ = nullptr;
  }

  bool
  operator== (const Transport_Selection_Guard& lhs,
              const TAO_Transport* rhs)
  {
    return lhs.curr_ == rhs;
  }

  bool
  operator== (const TAO_Transport* lhs,
              const Transport_Selection_Guard& rhs)
  {
    return lhs == rhs.curr_;
  }

  bool
  operator!= (const Transport_Selection_Guard& lhs,
              const TAO_Transport* rhs)
  {
    return lhs.curr_ != rhs;
  }

  bool
  operator!= (const TAO_Transport* lhs,
              const Transport_Selection_Guard& rhs)
  {
    return lhs != rhs.curr_;
  }
} /* namespace TAO */

TAO_END_VERSIONED_NAMESPACE_DECL