Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class eventBase {
- public:
- using eventHandler_t = std::function<void()>; /* для примера указал такой тип */
- eventBase();
- virtual ~eventBase();
- void setHandler(eventHandler_t h);
- void lockHandler();
- void unlockHandler();
- bool handlerLocked() const;
- bool update() { /* do something */ return this->run(); };
- int id() const;
- protected:
- void runHandler(); /* call python function in python space */
- private:
- eventHandler_t handler; /* pointer to python function */
- bool handlerLock = false;
- virtual bool run() = 0; /* event function */
- int _id = 0;
- };
- class eventChanged : public eventBase {
- public:
- eventChanged(qc::Channel* ch);
- virtual ~eventChanged();
- private:
- qc::Channel* _channel;
- virtual bool run() override; /* true if value of channel has changed */
- };
- class eventPython : public eventBase {
- public:
- using eventPythonFunc_t = std::function<bool()>; /* тоже для примера */
- eventPython();
- eventPython(eventPythonFunc_t);
- virtual ~eventPython();
- void setFunc(eventPythonFunc_t f) { evFunc = f; }
- private:
- eventPythonFunc_t evFunc;
- virtual bool run() override; /* run python event function, return true if event ocurred */
- };
- /* events collection. */
- class eventsFld {
- public:
- friend eventBase;
- static void update() { for (auto ev : events) ev->update(); }
- static auto size() { return events.size(); }
- private:
- static std::list<eventBase*> events;
- static int lastid;
- static int add(eventBase*); /* use in eventBase::eventBase() */
- static bool remove(eventBase*); /* use in eventBase::~eventBase() */
- };
- class scenario {
- public:
- scenario(const std::string& );
- void init() {
- try {
- /* run pyInit(): */
- /* make new events and bind handlers */
- } catch (...) {
- }
- }
- private:
- std::string pyScript;
- };
- /* далее создаем сценарий */
- /* нинциализируем его */
- /* а в рабочем цикле вызываем eventsFld::update() - обновляем все события */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement