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