Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
575ce067
Commit
575ce067
authored
Oct 26, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(python): Добавил реализацию UProxyObject. Объект асинхронно (поток),
следащий за датчиками и предоставляющий интерфейс для получения значения.
parent
f90f053d
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
691 additions
and
11 deletions
+691
-11
Makefile.am
python/lib/pyUniSet/Makefile.am
+8
-4
PyUInterface.cc
python/lib/pyUniSet/PyUInterface.cc
+15
-0
PyUInterface.h
python/lib/pyUniSet/PyUInterface.h
+1
-0
UInterface.i
python/lib/pyUniSet/UInterface.i
+2
-0
UInterface_wrap.cxx
python/lib/pyUniSet/UInterface_wrap.cxx
+335
-7
UProxyObject.cc
python/lib/pyUniSet/UProxyObject.cc
+210
-0
UProxyObject.h
python/lib/pyUniSet/UProxyObject.h
+64
-0
UProxyObject.i
python/lib/pyUniSet/UProxyObject.i
+18
-0
pyUniSet.py
python/lib/pyUniSet/pyUniSet.py
+34
-0
testUI.py
python/tests/UInterface/testUI.py
+2
-0
uniset2.files
uniset2.files
+2
-0
No files found.
python/lib/pyUniSet/Makefile.am
View file @
575ce067
...
...
@@ -17,14 +17,17 @@ pyUExceptions.py: _pyUExceptions.la
pyexec_LTLIBRARIES
=
_pyUConnector.la _pyUModbus.la _pyUExceptions.la _pyUniSet.la
_pyUniSet_la_SOURCES
=
PyUInterface.cc UInterface_wrap.cxx
_pyUniSet_la_CXXFLAGS
=
$(UNISET_CFLAGS)
$(PYTHON_CFLAGS)
_pyUniSet_la_SOURCES
=
PyUInterface.cc UInterface_wrap.cxx
UProxyObject.cc
_pyUniSet_la_CXXFLAGS
=
$(UNISET_CFLAGS)
$(
UNISET_EXT_CFLAGS)
$(
PYTHON_CFLAGS)
_pyUniSet_la_LDFLAGS
=
-module
-avoid-version
_pyUniSet_la_LIBADD
=
$(UNISET_LIBS)
$(PYTHON_LIBS)
_pyUniSet_la_LIBADD
=
$(UNISET_LIBS)
$(
UNISET_EXT_LIBS)
$(
PYTHON_LIBS)
UInterface_wrap.cxx
:
UInterface.i
PyUInterface
.h
UInterface_wrap.cxx
:
UInterface.i
UProxyObject.i PyUInterface.h UProxyObject
.h
swig
-python
-c
++
-classic
UInterface.i
#PyUObject_wrap.cxx: UObject.i PyUObject.h
# swig -python -c++ -classic UObject.i
_pyUConnector_la_SOURCES
=
UConnector.cc UConnector_wrap.cxx
_pyUConnector_la_CXXFLAGS
=
$(UNISET_CFLAGS)
$(PYTHON_CFLAGS)
_pyUConnector_la_LDFLAGS
=
-module
-avoid-version
...
...
@@ -33,6 +36,7 @@ _pyUConnector_la_LIBADD = $(UNISET_LIBS) $(PYTHON_LIBS)
UConnector_wrap.cxx
:
UConnector.i UConnector.h
swig
-python
-c
++
-classic
UConnector.i
_pyUModbus_la_SOURCES
=
UModbus.cc UModbus_wrap.cxx
_pyUModbus_la_CXXFLAGS
=
$(UNISET_CFLAGS)
$(UNISET_EXT_CFLAGS)
$(POCO_CFLAGS)
$(PYTHON_CFLAGS)
_pyUModbus_la_LDFLAGS
=
-module
-avoid-version
...
...
python/lib/pyUniSet/PyUInterface.cc
View file @
575ce067
...
...
@@ -19,6 +19,7 @@
#include "ORepHelpers.h"
#include "UInterface.h"
#include "Configuration.h"
#include "UniSetActivator.h"
#include "UniSetTypes.h"
#include "PyUInterface.h"
//---------------------------------------------------------------------------
...
...
@@ -195,3 +196,17 @@ string pyUInterface::getConfFileName()
}
//---------------------------------------------------------------------------
void
pyUInterface
::
uniset_activate_objects
()
throw
(
UException
)
{
try
{
auto
act
=
UniSetActivator
::
Instance
();
act
->
run
(
true
);
}
catch
(
const
std
::
exception
&
ex
)
{
throw
UException
(
"(uniset_activate_objects): catch "
+
std
::
string
(
ex
.
what
())
);
}
}
//---------------------------------------------------------------------------
python/lib/pyUniSet/PyUInterface.h
View file @
575ce067
...
...
@@ -25,6 +25,7 @@ namespace pyUInterface
{
void
uniset_init_params
(
UTypes
::
Params
*
p
,
const
std
::
string
&
xmlfile
)
throw
(
UException
);
void
uniset_init
(
int
argc
,
char
**
argv
,
const
std
::
string
&
xmlfile
)
throw
(
UException
);
void
uniset_activate_objects
()
throw
(
UException
);
//---------------------------------------------------------------------------
long
getValue
(
long
id
)
throw
(
UException
);
...
...
python/lib/pyUniSet/UInterface.i
View file @
575ce067
...
...
@@ -10,9 +10,11 @@
%{
#include "PyUInterface.h"
#include "UProxyObject.h"
%}
/* Для генерации классов и констант в Питоне */
%include "PyUInterface.h"
%include "UTypes.h"
%include "UExceptions.h"
%include "UProxyObject.h"
python/lib/pyUniSet/UInterface_wrap.cxx
View file @
575ce067
...
...
@@ -3008,13 +3008,14 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) {
/* -------- TYPES TABLE (BEGIN) -------- */
#define SWIGTYPE_p_UException swig_types[0]
#define SWIGTYPE_p_USysError swig_types[1]
#define SWIGTYPE_p_UTimeOut swig_types[2]
#define SWIGTYPE_p_UTypes__Params swig_types[3]
#define SWIGTYPE_p_char swig_types[4]
#define SWIGTYPE_p_p_char swig_types[5]
static
swig_type_info
*
swig_types
[
7
];
static
swig_module_info
swig_module
=
{
swig_types
,
6
,
0
,
0
,
0
,
0
};
#define SWIGTYPE_p_UProxyObject swig_types[1]
#define SWIGTYPE_p_USysError swig_types[2]
#define SWIGTYPE_p_UTimeOut swig_types[3]
#define SWIGTYPE_p_UTypes__Params swig_types[4]
#define SWIGTYPE_p_char swig_types[5]
#define SWIGTYPE_p_p_char swig_types[6]
static
swig_type_info
*
swig_types
[
8
];
static
swig_module_info
swig_module
=
{
swig_types
,
7
,
0
,
0
,
0
,
0
};
#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
...
...
@@ -3123,6 +3124,7 @@ namespace swig {
#include "PyUInterface.h"
#include "UProxyObject.h"
SWIGINTERN
swig_type_info
*
...
...
@@ -3470,6 +3472,16 @@ SWIGINTERNINLINE PyObject*
return
PyBool_FromLong
(
value
?
1
:
0
);
}
#define SWIG_From_double PyFloat_FromDouble
SWIGINTERNINLINE
PyObject
*
SWIG_From_float
(
float
value
)
{
return
SWIG_From_double
(
value
);
}
#ifdef __cplusplus
extern
"C"
{
#endif
...
...
@@ -3568,6 +3580,24 @@ fail:
}
SWIGINTERN
PyObject
*
_wrap_uniset_activate_objects
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
":uniset_activate_objects"
))
SWIG_fail
;
try
{
pyUInterface
::
uniset_activate_objects
();
}
catch
(
UException
&
_e
)
{
SWIG_Python_Raise
(
SWIG_NewPointerObj
((
new
UException
(
static_cast
<
const
UException
&
>
(
_e
))),
SWIGTYPE_p_UException
,
SWIG_POINTER_OWN
),
"UException"
,
SWIGTYPE_p_UException
);
SWIG_fail
;
}
resultobj
=
SWIG_Py_Void
();
return
resultobj
;
fail
:
return
NULL
;
}
SWIGINTERN
PyObject
*
_wrap_getValue
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
long
arg1
;
...
...
@@ -4525,10 +4555,297 @@ SWIGINTERN PyObject *USysError_swigregister(PyObject *SWIGUNUSEDPARM(self), PyOb
return
SWIG_Py_Void
();
}
SWIGINTERN
PyObject
*
_wrap_new_UProxyObject__SWIG_0
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
std
::
string
*
arg1
=
0
;
int
res1
=
SWIG_OLDOBJ
;
PyObject
*
obj0
=
0
;
UProxyObject
*
result
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"O:new_UProxyObject"
,
&
obj0
))
SWIG_fail
;
{
std
::
string
*
ptr
=
(
std
::
string
*
)
0
;
res1
=
SWIG_AsPtr_std_string
(
obj0
,
&
ptr
);
if
(
!
SWIG_IsOK
(
res1
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
res1
),
"in method '"
"new_UProxyObject"
"', argument "
"1"" of type '"
"std::string const &""'"
);
}
if
(
!
ptr
)
{
SWIG_exception_fail
(
SWIG_ValueError
,
"invalid null reference "
"in method '"
"new_UProxyObject"
"', argument "
"1"" of type '"
"std::string const &""'"
);
}
arg1
=
ptr
;
}
try
{
result
=
(
UProxyObject
*
)
new
UProxyObject
((
std
::
string
const
&
)
*
arg1
);
}
catch
(
UException
&
_e
)
{
SWIG_Python_Raise
(
SWIG_NewPointerObj
((
new
UException
(
static_cast
<
const
UException
&
>
(
_e
))),
SWIGTYPE_p_UException
,
SWIG_POINTER_OWN
),
"UException"
,
SWIGTYPE_p_UException
);
SWIG_fail
;
}
resultobj
=
SWIG_NewPointerObj
(
SWIG_as_voidptr
(
result
),
SWIGTYPE_p_UProxyObject
,
SWIG_POINTER_NEW
|
0
);
if
(
SWIG_IsNewObj
(
res1
))
delete
arg1
;
return
resultobj
;
fail
:
if
(
SWIG_IsNewObj
(
res1
))
delete
arg1
;
return
NULL
;
}
SWIGINTERN
PyObject
*
_wrap_new_UProxyObject__SWIG_1
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
long
arg1
;
long
val1
;
int
ecode1
=
0
;
PyObject
*
obj0
=
0
;
UProxyObject
*
result
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"O:new_UProxyObject"
,
&
obj0
))
SWIG_fail
;
ecode1
=
SWIG_AsVal_long
(
obj0
,
&
val1
);
if
(
!
SWIG_IsOK
(
ecode1
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
ecode1
),
"in method '"
"new_UProxyObject"
"', argument "
"1"" of type '"
"long""'"
);
}
arg1
=
static_cast
<
long
>
(
val1
);
try
{
result
=
(
UProxyObject
*
)
new
UProxyObject
(
arg1
);
}
catch
(
UException
&
_e
)
{
SWIG_Python_Raise
(
SWIG_NewPointerObj
((
new
UException
(
static_cast
<
const
UException
&
>
(
_e
))),
SWIGTYPE_p_UException
,
SWIG_POINTER_OWN
),
"UException"
,
SWIGTYPE_p_UException
);
SWIG_fail
;
}
resultobj
=
SWIG_NewPointerObj
(
SWIG_as_voidptr
(
result
),
SWIGTYPE_p_UProxyObject
,
SWIG_POINTER_NEW
|
0
);
return
resultobj
;
fail
:
return
NULL
;
}
SWIGINTERN
PyObject
*
_wrap_new_UProxyObject
(
PyObject
*
self
,
PyObject
*
args
)
{
Py_ssize_t
argc
;
PyObject
*
argv
[
2
]
=
{
0
};
Py_ssize_t
ii
;
if
(
!
PyTuple_Check
(
args
))
SWIG_fail
;
argc
=
args
?
PyObject_Length
(
args
)
:
0
;
for
(
ii
=
0
;
(
ii
<
1
)
&&
(
ii
<
argc
);
ii
++
)
{
argv
[
ii
]
=
PyTuple_GET_ITEM
(
args
,
ii
);
}
if
(
argc
==
1
)
{
int
_v
;
{
int
res
=
SWIG_AsVal_long
(
argv
[
0
],
NULL
);
_v
=
SWIG_CheckState
(
res
);
}
if
(
_v
)
{
return
_wrap_new_UProxyObject__SWIG_1
(
self
,
args
);
}
}
if
(
argc
==
1
)
{
int
_v
;
int
res
=
SWIG_AsPtr_std_string
(
argv
[
0
],
(
std
::
string
**
)(
0
));
_v
=
SWIG_CheckState
(
res
);
if
(
_v
)
{
return
_wrap_new_UProxyObject__SWIG_0
(
self
,
args
);
}
}
fail
:
SWIG_SetErrorMsg
(
PyExc_NotImplementedError
,
"Wrong number or type of arguments for overloaded function 'new_UProxyObject'.
\n
"
" Possible C/C++ prototypes are:
\n
"
" UProxyObject::UProxyObject(std::string const &)
\n
"
" UProxyObject::UProxyObject(long)
\n
"
);
return
0
;
}
SWIGINTERN
PyObject
*
_wrap_delete_UProxyObject
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
UProxyObject
*
arg1
=
(
UProxyObject
*
)
0
;
void
*
argp1
=
0
;
int
res1
=
0
;
PyObject
*
obj0
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"O:delete_UProxyObject"
,
&
obj0
))
SWIG_fail
;
res1
=
SWIG_ConvertPtr
(
obj0
,
&
argp1
,
SWIGTYPE_p_UProxyObject
,
SWIG_POINTER_DISOWN
|
0
);
if
(
!
SWIG_IsOK
(
res1
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
res1
),
"in method '"
"delete_UProxyObject"
"', argument "
"1"" of type '"
"UProxyObject *""'"
);
}
arg1
=
reinterpret_cast
<
UProxyObject
*
>
(
argp1
);
delete
arg1
;
resultobj
=
SWIG_Py_Void
();
return
resultobj
;
fail
:
return
NULL
;
}
SWIGINTERN
PyObject
*
_wrap_UProxyObject_addToAsk
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
UProxyObject
*
arg1
=
(
UProxyObject
*
)
0
;
long
arg2
;
void
*
argp1
=
0
;
int
res1
=
0
;
long
val2
;
int
ecode2
=
0
;
PyObject
*
obj0
=
0
;
PyObject
*
obj1
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"OO:UProxyObject_addToAsk"
,
&
obj0
,
&
obj1
))
SWIG_fail
;
res1
=
SWIG_ConvertPtr
(
obj0
,
&
argp1
,
SWIGTYPE_p_UProxyObject
,
0
|
0
);
if
(
!
SWIG_IsOK
(
res1
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
res1
),
"in method '"
"UProxyObject_addToAsk"
"', argument "
"1"" of type '"
"UProxyObject *""'"
);
}
arg1
=
reinterpret_cast
<
UProxyObject
*
>
(
argp1
);
ecode2
=
SWIG_AsVal_long
(
obj1
,
&
val2
);
if
(
!
SWIG_IsOK
(
ecode2
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
ecode2
),
"in method '"
"UProxyObject_addToAsk"
"', argument "
"2"" of type '"
"long""'"
);
}
arg2
=
static_cast
<
long
>
(
val2
);
try
{
(
arg1
)
->
addToAsk
(
arg2
);
}
catch
(
UException
&
_e
)
{
SWIG_Python_Raise
(
SWIG_NewPointerObj
((
new
UException
(
static_cast
<
const
UException
&
>
(
_e
))),
SWIGTYPE_p_UException
,
SWIG_POINTER_OWN
),
"UException"
,
SWIGTYPE_p_UException
);
SWIG_fail
;
}
resultobj
=
SWIG_Py_Void
();
return
resultobj
;
fail
:
return
NULL
;
}
SWIGINTERN
PyObject
*
_wrap_UProxyObject_getValue
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
UProxyObject
*
arg1
=
(
UProxyObject
*
)
0
;
long
arg2
;
void
*
argp1
=
0
;
int
res1
=
0
;
long
val2
;
int
ecode2
=
0
;
PyObject
*
obj0
=
0
;
PyObject
*
obj1
=
0
;
long
result
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"OO:UProxyObject_getValue"
,
&
obj0
,
&
obj1
))
SWIG_fail
;
res1
=
SWIG_ConvertPtr
(
obj0
,
&
argp1
,
SWIGTYPE_p_UProxyObject
,
0
|
0
);
if
(
!
SWIG_IsOK
(
res1
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
res1
),
"in method '"
"UProxyObject_getValue"
"', argument "
"1"" of type '"
"UProxyObject *""'"
);
}
arg1
=
reinterpret_cast
<
UProxyObject
*
>
(
argp1
);
ecode2
=
SWIG_AsVal_long
(
obj1
,
&
val2
);
if
(
!
SWIG_IsOK
(
ecode2
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
ecode2
),
"in method '"
"UProxyObject_getValue"
"', argument "
"2"" of type '"
"long""'"
);
}
arg2
=
static_cast
<
long
>
(
val2
);
try
{
result
=
(
long
)(
arg1
)
->
getValue
(
arg2
);
}
catch
(
UException
&
_e
)
{
SWIG_Python_Raise
(
SWIG_NewPointerObj
((
new
UException
(
static_cast
<
const
UException
&
>
(
_e
))),
SWIGTYPE_p_UException
,
SWIG_POINTER_OWN
),
"UException"
,
SWIGTYPE_p_UException
);
SWIG_fail
;
}
resultobj
=
SWIG_From_long
(
static_cast
<
long
>
(
result
));
return
resultobj
;
fail
:
return
NULL
;
}
SWIGINTERN
PyObject
*
_wrap_UProxyObject_getFloatValue
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
UProxyObject
*
arg1
=
(
UProxyObject
*
)
0
;
long
arg2
;
void
*
argp1
=
0
;
int
res1
=
0
;
long
val2
;
int
ecode2
=
0
;
PyObject
*
obj0
=
0
;
PyObject
*
obj1
=
0
;
float
result
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"OO:UProxyObject_getFloatValue"
,
&
obj0
,
&
obj1
))
SWIG_fail
;
res1
=
SWIG_ConvertPtr
(
obj0
,
&
argp1
,
SWIGTYPE_p_UProxyObject
,
0
|
0
);
if
(
!
SWIG_IsOK
(
res1
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
res1
),
"in method '"
"UProxyObject_getFloatValue"
"', argument "
"1"" of type '"
"UProxyObject *""'"
);
}
arg1
=
reinterpret_cast
<
UProxyObject
*
>
(
argp1
);
ecode2
=
SWIG_AsVal_long
(
obj1
,
&
val2
);
if
(
!
SWIG_IsOK
(
ecode2
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
ecode2
),
"in method '"
"UProxyObject_getFloatValue"
"', argument "
"2"" of type '"
"long""'"
);
}
arg2
=
static_cast
<
long
>
(
val2
);
try
{
result
=
(
float
)(
arg1
)
->
getFloatValue
(
arg2
);
}
catch
(
UException
&
_e
)
{
SWIG_Python_Raise
(
SWIG_NewPointerObj
((
new
UException
(
static_cast
<
const
UException
&
>
(
_e
))),
SWIGTYPE_p_UException
,
SWIG_POINTER_OWN
),
"UException"
,
SWIGTYPE_p_UException
);
SWIG_fail
;
}
resultobj
=
SWIG_From_float
(
static_cast
<
float
>
(
result
));
return
resultobj
;
fail
:
return
NULL
;
}
SWIGINTERN
PyObject
*
_wrap_UProxyObject_setValue
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
UProxyObject
*
arg1
=
(
UProxyObject
*
)
0
;
long
arg2
;
long
arg3
;
void
*
argp1
=
0
;
int
res1
=
0
;
long
val2
;
int
ecode2
=
0
;
long
val3
;
int
ecode3
=
0
;
PyObject
*
obj0
=
0
;
PyObject
*
obj1
=
0
;
PyObject
*
obj2
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"OOO:UProxyObject_setValue"
,
&
obj0
,
&
obj1
,
&
obj2
))
SWIG_fail
;
res1
=
SWIG_ConvertPtr
(
obj0
,
&
argp1
,
SWIGTYPE_p_UProxyObject
,
0
|
0
);
if
(
!
SWIG_IsOK
(
res1
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
res1
),
"in method '"
"UProxyObject_setValue"
"', argument "
"1"" of type '"
"UProxyObject *""'"
);
}
arg1
=
reinterpret_cast
<
UProxyObject
*
>
(
argp1
);
ecode2
=
SWIG_AsVal_long
(
obj1
,
&
val2
);
if
(
!
SWIG_IsOK
(
ecode2
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
ecode2
),
"in method '"
"UProxyObject_setValue"
"', argument "
"2"" of type '"
"long""'"
);
}
arg2
=
static_cast
<
long
>
(
val2
);
ecode3
=
SWIG_AsVal_long
(
obj2
,
&
val3
);
if
(
!
SWIG_IsOK
(
ecode3
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
ecode3
),
"in method '"
"UProxyObject_setValue"
"', argument "
"3"" of type '"
"long""'"
);
}
arg3
=
static_cast
<
long
>
(
val3
);
try
{
(
arg1
)
->
setValue
(
arg2
,
arg3
);
}
catch
(
UException
&
_e
)
{
SWIG_Python_Raise
(
SWIG_NewPointerObj
((
new
UException
(
static_cast
<
const
UException
&
>
(
_e
))),
SWIGTYPE_p_UException
,
SWIG_POINTER_OWN
),
"UException"
,
SWIGTYPE_p_UException
);
SWIG_fail
;
}
resultobj
=
SWIG_Py_Void
();
return
resultobj
;
fail
:
return
NULL
;
}
SWIGINTERN
PyObject
*
UProxyObject_swigregister
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
obj
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"O:swigregister"
,
&
obj
))
return
NULL
;
SWIG_TypeNewClientData
(
SWIGTYPE_p_UProxyObject
,
SWIG_NewClientData
(
obj
));
return
SWIG_Py_Void
();
}
static
PyMethodDef
SwigMethods
[]
=
{
{
(
char
*
)
"SWIG_PyInstanceMethod_New"
,
(
PyCFunction
)
SWIG_PyInstanceMethod_New
,
METH_O
,
NULL
},
{
(
char
*
)
"uniset_init_params"
,
_wrap_uniset_init_params
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"uniset_init"
,
_wrap_uniset_init
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"uniset_activate_objects"
,
_wrap_uniset_activate_objects
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"getValue"
,
_wrap_getValue
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"setValue"
,
_wrap_setValue
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"getSensorID"
,
_wrap_getSensorID
,
METH_VARARGS
,
NULL
},
...
...
@@ -4558,6 +4875,13 @@ static PyMethodDef SwigMethods[] = {
{
(
char
*
)
"new_USysError"
,
_wrap_new_USysError
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"delete_USysError"
,
_wrap_delete_USysError
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"USysError_swigregister"
,
USysError_swigregister
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"new_UProxyObject"
,
_wrap_new_UProxyObject
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"delete_UProxyObject"
,
_wrap_delete_UProxyObject
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"UProxyObject_addToAsk"
,
_wrap_UProxyObject_addToAsk
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"UProxyObject_getValue"
,
_wrap_UProxyObject_getValue
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"UProxyObject_getFloatValue"
,
_wrap_UProxyObject_getFloatValue
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"UProxyObject_setValue"
,
_wrap_UProxyObject_setValue
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"UProxyObject_swigregister"
,
UProxyObject_swigregister
,
METH_VARARGS
,
NULL
},
{
NULL
,
NULL
,
0
,
NULL
}
};
...
...
@@ -4571,6 +4895,7 @@ static void *_p_USysErrorTo_p_UException(void *x, int *SWIGUNUSEDPARM(newmemory)
return
(
void
*
)((
UException
*
)
((
USysError
*
)
x
));
}
static
swig_type_info
_swigt__p_UException
=
{
"_p_UException"
,
"UException *"
,
0
,
0
,
(
void
*
)
0
,
0
};
static
swig_type_info
_swigt__p_UProxyObject
=
{
"_p_UProxyObject"
,
"UProxyObject *"
,
0
,
0
,
(
void
*
)
0
,
0
};
static
swig_type_info
_swigt__p_USysError
=
{
"_p_USysError"
,
"USysError *"
,
0
,
0
,
(
void
*
)
0
,
0
};
static
swig_type_info
_swigt__p_UTimeOut
=
{
"_p_UTimeOut"
,
"UTimeOut *"
,
0
,
0
,
(
void
*
)
0
,
0
};
static
swig_type_info
_swigt__p_UTypes__Params
=
{
"_p_UTypes__Params"
,
"UTypes::Params *"
,
0
,
0
,
(
void
*
)
0
,
0
};
...
...
@@ -4579,6 +4904,7 @@ static swig_type_info _swigt__p_p_char = {"_p_p_char", "char **", 0, 0, (void*)0
static
swig_type_info
*
swig_type_initial
[]
=
{
&
_swigt__p_UException
,
&
_swigt__p_UProxyObject
,
&
_swigt__p_USysError
,
&
_swigt__p_UTimeOut
,
&
_swigt__p_UTypes__Params
,
...
...
@@ -4587,6 +4913,7 @@ static swig_type_info *swig_type_initial[] = {
};
static
swig_cast_info
_swigc__p_UException
[]
=
{
{
&
_swigt__p_UException
,
0
,
0
,
0
},
{
&
_swigt__p_UTimeOut
,
_p_UTimeOutTo_p_UException
,
0
,
0
},
{
&
_swigt__p_USysError
,
_p_USysErrorTo_p_UException
,
0
,
0
},{
0
,
0
,
0
,
0
}};
static
swig_cast_info
_swigc__p_UProxyObject
[]
=
{
{
&
_swigt__p_UProxyObject
,
0
,
0
,
0
},{
0
,
0
,
0
,
0
}};
static
swig_cast_info
_swigc__p_USysError
[]
=
{
{
&
_swigt__p_USysError
,
0
,
0
,
0
},{
0
,
0
,
0
,
0
}};
static
swig_cast_info
_swigc__p_UTimeOut
[]
=
{
{
&
_swigt__p_UTimeOut
,
0
,
0
,
0
},{
0
,
0
,
0
,
0
}};
static
swig_cast_info
_swigc__p_UTypes__Params
[]
=
{
{
&
_swigt__p_UTypes__Params
,
0
,
0
,
0
},{
0
,
0
,
0
,
0
}};
...
...
@@ -4595,6 +4922,7 @@ static swig_cast_info _swigc__p_p_char[] = { {&_swigt__p_p_char, 0, 0, 0},{0, 0
static
swig_cast_info
*
swig_cast_initial
[]
=
{
_swigc__p_UException
,
_swigc__p_UProxyObject
,
_swigc__p_USysError
,
_swigc__p_UTimeOut
,
_swigc__p_UTypes__Params
,
...
...
python/lib/pyUniSet/UProxyObject.cc
0 → 100644
View file @
575ce067
/*
* Copyright (c) 2015 Pavel Vainerman.
*
* This program 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, version 2.1.
*
* This program 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 Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// --------------------------------------------------------------------------
#include <sstream>
#include <mutex>
#include <string>
#include <unordered_map>
#include "Configuration.h"
#include "extensions/UObject_SK.h"
#include "UniSetActivator.h"
#include "UProxyObject.h"
// --------------------------------------------------------------------------
using
namespace
UniSetTypes
;
// --------------------------------------------------------------------------
/*! PIMPL реализация UProxyObject */
class
UProxyObject_impl
:
public
UObject_SK
{
public
:
UProxyObject_impl
(
UniSetTypes
::
ObjectId
id
);
virtual
~
UProxyObject_impl
();
void
impl_addToAsk
(
UniSetTypes
::
ObjectId
id
)
throw
(
UException
);
long
impl_getValue
(
long
id
)
throw
(
UException
);
void
impl_setValue
(
long
id
,
long
val
)
throw
(
UException
);
float
impl_getFloatValue
(
long
id
)
throw
(
UException
);
protected
:
virtual
void
askSensors
(
UniversalIO
::
UIOCommand
cmd
)
override
;
virtual
void
sensorInfo
(
const
UniSetTypes
::
SensorMessage
*
sm
)
override
;
private
:
struct
SInfo
{
IOController_i
::
SensorInfo
si
;
long
value
=
{
0
};
float
fvalue
=
{
0.0
};
};
std
::
mutex
mutexSMap
;
std
::
unordered_map
<
UniSetTypes
::
ObjectId
,
SInfo
>
smap
;
};
// --------------------------------------------------------------------------
UProxyObject
::
UProxyObject
()
throw
(
UException
)
{
throw
UException
(
"(UProxyObject): Unknown 'name'' or 'ID'"
);
}
// --------------------------------------------------------------------------
UProxyObject
::
UProxyObject
(
const
std
::
string
&
name
)
throw
(
UException
)
:
UProxyObject
::
UProxyObject
(
uniset_conf
()
->
getObjectID
(
name
))
{
}
// --------------------------------------------------------------------------
UProxyObject
::
UProxyObject
(
long
id
)
throw
(
UException
)
{
try
{
uobj
=
std
::
make_shared
<
UProxyObject_impl
>
(
id
);
auto
act
=
UniSetActivator
::
Instance
();
act
->
add
(
uobj
);
}
catch
(
std
::
exception
&
ex
)
{
std
::
ostringstream
err
;
err
<<
"(UProxyObject): id='"
<<
id
<<
"' error: "
<<
std
::
string
(
ex
.
what
());
throw
UException
(
err
.
str
());
}
}
// --------------------------------------------------------------------------
UProxyObject
::~
UProxyObject
()
{
}
// --------------------------------------------------------------------------
long
UProxyObject
::
getValue
(
long
id
)
throw
(
UException
)
{
return
uobj
->
impl_getValue
(
id
);
}
// --------------------------------------------------------------------------
void
UProxyObject
::
setValue
(
long
id
,
long
val
)
throw
(
UException
)
{
uobj
->
impl_setValue
(
id
,
val
);
}
// --------------------------------------------------------------------------
float
UProxyObject
::
getFloatValue
(
long
id
)
throw
(
UException
)
{
return
uobj
->
impl_getFloatValue
(
id
);
}
// --------------------------------------------------------------------------
void
UProxyObject
::
addToAsk
(
long
id
)
throw
(
UException
)
{
try
{
uobj
->
impl_addToAsk
(
id
);
}
catch
(
std
::
exception
&
ex
)
{
std
::
ostringstream
err
;
err
<<
uobj
->
getName
()
<<
"(addToAsk): "
<<
id
<<
" error: "
<<
std
::
string
(
ex
.
what
());
throw
UException
(
err
.
str
());
}
}
// --------------------------------------------------------------------------
UProxyObject_impl
::
UProxyObject_impl
(
ObjectId
id
)
:
UObject_SK
(
id
)
{
}
// --------------------------------------------------------------------------
UProxyObject_impl
::~
UProxyObject_impl
()
{
}
// --------------------------------------------------------------------------
void
UProxyObject_impl
::
impl_addToAsk
(
ObjectId
id
)
throw
(
UException
)
{
UProxyObject_impl
::
SInfo
i
;
i
.
si
.
id
=
id
;
i
.
si
.
node
=
uniset_conf
()
->
getLocalNode
();
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutexSMap
);
smap
[
id
]
=
i
;
}
// --------------------------------------------------------------------------
long
UProxyObject_impl
::
impl_getValue
(
long
id
)
throw
(
UException
)
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutexSMap
);
auto
i
=
smap
.
find
(
id
);
if
(
i
==
smap
.
end
()
)
{
std
::
ostringstream
err
;
err
<<
myname
<<
"(getValue): "
<<
id
<<
" not found in proxy sensors list.."
;
throw
UException
(
err
.
str
());
}
return
i
->
second
.
value
;
}
// --------------------------------------------------------------------------
float
UProxyObject_impl
::
impl_getFloatValue
(
long
id
)
throw
(
UException
)
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutexSMap
);
auto
i
=
smap
.
find
(
id
);
if
(
i
==
smap
.
end
()
)
{
std
::
ostringstream
err
;
err
<<
myname
<<
"(getFloatValue): "
<<
id
<<
" not found in proxy sensors list.."
;
throw
UException
(
err
.
str
());
}
return
i
->
second
.
fvalue
;
}
// --------------------------------------------------------------------------
void
UProxyObject_impl
::
impl_setValue
(
long
id
,
long
val
)
throw
(
UException
)
{
try
{
UObject_SK
::
setValue
(
id
,
val
);
}
catch
(
std
::
exception
&
ex
)
{
std
::
ostringstream
err
;
err
<<
myname
<<
"(setValue): "
<<
id
<<
" error: "
<<
std
::
string
(
ex
.
what
());
throw
UException
(
err
.
str
());
}
}
// --------------------------------------------------------------------------
void
UProxyObject_impl
::
askSensors
(
UniversalIO
::
UIOCommand
cmd
)
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutexSMap
);
for
(
const
auto
&
i
:
smap
)
{
try
{
ui
->
askRemoteSensor
(
i
.
second
.
si
.
id
,
cmd
,
i
.
second
.
si
.
node
,
getId
());
}
catch
(
std
::
exception
&
ex
)
{
std
::
ostringstream
err
;
err
<<
myname
<<
"(askSensors): "
<<
i
.
second
.
si
.
id
<<
" error: "
<<
std
::
string
(
ex
.
what
());
throw
UException
(
err
.
str
());
}
}
}
// --------------------------------------------------------------------------
void
UProxyObject_impl
::
sensorInfo
(
const
SensorMessage
*
sm
)
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutexSMap
);
auto
i
=
smap
.
find
(
sm
->
id
);
if
(
i
!=
smap
.
end
()
)
{
i
->
second
.
value
=
sm
->
value
;
i
->
second
.
fvalue
=
(
float
)
sm
->
value
/
pow
(
10.0
,
sm
->
ci
.
precision
);
}
}
// --------------------------------------------------------------------------
python/lib/pyUniSet/UProxyObject.h
0 → 100644
View file @
575ce067
/*
* Copyright (c) 2015 Pavel Vainerman.
*
* This program 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, version 2.1.
*
* This program 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 Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// -------------------------------------------------------------------------
#ifndef UProxyObject_H_
#define UProxyObject_H_
// --------------------------------------------------------------------------
#include <memory>
#include "UExceptions.h"
// --------------------------------------------------------------------------
class
UProxyObject_impl
;
// PIMPL
// --------------------------------------------------------------------------
/*! Интерфейс для взаимодействия с SM (с заказом датчиков).
* Текущая версия рассчитана на наличие локальной SM, т.е. в функциях нет аргумента node.
* Соответственно обращение к датчику на другом узле не возможно.
*
* Если всё-таки понадобится - доработаем.
*
* Общее описание:
* Перед активацией объекта необходимо при помощи addToAsk() добавить список датчиков,
* за которыми требуется "следить". После активации ( см. PyUInterface uniset_activate_objects() )
* (в асинхронном режиме!) объект заказывает датчики и сохраняет у себя их состояние.
* При этом "снаружи" можно запросить значение ранее добавленного датчика при помощи фунции getValue().
* Помимо этого можно изменять состояние датчиков (в SM!) при помощи setValue().
* По сути setValue() просто дублирует функциональность PyUInterface::setValue()
*/
class
UProxyObject
{
public
:
UProxyObject
(
const
std
::
string
&
name
)
throw
(
UException
);
UProxyObject
(
long
id
)
throw
(
UException
);
~
UProxyObject
();
//! \note Вызывать надо до активации объекта
void
addToAsk
(
long
id
)
throw
(
UException
);
long
getValue
(
long
id
)
throw
(
UException
);
float
getFloatValue
(
long
id
)
throw
(
UException
);
/*! Сохраняемые датчики не требуют добавления при помощи addToAsk ! */
void
setValue
(
long
id
,
long
val
)
throw
(
UException
);
protected
:
private
:
UProxyObject
()
throw
(
UException
);
std
::
shared_ptr
<
UProxyObject_impl
>
uobj
;
};
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
python/lib/pyUniSet/UProxyObject.i
0 → 100644
View file @
575ce067
/***********************************************************
* Interface file for wrapping test
* to regenerate the wrappers run:
* swig -python UInterface.i
***********************************************************/
%module pyUniSet
%include "std_string.i"
%{
#include "UProxyObject.h"
%}
/* Для генерации классов и констант в Питоне */
%include "UProxyObject.h"
%include "UTypes.h"
%include "UExceptions.h"
python/lib/pyUniSet/pyUniSet.py
View file @
575ce067
...
...
@@ -82,6 +82,10 @@ def uniset_init(argc, argv, xmlfile):
return
_pyUniSet
.
uniset_init
(
argc
,
argv
,
xmlfile
)
uniset_init
=
_pyUniSet
.
uniset_init
def
uniset_activate_objects
():
return
_pyUniSet
.
uniset_activate_objects
()
uniset_activate_objects
=
_pyUniSet
.
uniset_activate_objects
def
getValue
(
id
):
return
_pyUniSet
.
getValue
(
id
)
getValue
=
_pyUniSet
.
getValue
...
...
@@ -214,6 +218,36 @@ class USysError(UException):
USysError_swigregister
=
_pyUniSet
.
USysError_swigregister
USysError_swigregister
(
USysError
)
class
UProxyObject
:
__swig_setmethods__
=
{}
__setattr__
=
lambda
self
,
name
,
value
:
_swig_setattr
(
self
,
UProxyObject
,
name
,
value
)
__swig_getmethods__
=
{}
__getattr__
=
lambda
self
,
name
:
_swig_getattr
(
self
,
UProxyObject
,
name
)
__repr__
=
_swig_repr
def
__init__
(
self
,
*
args
):
this
=
_pyUniSet
.
new_UProxyObject
(
*
args
)
try
:
self
.
this
.
append
(
this
)
except
Exception
:
self
.
this
=
this
__swig_destroy__
=
_pyUniSet
.
delete_UProxyObject
__del__
=
lambda
self
:
None
def
addToAsk
(
self
,
id
):
return
_pyUniSet
.
UProxyObject_addToAsk
(
self
,
id
)
def
getValue
(
self
,
id
):
return
_pyUniSet
.
UProxyObject_getValue
(
self
,
id
)
def
getFloatValue
(
self
,
id
):
return
_pyUniSet
.
UProxyObject_getFloatValue
(
self
,
id
)
def
setValue
(
self
,
id
,
val
):
return
_pyUniSet
.
UProxyObject_setValue
(
self
,
id
,
val
)
UProxyObject_swigregister
=
_pyUniSet
.
UProxyObject_swigregister
UProxyObject_swigregister
(
UProxyObject
)
# This file is compatible with both classic and new-style classes.
python/tests/UInterface/testUI.py
View file @
575ce067
...
...
@@ -22,6 +22,8 @@ if __name__ == "__main__":
try
:
uniset_init_params
(
lst
,
"test.xml"
);
obj1
=
UProxyObject
(
"TestProc"
)
uniset_activate_objects
();
print
"getShortName: id=
%
d name=
%
s"
%
(
1
,
getShortName
(
1
))
print
" getName: id=
%
d name=
%
s"
%
(
1
,
getName
(
1
))
...
...
uniset2.files
View file @
575ce067
...
...
@@ -339,6 +339,8 @@ python/examples/test.xml
python/lib/pyUniSet/Makefile.am
python/lib/pyUniSet/PyUInterface.cc
python/lib/pyUniSet/PyUInterface.h
python/lib/pyUniSet/UProxyObject.cc
python/lib/pyUniSet/UProxyObject.h
python/lib/pyUniSet/UConnector.cc
python/lib/pyUniSet/UConnector.h
python/lib/pyUniSet/UConnector_wrap.cxx
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment