#ifndef BZOOK_INPUT_SELECTOR_H
#define BZOOK_INPUT_SELECTOR_H

#include "zmq_bazooka/sockets.h"

#include <vector>
#include <utility>
#include <functional>
#include <chrono>

// BUG: On Windows, I am getting a macro here called max. This means that one of the Windows SDK's headers defines one for us
// This is actually a Windows bug and is very dangerous. Someone should tell them.
#undef max

namespace bzook
{

class InputSelector
{
public:
   typedef std::chrono::duration<long, std::milli> milliseconds;

   InputSelector(std::vector<
                 std::pair<bzook::Socket*, std::function<void(bzook::Socket*)>>
                 > socket_callback_pairs);

   // Checks all registered sockets for input and runs their registered callbacks. Returns false if no sockets
   // have available input and the timeout was reached. REMEMBER: This function can throw bzook::Exceptions and any
   // exceptions that can bubble out of your callbacks.
   bool run(milliseconds timeout = milliseconds(-1));

   virtual ~InputSelector();
private:
   std::vector<std::pair<bzook::Socket*, std::function<void(bzook::Socket*)>>> _socket_callback_pairs;
   std::vector<zmq_pollitem_t> _poll_items;
};

}

#endif // BZOOK_INPUT_SELECTOR_H
