1 // file : SpaceCraft.cpp
2 // author : Boris Kolpackov <boris@dre.vanderbilt.edu>
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"
24 using namespace CORBA
;
25 using namespace CosNotifyComm
;
26 using namespace CosNotifyFilter
;
27 using namespace CosNotification
;
28 using namespace CosNotifyChannelAdmin
;
31 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
35 ORB_var
orb (ORB_init (argc
, argv
));
40 "Usage: %s <space-craft-name>={a, b, c}\n",
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 ();
64 "Notification Service not found! check svc.conf\n"));
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 ()))
78 "Unable to create channel factory\n"));
82 // Create the channel.
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])
124 space_craft_addr
= ACE_INET_Addr ("224.1.0.1:10000");
129 space_craft_addr
= ACE_INET_Addr ("224.1.0.2:10000");
134 space_craft_addr
= ACE_INET_Addr ("224.1.0.3:10000");
139 ACE_ERROR ((LM_ERROR
,
140 "Space craft name should be either 'a', 'b', or 'c'.\n"));
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 ());
161 catch (const CORBA::UserException
& ue
)
163 ue
._tao_print_exception ("User exception: ");
166 catch (const CORBA::SystemException
& se
)
168 se
._tao_print_exception ("System exception: ");