/src/client-async/callback/StatusCallback.cpp

https://gitlab.com/github-cloud-corporation/cynara · C++ · 46 lines · 19 code · 6 blank · 21 comment · 5 complexity · ef97cf43b903ab6838ace58eb4727789 MD5 · raw file

  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. * @file src/client-async/callback/StatusCallback.cpp
  18. * @author Marcin Niesluchowski <m.niesluchow@samsung.com>
  19. * @version 1.0
  20. * @brief This file contains definition of StatusCallback class
  21. */
  22. #include "StatusCallback.h"
  23. namespace Cynara {
  24. StatusCallback::StatusCallback(cynara_status_callback callback, void *userData)
  25. : m_callback(callback), m_userData(userData), m_sockFd(-1),
  26. m_status(cynara_async_status::CYNARA_STATUS_FOR_READ) {
  27. }
  28. void StatusCallback::onStatusChange(int newFd, cynara_async_status status) {
  29. if (!m_callback)
  30. return;
  31. if (m_status == status && m_sockFd == newFd)
  32. return;
  33. m_callback(m_sockFd, newFd, status, m_userData);
  34. m_sockFd = newFd;
  35. m_status = status;
  36. }
  37. void StatusCallback::onDisconnected(void) {
  38. onStatusChange(-1, cynara_async_status::CYNARA_STATUS_FOR_READ);
  39. }
  40. } // namespace Cynara