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