Agent class has been added and its usage in main.cpp file.
Change-Id: Iaec77d164c966a389df97e415febdca6622dc082
SET(ASKUSER_AGENT_PATH ${ASKUSER_PATH}/agent)
SET(ASKUSER_SOURCES
+ ${ASKUSER_AGENT_PATH}/main/Agent.cpp
${ASKUSER_AGENT_PATH}/main/main.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/agent/main/Agent.cpp
+ * @author Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @brief This file implements main class of ask user agent
+ */
+
+#include <unistd.h>
+
+#include <log/log.h>
+
+#include "Agent.h"
+
+namespace AskUser {
+
+namespace Agent {
+
+Agent::Agent() {
+ init();
+}
+
+Agent::~Agent() {
+ finish();
+}
+
+void Agent::init() {
+ // TODO: implement if needed
+
+ LOGD("Agent daemon initialized");
+}
+
+void Agent::run() {
+ // TODO: implement real task
+ while (true) {
+ sleep(1);
+ }
+
+ LOGD("Ask user agent task stopped");
+}
+
+void Agent::finish() {
+ // TODO: implement if needed
+
+ LOGD("Agent daemon has stopped commonly");
+}
+
+} // namespace Agent
+
+} // namespace AskUser
--- /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/agent/main/Agent.h
+ * @author Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @brief This file defines main class of ask user agent
+ */
+
+#pragma once
+
+namespace AskUser {
+
+namespace Agent {
+
+class Agent {
+public:
+ Agent();
+ ~Agent();
+
+ void run();
+
+private:
+ void init();
+ void finish();
+};
+
+} // namespace Agent
+
+} // namespace AskUser
*/
#include <cstdlib>
-#include <unistd.h>
-
+#include <exception>
#include <systemd/sd-journal.h>
#include <systemd/sd-daemon.h>
#include <attributes/attributes.h>
#include <log/log.h>
+#include "Agent.h"
+
int main(int argc UNUSED, char **argv UNUSED) {
init_log();
- int ret = sd_notify(0, "READY=1");
- if (ret == 0) {
- LOGW("Ask user agent was not configured to notify its status");
- } else if (ret < 0) {
- LOGE("sd_notify failed: [" << ret << "]");
- }
+ try {
+ AskUser::Agent::Agent agent;
+
+ int ret = sd_notify(0, "READY=1");
+ if (ret == 0) {
+ LOGW("Agent was not configured to notify its status");
+ } else if (ret < 0) {
+ LOGE("sd_notify failed: [" << ret << "]");
+ }
- while (true) {
- sleep(1);
+ agent.run();
+ } catch (const std::exception &e) {
+ LOGC("Agent stopped because of unhandled exception: <" << e.what() << ">");
+ return EXIT_FAILURE;
+ } catch (...) {
+ LOGC("Agent stopped because of unknown unhandled exception.");
+ return EXIT_FAILURE;
}
return EXIT_SUCCESS;