Salome HOME
7144bdc8bb2b6b156c67475009b6681414e2eb14
[samples/atomsolv.git] / src / ATOMSOLV / ATOMSOLV.cxx
1 // Copyright (C) 2007-2013  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.
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 using namespace std;
21 #include "ATOMSOLV.hxx"
22 #include "ATOMSOLV_version.h"
23 #include "utilities.h"
24
25 #include <string>
26
27
28 ATOMSOLV::ATOMSOLV(CORBA::ORB_ptr orb,
29         PortableServer::POA_ptr poa,
30         PortableServer::ObjectId * contId, 
31         const char *instanceName, 
32         const char *interfaceName) :
33   Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
34 {
35   MESSAGE("activate object");
36   _thisObj = this ;
37   _id = _poa->activate_object(_thisObj);
38 }
39
40 ATOMSOLV::~ATOMSOLV()
41 {
42 }
43
44 CORBA::Boolean ATOMSOLV::setData( CORBA::Long studyID, const ATOMSOLV_ORB::TMoleculeList& theData )
45 {
46   const int n = theData.length();
47   ATOMSOLV_ORB::TMoleculeList_var data = new ATOMSOLV_ORB::TMoleculeList();
48   data->length( n );
49   for ( int i = 0; i < n; i++ )
50     data[ i ] = theData[ i ];
51
52   //  printf( " -- ATOMSOLV::setData( %d ) length = %d\n", studyID, data->length() );
53   myData[ studyID ] = data._retn();
54
55   return (bool)n;
56 }
57
58 CORBA::Boolean ATOMSOLV::getData( CORBA::Long studyID, ATOMSOLV_ORB::TMoleculeList_out outData )
59 {
60   if ( myData.find( studyID ) != myData.end() ) {
61     ATOMSOLV_ORB::TMoleculeList* data = myData[ studyID ];
62
63     //    printf( " -- ATOMSOLV::getData( %d ) length = %d\n", studyID, data->length() );
64     const int n = data->length();
65     outData = new ATOMSOLV_ORB::TMoleculeList();
66     outData->length( n );
67
68     for ( int i = 0; i < n; i++ )
69       (*outData)[ i ] = (*data)[ i ];
70     
71     return true;
72   }
73   return false;
74 }
75
76 CORBA::Boolean ATOMSOLV::processData( CORBA::Long studyID )
77 {
78   if ( myData.find( studyID ) != myData.end() ) {
79     ATOMSOLV_ORB::TMoleculeList* data = myData[ studyID ];
80     for ( int i = 0, n = data->length(); i < n; i++ )
81       (*data)[i].temperature = rand();
82   }
83   return true;
84 }
85
86 char* ATOMSOLV::getVersion()
87 {
88 #if defined(ATOMSOLV_DEVELOPMENT)
89   return CORBA::string_dup(ATOMSOLV_VERSION_STR"dev");
90 #else
91   return CORBA::string_dup(ATOMSOLV_VERSION_STR);
92 #endif
93 }
94
95 extern "C"
96 {
97   PortableServer::ObjectId * ATOMSOLVEngine_factory(
98                                CORBA::ORB_ptr orb,
99                                PortableServer::POA_ptr poa, 
100                                PortableServer::ObjectId * contId,
101                                const char *instanceName, 
102                                const char *interfaceName)
103   {
104     MESSAGE("PortableServer::ObjectId * ATOMSOLVEngine_factory()");
105     SCRUTE(interfaceName);
106     ATOMSOLV * myATOMSOLV 
107       = new ATOMSOLV(orb, poa, contId, instanceName, interfaceName);
108     return myATOMSOLV->getId() ;
109   }
110 }