Fix casting from and to void*
[platform/core/test/security-tests.git] / src / cynara-tests / common / cynara_test_client_async_status_monitor.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <cynara_test_client_async_status_monitor.h>
18
19 #include <dpl/test/test_runner.h>
20
21 namespace CynaraTestClientAsync {
22
23 StatusMonitor::StatusMonitor(const StatusFunction &userFunction)
24     : m_fd(-1), m_status(CYNARA_STATUS_FOR_READ), m_userFunction(userFunction)
25 {
26 }
27
28 void StatusMonitor::updateStatus(int oldFd, int newFd, cynara_async_status status, void *data)
29 {
30     RUNNER_DEFER_TRYCATCH(
31         StatusMonitor *monitor = static_cast<StatusMonitor*>(data);
32         if (!monitor) {
33             RUNNER_FAIL_MSG("Bad user data (nullptr) in status callback.");
34             return;
35         }
36
37         RUNNER_ASSERT_MSG(monitor->m_fd == oldFd,
38                              "fd value mismatch: "
39                                  << " last saved fd = " << monitor->m_fd << ","
40                                  << " callback oldFd = " << oldFd << ".");
41
42         monitor->m_fd = newFd;
43         monitor->m_status = status;
44         if (monitor->m_userFunction)
45             monitor->m_userFunction(oldFd, newFd, status);
46     );
47 }
48
49 int StatusMonitor::getFd(void) const
50 {
51     return m_fd;
52 }
53
54 enum SocketStatus StatusMonitor::getStatus(void) const
55 {
56     if (m_fd == -1)
57         return DISCONNECTED;
58
59     switch (m_status) {
60         case CYNARA_STATUS_FOR_READ:
61             return READ;
62         case CYNARA_STATUS_FOR_RW:
63             return READWRITE;
64     }
65     RUNNER_FAIL_MSG("Unknown cynara socket status = " << m_status << ","
66                         << " fd = " << m_fd << ".");
67     return UNKNOWN;
68 }
69
70 }// namespace CynaraTestClientAsync