Fixed a segfault on shutdown
This commit is contained in:
@@ -177,7 +177,7 @@ private:
|
|||||||
/**
|
/**
|
||||||
* Device is a storage container for device data we retrieve from OpenCL
|
* Device is a storage container for device data we retrieve from OpenCL
|
||||||
*
|
*
|
||||||
* The data is mainly queries as strings or integer types and stored into
|
* The data are mainly queries as strings or integer types and stored into
|
||||||
* respective containers. We store this data into a file and retrieve it later
|
* respective containers. We store this data into a file and retrieve it later
|
||||||
* to let users select a preferred compute device and keep track of their choice
|
* to let users select a preferred compute device and keep track of their choice
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static std::mutex container_lock;
|
static std::mutex container_lock;
|
||||||
static std::list<Gui*> renderable_container;
|
static std::list<Gui*> renderable_container;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Event.hpp"
|
#include "Event.hpp"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
|
||||||
class VrEventPublisher;
|
class VrEventPublisher;
|
||||||
@@ -13,14 +14,6 @@ class VrEventPublisher;
|
|||||||
*
|
*
|
||||||
* VrEventSubscriber
|
* VrEventSubscriber
|
||||||
*
|
*
|
||||||
* When inherited, the user must impliment a
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -28,16 +21,25 @@ class VrEventPublisher;
|
|||||||
class VrEventSubscriber {
|
class VrEventSubscriber {
|
||||||
public:
|
public:
|
||||||
virtual ~VrEventSubscriber();
|
virtual ~VrEventSubscriber();
|
||||||
|
|
||||||
|
// Recieve an event from a publisher, event must be cast to it's respective event type
|
||||||
virtual void event_handler(VrEventPublisher *publisher, std::unique_ptr<vr::Event> event) = 0;
|
virtual void event_handler(VrEventPublisher *publisher, std::unique_ptr<vr::Event> event) = 0;
|
||||||
|
|
||||||
|
// Subscribes to the publisher, keeps track of the ptr and the relevent event types
|
||||||
void subscribe_to_publisher(VrEventPublisher* publisher, vr::Event::EventType type);
|
void subscribe_to_publisher(VrEventPublisher* publisher, vr::Event::EventType type);
|
||||||
void subscribe_to_publisher(VrEventPublisher* publisher, std::vector<vr::Event::EventType> type);
|
void subscribe_to_publisher(VrEventPublisher* publisher, std::vector<vr::Event::EventType> type);
|
||||||
|
|
||||||
|
// Looks for the publisher ptr and event type in the subscriptions map. If there, Removes them
|
||||||
void unsubscribe(VrEventPublisher* publisher, vr::Event::EventType type);
|
void unsubscribe(VrEventPublisher* publisher, vr::Event::EventType type);
|
||||||
|
void unsubscribe_all(VrEventPublisher* publisher);
|
||||||
|
void unsubscribe_all();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// When we destroy a subscriber we need to be able to notify the publishers
|
// When we destroy a subscriber we need to be able to notify the publishers
|
||||||
// We have to keep track of every EventType because of the way EventTypes
|
// We have to keep track of every EventType because of the way EventTypes
|
||||||
// are mapped to subscribers in the publisher
|
// are mapped to subscribers in the publisher
|
||||||
std::map<VrEventPublisher*, std::vector<vr::Event::EventType>> subscriptions;
|
std::map<VrEventPublisher*, std::set<vr::Event::EventType>> subscriptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -45,11 +47,20 @@ class VrEventPublisher {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~VrEventPublisher();
|
virtual ~VrEventPublisher();
|
||||||
|
|
||||||
|
// Adds the subscriber ptr to the bucket[event_type]
|
||||||
virtual void subscribe(VrEventSubscriber *subscriber, vr::Event::EventType type);
|
virtual void subscribe(VrEventSubscriber *subscriber, vr::Event::EventType type);
|
||||||
virtual void subscribe(VrEventSubscriber *subscriber, std::vector<vr::Event::EventType> type);
|
virtual void subscribe(VrEventSubscriber *subscriber, std::vector<vr::Event::EventType> type);
|
||||||
|
|
||||||
|
// Removes the subscriber ptr from the specified bucket[type]
|
||||||
|
// If subscribed to multiple events, unsubscribe must be called for each event
|
||||||
virtual void unsubscribe(VrEventSubscriber *s, vr::Event::EventType c);
|
virtual void unsubscribe(VrEventSubscriber *s, vr::Event::EventType c);
|
||||||
|
|
||||||
|
// Trigger the publisher to notify it's subscribers to the specified event
|
||||||
virtual void notify_subscribers(std::unique_ptr<vr::Event> event);
|
virtual void notify_subscribers(std::unique_ptr<vr::Event> event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::map<vr::Event::EventType, std::vector<VrEventSubscriber*>> subscribers;
|
std::map<vr::Event::EventType, std::vector<VrEventSubscriber*>> subscribers;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
/**
|
/**
|
||||||
* Subscriber
|
* Subscriber
|
||||||
*/
|
*/
|
||||||
|
|
||||||
VrEventSubscriber::~VrEventSubscriber() {
|
VrEventSubscriber::~VrEventSubscriber() {
|
||||||
|
|
||||||
// Cycles through the publishers we're subscribed to
|
// Cycles through the publishers we're subscribed to
|
||||||
@@ -23,18 +22,30 @@ void VrEventSubscriber::subscribe_to_publisher(VrEventPublisher* publisher, vr::
|
|||||||
|
|
||||||
publisher->subscribe(this, type);
|
publisher->subscribe(this, type);
|
||||||
|
|
||||||
subscriptions[publisher].push_back(type);
|
subscriptions[publisher].insert(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VrEventSubscriber::subscribe_to_publisher(VrEventPublisher* publisher, std::vector<vr::Event::EventType> type) {
|
void VrEventSubscriber::subscribe_to_publisher(VrEventPublisher* publisher, std::vector<vr::Event::EventType> type) {
|
||||||
|
|
||||||
publisher->subscribe(this, type);
|
publisher->subscribe(this, type);
|
||||||
|
|
||||||
subscriptions[publisher].insert(subscriptions[publisher].end(), type.begin(), type.end());
|
subscriptions[publisher].insert(type.begin(), type.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void VrEventSubscriber::unsubscribe(VrEventPublisher* publisher, vr::Event::EventType type){
|
void VrEventSubscriber::unsubscribe(VrEventPublisher* publisher, vr::Event::EventType type){
|
||||||
|
|
||||||
|
if (subscriptions.count(publisher)){
|
||||||
|
std::set<vr::Event::EventType> set = subscriptions[publisher];
|
||||||
|
auto it = set.find (type);
|
||||||
|
set.erase (it, set.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VrEventSubscriber::unsubscribe_all(VrEventPublisher* publisher){
|
||||||
|
|
||||||
|
if (subscriptions.count(publisher)){
|
||||||
|
subscriptions.erase(publisher);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,11 +54,11 @@ void VrEventSubscriber::unsubscribe(VrEventPublisher* publisher, vr::Event::Even
|
|||||||
VrEventPublisher::~VrEventPublisher() {
|
VrEventPublisher::~VrEventPublisher() {
|
||||||
|
|
||||||
// Cycle through the subscribers that are listening to us
|
// Cycle through the subscribers that are listening to us
|
||||||
for (auto const& subscriber_bucket : subscribers) {
|
for (auto const& event_bucket : subscribers) {
|
||||||
|
|
||||||
// And one by one remove the
|
// And one by one remove the subscriber
|
||||||
for (auto subscriber: subscriber_bucket.second){
|
for (auto subscriber: event_bucket.second){
|
||||||
//subscriber.
|
subscriber->unsubscribe(this, event_bucket.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user