forked from RedhawkSDR/Documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainch17.html
599 lines (570 loc) · 28.8 KB
/
mainch17.html
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html >
<head><title>17 Messaging</title>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8"">
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)">
<meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)">
<!-- html,2,next,javascript,charset="utf-8" -->
<meta name="src" content="main.tex">
<meta name="date" content="2013-03-12 19:46:00">
<link rel="stylesheet" type="text/css" href="main.css">
<script type="text/javascript" src="scripts/shCore.js"></script>
<script type="text/javascript" src="scripts/shBrushCpp.js"></script>
<script type="text/javascript" src="scripts/shBrushJava.js"></script>
<script type="text/javascript" src="scripts/shBrushPython.js"></script>
<script type="text/javascript" src="scripts/shBrushBash.js"></script>
<script type="text/javascript" src="scripts/shBrushXml.js"></script>
<link href="styles/shCore.css" rel="stylesheet" type="text/css" />
<link href="styles/shThemeDefault.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
SyntaxHighlighter.all()
</script>
</head><body
>
<script>
function f() {
document.getElementById('main_content_wrap').focus();
}
if (window.addEventListener) {
window.addEventListener("load", f, false);
} else if (window.attachEvent) {
window.attachEvent("onload", f);
}
</script>
<div class="header">
<ul class="navbar">
<li><a class="logo-small" href="index.html"><img src="images/RedHawk_Logo_ALT_B_121px.png"/></a></li> <li><a href="index.html">Home</a></li>
<li><a href="gettingstarted/main.html">Getting Started</a></li>
<li><a class="active" href="main.html">Documentation</a></li>
<li><a href="download.html">Download</a></li>
<li><a href="support.html">Support</a></li>
</ul>
<div class="pattern right"></div>
<a id="forkme_banner" href="https://github.com/redhawksdr">View on GitHub</a>
</div>
<!-- Custom MAIN CONTENT -->
<div id="main_content_wrap" tabindex="0" class="outer">
<section id="main_content" class="inner">
<!--l. 1--><div class="crosslinks"><p class="noindent">[<a
href="mainch18.html" >next</a>] [<a
href="mainch16.html" >prev</a>] [<a
href="mainch16.html#tailmainch16.html" >prev-tail</a>] [<a
href="#tailmainch17.html">tail</a>] [<a
href="main.html#mainch17.html" >up</a>] </p></div>
<h2 class="chapterHead"><span class="titlemark">Chapter 17</span><br /><a
id="x19-23100017"></a>Messaging</h2>
<h3 class="sectionHead"><span class="titlemark">17.1 </span> <a
id="x19-23200017.1"></a>Introduction</h3>
<!--l. 6--><p class="noindent" >Messaging relies on <a
href="mainap3.html#corba">CORBA</a>’s event structure as a transport structure. In <a
href="mainap3.html#corba">CORBA</a>’s event <a
href="mainap3.html#api">API</a>,
<a
href="mainli2.html#glo:message">Messages</a> are passed as an <span
class="cmtt-12">Any </span>type using the function <span
class="cmtt-12">push()</span>.
<!--l. 9--><p class="noindent" >While <a
href="mainap3.html#corba">CORBA</a> manages marshaling and delivery of the data, it does not provide any
mechanisms inherent to events to describe the contents of the <span
class="cmtt-12">Any </span>type. REDHAWK
decided to leverage an existing payload structure descriptor to describe the payload of
<a
href="mainli2.html#glo:message">Messages</a>, the <a
href="mainli2.html#glo:property">Properties</a> <a
href="mainap3.html#idl">IDL</a>. The selection of this interface eliminates the need to create a
new <a
href="mainap3.html#idl">IDL</a> describing <a
href="mainli2.html#glo:message">Messages</a>. Furthermore, there is already an <a
href="mainap3.html#xml">XML</a> structure that is
mapped to efficient binary data structures, allowing the use of <a
href="mainap3.html#xml">XML</a> to describe <a
href="mainli2.html#glo:message">Message</a>
contents while eliminating the need for introducing <a
href="mainap3.html#xml">XML</a> parsers in the <a
href="mainli2.html#glo:message">Message</a> delivery
mechanism.
<!--l. 14--><p class="noindent" >To support this additional functionality, REDHAWK has expanded the <a
href="mainli2.html#glo:property">Properties</a> descriptor to
allow a <a
href="mainli2.html#glo:property">Property</a> to have the kind <a
href="mainli2.html#glo:message"><span
class="cmbx-12">Message</span></a>. The only <a
href="mainli2.html#glo:property">Property</a> that can have a valid <a
href="mainli2.html#glo:message"><span
class="cmbx-12">Message</span></a>
kind is a structure.
<!--l. 17--><p class="noindent" >
<h3 class="sectionHead"><span class="titlemark">17.2 </span> <a
id="x19-23300017.2"></a>Message Producer</h3>
<!--l. 19--><p class="noindent" >To create a <a
href="mainli2.html#glo:message">Message</a> producer, create a new <a
href="mainli2.html#glo:component">Component</a> or edit an existing <a
href="mainli2.html#glo:component">Component</a>.
<!--l. 21--><p class="noindent" >
<ol class="enumerate1" >
<li
class="enumerate" id="x19-233002x1">Add a Struct <a
href="mainli2.html#glo:property">Property</a>
<ul class="itemize1">
<li class="itemize">Select the kind for the <a
href="mainli2.html#glo:property">Property</a> as only <a
href="mainli2.html#glo:message"><span
class="cmbx-12">Message</span></a>
</li>
<li class="itemize">Add any arbitrary number of members to the struct</li></ul>
</li>
<li
class="enumerate" id="x19-233004x2">Add <span
class="cmbx-12">uses </span><a
href="mainli2.html#glo:port">Port</a> of <a
href="mainap3.html#idl">IDL</a> Interface ExtendedEvent <span
class="cmmi-12">> </span>MessageEvent
</li>
<li
class="enumerate" id="x19-233006x3">Regenerate the <a
href="mainli2.html#glo:component">Component</a></li></ol>
<!--l. 31--><p class="noindent" >For the purposes of the following examples, assume that the structure is as follows:
<ul class="itemize1">
<li class="itemize">name: <span
class="cmtt-12">foo</span>
</li>
<li class="itemize">Contains two members:
<ul class="itemize2">
<li class="itemize">name: <span
class="cmtt-12">some</span><span
class="cmtt-12">_string</span>, type: <span
class="cmtt-12">string</span>
</li>
<li class="itemize">name: <span
class="cmtt-12">some</span><span
class="cmtt-12">_float</span>, type: <span
class="cmtt-12">float</span></li></ul>
</li></ul>
<!--l. 42--><p class="noindent" >The <a
href="mainli2.html#glo:component">Component</a>’s uses <a
href="mainli2.html#glo:port">Port</a> is called <span
class="cmtt-12">message</span><span
class="cmtt-12">_out</span>
<!--l. 44--><p class="noindent" >If a connection exists between this <a
href="mainli2.html#glo:component">Component</a> and either a <a
href="mainli2.html#glo:message">Message</a> consumer or an <a
href="mainli2.html#glo:eventchannel">Event
Channel</a>, the following code examples will send a <a
href="mainli2.html#glo:message">Message</a>.
<!--l. 46--><p class="noindent" >
<h4 class="subsectionHead"><span class="titlemark">17.2.1 </span> <a
id="x19-23400017.2.1"></a>C++</h4>
<!--l. 48--><p class="noindent" >Whenever a <a
href="mainli2.html#glo:message">Message</a> needs to be generated (e.g., in the <span
class="cmtt-12">serviceFunction() </span>method of the
implementation file):
<script type="syntaxhighlighter" class="brush: cpp"><![CDATA[
foo_struct my_msg;
my_msg.some_string = "hello";
my_msg.some_float = 1.0;
this->message_out->sendMessage(my_msg);
]]></script>
<!--l. 57--><p class="noindent" >
<h4 class="subsectionHead"><span class="titlemark">17.2.2 </span> <a
id="x19-23500017.2.2"></a>Java</h4>
<!--l. 59--><p class="noindent" >Whenever a <a
href="mainli2.html#glo:message">Message</a> needs to be generated (e.g., in the <span
class="cmtt-12">run() </span>method): <script type="syntaxhighlighter" class="brush: java"><![CDATA[
foo_struct my_msg = new foo_struct();
my_msg.some_string.setValue("hello");
my_msg.some_float.setValue((float)1.0);
this.port_message_out.sendMessage(my_msg);
]]></script>
<!--l. 68--><p class="noindent" >
<h4 class="subsectionHead"><span class="titlemark">17.2.3 </span> <a
id="x19-23600017.2.3"></a>Python</h4>
<!--l. 70--><p class="noindent" >Whenever a <a
href="mainli2.html#glo:message">Message</a> needs to be generated (e.g., in the <span
class="cmtt-12">process() </span>method of the implementation
file):
<script type="syntaxhighlighter" class="brush: python"><![CDATA[
my_msg = Foo()
my_msg.some_string = 'hello'
my_msg.some_float = 1.0
self.port_message_out.sendMessage(my_msg)
]]></script>
<!--l. 81--><p class="noindent" >
<h3 class="sectionHead"><span class="titlemark">17.3 </span> <a
id="x19-23700017.3"></a>Message Consumer</h3>
<!--l. 83--><p class="noindent" >To create a <a
href="mainli2.html#glo:message">Message</a> consumer, create a new <a
href="mainli2.html#glo:component">Component</a> or edit an existing <a
href="mainli2.html#glo:component">Component</a>.
<ol class="enumerate1" >
<li
class="enumerate" id="x19-237002x1">Add a Struct <a
href="mainli2.html#glo:property">Property</a>
<ul class="itemize1">
<li class="itemize">Select the kind for the <a
href="mainli2.html#glo:property">Property</a> as only <a
href="mainli2.html#glo:message"><span
class="cmbx-12">Message</span></a>
</li>
<li class="itemize">Add any arbitrary number of members to the struct</li></ul>
</li>
<li
class="enumerate" id="x19-237004x2">Add <span
class="cmbx-12">uses/provides </span>(bidirectional) <a
href="mainli2.html#glo:port">Port</a> of <a
href="mainap3.html#idl">IDL</a> <br
class="newline" /><span
class="cmtt-12">Interface ExtendedEvent</span><span
class="cmmi-12">> </span><span
class="cmtt-12">MessageEvent</span>
</li>
<li
class="enumerate" id="x19-237006x3">Regenerate the <a
href="mainli2.html#glo:component">Component</a></li></ol>
<!--l. 94--><p class="noindent" >The bidirectional <a
href="mainli2.html#glo:port">Port</a> is needed because in point-to-point connections, the <a
href="mainli2.html#glo:port">Port</a> behaves like a
Provides <a
href="mainli2.html#glo:port">Port</a>, while in connections with an <a
href="mainli2.html#glo:eventchannel">Event Channel</a>, the consumer behaves like a Uses <a
href="mainli2.html#glo:port">Port</a>.
This is an artifact of mapping a uses/provides pattern over a producer/consumer pattern. A single
object is created for the <a
href="mainli2.html#glo:port">Port</a>, and a call to <span
class="cmtt-12">getPort() </span>returns a pointer to the same object
irrespective of whether or not the <a
href="mainli2.html#glo:port">Port</a> is to be employed as a Uses or Provides; the object
implements both sets of interfaces. The <a
href="mainap3.html#scd">SCD</a> will contain two entries for this <a
href="mainli2.html#glo:port">Port</a>, both with the
same name, but one a uses and the other a provides.
<!--l. 99--><p class="noindent" >For the purposes of the following examples, assume that the structure is as follows:
<ul class="itemize1">
<li class="itemize">name: <span
class="cmtt-12">foo</span>
</li>
<li class="itemize">Contains two members:
<ul class="itemize2">
<li class="itemize">name: <span
class="cmtt-12">some</span><span
class="cmtt-12">_string</span>, type: <span
class="cmtt-12">string</span>
</li>
<li class="itemize">name: <span
class="cmtt-12">some</span><span
class="cmtt-12">_float</span>, type: <span
class="cmtt-12">float</span></li></ul>
</li></ul>
<!--l. 109--><p class="noindent" >The <a
href="mainli2.html#glo:component">Component</a>’s uses/provides <a
href="mainli2.html#glo:port">Port</a> is called <span
class="cmtt-12">message</span><span
class="cmtt-12">_in</span>
<!--l. 111--><p class="noindent" >The <a
href="mainli2.html#glo:component">Component</a>’s callback function for this <a
href="mainli2.html#glo:message">Message</a> is <span
class="cmtt-12">receivedMessage()</span>
<!--l. 113--><p class="noindent" >The <a
href="mainli2.html#glo:component">Component</a>’s name is <span
class="cmtt-12">message</span><span
class="cmtt-12">_consumer</span>
<!--l. 115--><p class="noindent" >If a connection exists between this <a
href="mainli2.html#glo:component">Component</a> and either a <a
href="mainli2.html#glo:message">Message</a> producer or an <a
href="mainli2.html#glo:eventchannel">Event
Channel</a>, the following code examples will process an incoming <a
href="mainli2.html#glo:message">Message</a>.
<!--l. 118--><p class="noindent" >
<h4 class="subsectionHead"><span class="titlemark">17.3.1 </span> <a
id="x19-23800017.3.1"></a>C++</h4>
<!--l. 120--><p class="noindent" >Given the asynchronous nature of events, a callback pattern was selected for the consumer.
<!--l. 122--><p class="noindent" >In the <a
href="mainli2.html#glo:component">Component</a> header file, declare the following callback function: <script type="syntaxhighlighter" class="brush: cpp"><![CDATA[
void receivedMessage(const std::string &id,
const foo_struct &msg);
]]></script>
<!--l. 128--><p class="noindent" >In the <a
href="mainli2.html#glo:component">Component</a> source file, implement the callback function: <script type="syntaxhighlighter" class="brush: cpp"><![CDATA[
void message_consumer_i::receivedMessage(const std::string &id,
const foo_struct &msg) {
std::cout<<id<<" "<<msg.some_float<<" "<<msg.some_string<<
std::endl;
}
]]></script>
<!--l. 137--><p class="noindent" >In the <a
href="mainli2.html#glo:component">Component</a> constructor, register the callback function: <script type="syntaxhighlighter" class="brush: cpp"><![CDATA[
message_in->registerMessage("foo", this,
&message_consumer_i::receivedMessage);
]]></script>
<!--l. 143--><p class="noindent" >
<h4 class="subsectionHead"><span class="titlemark">17.3.2 </span> <a
id="x19-23900017.3.2"></a>Java</h4>
<!--l. 145--><p class="noindent" >Add to the list of import packages: <script type="syntaxhighlighter" class="brush: java"><![CDATA[
import org.omg.CORBA.Any;
]]></script>
<!--l. 150--><p class="noindent" >Add the callback definition to the class after the <span
class="cmtt-12">run() </span>method.
<!--l. 152--><p class="noindent" ><span
class="cmbx-12">NOTE: the </span><span
class="cmtt-12">message() </span><span
class="cmbx-12">method is </span><a
href="mainli2.html#glo:message"><span
class="cmbx-12">Message</span></a> <span
class="cmbx-12">specific and must contain structure-specific code</span>: <script type="syntaxhighlighter" class="brush: java"><![CDATA[
public class callback implements
EventCallback<message_prop_struct> {
private test_message_rx_java parent;
public Object handlingMessagesLock;
public callback(test_message_rx_java _parent) {
this.parent = _parent;
this.handlingMessagesLock = new Object();
}
public void message(String id, Any msg) {
synchronized (this.handlingMessagesLock) {
CF.DataType [] msg_set =
(DataType[])AnyUtils.convertAny(msg);
message_prop_struct msg_container =
new message_prop_struct();
for (final DataType msg_item : msg_set) {
if (msg_item.id.equals("val1")) {
msg_container.val1.setValue(
msg_item.value.extract_string());
}
if (msg_item.id.equals("val2")) {
msg_container.val2.setValue(
msg_item.value.extract_double());
}
}
this.messageReceived(id, msg_container);
}
}
public void messageReceived(String id,
message_prop_struct msg) {
synchronized (this.handlingMessagesLock) {
String msg_out = id+","+msg.val1.getValue()+","+
msg.val2.getValue();
System.out.println("messageReceived " + msg_out);
}
}
}
]]></script>
<!--l. 196--><p class="noindent" >Add the <span
class="cmtt-12">callbackContainer </span>class variable after the <span
class="cmtt-12">MessageConsumerPort </span>declaration: <script type="syntaxhighlighter" class="brush: java"><![CDATA[
public callback callbackContainer;
]]></script>
<!--l. 201--><p class="noindent" >In the <span
class="cmtt-12">test</span><span
class="cmtt-12">_message</span><span
class="cmtt-12">_rx</span><span
class="cmtt-12">_java() </span>class constructor, create an instance of <span
class="cmtt-12">callbackContainer</span>: <script type="syntaxhighlighter" class="brush: java"><![CDATA[
this.callbackContainer = new callback(this);
]]></script>
<!--l. 206--><p class="noindent" >In the <span
class="cmtt-12">initialize() </span>method after <span
class="cmtt-12">super.initialize()</span>, register the <a
href="mainli2.html#glo:message">Message</a> with the callback
method. <span
class="cmbx-12">NOTE: This must occur in </span><span
class="cmtt-12">initialize() </span><span
class="cmbx-12">not the class constructor because the</span>
<a
href="mainli2.html#glo:message"><span
class="cmbx-12">Message</span></a> <span
class="cmbx-12">consumer object is not setup yet when the constructor is called. </span><script type="syntaxhighlighter" class="brush: java"><![CDATA[
this.port_message_in.registerMessage("message_prop",
this.callbackContainer);
]]></script>
<!--l. 213--><p class="noindent" >
<h4 class="subsectionHead"><span class="titlemark">17.3.3 </span> <a
id="x19-24000017.3.3"></a>Python</h4>
<!--l. 215--><p class="noindent" >To the <span
class="cmtt-12">initialize() </span>method, register the expected <a
href="mainli2.html#glo:message">Message</a> with a callback method: <script type="syntaxhighlighter" class="brush: python"><![CDATA[
self.port_message_in.registerMessage("message_prop",
test_message_rx_python_base.MessageProp, self.messageReceived)
]]></script>
<!--l. 221--><p class="noindent" >In the class, define the callback method. In this example, the method is called <span
class="cmtt-12">messageReceived()</span>: <script type="syntaxhighlighter" class="brush: python"><![CDATA[
def messageReceived(self, msgId, msgData):
self._log.info("messageReceived *************************");
self._log.info("messageReceived msgId " + str(msgId));
self._log.info("messageReceived msgData " + str(msgData));
]]></script>
<!--l. 229--><p class="noindent" >
<h3 class="sectionHead"><span class="titlemark">17.4 </span> <a
id="x19-24100017.4"></a>Viewing Messages</h3>
<!--l. 231--><p class="noindent" ><a
href="mainli2.html#glo:message">Messages</a> are events with their payload definition tied to structures in <a
href="mainli2.html#glo:component">Component</a> <a
href="mainli2.html#glo:property">Properties</a>.
Viewing <a
href="mainli2.html#glo:message">Messages</a> can be done with the same techniques that are used to view events.
<!--l. 234--><p class="noindent" >To view events and <a
href="mainli2.html#glo:message">Messages</a> sent to an <a
href="mainli2.html#glo:eventchannel">Event Channel</a> in a terminal window: <script type="syntaxhighlighter" class="brush: bash"><![CDATA[
eventviewer <domain name> <event channel>
]]></script>
<!--l. 239--><p class="noindent" >Help for the utility: <script type="syntaxhighlighter" class="brush: bash"><![CDATA[
eventviewer --help
]]></script>
<!--l. 244--><p class="noindent" >Example output: <script type="syntaxhighlighter" class="brush: bash"><![CDATA[
\$ eventviewer REDHAWK_DEV testchan
Receiving events. Press 'enter' key to exit
[{'id': 'message_prop', 'value': [{'id': 'val1', 'value': 'some
string'}, {'id': 'val2', 'value': 0.0}]}]
[{'id': 'message_prop', 'value': [{'id': 'val1', 'value': 'some
string'}, {'id': 'val2', 'value': 1.0}]}]
[{'id': 'message_prop', 'value': [{'id': 'val1', 'value': 'some
string'}, {'id': 'val2', 'value': 2.0}]}]
[{'id': 'message_prop', 'value': [{'id': 'val1', 'value': 'some
string'}, {'id': 'val2', 'value': 3.0}]}]
[{'id': 'message_prop', 'value': [{'id': 'val1', 'value': 'some
string'}, {'id': 'val2', 'value': 4.0}]}]
[{'id': 'message_prop', 'value': [{'id': 'val1', 'value': 'some
string'}, {'id': 'val2', 'value': 5.0}]}]
[{'id': 'message_prop', 'value': [{'id': 'val1', 'value': 'some
string'}, {'id': 'val2', 'value': 6.0}]}]
[{'id': 'message_prop', 'value': [{'id': 'val1', 'value': 'some
string'}, {'id': 'val2', 'value': 7.0}]}]
[{'id': 'message_prop', 'value': [{'id': 'val1', 'value': 'some
string'}, {'id': 'val2', 'value': 8.0}]}]
[{'id': 'message_prop', 'value': [{'id': 'val1', 'value': 'some
string'}, {'id': 'val2', 'value': 9.0}]}]
]]></script>
<!--l. 270--><p class="noindent" >
<h3 class="sectionHead"><span class="titlemark">17.5 </span> <a
id="x19-24200017.5"></a>Connecting Producers and Consumers</h3>
<!--l. 272--><p class="noindent" >Producers and consumers can be connected either point-to-point or through an <a
href="mainli2.html#glo:eventchannel">Event
Channel</a>.
<!--l. 274--><p class="noindent" >Connecting a producer directly to a consumer does not require an <a
href="mainli2.html#glo:application">Application</a> and can be done in the Sandbox: <script type="syntaxhighlighter" class="brush: python"><![CDATA[
>>> from ossie.utils import sb
>>> sb.catalog()
['structs_test', 'm_in', 'prop_changes', 'm_out',
'pass']
>>> prod=sb.Component('m_out')
>>> cons=sb.Component('m_in')
>>> prod.connect(cons)
True
>>> sb.start()
>>> foo 0 hello
foo 1 hello
foo 2 hello
foo 3 hello
foo 4 hello
foo 5 hello
foo 6 hello
]]></script>
<!--l. 294--><p class="noindent" >Connecting producers to consumers through an <a
href="mainli2.html#glo:eventchannel">Event Channel</a> requires an <a
href="mainli2.html#glo:application">Application</a>. An
<a
href="mainli2.html#glo:application">Application</a> can also support point-to-point connections.
<!--l. 296--><p class="noindent" >Below is a description of how to establish connections through an <a
href="mainli2.html#glo:eventchannel">Event Channel</a>:
<ol class="enumerate1" >
<li
class="enumerate" id="x19-242002x1">Add producer and consumer <a
href="mainli2.html#glo:component">Components</a>
</li>
<li
class="enumerate" id="x19-242004x2">For point-to-point messaging, connect output <span
class="cmtt-12">MessageEvent </span><a
href="mainli2.html#glo:port">Port</a> , <span
class="cmtt-12">message</span><span
class="cmtt-12">_out </span>in
this example, to the input <span
class="cmtt-12">MessageEvent </span><a
href="mainli2.html#glo:port">Port</a> of the receive <a
href="mainli2.html#glo:component">Component</a>.
</li>
<li
class="enumerate" id="x19-242006x3">For messaging via an <a
href="mainli2.html#glo:eventchannel">Event Channel</a>, add an <a
href="mainli2.html#glo:eventchannel">Event Channel</a> to the <a
href="mainli2.html#glo:waveformapplication">Waveform</a> and connect to
it
<ol class="enumerate2" >
<li
class="enumerate" id="x19-242008x1">In the <a
href="mainli2.html#glo:waveform">SCA Waveform</a> Diagram, under <span
class="cmbx-12">Palette </span><span
class="cmmi-12">> </span><span
class="cmbx-12">Find By:</span>
<ul class="itemize1">
<li class="itemize">Left-click <span
class="cmbx-12">FindBy </span>and drop in diagram. If necessary, the <span
class="cmbx-12">FindBy </span>box can
be expanded by left-click and drag in the diagram.
</li>
<li class="itemize">Left-click <span
class="cmbx-12">Domain Finder </span>and drag into <span
class="cmbx-12">FindBy </span>box dropped previously
into the diagram.
</li>
<li class="itemize">From the pull-down in the <span
class="cmbx-12">Domain Finder </span>box, select <span
class="cmbx-12">eventchannel</span>
</li>
<li class="itemize">Give the <a
href="mainli2.html#glo:eventchannel">Event Channel</a> a name by left-clicking on the <span
class="cmbx-12">Domain Finder </span>box.
If <a
href="mainli2.html#glo:property">Properties</a> tab view is not visible, right-click on the box and select <span
class="cmbx-12">Show</span>
<span
class="cmbx-12">Properties View</span>. Once in the Properties view, enter the <a
href="mainli2.html#glo:eventchannel">Event Channel</a>
name into the <span
class="cmbx-12">Value </span>portion next to the <a
href="mainli2.html#glo:property"><span
class="cmbx-12">Property</span></a> Name. In my example, I
have called the <a
href="mainli2.html#glo:eventchannel">Event Channel</a> <span
class="cmtt-12">testchan</span>.</li></ul>
</li>
<li
class="enumerate" id="x19-242010x2">Connect the Uses (Output) <span
class="cmtt-12">MessageEvent </span><a
href="mainli2.html#glo:port">Port</a> of the sending <a
href="mainli2.html#glo:component">Component</a>, called
<span
class="cmtt-12">message</span><span
class="cmtt-12">_out </span>in my example, to the <a
href="mainli2.html#glo:eventchannel">Event Channel</a>.
</li>
<li
class="enumerate" id="x19-242012x3">Connect the Uses (Output) <span
class="cmtt-12">MessageEvent </span><a
href="mainli2.html#glo:port">Port</a> of the receiving <a
href="mainli2.html#glo:component">Component</a>, called
<span
class="cmtt-12">message</span><span
class="cmtt-12">_in</span>, to the <a
href="mainli2.html#glo:eventchannel">Event Channel</a>. Note this is the <span
class="cmbx-12">black </span>Output <a
href="mainli2.html#glo:port">Port</a> that must be
connected to the <a
href="mainli2.html#glo:eventchannel">Event Channel</a>.</li></ol>
</li></ol>
<!--l. 313--><p class="noindent" >In this example, connections are made point-to-point and through the <a
href="mainli2.html#glo:eventchannel">Event Channel</a>. Therefore,
for every <a
href="mainli2.html#glo:message">Message</a> sent, two <a
href="mainli2.html#glo:message">Messages</a> are received.
<!--l. 1--><div class="crosslinks"><p class="noindent">[<a
href="mainch18.html" >next</a>] [<a
href="mainch16.html" >prev</a>] [<a
href="mainch16.html#tailmainch16.html" >prev-tail</a>] [<a
href="mainch17.html" >front</a>] [<a
href="main.html#mainch17.html" >up</a>] </p></div>
<!--l. 1--><p class="noindent" ><a
id="tailmainch17.html"></a>
<div class=license>
<hr>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.en_US"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/80x15.png" /></a><br /><span xmlns:dct="http:// purl.org/dc/terms/" property="dct:title">REDHAWK Documentation</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.en_US">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.
</div>
</body></html>