Compare commits
3 Commits
mqtt_clien
...
6efe77a395
| Author | SHA1 | Date | |
|---|---|---|---|
| 6efe77a395 | |||
| 6cfc4524f0 | |||
| 2798d7de9c |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,5 @@
|
|||||||
/src_main/piversion.h
|
/src_main/piversion.h
|
||||||
/.svn
|
/.*
|
||||||
/doc/rtf
|
/doc/rtf
|
||||||
_unsused
|
_unsused
|
||||||
CMakeLists.txt.user*
|
CMakeLists.txt.user*
|
||||||
|
|||||||
@@ -122,13 +122,13 @@ PITimer::PITimer(): PIObject() {
|
|||||||
|
|
||||||
PITimer::PITimer(std::function<void(int)> func) {
|
PITimer::PITimer(std::function<void(int)> func) {
|
||||||
initFirst();
|
initFirst();
|
||||||
ret_func = func;
|
ret_func_delim = std::move(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PITimer::PITimer(std::function<void()> func) {
|
PITimer::PITimer(std::function<void()> func) {
|
||||||
initFirst();
|
initFirst();
|
||||||
ret_func = [func](int) { func(); };
|
ret_func = std::move(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -224,7 +224,8 @@ void PITimer::adjustTimes() {
|
|||||||
void PITimer::execTick() {
|
void PITimer::execTick() {
|
||||||
if (!isRunning()) return;
|
if (!isRunning()) return;
|
||||||
if (lockRun) lock();
|
if (lockRun) lock();
|
||||||
if (ret_func) ret_func(1);
|
if (ret_func) ret_func();
|
||||||
|
if (ret_func_delim) ret_func_delim(1);
|
||||||
tick(1);
|
tick(1);
|
||||||
tickEvent(1);
|
tickEvent(1);
|
||||||
if (callEvents) maybeCallQueuedEvents();
|
if (callEvents) maybeCallQueuedEvents();
|
||||||
@@ -233,8 +234,8 @@ void PITimer::execTick() {
|
|||||||
i.tick = 0;
|
i.tick = 0;
|
||||||
if (i.func)
|
if (i.func)
|
||||||
i.func(i.delim);
|
i.func(i.delim);
|
||||||
else if (ret_func)
|
else if (ret_func_delim)
|
||||||
ret_func(i.delim);
|
ret_func_delim(i.delim);
|
||||||
tick(i.delim);
|
tick(i.delim);
|
||||||
tickEvent(i.delim);
|
tickEvent(i.delim);
|
||||||
}
|
}
|
||||||
@@ -262,7 +263,7 @@ bool PITimer::start(PISystemTime interval) {
|
|||||||
bool PITimer::start(PISystemTime interval, std::function<void()> func) {
|
bool PITimer::start(PISystemTime interval, std::function<void()> func) {
|
||||||
if (isRunning()) stopAndWait();
|
if (isRunning()) stopAndWait();
|
||||||
setInterval(interval);
|
setInterval(interval);
|
||||||
setSlot(func);
|
setSlot(std::move(func));
|
||||||
return start();
|
return start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,7 +275,7 @@ void PITimer::stopAndWait(PISystemTime timeout) {
|
|||||||
|
|
||||||
|
|
||||||
void PITimer::addDelimiter(int delim, std::function<void(int)> func) {
|
void PITimer::addDelimiter(int delim, std::function<void(int)> func) {
|
||||||
delims << Delimiter(func, delim);
|
delims << Delimiter(std::move(func), delim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -127,12 +127,16 @@ public:
|
|||||||
//! \~english Sets a tick callback that ignores the delimiter value.
|
//! \~english Sets a tick callback that ignores the delimiter value.
|
||||||
//! \~russian Устанавливает обратный вызов тика, игнорирующий значение делителя.
|
//! \~russian Устанавливает обратный вызов тика, игнорирующий значение делителя.
|
||||||
void setSlot(std::function<void()> func) {
|
void setSlot(std::function<void()> func) {
|
||||||
ret_func = [func](int) { func(); };
|
ret_func_delim = nullptr;
|
||||||
|
ret_func = std::move(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~english Sets a tick callback that receives the current delimiter value.
|
//! \~english Sets a tick callback that receives the current delimiter value.
|
||||||
//! \~russian Устанавливает обратный вызов тика, принимающий текущее значение делителя.
|
//! \~russian Устанавливает обратный вызов тика, принимающий текущее значение делителя.
|
||||||
void setSlot(std::function<void(int)> func) { ret_func = func; }
|
void setSlot(std::function<void(int)> func) {
|
||||||
|
ret_func = nullptr;
|
||||||
|
ret_func_delim = std::move(func);
|
||||||
|
}
|
||||||
|
|
||||||
//! \~english Enables locking of the internal mutex around tick processing.
|
//! \~english Enables locking of the internal mutex around tick processing.
|
||||||
//! \~russian Включает блокировку внутреннего мьютекса вокруг обработки тиков.
|
//! \~russian Включает блокировку внутреннего мьютекса вокруг обработки тиков.
|
||||||
@@ -141,7 +145,8 @@ public:
|
|||||||
EVENT_HANDLER0(void, unlock) { mutex_.unlock(); }
|
EVENT_HANDLER0(void, unlock) { mutex_.unlock(); }
|
||||||
|
|
||||||
//! \~english Returns whether the timer drains queued delivery for itself as performer on each main tick. By default \b true.
|
//! \~english Returns whether the timer drains queued delivery for itself as performer on each main tick. By default \b true.
|
||||||
//! \~russian Возвращает, должен ли таймер обрабатывать отложенную доставку для себя как исполнителя на каждом основном тике. По умолчанию \b true.
|
//! \~russian Возвращает, должен ли таймер обрабатывать отложенную доставку для себя как исполнителя на каждом основном тике. По
|
||||||
|
//! умолчанию \b true.
|
||||||
bool isCallQueuedEvents() const { return callEvents; }
|
bool isCallQueuedEvents() const { return callEvents; }
|
||||||
|
|
||||||
//! \~english Enables or disables queued-delivery draining through \a maybeCallQueuedEvents() on each main tick.
|
//! \~english Enables or disables queued-delivery draining through \a maybeCallQueuedEvents() on each main tick.
|
||||||
@@ -221,7 +226,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
struct PIP_EXPORT Delimiter {
|
struct PIP_EXPORT Delimiter {
|
||||||
Delimiter(std::function<void(int)> func_ = nullptr, int delim_ = 1) {
|
Delimiter(std::function<void(int)> func_ = nullptr, int delim_ = 1) {
|
||||||
func = func_;
|
func = std::move(func_);
|
||||||
delim = delim_;
|
delim = delim_;
|
||||||
}
|
}
|
||||||
std::function<void(int)> func;
|
std::function<void(int)> func;
|
||||||
@@ -245,7 +250,8 @@ protected:
|
|||||||
PIMutex mutex_;
|
PIMutex mutex_;
|
||||||
PISystemTime m_interval, m_interval_x5;
|
PISystemTime m_interval, m_interval_x5;
|
||||||
PISystemTime m_time_next;
|
PISystemTime m_time_next;
|
||||||
std::function<void(int)> ret_func = nullptr;
|
std::function<void()> ret_func = nullptr;
|
||||||
|
std::function<void(int)> ret_func_delim = nullptr;
|
||||||
PIVector<Delimiter> delims;
|
PIVector<Delimiter> delims;
|
||||||
PIConditionVariable event;
|
PIConditionVariable event;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user