summaryrefslogtreecommitdiff
path: root/tests/Bug_3068_Regression/test_i.cpp
blob: 0aed21b49f2759714f3800fc0bc6b8f7568d1945 (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
// $Id$

#include "test_i.h"

#include "tao/ORB_Core.h"
#include "tao/debug.h"
#include "tao/Transport_Cache_Manager.h"
#include "tao/Thread_Lane_Resources.h"
#include "ace/OS_NS_unistd.h"

#if !defined(__ACE_INLINE__)
#include "test_i.inl"
#endif /* __ACE_INLINE__ */

ACE_RCSID (Bug_3068_Regression, test_i, "$Id$")

void
Callback_i::shutdown ()
{
  ACE_DEBUG ((LM_DEBUG, "Performing clean shutdown\n"));
  this->orb_->shutdown (0);
}

void
Callback_i::callback_method (const CORBA::OctetSeq &)
{
  static int count = 0;
  if (count++ > 0)
    ACE_OS::exit(0);
}


// ****************************************************************

CORBA::Long
Simple_Server_i::test_method (CORBA::Boolean do_callback)
{
  if (do_callback && this->caller_ != 0)
    {
      this->caller_->go ();
    }

  return 0;
}


void
Simple_Server_i::ow_test ()
{
  int iter = this->ow_count_++;
  ACE_DEBUG ((LM_DEBUG, "%t: Invoking ow test, iter = %d\n", iter));
}

void
Simple_Server_i::callback_object (Callback_ptr callback)
{
  this->caller_ = new Caller (callback, orb_.in ());
}

Caller::Caller (Callback_ptr callback, CORBA::ORB_ptr orb)
  : cbobj_ (Callback::_duplicate (callback))
  , orb_ (CORBA::ORB::_duplicate (orb))
  , cond_ (this->lock_)
  , going_ (false)
{
  this->payload_.length (0); //10000);
  this->activate (THR_JOINABLE | THR_NEW_LWP, 4);
  ACE_OS::sleep (1);
  ACE_DEBUG ((LM_DEBUG, "%t returning\n"));
}

void
Caller::go ()
{
  this->lock_.acquire ();
  this->going_ = true;
  this->cond_.broadcast ();
  this->lock_.release ();
}

int
Caller::svc ()
{
  this->lock_.acquire ();
  ACE_DEBUG ((LM_DEBUG, "%t Getting ready to call\n"));
  while (!this->going_) this->cond_.wait ();
  this->lock_.release ();
  try
    {
      while (1)
        {
          ACE_DEBUG ((LM_DEBUG, "%t calling, payload len = %d\n",
                      payload_.length ()));
          this->cbobj_->callback_method (this->payload_);
          ACE_DEBUG ((LM_DEBUG, "%t callback returned\n"));
          ACE_Time_Value tv (0, 100);
          ACE_OS::sleep (tv);
        }
    }
  catch (CORBA::Exception &ex)
    {
      ACE_DEBUG ((LM_DEBUG, "%t caught: %C\n", ex._name ()));
    }
  try
    {
      ACE_OS::sleep (1);
      this->orb_->shutdown (0);
    }
  catch (CORBA::Exception &ex)
    {
      ACE_DEBUG ((LM_DEBUG, "%t orb shutdown raised %C\n", ex._name ()));
    }
  return 0;
}

void
Simple_Server_i::shutdown ()
{
  this->orb_->shutdown (0);
}