Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 4 files changed
  • 2 commit comments
  • 1 contributor
Commits on Mar 12, 2014
@beanpole135 beanpole135 Add a new file/classes to libpcbsd - utils.
1) SystemFlags : public enumeration of different flag types, and a static function to set a particular system flag (SystemFlags::setFlat(SYSFLAG, QString contents) )
2) SystemFlagWatcher : Class that can be used in Qt utilites for alerting when a new system flag is available (as well as a public function to look for new flags within the last X minutes - for when a utility just started up)

Still needs testing in an actual utility.
One known restriction: setFlag() needs to be run by a root-permissions utility after computer startup before non-root utilities can successfully set flags. This is because the /tmp/pcbsdflags dir needs to be initially created first with 666 permissions.
cab198c
@beanpole135 beanpole135 Merge branch 'master' of github.com:pcbsd/pcbsd 535e584
View
0  src-qt4/libpcbsd/utils/moc_pcbsd-utils.cpp
No changes.
View
58 src-qt4/libpcbsd/utils/pcbsd-sysFlags.cpp
@@ -0,0 +1,58 @@
+#include "pcbsd-sysFlags.h"
+
+SystemFlagWatcher::SystemFlagWatcher(){
+ CDT = QDateTime::currentDateTime();
+ watcher = new QFileSystemWatcher(this);
+ connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(watcherNotification()) );
+ connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(watcherNotification()) );
+ QTimer::singleShot(1, this, SLOT(watchFlagDir()) );
+}
+
+SystemFlagWatcher::~SystemFlagWatcher(){
+
+}
+
+//========
+// PUBLIC
+//========
+void SystemFlagWatcher::checkForRecent(int minutes){
+ CDT = QDateTime::currentDateTime();
+ CDT = CDT.addMSecs( -(minutes*60000) );
+ watcherNotification(); //Now manually check for flags since then
+}
+
+//=========
+// PRIVATE
+//=========
+void SystemFlagWatcher::watchFlagDir(){
+ watcher->addPath(FLAGDIR);
+ //Now manually run the detection routine
+ watcherNotification();
+ //Now check that the directory is being watched
+ if(watcher->directories().isEmpty()){
+ //flag dir does not exist yet, try again in 2 minutes
+ QTimer::singleShot(120000, this, SLOT(watchFlagDir()) );
+ }
+}
+
+void SystemFlagWatcher::watcherNotification(){
+ //Does not specify the contents of a flag just yet - KenMoore 3/12/14
+ QDir dir(FLAGDIR);
+ if(!dir.exists()){ return; } //flag directory does not exist yet - do nothing
+ QFileInfoList flags = dir.entryInfoList( QDir::Files | QDir::NoDotAndDotDot, QDir::Time);
+ for(int i=0; i<flags.length(); i++){
+ if(CDT < flags[i].lastModified()){
+ //New flag - check which one and emit the proper signal
+ if(flags[i].fileName() == NETWORKRESTARTED){
+ emit FlagChanged(SystemFlags::NetRestart, "");
+ }else if(flags[i].fileName() == PKGUPDATEAVAILABLE){
+ emit FlagChanged(SystemFlags::PkgUpdate, "");
+ }else if(flags[i].fileName() == SYSUPDATEAVAILABLE){
+ emit FlagChanged(SystemFlags::SysUpdate, "");
+ }else if(flags[i].fileName() == PBIUPDATEAVAILABLE){
+ emit FlagChanged(SystemFlags::PbiUpdate, "");
+ }
+ }
+ }
+ CDT = QDateTime::currentDateTime(); //Now update the last time flags were checked
+}
View
77 src-qt4/libpcbsd/utils/pcbsd-sysFlags.h
@@ -0,0 +1,77 @@
+#ifndef _PCBSD_SYSTEM_FLAGS_H
+#define _PCBSD_SYSTEM_FLAGS_H
+
+#include <QObject>
+#include <QFileSystemWatcher>
+#include <QString>
+#include <QDateTime>
+#include <QFileInfo>
+#include <QFile>
+#include <QDir>
+#include <QTimer>
+
+#include "pcbsd-utils.h"
+
+// DEFINE THE FLAG FILES
+#define FLAGDIR QString("/tmp/pcbsdflags")
+#define NETWORKRESTARTED QString("network-restarted")
+#define PKGUPDATEAVAILABLE QString("pkg-update-available")
+#define SYSUPDATEAVAILABLE QString("sys-update-available")
+#define PBIUPDATEAVAILABLE QString("pbi-update-available")
+
+class SystemFlags{
+public:
+ enum SYSFLAG{ NetRestart, PkgUpdate, SysUpdate, PbiUpdate};
+
+ static void setFlag( SYSFLAG flag, QString contents = ""){
+ if(!QFile::exists(FLAGDIR)){
+ pcbsd::Utils::runShellCommand("mkdir -p -m 666 "+FLAGDIR);
+ if( !QFile::exists(FLAGDIR) ){ return; }
+ }
+ QString cmd;
+ if(contents.isEmpty()){ cmd = "touch %1"; }
+ else{ cmd = "echo '%2' > %1"; cmd = cmd.arg("%1", contents); }
+ //Now get the flag type
+ cmd = cmd.arg(FLAGDIR+"/");
+ switch(flag){
+ case NetRestart:
+ cmd = cmd.arg(NETWORKRESTARTED);
+ break;
+ case PkgUpdate:
+ cmd = cmd.arg(PKGUPDATEAVAILABLE);
+ break;
+ case SysUpdate:
+ cmd = cmd.arg(SYSUPDATEAVAILABLE);
+ break;
+ case PbiUpdate:
+ cmd = cmd.arg(PBIUPDATEAVAILABLE);
+ break;
+ default:
+ return;
+ }
+ pcbsd::Utils::runShellCommand(cmd);
+ }
+
+};
+
+class SystemFlagWatcher : public QObject{
+ Q_OBJECT
+public:
+ SystemFlagWatcher();
+ ~SystemFlagWatcher();
+
+ void checkForRecent(int minutes);
+
+private:
+ QDateTime CDT; //current date time
+ QFileSystemWatcher *watcher;
+
+private slots:
+ void watchFlagDir();
+ void watcherNotification();
+
+signals:
+ void FlagChanged(SystemFlags::SYSFLAG, QString);
+};
+
+#endif
View
6 src-qt4/libpcbsd/utils/utils.pro
@@ -13,12 +13,14 @@ VERSION = 0.9.8
HEADERS += pcbsd-netif.h \
pcbsd-utils.h \
pcbsd-hardware.h \
- pcbsd-DLProcess.h
+ pcbsd-DLProcess.h \
+ pcbsd-sysFlags.h
SOURCES += utils.cpp \
hardware.cpp \
netif.cpp \
- pcbsd-DLProcess.cpp
+ pcbsd-DLProcess.cpp \
+ pcbsd-sysFlags.cpp
include.path=/usr/local/include/
include.files=pcbsd-*.h

Showing you all comments on commits in this comparison.

@kmoore134
Owner

Does this .h file get installed to the system include dir? Did you forget to update pkg-plist?

@beanpole135
Collaborator

Thanks for the reminder - I just added it to the pkg-plist too... :-)

Something went wrong with that request. Please try again.