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
ZblCog.h
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2014 Bob Dinitto
4  *
5  * Filename: ZblCog.h
6  * Created on: 12/10/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 #ifndef ZBLCOG_H
26 #define ZBLCOG_H
27 
28 #include <QObject>
29 #include <QReadWriteLock>
30 #include <qqml.h>
31 #include "ZblPlugin.h"
32 #include "ZblLogManager.h"
33 
34 #define zCog (Zbl::ZblCog::zInstance())
35 
36 #define zblRegisterType(uri, versionMajor, versionMinor, qmlName, typeName, createFunc) \
37  qmlRegisterType<typeName>(uri, versionMajor, versionMinor, qmlName); \
38  zCog.registerSprocketObject(uri, versionMajor, versionMinor, qmlName, createFunc); \
39 
40 
41 class QXmlQuery;
42 class QXmlItem;
43 
44 namespace Zbl
45 {
46 
47 class ZblSprocket;
48 class ZblFactory;
49 
110 class ZblCog : public QObject
111 {
112  //friend class ZblFactory;
113 
114  Q_OBJECT
115 
116 public:
117  explicit ZblCog(QObject *parent = 0);
118  virtual ~ZblCog();
119 
120  static ZblCog& zInit(QObject* parent);
121 
138  bool registerSprocket(const char* uri,
139  int versionMajor,
140  int versionMinor);
141 
163  const char* uri,
164  int versionMajor,
165  int versionMinor,
166  const char* qmlName,
167  sprocketObjectConstructor createFunc);
168 
169 
191  const char* sprocketUri,
192  int versionMajor,
193  int versionMinor,
194  QObject* parent = NULL);
195 
196 
197 
228  bool mapResource(
229  const char* uri,
230  int versionMajor,
231  int versionMinor,
232  const char* fileName);
233 
266  bool mapPluginResources(const char* fileName, bool qmlRegister = false);
267 
275  bool mapConfigResources(const char* configFilePath);
276 
288  bool isMappedResource(
289  const char* uri,
290  int versionMajor,
291  int versionMinor);
292 
299  QStringList getMappedResources();
300 
326  bool registerResource(
327  const char* uri, int versionMajor, int versionMinor);
328 
329 
330 
337  static ZblCog& zInstance();
338 
339 
340 signals:
341 
342 public slots:
343 
344 protected:
345 
346  QString getNodeName(const QXmlItem& item, const QXmlQuery& query);
347 
352 
353  commandFieldCount // must be last
354  };
355 
356  enum paramFile {
357  fileUri = 1,
360  fileName
361  };
362 
363  enum paramPlugin {
365  };
366 
367 #if 0
368 
377  const ZblSprockOb* findSprock(
378  const char* uri,
379  int versionMajor,
380  int versionMinor,
381  const char* qmlName) const;
382 #endif
383 
385  const QString& label, const QString& command);
386 
388  const QString& label, const QString& reason);
389 
390  bool validateParamCount(int actual, int required);
391 
392  bool getPluginResParams(const QJsonValue& resourceValue,
393  QString& uri,
394  QString& fileName,
395  QString& versionMajor,
396  QString& versionMinor);
397 
398  bool getPluginStringParam(const QJsonObject& resource,
399  const QString& paramKey,
400  QString& outValue);
401 
402  static const QString m_commandSeparator;
403  static const QString m_actionMap;
404  static const QString m_actionQmlregister;
405  static const QString m_actionIgnore;
406  static const QString m_restypeFile;
407  static const QString m_restypePlugin;
408  static const QString m_restypeInvalid;
409 
410  static const int m_paramcountFile;
411  static const int m_paramcountPlugin;
412 
413 
419 
425 
430  QReadWriteLock m_lock;
431 
432 private:
433 
434 
440  static ZblCog* m_zCog;
441 
442 
443 
445 };
446 
447 } // Zbl
448 
449 #endif // ZBLCOG_H
bool registerResource(const char *uri, int versionMajor, int versionMinor)
Makes a Zuble resource file available to QML and background javascript programs.
Definition: ZblCog.cpp:794
virtual ~ZblCog()
Definition: ZblCog.cpp:75
ZblFactory * createFactory(const char *sprocketUri, int versionMajor, int versionMinor, QObject *parent=NULL)
Constructs a ZblFactory object and populates it with a set of version-specific Sprocket object constr...
Definition: ZblCog.cpp:163
static ZblCog * m_zCog
The one and only ZblCog object allowed to exist in this process.
Definition: ZblCog.h:440
QMap< QString, ZblSprocket * > sprocketPluginMap
Map Zuble Sprocket uri&#39;s to Sprocket plugin objects.
Definition: ZblPlugin.h:51
static const int m_paramcountPlugin
Definition: ZblCog.h:411
#define ZBL_DECLARE_LOGGED_OBJECT
Definition: zglobal.h:94
bool mapPluginResources(const char *fileName, bool qmlRegister=false)
Make a plugin&#39;s binary resource files known to Zuble so they can be loaded into QML by calling Zbl...
Definition: ZblCog.cpp:278
bool getPluginStringParam(const QJsonObject &resource, const QString &paramKey, QString &outValue)
Definition: ZblCog.cpp:440
bool isMappedResource(const char *uri, int versionMajor, int versionMinor)
Determine whether a resource is mapped.
Definition: ZblCog.cpp:849
bool getPluginResParams(const QJsonValue &resourceValue, QString &uri, QString &fileName, QString &versionMajor, QString &versionMinor)
Definition: ZblCog.cpp:412
bool mapConfigResources(const char *configFilePath)
Reads specified zblconfig.xml file and maps/loads resources accordingly.
Definition: ZblCog.cpp:457
sprocketPluginMap m_sprockets
Maps Sprocket plugin uri&#39;s to sprocket objects.
Definition: ZblCog.h:418
static ZblCog & zInstance()
zInstance
Definition: ZblCog.cpp:919
void warnAbortingResourceLoad(const QString &label, const QString &reason)
Definition: ZblCog.cpp:764
static const QString m_restypeInvalid
Definition: ZblCog.h:408
static const QString m_commandSeparator
Definition: ZblCog.h:402
resourceMap m_resources
Maps Resource plugin uri&#39;s to resource objects.
Definition: ZblCog.h:424
Definition: ZAndGate.cpp:6
static const QString m_actionMap
Definition: ZblCog.h:403
static int versionMinor
Definition: main.cpp:60
static int versionMajor
Definition: main.cpp:59
QString getNodeName(const QXmlItem &item, const QXmlQuery &query)
Definition: ZblCog.cpp:773
static const QString m_actionIgnore
Definition: ZblCog.h:405
bool validateParamCount(int actual, int required)
Definition: ZblCog.cpp:738
bool registerSprocketObject(const char *uri, int versionMajor, int versionMinor, const char *qmlName, sprocketObjectConstructor createFunc)
Called by Zuble sprocket extension plugins to register their object constructors with Zuble so their ...
Definition: ZblCog.cpp:139
static const QString m_restypePlugin
Definition: ZblCog.h:407
static const QString m_restypeFile
Definition: ZblCog.h:406
void warnInvalidResourceCommand(const QString &label, const QString &command)
Definition: ZblCog.cpp:751
Maintains a map of Zuble Sprockets and creates Sprocket object factories for javascript background th...
Definition: ZblCog.h:110
bool mapResource(const char *uri, int versionMajor, int versionMinor, const char *fileName)
Binds a resource uri with it&#39;s associated binary resource file. The resource can subsequently be refe...
Definition: ZblCog.cpp:212
An object factory that creates new instances of objects defined by a Zuble sprocket. Used primarily to construct sprocket objects in Zuble background threads.
Definition: ZblFactory.h:54
QObject *(* sprocketObjectConstructor)(QObject *parent)
A pointer to a function that creates a Zuble Sprocket object. Sprocket object constructor functions s...
Definition: ZblPlugin.h:45
This class acts as an object construction wrapper for objects defined in Zuble Sprocket plugins...
Definition: ZblSprockOb.h:42
QReadWriteLock m_lock
ZblCog&#39;s multithreaded lock.
Definition: ZblCog.h:430
static const QString m_actionQmlregister
Definition: ZblCog.h:404
ZblCog(QObject *parent=0)
Definition: ZblCog.cpp:62
QStringList getMappedResources()
Returns the list of mapped resource keys in the form of uri:versionMajor:versionMinor, ie: &#39;org.zuble.qml:1:0&#39;.
Definition: ZblCog.cpp:896
QMap< QString, ZblResource * > resourceMap
Maps resource uri&#39;s to Zuble resource objects.
Definition: ZblPlugin.h:84
bool registerSprocket(const char *uri, int versionMajor, int versionMinor)
Called by Zuble sprocket extension plugins to register themselves with Zuble so their objects can be ...
Definition: ZblCog.cpp:92
static const int m_paramcountFile
Definition: ZblCog.h:410
static ZblCog & zInit(QObject *parent)
Definition: ZblCog.cpp:904