User can pass now own function, that will be executed when status changes.
Change-Id: Ic3f514f18c780aff51cf62114fc3cf98dac70067
{
}
-Client::Client()
- : m_cynara(nullptr)
+Client::Client(const StatusFunction &userFunction)
+ : m_cynara(nullptr), m_statusMonitor(userFunction)
{
int ret = cynara_async_initialize(&m_cynara, nullptr, StatusMonitor::updateStatus,
reinterpret_cast<void*>(&m_statusMonitor));
IGNORE_TIMEOUT,
};
- Client();
+ Client(const StatusFunction &userFunction = StatusFunction());
~Client() noexcept(false);
void assertStatus(enum SocketStatus expectedStatus);
namespace CynaraTestClientAsync {
-StatusMonitor::StatusMonitor()
- : m_fd(-1), m_status(CYNARA_STATUS_FOR_READ)
+StatusMonitor::StatusMonitor(const StatusFunction &userFunction)
+ : m_fd(-1), m_status(CYNARA_STATUS_FOR_READ), m_userFunction(userFunction)
{
}
monitor->m_fd = newFd;
monitor->m_status = status;
+ if (monitor->m_userFunction)
+ monitor->m_userFunction(oldFd, newFd, status);
}
int StatusMonitor::getFd(void) const
#include <cynara-client-async.h>
+#include <functional>
+
namespace CynaraTestClientAsync {
enum SocketStatus
UNKNOWN,
};
+typedef std::function<void(int oldFd, int newFd, cynara_async_status status)> StatusFunction;
+
class StatusMonitor
{
public:
- StatusMonitor();
+ StatusMonitor(const StatusFunction &userFunction);
static void updateStatus(int oldFd, int newFd, cynara_async_status status, void *data);
private:
int m_fd;
cynara_async_status m_status;
+ StatusFunction m_userFunction;
};
}// namespace CynaraTestClientAsync