2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <cynara_test_client_async_status_monitor.h>
19 #include <dpl/test/test_runner.h>
21 namespace CynaraTestClientAsync {
23 StatusMonitor::StatusMonitor(const StatusFunction &userFunction)
24 : m_fd(-1), m_status(CYNARA_STATUS_FOR_READ), m_userFunction(userFunction)
28 void StatusMonitor::updateStatus(int oldFd, int newFd, cynara_async_status status, void *data)
30 RUNNER_DEFER_TRYCATCH(
31 StatusMonitor *monitor = static_cast<StatusMonitor*>(data);
33 RUNNER_FAIL_MSG("Bad user data (nullptr) in status callback.");
37 RUNNER_ASSERT_MSG(monitor->m_fd == oldFd,
39 << " last saved fd = " << monitor->m_fd << ","
40 << " callback oldFd = " << oldFd << ".");
42 monitor->m_fd = newFd;
43 monitor->m_status = status;
44 if (monitor->m_userFunction)
45 monitor->m_userFunction(oldFd, newFd, status);
49 int StatusMonitor::getFd(void) const
54 enum SocketStatus StatusMonitor::getStatus(void) const
60 case CYNARA_STATUS_FOR_READ:
62 case CYNARA_STATUS_FOR_RW:
65 RUNNER_FAIL_MSG("Unknown cynara socket status = " << m_status << ","
66 << " fd = " << m_fd << ".");
70 }// namespace CynaraTestClientAsync