Advertisement
NuLL3rr0r

client.hpp / ZeroMQ C-Bindings

Dec 22nd, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #ifndef CLIENT_HPP
  2. #define CLIENT_HPP
  3.  
  4.  
  5. #include <queue>
  6. #include <string>
  7. #include <boost/function.hpp>
  8. #include <boost/thread.hpp>
  9. #include <zmq.h>
  10.  
  11. namespace GSLogger {
  12. class Client;
  13. }
  14.  
  15. class GSLogger::Client
  16. {
  17. private:
  18.     static const std::string MSG_RECEIVED;
  19.    
  20. public:
  21.     boost::function<void(const std::string &)> OnMessageSent;
  22.    
  23. private:
  24.     std::string m_id;
  25.     bool m_running;
  26.     size_t m_port;
  27.    
  28.     std::queue<std::string> m_requests;
  29.    
  30.     boost::thread *m_workerThread;
  31.     boost::mutex m_workerMutex;
  32.     boost::mutex m_dataMutex;
  33.    
  34.     void *m_context;
  35.     void *m_socket;
  36.    
  37. public:
  38.     Client();
  39.     Client(const std::string &id, size_t port);
  40.     ~Client();
  41.    
  42. public:
  43.     void SetId(const std::string &id);
  44.     void SetPort(const size_t port);
  45.    
  46.     bool IsRunning();
  47.     void Start();
  48.     void Stop();
  49.    
  50.     void SendMessage(const std::string &msg);
  51.    
  52. private:
  53.     void SendRequest(const std::string &req);
  54.     void SendRequests();
  55. };
  56.  
  57.  
  58. #endif /* CLIENT_HPP */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement