Skip to content

Commit

Permalink
Merge pull request #384 from mmurooka/python-client
Browse files Browse the repository at this point in the history
  • Loading branch information
gergondet authored Aug 16, 2023
2 parents 4717774 + b44c05a commit a0e2841
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
12 changes: 12 additions & 0 deletions binding/python/mc_control/c_mc_control.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,15 @@ cdef extern from "mc_control_wrapper.hpp" namespace "mc_control":

void add_anchor_frame_callback[T, U](MCPythonController &, const string &, T, U)
void remove_anchor_frame_callback(MCPythonController &, const string &)

cdef extern from "<mc_control/ControllerClient.h>" namespace "mc_control":
cdef cppclass ElementId:
ElementId()
ElementId(const vector[string]&, const string&)
vector[string] category
string name
cdef cppclass ControllerClient:
ControllerClient()
ControllerClient(const string&, const string&, double)
void send_request(const ElementId&)
void send_request(const ElementId&, c_mc_rtc.Configuration)
6 changes: 6 additions & 0 deletions binding/python/mc_control/mc_control.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ cdef public api class MCPythonController(MCController)[object MCPythonController

cdef class MCGlobalController(object):
cdef c_mc_control.MCGlobalController * impl

cdef class ElementId(object):
cdef c_mc_control.ElementId impl

cdef class ControllerClient(object):
cdef c_mc_control.ControllerClient * impl
25 changes: 25 additions & 0 deletions binding/python/mc_control/mc_control.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,28 @@ cdef class MCGlobalController(object):
return self.impl.running
def __set__(self, b):
self.impl.running = b

cdef class ElementId(object):
def __cinit__(self, category, name):
if isinstance(name, unicode):
name = name.encode(u'ascii')
self.impl = c_mc_control.ElementId([s.encode(u'ascii') if isinstance(s, unicode) else s for s in category] , name)
property category:
def __get__(self):
return self.impl.category
property name:
def __get__(self):
return self.impl.name

cdef class ControllerClient(object):
def __cinit__(self, sub_conn_uri, push_conn_uri, timeout = 0.0):
if isinstance(sub_conn_uri, unicode):
sub_conn_uri = sub_conn_uri.encode(u'ascii')
if isinstance(push_conn_uri, unicode):
push_conn_uri = push_conn_uri.encode(u'ascii')
self.impl = new c_mc_control.ControllerClient(sub_conn_uri, push_conn_uri, timeout)
def send_request(self, element_id, data = None):
if data is None:
deref(self.impl).send_request((<ElementId>element_id).impl)
else:
deref(self.impl).send_request((<ElementId>element_id).impl, deref((<mc_rtc.Configuration>data).impl))
2 changes: 1 addition & 1 deletion include/mc_control/ControllerClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ struct MC_CONTROL_CLIENT_DLLAPI ControllerClient
virtual void stopped() {}

/** Should be implemented to create a new category container */
virtual void category(const std::vector<std::string> & parent, const std::string & category) = 0;
virtual void category(const std::vector<std::string> & parent, const std::string & category){};

/** Should be implemented to create a label for data that can be displayed as string */
inline virtual void label(const ElementId & id, const std::string &) { default_impl("Label", id); }
Expand Down

0 comments on commit a0e2841

Please sign in to comment.