summaryrefslogtreecommitdiff
path: root/TAO/DevGuideExamples/BiDirectionalGIOP/simple_i.cpp
blob: ed01838377c487d64a0ef84ed7e0989354706078 (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
// $Id$

#include "bidir_giop_pch.h"

#include "simple_i.h"

#include "tao/ORB_Core.h"
#include "tao/Transport_Cache_Manager.h"
#include "tao/Thread_Lane_Resources.h"

#include <iostream>

Simple_i::Simple_i (CORBA::ORB_ptr orb, int callback_count)
: orb_(CORBA::ORB::_duplicate(orb))
, ready_for_callback_(0)
, callback_count_(callback_count)
, callback_(0)
{
}

Simple_i::~Simple_i (void)
{
}

CORBA::Long Simple_i::test_method (CORBA::Boolean do_callback)
{
  if (do_callback) {
    ready_for_callback_ = 1;
  }
  return 0;
}

void Simple_i::callback_object (Callback_ptr cb)
{
  callback_ = Callback::_duplicate(cb);
}

void Simple_i::shutdown ()
{
  const int wait = 0;
  orb_->shutdown(wait);
}

int
Simple_i::call_client()
{
  if (ready_for_callback_) {

    ready_for_callback_ = 0;

    for (int times = 0; times < callback_count_; ++times) {

      callback_->callback_method();

      if (orb_->orb_core()->lane_resources().transport_cache().current_size() > 1)
      {
        std::cerr << "The connection cache has grown.  "
          << "BiDirection did not work. aborting..." << std::endl;
        ACE_OS::abort(); // Should probably define and throw a UserException
      }
    }

    callback_->shutdown();

    return 1;
  }

  return 0;
}