-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathProxyHelpers.cpp
29 lines (25 loc) · 1.09 KB
/
ProxyHelpers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright (c) 2014-2014 Josh Blum
// SPDX-License-Identifier: BSL-1.0
#include "PythonProxy.hpp"
#include <Pothos/Plugin.hpp>
#include <cassert>
/***********************************************************************
* PyObject helpers - used in python bindings
**********************************************************************/
static Pothos::Proxy convertPyObjectToProxy(Pothos::ProxyEnvironment::Sptr env, PyObject *obj)
{
return std::dynamic_pointer_cast<PythonProxyEnvironment>(env)->makeHandle(obj, REF_BORROWED);
}
static PyObject *convertProxyToPyObject(const Pothos::Proxy &proxy)
{
assert(proxy);
assert(std::dynamic_pointer_cast<PythonProxyHandle>(proxy.getHandle()));
return std::dynamic_pointer_cast<PythonProxyHandle>(proxy.getHandle())->ref.newRef();
}
pothos_static_block(pothosRegisterPyObjectHelpers)
{
Pothos::PluginRegistry::add("/proxy_helpers/python/pyobject_to_proxy",
PyObjectToProxyFcn(&convertPyObjectToProxy));
Pothos::PluginRegistry::add("/proxy_helpers/python/proxy_to_pyobject",
ProxyToPyObjectFcn(&convertProxyToPyObject));
}