Salome HOME
merge from branch BR_V5_DEV
[modules/kernel.git] / src / DSC / DSC_User / Datastream / Calcium / Calcium.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "Calcium.hxx"
23 #include "CalciumInterface.hxx"
24 #include "calcium.h"
25 #include <iostream>
26 #include <string>
27 #include <exception>
28
29 //#define _DEBUG_
30
31 PySupervCompo::PySupervCompo( CORBA::ORB_ptr orb,
32                               PortableServer::POA_ptr poa,
33                               Engines::Container_ptr contain,
34                               const char *instanceName,
35                               const char *interfaceName,
36                               bool notif) :
37   Superv_Component_i(orb, poa,contain, instanceName, interfaceName,false,false)
38 {
39 }
40
41 PySupervCompo::~PySupervCompo()
42 {
43 }
44
45
46 extern "C" 
47 {
48   void cp_exit(int err)
49     {
50       throw CalciumException(err,LOC("Abort coupling"));
51     }
52
53   void setDependency(provides_port * port,char* type,CalciumTypes::DependencyType depend)
54   {
55     if(std::string(type)=="CALCIUM_real")
56       {
57         dynamic_cast<calcium_real_port_provides *>(port)->setDependencyType(depend);
58       }
59     else if(std::string(type)=="CALCIUM_double")
60       {
61         dynamic_cast<calcium_double_port_provides *>(port)->setDependencyType(depend);
62       }
63     else if(std::string(type)=="CALCIUM_integer")
64       {
65         dynamic_cast<calcium_integer_port_provides *>(port)->setDependencyType(depend);
66       }
67     else if(std::string(type)=="CALCIUM_string")
68       {
69         dynamic_cast<calcium_string_port_provides *>(port)->setDependencyType(depend);
70       }
71     else if(std::string(type)=="CALCIUM_logical")
72       {
73         dynamic_cast<calcium_logical_port_provides *>(port)->setDependencyType(depend);
74       }
75     else if(std::string(type)=="CALCIUM_complex")
76       {
77         dynamic_cast<calcium_complex_port_provides *>(port)->setDependencyType(depend);
78       }
79     else
80       {
81         std::cerr << "unknown type:" << std::endl;
82       }
83   }
84
85   void create_calcium_port(Superv_Component_i* compo,char* name,char* type,char *mode,char* depend)
86   {
87 #ifdef _DEBUG_
88     std::cerr << "create_calcium_port: " << name << " " << type << " " << mode << " " << depend << std::endl;
89 #endif
90
91     if(std::string(mode) == "IN")
92       {
93         provides_port * port ;
94         //provides port
95         try
96           {
97             port = compo->create_provides_data_port(type);
98             compo->add_port(port, name);
99             if(std::string(depend) == "I")
100               setDependency(port,type,CalciumTypes::ITERATION_DEPENDENCY);
101             else if(std::string(depend) == "T")
102               setDependency(port,type,CalciumTypes::TIME_DEPENDENCY);
103             else
104               {
105                 std::cerr << "create_calcium_port:unknown dependency: " << depend << std::endl;
106               }
107           }
108         catch(const Superv_Component_i::PortAlreadyDefined& ex)
109           {
110             //Port already defined : we use the old one
111             delete port;
112             std::cerr << "create_calcium_port: " << ex.what() << std::endl;
113           }
114         catch ( ... )
115           {
116             std::cerr << "create_calcium_port: unknown exception" << std::endl;
117           }
118       }
119     else if(std::string(mode) == "OUT")
120       {
121         uses_port * uport ;
122         try
123           {
124             uport = compo->create_uses_data_port(type);
125             compo->add_port(uport, name);
126           }
127         catch(const Superv_Component_i::PortAlreadyDefined& ex)
128           {
129             //Port already defined : we use the old one
130             delete uport;
131             std::cerr << "create_calcium_port: " << ex.what() << std::endl;
132           }
133         catch ( ... )
134           {
135             std::cerr << "create_calcium_port: unknown exception" << std::endl;
136           }
137       }
138     else
139       {
140         //Unknown mode
141         std::cerr << "create_calcium_port:Unknown mode: " << mode << std::endl;
142       }
143   }
144
145 }
146
147