summaryrefslogtreecommitdiff
path: root/ACE/TAO/orbsvcs/tests/Bug_2377_Regression/Hello_Impl.cpp
blob: cd1f6e360cf484b878d870a445556c13a964fa0a (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
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
//
// $Id$
//

#include "Hello_Impl.h"

Hello_Impl::Hello_Impl (CORBA::ORB_ptr orb, MessageLog *log)
  : orb_ (CORBA::ORB::_duplicate (orb))
  , logger_ (log)
{
}

void
Hello_Impl::say_hello (CORBA::Short count)
{
  this->logger_->register_message_recv (count);
}

void
Hello_Impl::shutdown ()
{
  try
    {
      this->orb_->shutdown (0);
    }
  catch (const CORBA::Exception& ex)
    {
      //FUZZ: disable check_for_lack_ACE_OS
      ex._tao_print_exception ("Exception caught in shutdown ():");
      //FUZZ: enable check_for_lack_ACE_OS
    }
}

MessageLog::MessageLog (int num, bool sprs)
  : expected_ (num)
  , overdoseS_ (0)
  , overdoseR_ (0)
  , supress_ (sprs)
{
  this->sent_ = new int[this->expected_];
  this->rcvd_ = new int[this->expected_];

  int i;
  for (i = 0; i < this->expected_; i++)
    {
      this->sent_[i] = 0;
      this->rcvd_[i] = 0;
    }
}

MessageLog::~MessageLog ()
{
  delete [] this->sent_;
  delete [] this->rcvd_;
}

void
MessageLog::register_message_send (int message_num)
{
  ACE_Guard<ACE_Mutex> guard(this->mutex_);
  if (0 <= message_num && message_num < this->expected_)
    {
      this->sent_[message_num]++;
    }
  else
    {
      this->overdoseS_++;
    }
  
  if (!this->supress_)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "%02d>>; ",
                  message_num));
    }
}

void
MessageLog::register_message_recv (int message_num)
{
  ACE_Guard<ACE_Mutex> guard(this->mutex_);
  if (0 <= message_num && message_num < this->expected_)
    {
      this->rcvd_[message_num]++;
    }
  else
    {
      this->overdoseR_++;
    }

  if (!this->supress_)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "%02d<<; ",
                  message_num));
    }
}

int
MessageLog::report_statistics ()
{
  int i;
  int lmco = 0;

  for (i = 0; i < this->expected_; i++)
    {
      lmco += this->sent_[i] - this->rcvd_[i];

      if (this->sent_[i] > 1 && !this->supress_)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "\nSENT message <<< %d >>> %d times",
                      i, this->sent_[i]));
        }

      if (this->rcvd_[i] > 1 && !this->supress_)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "\nRECEIVED message <<< %d >>> %d times",
                      i, this->rcvd_[i]));
        }

      if (this->sent_[i] != this->rcvd_[i] && !this->supress_)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "\nLOST message <<< %d >>> %d times",
                      i, this->sent_[i] - this->rcvd_[i]));
        }
    }

  if (this->overdoseS_ != 0 && !this->supress_)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "\nSent more than expected."));
    }

  if (this->overdoseR_ != 0 && !this->supress_)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "\nReceived more than expected."));
    }

  return lmco;
}