145 if (r->
_metadata[
"createIfMissing"].toBool())
164 QMutexLocker l(&
_lock);
167 QMapIterator<QString, crontime> i(
_crontab);
168 while (i.hasNext()) {
170 r << i.key() +
":\n"+i.value().toString();
174 return "(no events)";
209 QTime now = QTime::currentTime();
210 QTime next = QTime::currentTime();
211 next.setHMS(next.hour(),next.minute(),next.second(),0);
212 next = next.addSecs(1);
215 int w = now.msecsTo(next) - 5;
218 QTimer::singleShot(w,Qt::PreciseTimer,
this,SLOT(
startCron()));
231 QTime now = QTime::currentTime();
232 while (now.msec() != 0)
233 { QThread::usleep(1);
234 now = QTime::currentTime();
237 _cronID = startTimer(1000,Qt::PreciseTimer);
259 QDateTime now = QDateTime::currentDateTime();
260 QTime nowt = now.time();
261 QDate nowd = now.date();
262 quint8 second = nowt.second();
263 quint8 minute = nowt.minute();
264 quint8 hour = nowt.hour();
265 quint8
date = nowd.day();
266 quint8 month = nowd.month();
267 quint8 weekday = nowd.dayOfWeek() % 7;
268 quint16 year = nowd.year();
270 for( QMultiMap<QString, crontime>::iterator i =
_crontab.begin();
275 QString
event = i.key();
279 if (time.
matches(second,minute,hour,
date,month,weekday,year))
281 VFS::LOG( QString(
"%1 event: '%2' %3").arg(
className()).arg(event).arg(now.toString()), 9,
"cron" );
286 o[
"time"] = QDateTime::currentDateTime().toMSecsSinceEpoch();
302 QStringList entries = tab.split(
"|",Qt::SkipEmptyParts);
306 for (
int i=0;i<entries.length();i++)
308 QStringList e = entries[i].split(
":",Qt::SkipEmptyParts);
313 event = e[0].trimmed();
337 if (r->
_metadata[
"createIfMissing"].toBool())
339 QJsonObject o = r->
_data.object();
341 for(QJsonObject::iterator i=o.begin();
346 QString
event = i.key();
347 crontime time(i.value().toString());
395 for( QMultiMap<QString, crontime>::iterator i =
_crontab.begin();
403 r->
_data = QJsonDocument::fromVariant(o);
418 r->
_data = QJsonDocument::fromVariant(o);
456 QString c = spec.trimmed();
457 QStringList fields = c.split(QRegExp(
"\\s+"),Qt::SkipEmptyParts);
483 QStringList parts = field.split(
",",Qt::SkipEmptyParts);
485 for(
int i=0;i<parts.length();i++)
486 mask |= parseRange(parts[i]);
501 if (range.contains(
'*'))
502 return mask = 0xFFFFFFFFFFFFFFFF;
504 QStringList r = range.split(
"-",Qt::SkipEmptyParts);
509 int v = r[0].trimmed().toInt(&ok);
511 mask |= (ulong) 1 << v;
513 else if (r.length() == 2)
516 int s = r[0].trimmed().toInt(&ok1);
517 int e = r[1].trimmed().toInt(&ok2);
518 int start = qMin(s,e);
521 if (ok1 && ok2 && start>=0 && end>=0)
522 for (
int i=start;i<=end;i++)
525 {
VFS::ERROR( QString(
"%1 bad crontab range: \"%2\"").arg(
"crontime").arg(range) );
530 {
VFS::ERROR( QString(
"%1 bad crontab range: \"%2\"").arg(
"crontime").arg(range) );
550 QStringList parts = y.split(
",",Qt::SkipEmptyParts);
553 for (
int i=0;i<parts.length();i++)
555 QString part = parts[i];
556 QStringList r = part.split(
"-",Qt::SkipEmptyParts);
561 v = r[0].trimmed().toInt(&ok);
565 else if (r.length() == 2)
569 int s = r[0].trimmed().toInt(&ok1);
570 int e = r[0].trimmed().toInt(&ok2);
571 int start = qMin(s,e);
574 if (ok1 && ok2 && start>=0 && end>=0)
575 for (
int i=start; i<=end; i++)
578 {
VFS::ERROR( QString(
"%1 bad crontab range: \"%2\"").arg(
"crontime").arg(part) );
583 {
VFS::ERROR( QString(
"%1 bad crontab range: \"%2\"").arg(
"crontime").arg(part) );
618 ( _years.isEmpty() || _years.contains(y) ) &&
640 s +=
"Seconds: "+_seconds.to_string() +
"\n";
641 s +=
"Minutes: "+_minutes.to_string() +
"\n";
642 s +=
"Hours: "+_hours.to_string() +
"\n";
643 s +=
"Dates: "+_dates.to_string() +
"\n";
644 s +=
"Months: "+_months.to_string() +
"\n";
645 s +=
"Weekdays: "+_weekdays.to_string() +
"\n";
649 QString q = QString::fromStdString(s);
652 for(
int i=0; i<_years.length(); i++)
653 q += QString::number(_years[i]) + (i==_years.length()-1?
",":
"");
671 t += toCrontimeString(
"seconds") +
" ";
672 t += toCrontimeString(
"minutes") +
" ";
673 t += toCrontimeString(
"hours") +
" ";
674 t += toCrontimeString(
"dates") +
" ";
675 t += toCrontimeString(
"months") +
" ";
676 t += toCrontimeString(
"weekdays") +
" ";
677 t += toCrontimeString(
"years");
692 if (which ==
"seconds") {
if (_seconds.all())
695 for (
size_t i=0;i<_seconds.size(); i++)
696 s += QString(
"%1,").arg(i);
699 if (which ==
"minutes") {
if (_minutes.all())
702 for (
size_t i=0;i<_minutes.size(); i++)
703 s += QString(
"%1,").arg(i);
706 if (which ==
"hours") {
if (_hours.all())
709 for (
size_t i=0;i<_hours.size(); i++)
710 s += QString(
"%1,").arg(i);
713 if (which ==
"dates") {
if (_dates.all())
716 for (
size_t i=1;i<_dates.size(); i++)
717 s += QString(
"%1,").arg(i);
720 if (which ==
"months") {
if (_months.all())
723 for (
size_t i=1;i<_months.size(); i++)
724 s += QString(
"%1,").arg(i);
727 if (which ==
"weekdays"){
if (_weekdays.all())
730 for (
size_t i=0;i<_weekdays.size(); i++)
731 s += QString(
"%1,").arg(i);
734 if (which ==
"years") {
if (_years.isEmpty())
737 for (
int i=0;i<_years.size(); i++)
738 s += QString(
"%1,").arg(_years[i]);
A class to represent a crontime, which can be matched against a (current) time to see if it is active...
bool valid()
Vailidty of a VFS_cron::crontime.
std::bitset< 60 > _minutes
bitset of minutes
bool _valid
Is the crontime valid?
crontime(QString time="")
QList< quint16 > parseYear(QString y)
Parse the year component of a crontime string.
std::bitset< 7 > _weekdays
bitset of weekdays
QString toString() const
A pretty print version of a crontime.
quint64 parseRange(QString range)
Parse a range component from a crontime string.
std::bitset< 24 > _hours
bitset of hours
QList< quint16 > _years
list of years
std::bitset< 60 > _seconds
bitset of seconds
std::bitset< 32 > _dates
bitset of dates
QString toCrontime() const
Create a parseable crontime string.
bool matches(quint8 s, quint8 m, quint8 h, quint8 d, quint8 mo, quint8 w, quint16 y)
Check if a crontime matches.
QString toCrontimeString(QString which) const
Generate a crontime string component.
quint64 parseField(QString field)
VFS_cron::crontime::parseField.
std::bitset< 13 > _months
bitset of months
virtual void unsubscribe(VFS_request *r)
virtual QString reportDetails()
virtual QByteArray icon()
Return the clock icon from VFS_icons.
virtual void parseCrontab(QString tab)
virtual bool isContainer()
A VFS_cron node cannot contain children, however listing the contents will return the entry list.
virtual void subscribe(VFS_request *r)
virtual void timerEvent(QTimerEvent *event)
Scan the event map for entries that match the current time.
Q_INVOKABLE VFS_cron(QString crontab)
int _cronID
the timerID of the cron node
virtual VFS_node * find(VFS_request *r)
virtual void initialize()
Schedule a start for the scheduler.
virtual void startCron()
Start the scheduler.
virtual void read(VFS_request *r)
Read or list the event entries.
virtual void ls(VFS_request *r)
List all entries in the crontab by name.
QMultiMap< QString, crontime > _crontab
map of "event:crontime" fields
static char * get(QString which="")
Fetch an icon from the library.
VFS_node is the base class from which all other VFS_node classes derive.
virtual VFS_request * createRequest(VFS_request::requestType type, QString path, QString user="unknown", QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool dontDelete=false)
Create a new VFS_request with this object as _origin.
VFS_node * find(QString path)
Find a node by string path.
void diff(VFS_node *origin, VFS_request *t)
Emit a diff, which will trigger notifySubscribers() for a mounted node.
QString className()
Return the class name of a node.
VFS_subscriptionType _subscribers
This node's subscribers. These subscribers will receive diff notifications.
QMutex _lock
A recursive mutex that is local to this node.
virtual void unsubscribe(VFS_request *r)
Remove an entry from this node's _subscription list.
virtual void subscribe(VFS_request *r)
Add an entry to this node's _subscription list.
The base class for all requests between nodes.
@ read
read full contents (4)
@ ls
list children of a node (1)
requestType _requestType
the action this request is performing or requesting
QString _reason
if something (probably bad) happened, this is the reason
QString _path
the target path remnant... the remaining path element once the request has found its target
bool _success
if the request was successfully completed
QJsonDocument _data
the request payload
QJsonObject _metadata
the request payload
static VFS * root()
Return the root node of the VFS filesystem.
static void LOG(QString message, int level=0, QString user="server")
Send a message to the VFS::_messages VFS_stream.
static void ERROR(QString message, int level=0, QString user="server")
Send a message to the VFS::_errors VFS_stream.
The remoto date object, which has useful features not in the default javascript Date object.