Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VAPython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Institute of Technical Acoustics (ITA)
VAPython
Commits
cf38808d
Commit
cf38808d
authored
7 years ago
by
Dipl.-Ing. Jonas Stienen
Browse files
Options
Downloads
Patches
Plain Diff
Improving error handling and fixing problems with connection method
parent
d0999363
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
CMakeLists.txt
+4
-4
4 additions, 4 deletions
CMakeLists.txt
distutils_build.bat
+3
-3
3 additions, 3 deletions
distutils_build.bat
src/vasingletonmethods.hpp
+64
-60
64 additions, 60 deletions
src/vasingletonmethods.hpp
tests/va_test_connection.py
+7
-3
7 additions, 3 deletions
tests/va_test_connection.py
with
78 additions
and
70 deletions
CMakeLists.txt
+
4
−
4
View file @
cf38808d
...
@@ -32,10 +32,10 @@ endif( )
...
@@ -32,10 +32,10 @@ endif( )
add_custom_command
(
TARGET VAPython POST_BUILD COMMAND
"distutils_build.
${
BATCH_SCRIPT_EXTENSION
}
"
WORKING_DIRECTORY
${
CMAKE_CURRENT_SOURCE_DIR
}
COMMENT
"Running distutils"
VERBATIM
)
add_custom_command
(
TARGET VAPython POST_BUILD COMMAND
"distutils_build.
${
BATCH_SCRIPT_EXTENSION
}
"
WORKING_DIRECTORY
${
CMAKE_CURRENT_SOURCE_DIR
}
COMMENT
"Running distutils"
VERBATIM
)
# configure
# configure
vista_configure_lib
(
VAPython
)
#
vista_configure_lib( VAPython )
vista_install
(
VAPython
)
#
vista_install( VAPython )
vista_create_cmake_configs
(
VAPython
)
#
vista_create_cmake_configs( VAPython )
vista_create_default_info_file
(
VAPython
)
#
vista_create_default_info_file( VAPython )
set_property
(
TARGET VAPython PROPERTY FOLDER
"VA/Bindings"
)
set_property
(
TARGET VAPython PROPERTY FOLDER
"VA/Bindings"
)
...
...
This diff is collapsed.
Click to expand it.
distutils_build.bat
+
3
−
3
View file @
cf38808d
python
.exe
setup
.py
clean
python
.exe
setup
.py
clean
python
.exe
setup
.py
build
python
.exe
setup
.py
build
--force
python
.exe
setup
.py
install
--prefix
dist
python
.exe
setup
.py
install
--prefix
dist
python
.exe
setup
.py
sdist
--formats
=
zip
python
.exe
setup
.py
sdist
--formats
=
zip
#
later
:
rem
later:
#
python.exe
setup
.py
bdist_wininst
rem
python.exe setup.py bdist_wininst
python
.exe
setup
.py
check
python
.exe
setup
.py
check
This diff is collapsed.
Click to expand it.
src/vasingletonmethods.hpp
+
64
−
60
View file @
cf38808d
...
@@ -11,12 +11,16 @@
...
@@ -11,12 +11,16 @@
static
IVANetClient
*
g_pVANetClient
=
nullptr
;
//!< Static pointer to VANetClient instance
static
IVANetClient
*
g_pVANetClient
=
nullptr
;
//!< Static pointer to VANetClient instance
static
PyObject
*
g_pVAError
=
nullptr
;
//!< Static pointer to error instance
static
PyObject
*
g_pVAError
=
nullptr
;
//!< Static pointer to error instance
// Ugly definitions to ease try-catching VA exceptions
#define VAPY_REQUIRE_CONN_TRY try { RequireCoreAvailable();
#define VAPY_CATCH_RETURN } catch (const CVAException& oError) { PyErr_SetString(PyExc_Exception, oError.ToString().c_str()); return NULL; }
//! Helper for API dev
//! Helper for API dev
static
PyObject
*
va_not_implemented
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
static
PyObject
*
va_not_implemented
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
{
{
VA_EXCEPT_NOT_IMPLEMENTED
;
VA_EXCEPT_NOT_IMPLEMENTED
;
return
NULL
;
return
NULL
;
}
}
;
//! Raises an exception if core is not available
//! Raises an exception if core is not available
static
void
RequireCoreAvailable
()
static
void
RequireCoreAvailable
()
...
@@ -26,7 +30,7 @@ static void RequireCoreAvailable()
...
@@ -26,7 +30,7 @@ static void RequireCoreAvailable()
if
(
!
g_pVANetClient
->
GetCoreInstance
())
if
(
!
g_pVANetClient
->
GetCoreInstance
())
VA_EXCEPT2
(
CVAException
::
NETWORK_ERROR
,
"VA client available, but access to VA interface failed. Please reconnect."
);
VA_EXCEPT2
(
CVAException
::
NETWORK_ERROR
,
"VA client available, but access to VA interface failed. Please reconnect."
);
}
}
;
static
PyObject
*
va_connect
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
static
PyObject
*
va_connect
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
{
{
...
@@ -40,88 +44,88 @@ static PyObject* va_connect( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArg
...
@@ -40,88 +44,88 @@ static PyObject* va_connect( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArg
}
}
static
const
char
*
const
_keywords
[]
=
{
"server"
,
"port"
,
NULL
};
static
const
char
*
const
_keywords
[]
=
{
"server"
,
"port"
,
NULL
};
static
_PyArg_Parser
_parser
=
{
"Oi:connect"
,
_keywords
,
0
};
static
_PyArg_Parser
_parser
=
{
"|si:connect"
,
_keywords
,
0
};
PyObject
*
pServer
;
char
*
pcServerIP
;
PyObject
*
pPort
;
int
iServerPort
=
12340
;
if
(
!
_PyArg_ParseStack
(
ppArgs
,
nArgs
,
pKeywordNames
,
&
_parser
,
&
pServer
,
&
pPort
)
)
return
PyBool_FromLong
(
0
);
std
::
string
sServerIP
=
"localhost"
;
if
(
!
_PyArg_ParseStack
(
ppArgs
,
nArgs
,
pKeywordNames
,
&
_parser
,
pcServerIP
,
&
iServerPort
))
char
*
pcServerIP
=
nullptr
;
return
NULL
;
if
(
PyArg_ParseTuple
(
pPort
,
"i"
,
&
pcServerIP
)
)
sServerIP
=
std
::
string
(
pcServerIP
);
int
iServerPort
=
12340
;
std
::
string
sServerIP
=
pcServerIP
?
std
::
string
(
pcServerIP
)
:
"localhost"
;
int
*
piServerPort
=
nullptr
;
if
(
PyArg_ParseTuple
(
pPort
,
"i"
,
&
piServerPort
)
)
iServerPort
=
*
piServerPort
;
if
(
IVANetClient
::
VA_NO_ERROR
==
g_pVANetClient
->
Initialize
(
sServerIP
,
iServerPort
))
if
(
IVANetClient
::
VA_NO_ERROR
==
g_pVANetClient
->
Initialize
(
sServerIP
,
iServerPort
))
return
PyBool_FromLong
(
1
);
return
PyBool_FromLong
(
1
);
PyErr_SetString
(
PyExc_ConnectionError
,
std
::
string
(
"Could not connect to "
+
sServerIP
+
" on "
+
std
::
to_string
((
long
)
iServerPort
)).
c_str
());
PyErr_SetString
(
PyExc_ConnectionError
,
std
::
string
(
"Could not connect to "
+
sServerIP
+
" on "
+
std
::
to_string
((
long
)
iServerPort
)).
c_str
());
return
NULL
;
return
NULL
;
}
}
;
static
PyObject
*
va_disconnect
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
static
PyObject
*
va_disconnect
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
{
{
if
(
g_pVANetClient
)
if
(
g_pVANetClient
)
g_pVANetClient
->
Disconnect
();
g_pVANetClient
->
Disconnect
();
else
PyErr_Warn
(
pSelf
,
"Was not connected, doing nothing. Use is_connected to avoid this message."
);
return
PyBool_FromLong
(
1
);
return
PyBool_FromLong
(
1
);
}
};
static
PyObject
*
va_is_connected
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
static
PyObject
*
va_is_connected
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
{
{
if
(
!
g_pVANetClient
)
if
(
!
g_pVANetClient
)
return
PyBool_FromLong
(
0
);
return
PyBool_FromLong
(
0
);
else
else
return
PyBool_FromLong
(
g_pVANetClient
->
IsConnected
());
return
PyBool_FromLong
(
g_pVANetClient
->
IsConnected
());
}
}
;
static
PyObject
*
va_reset
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
static
PyObject
*
va_reset
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
{
{
RequireCoreAvailable
()
;
VAPY_REQUIRE_CONN_TRY
;
g_pVANetClient
->
GetCoreInstance
()
->
Reset
();
g_pVANetClient
->
GetCoreInstance
()
->
Reset
();
return
PyBool_FromLong
(
1
);
return
PyBool_FromLong
(
1
);
}
VAPY_CATCH_RETURN
;
};
static
PyObject
*
va_enumerate_modules
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
static
PyObject
*
va_enumerate_modules
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
{
{
RequireCoreAvailable
()
;
VAPY_REQUIRE_CONN_TRY
;
VA_EXCEPT_NOT_IMPLEMENTED
;
VA_EXCEPT_NOT_IMPLEMENTED
;
return
NULL
;
return
NULL
;
}
VAPY_CATCH_RETURN
;
};
static
PyObject
*
va_call_module
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
static
PyObject
*
va_call_module
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
{
{
RequireCoreAvailable
()
;
VAPY_REQUIRE_CONN_TRY
;
VA_EXCEPT_NOT_IMPLEMENTED
;
VA_EXCEPT_NOT_IMPLEMENTED
;
return
NULL
;
return
NULL
;
}
VAPY_CATCH_RETURN
;
};
static
PyObject
*
va_add_search_path
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
static
PyObject
*
va_add_search_path
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
{
{
RequireCoreAvailable
()
;
VAPY_REQUIRE_CONN_TRY
;
VA_EXCEPT_NOT_IMPLEMENTED
;
VA_EXCEPT_NOT_IMPLEMENTED
;
return
NULL
;
return
NULL
;
}
VAPY_CATCH_RETURN
;
};
static
PyObject
*
va_create_listener
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
static
PyObject
*
va_create_listener
(
PyObject
*
pSelf
,
PyObject
**
ppArgs
,
Py_ssize_t
nArgs
,
PyObject
*
pKeywordNames
)
{
{
RequireCoreAvailable
()
;
VAPY_REQUIRE_CONN_TRY
;
std
::
string
sName
=
"PyListener"
;
std
::
string
sName
=
"PyListener"
;
int
iID
=
g_pVANetClient
->
GetCoreInstance
()
->
CreateListener
(
sName
,
IVACore
::
VA_AURAMODE_ALL
);
int
iID
=
g_pVANetClient
->
GetCoreInstance
()
->
CreateListener
(
sName
,
IVACore
::
VA_AURAMODE_ALL
);
return
PyLong_FromLong
(
iID
);
return
PyLong_FromLong
(
iID
);
}
VAPY_CATCH_RETURN
;
};
This diff is collapsed.
Click to expand it.
tests/va_test_connection.py
+
7
−
3
View file @
cf38808d
# VA is used as a singleton.
# VA is used as a singleton.
# You can access va in every script, function and method.
# You can access va in every script, function and method.
print
(
"
Testing va extension connection.
"
)
# Add va module if it was not installed
import
sys
sys
.
path
.
append
(
'
../Lib/site-packages
'
)
# deploy structure
import
va
import
va
if
va
.
connect
(
"
localhost
"
,
12340
)
==
1
:
print
(
"
Testing va extension connection.
"
)
if
va
.
connect
(
"
pc-jst
"
)
:
print
(
"
Successfully connected
"
)
print
(
"
Successfully connected
"
)
else
:
else
:
print
(
"
Connection failed
"
)
print
(
"
Connection failed
"
)
if
va
.
is_connected
()
==
1
:
if
va
.
is_connected
()
:
va
.
disconnect
()
va
.
disconnect
()
print
(
"
Test done.
"
)
print
(
"
Test done.
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment