summaryrefslogtreecommitdiff
path: root/trunk/TAO/orbsvcs/tests/CosEvent/Timeout/TestEventConsumer_i.cpp
blob: 3756ba12c543c049a0deb9419121b7e392cbe223 (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 "TestEventConsumer_i.h"

#include "ace/Log_Msg.h"


TestEventConsumer_i::TestEventConsumer_i (CORBA::ORB_ptr orb, bool hang)
  : orb_ (CORBA::ORB::_duplicate (orb)),
    hang_ (hang),
    count_ (0),
    orbtask_ (orb),
    cond_ (this->mtx_),
    shutdown_ (false)
{
}

void
TestEventConsumer_i::activate ()
{
  this->orbtask_.activate ();
}

int
TestEventConsumer_i::ORB_task::svc ()
{
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TestEventConsumer_i ORB_task starting\n")));
  try
    {
      this->orb_->run ();
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TestEventConsumer_i ORB_task "
                                      "exiting\n")));
    }
  catch (CORBA::SystemException &e)
    {
      e._tao_print_exception (
        ACE_TEXT (
          "TestEventConsumer_i ORB_task: ""Caught CORBA::Exception:"));
    }
  return 0;
}


void
TestEventConsumer_i::push (const CORBA::Any & data)
  throw (CORBA::SystemException, CosEventComm::Disconnected)
{
  // Extract event data from the any.
  const char *eventData;
  if (data >>= eventData)
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TestEventConsumer_i::push(): Received "
                                      "event containing %d bytes.\n"),
                                      ACE_OS::strlen (eventData)));
      if (this->hang_ && ++this->count_ == 10)
        {
          ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TestEventConsumer_i::push(): "
                                          "Simulating hung consumer\n")));
          {
            ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->mtx_);
            while (!this->shutdown_)
              this->cond_.wait ();
          }
          ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TestEventConsumer_i::push Done\n")
                      ));
        }
    }
}

void
TestEventConsumer_i::disconnect_push_consumer ()
 throw (CORBA::SystemException)
{
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("TestEventConsumer_i::disconnect_push_consumer()\n")));
  this->orb_->shutdown ();
  this->shutdown_ = true;
  this->cond_.signal ();
}