summaryrefslogtreecommitdiff
path: root/TAO/tao/PI_Server/PICurrent_Guard.cpp
blob: 9aff070ca96351f03fb7989e3c86880c22577847 (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
#include "PICurrent_Guard.h"

#if TAO_HAS_INTERCEPTORS == 1


ACE_RCSID (PortableServer,
           PICurrent_Guard,
           "$Id$")


#include "tao/ORB_Core.h"
#include "tao/TAO_Server_Request.h"
#include "tao/PI/PICurrent_Copy_Callback.h"
#include "tao/PI/PICurrent.h"
#include "tao/PI/PICurrent_Impl.h"

TAO::PICurrent_Guard::PICurrent_Guard (TAO_ServerRequest &server_request,
                                       bool tsc_to_rsc)
  : src_ (0),
    dest_ (0),
    copy_callback_ (server_request.pi_current_copy_callback ()),
    tsc_to_rsc_ (tsc_to_rsc)
{
  // This constructor is used on the server side.

  // Retrieve the thread scope current (no TSS access incurred yet).
  CORBA::Object_ptr pi_current_obj =
    server_request.orb_core ()->pi_current ();

  TAO::PICurrent *pi_current =
    dynamic_cast <TAO::PICurrent*> (pi_current_obj);

  // If the slot count is zero, there is nothing to copy.  Prevent any
  // copying (and hence TSS accesses) from occurring.
  if (pi_current != 0 && pi_current->slot_count () != 0)
    {
      // Retrieve the request scope current.
      PICurrent_Impl * rsc = server_request.rs_pi_current ();

      // Retrieve the thread scope current.
      PICurrent_Impl * tsc = pi_current->tsc ();

      if (tsc_to_rsc)
        {
          // TSC to RSC copy.
          // Occurs after receive_request() interception point and
          // upcall.
          this->src_  = tsc;
          this->dest_ = rsc;
        }
      else
        {
          // RSC to TSC copy.
          // Occurs after receive_request_service_contexts()
          // interception point.
          this->src_  = rsc;
          this->dest_ = tsc;
        }
    }
}

TAO::PICurrent_Guard::~PICurrent_Guard (void)
{
  if (this->src_ != 0 && this->dest_ != 0
      && this->src_ != this->dest_)
    {
      // This copy better be exception-safe!
      this->dest_->lc_slot_table (this->src_);

      // PICurrent will potentially have to call back on the request
      // scope current so that it can deep copy the contents of the
      // thread scope current if the contents of the thread scope
      // current are about to be modified.  It is necessary to do this
      // deep copy once in order to completely isolate the request
      // scope current from the thread scope current.  This is only
      // necessary, if the thread scope current is modified after its
      // contents have been *logically* copied to the request scope
      // current.  The same goes for the reverse, i.e. RSC to TSC.
      this->copy_callback_->src_and_dst (this->src_, this->dest_);
      this->src_->copy_callback (this->copy_callback_);
    }
}


#endif  /* TAO_HAS_INTERCEPTORS == 1 */