summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Notify/Bug_1884_Regression/common.h
blob: 18df456f8d420176bc590d98653100887bc55a91 (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
// $Id$

#include "orbsvcs/orbsvcs/CosNotifyChannelAdminC.h"
#include "orbsvcs/orbsvcs/CosNotifyChannelAdminS.h"
#include <iostream>
const char *ior = "file://ecf.ior";

CosNotifyChannelAdmin::EventChannel_var 
get_event_channel(CORBA::ORB_ptr orb)

{
  CosNotifyChannelAdmin::EventChannel_var ec;
  CosNotifyChannelAdmin::ChannelID id;
  CosNotification::QoSProperties init_qos(0);
  CosNotification::AdminProperties init_admin(0);

  std::cout << "Get CosNotifyChannelAdmin::EventChannelFactory"  << std::endl;
  std::cout << "IorEventChannelFactory=" << ior << std::endl;
  CORBA::Object_var obj = orb->string_to_object(ior);

  if (CORBA::is_nil(obj.in ()))
  {
    std::cerr << "Bad ec_fact.ior " << std::endl; 
    ACE_OS::exit (1);    
  }

  CosNotifyChannelAdmin::EventChannelFactory_var factory =
    CosNotifyChannelAdmin::EventChannelFactory::_narrow(obj.in ());
  if (CORBA::is_nil(factory.in()))
  {
    std::cerr << "Could not _narrow object to type CosNotifyChannelAdmin::EventChannelFactory" << std::endl;
    ACE_OS::exit(1);
  }

  //Get the first ec
  CosNotifyChannelAdmin::ChannelIDSeq_var channelIdSeq;
  try
  {
    channelIdSeq = factory->get_all_channels();
  }
  catch (CORBA::SystemException& se )
  {
    std::cerr << "System exception occurred during get_all_channels: " 
      << se << std::endl;
    throw;
  }

  if( channelIdSeq->length() == 0 )
  {
    try 
    {
      ec = factory->create_channel( init_qos, init_admin, id);
    }
    catch (CORBA::SystemException& se )
    {
      std::cerr << "System exception occurred during find_channel: " 
        << se << std::endl;
      throw;
    }
  }
  else {
    try
    {
      ec = factory->get_event_channel(channelIdSeq[0]);
    }
    catch (CosNotifyChannelAdmin::ChannelNotFound& )
    {
      std::cerr << "ChannelNotFound: " 
        << channelIdSeq[0] << std::endl;
      throw;
    }

    catch (CORBA::SystemException& se )
    {
      std::cerr << "System exception occurred during get_event_channel: " 
        << se << std::endl;
      throw;
    }
  }

  return ec._retn();
}