From 47e1da17f2887dc2b624ed8bd65cf0043813dd33 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Thu, 15 Apr 2021 21:30:45 +0200 Subject: [PATCH] Implementation de SALOME_Embedded_NamingService_Client pour le server SALOME_Container --- src/Container/SALOME_Container_i.hxx | 2 +- src/NamingService/CMakeLists.txt | 2 + .../SALOME_Embedded_NamingService.cxx | 28 +-------- .../SALOME_Embedded_NamingService.hxx | 2 +- .../SALOME_Embedded_NamingService_Client.cxx | 62 +++++++++++++++++++ .../SALOME_Embedded_NamingService_Client.hxx | 43 +++++++++++++ .../SALOME_Embedded_NamingService_Common.cxx | 48 ++++++++++++++ .../SALOME_Embedded_NamingService_Common.hxx | 30 +++++++++ 8 files changed, 189 insertions(+), 28 deletions(-) create mode 100644 src/NamingService/SALOME_Embedded_NamingService_Client.cxx create mode 100644 src/NamingService/SALOME_Embedded_NamingService_Client.hxx create mode 100644 src/NamingService/SALOME_Embedded_NamingService_Common.cxx create mode 100644 src/NamingService/SALOME_Embedded_NamingService_Common.hxx diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index 427c12392..5ce4ff26e 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -60,7 +60,7 @@ public: PortableServer::POA_ptr poa, char * containerName , int argc, char* argv[], - SALOME_NamingService_Container_Abstract *ns = nullptr, + SALOME_NamingService_Container_Abstract *ns = nullptr, bool isServantAloneInProcess = true); virtual ~Engines_Container_i(); diff --git a/src/NamingService/CMakeLists.txt b/src/NamingService/CMakeLists.txt index b9a6fc4ed..d825ce3fe 100644 --- a/src/NamingService/CMakeLists.txt +++ b/src/NamingService/CMakeLists.txt @@ -37,6 +37,8 @@ SET(SalomeNS_SOURCES SALOME_Fake_NamingService.cxx SALOME_NamingService_Abstract.cxx SALOME_Embedded_NamingService.cxx + SALOME_Embedded_NamingService_Common.cxx + SALOME_Embedded_NamingService_Client.cxx ) ADD_DEFINITIONS(${OMNIORB_DEFINITIONS}) diff --git a/src/NamingService/SALOME_Embedded_NamingService.cxx b/src/NamingService/SALOME_Embedded_NamingService.cxx index 3eca13ba6..b9f57913f 100644 --- a/src/NamingService/SALOME_Embedded_NamingService.cxx +++ b/src/NamingService/SALOME_Embedded_NamingService.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2021 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2021 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -18,36 +18,12 @@ // #include "SALOME_Embedded_NamingService.hxx" +#include "SALOME_Embedded_NamingService_Common.hxx" #include "SALOME_Fake_NamingService.hxx" -#include "SALOME_KernelORB.hxx" #include #include -CORBA::Object_var IORToObject(const Engines::IORType& ObjRef) -{ - CORBA::ORB_ptr orb(KERNEL::getORB()); - CORBA::ULong size(ObjRef.length()); - std::unique_ptr pt(new char[size+1]); - pt[size] = '\0'; - for(CORBA::ULong i = 0 ; i < size ; ++i) - pt[i] = ObjRef[i]; - CORBA::Object_var obj = orb->string_to_object(pt.get()); - return obj; -} - -Engines::IORType *ObjectToIOR(CORBA::Object_ptr obj) -{ - std::unique_ptr ret(new Engines::IORType); - CORBA::ORB_ptr orb(KERNEL::getORB()); - CORBA::String_var ior = orb->object_to_string(obj); - auto len( strlen(ior) ); - ret->length( len ); - for(std::size_t i = 0 ; i < len ; ++i) - (*ret)[i] = ior[i]; - return ret.release(); -} - void SALOME_Embedded_NamingService::Register(const Engines::IORType& ObjRef, const char *Path) { SALOME_Fake_NamingService ns; diff --git a/src/NamingService/SALOME_Embedded_NamingService.hxx b/src/NamingService/SALOME_Embedded_NamingService.hxx index 38f76c758..8a152aa17 100644 --- a/src/NamingService/SALOME_Embedded_NamingService.hxx +++ b/src/NamingService/SALOME_Embedded_NamingService.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2021 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2021 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public diff --git a/src/NamingService/SALOME_Embedded_NamingService_Client.cxx b/src/NamingService/SALOME_Embedded_NamingService_Client.cxx new file mode 100644 index 000000000..9ec02a73b --- /dev/null +++ b/src/NamingService/SALOME_Embedded_NamingService_Client.cxx @@ -0,0 +1,62 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// 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, or (at your option) any later version. +// +// 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 +// + +#include "SALOME_Embedded_NamingService_Client.hxx" +#include "SALOME_Embedded_NamingService_Common.hxx" + +#include + +void SALOME_Embedded_NamingService_Client::init_orb(CORBA::ORB_ptr orb) +{ +} + +SALOME_NamingService_Container_Abstract *SALOME_Embedded_NamingService_Client::clone() +{ + return new SALOME_Embedded_NamingService_Client(*this); +} + +void SALOME_Embedded_NamingService_Client::Register(CORBA::Object_ptr ObjRef, const char* Path) +{ + std::unique_ptr ior( ObjectToIOR(ObjRef) ); + this->_remote_ns_serv->Register( *(ior.get()), Path); +} + +void SALOME_Embedded_NamingService_Client::Destroy_FullDirectory(const char* Path) +{ + this->_remote_ns_serv->Destroy_FullDirectory(Path); +} + +void SALOME_Embedded_NamingService_Client::Destroy_Name(const char* Path) +{ + this->_remote_ns_serv->Destroy_Name(Path); +} + +CORBA::Object_ptr SALOME_Embedded_NamingService_Client::Resolve(const char* Path) +{ + std::unique_ptr ior( this->_remote_ns_serv->Resolve(Path) ); + CORBA::Object_var ret( IORToObject( *(ior.get()) ) ); + return CORBA::Object::_duplicate(ret); +} + +CORBA::Object_ptr SALOME_Embedded_NamingService_Client::ResolveFirst(const char* Path) +{ + std::unique_ptr ior( this->_remote_ns_serv->ResolveFirst(Path) ); + CORBA::Object_var ret( IORToObject( *(ior.get()) ) ); + return CORBA::Object::_duplicate(ret); +} diff --git a/src/NamingService/SALOME_Embedded_NamingService_Client.hxx b/src/NamingService/SALOME_Embedded_NamingService_Client.hxx new file mode 100644 index 000000000..00befd4d5 --- /dev/null +++ b/src/NamingService/SALOME_Embedded_NamingService_Client.hxx @@ -0,0 +1,43 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// 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, or (at your option) any later version. +// +// 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 +// + +#pragma once + +#include "SALOME_NamingService_defs.hxx" +#include "SALOME_NamingService_Abstract.hxx" + +#include +#include CORBA_CLIENT_HEADER(SALOME_Embedded_NamingService) + +class NAMINGSERVICE_EXPORT SALOME_Embedded_NamingService_Client : public SALOME_NamingService_Container_Abstract +{ +public: + SALOME_Embedded_NamingService_Client(Engines::EmbeddedNamingService_var remoteNSServ):_remote_ns_serv(remoteNSServ) { } + void init_orb(CORBA::ORB_ptr orb=0) override; + SALOME_NamingService_Container_Abstract *clone() override; + void Register(CORBA::Object_ptr ObjRef, const char* Path) override; + void Destroy_FullDirectory(const char* Path) override; + void Destroy_Name(const char* Path) override; + CORBA::Object_ptr Resolve(const char* Path) override; + CORBA::Object_ptr ResolveFirst(const char* Path) override; +private: + SALOME_Embedded_NamingService_Client(const SALOME_Embedded_NamingService_Client& other) = default; +private: + Engines::EmbeddedNamingService_var _remote_ns_serv; +}; diff --git a/src/NamingService/SALOME_Embedded_NamingService_Common.cxx b/src/NamingService/SALOME_Embedded_NamingService_Common.cxx new file mode 100644 index 000000000..46675b433 --- /dev/null +++ b/src/NamingService/SALOME_Embedded_NamingService_Common.cxx @@ -0,0 +1,48 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// 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, or (at your option) any later version. +// +// 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 +// + +#include "SALOME_Embedded_NamingService_Common.hxx" +#include "SALOME_KernelORB.hxx" + +#include +#include + +CORBA::Object_var IORToObject(const Engines::IORType& ObjRef) +{ + CORBA::ORB_ptr orb(KERNEL::getORB()); + CORBA::ULong size(ObjRef.length()); + std::unique_ptr pt(new char[size+1]); + pt[size] = '\0'; + for(CORBA::ULong i = 0 ; i < size ; ++i) + pt[i] = ObjRef[i]; + CORBA::Object_var obj = orb->string_to_object(pt.get()); + return obj; +} + +Engines::IORType *ObjectToIOR(CORBA::Object_ptr obj) +{ + std::unique_ptr ret(new Engines::IORType); + CORBA::ORB_ptr orb(KERNEL::getORB()); + CORBA::String_var ior = orb->object_to_string(obj); + auto len( strlen(ior) ); + ret->length( len ); + for(std::size_t i = 0 ; i < len ; ++i) + (*ret)[i] = ior[i]; + return ret.release(); +} diff --git a/src/NamingService/SALOME_Embedded_NamingService_Common.hxx b/src/NamingService/SALOME_Embedded_NamingService_Common.hxx new file mode 100644 index 000000000..3707cdd8c --- /dev/null +++ b/src/NamingService/SALOME_Embedded_NamingService_Common.hxx @@ -0,0 +1,30 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// 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, or (at your option) any later version. +// +// 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 +// + +#pragma once + +#include "SALOME_NamingService_defs.hxx" + +#include + +#include CORBA_CLIENT_HEADER(SALOME_Embedded_NamingService) + +CORBA::Object_var IORToObject(const Engines::IORType& ObjRef); + +Engines::IORType *ObjectToIOR(CORBA::Object_ptr obj); -- 2.39.2