Salome HOME
Merge from V6_5_BR 05/06/2012
[modules/smesh.git] / src / Tools / padder / meshjob / impl / SPADDERPluginTester_i.cxx
1 // Copyright (C) 2011-2012  CEA/DEN, 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 // Authors : Guillaume Boulant (EDF) - 01/03/2011
20
21 #include "SPADDERPluginTester_i.hxx"
22
23 #include <SALOME_NamingService.hxx>
24 #include <Utils_SALOME_Exception.hxx>
25
26 // For standard logging
27 #include "Basics_Utils.hxx"
28
29 //
30 // ==========================================================================
31 // Implementation of the SPADDER component interface
32 // ==========================================================================
33 //
34 using namespace std;
35
36 /*!
37  * Constructor for component "SPADDER" instance
38  */
39 SPADDERPluginTester_i::SPADDERPluginTester_i(CORBA::ORB_ptr orb,
40                                              PortableServer::POA_ptr poa,
41                                              PortableServer::ObjectId * contId,
42                                              const char *instanceName,
43                                              const char *interfaceName)
44   : Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
45 {
46   LOG("Activating SPADDERPluginTester_i::SPADDERPluginTester object");
47   _thisObj = this ;
48   _id = _poa->activate_object(_thisObj);
49 }
50
51 //! Destructor for component "SPADDER" instance
52 SPADDERPluginTester_i::~SPADDERPluginTester_i()
53 {
54   std::cerr << "SPADDERPluginTester destruction" << std::endl;
55 }
56
57 /*!
58  * This test is just to check the component SPADDER.
59  */
60 void SPADDERPluginTester_i::demo(CORBA::Double a,CORBA::Double b,CORBA::Double& c)
61 {
62   beginService("SPADDERPluginTester_i::demo");
63   try {
64     //BODY
65     
66     std::cerr << "a: " << a << std::endl;
67     std::cerr << "b: " << b << std::endl;
68     c=a+b;
69     std::cerr << "c: " << c << std::endl;
70     
71   }
72   catch ( const SALOME_Exception & ex) {
73     SALOME::ExceptionStruct es;
74     es.text=CORBA::string_dup(ex.what());
75     es.type=SALOME::INTERNAL_ERROR;
76     throw SALOME::SALOME_Exception(es);
77   }
78   catch ( const SALOME::SALOME_Exception & ex) {
79     throw;
80   }
81   catch (...) {
82     std::cerr << "unknown exception" << std::endl;
83     SALOME::ExceptionStruct es;
84     es.text=CORBA::string_dup(" unknown exception");
85     es.type=SALOME::INTERNAL_ERROR;
86     throw SALOME::SALOME_Exception(es);
87   }
88   endService("SPADDERPluginTester_i::demo");
89 }
90
91 #ifdef LOG
92 #undef LOG
93 #endif
94
95 #include <SALOME_KernelServices.hxx>
96 #include "SALOME_Launcher.hxx"
97 bool SPADDERPluginTester_i::testkernel()
98 {
99   beginService("SPADDERPluginTester_i::testplugin");
100
101   Engines::SalomeLauncher_ptr salomeLauncher = KERNEL::getSalomeLauncher();
102
103   endService("SPADDERPluginTester_i::testplugin");
104   return true;
105 }
106
107
108 #include <SMESH_Gen_i.hxx>
109 #include <SMESH_Gen.hxx>
110 #include <SALOMEconfig.h>
111 #include CORBA_CLIENT_HEADER(SALOMEDS)
112
113 #include <utilities.h>
114
115 /*!
116  * This test checks the constructor of the basic classes of the SMESH
117  * plugin for PADDER.
118  */
119 bool SPADDERPluginTester_i::testsmesh(CORBA::Long studyId)
120 {
121   beginService("SPADDERPluginTester_i::testsmesh");
122
123   // Resolve the SMESH engine and the SALOME study
124   // _WARN_ The SMESH engine should have been loaded first
125   SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
126   CORBA::Object_var anObject = smeshGen_i->GetNS()->Resolve("/myStudyManager");
127   SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject);
128   SALOMEDS::Study_var myStudy = aStudyMgr->GetStudyByID(studyId);
129
130   //
131   // _MEM_ CAUTION: SMESH_Gen define a data structure for local usage
132   // while SMESH_Gen_i is the implementation of the SMESH_Gen IDL
133   // interface.
134   //
135
136   endService("SPADDERPluginTester_i::testsmesh");
137   return true;
138 }
139
140 //
141 // ==========================================================================
142 // Factory services
143 // ==========================================================================
144 //
145 extern "C"
146 {
147   PortableServer::ObjectId * SPADDERPluginTesterEngine_factory( CORBA::ORB_ptr orb,
148                                                                 PortableServer::POA_ptr poa,
149                                                                 PortableServer::ObjectId * contId,
150                                                                 const char *instanceName,
151                                                                 const char *interfaceName)
152   {
153     MESSAGE("PortableServer::ObjectId * SPADDERPluginTesterEngine_factory()");
154     SPADDERPluginTester_i * myEngine = new SPADDERPluginTester_i(orb, poa, contId, instanceName, interfaceName);
155     return myEngine->getId() ;
156   }
157 }