mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-08-17 17:01:58 +08:00
[fibre] fix handling of multiple devices
This commit is contained in:
@@ -210,8 +210,8 @@ void Context::deregister_backend(std::string name) {
|
||||
void Domain::start_discovery(Callback<void, Object*, Interface*> on_found_object, Callback<void, Object*> on_lost_object) {
|
||||
on_found_object_ = on_found_object;
|
||||
on_lost_object_ = on_lost_object;
|
||||
if (root_object_) {
|
||||
on_found_object_.invoke(root_object_, root_intf_);
|
||||
for (auto& it: root_objects_) {
|
||||
on_found_object_.invoke(it.first, it.second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,8 +219,8 @@ void Domain::stop_discovery() {
|
||||
auto on_lost_object = on_lost_object_;
|
||||
on_found_object_ = nullptr;
|
||||
on_lost_object_ = nullptr;
|
||||
if (root_object_) {
|
||||
on_lost_object.invoke(root_object_);
|
||||
for (auto& it: root_objects_) {
|
||||
on_lost_object.invoke(it.first);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -251,16 +251,17 @@ void Domain::on_found_channels(ChannelDiscoveryResult result) {
|
||||
|
||||
#if FIBRE_ENABLE_CLIENT
|
||||
void Domain::on_found_root_object(LegacyObjectClient* obj_client, std::shared_ptr<LegacyObject> obj) {
|
||||
root_object_ = reinterpret_cast<Object*>(obj.get());
|
||||
root_intf_ = reinterpret_cast<Interface*>(obj->intf.get());
|
||||
on_found_object_.invoke(root_object_, root_intf_);
|
||||
Object* root_object = reinterpret_cast<Object*>(obj.get());
|
||||
Interface* root_intf = reinterpret_cast<Interface*>(obj->intf.get());
|
||||
root_objects_[root_object] = root_intf;
|
||||
on_found_object_.invoke(root_object, root_intf);
|
||||
}
|
||||
|
||||
void Domain::on_lost_root_object(LegacyObjectClient* obj_client) {
|
||||
auto root_object = root_object_;
|
||||
root_object_ = nullptr;
|
||||
root_intf_ = nullptr;
|
||||
on_lost_object_.invoke(reinterpret_cast<Object*>(root_object));
|
||||
void Domain::on_lost_root_object(LegacyObjectClient* obj_client, std::shared_ptr<LegacyObject> obj) {
|
||||
Object* root_object = reinterpret_cast<Object*>(obj.get());
|
||||
auto it = root_objects_.find(root_object);
|
||||
root_objects_.erase(it);
|
||||
on_lost_object_.invoke(root_object);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ public:
|
||||
private:
|
||||
#if FIBRE_ENABLE_CLIENT
|
||||
void on_found_root_object(LegacyObjectClient* obj_client, std::shared_ptr<LegacyObject> obj);
|
||||
void on_lost_root_object(LegacyObjectClient* obj_client);
|
||||
void on_lost_root_object(LegacyObjectClient* obj_client, std::shared_ptr<LegacyObject> obj);
|
||||
#endif
|
||||
void on_stopped(LegacyProtocolPacketBased* protocol, StreamStatus status);
|
||||
|
||||
@@ -116,8 +116,7 @@ private:
|
||||
#if FIBRE_ENABLE_CLIENT
|
||||
Callback<void, Object*, Interface*> on_found_object_;
|
||||
Callback<void, Object*> on_lost_object_;
|
||||
Object* root_object_ = nullptr;
|
||||
Interface* root_intf_ = nullptr;
|
||||
std::unordered_map<Object*, Interface*> root_objects_;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ std::vector<LegacyFibreArg> parse_arglist(const json_value& list_val) {
|
||||
return arglist;
|
||||
}
|
||||
|
||||
void LegacyObjectClient::start(Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_found_root_object, Callback<void, LegacyObjectClient*> on_lost_root_object) {
|
||||
void LegacyObjectClient::start(Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_found_root_object, Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_lost_root_object) {
|
||||
FIBRE_LOG(D) << "start";
|
||||
on_found_root_object_ = on_found_root_object;
|
||||
on_lost_root_object_ = on_lost_root_object;
|
||||
|
||||
@@ -121,12 +121,12 @@ class LegacyObjectClient {
|
||||
public:
|
||||
LegacyObjectClient(LegacyProtocolPacketBased* protocol) : protocol_(protocol) {}
|
||||
|
||||
void start(Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_found_root_object, Callback<void, LegacyObjectClient*> on_lost_root_object);
|
||||
void start(Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_found_root_object, Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_lost_root_object);
|
||||
bool transcode(cbufptr_t src, bufptr_t dst, std::string src_codec, std::string dst_codec);
|
||||
|
||||
// For direct access by LegacyProtocolPacketBased and libfibre.cpp
|
||||
uint16_t json_crc_ = 0;
|
||||
Callback<void, LegacyObjectClient*> on_lost_root_object_;
|
||||
Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_lost_root_object_;
|
||||
std::shared_ptr<LegacyObject> root_obj_;
|
||||
std::vector<std::shared_ptr<LegacyObject>> objects_;
|
||||
void* user_data_; // used by libfibre to store the libfibre context pointer
|
||||
|
||||
@@ -541,15 +541,16 @@ void LegacyProtocolPacketBased::on_rx_tx_closed(StreamStatus status) {
|
||||
|
||||
// Report that the root object was lost
|
||||
if (client_.on_lost_root_object_ && client_.root_obj_) {
|
||||
auto root_obj = client_.root_obj_;
|
||||
client_.root_obj_ = nullptr;
|
||||
client_.on_lost_root_object_.invoke(&client_);
|
||||
client_.on_lost_root_object_.invoke(&client_, root_obj);
|
||||
}
|
||||
#endif
|
||||
on_stopped_.invoke_and_clear(this, status);
|
||||
}
|
||||
|
||||
#if FIBRE_ENABLE_CLIENT
|
||||
void LegacyProtocolPacketBased::start(Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_found_root_object, Callback<void, LegacyObjectClient*> on_lost_root_object, Callback<void, LegacyProtocolPacketBased*, StreamStatus> on_stopped) {
|
||||
void LegacyProtocolPacketBased::start(Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_found_root_object, Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_lost_root_object, Callback<void, LegacyProtocolPacketBased*, StreamStatus> on_stopped) {
|
||||
#else
|
||||
void LegacyProtocolPacketBased::start(Callback<void, LegacyProtocolPacketBased*, StreamStatus> on_stopped) {
|
||||
#endif
|
||||
|
||||
@@ -114,7 +114,7 @@ public:
|
||||
#endif
|
||||
|
||||
#if FIBRE_ENABLE_CLIENT
|
||||
void start(Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_found_root_object, Callback<void, LegacyObjectClient*> on_lost_root_object, Callback<void, LegacyProtocolPacketBased*, StreamStatus> on_stopped);
|
||||
void start(Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_found_root_object, Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_lost_root_object, Callback<void, LegacyProtocolPacketBased*, StreamStatus> on_stopped);
|
||||
#else
|
||||
void start(Callback<void, LegacyProtocolPacketBased*, StreamStatus> on_stopped);
|
||||
#endif
|
||||
@@ -154,7 +154,7 @@ public:
|
||||
|
||||
|
||||
#if FIBRE_ENABLE_CLIENT
|
||||
void start(Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_found_root_object, Callback<void, LegacyObjectClient*> on_lost_root_object, Callback<void, LegacyProtocolPacketBased*, StreamStatus> on_stopped) {
|
||||
void start(Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_found_root_object, Callback<void, LegacyObjectClient*, std::shared_ptr<LegacyObject>> on_lost_root_object, Callback<void, LegacyProtocolPacketBased*, StreamStatus> on_stopped) {
|
||||
inner_protocol_.start(on_found_root_object, on_lost_root_object, on_stopped);
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
DEFINE_LOG_TOPIC(LIBFIBRE);
|
||||
USE_LOG_TOPIC(LIBFIBRE);
|
||||
|
||||
static const struct LibFibreVersion libfibre_version = { 0, 1, 0 };
|
||||
static const struct LibFibreVersion libfibre_version = { 0, 1, 1 };
|
||||
|
||||
class FIBRE_PRIVATE ExternalEventLoop final : public fibre::EventLoop {
|
||||
public:
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -243,6 +243,7 @@ class ObjectPtrCodec():
|
||||
if value is None:
|
||||
return struct.pack("P", 0)
|
||||
elif isinstance(value, RemoteObject):
|
||||
assert(value._obj_handle) # Cannot serialize reference to a lost object
|
||||
return struct.pack("P", value._obj_handle)
|
||||
else:
|
||||
raise TypeError("Expected value of type RemoteObject or None but got '{}'. An example for a RemoteObject is this expression: odrv0.axis0.controller._input_pos_property".format(type(value).__name__))
|
||||
@@ -642,6 +643,11 @@ class RemoteAttribute(object):
|
||||
else:
|
||||
raise Exception("this attribute cannot be written to")
|
||||
|
||||
class EmptyInterface():
|
||||
def __str__(self):
|
||||
return "[lost object]"
|
||||
def __repr__(self):
|
||||
return self.__str__()
|
||||
|
||||
class RemoteObject(object):
|
||||
"""
|
||||
@@ -725,6 +731,7 @@ class RemoteObject(object):
|
||||
if self.__class__._refcount == 0:
|
||||
libfibre.interfaces.pop(self.__class__._handle)
|
||||
|
||||
self.__class__ = EmptyInterface # ensure that this object has no more attributes
|
||||
on_lost.set_result(True)
|
||||
|
||||
|
||||
@@ -844,6 +851,7 @@ class LibFibre():
|
||||
old_future.set_result(None)
|
||||
|
||||
def _on_lost_object(self, ctx, obj):
|
||||
assert(obj)
|
||||
self._release_py_obj(obj)
|
||||
|
||||
def _on_discovery_stopped(self, ctx, result):
|
||||
|
||||
Reference in New Issue
Block a user