summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Miop/McastFragmentation/Hello_Impl.cpp
blob: 906ffd17cccd91a99061098cb525f25118de3ee1 (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
//
// $Id$
//

#include "Hello_Impl.h"

UIPMC_Object_Impl::UIPMC_Object_Impl (CORBA::ULong payload,
                                      CORBA::ULong clients,
                                      CORBA::ULong calls)
  : payload_ (payload)
  , clients_ (clients)
  , calls_ (calls)
{
}

UIPMC_Object_Impl::~UIPMC_Object_Impl (void)
{
  if (this->received_.current_size () == 0)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("ERROR: expected %d clients but only %d encountered\n"),
                  this->clients_, this->received_.current_size ()));
      return;
    }

  for (CORBA::ULong i = 0; i < this->clients_; ++i)
    {
      CORBA::ULong count = 0;
      this->received_.find (Test::ClientIDs[i], count);

      if (count != this->calls_)
        // This perfectly ok for MIOP to lose messages.
        // So, this is not an error.
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("DEBUG: expected %d messages from '%c' client ")
                    ACE_TEXT ("but only %d encountered\n"),
                    this->calls_, Test::ClientIDs[i], count));
    }
}

void
UIPMC_Object_Impl::process (Test::Octets const &payload)
{
  if (this->payload_ != payload.length ())
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("ERROR: expected %d but received %d ")
                  ACE_TEXT ("sequence length\n"),
                  this->payload_, payload.length ()));
      return;
    }

  CORBA::ULong count = 0;
  CORBA::Octet c = payload[0];
  this->received_.find (c, count);

  Test::Octets seq (this->payload_);
  seq.length (this->payload_);
  CORBA::Octet *buff = seq.get_buffer ();
  ACE_OS::memset (buff, c, this->payload_);
  char *one = static_cast<char *> (static_cast<void *> (buff));
  char const *two = static_cast<char const *> (
    static_cast<void const *> (payload.get_buffer ()));
  if (ACE_OS::strncmp (one, two, this->payload_) != 0)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("ERROR: received malformed message from client '%c'\n"),
                  c));
      return;
    }

  if (ACE_OS::strchr (Test::ClientIDs, c) == 0)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("ERROR: client id '%c' doesn't match any known value\n"),
                  c));
      return;
    }

  ++count;
  if (this->received_.rebind (c, count) == -1)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("ERROR: cann't rebind received count\n")));
    }
}

Hello_Impl::Hello_Impl (CORBA::ORB_ptr orb,
                        Test::UIPMC_Object_ptr obj)
  : orb_ (CORBA::ORB::_duplicate (orb))
  , obj_ (Test::UIPMC_Object::_duplicate (obj))
{
}

Test::UIPMC_Object_ptr
Hello_Impl::get_object (void)
{
  return Test::UIPMC_Object::_duplicate (this->obj_.in ());
}

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