diff options
Diffstat (limited to 'runtimes/libs/xray/mux')
-rw-r--r-- | runtimes/libs/xray/mux/CMakeLists.txt | 9 | ||||
-rw-r--r-- | runtimes/libs/xray/mux/include/xray/mux.h | 62 | ||||
-rw-r--r-- | runtimes/libs/xray/mux/src/mux.cc | 34 |
3 files changed, 105 insertions, 0 deletions
diff --git a/runtimes/libs/xray/mux/CMakeLists.txt b/runtimes/libs/xray/mux/CMakeLists.txt new file mode 100644 index 000000000..e020cd877 --- /dev/null +++ b/runtimes/libs/xray/mux/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(nnfw_lib_xray_mux SHARED src/mux.cc) +set_target_properties(nnfw_lib_xray_mux PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(nnfw_lib_xray_mux PUBLIC include) +target_link_libraries(nnfw_lib_xray_mux PUBLIC nnfw_lib_xray_event) +target_link_libraries(nnfw_lib_xray_mux PUBLIC nnfw_lib_xray_pipe) +target_link_libraries(nnfw_lib_xray_mux PRIVATE nnfw_common) +target_link_libraries(nnfw_lib_xray_mux PRIVATE nnfw_coverage) + +install(TARGETS nnfw_lib_xray_mux LIBRARY DESTINATION lib) diff --git a/runtimes/libs/xray/mux/include/xray/mux.h b/runtimes/libs/xray/mux/include/xray/mux.h new file mode 100644 index 000000000..4cdfc1482 --- /dev/null +++ b/runtimes/libs/xray/mux/include/xray/mux.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2019 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 __NNFW_XRAY_MUX_H__ +#define __NNFW_XRAY_MUX_H__ + +#include <xray/event.h> + +#include <set> + +namespace xray +{ + +struct listener +{ + virtual ~listener() = default; + + virtual void notify(const event *) = 0; +}; + +class mux +{ +private: + // Use "get()" below + mux() = default; + +public: + void attach(listener *l) { _listeners.insert(l); } + void detach(listener *l) { _listeners.erase(l); } + +public: + void notify(const event *e) const + { + for (auto listener : _listeners) + { + listener->notify(e); + } + } + +private: + std::set<listener *> _listeners; + +public: + static mux &get(void); +}; + +} // namespace xray + +#endif // __NNFW_XRAY_MUX_H__ diff --git a/runtimes/libs/xray/mux/src/mux.cc b/runtimes/libs/xray/mux/src/mux.cc new file mode 100644 index 000000000..a224294dd --- /dev/null +++ b/runtimes/libs/xray/mux/src/mux.cc @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019 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 "xray/mux.h" + +#define XRAY_TRACER +#include <xray/pipe.h> +#undef XRAY_TRACER + +namespace xray +{ + +mux &mux::get(void) +{ + static mux m; + return m; +} + +void pipe::post(const event *e) { mux::get().notify(e); } + +} // namespace xray |