Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sds
py-bake
Commits
2ac00fb6
Commit
2ac00fb6
authored
Mar 22, 2018
by
Matthieu Dorier
Browse files
added client
parent
cd8b0159
Changes
4
Hide whitespace changes
Inline
Side-by-side
pybake/client.py
0 → 100644
View file @
2ac00fb6
import
_pybakeclient
import
pymargo
class
BakeClient
():
def
__init__
(
self
,
mid
):
self
.
_client
=
_pybakeclient
.
client_init
(
mid
.
_mid
)
def
create_provider_handle
(
self
,
addr
,
mplex_id
):
ph
=
_pybakeclient
.
provider_handle_create
(
self
.
_client
,
addr
.
get_hg_addr
(),
mplex_id
)
return
BakeProviderHandle
(
ph
)
def
shutdown_service
(
self
,
addr
):
_pybakeclient
.
shutdown_service
(
self
.
_client
,
addr
.
get_hg_addr
())
def
__del__
(
self
):
_pybakeclient
.
client_finalize
(
self
.
_client
)
class
BakeProviderHandle
():
def
__init__
(
self
,
ph
):
self
.
_ph
=
ph
def
__del__
(
self
):
_pybakeclient
.
provider_handle_release
(
self
.
_ph
)
pybake/src/client.cpp
0 → 100644
View file @
2ac00fb6
#define BOOST_NO_AUTO_PTR
#include
<boost/python.hpp>
#include
<boost/python/return_opaque_pointer.hpp>
#include
<boost/python/handle.hpp>
#include
<boost/python/enum.hpp>
#include
<boost/python/def.hpp>
#include
<boost/python/module.hpp>
#include
<boost/python/return_value_policy.hpp>
#include
<string>
#include
<vector>
#include
<cstring>
#include
<iostream>
#include
<margo.h>
#include
<bake.h>
#include
<bake-client.h>
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID
(
margo_instance
)
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID
(
bake_provider_handle
)
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID
(
bake_client
)
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID
(
hg_addr
)
namespace
bpl
=
boost
::
python
;
static
bake_client_t
pybake_client_init
(
margo_instance_id
mid
)
{
bake_client_t
result
=
BAKE_CLIENT_NULL
;
bake_client_init
(
mid
,
&
result
);
return
result
;
}
static
bake_provider_handle_t
pybake_provider_handle_create
(
bake_client_t
client
,
hg_addr_t
addr
,
uint8_t
mplex_id
)
{
bake_provider_handle_t
providerHandle
=
BAKE_PROVIDER_HANDLE_NULL
;
bake_provider_handle_create
(
client
,
addr
,
mplex_id
,
&
providerHandle
);
return
providerHandle
;
}
BOOST_PYTHON_MODULE
(
_pybakeclient
)
{
#define ret_policy_opaque bpl::return_value_policy<bpl::return_opaque_pointer>()
bpl
::
opaque
<
bake_client
>
();
bpl
::
opaque
<
bake_provider_handle
>
();
bpl
::
def
(
"client_init"
,
&
pybake_client_init
,
ret_policy_opaque
);
bpl
::
def
(
"client_finalize"
,
&
bake_client_finalize
);
bpl
::
def
(
"provider_handle_create"
,
&
pybake_provider_handle_create
,
ret_policy_opaque
);
bpl
::
def
(
"provider_handle_ref_incr"
,
&
bake_provider_handle_ref_incr
);
bpl
::
def
(
"provider_handle_release"
,
&
bake_provider_handle_release
);
bpl
::
def
(
"shutdown_service"
,
&
bake_shutdown_service
);
#undef ret_policy_opaque
}
setup.py
View file @
2ac00fb6
...
...
@@ -14,10 +14,15 @@ pybake_server_module = Extension('_pybakeserver', ["pybake/src/server.cpp"],
libraries
=
[
'boost_python'
,
'margo'
,
'bake-server'
],
include_dirs
=
[
'.'
],
depends
=
[])
pybake_client_module
=
Extension
(
'_pybakeclient'
,
[
"pybake/src/client.cpp"
],
libraries
=
[
'boost_python'
,
'margo'
,
'bake-client'
],
include_dirs
=
[
'.'
],
depends
=
[])
setup
(
name
=
'pybake'
,
version
=
'0.1'
,
author
=
'Matthieu Dorier'
,
description
=
"""Python binding for BAKE"""
,
ext_modules
=
[
pybake_server_module
],
ext_modules
=
[
pybake_server_module
,
pybake_client_module
],
packages
=
[
'pybake'
]
)
test/server.py
View file @
2ac00fb6
...
...
@@ -4,6 +4,7 @@ import pybake.server
from
pybake.server
import
BakeProvider
mid
=
MargoInstance
(
'tcp'
)
mid
.
enable_remote_shutdown
()
mplex_id
=
42
print
"Server running at address "
+
str
(
mid
.
addr
())
+
"with mplex_id="
+
str
(
mplex_id
)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment