Add extra line about src files are part of RIC platform project
[ric-plt/sdl.git] / include / private / engineimpl.hpp
1 /*
2    Copyright (c) 2018-2019 Nokia.
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 */
16
17 /*
18  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19  * platform project (RICP).
20 */
21
22 #ifndef SHAREDDATALAYER_ENGINEIMPL_HPP_
23 #define SHAREDDATALAYER_ENGINEIMPL_HPP_
24
25 #include <map>
26 #include <memory>
27 #include <vector>
28 #include <sys/epoll.h>
29 #include "private/engine.hpp"
30 #include "private/filedescriptor.hpp"
31
32 namespace shareddatalayer
33 {
34     class TimerFD;
35     class EventFD;
36     class System;
37
38     class EngineImpl: public Engine
39     {
40     public:
41         EngineImpl();
42
43         explicit EngineImpl(System& system);
44
45         ~EngineImpl();
46
47         int fd() const override { return epollFD; }
48
49         void handleEvents() override;
50
51         void addMonitoredFD(int fd, unsigned int events, const EventHandler& eh) override;
52
53         void addMonitoredFD(FileDescriptor& fd, unsigned int events, const EventHandler& eh) override;
54
55         void modifyMonitoredFD(int fd, unsigned int events) override;
56
57         void deleteMonitoredFD(int fd) override;
58
59         void postCallback(const Callback& callback) override;
60
61         void run() override;
62
63         void stop() override;
64
65     protected:
66         void armTimer(Timer& timer, const Timer::Duration& duration, const Timer::Callback& cb) override;
67
68         void disarmTimer(const Timer& timer) override;
69
70     private:
71         TimerFD& getTimerFD();
72
73         EventFD& getEventFD();
74
75         void epollWait(int timeout);
76
77         void callHandler(const epoll_event& e);
78
79         System& system;
80         bool stopped;
81         FileDescriptor epollFD;
82         std::map<int, EventHandler> handlers;
83         std::vector<epoll_event> ebuffer;
84         std::unique_ptr<TimerFD> timerFD;
85         std::unique_ptr<EventFD> eventFD;
86     };
87 }
88
89 #endif