From 8e10646abd732456539300b7407cd3b19c88d8a9 Mon Sep 17 00:00:00 2001 From: prascle Date: Tue, 18 Apr 2006 14:25:50 +0000 Subject: [PATCH] PR: add matrix type --- idl/SALOME_Comm.idl | 6 ++ src/Communication/Makefile.am | 8 +- src/Communication/MatrixClient.cxx | 12 +++ src/Communication/MatrixClient.hxx | 13 +++ src/Communication/SALOME_Matrix_i.cxx | 33 +++++++ src/Communication/SALOME_Matrix_i.hxx | 26 ++++++ src/Communication_SWIG/libSALOME_Comm.i | 115 ++++++++++++++++++++++++ 7 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 src/Communication/MatrixClient.cxx create mode 100644 src/Communication/MatrixClient.hxx create mode 100644 src/Communication/SALOME_Matrix_i.cxx create mode 100644 src/Communication/SALOME_Matrix_i.hxx diff --git a/idl/SALOME_Comm.idl b/idl/SALOME_Comm.idl index b4e1f9de5..0ce2dc7c3 100644 --- a/idl/SALOME_Comm.idl +++ b/idl/SALOME_Comm.idl @@ -118,6 +118,12 @@ module SALOME { interface SocketSenderInt : SenderInt,SocketSender { }; + + interface Matrix { + SenderDouble getData(); + long getSizeOfColumn(); + void release(); + }; }; #endif diff --git a/src/Communication/Makefile.am b/src/Communication/Makefile.am index fd20d963a..5131e7b75 100644 --- a/src/Communication/Makefile.am +++ b/src/Communication/Makefile.am @@ -11,7 +11,9 @@ salomeinclude_HEADERS = \ SenderFactory.hxx \ SALOMEMultiComm.hxx \ MultiCommException.hxx \ - SALOME_Comm_i.hxx + SALOME_Comm_i.hxx \ + MatrixClient.hxx \ + SALOME_Matrix_i.hxx # Scripts to be installed @@ -50,15 +52,19 @@ OPT_LDFLAGS = -Xlinker -export-dynamic lib_LTLIBRARIES = libSalomeCommunication.la libSalomeCommunication_la_SOURCES =\ SALOME_Comm_i.cxx \ + SALOME_Matrix_i.cxx \ SenderFactory.cxx \ MultiCommException.cxx \ SALOMEMultiComm.cxx \ ReceiverFactory.cxx \ + MatrixClient.cxx \ \ MultiCommException.hxx \ SALOME_Comm_i.hxx \ + SALOME_Matrix_i.hxx \ SenderFactory.hxx \ ReceiverFactory.hxx \ + MatrixClient.hxx \ SALOMEMultiComm.hxx \ Receivers.hxx \ Receiver.hxx diff --git a/src/Communication/MatrixClient.cxx b/src/Communication/MatrixClient.cxx new file mode 100644 index 000000000..a7eeca264 --- /dev/null +++ b/src/Communication/MatrixClient.cxx @@ -0,0 +1,12 @@ +#include "MatrixClient.hxx" +#include "ReceiverFactory.hxx" + +double *MatrixClient::getValue(SALOME::Matrix_ptr distMat, int& columnSize, int& rowSize) +{ + long totalSize; + double *ret=ReceiverFactory::getValue(distMat->getData(),totalSize); + columnSize=distMat->getSizeOfColumn(); + distMat->release(); + rowSize=totalSize/columnSize; + return ret; +} diff --git a/src/Communication/MatrixClient.hxx b/src/Communication/MatrixClient.hxx new file mode 100644 index 000000000..489340efa --- /dev/null +++ b/src/Communication/MatrixClient.hxx @@ -0,0 +1,13 @@ +#ifndef __MATRIXCLIENT_HXX__ +#define __MATRIXCLIENT_HXX__ + +#include +#include CORBA_SERVER_HEADER(SALOME_Comm) + +class MatrixClient +{ +public: + static double *getValue(SALOME::Matrix_ptr distMat, int& columnSize, int& rowSize); +}; + +#endif diff --git a/src/Communication/SALOME_Matrix_i.cxx b/src/Communication/SALOME_Matrix_i.cxx new file mode 100644 index 000000000..72521d69f --- /dev/null +++ b/src/Communication/SALOME_Matrix_i.cxx @@ -0,0 +1,33 @@ +#include "SALOME_Matrix_i.hxx" +#include "SenderFactory.hxx" + +SALOME_Matrix_i::SALOME_Matrix_i(const SALOMEMultiComm& multiCommunicator,const double *tabToSend,int nbOfRow,int nbOfColumn,bool ownTabToSend):_tabToSend(tabToSend), + _nbOfRow(nbOfRow), + _nbOfColumn(nbOfColumn), + _ownTabToSend(ownTabToSend), + _type(multiCommunicator) +{ +} + +SALOME_Matrix_i::~SALOME_Matrix_i() +{ + if(_ownTabToSend) + delete [] _tabToSend; +} + +SALOME::SenderDouble_ptr SALOME_Matrix_i::getData() +{ + return SenderFactory::buildSender(_type,_tabToSend,_nbOfRow*_nbOfColumn,_ownTabToSend); +} + +CORBA::Long SALOME_Matrix_i::getSizeOfColumn() +{ + return _nbOfColumn; +} + +void SALOME_Matrix_i::release() +{ + PortableServer::ObjectId_var oid = _default_POA()->servant_to_id(this); + _default_POA()->deactivate_object(oid); + _remove_ref(); +} diff --git a/src/Communication/SALOME_Matrix_i.hxx b/src/Communication/SALOME_Matrix_i.hxx new file mode 100644 index 000000000..24a559781 --- /dev/null +++ b/src/Communication/SALOME_Matrix_i.hxx @@ -0,0 +1,26 @@ +#ifndef __SALOME_MATRIX_I_HXX__ +#define __SALOME_MATRIX_I_HXX__ + +#include +#include +#include CORBA_SERVER_HEADER(SALOME_Comm) +#include "SALOMEMultiComm.hxx" + +class SALOME_Matrix_i : public virtual POA_SALOME::Matrix, + public PortableServer::RefCountServantBase { +private: + const double *_tabToSend; + int _nbOfRow; + int _nbOfColumn; + bool _ownTabToSend; + SALOMEMultiComm _type; +protected: + ~SALOME_Matrix_i(); +public: + SALOME_Matrix_i(const SALOMEMultiComm& multiCommunicator,const double *tabToSend,int nbOfRow,int nbOfColumn,bool ownTabToSend=false); + SALOME::SenderDouble_ptr getData(); + CORBA::Long getSizeOfColumn(); + void release(); +}; + +#endif diff --git a/src/Communication_SWIG/libSALOME_Comm.i b/src/Communication_SWIG/libSALOME_Comm.i index 9a1b8dc0c..7fce88a21 100644 --- a/src/Communication_SWIG/libSALOME_Comm.i +++ b/src/Communication_SWIG/libSALOME_Comm.i @@ -21,10 +21,13 @@ %{ #include "ReceiverFactory.hxx" + #include "MatrixClient.hxx" #undef SEEK_SET #undef SEEK_CUR #undef SEEK_END #include "SALOME_Comm_i.hxx" + #include "SALOMEMultiComm.hxx" + #include "SenderFactory.hxx" %} %typemap(python,in) SALOME::SenderDouble_ptr @@ -87,6 +90,42 @@ $1 = t; } +%typemap(python,out) SALOME::SenderDouble_ptr +{ + PyObject* pdict = PyDict_New(); + PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins()); + PyRun_String("import CORBA", Py_single_input, pdict, pdict); + PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input, + pdict, pdict); + PyObject* orb = PyDict_GetItemString(pdict, "o"); + // Get the orb Corba C++ + int argc = 0; + char *xargv = ""; + char **argv = &xargv; + CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv); + std::string s = ORB->object_to_string($1); + PyObject * tmp = PyString_FromString(s.c_str()); + $result = PyObject_CallMethod(orb, "string_to_object", "O", tmp); +} + +%typemap(python,out) SALOME::SenderInt_ptr +{ + PyObject* pdict = PyDict_New(); + PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins()); + PyRun_String("import CORBA", Py_single_input, pdict, pdict); + PyRun_String("o = CORBA.ORB_init([''], CORBA.ORB_ID);", Py_single_input, + pdict, pdict); + PyObject* orb = PyDict_GetItemString(pdict, "o"); + // Get the orb Corba C++ + int argc = 0; + char *xargv = ""; + char **argv = &xargv; + CORBA::ORB_var ORB = CORBA::ORB_init(argc, argv); + std::string s = ORB->object_to_string($1); + PyObject * tmp = PyString_FromString(s.c_str()); + $result = PyObject_CallMethod(orb, "string_to_object", "O", tmp); +} + PyObject * getValueForSenderDouble(SALOME::SenderDouble_ptr senderDouble); %{ @@ -139,3 +178,79 @@ PyObject * getValueForSenderInt(SALOME::SenderInt_ptr senderInt) return result; } %} + +PyObject * getValueForMatrix(SALOME::Matrix_ptr matrix); +%{ +PyObject * getValueForMatrix(SALOME::Matrix_ptr matrix) +{ + PyObject *py_list; + int column,row; + double *ret=MatrixClient::getValue(matrix,column,row); + py_list = PyList_New(row); + for(int i=0;i