[SECIOTSW-349] Add AuditTrail class to audit namespace 26/130626/1
authorLee Sung Jun <sjun221.lee@samsung.com>
Tue, 23 May 2017 06:55:49 +0000 (15:55 +0900)
committerLee Sung Jun <sjun221.lee@samsung.com>
Tue, 23 May 2017 06:55:49 +0000 (15:55 +0900)
Change-Id: I3e3daaef1d829c4cac0c04bb288f5d05a4cecdbc
Signed-off-by: Lee Sung Jun <sjun221.lee@samsung.com>
include/klay/audit/audit-trail.h [new file with mode: 0644]
src/CMakeLists.txt
src/audit/audit-trail.cpp [new file with mode: 0644]

diff --git a/include/klay/audit/audit-trail.h b/include/klay/audit/audit-trail.h
new file mode 100644 (file)
index 0000000..0b25c75
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ *  Copyright (c) 2015 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
+ */
+
+#ifndef __AUDIT_TRAIL_H__
+#define __AUDIT_TRAIL_H__
+
+#include <thread>
+#include <string>
+
+#include <klay/mainloop.h>
+
+namespace audit {
+
+class AuditTrail {
+public:
+       AuditTrail();
+       ~AuditTrail();
+
+       void start();
+       void stop();
+
+       void subscribe(const int fd, const runtime::Mainloop::Event events, runtime::Mainloop::Callback&& callback);
+       void unsubscribe(const int fd);
+
+private:
+       runtime::Mainloop mainloop;
+       std::thread dispatcher;
+};
+
+} // namespace audit
+#endif //__AUDIT_TRAIL_H__
index 8ad2cec8725289e387b9709dacd4dfaf201b0415..3c1339637408ea1cf9ead3258e14df3880f0f964 100755 (executable)
@@ -45,6 +45,7 @@ SET (KLAY_SOURCES             ${KLAY_SRC}/error.cpp
                                                ${KLAY_SRC}/audit/null-sink.cpp
                                                ${KLAY_SRC}/audit/console-sink.cpp
                                                ${KLAY_SRC}/audit/dlog-sink.cpp
+                                               ${KLAY_SRC}/audit/audit-trail.cpp
 )
 
 SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack")
diff --git a/src/audit/audit-trail.cpp b/src/audit/audit-trail.cpp
new file mode 100644 (file)
index 0000000..e9fe960
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2015 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.
+ */
+#include <klay/audit/audit-trail.h>
+
+namespace audit {
+
+AuditTrail::AuditTrail()
+{
+}
+
+AuditTrail::~AuditTrail()
+{
+       stop();
+}
+
+void AuditTrail::start()
+{
+       dispatcher = std::thread([this] { mainloop.run(); });
+}
+
+void AuditTrail::stop()
+{
+       mainloop.stop();
+       if (dispatcher.joinable()) {
+               dispatcher.join();
+       }
+}
+
+void AuditTrail::subscribe(const int fd, const runtime::Mainloop::Event events, runtime::Mainloop::Callback&& callback)
+{
+       mainloop.addEventSource(fd, events, std::move(callback));
+}
+
+void AuditTrail::unsubscribe(const int fd)
+{
+       mainloop.removeEventSource(fd);
+}
+
+} // namespace audit