]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMESDS/KernelSDS.i
Salome HOME
SDS in SSL mode.
[modules/kernel.git] / src / SALOMESDS / KernelSDS.i
1 // Copyright (C) 2021  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 %module KernelSDS
21
22 %include "std_string.i"
23
24 %{
25 #include "KernelSDS.hxx"
26 #include "Utils_SALOME_Exception.hxx"
27 %}
28
29
30 class SALOME_Exception
31 {
32   public:
33   SALOME_Exception(const std::string& text);
34   %extend
35   {
36     std::string __str__() const
37     {
38       return std::string(self->what());
39     }
40   }
41 };
42
43 %exception {
44   try {
45     $action
46   }
47   catch (SALOME_Exception& _e) {
48     // Reraise with SWIG_Python_Raise
49     SWIG_Python_Raise(SWIG_NewPointerObj((new SALOME_Exception(static_cast< const SALOME_Exception& >(_e.what()))),SWIGTYPE_p_SALOME_Exception,SWIG_POINTER_OWN), "SALOME_Exception", SWIGTYPE_p_SALOME_Exception);
50     SWIG_fail;
51   }
52 }
53
54 %inline
55 {
56   std::string GetDSMInstanceInternal(PyObject *argv)
57   {
58     if(!PyList_Check(argv))
59       THROW_SALOME_EXCEPTION("Not a pylist");
60     Py_ssize_t sz=PyList_Size(argv);
61     std::vector<std::string> argvCpp(sz);
62     for(Py_ssize_t i = 0 ; i < sz ; ++i)
63     {
64       PyObject *obj = PyList_GetItem(argv,i);
65       if(!PyUnicode_Check(obj))
66         THROW_SALOME_EXCEPTION("Not a pylist of strings");
67       {
68         Py_ssize_t dummy;
69         argvCpp[i] = PyUnicode_AsUTF8AndSize(obj,&dummy);
70       }
71     }
72     return GetDSMInstanceInternal(argvCpp);
73   }
74 }
75
76 %pythoncode %{
77 def GetDSMInstance(argv):
78   import SALOME
79   import CORBA
80   orb=CORBA.ORB_init([''])
81   return orb.string_to_object(GetDSMInstanceInternal(argv))
82 %}