From be57b6cd35dfec765b4a8c05cbf8bbd1ff25857d Mon Sep 17 00:00:00 2001 From: Lee Sung Jun Date: Tue, 23 May 2017 15:55:49 +0900 Subject: [PATCH] [SECIOTSW-349] Add AuditTrail class to audit namespace Change-Id: I3e3daaef1d829c4cac0c04bb288f5d05a4cecdbc Signed-off-by: Lee Sung Jun --- include/klay/audit/audit-trail.h | 44 +++++++++++++++++++++++++++ src/CMakeLists.txt | 1 + src/audit/audit-trail.cpp | 52 ++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 include/klay/audit/audit-trail.h create mode 100644 src/audit/audit-trail.cpp diff --git a/include/klay/audit/audit-trail.h b/include/klay/audit/audit-trail.h new file mode 100644 index 0000000..0b25c75 --- /dev/null +++ b/include/klay/audit/audit-trail.h @@ -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 +#include + +#include + +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__ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8ad2cec..3c13396 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 index 0000000..e9fe960 --- /dev/null +++ b/src/audit/audit-trail.cpp @@ -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 + +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 -- 2.34.1