WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
Zblcore.cpp
Go to the documentation of this file.
1 /*
2 * Zuble - A run-time system for QML/Javascript applications
3 * Copyright (C) 2013, 2014 Bob Dinitto
4 *
5 * Filename: Zblcore.cpp
6 * Created on: 11/9/2014
7 * Author: Bob Dinitto
8 *
9 * Zuble is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 *
23 */
24 
25 #include "Zblcore.h"
26 
27 #include <QQmlContext>
28 #include <QtQml>
29 //#include <QTemporaryFile>
30 #include "ZblApp.h"
31 #include "ZApplication.h"
32 #include "ZblThreadErr.h"
33 #include "ZScriptThread.h"
34 #include "ZxQuery.h"
35 #include "ZxResultItems.h"
36 #include "ZxItem.h"
37 #include "ZSchemaValidator.h"
38 #include "ZDir.h"
39 #include "ZFile.h"
40 #include "ZByteArray.h"
41 #include "ZTextStream.h"
42 #include "ZDataStream.h"
43 #include "ZioDevice.h"
44 #include "ZTableModel.h"
45 #include "ZblCog.h"
46 #include "ZblLogManager.h"
47 #include "ZSettings.h"
48 #include "ZFileSystemWatcher.h"
49 #include "ZLogReader.h"
50 #include "ZMessageQueue.h"
51 #include "ZMailbox.h"
52 #include "ZMailslot.h"
53 #include "ZMap.h"
54 #include "ZTableColumn.h"
55 #include "ZTableColumnList.h"
56 #include "ZLogViewport.h"
57 #include "ZLogMap.h"
58 #include "ZScopedMap.h"
59 #include "ZAndGate.h"
60 #include "zblcore_global.h"
61 #include "zglobal.h"
62 #include "ZblLogOutput.h"
63 #include "ZProcess.h"
64 
65 
66 //#include "ZblLogMessage.h"
67 //#include <QMetaType>
68 //#include <QtQml>
69 
70 
71 namespace Zbl
72 {
73 
74 ZApplication* Zblcore::m_zApp = nullptr;
75 
77 
78 Zblcore::Zblcore(QObject* parent)
79  : QQmlExtensionPlugin(parent)
80 {
81  zDebug() << "Zblcore::Zblcore";
82 
83  if(m_zApp)
84  throw ZblException(
85  "Zbl::Zblcore::Zblcore programming error: "
86  "only one instance of Zblcore class should exist per linux process!");
87 
88  qRegisterMetaType<Zbl::ZRoleRow>(); // TBD: need this?
89 
90  // qRegisterMetaType<ZScriptThread::AlertConversion>(); // TBD: need this?
91 
93 
95 
96  QString logProfilePath = ZblLogManager::createTemporaryLogProfile("~startup-profile-XXXXXX");
97 
98  loadLogModules();
99 
100  ZSettings::insertBundle("current-log-profile",
102  logProfilePath, true);
103 
104  ZblLogManager& logMan = ZblLogManager::zInit(nullptr);
105 
106 
107  m_zApp = new ZApplication(&logMan);
108 
109  m_zApp->zInit();
110 
111  logMan.setApplicationObject(m_zApp);
112 
113  //logMan.updateMessageHandlerStatus();
114 
116 
117  zDebug() << "Log Manager initialized";
118 
119  ZblCog::zInit(&logMan);
120 
121  zDebug() << "Cog initialized";
122 
123  if(!inObjectThread(qApp))
124  {
125  QThread* guiThread = qApp->thread();
126 
127  zDebug() << "Moving Zuble core objects to GUI thread.";
128 
129  logMan.moveToThread(guiThread);
130 
131  zDebug() << "Core objects move to GUI thread complete.";
132  }
133 }
134 
135 Zblcore::~Zblcore()
136 {
137  zDebug() << "Zblcore::~Zblcore";
138 }
139 
141 {
142  return m_zApp ? true : false;
143 }
144 
146  const char* uri, int versionMajor, int versionMinor)
147 {
148  zDebug() << "Zblcore::registerResource";
149 
150  if(!uri)
151  return false;
152 
153  return zCog.registerResource(uri, versionMajor, versionMinor);
154 
155 }
156 
158  const char* uri,
159  int versionMajor,
160  int versionMinor,
161  const char* fileName)
162 {
163  zDebug() << "Zblcore::mapResource";
164 
165  if(!uri || !fileName)
166  return false;
167 
168  return zCog.mapResource(uri, versionMajor, versionMinor, fileName);
169 }
170 
171 bool Zblcore::mapConfigResources(const char* configFilePath)
172 {
173  if(!configFilePath)
174  return false;
175 
176  zDebug() << "Zblcore::mapResource: " << configFilePath;
177 
178  return zCog.mapConfigResources(configFilePath);
179 }
180 
181 bool Zblcore::mapPluginResources(const char* fileName, bool qmlRegister)
182 {
183  zDebug() << "Zblcore::mapPluginResources";
184 
185  return zCog.mapPluginResources(fileName, qmlRegister);
186 }
187 
188 void Zblcore::initializeEngine(QQmlEngine * engine, const char* uri)
189 {
190  Q_UNUSED(engine)
191 
192  zDebug() << "Zblcore::initializeEngine, uri: " << uri;
193 }
194 
195 void Zblcore::registerTypes(const char* uri)
196 {
197 
198 #if 0
199  zDebug() << "Zblcore::registerTypes, uri: " << uri;
200 
201  qDebug() << "Zblcore::registerTypes thread: "
203 #endif
204 
205  // In case Zblcore constructor and registerTypes are called in different
206  // threads.
207 
209 
210  ZApplication::debugCompareThreadAddress("Zblcore::registerTypes", this);
211 
212 
213  //Q_ASSERT(uri == QLatin1String("TimeExample"));
214  //qmlRegisterType<TimeModel>(uri, 1, 0, "Time");
215 
243 
244  bool status = qmlProtectModule(uri, 1);
245 
246  if(!status)
247  qWarning("Zblcore::registerTypes - Warning: QML module %s could not "
248  "be protected.", uri);
249 }
250 
252 {
253  zDebug() << "Zblcore::mapConfigSettings";
254 
255  return ZSettings::mapConfigSettings(fileName);
256 }
257 
259 {
260  if(!m_zApp)
261  throw ZblException(
262  "Zbl::Zblcore::zInstance programming error: "
263  "embedded ZApplication object not initialized!");
264 
265  return *m_zApp;
266 }
267 
269 {
271 
272  ZblLogOutput* tmpOut = new ZblLogFormatPlainText(this);
273  modules.append(tmpOut);
274 
275  tmpOut = new ZblLogFormatPlainText(this);
276  modules.append(tmpOut);
277 
278  tmpOut = new ZblLogToHistory(this);
279  modules.append(tmpOut);
280 
281  tmpOut = new ZblLogToStdout(this);
282  modules.append(tmpOut);
283 
284  tmpOut = new ZblLogToTextFile(this);
285  modules.append(tmpOut);
286 
287  qApp->setProperty("org_zuble_logModules",
288  QVariant::fromValue<Zbl::ZblLogOutput::zLogModuleList>(modules));
289 
290 
291 }
292 
293 
294 } // Zbl
static void registerType()
Registers ZTextStream as a QML type.
static void registerType()
Registers ZioDevice as a QML type.
Definition: ZioDevice.cpp:48
static void zInit()
Initialize static variables.
Definition: ZSettings.cpp:113
static void registerType()
Registers ZAndGate as a QML type.
Definition: ZAndGate.cpp:14
static void registerType()
Registers ZLogReader as a QML type.
Definition: ZLogReader.cpp:78
static bool isInitialized()
true if the ZApplication object has completed initialization, false otherwise
Definition: Zblcore.cpp:140
static void registerType()
Registers ZSettings as a QML type.
Definition: ZSettings.cpp:82
static void registerType()
Registers ZByteArray as a QML type.
Definition: ZByteArray.cpp:54
static void debugCompareThreadAddress(const char *label, QObject *obj)
Sends both current thread address and object&#39;s thread address to qDebug.
void loadLogModules()
Definition: Zblcore.cpp:268
static ZblLogManager & zInit(QObject *parent)
Construct, initialize and obtain a reference to Zuble&#39;s log manager object.
static void registerType()
Registers ZTableColumnList as a QML type.
static void registerType()
Registers ZScriptThread as a QML type.
static void registerType()
Registers ZxItem as a QML type.
Definition: ZxItem.cpp:40
#define zCog
Definition: ZblCog.h:34
static void registerType()
Definition: ZMailslot.cpp:45
#define ZBL_REGISTER_LOGGED_OBJECT
Definition: zglobal.h:104
static void registerType()
Registers ZFile as a QML type.
Definition: ZFile.cpp:76
static void registerType()
Registers ZxResultItems as a QML type. TBD: should we do this?
static ZApplication * m_zApp
Definition: Zblcore.h:204
static bool mapConfigSettings(const char *configFilePath)
Definition: ZSettings.cpp:770
static void registerType()
Registers ZFile as a QML type.
Definition: ZProcess.cpp:40
The core Zuble QML Extension plugin class.
Definition: Zblcore.h:78
Definition: ZAndGate.cpp:6
static void registerType()
Registers ZLogMap as a QML type.
Definition: ZLogMap.cpp:32
static int versionMinor
Definition: main.cpp:60
Abstract base class for Zuble log output modules.
Definition: ZblLogOutput.h:54
static void zInit()
This method must be called once at the start of each thread that throws or catches ZblException objec...
static void registerType()
Registers ZTableModel as a QML type.
Definition: ZTableModel.cpp:52
#define ZBL_DEFINE_LOGGED_OBJECT(class_name)
Definition: zglobal.h:99
virtual bool mapPluginResources(const char *fileName, bool qmlRegister)
Read binary resource file information from the specified Zuble sprocket plugin.
Definition: Zblcore.cpp:181
static void registerType()
Registers ZFileSystemWatcher as a QML type.
static int versionMajor
Definition: main.cpp:59
static int registerType()
Registers this object with the QML type system.
static void registerType()
Registers ZTableColumn as a QML type.
static void registerType()
Registers ZDataStream as a QML type.
#define zDebug()
Definition: zglobal.h:113
virtual bool registerResource(const char *uri, int versionMajor, int versionMinor)
Registers a binary resource with QML. This makes a resource available to QML documents.
Definition: Zblcore.cpp:145
virtual bool mapConfigResources(const char *configFilePath)
Read binary resource file information from the specified Zuble application configuration file (zblcon...
Definition: Zblcore.cpp:171
static QString getObjectThreadAddress(QObject *object)
Returns the human-readable memory address of the specified object&#39;s thread.
static int registerSingletonType()
Registers this object with QML as a singleton type.
Definition: ZblApp.cpp:174
static QString createTemporaryLogProfile(const QString &nameTemplate, bool remove=false)
Creates an empty file with a unique file name in the log profile directory.
bool inObjectThread(const QObject &object)
Definition: zglobal.h:173
static void registerType()
Register ZMailbox as a QML type.
Definition: ZMailbox.cpp:38
Zuble&#39;s Singleton Application Object.
Definition: ZApplication.h:54
static ZApplication & zApplication()
Return a reference to the encapsulated singleton ZApplication object.
Definition: Zblcore.cpp:258
static void registerType()
Registers ZDir as a QML type.
Definition: ZDir.cpp:65
static void registerType()
Registers ZxQuery as a QML type.
Definition: ZxQuery.cpp:252
Zuble&#39;s Qt Exception Object.
Definition: ZblException.h:45
static QString getLogSettingsMetadata()
Returns an xml data structure that defines the zuble application&#39;s log settings.
virtual bool mapConfigSettings(const char *fileName)
Load QML settings bundles from the specified Zuble application configuration file (zblconfig...
Definition: Zblcore.cpp:251
virtual bool mapResource(const char *uri, int versionMajor, int versionMinor, const char *fileName)
Binds a resource uri to a resource file. See ZblCog for more information.
Definition: Zblcore.cpp:157
static void registerType()
Registers ZMessageQueue as a QML type.
QList< ZblLogOutput * > zLogModuleList
Definition: ZblLogOutput.h:60
virtual void initializeEngine(QQmlEngine *engine, const char *uri)
This override of QQmlExtensionPlugin is currently unused and may be deprecated.
Definition: Zblcore.cpp:188
static void registerType()
Registers ZLogViewport as a QML type.
static bool insertBundle(const QString &id, const QString &metaPath, QSettings::Scope scope=QSettings::UserScope, const QString organization=QString(), const QString application=QString())
Adds the specified settings bundle to the settings repository.
Definition: ZSettings.cpp:530
virtual void registerTypes(const char *uri)
Override of QQmlExtensionPlugin is called by the QML engine to register the Zuble core plugin&#39;s QML t...
Definition: Zblcore.cpp:195
static void registerType()
Register ZMailbox as a QML type.
Definition: ZScopedMap.cpp:39
static void registerType()
Register ZMailbox as a QML type.
Definition: ZMap.cpp:36
static ZblCog & zInit(QObject *parent)
Definition: ZblCog.cpp:904