Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up Registry class #10222

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions lib/base/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,55 +23,13 @@ class Registry
public:
typedef std::map<String, T> ItemMap;

void RegisterIfNew(const String& name, const T& item)
{
std::unique_lock<std::mutex> lock(m_Mutex);

if (m_Items.find(name) != m_Items.end())
return;

RegisterInternal(name, item, lock);
}

void Register(const String& name, const T& item)
{
std::unique_lock<std::mutex> lock(m_Mutex);

RegisterInternal(name, item, lock);
}

void Unregister(const String& name)
{
size_t erased;

{
std::unique_lock<std::mutex> lock(m_Mutex);
erased = m_Items.erase(name);
}

if (erased > 0)
OnUnregistered(name);
}

void Clear()
{
typename Registry<U, T>::ItemMap items;

{
std::unique_lock<std::mutex> lock(m_Mutex);
items = m_Items;
}

for (const auto& kv : items) {
OnUnregistered(kv.first);
}

{
std::unique_lock<std::mutex> lock(m_Mutex);
m_Items.clear();
}
}

T GetItem(const String& name) const
{
std::unique_lock<std::mutex> lock(m_Mutex);
Expand Down
5 changes: 0 additions & 5 deletions lib/remote/apiaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ void ApiAction::Register(const String& name, const ApiAction::Ptr& action)
ApiActionRegistry::GetInstance()->Register(name, action);
}

void ApiAction::Unregister(const String& name)
{
ApiActionRegistry::GetInstance()->Unregister(name);
}

ApiActionRegistry *ApiActionRegistry::GetInstance()
{
return Singleton<ApiActionRegistry>::GetInstance();
Expand Down
1 change: 0 additions & 1 deletion lib/remote/apiaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class ApiAction final : public Object

static ApiAction::Ptr GetByName(const String& name);
static void Register(const String& name, const ApiAction::Ptr& action);
static void Unregister(const String& name);

private:
std::vector<String> m_Types;
Expand Down
5 changes: 0 additions & 5 deletions lib/remote/apifunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ void ApiFunction::Register(const String& name, const ApiFunction::Ptr& function)
ApiFunctionRegistry::GetInstance()->Register(name, function);
}

void ApiFunction::Unregister(const String& name)
{
ApiFunctionRegistry::GetInstance()->Unregister(name);
}

ApiFunctionRegistry *ApiFunctionRegistry::GetInstance()
{
return Singleton<ApiFunctionRegistry>::GetInstance();
Expand Down
1 change: 0 additions & 1 deletion lib/remote/apifunction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class ApiFunction final : public Object

static ApiFunction::Ptr GetByName(const String& name);
static void Register(const String& name, const ApiFunction::Ptr& function);
static void Unregister(const String& name);

private:
Callback m_Callback;
Expand Down
13 changes: 0 additions & 13 deletions lib/remote/eventqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@ void EventQueue::RemoveClient(void *client)
m_Events.erase(client);
}

void EventQueue::UnregisterIfUnused(const String& name, const EventQueue::Ptr& queue)
{
std::unique_lock<std::mutex> lock(queue->m_Mutex);

if (queue->m_Events.empty())
Unregister(name);
}

void EventQueue::SetTypes(const std::set<String>& types)
{
std::unique_lock<std::mutex> lock(m_Mutex);
Expand Down Expand Up @@ -135,11 +127,6 @@ void EventQueue::Register(const String& name, const EventQueue::Ptr& function)
EventQueueRegistry::GetInstance()->Register(name, function);
}

void EventQueue::Unregister(const String& name)
{
EventQueueRegistry::GetInstance()->Unregister(name);
}

EventQueueRegistry *EventQueueRegistry::GetInstance()
{
return Singleton<EventQueueRegistry>::GetInstance();
Expand Down
2 changes: 0 additions & 2 deletions lib/remote/eventqueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ class EventQueue final : public Object
Dictionary::Ptr WaitForEvent(void *client, double timeout = 5);

static std::vector<EventQueue::Ptr> GetQueuesForType(const String& type);
static void UnregisterIfUnused(const String& name, const EventQueue::Ptr& queue);

static EventQueue::Ptr GetByName(const String& name);
static void Register(const String& name, const EventQueue::Ptr& function);
static void Unregister(const String& name);

private:
String m_Name;
Expand Down
Loading