SET(CYAD_SOURCES
${CYAD_PATH}/AdminApiWrapper.cpp
${CYAD_PATH}/AdminPolicyParser.cpp
+ ${CYAD_PATH}/Cyad.cpp
${CYAD_PATH}/CynaraAdminPolicies.cpp
${CYAD_PATH}/CommandlineParser/CyadCommand.cpp
${CYAD_PATH}/CommandlineParser/CyadCommandlineParser.cpp
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file src/cyad/Cyad.cpp
+ * @author Aleksander Zdyb <a.zdyb@samsung.com>
+ * @version 1.0
+ * @brief A command-line tool to manage Cynara's database
+ */
+
+#include <new>
+#include <ostream>
+
+#include <cynara-error.h>
+
+#include <cyad/AdminLibraryInitializationFailedException.h>
+
+#include "Cyad.h"
+
+namespace Cynara {
+
+Cyad::Cyad(int argc, char **argv) : m_parser(argc, argv), m_cynaraInitError(CYNARA_API_SUCCESS) {
+ try {
+ m_dispatcher.reset(new CommandsDispatcher(m_io, m_adminApiWrapper));
+ } catch (const Cynara::AdminLibraryInitializationFailedException &ex) {
+ m_cynaraInitError = ex.errorCode();
+ }
+}
+
+Cyad::~Cyad() {}
+
+int Cyad::run(void) {
+ if (cynaraOperational() == false) {
+ m_io.cerr() << "Failed to initialize libcynara-admin: " << m_cynaraInitError << std::endl;
+ return m_cynaraInitError;
+ }
+
+ try {
+ auto command = m_parser.parseMain();
+ return command->run(*m_dispatcher);
+ } catch (const std::bad_alloc &) {
+ m_io.cerr() << "Cyad could not allocate memory" << std::endl;
+ return CYNARA_API_OUT_OF_MEMORY;
+ }
+}
+
+bool Cyad::cynaraOperational(void) const {
+ return m_cynaraInitError == CYNARA_API_SUCCESS;
+}
+
+} /* namespace Cynara */
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file src/cyad/Cyad.h
+ * @author Aleksander Zdyb <a.zdyb@samsung.com>
+ * @version 1.0
+ * @brief A command-line tool to manage Cynara's database
+ */
+
+#ifndef SRC_CYAD_CYAD_H_
+#define SRC_CYAD_CYAD_H_
+
+#include <memory>
+
+#include <cyad/AdminApiWrapper.h>
+#include <cyad/CommandlineParser/CyadCommandlineParser.h>
+#include <cyad/CommandsDispatcher.h>
+#include <cyad/DispatcherIO.h>
+
+namespace Cynara {
+
+class Cyad {
+public:
+ Cyad(int argc, char **argv);
+ ~Cyad();
+
+ int run(void);
+ bool cynaraOperational(void) const;
+
+private:
+ AdminApiWrapper m_adminApiWrapper;
+ DispatcherIO m_io;
+ std::unique_ptr<CommandsDispatcher> m_dispatcher;
+ CyadCommandlineParser m_parser;
+ int m_cynaraInitError;
+};
+
+} /* namespace Cynara */
+
+#endif /* SRC_CYAD_CYAD_H_ */
* @file src/cyad/main.cpp
* @author Aleksander Zdyb <a.zdyb@samsung.com>
* @version 1.0
- * @brief A commandline tool for managing Cynara's database
+ * @brief A command-line tool for managing Cynara's database
*/
-int main(int, char **) {
- return 0;
+#include <cyad/Cyad.h>
+
+int main(int argc, char **argv) {
+ Cynara::Cyad cyad(argc, argv);
+ return cyad.run();
}