Salome HOME
adafbbcb25aa4dad0c30fb94309ffc6c161b8452
[modules/kernel.git] / src / KernelHelpers / KernelHelpersUseCases.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
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 // Author: Guillaume Boulant (EDF/R&D) 
20
21 #include "SALOME_KernelServices.hxx"
22 #include "Basics_Utils.hxx"
23
24 #include <SALOMEconfig.h>
25 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
26
27 bool TEST_corba() {
28   CORBA::ORB_var orb = KERNEL::getORB();
29   if ( CORBA::is_nil(orb) ) {
30     LOG("TEST_Corba: orb ERROR");
31     return false;
32   }
33   SALOME_NamingService *  ns  = KERNEL::getNamingService();
34   if ( ns == NULL ) {
35     LOG("TEST_Corba: ns ERROR");
36     return false;
37     
38   }
39   SALOME_LifeCycleCORBA * lcc = KERNEL::getLifeCycleCORBA();
40   if ( lcc == NULL ) {
41     LOG("TEST_Corba: lcc ERROR");
42     return false;
43   }
44   LOG("TEST_Corba: OK");
45   return true;
46 }
47
48 #include <string.h>
49 bool TEST_getLifeCycleCORBA() {
50   Engines::EngineComponent_var component =
51     KERNEL::getLifeCycleCORBA()->FindOrLoad_Component( "FactoryServer","SalomeTestComponent" );
52   
53   Engines::TestComponent_var engine = Engines::TestComponent::_narrow(component);
54   char * coucou_res = engine->Coucou(123.);
55   const char * coucou_ref = "L = 123";
56   LOG(coucou_res);
57   if ( strcmp(coucou_res, coucou_ref) == 0 ) {
58     return false;
59   }
60   return true;
61 }
62
63 bool TEST_getStudyManager() {
64   SALOMEDS::Study_ptr myTestStudy = KERNEL::getStudyManager()->NewStudy("kerneltest");
65   if ( CORBA::is_nil(myTestStudy) ) {
66     return false;
67   }
68
69   // One can use the study to store some general properties
70   myTestStudy->SetString("material","wood");
71   myTestStudy->SetReal("volume",3.23);
72
73   // The study is characterized by an ID
74   int myTestStudyId = myTestStudy->StudyId();
75   LOG("TestComponentImpl::testkernel: study id = "<<myTestStudyId);
76   return true;
77 }
78
79
80 bool TEST_getSalomeLauncher() {
81   Engines::SalomeLauncher_var salomeLauncher = KERNEL::getSalomeLauncher();
82   for (int i=0; i<10; i++) {
83     try {
84       int pid = salomeLauncher->getPID();
85       LOG("["<<i<<"] SALOME launcher PID = " << pid);
86     }
87     catch (const SALOME::SALOME_Exception & ex) {
88       LOG("SALOME Exception in createJob !" <<ex.details.text.in());
89       return false;
90     }
91     catch (const CORBA::SystemException& ex) {
92       LOG("Receive SALOME System Exception: "<<ex);
93       LOG("Check SALOME servers...");
94       return false;
95     }
96     catch (const std::exception& ex) {
97       LOG("Receive undefined exception : "<<ex.what());
98     }
99 #ifndef WIN32
100       sleep(2);
101 #else
102       Sleep(2000);
103 #endif
104   }
105   return true;
106 }
107
108 // TODO:
109 // - complete the coverture of the KernelService interface
110 // - provide use case for the StudyEditor
111
112
113
114 int main (int argc, char * argv[]) {
115   TEST_corba();
116   TEST_getLifeCycleCORBA();
117   TEST_getStudyManager();
118   TEST_getSalomeLauncher();
119   return 0;
120 }