Back to index

salome-kernel  6.5.0
KernelHelpersUseCases.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 // Author: Guillaume Boulant (EDF/R&D) 
00020 
00021 #include "SALOME_KernelServices.hxx"
00022 #include "Basics_Utils.hxx"
00023 
00024 #include <SALOMEconfig.h>
00025 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
00026 
00027 bool TEST_corba() {
00028   CORBA::ORB_var orb = KERNEL::getORB();
00029   if ( CORBA::is_nil(orb) ) {
00030     LOG("TEST_Corba: orb ERROR");
00031     return false;
00032   }
00033   SALOME_NamingService *  ns  = KERNEL::getNamingService();
00034   if ( ns == NULL ) {
00035     LOG("TEST_Corba: ns ERROR");
00036     return false;
00037     
00038   }
00039   SALOME_LifeCycleCORBA * lcc = KERNEL::getLifeCycleCORBA();
00040   if ( lcc == NULL ) {
00041     LOG("TEST_Corba: lcc ERROR");
00042     return false;
00043   }
00044   LOG("TEST_Corba: OK");
00045   return true;
00046 }
00047 
00048 #include <string.h>
00049 bool TEST_getLifeCycleCORBA() {
00050   Engines::EngineComponent_var component =
00051     KERNEL::getLifeCycleCORBA()->FindOrLoad_Component( "FactoryServer","SalomeTestComponent" );
00052   
00053   Engines::TestComponent_var engine = Engines::TestComponent::_narrow(component);
00054   char * coucou_res = engine->Coucou(123.);
00055   const char * coucou_ref = "L = 123";
00056   LOG(coucou_res);
00057   if ( strcmp(coucou_res, coucou_ref) == 0 ) {
00058     return false;
00059   }
00060   return true;
00061 }
00062 
00063 bool TEST_getStudyManager() {
00064   SALOMEDS::Study_ptr myTestStudy = KERNEL::getStudyManager()->NewStudy("kerneltest");
00065   if ( CORBA::is_nil(myTestStudy) ) {
00066     return false;
00067   }
00068 
00069   // One can use the study to store some general properties
00070   myTestStudy->SetString("material","wood");
00071   myTestStudy->SetReal("volume",3.23);
00072 
00073   // The study is characterized by an ID
00074   int myTestStudyId = myTestStudy->StudyId();
00075   LOG("TestComponentImpl::testkernel: study id = "<<myTestStudyId);
00076   return true;
00077 }
00078 
00079 
00080 bool TEST_getSalomeLauncher() {
00081   Engines::SalomeLauncher_var salomeLauncher = KERNEL::getSalomeLauncher();
00082   for (int i=0; i<10; i++) {
00083     try {
00084       int pid = salomeLauncher->getPID();
00085       LOG("["<<i<<"] SALOME launcher PID = " << pid);
00086     }
00087     catch (const SALOME::SALOME_Exception & ex) {
00088       LOG("SALOME Exception in createJob !" <<ex.details.text.in());
00089       return false;
00090     }
00091     catch (const CORBA::SystemException& ex) {
00092       LOG("Receive SALOME System Exception: "<<ex);
00093       LOG("Check SALOME servers...");
00094       return false;
00095     }
00096     catch (const std::exception& ex) {
00097       LOG("Receive undefined exception : "<<ex.what());
00098     }
00099 #ifndef WIN32
00100       sleep(2);
00101 #else
00102       Sleep(2000);
00103 #endif
00104   }
00105   return true;
00106 }
00107 
00108 // TODO:
00109 // - complete the coverture of the KernelService interface
00110 // - provide use case for the StudyEditor
00111 
00112 
00113 
00114 int main (int argc, char * argv[]) {
00115   TEST_corba();
00116   TEST_getLifeCycleCORBA();
00117   TEST_getStudyManager();
00118   TEST_getSalomeLauncher();
00119   return 0;
00120 }