Salome HOME
Merge from V6_main 01/04/2013
[modules/smesh.git] / src / Tools / padder / meshjob / impl / SPADDERPluginTester_i.cxx
1 // Copyright (C) 2011-2013  EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // Authors : Guillaume Boulant (EDF) - 01/03/2011
21
22 #include "SPADDERPluginTester_i.hxx"
23
24 #include <SALOME_NamingService.hxx>
25 #include <Utils_SALOME_Exception.hxx>
26
27 // For standard logging
28 #include "Basics_Utils.hxx"
29
30 //
31 // ==========================================================================
32 // Implementation of the SPADDER component interface
33 // ==========================================================================
34 //
35 using namespace std;
36
37 /*!
38  * Constructor for component "SPADDER" instance
39  */
40 SPADDERPluginTester_i::SPADDERPluginTester_i(CORBA::ORB_ptr orb,
41                                              PortableServer::POA_ptr poa,
42                                              PortableServer::ObjectId * contId,
43                                              const char *instanceName,
44                                              const char *interfaceName)
45   : Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
46 {
47   LOG("Activating SPADDERPluginTester_i::SPADDERPluginTester object");
48   _thisObj = this ;
49   _id = _poa->activate_object(_thisObj);
50 }
51
52 //! Destructor for component "SPADDER" instance
53 SPADDERPluginTester_i::~SPADDERPluginTester_i()
54 {
55   std::cerr << "SPADDERPluginTester destruction" << std::endl;
56 }
57
58 /*!
59  * This test is just to check the component SPADDER.
60  */
61 void SPADDERPluginTester_i::demo(CORBA::Double a,CORBA::Double b,CORBA::Double& c)
62 {
63   beginService("SPADDERPluginTester_i::demo");
64   try {
65     //BODY
66     
67     std::cerr << "a: " << a << std::endl;
68     std::cerr << "b: " << b << std::endl;
69     c=a+b;
70     std::cerr << "c: " << c << std::endl;
71     
72   }
73   catch ( const SALOME_Exception & ex) {
74     SALOME::ExceptionStruct es;
75     es.text=CORBA::string_dup(ex.what());
76     es.type=SALOME::INTERNAL_ERROR;
77     throw SALOME::SALOME_Exception(es);
78   }
79   catch ( const SALOME::SALOME_Exception & ex) {
80     throw;
81   }
82   catch (...) {
83     std::cerr << "unknown exception" << std::endl;
84     SALOME::ExceptionStruct es;
85     es.text=CORBA::string_dup(" unknown exception");
86     es.type=SALOME::INTERNAL_ERROR;
87     throw SALOME::SALOME_Exception(es);
88   }
89   endService("SPADDERPluginTester_i::demo");
90 }
91
92 #ifdef LOG
93 #undef LOG
94 #endif
95
96 #include <SALOME_KernelServices.hxx>
97 #include "SALOME_Launcher.hxx"
98 bool SPADDERPluginTester_i::testkernel()
99 {
100   beginService("SPADDERPluginTester_i::testplugin");
101
102   Engines::SalomeLauncher_ptr salomeLauncher = KERNEL::getSalomeLauncher();
103
104   endService("SPADDERPluginTester_i::testplugin");
105   return true;
106 }
107
108
109 #include <SMESH_Gen_i.hxx>
110 #include <SMESH_Gen.hxx>
111 #include <SALOMEconfig.h>
112 #include CORBA_CLIENT_HEADER(SALOMEDS)
113
114 #include <utilities.h>
115
116 /*!
117  * This test checks the constructor of the basic classes of the SMESH
118  * plugin for PADDER.
119  */
120 bool SPADDERPluginTester_i::testsmesh(CORBA::Long studyId)
121 {
122   beginService("SPADDERPluginTester_i::testsmesh");
123
124   // Resolve the SMESH engine and the SALOME study
125   // _WARN_ The SMESH engine should have been loaded first
126   SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
127   CORBA::Object_var anObject = smeshGen_i->GetNS()->Resolve("/myStudyManager");
128   SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject);
129   SALOMEDS::Study_var myStudy = aStudyMgr->GetStudyByID(studyId);
130
131   //
132   // _MEM_ CAUTION: SMESH_Gen define a data structure for local usage
133   // while SMESH_Gen_i is the implementation of the SMESH_Gen IDL
134   // interface.
135   //
136
137   endService("SPADDERPluginTester_i::testsmesh");
138   return true;
139 }
140
141 //
142 // ==========================================================================
143 // Factory services
144 // ==========================================================================
145 //
146 extern "C"
147 {
148   PortableServer::ObjectId * SPADDERPluginTesterEngine_factory( CORBA::ORB_ptr orb,
149                                                                 PortableServer::POA_ptr poa,
150                                                                 PortableServer::ObjectId * contId,
151                                                                 const char *instanceName,
152                                                                 const char *interfaceName)
153   {
154     MESSAGE("PortableServer::ObjectId * SPADDERPluginTesterEngine_factory()");
155     SPADDERPluginTester_i * myEngine = new SPADDERPluginTester_i(orb, poa, contId, instanceName, interfaceName);
156     return myEngine->getId() ;
157   }
158 }