]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
- adding register factory to Superv_Component
authorribes <ribes>
Wed, 10 Oct 2007 12:37:46 +0000 (12:37 +0000)
committerribes <ribes>
Wed, 10 Oct 2007 12:37:46 +0000 (12:37 +0000)
src/DSC/DSC_User/Basic/basic_port_factory.hxx
src/DSC/DSC_User/Datastream/Calcium/calcium_port_factory.hxx
src/DSC/DSC_User/Datastream/Palm/palm_port_factory.hxx
src/DSC/DSC_User/Makefile.am
src/DSC/DSC_User/Superv_Component_i.cxx
src/DSC/DSC_User/Superv_Component_i.hxx
src/DSC/DSC_User/port_factory.hxx [new file with mode: 0644]

index 7550ffaee9812e68969f6c783e7177ae3de81dbf..8407c217b0f01f857ab8d335453130df2b92679a 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef _BASIC_PORT_FACTORY_HXX_
 #define _BASIC_PORT_FACTORY_HXX_
 
+#include "port_factory.hxx"
 #include "data_short_port_provides.hxx"
 #include "data_short_port_uses.hxx"
 
@@ -38,7 +39,8 @@ using namespace std;
  *  to be used by Superv_Component_i.
  *  It builds basic ports.
  */
-class basic_port_factory
+class basic_port_factory :
+  public port_factory
 {
   public:
     basic_port_factory();
index a722cd966f25e21a6fff23da49055792266d797a..6cb0504117eff1ac982a9cdc045a7f8f9246422f 100644 (file)
@@ -30,6 +30,7 @@
 #ifndef _CALCIUM_PORT_FACTORY_HXX_
 #define _CALCIUM_PORT_FACTORY_HXX_
 
+#include "port_factory.hxx"
 #include "uses_port.hxx"
 #include "provides_port.hxx"
 #include <string>
@@ -45,7 +46,8 @@
 
 using namespace std;
 
-class calcium_port_factory
+class calcium_port_factory :
+  public port_factory
 {
   public:
     calcium_port_factory();
index df030c2af8a03650f07100ba321b22455b45b9ba..544a9c1eb8c67985ff7cccc0457f32a0fe89cd3f 100644 (file)
@@ -30,6 +30,7 @@
 #ifndef _PALM_PORT_FACTORY_HXX_
 #define _PALM_PORT_FACTORY_HXX_
 
+#include "port_factory.hxx"
 #include "uses_port.hxx"
 #include "provides_port.hxx"
 #include <string>
@@ -39,7 +40,8 @@
 
 using namespace std;
 
-class palm_port_factory
+class palm_port_factory :
+  public port_factory
 {
   public:
     palm_port_factory();
index 37d753254fd695055a22e0866bc871592032a205..42c20a9c3b7e67290d1d52b1a552009355d060b9 100644 (file)
@@ -36,7 +36,8 @@ salomeinclude_HEADERS = base_port.hxx \
                        uses_port.hxx \
                        provides_port.hxx \
                        Superv_Component_i.hxx \
-                       DSC_Exception.hxx
+                       DSC_Exception.hxx \
+                       port_factory.hxx
 
 #
 # ===============================================================
index 187657c2c5e13c4b9ec07642bd01abd95b386ce4..e94cad7c828c3cb29208b263b498fe8d4a4d6c57 100644 (file)
@@ -46,40 +46,64 @@ Superv_Component_i::Superv_Component_i(CORBA::ORB_ptr orb,
 #ifdef _DEBUG_
   std::cout << "--Superv_Component_i : MARK 1 ----  " << instanceName << "----" << std::endl;
 #endif
-  _my_basic_factory = new basic_port_factory();
-  _my_palm_factory = new palm_port_factory();
-  _my_calcium_factory = new calcium_port_factory();
+  register_factory("BASIC", new basic_port_factory());
+  register_factory("PALM", new palm_port_factory());
+  register_factory("CALCIUM", new calcium_port_factory());
 }
 
   
-Superv_Component_i::~Superv_Component_i() {
-  delete _my_basic_factory;
+Superv_Component_i::~Superv_Component_i() 
+{
+  factory_map_t::iterator begin = _factory_map.begin();
+  factory_map_t::iterator end = _factory_map.end();
+  for(;begin!=end;begin++) 
+  {
+    delete begin->second;
+  }
+}
+
+void 
+Superv_Component_i::register_factory(const std::string & factory_name,
+                                    port_factory * factory_ptr) 
+{
+  factory_map_t::iterator it = _factory_map.find(factory_name);
+
+  if (it == _factory_map.end() )
+  {
+    _factory_map[factory_name] = factory_ptr;
+  }
+}
+
+port_factory *
+Superv_Component_i::get_factory(const std::string & factory_name) 
+{
+  port_factory * rtn_factory = NULL;
+  factory_map_t::iterator it = _factory_map.find(factory_name);
+
+  if (it != _factory_map.end() )
+  {
+    rtn_factory = _factory_map[factory_name];
+  }
+
+  return rtn_factory;
 }
 
 provides_port *
-Superv_Component_i::create_provides_data_port(const char* port_fab_type)
+Superv_Component_i::create_provides_data_port(const std::string& port_fab_type)
   throw (BadFabType)
 { 
-  assert(port_fab_type);
-
   provides_port * rtn_port = NULL;
-  string the_type(port_fab_type);
+  std::string factory_name;
+  std::string type_name;
   int search_result;
 
-  search_result = the_type.find("BASIC_");
-  if (search_result == 0) {
-    rtn_port = _my_basic_factory->create_data_servant(the_type.substr(search_result+6, 
-                                                                     the_type.length()));
-  }
-  search_result = the_type.find("PALM_");
-  if (search_result == 0) {
-    rtn_port = _my_palm_factory->create_data_servant(the_type.substr(search_result+5, 
-                                                                    the_type.length()));
-  }
+  search_result = port_fab_type.find("_");
+  factory_name = port_fab_type.substr(0,search_result);
+  type_name = port_fab_type.substr(search_result+1, port_fab_type.length());
 
-  search_result = the_type.find("CALCIUM_");
-  if (search_result == 0) {
-    rtn_port = _my_calcium_factory->create_data_servant(the_type.substr(search_result+8, the_type.length()));
+  port_factory * factory = get_factory(factory_name);
+  if (factory) {
+    rtn_port = factory->create_data_servant(type_name);
   }
 
   if (rtn_port == NULL)
@@ -90,27 +114,21 @@ Superv_Component_i::create_provides_data_port(const char* port_fab_type)
 }
 
 uses_port *
-Superv_Component_i::create_uses_data_port(const char* port_fab_type) 
+Superv_Component_i::create_uses_data_port(const std::string& port_fab_type) 
 throw (BadFabType)
 {
-  assert(port_fab_type);
-
   uses_port * rtn_proxy = NULL;
-  string the_type(port_fab_type);
+  std::string factory_name;
+  std::string type_name;
   int search_result;
 
-  search_result = the_type.find("BASIC_");
-  if (search_result == 0) {
-    rtn_proxy = _my_basic_factory->create_data_proxy(the_type.substr(search_result+6, 
-                                                                    the_type.length()));
-  }
-  
-  search_result = the_type.find("CALCIUM_");
-  if (search_result == 0) {
-#ifdef _DEBUG_
-    std::cout << "---- Superv_Component_i::create_uses_data_port : MARK 1 ----  " << the_type.substr(search_result+8, the_type.length()) << "----" << std::endl;
-#endif
-    rtn_proxy = _my_calcium_factory->create_data_proxy(the_type.substr(search_result+8, the_type.length()));
+  search_result = port_fab_type.find("_");
+  factory_name = port_fab_type.substr(0,search_result);
+  type_name = port_fab_type.substr(search_result+1, port_fab_type.length());
+
+  port_factory * factory = get_factory(factory_name);
+  if (factory) {
+    rtn_proxy = factory->create_data_proxy(type_name);
   }
   
   if (rtn_proxy == NULL)
index 8b46949ba236d2fb8f6170ae0a14cbabcc90b547..4bac01fc3f8c942e7e0a639008a70dab7a3c6c72 100644 (file)
@@ -30,8 +30,9 @@
 #include "base_port.hxx"
 #include "uses_port.hxx"
 #include "provides_port.hxx"
+#include "port_factory.hxx"
 
-// Les différentes fabriques de ports
+// default ports factories on the Kernel
 #include "basic_port_factory.hxx"
 #include "palm_port_factory.hxx"
 #include "calcium_port_factory.hxx"
@@ -104,7 +105,7 @@ public:
   {return NULL;}
 
   /*!
-   * This methode permits to create a provides port provided by the platform.
+   * This method permits to create a provides port provided by the platform.
    * (See documentation of DSC for knoing these ports).
    *   
    *
@@ -113,12 +114,12 @@ public:
    *
    * \note It's user repsonsability to destroy the provides port.
    */
-  virtual provides_port * create_provides_data_port(const char* port_fab_type)
+  virtual provides_port * create_provides_data_port(const std::string& port_fab_type)
     throw (BadFabType);
 
 
   /*!
-   * This methode permits to create a uses port provided by the platform.
+   * This method permits to create a uses port provided by the platform.
    * (See documentation of DSC for knoing these ports).
    *   
    *
@@ -127,7 +128,7 @@ public:
    *
    * \note It's user repsonsability to destroy the uses port.
    */
-  virtual uses_port * create_uses_data_port(const char* port_fab_type)
+  virtual uses_port * create_uses_data_port(const std::string& port_fab_type)
     throw (BadFabType); 
 
   /*!
@@ -234,12 +235,29 @@ public:
                                 const Engines::DSC::Message message);
 
 
-private:    
+  /*!
+   * Add a factory the component. If the factory_name is already
+   * used, the new library is not added.
+   *
+   * \param factory_name name of the factory (used by Superv_Component_i::create_provides_data_port
+   * and Superv_Component_i::create_uses_data_port)
+   * \param factory_ptr factory pointer (destroyed by the component)
+   */
+  virtual void register_factory(const std::string & factory_name,
+                               port_factory * factory_ptr);
+
+  /*!
+   * Get a factory from the component. 
+   *
+   * \param factory_name name of the factory.
+   * \return factory pointer, NULL if the factory doesn't exist.
+   */
+  virtual port_factory * get_factory(const std::string & factory_name);
 
-  // Fabrics
-  basic_port_factory * _my_basic_factory;
-  palm_port_factory * _my_palm_factory;
-  calcium_port_factory *   _my_calcium_factory;
+private:   
+  // Factory map
+  typedef std::map<std::string, port_factory*> factory_map_t;
+  factory_map_t _factory_map;
 
   /*-------------------------------------------------*/
   // A Superv_Component port.
diff --git a/src/DSC/DSC_User/port_factory.hxx b/src/DSC/DSC_User/port_factory.hxx
new file mode 100644 (file)
index 0000000..e2920ce
--- /dev/null
@@ -0,0 +1,61 @@
+//  Copyright (C) 2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+//
+//
+//  File   : port_factory.hxx
+//  Author : André RIBES (EDF)
+//  Module : KERNEL
+
+#ifndef _PORT_FACTORY_HXX
+#define _PORT_FACTORY_HXX
+
+#include "base_port.hxx"
+#include "uses_port.hxx"
+#include "provides_port.hxx"
+
+#include <string>
+
+/*! \class port_factory
+ *  \brief This class is an abstract for all the DSC ports factories that have to be 
+ *  registered into the component.
+ */
+class port_factory {
+ public:
+   virtual ~port_factory() {}
+
+    /*!
+     * This method creates a provides port.
+     *
+     * \param type port's type.
+     * \return a pointer of the provides port.
+     */
+   virtual provides_port * create_data_servant(std::string type) = 0;
+
+    /*!
+     * This method creates a uses port.
+     *
+     * \param type port's type.
+     * \return a pointer of the uses port.
+     */
+   virtual uses_port * create_data_proxy(std::string type) = 0;
+};
+
+#endif
+