Assemble all Cyad's components 85/32185/8
authorAleksander Zdyb <a.zdyb@samsung.com>
Sat, 20 Dec 2014 12:42:34 +0000 (13:42 +0100)
committerPawel Wieczorek <p.wieczorek2@samsung.com>
Tue, 30 Dec 2014 07:38:15 +0000 (08:38 +0100)
Change-Id: I1a711cad7d5aba0508ef41f308cddcc7a0704b28

src/cyad/CMakeLists.txt
src/cyad/Cyad.cpp [new file with mode: 0644]
src/cyad/Cyad.h [new file with mode: 0644]
src/cyad/main.cpp

index 2a53be4..99e371e 100644 (file)
@@ -21,6 +21,7 @@ SET(CYAD_PATH ${CYNARA_PATH}/cyad)
 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
diff --git a/src/cyad/Cyad.cpp b/src/cyad/Cyad.cpp
new file mode 100644 (file)
index 0000000..092d9a7
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * 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 */
diff --git a/src/cyad/Cyad.h b/src/cyad/Cyad.h
new file mode 100644 (file)
index 0000000..ba98fd8
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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_ */
index ab4a0a8..45aa48c 100644 (file)
  * @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();
 }