# ParaView viewer specific targets:
IF(SALOME_USE_PVVIEWER)
- LIST(APPEND _${PROJECT_NAME}_exposed_targets PVViewer)
+ LIST(APPEND _${PROJECT_NAME}_exposed_targets PVViewer PVServerService)
ENDIF()
SET(GUI_ViewerData ViewerData)
SET(GUI_VTKViewer VTKViewer)
SET(GUI_PVViewer PVViewer)
+SET(GUI_PVServerService PVServerService)
SET(GUI_vtkEDFOverloads vtkEDFOverloads)
SET(GUI_vtkTools vtkTools)
SET(GUI_SalomeGuiHelpers SalomeGuiHelpers)
OMNIORB_ADD_MODULE(SalomeIDLGUI "${SalomeIDLGUI_IDLSOURCES}" "${_idl_include_dirs}" "${_idl_link_flags}")
INSTALL(TARGETS SalomeIDLGUI EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
+
+########################################################################
+### PVServer service:
+SET(SalomeIDLPVSERVER_IDLSOURCES
+ ${CMAKE_CURRENT_SOURCE_DIR}/PVSERVER_Gen.idl
+ )
+# Demand Python generation:
+SET(OMNIORB_PYTHON_BACKEND 1)
+OMNIORB_ADD_MODULE(SalomeIDLPVServer "${SalomeIDLPVSERVER_IDLSOURCES}" "${_idl_include_dirs}" "${_idl_link_flags}")
+INSTALL(TARGETS SalomeIDLPVServer EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
+
--- /dev/null
+// Copyright (C) 2010-2015 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
+//
+// Author : Adrien Bruneton (CEA)
+
+
+#ifndef __PVSERVER_GEN__
+#define __PVSERVER_GEN__
+
+#include "SALOME_Exception.idl"
+
+/*!
+ PVSERVER interface. This is a standalone service, not inheriting the EngineComponent interfaces.
+
+ The main service provided by the interface is to give to the caller the URL of the pvserver, and to launch it
+ if it is not already started.
+ The connection to the ParaView's pvserver should then be done using ParaView's API directly.
+*/
+module PVSERVER_ORB {
+
+ /*!
+ * \brief The main interface class for PVSERVER CORBA service.
+ * Instantiation of this class has to be done before access to any other PARAVIS interfaces
+ */
+ interface PVSERVER_Gen
+ {
+
+ /*!
+ * \brief Returns IOR of the current object.
+ */
+ string GetIOR();
+
+ /*! If a pvserver is already started, returns its current URL, regardless of the provided
+ * parameters.
+ * If not, start a pvserver on the machine hosting the PARAVIS engine and on the given port.
+ * If port <= 0, a free port is automatically detected, starting from the usual 11111 pvserver port.
+ */
+ string FindOrStartPVServer(in long port);
+
+ /*! Tries to stop the PVserver currently running (send KILL).
+ * @return false if no server was running, true otherwise.
+ */
+ boolean StopPVServer();
+
+ /*! Indicates if the GUI process is already connected to the pvserver.
+ * This avoids multiple attempts to connect from a single thread (makes ParaView crash). */
+ void SetGUIConnected(in boolean isConnected);
+
+ /*! Indicates if the GUI process is already connected to the pvserver.
+ * This avoids multiple attempts to connect from a single thread (makes ParaView crash). */
+ boolean GetGUIConnected();
+
+ };
+
+};
+
+#endif
\ No newline at end of file
# ParaView Viewer
IF(SALOME_USE_PVVIEWER)
ADD_SUBDIRECTORY(PVViewer)
+ ADD_SUBDIRECTORY(PVServerService)
ENDIF()
##
createActionForViewer( NewGraphicsViewId, newWinMenu, QString::number( 5 ), Qt::ALT+Qt::Key_C );
#endif
#ifndef DISABLE_PVVIEWER
- QStringList aModuleNames;
- modules( aModuleNames, false );
- if ( aModuleNames.contains( "ParaViS", Qt::CaseInsensitive ) )
- createActionForViewer( NewPVViewId, newWinMenu, QString::number( 6 ), Qt::ALT+Qt::Key_A );
+ createActionForViewer( NewPVViewId, newWinMenu, QString::number( 6 ), Qt::ALT+Qt::Key_A );
#endif
#ifndef DISABLE_PYVIEWER
createActionForViewer( NewPyViewerId, newWinMenu, QString::number( 7 ), Qt::ALT+Qt::Key_Y );
--- /dev/null
+# Copyright (C) 2010-2015 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
+#
+
+ADD_SUBDIRECTORY(ENGINE)
+IF(NOT SALOME_LIGHT_ONLY)
+ ADD_SUBDIRECTORY(ServiceLoader)
+ENDIF()
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${KERNEL_INCLUDE_DIRS}
+ ${PROJECT_SOURCE_DIR}/src/PyInterp
+ )
+
+ADD_DEFINITIONS(
+ ${KERNEL_DEFINITIONS}
+ ${PYTHON_DEFINITIONS}
+ )
+
+SET(_link_LIBRARIES
+ ${KERNEL_OpUtil} # class SALOME_Exception
+ PyInterp # class PyLockWrapper
+ )
+
+# --- headers ---
+SET(PVServer_HEADERS
+ PVServerService.h
+ PVServer_ServiceWrapper.h
+)
+
+# --- sources ---
+SET(PVServer_SOURCES
+ PVServer_ServiceWrapper.cxx
+ )
+
+SET(PVServer_SWIG
+ PVServer_ServiceLoader.i
+ )
+
+# --- rules ---
+ADD_LIBRARY(PVServerService ${PVServer_SOURCES})
+TARGET_LINK_LIBRARIES(PVServerService ${_link_LIBRARIES})
+INSTALL(TARGETS PVServerService EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
+
+# --- header installation ---
+INSTALL(FILES ${PVServer_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})
--- /dev/null
+# Copyright (C) 2010-2015 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
+#
+
+SET(_bin_SCRIPTS
+ PVSERVER_impl.py
+ )
+
+IF(NOT SALOME_LIGHT_ONLY)
+ LIST(APPEND _bin_SCRIPTS
+ PVSERVER.py
+ PVSERVER_utils.py
+ )
+ENDIF()
+
+
+# --- rules ---
+SALOME_INSTALL_SCRIPTS("${_bin_SCRIPTS}" ${SALOME_INSTALL_SCRIPT_PYTHON})
+
+
\ No newline at end of file
--- /dev/null
+# Copyright (C) 2007-2015 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
+#
+# Author : Adrien BRUNETON (CEA)
+#
+
+import PVSERVER_ORB__POA
+from SALOME_NamingServicePy import SALOME_NamingServicePy_i
+from PVSERVER_impl import PVSERVER_impl, MESSAGE
+
+class PVSERVER(PVSERVER_ORB__POA.PVSERVER_Gen,
+ PVSERVER_impl):
+ """
+ Construct an instance of PVSERVER *service*.
+ The class PVSERVER implements the CORBA interface PVSERVER_Gen (see PVSERVER_Gen.idl).
+ It is NOT inherited from the classes SALOME_ComponentPy_i, as we present
+ the class as a pure CORBA service, not as a standard SALOME component.
+ """
+ def __init__ ( self, orb, poa, contID, containerName, instanceName,
+ interfaceName ):
+
+
+ PVSERVER_impl.__init__(self)
+
+ self._orb = orb
+ self._poa = poa
+ self._instanceName = instanceName
+# self._interfaceName = interfaceName
+ self._containerName = containerName
+# self._contId = contID
+
+ self._naming_service = SALOME_NamingServicePy_i(self._orb)
+ Component_path = self._containerName + "/" + self._instanceName
+ MESSAGE( 'SALOME_ComponentPy_i Register' + str( Component_path ) )
+ id_o = poa.activate_object(self)
+ compo_o = poa.id_to_reference(id_o)
+
+ ## And launch registration
+ ##
+ self._naming_service.Register(compo_o, Component_path)
+
+ """ Override base class destroy to make sure we try to kill the pvserver
+ before leaving.
+ """
+ def destroy(self):
+ # TODO
+ self.StopPVServer()
+
\ No newline at end of file
--- /dev/null
+# Copyright (C) 2007-2015 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
+#
+# Author : Adrien Bruneton (CEA)
+#
+
+import subprocess as subp
+import socket
+from time import sleep
+import os
+from SALOME import SALOME_Exception
+#from SALOME_utilities import MESSAGE
+
+def MESSAGE(m):
+ """ Debug function """
+ pass
+ #os.system("echo \"%s\" >> /tmp/paravis_log.txt" % m)
+
+class PVSERVER_impl(object):
+ """ The core implementation (non CORBA, or Study related).
+ See the IDL for the documentation.
+ """
+ MAX_PVSERVER_PORT_TRIES = 1000 # Maximum number of tries to get a free port for the PVServer
+ PVSERVER_DEFAULT_PORT = 11111 # First port being tried to launch the pvserver
+
+ def __init__(self):
+ self.pvserverPort = -1
+ self.pvserverPop = None # Popen object from subprocess module
+ self.isGUIConnected = False # whether there is an active connection from the GUI.
+ try:
+ import paraview
+ tmp=paraview.__file__
+ except:
+ raise Exception("PVSERVER_Impl.__init__ : \"import paraview\" failed !")
+ # deduce dynamically PARAVIEW_ROOT_DIR from the paraview module location
+ self.PARAVIEW_ROOT_DIR = None
+ ZE_KEY_TO_FIND_PV_ROOT_DIR="lib"
+ li=tmp.split(os.path.sep) ; li.reverse()
+ if ZE_KEY_TO_FIND_PV_ROOT_DIR not in li:
+ raise SALOME_Exception(SALOME.ExceptionStruct(SALOME.INTERNAL_ERROR,
+ "PVSERVER_Impl.__init__ : error during dynamic deduction of PARAVIEW_ROOT_DIR : Loc of paraview module is \"%s\" ! \"%s\" is supposed to be the key to deduce it !"%(tmp,ZE_KEY_TO_FIND_PV_ROOT_DIR),
+ "PVSERVER.py", 0))
+ li=li[li.index("lib")+1:] ; li.reverse()
+ self.PARAVIEW_ROOT_DIR = os.path.sep.join(li)
+
+ """
+ Private. Identify a free port to launch the PVServer.
+ This is done by trying to bind a socket on the port.
+ We are still subject to a race condition between this detection mechanism and the actual launch of the pvserver
+ itself ...
+ """
+ def __getFreePort(self, startPort):
+ cnt = 0
+ currPort = startPort
+ while cnt < self.MAX_PVSERVER_PORT_TRIES:
+ try:
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.bind(('', currPort))
+ s.close()
+ return currPort
+ except socket.error as e:
+ cnt += 1
+ currPort += 1
+ pass
+ raise SALOME_Exception(SALOME.ExceptionStruct(SALOME.INTERNAL_ERROR,
+ "[PVSERVER] maximum number of tries to retrieve a free port for the PVServer",
+ "PVSERVER.py", 0))
+
+ def FindOrStartPVServer( self, port ):
+ MESSAGE("[PVSERVER] FindOrStartPVServer ...")
+ host = "localhost"
+ alive = True
+ if self.pvserverPop is None:
+ alive = False
+ else:
+ # Poll active server to check if still alive
+ self.pvserverPop.poll()
+ if not self.pvserverPop.returncode is None: # server terminated
+ alive = False
+
+ if alive:
+ return "cs://%s:%d" % (host, self.pvserverPort)
+
+ # (else) Server not alive, start it:
+ pvServerPath = os.path.join(self.PARAVIEW_ROOT_DIR, 'bin', 'pvserver')
+ opt = []
+ if port <= 0:
+ port = self.__getFreePort(self.PVSERVER_DEFAULT_PORT)
+ self.pvserverPop = subp.Popen([pvServerPath, "--multi-clients", "--server-port=%d" % port, "--use-offscreen-rendering"])
+ sleep(3) # Give some time to the server to start up to avoid
+ # ugly messages on the client side saying that it cannot connect
+ # Is PID still alive? If yes, consider that the launch was successful
+ self.pvserverPop.poll()
+ if self.pvserverPop.returncode is None:
+ success = True
+ self.pvserverPort = port
+ MESSAGE("[PVSERVER] pvserver successfully launched on port %d" % port)
+ else:
+ raise SALOME_Exception(SALOME.ExceptionStruct(SALOME.INTERNAL_ERROR,
+ "[PVSERVER] Unable to start PVServer on port %d!" % port,
+ "PVSERVER.py", 0))
+ return "cs://%s:%d" % (host, self.pvserverPort)
+
+ def StopPVServer( self ):
+ MESSAGE("[PVSERVER] Trying to stop PVServer (sending KILL) ...")
+ if not self.pvserverPop is None:
+ self.pvserverPop.poll()
+ if self.pvserverPop.returncode is None:
+ # Terminate if still running:
+ self.pvserverPop.terminate()
+ MESSAGE("[PVSERVER] KILL signal sent.")
+ return True
+ MESSAGE("[PVSERVER] Nothing to kill.")
+ return False
+
+ def SetGUIConnected( self, isConnected ):
+ self.isGUIConnected = isConnected
+
+ def GetGUIConnected( self ):
+ return self.isGUIConnected
+
+
+
\ No newline at end of file
--- /dev/null
+# Copyright (C) 2007-2015 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
+#
+# Author : Adrien BRUNETON (CEA)
+#
+
+from omniORB import CORBA
+from SALOME_NamingServicePy import SALOME_NamingServicePy_i
+import SALOMEDS
+
+from PVServer_ServiceLoader import PVServer_ServiceLoader
+import PVSERVER_ORB
+
+###
+# Get verbose level
+###
+__verbose__ = None
+def verbose():
+ import os
+ global __verbose__
+ if __verbose__ is None:
+ try:
+ __verbose__ = int( os.getenv( 'SALOME_VERBOSE', 0 ) )
+ except:
+ __verbose__ = 0
+ pass
+ pass
+ return __verbose__
+
+###
+# Get ORB reference
+###
+__orb__ = None
+def getORB():
+ global __orb__
+ if __orb__ is None:
+ __orb__ = CORBA.ORB_init( [''], CORBA.ORB_ID )
+ pass
+ return __orb__
+
+###
+# Get naming service instance
+###
+__naming_service__ = None
+def getNS():
+ global __naming_service__
+ if __naming_service__ is None:
+ __naming_service__ = SALOME_NamingServicePy_i( getORB() )
+ pass
+ return __naming_service__
+
+###
+# Get PVSERVER service
+###
+__service__ = None
+__serviceLoader__ = None
+def getService():
+ global __service__, __serviceLoader__
+ containerName = "FactoryServer"
+ if __serviceLoader__ is None:
+ __serviceLoader__ = PVServer_ServiceLoader()
+ if __service__ is None:
+ import PVSERVER
+ ior = __serviceLoader__.findOrLoadService(containerName)
+ obj = getORB().string_to_object( ior )
+ __service__ = obj._narrow(PVSERVER.PVSERVER)
+ pass
+ return __service__
+
+###
+# Get PVSERVER engine IOR
+###
+def getServiceIOR():
+ IOR = ""
+ if getORB() and getService():
+ IOR = getORB().object_to_string( getService() )
+ pass
+ return IOR
--- /dev/null
+// Copyright (C) 2010-2015 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
+//
+
+#ifndef PVSERVERSERVICE_H
+#define PVSERVERSERVICE_H
+
+#ifdef WIN32
+#if defined PVServerService_EXPORTS
+#define PVSERVERSERVICE_EXPORT __declspec(dllexport)
+#else
+#define PVSERVERSERVICE_EXPORT __declspec(dllimport)
+#endif
+#else
+#define PVSERVERSERVICE_EXPORT
+#endif
+
+#endif //PVSERVERSERVICE_H
--- /dev/null
+// Copyright (C) 2010-2015 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
+//
+// Author: Adrien Bruneton (CEA)
+
+#include "PVServer_ServiceWrapper.h"
+#include <Utils_SALOME_Exception.hxx>
+
+#include <PyInterp_Utils.h>
+
+class PVServer_ServiceWrapper::Private
+{
+public:
+ // Borrowed reference to the Python object representing the service
+ PyObject* pvserverService;
+};
+
+PVServer_ServiceWrapper * PVServer_ServiceWrapper::instance = NULL;
+
+PVServer_ServiceWrapper * PVServer_ServiceWrapper::GetInstance()
+{
+ if (!instance)
+ instance = new PVServer_ServiceWrapper();
+ return instance;
+}
+
+PVServer_ServiceWrapper::PVServer_ServiceWrapper()
+{
+ myData = new Private;
+ PyLockWrapper lock;
+#ifdef GUI_DISABLE_CORBA
+ const char* code = "import PVSERVER_impl as pi;__servicePVSERVER=pi.PVSERVER_Impl()";
+#else
+ const char* code = "import PVSERVER_utils as pa;__servicePVSERVER=pa.getService()";
+#endif
+
+ int ret = PyRun_SimpleString(const_cast<char*>(code));
+ if (ret == -1)
+ throw SALOME_Exception("Unable to retrieve PVSERVER service!");
+
+ // Now get the reference to __engine and save the pointer.
+ // All the calls below returns *borrowed* references
+ PyObject* main_module = PyImport_AddModule((char*)"__main__");
+ PyObject* global_dict = PyModule_GetDict(main_module);
+ PyObject* tmp = PyDict_GetItemString(global_dict, "__servicePVSERVER");
+ myData->pvserverService = tmp;
+}
+
+PVServer_ServiceWrapper::~PVServer_ServiceWrapper()
+{
+ StopPVServer();
+ delete myData;
+}
+
+bool PVServer_ServiceWrapper::GetGUIConnected()
+{
+ PyLockWrapper lock;
+ PyObjWrapper obj(PyObject_CallMethod(myData->pvserverService, (char*)("GetGUIConnected"), NULL));
+ if (!obj)
+ {
+ PyErr_Print();
+ throw SALOME_Exception("Unable to invoke PVSERVER engine!");
+ }
+ return PyObject_IsTrue(obj);
+}
+
+void PVServer_ServiceWrapper::SetGUIConnected(bool isConnected)
+{
+ PyLockWrapper lock;
+
+ PyObjWrapper obj(PyObject_CallMethod(myData->pvserverService, (char*)("SetGUIConnected"),
+ (char *)"i", (int)isConnected ) );
+ if (!obj)
+ {
+ PyErr_Print();
+ throw SALOME_Exception("Unable to invoke PVSERVER service!");
+ }
+}
+
+std::string PVServer_ServiceWrapper::FindOrStartPVServer(int port)
+{
+ PyLockWrapper lock;
+ PyObjWrapper obj(PyObject_CallMethod(myData->pvserverService, (char*)("FindOrStartPVServer"),
+ (char *)"i", port ) );
+ if (!obj)
+ {
+ PyErr_Print();
+ throw SALOME_Exception("Unable to invoke PVSERVER service!");
+ }
+ return std::string(PyString_AsString(obj));
+}
+
+
+bool PVServer_ServiceWrapper::StopPVServer()
+{
+ PyLockWrapper lock;
+ PyObjWrapper obj(PyObject_CallMethod(myData->pvserverService, (char*)("StopPVServer"), NULL ));
+ if (!obj)
+ {
+ PyErr_Print();
+ throw SALOME_Exception("Unable to invoke PVSERVER service!");
+ }
+ return PyObject_IsTrue(obj);
+}
+
--- /dev/null
+// Copyright (C) 2010-2015 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
+//
+// Author: Adrien Bruneton (CEA)
+
+#ifndef PVSERVERSERVICEWRAPPER_H_
+#define PVSERVERSERVICEWRAPPER_H_
+
+#include "PVServerService.h"
+
+#include <string>
+
+/*!
+ * Class facilitating the access to the PARAVIS engine without having to link
+ * to it. Documentation of the method is found in the PARAVIS module (in the idl directory).
+ */
+class PVSERVERSERVICE_EXPORT PVServer_ServiceWrapper
+{
+ class Private;
+public:
+ //! Returns the unique instance of the engine.
+ static PVServer_ServiceWrapper* GetInstance();
+
+ bool GetGUIConnected();
+ void SetGUIConnected(bool isConnected);
+ std::string FindOrStartPVServer(int port);
+ bool StopPVServer();
+
+private:
+ PVServer_ServiceWrapper();
+ virtual ~PVServer_ServiceWrapper();
+
+ static PVServer_ServiceWrapper* instance;
+ Private* myData;
+};
+
+#endif /* PVSERVERSERVICEWRAPPER_H_ */
--- /dev/null
+# Copyright (C) 2010-2015 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(${SWIG_USE_FILE})
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/..
+ ${OMNIORB_INCLUDE_DIR}
+ ${KERNEL_INCLUDE_DIRS}
+ )
+
+ADD_DEFINITIONS(
+ ${KERNEL_DEFINITIONS}
+ )
+
+SET(_link_LIBRARIES
+ ${KERNEL_OpUtil} # class SALOME_Exception
+ ${KERNEL_SalomeContainer}
+ ${KERNEL_SalomeNS}
+ ${KERNEL_SalomeLifeCycleCORBA}
+ )
+
+# --- headers ---
+SET(_HEADERS
+ PVServer_ServiceLoader.h
+)
+
+# --- sources ---
+SET(_SOURCES
+ PVServer_ServiceLoader.cxx
+ )
+
+SET(_SWIG
+ PVServer_ServiceLoader.i
+ )
+
+# --- rules ---
+ADD_LIBRARY(PVServerServiceLoader ${_SOURCES})
+TARGET_LINK_LIBRARIES(PVServerServiceLoader ${_link_LIBRARIES})
+INSTALL(TARGETS PVServerServiceLoader EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
+
+# --- SWIG part ---
+SET_SOURCE_FILES_PROPERTIES(${_SWIG} PROPERTIES CPLUSPLUS ON)
+SET_SOURCE_FILES_PROPERTIES(${_SWIG} PROPERTIES SWIG_DEFINITIONS "-shadow")
+SWIG_ADD_MODULE(PVServer_ServiceLoader python ${_SWIG})
+SWIG_LINK_LIBRARIES(PVServer_ServiceLoader ${PYTHON_LIBRARIES} PVServerServiceLoader)
+
+INSTALL(TARGETS ${SWIG_MODULE_PVServer_ServiceLoader_REAL_NAME} EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_PYTHON})
+SALOME_INSTALL_SCRIPTS(${CMAKE_CURRENT_BINARY_DIR}/PVServer_ServiceLoader.py ${SALOME_INSTALL_PYTHON})
+
+# --- header installation ---
+INSTALL(FILES ${_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})
--- /dev/null
+// Copyright (C) 2010-2015 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
+//
+// Author: Adrien Bruneton (CEA)
+
+#include "PVServer_ServiceLoader.h"
+#include "PVServer_ServiceWrapper.h"
+
+#include <SALOME_LifeCycleCORBA.hxx>
+#include <SALOME_NamingService.hxx>
+#include <utilities.h> // MESSAGE() macro
+
+PVServer_ServiceLoader::PVServer_ServiceLoader():
+ _lcc(0)
+{
+ _lcc = new SALOME_LifeCycleCORBA();
+ _ns = _lcc->namingService();
+ _cm = _lcc->getContainerManager();
+ _orb = _lcc->orb();
+
+}
+
+PVServer_ServiceLoader::~PVServer_ServiceLoader()
+{
+ if (_lcc)
+ delete _lcc;
+ _lcc = 0;
+}
+
+std::string PVServer_ServiceLoader::findOrLoadService(const char * containerName)
+{
+ std::string ior = findService(containerName);
+ if (ior == "")
+ ior = loadService(containerName);
+ return ior;
+}
+
+std::string PVServer_ServiceLoader::findService(const char * containerName)
+{
+ std::string path = std::string(containerName) + "/PVSERVER";
+ CORBA::Object_ptr obj = _ns->Resolve(path.c_str());
+ if(!CORBA::is_nil(obj))
+ {
+ MESSAGE("PVServer_ServiceLoader::findService(): Service found! ");
+ char * ior = _orb->object_to_string(obj);
+ return std::string(ior);
+ }
+ else
+ {
+ MESSAGE("PVServer_ServiceLoader::findService(): Service NOT found! ");
+ return std::string("");
+ }
+
+}
+
+std::string PVServer_ServiceLoader::loadService(const char * containerName)
+{
+ // Get the requested container
+ Engines::ContainerParameters params;
+ params.container_name = CORBA::string_dup(containerName);
+ params.isMPI = false;
+ params.mode = "getorstart";
+ Engines::Container_ptr contain = _cm->GiveContainer(params);
+
+ if (!CORBA::is_nil(contain))
+ {
+ char * reason;
+ char * ior = contain->create_python_service_instance("PVSERVER", reason);
+ std::string reas(reason);
+ CORBA::string_free(reason);
+ if (reas != "")
+ {
+ MESSAGE("PVServer_ServiceLoader::loadService(): Python service instance could not be created! ");
+ MESSAGE("PVServer_ServiceLoader::loadService(): " << reas);
+ return std::string("");
+ }
+ else
+ {
+ MESSAGE("PVServer_ServiceLoader::loadService(): Container and service loaded! ");
+ return std::string(ior);
+ }
+ }
+ else
+ {
+ MESSAGE("PVServer_ServiceLoader::loadService(): Container could not be retrieved! ");
+ return std::string("");
+ }
+}
+
--- /dev/null
+// Copyright (C) 2010-2015 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
+//
+// Author: Adrien Bruneton (CEA)
+
+#ifndef PVSERVERSERVICELOADER_H_
+#define PVSERVERSERVICELOADER_H_
+
+#include "PVServerService.h"
+
+#include <SALOME_ContainerManager.hxx>
+
+class SALOME_LifeCycleCORBA;
+class SALOME_NamingService;
+
+class PVSERVERSERVICE_EXPORT PVServer_ServiceLoader
+{
+public:
+ PVServer_ServiceLoader();
+ virtual ~PVServer_ServiceLoader();
+
+ //! Get the IOR of the CORBA service handling the PVServer
+ std::string findOrLoadService(const char * containerName);
+
+private:
+ std::string findService(const char * containerName);
+ std::string loadService(const char * containerName);
+
+ SALOME_LifeCycleCORBA * _lcc;
+ CORBA::ORB_ptr _orb;
+ SALOME_NamingService * _ns;
+ Engines::ContainerManager_ptr _cm;
+};
+
+#endif /* PVSERVERSERVICELOADER_H_ */
--- /dev/null
+%module PVServer_ServiceLoader
+
+%{
+ #include "PVServer_ServiceLoader.h"
+%}
+
+%include <std_string.i>
+
+class PVServer_ServiceLoader
+{
+public:
+ //! Get the IOR of the CORBA service handling the PVServer
+ std::string findOrLoadService(const char * containerName);
+};
${PROJECT_SOURCE_DIR}/src/Qtx
${PROJECT_SOURCE_DIR}/src/Event
${PROJECT_SOURCE_DIR}/src/PyInterp
+ ${PROJECT_SOURCE_DIR}/src/PVServerService
${CMAKE_SOURCE_DIR}/src/LogWindow
)
PyInterp
suit
Event
+ PVServerService
pqApplicationComponents
vtkRenderingFreeTypeOpenGL
)
SET(_other_HEADERS
PVViewer.h
PVViewer_LogWindowAdapter.h
- PVViewer_EngineWrapper.h
PVViewer_Core.h
)
# header files / to install
PVViewer_LogWindowAdapter.cxx
PVViewer_Behaviors.cxx
PVViewer_GUIElements.cxx
- PVViewer_EngineWrapper.cxx
PVViewer_Core.cxx
)
#include "PVViewer_LogWindowAdapter.h"
#include "PVViewer_GUIElements.h"
#include "PVViewer_Behaviors.h"
-#include "PVViewer_EngineWrapper.h"
#include "PVViewer_Core.h"
#include <QApplication>
#include <QString>
-class PVViewer_EngineWrapper;
+class PVServer_ServiceWrapper;
class PVViewer_Behaviors;
class LogWindow;
class QMainWindow;
+++ /dev/null
-// Copyright (C) 2010-2015 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
-//
-// Author: Adrien Bruneton (CEA)
-
-#include "PVViewer_EngineWrapper.h"
-#include <Utils_SALOME_Exception.hxx>
-
-#include <SUIT_Session.h>
-#include <PyInterp_Utils.h>
-
-class PVViewer_EngineWrapper::Private
-{
-public:
- PyObjWrapper pvserverEngine;
-};
-
-PVViewer_EngineWrapper * PVViewer_EngineWrapper::instance = NULL;
-
-PVViewer_EngineWrapper * PVViewer_EngineWrapper::GetInstance()
-{
- if (!instance)
- instance = new PVViewer_EngineWrapper();
- return instance;
-}
-
-PVViewer_EngineWrapper::PVViewer_EngineWrapper()
-{
- myData = new Private;
- PyLockWrapper lock;
- const char* code = "import PVSERVER_utils as pa;__enginePVSERVER=pa.getEngine()";
- int ret = PyRun_SimpleString(const_cast<char*>(code));
-
- if (ret == -1)
- throw SALOME_Exception("Unable to retrieve PVSERVER engine!");
-
- // Now get the reference to __engine and save the pointer.
- PyObject* main_module = PyImport_AddModule((char*)"__main__");
- PyObject* global_dict = PyModule_GetDict(main_module);
- PyObjWrapper tmp(PyDict_GetItemString(global_dict, "__enginePVSERVER"));
- myData->pvserverEngine = tmp;
-}
-
-PVViewer_EngineWrapper::~PVViewer_EngineWrapper()
-{
- delete myData;
-}
-
-bool PVViewer_EngineWrapper::GetGUIConnected()
-{
- PyLockWrapper lock;
- PyObjWrapper obj(PyObject_CallMethod(myData->pvserverEngine, (char*)("GetGUIConnected"), NULL));
- if (!obj)
- {
- PyErr_Print();
- throw SALOME_Exception("Unable to invoke PVSERVER engine!");
- }
- return PyObject_IsTrue(obj);
-}
-
-void PVViewer_EngineWrapper::SetGUIConnected(bool isConnected)
-{
- PyLockWrapper lock;
-
- PyObjWrapper obj(PyObject_CallMethod(myData->pvserverEngine, (char*)("SetGUIConnected"),
- (char *)"i", (int)isConnected ) );
- if (!obj)
- {
- PyErr_Print();
- throw SALOME_Exception("Unable to invoke PVSERVER service!");
- }
-}
-
-std::string PVViewer_EngineWrapper::FindOrStartPVServer(int port)
-{
- PyLockWrapper lock;
- PyObjWrapper obj(PyObject_CallMethod(myData->pvserverEngine, (char*)("FindOrStartPVServer"),
- (char *)"i", port ) );
- if (!obj)
- {
- PyErr_Print();
- throw SALOME_Exception("Unable to invoke PVSERVER service!");
- }
- char * s = PyString_AsString(obj);
-
- return std::string(s);
-}
-
-void PVViewer_EngineWrapper::PutPythonTraceStringToEngine(const char * str)
-{
- PyLockWrapper lock;
- PyObjWrapper obj(PyObject_CallMethod(myData->pvserverEngine, (char*)("PutPythonTraceStringToEngine"),
- (char *)"s", str) );
- if (!obj)
- {
- PyErr_Print();
- throw SALOME_Exception("Unable to invoke PVSERVER service!");
- }
-}
+++ /dev/null
-// Copyright (C) 2010-2015 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
-//
-// Author: Adrien Bruneton (CEA)
-
-#ifndef PVVIEWERENGINEWRAPPER_H_
-#define PVVIEWERENGINEWRAPPER_H_
-
-#include "PVViewer.h"
-
-#include <string>
-
-/*!
- * Class facilitating the access to the PARAVIS engine without having to link
- * to it. Documentation of the method is found in the PARAVIS module (in the idl directory).
- */
-class PVVIEWER_EXPORT PVViewer_EngineWrapper
-{
- class Private;
-public:
- //! Returns the unique instance of the engine.
- static PVViewer_EngineWrapper* GetInstance();
-
- bool GetGUIConnected();
- void SetGUIConnected(bool isConnected);
- std::string FindOrStartPVServer(int port);
- void PutPythonTraceStringToEngine(const char*);
-
-private:
- PVViewer_EngineWrapper();
- virtual ~PVViewer_EngineWrapper();
-
- static PVViewer_EngineWrapper* instance;
- Private* myData;
-};
-
-#endif /* PVVIEWERENGINEWRAPPER_H_ */
#include "PVViewer_ViewModel.h"
#include "PVViewer_GUIElements.h"
#include "PVViewer_Core.h"
-#include "PVViewer_EngineWrapper.h"
+#include "PVServer_ServiceWrapper.h"
#include <utilities.h>
}
-PVViewer_EngineWrapper * PVViewer_ViewManager::GetEngine()
+PVServer_ServiceWrapper * PVViewer_ViewManager::GetService()
{
- return PVViewer_EngineWrapper::GetInstance();
+ return PVServer_ServiceWrapper::GetInstance();
}
QString PVViewer_ViewManager::GetPVConfigPath()
return false;
}
- if (GetEngine()->GetGUIConnected())
+ if (GetService()->GetGUIConnected())
{
// Should never be there as the above should already tell us that we are connected.
std::stringstream msg2;
else
{
// Get the URL from the engine (possibly starting the pvserver)
- serverUrl = GetEngine()->FindOrStartPVServer(0); // take the first free port
+ serverUrl = GetService()->FindOrStartPVServer(0); // take the first free port
}
msg << "connectToExternalPVServer(): Trying to connect to the external PVServer '" << serverUrl << "' ...";
else
{
MESSAGE("connectToExternalPVServer(): Connected!");
- GetEngine()->SetGUIConnected(true);
+ GetService()->SetGUIConnected(true);
}
return true;
}
class SUIT_Study;
class SUIT_ViewWindow;
class LogWindow;
-class PVViewer_EngineWrapper;
+class PVServer_ServiceWrapper;
class QMainWindow;
class PVVIEWER_EXPORT PVViewer_ViewManager : public SUIT_ViewManager
~PVViewer_ViewManager() {}
//! Get the CORBA engine wrapper.
- static PVViewer_EngineWrapper * GetEngine();
+ static PVServer_ServiceWrapper * GetService();
//! Get PVViewer configuration path as stored by SALOME's resource manager:
static QString GetPVConfigPath();