Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
VAPython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Institute of Technical Acoustics (ITA)
VAPython
Commits
8a47fab0
Commit
8a47fab0
authored
Aug 23, 2017
by
Dipl.-Ing. Jonas Stienen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
VAStruct parser for Py dicts
parent
3606f09d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
9 deletions
+65
-9
src/vasingletonmethods.hpp
src/vasingletonmethods.hpp
+65
-9
No files found.
src/vasingletonmethods.hpp
View file @
8a47fab0
...
...
@@ -42,7 +42,63 @@ PyObject* ConvertVAStructToPythonDict( const CVAStruct& oInStruct )
//! Helper to convert recursively from Python dict to VAStruct
CVAStruct
ConvertPythonDictToVAStruct
(
PyObject
*
pInDict
)
{
return
CVAStruct
();
CVAStruct
oReturn
;
PyObject
*
pKeyList
=
PyDict_Keys
(
pInDict
);
PyObject
*
pValueList
=
PyDict_Values
(
pInDict
);
for
(
Py_ssize_t
i
=
0
;
i
<
PyList_Size
(
pKeyList
);
i
++
)
{
PyObject
*
pKey
=
PyList_GetItem
(
pKeyList
,
i
);
PyObject
*
pValue
=
PyList_GetItem
(
pValueList
,
i
);
char
*
pcKeyName
=
nullptr
;
if
(
!
PyArg_Parse
(
pKey
,
"s"
,
&
pcKeyName
))
VA_EXCEPT2
(
CVAException
::
INVALID_PARAMETER
,
"Invalid key '"
+
std
::
string
(
pcKeyName
)
+
"'"
);
if
(
Py_None
==
pValue
)
{
oReturn
[
pcKeyName
]
=
false
;
}
else
if
(
PyBool_Check
(
pValue
))
{
oReturn
[
pcKeyName
]
=
bool
(
PyLong_AsLong
(
pValue
));
}
else
if
(
PyLong_Check
(
pValue
))
{
oReturn
[
pcKeyName
]
=
PyLong_AsLong
(
pValue
);
}
else
if
(
PyFloat_Check
(
pValue
))
{
oReturn
[
pcKeyName
]
=
PyFloat_AsDouble
(
pValue
);
}
else
if
(
PyUnicode_Check
(
pValue
))
{
char
*
pcStringValue
=
nullptr
;
if
(
!
PyArg_Parse
(
pValue
,
"s"
,
&
pcStringValue
))
VA_EXCEPT2
(
CVAException
::
INVALID_PARAMETER
,
"Invalid string value at key '"
+
std
::
string
(
pcKeyName
)
+
"': "
+
std
::
string
(
pcStringValue
));
oReturn
[
pcKeyName
]
=
std
::
string
(
pcStringValue
);
}
else
if
(
PyDict_Check
(
pValue
))
{
oReturn
[
pcKeyName
]
=
ConvertPythonDictToVAStruct
(
pValue
);
}
else
if
(
PyList_Check
(
pValue
))
{
// Sample buffer
VA_EXCEPT_NOT_IMPLEMENTED
;
}
else
if
(
PyByteArray_Check
(
pValue
))
{
// Data blob
VA_EXCEPT_NOT_IMPLEMENTED
;
}
else
{
VA_EXCEPT2
(
INVALID_PARAMETER
,
"Could not interpret value of key '"
+
std
::
string
(
pcKeyName
)
+
"' as a supported VAStruct type."
)
}
}
return
oReturn
;
};
...
...
@@ -126,21 +182,21 @@ static PyObject* va_call_module(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t n
{
VAPY_REQUIRE_CONN_TRY
;
static
const
char
*
const
_keywords
[]
=
{
"module_name"
,
"arguments"
,
NULL
};
static
_PyArg_Parser
_parser
=
{
"s
o
:call_module"
,
_keywords
,
0
};
static
const
char
*
const
_keywords
[]
=
{
"module_name"
,
"arguments
_dict
"
,
NULL
};
static
_PyArg_Parser
_parser
=
{
"s
O!
:call_module"
,
_keywords
,
0
};
char
*
pcModuleName
=
nullptr
;
PyObject
*
pArguments
=
nullptr
;
PyObject
*
pArguments
Dict
=
nullptr
;
if
(
!
_PyArg_ParseStack
(
ppArgs
,
nArgs
,
pKeywordNames
,
&
_parser
,
&
pcModuleName
,
&
pArguments
)
)
if
(
!
_PyArg_ParseStack
(
ppArgs
,
nArgs
,
pKeywordNames
,
&
_parser
,
&
pcModuleName
,
&
PyDict_Type
,
&
pArgumentsDict
)
)
return
NULL
;
std
::
string
sModuleName
=
std
::
string
(
pcModuleName
);
CVAStruct
o
Args
=
ConvertPythonDictToVAStruct
(
pArguments
);
CVAStruct
o
Return
;
CVAStruct
o
InArgs
=
ConvertPythonDictToVAStruct
(
pArgumentsDict
);
CVAStruct
o
OutArgs
;
g_pVANetClient
->
GetCoreInstance
()
->
CallModule
(
sModuleName
,
o
Args
,
oReturn
);
g_pVANetClient
->
GetCoreInstance
()
->
CallModule
(
sModuleName
,
o
InArgs
,
oOutArgs
);
return
ConvertVAStructToPythonDict
(
o
Return
);
return
ConvertVAStructToPythonDict
(
o
OutArgs
);
VAPY_CATCH_RETURN
;
};
...
...
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