Salome HOME
This commit was generated by cvs2git to create tag 'V1_4_0b1'.
[modules/kernel.git] / doc / html / INPUT / sources / static / examples_Life_cycle.html
1 <!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">\r
2 <html>\r
3 <head>\r
4     \r
5   <meta http-equiv="Content-Type"\r
6  content="text/html; charset=iso-8859-1">\r
7     \r
8   <meta name="GENERATOR"\r
9  content="Mozilla/4.73 [en] (WinNT; I) [Netscape]">\r
10   <title>Main Page</title>\r
11      \r
12   <link href="doxygen.css" rel="stylesheet" type="text/css">\r
13 </head>\r
14   <body>\r
15  &nbsp; \r
16 <center>\r
17 <table width="96%">\r
18  <tbody>\r
19     <tr>\r
20  <td><a href="http://www.opencascade.com"><img\r
21  src="sources/logocorp.gif" border="0" height="46" width="122">\r
22       </a></td>\r
23    <td> \r
24       <div align="right"><a href="http://www.opencascade.org/SALOME/"><img\r
25  src="sources/application.gif" border="0" height="46" width="108">\r
26       </a></div>\r
27  </td>\r
28  </tr>\r
29  \r
30   </tbody>\r
31 </table>\r
32 </center>\r
33    \r
34 <h1><a name="page2">Examples</a> </h1>\r
35    <font color="#3333ff">//There is a CXX example of LifeCycleCORBA using<br>\r
36 </font><br>\r
37 #include CORBA_CLIENT_HEADER(TestComponent)<br>\r
38 #include "SALOME_NamingService.hxx"<br>\r
39 #include "SALOME_LifeCycleCORBA.hxx"<br>\r
40 <br>\r
41 int main (int argc, char * argv[]){<br>\r
42 &nbsp; try {<br>\r
43 <font color="#3333ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Initializing omniORB<br>\r
44 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CORBA::ORB_var orb = CORBA::ORB_init(argc,\r
45 argv);<br>\r
46 &nbsp;&nbsp;&nbsp; <br>\r
47 <font color="#3333ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Obtain a reference\r
48 to the root POA<br>\r
49 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CORBA::Object_var obj = orb-&gt;resolve_initial_references("RootPOA")\r
50 ;<br>\r
51 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PortableServer::POA_var poa = PortableServer::POA::_narrow(obj)\r
52 ;<br>\r
53 &nbsp;&nbsp;&nbsp; <br>\r
54 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SALOME_NamingService _NS(orb) ;<br>\r
55 <br>\r
56 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SALOME_LifeCycleCORBA _LCC(&amp;_NS) ;<br>\r
57 <br>\r
58 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Engines::Component_var myComponent = _LCC.FindOrLoad_Component("FactoryServerPy","TestComponentPy");<br>\r
59 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; if(!CORBA::is_nil(myComponent)){<br>\r
60 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Engines::TestComponent_var\r
61 myConcreateComponent = TestComponent::_narrow(myComponent);<br>\r
62 <font color="#3333ff">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; //do something\r
63 what you like with the interface<br>\r
64 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...<br>\r
65 </font>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; return 0;<br>\r
66 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<br>\r
67 &nbsp;&nbsp;&nbsp; }<br>\r
68 &nbsp; catch(CORBA::COMM_FAILURE&amp; ex){<br>\r
69 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout&lt;&lt;"Caught system exception COMM_FAILURE\r
70 -- unable to contact the object.\n";<br>\r
71 &nbsp; }catch(CORBA::SystemException&amp;){<br>\r
72 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout&lt;&lt;"Caught a CORBA::SystemException.\n";<br>\r
73 &nbsp; }catch(CORBA::Exception&amp;){<br>\r
74 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout&lt;&lt;"Caught CORBA::Exception.\n";<br>\r
75 &nbsp; }catch(...){<br>\r
76 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout&lt;&lt;"Caught unknown exception.\n";<br>\r
77 &nbsp; }<br>\r
78 &nbsp; return 1;<br>\r
79 }<br>\r
80 <br>\r
81 <font color="#3333ff">#The example may be rewritten on Python like this:<br>\r
82 </font><br>\r
83 from omniORB import CORBA<br>\r
84 from SALOME_TestComponent import *<br>\r
85 from SALOME_NamingServicePy import *<br>\r
86 from LifeCycleCORBA import *<br>\r
87 <br>\r
88 try:<br>\r
89 &nbsp;&nbsp;&nbsp; orb = CORBA.ORB_init(sys.argv,CORBA.ORB_ID)<br>\r
90 &nbsp;&nbsp;&nbsp; _NS = SALOME_NamingService(orb)<br>\r
91 &nbsp;&nbsp;&nbsp; _LCC = SALOME_LifeCycleCORBA(orb)<br>\r
92 <br>\r
93 &nbsp;&nbsp;&nbsp;&nbsp; myComponent = _LCC.FindOrLoadComponent("FactoryServerPy","TestComponentPy");<br>\r
94 &nbsp;&nbsp;&nbsp; &nbsp;myConcreatComponent = myComponent._narrow(TestComponent)<br>\r
95 &nbsp;&nbsp;&nbsp; if myConcreatComponent is not None :<font\r
96  color="#3333ff"><br>\r
97 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //do something what you like with the\r
98 interface<br>\r
99  &nbsp; &nbsp; &nbsp; &nbsp; ...<br>\r
100  </font>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return 0<br>\r
101 &nbsp;&nbsp;&nbsp; }<br>\r
102 except CosNaming.NamingContext.NotFound, e :<br>\r
103 &nbsp;&nbsp;&nbsp; print "Caught exception: Naming Service can't found Logger"<br>\r
104 except CORBA.COMM_FAILURE, e:<br>\r
105 &nbsp;&nbsp;&nbsp; print "Caught CORBA::SystemException CommFailure"<br>\r
106 except CORBA.SystemException, e:<br>\r
107 &nbsp;&nbsp;&nbsp; print "Caught CORBA::SystemException."<br>\r
108 except CORBA.Exception, e:<br>\r
109 &nbsp;&nbsp;&nbsp; print "Caught CORBA::Exception."<br>\r
110 except Exception, e:<br>\r
111 &nbsp;&nbsp;&nbsp; print "Caught unknown exception."<br>\r
112 &nbsp;&nbsp; <br>\r
113 <br>\r
114 <br>\r
115 </body>\r
116 </html>\r