Skip to content

Commit

Permalink
fix: all test passing
Browse files Browse the repository at this point in the history
  • Loading branch information
LucioDonda committed Jul 15, 2024
1 parent 709372f commit 1e7f47f
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 138 deletions.
27 changes: 3 additions & 24 deletions src/agent/queue/include/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ class PersistedQueue
class MultiTypeQueue
{
private:
// std::condition_variable m_cv;
std::unordered_map<MessageType, std::unique_ptr<PersistedQueue>> m_queuesMap;
int m_maxItems;

Expand All @@ -215,7 +214,7 @@ class MultiTypeQueue
{
// Populate the map inside the constructor body
m_queuesMap[MessageType::STATE_LESS] = std::make_unique<PersistedQueue>(MessageType::STATE_LESS, m_maxItems);
m_queuesMap[MessageType::STATE_FULL] = std::make_unique<PersistedQueue>(MessageType::STATE_FULL, m_maxItems);
m_queuesMap[MessageType::STATE_FUL] = std::make_unique<PersistedQueue>(MessageType::STATE_FUL, m_maxItems);
m_queuesMap[MessageType::COMMAND] = std::make_unique<PersistedQueue>(MessageType::COMMAND, m_maxItems);
}

Expand All @@ -232,9 +231,7 @@ class MultiTypeQueue
MultiTypeQueue& operator=(MultiTypeQueue&&) = delete;

// TODO
~MultiTypeQueue() {
// m_queuesMap;
};
~MultiTypeQueue() {};
/**
* @brief: push message to a queue of t
*
Expand All @@ -248,7 +245,7 @@ class MultiTypeQueue
{
// TODO: delete this
std::cout << "waiting" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::this_thread::sleep_for(std::chrono::milliseconds(250));
}
m_queuesMap[message.type]->insertMessage(message);
}
Expand All @@ -259,7 +256,6 @@ class MultiTypeQueue
}
}

// FIFO order
/**
* @brief Get the Last Message object
*
Expand Down Expand Up @@ -300,23 +296,6 @@ class MultiTypeQueue
}
}

// TODO
/**
* @brief
*
* @param event
*/
// void updateLast(Message event)
// {
// std::unique_lock<std::mutex> lock(m_mtx);
// while (m_queuesMap[event.type].empty())
// {
// m_cv.wait(lock);
// }
// m_queuesMap[event.type] = event;
// m_cv.notify_one();
// }

/**
* @brief
*
Expand Down
4 changes: 2 additions & 2 deletions src/agent/queue/include/shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ constexpr char DEFAULT_DB_PATH[] = "queue.db";
enum MessageType
{
STATE_LESS,
STATE_FULL,
STATE_FUL,
COMMAND
};

Expand All @@ -23,7 +23,7 @@ enum MessageType
*/
std::map<MessageType, std::string> MessageTypeName {
{MessageType::STATE_LESS, "STATE_LESS"},
{MessageType::STATE_FULL, "STATE_FULL"},
{MessageType::STATE_FUL, "STATE_FUL"},
{MessageType::COMMAND, "COMMAND"},
};

Expand Down
2 changes: 1 addition & 1 deletion src/agent/queue/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main()
int item;
for (int i = 0; i < count; ++i)
{
queue.popLastMessage(MessageType::STATE_FULL);
queue.popLastMessage(MessageType::STATE_FUL);
std::cout << "Popping event 2: " << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
Expand Down
Loading

0 comments on commit 1e7f47f

Please sign in to comment.