- // unix:pass@/var/run/stg.sock
- // tcp:secret@192.168.0.1:12345
- // udp:key@isp.com.ua:54321
-
- size_t pos = addr.find_first_of(':');
- if (pos == std::string::npos)
- throw Error("Missing transport name.");
- transport = toTransport(addr.substr(0, pos));
- addr = addr.substr(pos + 1);
- if (addr.empty())
- throw Error("Missing address to connect to.");
- pos = addr.find_first_of('@');
- if (pos != std::string::npos) {
- key = addr.substr(0, pos);
- addr = addr.substr(pos + 1);
- if (addr.empty())
- throw Error("Missing address to connect to.");
- }
- if (transport == STG::SGCP::UNIX)
- {
- address = addr;
- return;
- }
- pos = addr.find_first_of(':');
- if (pos == std::string::npos)
- throw Error("Missing port.");
- address = addr.substr(0, pos);
- if (str2x(addr.substr(pos + 1), port))
- throw Error("Invalid port value.");
-}
+ public:
+ Impl(const std::string& address);
+ ~Impl();
+
+ bool stop() { return m_conn->stop(); }
+
+ RESULT request(REQUEST_TYPE type, const std::string& userName, const std::string& password, const PAIRS& pairs);
+
+ private:
+ std::string m_address;
+ boost::scoped_ptr<Conn> m_conn;
+
+ pthread_mutex_t m_mutex;
+ pthread_cond_t m_cond;
+ bool m_done;
+ RESULT m_result;
+ bool m_status;
+
+ static bool callback(void* data, const RESULT& result, bool status)
+ {
+ Impl& impl = *static_cast<Impl*>(data);
+ pthread_mutex_lock(&impl.m_mutex);
+ impl.m_result = result;
+ impl.m_status = status;
+ impl.m_done = true;
+ pthread_cond_signal(&impl.m_cond);
+ pthread_mutex_unlock(&impl.m_mutex);
+ return true;
+ }
+};