Back to index

salome-kernel  6.5.0
Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Attributes
Engines_DSC_interface Class Reference

This class implements the interface Engines::DSC. More...

#include <DSC_interface.hxx>

Inheritance diagram for Engines_DSC_interface:
Inheritance graph
[legend]
Collaboration diagram for Engines_DSC_interface:
Collaboration graph
[legend]

List of all members.

Classes

struct  port_t

Public Member Functions

 Engines_DSC_interface ()
virtual ~Engines_DSC_interface ()
virtual void add_provides_port (Ports::Port_ptr ref, const char *provides_port_name, Ports::PortProperties_ptr port_prop) throw (Engines::DSC::PortAlreadyDefined, Engines::DSC::NilPort, Engines::DSC::BadProperty)
virtual void add_uses_port (const char *repository_id, const char *uses_port_name, Ports::PortProperties_ptr port_prop) throw (Engines::DSC::PortAlreadyDefined, Engines::DSC::BadProperty)
virtual Ports::Port_ptr get_provides_port (const char *provides_port_name, const CORBA::Boolean connection_error) throw (Engines::DSC::PortNotDefined, Engines::DSC::PortNotConnected, Engines::DSC::BadPortType)
virtual Engines::DSC::uses_portget_uses_port (const char *uses_port_name) throw (Engines::DSC::PortNotDefined, Engines::DSC::PortNotConnected, Engines::DSC::BadPortType)
virtual void connect_provides_port (const char *provides_port_name) throw (Engines::DSC::PortNotDefined)
virtual void connect_uses_port (const char *uses_port_name, Ports::Port_ptr provides_port_ref) throw (Engines::DSC::PortNotDefined, Engines::DSC::BadPortType, Engines::DSC::NilPort)
virtual CORBA::Boolean is_connected (const char *port_name) throw (Engines::DSC::PortNotDefined)
virtual void disconnect_provides_port (const char *provides_port_name, const Engines::DSC::Message message) throw (Engines::DSC::PortNotDefined, Engines::DSC::PortNotConnected)
virtual void disconnect_uses_port (const char *uses_port_name, Ports::Port_ptr provides_port_ref, const Engines::DSC::Message message) throw (Engines::DSC::PortNotDefined, Engines::DSC::PortNotConnected, Engines::DSC::BadPortReference)
virtual Ports::PortProperties_ptr get_port_properties (const char *port_name) throw (Engines::DSC::PortNotDefined)

Static Public Member Functions

static void writeEvent (const char *request, const std::string &containerName, const char *instance_name, const char *port_name, const char *error, const char *message)
 Write a record in the trace file.

Protected Types

enum  port_type { uses, provides, none }
typedef std::map< std::string,
port_t * > 
ports

Protected Attributes

ports my_ports
ports::iterator my_ports_it

Detailed Description

This class implements the interface Engines::DSC.

This class is used by the sequential DSC implementation and the parallel DSC implementation.

Definition at line 43 of file DSC_interface.hxx.


Class Documentation

struct Engines_DSC_interface::port_t

Definition at line 162 of file DSC_interface.hxx.

Collaboration diagram for Engines_DSC_interface::port_t:
Class Members
int connection_nbr
PortProperties_var port_prop
Port_var provides_port_ref
string repository_id
port_type type
uses_port uses_port_refs

Member Typedef Documentation

typedef std::map<std::string, port_t *> Engines_DSC_interface::ports [protected]

Definition at line 176 of file DSC_interface.hxx.


Member Enumeration Documentation

Enumerator:
uses 
provides 
none 

Definition at line 160 of file DSC_interface.hxx.


Constructor & Destructor Documentation

Definition at line 40 of file DSC_interface.cxx.

{}

Definition at line 42 of file DSC_interface.cxx.

{
  my_ports_it = my_ports.begin();
  for(;my_ports_it != my_ports.end();my_ports_it++)
    delete my_ports_it->second;

}

Member Function Documentation

void Engines_DSC_interface::add_provides_port ( Ports::Port_ptr  ref,
const char *  provides_port_name,
Ports::PortProperties_ptr  port_prop 
) throw (Engines::DSC::PortAlreadyDefined, Engines::DSC::NilPort, Engines::DSC::BadProperty) [virtual]
See also:
Engines::DSC::add_provides_port

Reimplemented in DSC_BASIC_EXPORT, and Engines_ParallelDSC_i.

Definition at line 51 of file DSC_interface.cxx.

{
  // Method args test
  assert(provides_port_name);
  if (CORBA::is_nil(ref))
    throw Engines::DSC::NilPort();
  if (CORBA::is_nil(port_prop))
    throw Engines::DSC::BadProperty();

  my_ports_it = my_ports.find(provides_port_name);
  if (my_ports_it ==  my_ports.end()) {
    // Creating a new port provides
    port_t * new_port = new port_t();
    new_port->type = provides;
    new_port->connection_nbr = 0;
    new_port->provides_port_ref = Ports::Port::_duplicate(ref);
    new_port->port_prop = Ports::PortProperties::_duplicate(port_prop);

    // Port into the port's map
    my_ports[provides_port_name] = new_port;
  }
  else
    throw Engines::DSC::PortAlreadyDefined();
}

Here is the caller graph for this function:

void Engines_DSC_interface::add_uses_port ( const char *  repository_id,
const char *  uses_port_name,
Ports::PortProperties_ptr  port_prop 
) throw (Engines::DSC::PortAlreadyDefined, Engines::DSC::BadProperty) [virtual]
See also:
Engines::DSC::add_uses_port

Reimplemented in DSC_BASIC_EXPORT, and Engines_ParallelDSC_i.

Definition at line 82 of file DSC_interface.cxx.

{
  // Method args test
  // Note : We can't be shure that repository id
  // is a correct CORBA id.
  assert(repository_id);
  assert(uses_port_name);
  if (CORBA::is_nil(port_prop))
    throw Engines::DSC::BadProperty();

  my_ports_it = my_ports.find(uses_port_name);
  if (my_ports_it ==  my_ports.end()) {
    // Creating a new uses port
    port_t * new_port = new port_t();
    new_port->type = uses;
    new_port->connection_nbr = 0;
    new_port->uses_port_refs.length(0);
    new_port->repository_id = repository_id;
    new_port->port_prop = Ports::PortProperties::_duplicate(port_prop);

    // Port into port's map
    my_ports[uses_port_name] = new_port;
  }
  else
    throw Engines::DSC::PortAlreadyDefined();
}

Here is the caller graph for this function:

void Engines_DSC_interface::connect_provides_port ( const char *  provides_port_name) throw (Engines::DSC::PortNotDefined) [virtual]
See also:
Engines::DSC::connect_provides_port
Note:
This method uses Callbacks mechanism to inform the provides port how much uses ports are connected with. Currently, the provides port doesn't know its uses ports references. It's framework or application role to manage connections between ports.

Reimplemented in DSC_BASIC_EXPORT, and Engines_ParallelDSC_i.

Definition at line 190 of file DSC_interface.cxx.

{
  // Method arg test
  assert(provides_port_name);

  // Searching the provides port
  my_ports_it = my_ports.find(provides_port_name);
  if (my_ports_it ==  my_ports.end())
    throw Engines::DSC::PortNotDefined();
  if (my_ports[provides_port_name]->type != provides)
    throw Engines::DSC::PortNotDefined();


  // Adding a new connection
  my_ports[provides_port_name]->connection_nbr += 1;
  // User code is informed
  provides_port_changed(provides_port_name, 
                        my_ports[provides_port_name]->connection_nbr,
                        Engines::DSC::AddingConnection
                       );
}
void Engines_DSC_interface::connect_uses_port ( const char *  uses_port_name,
Ports::Port_ptr  provides_port_ref 
) throw (Engines::DSC::PortNotDefined, Engines::DSC::BadPortType, Engines::DSC::NilPort) [virtual]
See also:
Engines::DSC::connect_uses_port
Note:
This method uses Callbacks mechanism to inform the uses port how much provides ports are connected with.

Reimplemented in DSC_BASIC_EXPORT, and Engines_ParallelDSC_i.

Definition at line 214 of file DSC_interface.cxx.

{
  // Method arg test
  assert(uses_port_name);

  if (CORBA::is_nil(provides_port_ref))
    throw Engines::DSC::NilPort();

  // Searching the uses port
  my_ports_it = my_ports.find(uses_port_name);
  if (my_ports_it ==  my_ports.end())
    throw Engines::DSC::PortNotDefined();
  if (my_ports[uses_port_name]->type != uses) {
    Engines::DSC::BadPortType BPT;
    BPT.expected = CORBA::string_dup("Expected a uses port");
    BPT.received = CORBA::string_dup((std::string("Received a provides/none port : ")+uses_port_name).c_str());
    throw BPT;
  }

  // repository_id test
  const char * repository_id = my_ports[uses_port_name]->repository_id.c_str();
  if (provides_port_ref->_is_a(repository_id)) 
  {
    // Adding provides port into the uses port sequence
    CORBA::ULong lgth = my_ports[uses_port_name]->uses_port_refs.length();
    my_ports[uses_port_name]->
      uses_port_refs.length(lgth + 1);
    my_ports[uses_port_name]->uses_port_refs[lgth] = 
      Ports::Port::_duplicate(provides_port_ref);

    // Adding a new connection
    my_ports[uses_port_name]->connection_nbr += 1;
    // User code is informed
    uses_port_changed(uses_port_name,
                      new Engines::DSC::uses_port(my_ports[uses_port_name]->uses_port_refs),
                      Engines::DSC::AddingConnection);
  }
  else {
    Engines::DSC::BadPortType BPT;
    BPT.expected = CORBA::string_dup("Expected ...");
    BPT.received = CORBA::string_dup((std::string("Received an incorrect repository id type ")+
                                      repository_id).c_str());
    throw BPT;
  }

}
void Engines_DSC_interface::disconnect_provides_port ( const char *  provides_port_name,
const Engines::DSC::Message  message 
) throw (Engines::DSC::PortNotDefined, Engines::DSC::PortNotConnected) [virtual]
See also:
Engines::DSC::disconnect_provides_port
Note:
This method uses Callbacks mechanism to inform the provides port how much uses ports are connected with. Currently, the provides port doesn't know its uses ports references. It's framework or application role to manage connections between ports.

Reimplemented in DSC_BASIC_EXPORT, and Engines_ParallelDSC_i.

Definition at line 286 of file DSC_interface.cxx.

{
  // Method args test
  assert(provides_port_name);

  my_ports_it = my_ports.find(provides_port_name);
  if (my_ports_it ==  my_ports.end())
    throw Engines::DSC::PortNotDefined();
  if (my_ports[provides_port_name]->type != provides)
    throw Engines::DSC::PortNotDefined();

  // Is it connected ?
  if (my_ports[provides_port_name]->connection_nbr > 0) 
  {
    my_ports[provides_port_name]->connection_nbr -= 1;
    provides_port_changed(provides_port_name,
                          my_ports[provides_port_name]->connection_nbr,
                          message);
  }
  else
    throw Engines::DSC::PortNotConnected();
}
void Engines_DSC_interface::disconnect_uses_port ( const char *  uses_port_name,
Ports::Port_ptr  provides_port_ref,
const Engines::DSC::Message  message 
) throw (Engines::DSC::PortNotDefined, Engines::DSC::PortNotConnected, Engines::DSC::BadPortReference) [virtual]
See also:
Engines::DSC::disconnect_uses_port
Note:
This method uses Callbacks mechanism to inform the uses port how much provides ports are connected with.
Warning:
The new sequence of the uses port is sended by the callback. The old sequence is not destoyed. Is uses port user's role to destroy the sequence.

Reimplemented in DSC_BASIC_EXPORT, and Engines_ParallelDSC_i.

Definition at line 313 of file DSC_interface.cxx.

{
  // Method args test
  assert(uses_port_name);

  my_ports_it = my_ports.find(uses_port_name);
  if (my_ports_it ==  my_ports.end())
    throw Engines::DSC::PortNotDefined();
  if (my_ports[uses_port_name]->type != uses)
    throw Engines::DSC::PortNotDefined();

  if (CORBA::is_nil(provides_port_ref))
    throw Engines::DSC::BadPortReference();

  // Is it connected ?
  if (my_ports[uses_port_name]->connection_nbr > 0) {
    CORBA::Long port_index = -1;
    CORBA::ULong seq_length = my_ports[uses_port_name]->uses_port_refs.length(); 
    for(int i = 0; i < seq_length; i++)
    {
      if (my_ports[uses_port_name]->uses_port_refs[i]->_is_equivalent(provides_port_ref))
      {
        port_index = i;
        break;
      }
    }
    if (port_index == -1)
      throw Engines::DSC::BadPortReference();

    my_ports[uses_port_name]->connection_nbr -= 1;
    Engines::DSC::uses_port * new_uses_port = 
      new Engines::DSC::uses_port();
    new_uses_port->length(seq_length - 1);

    int index_ancien = 0;
    int index_nouveau = 0;
    for(;index_ancien < seq_length;) {
      if (index_ancien == port_index) 
      {
        // Rien a faire !
        // On ne change pas le index du nouveau tableau
        index_ancien += 1;
      }
      else 
      {
        (*new_uses_port)[index_nouveau] = my_ports[uses_port_name]->uses_port_refs[index_ancien];
        index_ancien += 1;
        index_nouveau += 1;
      }
    }

    // New uses port's sequence
    my_ports[uses_port_name]->uses_port_refs = *new_uses_port;

    // The user code is informed
    uses_port_changed(uses_port_name,
                      new_uses_port,
                      message);
  }
  else
    throw Engines::DSC::PortNotConnected();
}
Ports::PortProperties_ptr Engines_DSC_interface::get_port_properties ( const char *  port_name) throw (Engines::DSC::PortNotDefined) [virtual]
See also:
Engines::DSC::get_port_properties

Reimplemented in DSC_BASIC_EXPORT, and Engines_ParallelDSC_i.

Definition at line 382 of file DSC_interface.cxx.

{
  Ports::PortProperties_ptr rtn_properties = Ports::PortProperties::_nil();

  // Method arg test
  assert(port_name);

  my_ports_it = my_ports.find(port_name);
  if (my_ports_it ==  my_ports.end())
    throw Engines::DSC::PortNotDefined();

  rtn_properties = Ports::PortProperties::_duplicate(my_ports[port_name]->port_prop);
  return rtn_properties;
}
Ports::Port_ptr Engines_DSC_interface::get_provides_port ( const char *  provides_port_name,
const CORBA::Boolean  connection_error 
) throw (Engines::DSC::PortNotDefined, Engines::DSC::PortNotConnected, Engines::DSC::BadPortType) [virtual]
See also:
Engines::DSC::get_provides_port

Reimplemented in DSC_BASIC_EXPORT, and Engines_ParallelDSC_i.

Definition at line 114 of file DSC_interface.cxx.

{
  // Method arg test
  assert(provides_port_name);

  Ports::Port_ptr rtn_port = Ports::Port::_nil();
//   std::cout << "---- DSC_Interface : MARK 1 ---- Recherche de : " << provides_port_name << "----" << std::endl;
//   ports::iterator it;
//   std::cout << "----> ";
//   for(it=my_ports.begin();it!=my_ports.end();++it) 
//     std::cout << "|"<<(*it).first<<"|, ";
//   std::cout << std::endl;
 
  // Searching the port
  my_ports_it = my_ports.find(provides_port_name);
  if (my_ports_it ==  my_ports.end())
    throw Engines::DSC::PortNotDefined();
  if (my_ports[provides_port_name]->type != provides) {
    Engines::DSC::BadPortType BPT;
    BPT.expected = CORBA::string_dup("Expected a provides port");
    BPT.received = CORBA::string_dup((std::string("Received a uses/none port : ")+provides_port_name).c_str());
    throw BPT;
  }

  if (my_ports[provides_port_name]->connection_nbr == 0 && connection_error)
    throw Engines::DSC::PortNotConnected();

  rtn_port = Ports::Port::_duplicate(my_ports[provides_port_name]->provides_port_ref);
  return rtn_port;
}

Here is the caller graph for this function:

See also:
Engines::DSC::get_uses_port

Reimplemented in DSC_BASIC_EXPORT, and Engines_ParallelDSC_i.

Definition at line 150 of file DSC_interface.cxx.

{
  // Method arg test
  assert(uses_port_name);

  Engines::DSC::uses_port * rtn_port = NULL;  

  // Searching the uses port
  my_ports_it = my_ports.find(uses_port_name);
  if (my_ports_it == my_ports.end())
    throw Engines::DSC::PortNotDefined();
  if (my_ports[uses_port_name]->type != uses){
    Engines::DSC::BadPortType BPT;
    BPT.expected = CORBA::string_dup("Expected a uses port");
    BPT.received = CORBA::string_dup((std::string("Received a provides/none port : ")+uses_port_name).c_str());
#ifdef MYDEBUG
   std::cout << "---- DSC_Interface : MARK 1 ---- exception : " << uses_port_name << "----" << std::endl;
#endif
    throw BPT;
  }

  // Is the port connected ?
  if (my_ports[uses_port_name]->connection_nbr > 0) {
    rtn_port = new Engines::DSC::uses_port(my_ports[uses_port_name]->uses_port_refs);
  }
  else
    {
#ifdef MYDEBUG
   std::cout << "---- DSC_Interface : MARK 2 ---- exception : " << uses_port_name << "----" << std::endl;
#endif
    throw Engines::DSC::PortNotConnected();
    }
  
  return rtn_port;
}
CORBA::Boolean Engines_DSC_interface::is_connected ( const char *  port_name) throw (Engines::DSC::PortNotDefined) [virtual]
See also:
Engines::DSC::is_connected

Reimplemented in DSC_BASIC_EXPORT, and Engines_ParallelDSC_i.

Definition at line 266 of file DSC_interface.cxx.

{
  CORBA::Boolean rtn = false;

  // Method arg test
  assert(port_name);

  my_ports_it = my_ports.find(port_name);
  if (my_ports_it ==  my_ports.end())
    throw Engines::DSC::PortNotDefined();

  // Is it connected ?
  if (my_ports[port_name]->connection_nbr > 0)
    rtn = true;

  return rtn;
}
void Engines_DSC_interface::writeEvent ( const char *  request,
const std::string &  containerName,
const char *  instance_name,
const char *  port_name,
const char *  error,
const char *  message 
) [static]

Write a record in the trace file.

Parameters:
requestthe name of the request executed
containerNamethe name of the container where the request is executed
instance_namethe name of the component where the request is executed
port_namethe name of the port that is concerned
errorif an error has occured, a string that identifies the error
messageinformations about error or about the request

Definition at line 499 of file DSC_interface.cxx.

{
  if(traceLevel < 0)
    initTrace(containerName);
  if(traceLevel == 0)return;

#ifdef WNT
#else
  struct timeval tv;
  gettimeofday(&tv,0);
  long tt0=tv.tv_sec/3600; //hours

  if(traceType == 2)
    {
      //notifier (not used: salome notifier is now obsolete)
      std::ostringstream msg;
      msg.width(7);
      msg << tt0 ;
      msg << ":" ;
      long tt1=(tv.tv_sec-3600*tt0)/60;//minutes
      msg.width(2);
      msg << tt1 ;
      msg << ":" ;
      long tt2=tv.tv_sec - 3600*tt0-60*tt1; //seconds
      msg.width(2);
      msg << tt2 ;
      msg << ":" ;
      long tt3=tv.tv_usec/1000; //milliseconds
      msg.width(3);
      msg << tt3 ;
      msg << " | " ;
      msg.width(24);
      msg << error;
      msg << " | " ;
      msg << message ;
      //send event to notifier (containerName.c_str(),instance_name, request, msg.str().c_str())
    }
  else
    {
      //cerr or file
      out->width(7);
      *out << tt0 ;
      *out << ":" ;
      long tt1=(tv.tv_sec-3600*tt0)/60;//minutes
      out->width(2);
      *out << tt1 ;
      *out << ":" ;
      long tt2=tv.tv_sec - 3600*tt0-60*tt1; //seconds
      out->width(2);
      *out << tt2 ;
      *out << ":" ;
      long tt3=tv.tv_usec/1000; //milliseconds
      out->width(3);
      *out << tt3 ;
      *out << " | " ;
      out->width(16);
      *out << request ;
      *out << " | " ;
      out->width(16);
      *out << containerName ;
      *out << " | " ;
      out->width(16);
      *out << instance_name ;
      *out << " | " ;
      out->width(16);
      *out << port_name ;
      *out << " | " ;
      out->width(24);
      *out << error;
      *out << " | " ;
      *out << message ;
      *out << std::endl;
    }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 181 of file DSC_interface.hxx.

ports::iterator Engines_DSC_interface::my_ports_it [protected]

Definition at line 182 of file DSC_interface.hxx.


The documentation for this class was generated from the following files: