Salome HOME
Copyright update 2021
[modules/smesh.git] / src / Tools / padder / meshjob / impl / SPADDERPluginTester_i.cxx
1 // Copyright (C) 2011-2021  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, or (at your option) any later version.
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   if ( salomeLauncher ) salomeLauncher = NULL;
104
105   endService("SPADDERPluginTester_i::testplugin");
106   return true;
107 }
108
109
110 #include <SMESH_Gen_i.hxx>
111 #include <SMESH_Gen.hxx>
112 #include <SALOMEconfig.h>
113 #include CORBA_CLIENT_HEADER(SALOMEDS)
114
115 #include <utilities.h>
116
117 /*!
118  * This test checks the constructor of the basic classes of the SMESH
119  * plugin for PADDER.
120  */
121 bool SPADDERPluginTester_i::testsmesh()
122 {
123   beginService("SPADDERPluginTester_i::testsmesh");
124
125   // Resolve the SMESH engine and the SALOME study
126   // _WARN_ The SMESH engine should have been loaded first
127   SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
128   CORBA::Object_var anObject = smeshGen_i->GetNS()->Resolve("/Study");
129   SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(anObject);
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   SPADDERPLUGINTESTERENGINE_EXPORT PortableServer::ObjectId * 
149   SPADDERPluginTesterEngine_factory( CORBA::ORB_ptr orb,
150                                      PortableServer::POA_ptr poa,
151                                      PortableServer::ObjectId * contId,
152                                      const char *instanceName,
153                                      const char *interfaceName)
154   {
155     MESSAGE("PortableServer::ObjectId * SPADDERPluginTesterEngine_factory()");
156     SPADDERPluginTester_i * myEngine = new SPADDERPluginTester_i(orb, poa, contId, instanceName, interfaceName);
157     return myEngine->getId() ;
158   }
159 }