Torc  0.1
torclocalcontext.h
Go to the documentation of this file.
1 #ifndef TORCLOCALCONTEXT_H
2 #define TORCLOCALCONTEXT_H
3 
4 // Qt
5 #include <QObject>
6 #include <QString>
7 #include <QReadWriteLock>
8 #include <QMutex>
9 
10 // Torc
11 #include "torclocaldefs.h"
12 #include "torcsetting.h"
13 #include "torcobservable.h"
14 #include "torcsqlitedb.h"
15 #include "torcadminthread.h"
16 #include "torccommandline.h"
17 
18 #ifdef Q_OS_LINUX
19 #include <unistd.h>
20 #endif
21 
22 class TorcAdminObject;
23 class TorcLanguage;
24 
25 class Torc
26 {
27  Q_GADGET
28 
29  public:
30  enum Actions
31  {
32  None = 0,
37  TorcWillStop, // or restart etc
38  // Power management
39  Shutdown = 1000,
49  // these are issued directly to the power object
50  // when a delayed event is issued
55  // network
60  // service discovery
63  // system time
65  // end of predefined
66  MaxTorc = 60000,
67  // plugins etc
68  MaxUser = 65535
69  };
70 
71  Q_ENUM(Actions)
72 };
73 
74 class TorcLocalContext : public QObject, public TorcObservable
75 {
76  Q_OBJECT
77 
78  public:
79  static qint16 Create (TorcCommandLine* CommandLine, bool Init = true);
80  static void TearDown (void);
81 
82  static void NotifyEvent (int Event);
83  QString GetSetting (const QString &Name, const QString &DefaultValue);
84  bool GetSetting (const QString &Name, bool DefaultValue);
85  int GetSetting (const QString &Name, int DefaultValue);
86  void SetSetting (const QString &Name, const QString &Value);
87  void SetSetting (const QString &Name, bool Value);
88  void SetSetting (const QString &Name, int Value);
89  QString GetUuid (void) const;
90  TorcSetting* GetRootSetting (void);
91  qint64 GetStartTime (void);
92  int GetPriority (void);
93 
94  QLocale GetLocale (void);
95  TorcLanguage* GetLanguage (void);
96  void CloseDatabaseConnections (void);
97  bool QueueShutdownEvent (int Event);
98  void SetShutdownDelay (uint Delay);
99  uint GetShutdownDelay (void);
100 
101  public slots:
102  void RegisterQThread (void);
103  void DeregisterQThread (void);
104  bool event (QEvent *Event) override;
105  void ShutdownTimeout (void);
106 
107  private:
108  explicit TorcLocalContext(TorcCommandLine* CommandLine);
109  ~TorcLocalContext();
110  Q_DISABLE_COPY(TorcLocalContext)
111 
112  bool Init (void);
113  QString GetDBSetting (const QString &Name, const QString &DefaultValue);
114  void SetDBSetting (const QString &Name, const QString &Value);
115  bool HandleShutdown (int Event);
116 
117  private:
118  TorcSQLiteDB *m_sqliteDB;
119  QString m_dbName;
120  QMap<QString,QString> m_localSettings;
121  QReadWriteLock m_localSettingsLock;
122  TorcAdminThread *m_adminThread;
123  TorcLanguage *m_language;
124  QString m_uuid;
125  uint m_shutdownDelay;
126  int m_shutdownEvent;
127  qint64 m_startTime;
128  TorcSetting *m_rootSetting;
129 };
130 
132 
133 #endif // TORCLOCALCONTEXT_H
A simple thread to launch helper objects outside of the main loop.
TorcLocalContext * gLocalContext
TorcLocalContext is the core Torc object.
A wrapper around a database setting.
Definition: torcsetting.h:15
A factory class for automatically running objects outside of the main loop.
Torc command line handler.
A class to track and manage language and locale settings and available translations.
Definition: torclanguage.h:17
TorcObservable will send event notifcations to registered &#39;listeners&#39;.
SQLite implementation of TorcDB.
Definition: torcsqlitedb.h:6