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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--// -->
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252">
<TITLE>AMICCM Tutorial Hello - Implementation exec</TITLE>
</HEAD>
<BODY>
<TABLE WIDTH="100%" BORDER=0 CELLPADDING=2 CELLSPACING=2 STYLE="PAGE-BREAK-BEFORE: always">
<TR>
<TD ALIGN=left><A href="03_executors.html">Previous</A></TD>
<TD ALIGN=center></TD>
<TD ALIGN=right><A href="05_compilation.html">Next</A></TD>
</TR></TABLE>
<HR>
<H1>Implementation executors</H1>
<H2 CLASS="western">AMI4CCM basics</H2>
<UL>
<LI><P>The writer has basically only to write 3 idl files, first the
one that defines the common interface between the Sender and
Receiver , second the interface for the Sender and third the
interface for the Receiver. In this tutorial are that the IDL files
Hello_MyFoo_obj.idl, Hello_Sender_comp.idl and the
Hello_Receiver_comp.idl.<BR>
Naturally, it is possible that there are more IDL-files
to be used, as in this example the Hello_Common_defn.idl file for the common
definitions.</P></LI>
<LI><P>The Receiver component ('server') has no idea which
component (AMI connector or Sender) uses his interface.</P></LI>
<LI><P>The Connector, the AMI-Component, will be generated by
the IDL compiler by implying ami4ccm.idl</P></LI>
<LI><P>In the Sender executor the handling of the AMI
callbacks and also the asynchronous and synchronous invocations must be
coded.</P></LI>
</UL>
<H2 CLASS="western">Example</H2>
<P>The Sender component of this Hello tutorial invokes some
asynchronous methods and some synchronous methods. For asynchronous invocations,
the Sender component uses the AMI4CCM_MyFoo_obj interface of the AMI component
and provides the AMI4CCM_MyFoo_objReplyHandler interface to the AMI
component.</P>
<P>For synchronous invocations, the Sender component uses
the MyFoo_obj interface (which the Receiver provides).</P>
<P STYLE="MARGIN-BOTTOM: 0cm">The receiver just implements
the interface provided by the application programmer. The Receiver should have
no idea which component (in this case Sender or AMI) uses his interface!</P>
<p><B><u>Sender_comp_exec.cpp</u></B><br><br>
In de ccm_activate method, first retrieve the
receptacles:<br>
Asynchronous:<br><CODE>::Hello::AMI4CCM_MyFoo_obj_var asynch_foo<B> = </B><FONT COLOR="#0000ff">this</FONT>->context_->
get_connection_sendc_run_my_foo();</CODE><br>
Synchronous:<br>
<CODE>::Hello::MyFoo_obj_var synch_foo = <FONT COLOR="#0000ff">this</FONT>->context_->get_connection_run_my_foo ();</CODE>
</P>
<P>After retrieving the receptacles, make the desired
asynchronus and synchronous invocations.<br>
The asynchronous methods have the prefix sendc_. The first
argument is the Reply handler.<br>
<CODE>my_foo_ami_->sendc_foo (<FONT COLOR="blue">new</FONT> AMI4CCM_MyFoo_objReplyHandler_run_my_foo_i (), <FONT COLOR="red">"Do something
asynchronous"</FONT>);</CODE><br>
The same synchronous method:<br>
<CODE>CORBA::Long result = my_foo_ami_->foo(<FONT COLOR="red">"Do something synchronous"</FONT>, out_str.out());</P>
<P>For the asynchronus methods the implied Reply Handler
interface for each method must be coded.</P>
<P>Example foo callback:<br>
<CODE><FONT COLOR="#0000ff">void<BR></FONT>
AMI4CCM_MyFoo_objReplyHandler_run_my_foo_i::foo (::CORBA::Long
ami_return_val, <FONT COLOR="blue">const char</FONT> * answer)<BR>
{<BR>
<FONT COLOR="green"> /*Your code here. */<BR></FONT>
</FONT><FONT COLOR="#000000">
ACE_DEBUG
((LM_DEBUG,<BR>
ACE_TEXT(<FONT COLOR="red">"Sender:\tMyFoo AMI Callback from
foo:"</FONT>);<BR> ACE_TEXT(<FONT COLOR="red">"result <%u> answer
<%C>\n"</FONT>),<BR> ami_return_val,answer));<BR>
}<br><br>
<FONT COLOR="blue">void<BR></FONT>
AMI4CCM_MyFoo_objReplyHandler_run_my_foo_i::foo_excep (::CCM_AMI::ExceptionHolder * excep_holder)<BR>
{<BR>
<FONT COLOR="green"> /* Your code here. */</FONT><BR>
}</CODE></P>
<P><B><u>Receiver_comp_exec.cpp</u></B></P>
<P> In this file the interface methods must be programmed.<br><br>
Example foo method:<br>
<CODE>::CORBA::Long MyFoo_obj_exec_i::foo (<FONT COLOR="#0000ff">const char</FONT> * in_str, ::CORBA::String_out answer)<BR>
{<BR> <FONT color="green">/* Your code here. */</FONT><BR>
answer = CORBA::string_dup (<FONT COLOR="red">"This is my answer : Hi"</FONT>);<BR>
return ACE_OS::rand () % 100;<BR>
}</CODE>
</P>
<TABLE WIDTH="100%" BORDER=0 CELLPADDING=2 CELLSPACING=2>
<TR>
<TD ALIGN=left><A href="03_executors.html">Previous</A></TD>
<TD ALIGN=center></TD>
<TD ALIGN=right><A href="05_compilation.html">Next</A></TD></TR></TABLE>
<P><BR><BR></P>
</BODY>
</HTML>
|