Back to index

salome-kernel  6.5.0
Calcium.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 
00020 #include "Calcium.hxx"
00021 #include "CalciumInterface.hxx"
00022 #include "calcium.h"
00023 #include <iostream>
00024 #include <sstream>
00025 #include <string>
00026 #include <exception>
00027 
00028 PySupervCompo::PySupervCompo( CORBA::ORB_ptr orb,
00029                               PortableServer::POA_ptr poa,
00030                               Engines::Container_ptr contain,
00031                               const char *instanceName,
00032                               const char *interfaceName,
00033                               bool notif) :
00034   Superv_Component_i(orb, poa,contain, instanceName, interfaceName,false,false)
00035 {
00036 }
00037 
00038 PySupervCompo::~PySupervCompo()
00039 {
00040 }
00041 
00042 
00043 extern "C"
00044 {
00045   void cp_exit(int);
00046   void setDependency(provides_port*, char*, CalciumTypes::DependencyType);
00047 
00048   void cp_exit(int err)
00049     {
00050       throw CalciumException(err,LOC("Abort coupling"));
00051     }
00052 
00053   void setDependency(provides_port * port,char* type,CalciumTypes::DependencyType depend)
00054   {
00055     if(std::string(type)=="CALCIUM_real")
00056       {
00057         dynamic_cast<calcium_real_port_provides *>(port)->setDependencyType(depend);
00058       }
00059     else if(std::string(type)=="CALCIUM_double")
00060       {
00061         dynamic_cast<calcium_double_port_provides *>(port)->setDependencyType(depend);
00062       }
00063     else if(std::string(type)=="CALCIUM_integer")
00064       {
00065         dynamic_cast<calcium_integer_port_provides *>(port)->setDependencyType(depend);
00066       }
00067     else if(std::string(type)=="CALCIUM_long")
00068       {
00069         dynamic_cast<calcium_long_port_provides *>(port)->setDependencyType(depend);
00070       }
00071     else if(std::string(type)=="CALCIUM_string")
00072       {
00073         dynamic_cast<calcium_string_port_provides *>(port)->setDependencyType(depend);
00074       }
00075     else if(std::string(type)=="CALCIUM_logical")
00076       {
00077         dynamic_cast<calcium_logical_port_provides *>(port)->setDependencyType(depend);
00078       }
00079     else if(std::string(type)=="CALCIUM_complex")
00080       {
00081         dynamic_cast<calcium_complex_port_provides *>(port)->setDependencyType(depend);
00082       }
00083     else
00084       {
00085         std::cerr << "unknown type:" << std::endl;
00086       }
00087   }
00088 
00089   void create_calcium_port(Superv_Component_i* compo,char* name,char* type,char *mode,char* depend)
00090   {
00091     std::stringstream msg;
00092     msg << type << " " << mode << " " << depend;
00093     CORBA::String_var componentName=compo->instanceName();
00094     std::string containerName=compo->getContainerName();
00095     Engines_DSC_interface::writeEvent("create_calcium_port",containerName,componentName,name,"",msg.str().c_str());
00096 
00097     if(std::string(mode) == "IN")
00098       {
00099         provides_port * port ;
00100         //provides port
00101         try
00102           {
00103             port = compo->create_provides_data_port(type);
00104             compo->add_port(port, name);
00105             if(std::string(depend) == "I")
00106               setDependency(port,type,CalciumTypes::ITERATION_DEPENDENCY);
00107             else if(std::string(depend) == "T")
00108               setDependency(port,type,CalciumTypes::TIME_DEPENDENCY);
00109             else
00110               {
00111                 std::cerr << "create_calcium_port:unknown dependency: " << depend << std::endl;
00112               }
00113           }
00114         catch(const Superv_Component_i::PortAlreadyDefined& ex)
00115           {
00116             //Port already defined : we use the old one
00117             delete port;
00118             std::cerr << "create_calcium_port: " << ex.what() << std::endl;
00119           }
00120         catch ( ... )
00121           {
00122             std::cerr << "create_calcium_port: unknown exception" << std::endl;
00123           }
00124       }
00125     else if(std::string(mode) == "OUT")
00126       {
00127         uses_port * uport ;
00128         try
00129           {
00130             uport = compo->create_uses_data_port(type);
00131             compo->add_port(uport, name);
00132           }
00133         catch(const Superv_Component_i::PortAlreadyDefined& ex)
00134           {
00135             //Port already defined : we use the old one
00136             delete uport;
00137             std::cerr << "create_calcium_port: " << ex.what() << std::endl;
00138           }
00139         catch ( ... )
00140           {
00141             std::cerr << "create_calcium_port: unknown exception" << std::endl;
00142           }
00143       }
00144     else
00145       {
00146         //Unknown mode
00147         std::cerr << "create_calcium_port:Unknown mode: " << mode << std::endl;
00148       }
00149   }
00150 
00151 }
00152 
00153