Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / examples / Notify / Federation / SpaceCraft / SpaceCraft.cpp
blob546218fb178a39d59a76b30f75825ba4bca41180
1 // file : SpaceCraft.cpp
2 // author : Boris Kolpackov <boris@dre.vanderbilt.edu>
3 #include "tao/corba.h"
5 #include "orbsvcs/CosNotificationC.h"
6 #include "orbsvcs/CosNotifyChannelAdminC.h"
7 #include "orbsvcs/CosNotifyCommC.h"
8 #include "orbsvcs/CosNotifyCommS.h"
10 // For in-process Notification Service.
12 #include "orbsvcs/Notify/Service.h"
13 #include "orbsvcs/Notify/CosNotify_Initializer.h" // NS static link helper.
16 #include "Gate/Gate.h"
18 #include <iostream>
19 #include <sstream>
21 using std::cerr;
22 using std::endl;
24 using namespace CORBA;
25 using namespace CosNotifyComm;
26 using namespace CosNotifyFilter;
27 using namespace CosNotification;
28 using namespace CosNotifyChannelAdmin;
30 int
31 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
33 try
35 ORB_var orb (ORB_init (argc, argv));
37 if (argc < 2)
39 ACE_ERROR ((LM_ERROR,
40 "Usage: %s <space-craft-name>={a, b, c}\n",
41 argv[0]));
42 return 1;
45 // Activate the root POA.
47 CORBA::Object_var obj (
48 orb->resolve_initial_references ("RootPOA"));
50 PortableServer::POA_var root_poa (PortableServer::POA::_narrow (obj.in ()));
52 PortableServer::POAManager_var poa_manager (root_poa->the_POAManager ());
54 poa_manager->activate ();
57 // Initialize Notification Service.
59 TAO_Notify_Service* ns = TAO_Notify_Service::load_default ();
61 if (ns == 0)
63 ACE_ERROR ((LM_ERROR,
64 "Notification Service not found! check svc.conf\n"));
65 return -1;
69 ns->init_service (orb.in ());
71 // Create the channel factory.
73 EventChannelFactory_var factory (ns->create (root_poa.in ()));
75 if (is_nil (factory.in ()))
77 ACE_ERROR ((LM_ERROR,
78 "Unable to create channel factory\n"));
79 return 1;
82 // Create the channel.
84 QoSProperties qosp;
85 AdminProperties ap;
86 ChannelID id;
88 EventChannel_var channel (factory->create_channel (qosp, ap, id));
90 // Create and install the filter. We want to reduce the amount
91 // of dicovery messages that are propagated between space crafts.
93 FilterFactory_var filter_factory (channel->default_filter_factory ());
94 Filter_var filter (filter_factory->create_filter ("EXTENDED_TCL"));
96 ConstraintExpSeq constraints (1);
97 constraints.length (1);
99 constraints[0].event_types.length (0);
100 constraints[0].constraint_expr = string_dup (
101 "$domain_name == 'Aerospace' and "
102 "$type_name == 'AgentDiscovery' and "
103 "($.counter - 3 * ($.counter / 3)) == 0");// ETCL (or TAO) doesn't have %?
105 filter->add_constraints (constraints);
107 AdminID admin_id = 0;
108 ConsumerAdmin_var consumer_admin (
109 channel->new_for_consumers (AND_OP, admin_id));
111 consumer_admin->add_filter (filter.in ());
113 // Find which space craft we are.
115 ACE_INET_Addr space_craft_addr;
116 const ACE_TCHAR *space_craft_name = argv[1];
118 // Do a quick mapping to mcast addresses.
120 switch (space_craft_name[0])
122 case 'a':
124 space_craft_addr = ACE_INET_Addr ("224.1.0.1:10000");
125 break;
127 case 'b':
129 space_craft_addr = ACE_INET_Addr ("224.1.0.2:10000");
130 break;
132 case 'c':
134 space_craft_addr = ACE_INET_Addr ("224.1.0.3:10000");
135 break;
137 default:
139 ACE_ERROR ((LM_ERROR,
140 "Space craft name should be either 'a', 'b', or 'c'.\n"));
141 return 1;
145 // Create the SpaceCraft <=> Channel gate.
147 Gate space_craft_gate (space_craft_addr,
148 consumer_admin.in (),
149 channel->default_supplier_admin ());
152 // Create the Channel <=> Constellation gate.
154 ACE_INET_Addr constellation_addr ("224.1.1.1:10000");
155 Gate constellation_gate (constellation_addr, channel.in ());
157 orb->run ();
159 return 0;
161 catch (const CORBA::UserException& ue)
163 ue._tao_print_exception ("User exception: ");
164 return 1;
166 catch (const CORBA::SystemException& se)
168 se._tao_print_exception ("System exception: ");
169 return 1;
172 return 1;