blob: f166a3d1257ad8a23e286f17dee22179219fe589 (
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
113
114
115
116
117
118
119
120
121
|
// $Id$
// EchoEventSupplierMain.cpp
// Main program for a PushSupplier of Echo events.
#include "EchoEventSupplier_i.h"
#include "orbsvcs/RtecEventCommC.h"// for Event Communication interfaces
#include "orbsvcs/RtecEventChannelAdminC.h"
#include "orbsvcs/Time_Utilities.h"
#include "orbsvcs/Event_Utilities.h"
#include "orbsvcs/CosNamingC.h"// for Naming Service interfaces
#include <iostream>
const RtecEventComm::EventSourceID MY_SOURCE_ID_START = ACE_ES_EVENT_SOURCE_ANY + 1;
const RtecEventComm::EventSourceID MY_SOURCE_ID_END = ACE_ES_EVENT_SOURCE_ANY + 3;
const RtecEventComm::EventType MY_EVENT_START = ACE_ES_EVENT_UNDEFINED + 1;
const RtecEventComm::EventType MY_EVENT_END = ACE_ES_EVENT_UNDEFINED + 4;
const int EVENT_DELAY_MS = 10;
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
// Initialize the ORB.
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
// Find the Naming Service.
CORBA::Object_var obj = orb->resolve_initial_references("NameService");
CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in());
// Get the Event Channel using Naming Services
obj = root_context->resolve_str("EventService");
// Downcast the object reference to an EventChannel reference.
RtecEventChannelAdmin::EventChannel_var ec =
RtecEventChannelAdmin::EventChannel::_narrow(obj.in());
if (CORBA::is_nil(ec.in())) {
std::cerr << "Could not resolve EchoEventChannel." << std::endl;
return 1;
}
// Get a SupplierAdmin object from the EventChannel.
RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers();
// Get a ProxyPushConsumer from the SupplierAdmin.
RtecEventChannelAdmin::ProxyPushConsumer_var consumer =
admin->obtain_push_consumer();
// Get the RootPOA.
obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
// Instantiate an EchoEventConsumer_i servant.
PortableServer::Servant_var<EchoEventSupplier_i> servant =
new EchoEventSupplier_i(orb.in());
// Register it with the RootPOA.
PortableServer::ObjectId_var oid = poa->activate_object(servant.in());
CORBA::Object_var supplier_obj = poa->id_to_reference(oid.in());
RtecEventComm::PushSupplier_var supplier =
RtecEventComm::PushSupplier::_narrow(supplier_obj.in());
// Publish the events the supplier provides.
ACE_SupplierQOS_Factory qos;
RtecEventComm::EventSourceID supplier_id = MY_SOURCE_ID_START;
for (; supplier_id <= MY_SOURCE_ID_END; ++supplier_id) {
RtecEventComm::EventType event_type = MY_EVENT_START;
for (; event_type <= MY_EVENT_END; ++event_type)
{
qos.insert (supplier_id, event_type,
0, // handle to the rt_info structure
1); // number of calls
}
}
// Connect as a supplier of the published events.
consumer->connect_push_supplier (supplier.in (), qos.get_SupplierQOS ());
// Create an event (just a string in this case).
const CORBA::String_var eventData = CORBA::string_dup("Hello, world.");
// Create an event set for one event
RtecEventComm::EventSet event (1);
event.length (1);
// Initialize event header.
event[0].header.source = MY_SOURCE_ID_START;
event[0].header.type = MY_EVENT_START;
// Initialize data fields in event.
event[0].data.any_value <<= eventData;
std::cout << "Supplier starting sending events.\n";
while (1) {
event[0].header.type++;
if (event[0].header.type > MY_EVENT_END) {
event[0].header.type = MY_EVENT_START;
}
event[0].header.source++;
if (event[0].header.source > MY_SOURCE_ID_END) {
event[0].header.source = MY_SOURCE_ID_START;
}
consumer->push (event);
ACE_Time_Value tv(0, EVENT_DELAY_MS * 1000);
orb->run(tv);
}
orb->destroy();
return 0;
}
catch(const CORBA::Exception& exc)
{
std::cerr << "Caught CORBA::Exception" << std::endl << exc << std::endl;
}
return 1;
}
|