summaryrefslogtreecommitdiff
path: root/TAO/tests/AMI_Buffering/AMI_Buffering.cpp
blob: a85b561d23e6af42eda70f15f56fc3770e631213 (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
//
// $Id$
//
#include "AMI_Buffering.h"

ACE_RCSID(AMI_Buffering, AMI_Buffering, "$Id$")

AMI_Buffering::AMI_Buffering (CORBA::ORB_ptr orb,
                              Test::AMI_Buffering_Admin_ptr admin)
  : orb_ (CORBA::ORB::_duplicate (orb)),
    admin_ (Test::AMI_Buffering_Admin::_duplicate (admin)),
    nest_ (0),
    max_nest_ (0),
    must_shutdown_ (false)
{
}

AMI_Buffering::Nest_Guard::Nest_Guard (AMI_Buffering &a)
  :target_(a)
{
  ++target_.nest_;
  if (target_.nest_ > target_.max_nest_)
    target_.max_nest_ = target_.nest_;
}

AMI_Buffering::Nest_Guard::~Nest_Guard (void)
{
  --target_.nest_;
}

void
AMI_Buffering::receive_data (const Test::Payload &the_payload)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  try
    {
      AMI_Buffering::Nest_Guard ng(*this);
      this->admin_->request_received (the_payload.length ());
    }
  catch (const CORBA::Exception&)
    {
      ACE_DEBUG ((LM_DEBUG,"(%P|%t) DEBUG: AMI_Buffering::receive_data"));
    }

  this->try_shutdown();
}

void
AMI_Buffering::flush (void)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
}

void
AMI_Buffering::sync (void)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  this->admin_->flush ();
}

void
AMI_Buffering::shutdown (void)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  this->must_shutdown_ = true;
  this->try_shutdown();
}

void
AMI_Buffering::try_shutdown(void)
{
  if (!this->must_shutdown_ || this->nest_ > 0)
    return;
  if (this->max_nest_ > 1)
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) max nesting level: %d\n", max_nest_));
  this->admin_->shutdown();

  this->orb_->shutdown (0);
}