/src/cyad/Cyad.cpp

https://gitlab.com/github-cloud-corporation/cynara · C++ · 63 lines · 31 code · 11 blank · 21 comment · 3 complexity · 751cf0c62a2e8e8f6ea6521cad3a2675 MD5 · raw file

  1. /*
  2. * Copyright (c) 2014-2015 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/cyad/Cyad.cpp
  18. * @author Aleksander Zdyb <a.zdyb@samsung.com>
  19. * @version 1.0
  20. * @brief A command-line tool to manage Cynara's database
  21. */
  22. #include <new>
  23. #include <ostream>
  24. #include <cynara-error.h>
  25. #include <cyad/AdminLibraryInitializationFailedException.h>
  26. #include "Cyad.h"
  27. namespace Cynara {
  28. Cyad::Cyad(int argc, char **argv) : m_parser(argc, argv), m_cynaraInitError(CYNARA_API_SUCCESS) {
  29. try {
  30. m_dispatcher.reset(new CommandsDispatcher(m_io, m_adminApiWrapper, m_errorApiWrapper));
  31. } catch (const Cynara::AdminLibraryInitializationFailedException &ex) {
  32. m_cynaraInitError = ex.errorCode();
  33. }
  34. }
  35. Cyad::~Cyad() {}
  36. int Cyad::run(void) {
  37. if (cynaraOperational() == false) {
  38. m_io.cerr() << "Failed to initialize libcynara-admin: " << m_cynaraInitError << std::endl;
  39. return m_cynaraInitError;
  40. }
  41. try {
  42. auto command = m_parser.parseMain();
  43. return command->run(*m_dispatcher);
  44. } catch (const std::bad_alloc &) {
  45. m_io.cerr() << "Cyad could not allocate memory" << std::endl;
  46. return CYNARA_API_OUT_OF_MEMORY;
  47. }
  48. }
  49. bool Cyad::cynaraOperational(void) const {
  50. return m_cynaraInitError == CYNARA_API_SUCCESS;
  51. }
  52. } /* namespace Cynara */