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.cpp
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.cpp
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 #include "ZblCog.h"
26 #include "ZblSprocket.h"
27 #include "ZblException.h"
28 #include "ZblFactory.h"
29 #include "ZblResource.h"
30 #include "zglobal.h"
31 #include <QDebug>
32 #include <QXmlQuery>
33 #include <QXmlResultItems>
34 #include <QXmlItem>
35 #include <QFile>
36 #include <QPluginLoader>
37 #include <QJsonDocument>
38 #include <QJsonObject>
39 #include <QJsonArray>
40 
41 
42 //#include <QResource>
43 
44 namespace Zbl
45 {
46 
47 ZblCog* ZblCog::m_zCog = 0;
48 
50 
51 const QString ZblCog::m_commandSeparator = "::";
52 const QString ZblCog::m_actionMap = "map";
53 const QString ZblCog::m_actionQmlregister = "register";
54 const QString ZblCog::m_actionIgnore = "ignore";
55 const QString ZblCog::m_restypeInvalid = "invalid";
56 const QString ZblCog::m_restypeFile = "file";
57 const QString ZblCog::m_restypePlugin = "plugin";
58 
59 const int ZblCog::m_paramcountFile = 4;
60 const int ZblCog::m_paramcountPlugin = 1;
61 
62 ZblCog::ZblCog(QObject *parent) :
63  QObject(parent)
64 {
66 
67  if(m_zCog)
68  throw ZblException(
69  "Zbl::ZblCog::Zblcore programming error: "
70  "Only one instance of ZblCog class should exist per linux process.");
71 
72  m_zCog = this;
73 }
74 
76 {
77  QWriteLocker lock(&m_lock);
78 
79  QList<ZblSprocket*> sprockets(m_sprockets.values());
80 
81  for(int i=0; i < sprockets.size(); i++)
82  delete sprockets.at(i);
83 
84  QList<ZblResource*> resources(m_resources.values());
85 
86  for(int i=0; i < resources.size(); i++)
87  delete resources.at(i);
88 
89  m_zCog = NULL;
90 }
91 
92 bool ZblCog::registerSprocket(const char* uri,
93  int versionMajor,
94  int versionMinor)
95 {
96  zDebug() << "ZblCog::registerSprocket:"
97  << ZblSprocket::sprocketTag(uri, versionMajor, versionMinor);
98 
99  ZblSprocket* sv = NULL;
100 
101  try
102  {
103  QWriteLocker lock(&m_lock);
104 
105  const ZblSprocket* previous = m_sprockets.value(uri, NULL);
106 
107  if(previous)
108  {
109  zWarning() << "ZblCog::registerSprocket FAILED: sprocket already"
110  "registered as: " << previous->sprocketTag();
111 
112  return false;
113  }
114 
115  sv = new ZblSprocket(uri, versionMajor, versionMinor);
116 
117  if(!sv)
118  {
119  zWarning() << "ZblCog::registerSprocket FAILED: can't create "
120  "sprocket object";
121 
122  return false;
123  }
124 
125  m_sprockets.insert(uri, sv);
126 
127  }
128  catch(...)
129  {
130  if(sv)
131  delete sv;
132 
133  return false;
134  }
135 
136  return true;
137 }
138 
140  const char* uri,
141  int versionMajor,
142  int versionMinor,
143  const char* qmlName,
144  sprocketObjectConstructor createFunc)
145 {
146  QReadLocker lock(&m_lock);
147 
148  ZblSprocket* sprock = m_sprockets.value(uri, NULL);
149 
150  if(!sprock)
151  {
152  zWarning() << "ZblCog::registerSprocketObject FAILED: "
153  "no sprocket plugin is registered for uri: "
154  << uri << "; Call Zbl::ZblCog::registerSprocket "
155  "before calling this method.";
156  return false;
157  }
158 
159  return sprock->registerSprocketObject(
160  uri, versionMajor, versionMinor, qmlName, createFunc);
161 }
162 
164  const char* sprocketUri,
165  int versionMajor,
166  int versionMinor,
167  QObject* parent)
168 {
169  QReadLocker lock(&m_lock);
170 
171  ZblSprocket* s = m_sprockets.value(sprocketUri, NULL);
172 
173  if(!s)
174  {
175  zWarning() << "ZblCog::createFactory FAILED: no sprocket plugin "
176  "exists for uri: " << sprocketUri;
177  return NULL;
178  }
179 
180  ZblFactory* f = new ZblFactory(versionMajor, versionMinor, parent);
181 
182  if(!f)
183  {
184  zWarning() << "ZblCog::createFactory FAILED: can't construct "
185  "ZblFactory object";
186 
187  return NULL;
188  }
189 
190  QList<QString> foundaryKeys(s->m_objects.keys());
191 
192  for(int i=0; i < foundaryKeys.size(); i++)
193  {
194  const QString qmlName(foundaryKeys.at(i));
195 
196  ZblSprockOb* sproc = s->findSprock(
197  versionMajor, versionMinor, cStr(qmlName));
198 
199  if(sproc)
200  f->m_objectFunctions.insert(qmlName, sproc);
201  }
202 
203  if(f->m_objectFunctions.isEmpty())
204  {
205  zWarning() <<
206  "ZblCog::createFactory WARNING: Sprocket contains no objects";
207  }
208 
209  return f;
210 }
211 
213  const char* uri,
214  int versionMajor,
215  int versionMinor,
216  const char* fileName)
217 {
218  ZblResource* rs = NULL;
219 
220  const QString key(ZblSprocket::sprocketTag(
221  uri, versionMajor, versionMinor));
222 
223  zDebug() << "ZblCog::mapResource - mapping resource: "
224  << key;
225 
226  try
227  {
228  QWriteLocker lock(&m_lock);
229 
230  const ZblResource* previous = m_resources.value(key, nullptr);
231 
232  if(previous)
233  {
234  zWarning() << "ZblCog::mapResource FAILED: resource already"
235  "registered as: " << key;
236 
237  return false;
238  }
239 
240  rs = new ZblResource(uri, versionMajor, versionMinor, fileName);
241 
242  if(!rs)
243  {
244  zWarning() << "ZblCog::registerResource FAILED: can't create "
245  "resource object for resource: " << key;
246 
247  return false;
248  }
249 
250  if(!rs->validate())
251  {
252  zWarning() << "ZblCog::mapResource FAILED: can't locate "
253  "resource file: " << fileName <<
254  " for resource: " << key;
255 
256  delete rs;
257 
258  return false;
259  }
260 
261  m_resources.insert(key, rs);
262 
263  }
264  catch(...)
265  {
266  if(rs)
267  delete rs;
268 
269  return false;
270  }
271 
272  zDebug() << "ZblCog::mapResource - mapped resource: "
273  << key;
274 
275  return true;
276 }
277 
278 bool ZblCog::mapPluginResources(const char* fileName, bool qmlRegister)
279 {
280 
281  static const QString label("ZblCog::mapPluginResources");
282 
283  // locate zblconfig file
284 
285  if(!fileName)
286  {
287  zWarning() << label << " - FAILED - " <<
288  "invalid configuration file path: NULL";
289  return false;
290  }
291 
292  zDebug() << "Mapping plugin file resources: "
293  << fileName;
294 
295  QPluginLoader loader;
296 
297  loader.setFileName(fileName);
298 
299  QJsonObject metaObject = loader.metaData();
300 
301 
302 // start debug code
303  QJsonDocument doc(metaObject);
304 
305  QByteArray ba = doc.toJson();
306 
307  zDebug() << "plugin metadata = " << ba.constData();
308  zDebug() << "plugin file name = " << loader.fileName();
309 // end debug code
310 
311  bool failed = false;
312 
313  QJsonObject metaData = metaObject.value("MetaData").toObject();
314 
315  QJsonArray resourceBundle = metaData.value("Resources").toArray();
316 
317  if(resourceBundle.isEmpty())
318  {
319  zWarning() << label
320  << " - WARNING: plugin file %s has no resource metadata: "
321  << fileName;
322 
323  return false;
324  }
325 
326  zDebug() << "got resource metadata!";
327 
328  const int bundleSize = resourceBundle.size();
329 
330  for(int i=0; i < bundleSize; i++)
331  {
332  QJsonValue nextResource;
333 
334  nextResource = resourceBundle.at(i);
335 
336  QString uri;
337  QString fileName;
338  QString vMajor;
339  QString vMinor;
340 
341  if(getPluginResParams(nextResource, uri, fileName, vMajor, vMinor))
342  {
343  zDebug() << label << "processing resource metadata: " << uri;
344 
345  bool numOK;
346 
347  int numMajor = vMajor.toInt(&numOK);
348 
349  if(!numOK)
350  {
351  zWarning() << label
352  << " - WARNING - can't load resource, metadata has invalid value - "
353  "major-version should be an integer string, ie \"1\","
354  " instead it was: "
355  << vMajor;
356 
357 
358 
359  failed = true;
360  continue;
361  }
362 
363  int numMinor = vMinor.toInt(&numOK);
364 
365  if(!numOK)
366  {
367  zWarning() << label
368  << " - WARNING - can't load resource, metadata has invalid value - "
369  "minor-version should be an integer string, ie \"0\","
370  " instead it was: "
371  << vMinor;
372 
373  failed = true;
374  continue;
375  }
376 
377  if(!mapResource(cStr(uri), numMajor, numMinor, cStr(fileName)))
378  {
379  zWarning() << label
380  << " - WARNING - Zuble failed to map resource: "
381  << uri;
382 
383  failed = true;
384  continue;
385  }
386  else if(qmlRegister)
387  {
388  if(!registerResource(cStr(uri), numMajor, numMinor))
389  {
390  zWarning() << label
391  << " - WARNING - Qt failed to register resource: "
392  << uri;
393 
394  failed = true;
395  }
396  }
397  }
398  else
399  {
400  zWarning() << label
401  << " - WARNING - resource metadata was invalid for plugin file: "
402  << fileName;
403 
404  failed = true;
405  }
406 
407  } // end for
408 
409  return !failed;
410 }
411 
412 bool ZblCog::getPluginResParams(const QJsonValue& resourceValue,
413  QString& uri,
414  QString& fileName,
415  QString& versionMajor,
416  QString& versionMinor)
417 {
418  static const QString uriName("uri");
419  static const QString filenameName("fileName");
420  static const QString vMajorName("version-major");
421  static const QString vMinorName("version-minor");
422 
423  if(resourceValue.isObject())
424  {
425  QJsonObject resObject(resourceValue.toObject());
426 
427  if(!getPluginStringParam(resObject, uriName, uri))
428  return false;
429  if(!getPluginStringParam(resObject, filenameName, fileName))
430  return false;
431  if(!getPluginStringParam(resObject, vMajorName, versionMajor))
432  return false;
433  if(!getPluginStringParam(resObject, vMinorName, versionMinor))
434  return false;
435  }
436 
437  return true;
438 }
439 
440 bool ZblCog::getPluginStringParam(const QJsonObject& resource,
441  const QString& paramKey,
442  QString& outValue)
443 {
444  QJsonValue value;
445 
446  value = resource.value(paramKey);
447 
448  if(value.isString())
449  {
450  outValue = value.toString();
451  return true;
452  }
453 
454  return false;
455 }
456 
457 bool ZblCog::mapConfigResources(const char* configFilePath)
458 {
459 
460  static const QString label("ZblCog::mapConfigResources");
461 
462  // locate zblconfig file
463 
464  if(!configFilePath)
465  {
466  zWarning() << "ZblCog::mapAppResources - FAILED - " <<
467  "invalid configuration file path: NULL";
468  return false;
469  }
470 
471  zDebug() << "Mapping configuration file resources: "
472  << configFilePath;
473 
474 
475  QFile cfg(configFilePath);
476 
477  if(!cfg.exists())
478  {
480  QString("Nonexistent configuration file: %1").arg(configFilePath));
481 
482  return false;
483  }
484 
485  // create query
486 
487  QXmlQuery xq;
488 
489  QUrl url(QUrl::fromLocalFile(configFilePath));
490 
491  zDebug() << label << "setting XQuery focus to config file: " << url.path();
492 
493  QString query = "declare default element namespace 'http://zuble.org/schema/zuble/zblconfig'; \n"
494  "declare function local:pluginElement($action as xs:string, $pe as element()?) as xs:string* \n"
495  "{ (string-join(($action,\"plugin\",\"1\"),\"::\"),xs:string($pe/filename)) }; \n"
496  "declare function local:fileElement($action as xs:string, $fe as element()?) as xs:string* \n"
497  "{ (string-join(($action,\"file\",\"4\"), \"::\"), \n"
498  " xs:string($fe/uri), xs:string($fe/version-major), \n"
499  " xs:string($fe/version-minor),xs:string($fe/filename)) }; \n"
500  "for $map in /zblconfig/resources/resource-map \n"
501  " let $plugin := $map/plugin let $file := $map/file \n"
502  " return (if($plugin) then local:pluginElement($map/@action,$plugin) \n"
503  " else if($file) then local:fileElement($map/@action,$file) \n"
504  " else string-join((\"ignore\",\"invalid\",\"0\"), \"::\"))";
505 
506 
507  bool status = xq.setFocus(url);
508 
509  if(!status)
510  {
512  QString("QXmlQuery can't load configuration file: %1").arg(url.path().toUtf8().constData()));
513 
514  return false;
515  }
516 
517  zDebug() << "Query=" << query;
518 
519  xq.setQuery(query);
520 
521  if(!xq.isValid())
522  {
524  QString("Programming error: invalid XQuery: %1").arg(query.toUtf8().constData()));
525 
526  return false;
527  }
528 
529  // evaluate results
530 
531  QStringList xmlResults;
532 
533  xq.evaluateTo(&xmlResults);
534 
535  const int count = xmlResults.count();
536 
537  zDebug() << "Dumping XQuery evaluation results ++++++++++++++++++++++++++";
538 
539  for(int x=0; x<count; x++)
540  zDebug() << xmlResults.at(x).toUtf8().constData();
541 
542  // qDebug("Evaluated to: %s", xmlResults.at(x).toUtf8().constData());
543 
544  zDebug() << "End dumping XQuery evaluation results ++++++++++++++++++++++++++";
545 
546 
547 
548 
549  for(int j=0; j<count; j++)
550  {
551  const QStringList command(xmlResults.at(j).split(m_commandSeparator));
552 
553  //const int fieldCount = command.count();
554 
555  if(command.count() != commandFieldCount)
556  {
557  warnInvalidResourceCommand(label, xmlResults.at(j));
558 
559  warnAbortingResourceLoad(label, "invalid command format");
560 
561  return false;
562  }
563 
564  const QString& strAction(command.at(cmdAction));
565  const QString& strResourceType(command.at(cmdResourceType));
566  const QString& strSize(command.at(cmdRecordSize));
567 
568 
569  zDebug() << "Resource command - Action: " << strAction
570  << "Type: " << strResourceType
571  << "Size: " << strSize;
572 
573  bool intOK;
574 
575  const int size = strSize.toInt(&intOK);
576 
577  if(!intOK)
578  {
579  zWarning() <<
580  "ZblCog::mapConfigResources - WARNING: invalid command format, "
581  "third field should contain an integer specifying the number "
582  "of command parameter strings that follow this command string "
583  "in the string array: "
584  << xmlResults.at(j);
585 
586  warnAbortingResourceLoad(label, "invalid command format");
587 
588  return false;
589  }
590 
591  if(strAction == m_actionIgnore)
592  {
593  zWarning() << "ZblCog::mapConfigResources - "
594  "WARNING: invalid XML configuration file format - "
595  "an invalid XML node or text was encountered and ignored "
596  "by the XQuery.";
597 
598  j += size;
599 
600  continue;
601 
602  }
603  else if(strAction != m_actionMap && strAction != m_actionQmlregister )
604  {
605  zWarning() << "ZblCog::mapConfigResources - "
606  "WARNING: invalid command format - skipping this command -"
607  "first field should contain a valid action string - "
608  "instead it contained: " << strAction;
609 
610  warnInvalidResourceCommand(label, xmlResults.at(j));
611 
612  j += size;
613 
614  continue;
615  }
616 
617  if(strResourceType == m_restypePlugin)
618  {
620  {
621  warnInvalidResourceCommand(label, xmlResults.at(j));
622 
623  warnAbortingResourceLoad(label, "invalid command format");
624 
625  return false;
626  }
627 
628  bool loadPlugin = strAction == m_actionQmlregister;
629 
630  if(!mapPluginResources(
631  xmlResults.at(j+pluginName).toUtf8().constData(),
632  loadPlugin))
633  {
634  zWarning() <<
635  "ZblCog::mapConfigResources - "
636  "WARNING: failed to map plugin resources for plugin: "
637  << xmlResults.at(j+pluginName);
638  }
639  }
640  else if(strResourceType == m_restypeFile)
641  {
642  // loading a resource file
643 
645  {
646  warnInvalidResourceCommand(label, xmlResults.at(j));
647 
648  warnAbortingResourceLoad(label, "invalid command format");
649 
650  return false;
651  }
652 
653  // convert versionMajor and versionMinor to integers
654 
655  const int versionMajor = xmlResults.at(j+fileVersionMajor).toInt(&intOK);
656 
657  if(!intOK)
658  {
659  zWarning() <<
660  "ZblCog::mapConfigResources - WARNING: invalid file resource parameter - "
661  "version-major should contain an integer specifying the major "
662  "version number of the resource file to be mapped - "
663  "instead it contains: "
664  << xmlResults.at(j+fileVersionMajor);
665 
666  warnAbortingResourceLoad(label, "invalid parameter");
667 
668  return false;
669  }
670 
671  const int versionMinor = xmlResults.at(j+fileVersionMinor).toInt(&intOK);
672 
673  if(!intOK)
674  {
675  zWarning() <<
676  "ZblCog::mapConfigResources - WARNING: invalid file resource parameter - "
677  "version-mainor should contain an integer specifying the minor "
678  "version number of the resource file to be mapped - "
679  "instead it contains: %s"
680  << xmlResults.at(j+fileVersionMinor);
681 
682  warnAbortingResourceLoad(label, "invalid parameter");
683 
684  return false;
685  }
686 
687  if(!mapResource(
688  xmlResults.at(j+fileUri).toUtf8().constData(),
689  versionMajor,
690  versionMinor,
691  xmlResults.at(j+fileName).toUtf8().constData()))
692  {
693  zWarning() <<
694  "ZblCog::mapConfigResources - "
695  "WARNING: failed to map file resources for file: "
696  << xmlResults.at(j+fileName);
697  }
698  else if(strAction == "load")
699  {
700 
701  if(!registerResource(
702  xmlResults.at(j+fileUri).toUtf8().constData(),
703  versionMajor,
704  versionMinor))
705  {
706  zWarning() << "ZblCog::mapConfigResources - "
707  "WARNING: failed to register resources for uri: "
708  << xmlResults.at(j+fileUri);
709  }
710 
711  }
712  }
713  else
714  {
715  // neither resource file or plugin resource was specified
716 
717  zWarning() << "ZblCog::mapConfigResources - "
718  "WARNING: invalid command format - "
719  "second field should contain a valid resource type string.";
720 
721  warnInvalidResourceCommand(label, xmlResults.at(j));
722 
723  warnAbortingResourceLoad(label, "invalid command format");
724 
725  return false;
726  }
727 
728  j += size;
729 
730  } // end for
731 
732  zDebug() << "Done mapping configuration file resources";
733 
734  return true;
735 
736 }
737 
738 bool ZblCog::validateParamCount(int actual, int required)
739 {
740  if(actual == required)
741  return true;
742 
743  zWarning() << "ZblCog::validateParamCount - "
744  "WARNING: invalid parameter count - command required "
745  << required << " paramaters but " << actual << " were passed.";
746 
747  return false;
748 
749 }
750 
751 void ZblCog::warnInvalidResourceCommand(const QString& label, const QString& command)
752 {
753  zWarning() << label <<
754  " - WARNING: invalid resource command format - "
755  "command strings should have exactly three fields as follows: "
756  "[action]::[recordType]::[parameterCount] where: "
757  "action=\"map\"|\"load\" resourceType=\"file\"|\"plugin\" "
758  "parameterCount=[integer number of parameters following this command.]"
759  " INVALID COMMAND STRING="
760  << command;
761 
762  }
763 
765  const QString& label, const QString& reason)
766 {
767  zWarning() << label
768  << " - WARNING - ABORTING configuration resource load operation! "
769  << reason;
770 }
771 
772 
773 QString ZblCog::getNodeName(const QXmlItem& item, const QXmlQuery& query)
774 {
775  // TBD: deprecated! don't use QXmlItems! Qt implementation too flaky!
776 
777  QString retval;
778 
779  if(!item.isNode())
780  return retval;
781 
782  QXmlNodeModelIndex index(item.toNodeModelIndex());
783 
784  const QAbstractXmlNodeModel* model = index.model();
785 
786  QXmlName name(model->name(index));
787 
788  retval = name.localName();
789 
790  return retval;
791 
792 }
793 
795  const char* uri, int versionMajor, int versionMinor)
796 {
797 
798 
799  bool status = false;
800 
801  ZblResource* rs = NULL;
802 
803  const QString key(ZblSprocket::sprocketTag(
804  uri, versionMajor, versionMinor));
805 
806  zDebug() << "ZblCog::registerResource - registering resource: "
807  << key;
808 
809 
810  try
811  {
812  QReadLocker lock(&m_lock);
813 
814  rs = m_resources.value(key, NULL);
815 
816  if(!rs)
817  {
818  zWarning() << "ZblCog::registerResource FAILED: resource not mapped: "
819  << key;
820 
821  return false;
822  }
823 
824  if(!rs->validate())
825  {
826  zWarning() << "ZblCog::loadResource FAILED: can't access "
827  "resource file: " << rs->fileName() <<
828  " for resource: " << key;
829 
830  return false;
831  }
832 
833  status = rs->load();
834 
835  //m_resources.insert(key, rs);
836 
837  }
838  catch(...)
839  {
840  return false;
841  }
842 
843  zDebug() << "ZblCog::loadResource - loadResource resource: "
844  << key;
845 
846  return status;
847 }
848 
850  const char* uri,
851  int versionMajor,
852  int versionMinor)
853 {
854  try
855  {
856  QReadLocker lock(&m_lock);
857 
858  if(versionMajor != -1 && versionMinor != -1)
859  {
860  // use both version numbers in test
861 
862  const QString key(ZblSprocket::sprocketTag(
863  uri, versionMajor, versionMinor));
864 
865  return m_resources.contains(key);
866  }
867 
868  // use no version number in test
869 
870  QString prefix(uri);
871  prefix += ":";
872 
873  if(versionMajor != -1)
874  {
875  // add major version number to test
876 
877  prefix += QString::number(versionMajor);
878  prefix += ":";
879  }
880 
881  QStringList keys(m_resources.keys());
882 
883  keys = keys.filter(prefix);
884 
885  return !keys.isEmpty();
886  }
887  catch(...)
888  {
889  throw ZblException("ZblCog::isMappedResource - unknown exception");
890  }
891 
892  return false;
893 }
894 
895 
897 {
898  QReadLocker lock(&m_lock);
899 
900  return m_resources.keys();
901 }
902 
903 
904 ZblCog& ZblCog::zInit(QObject* parent)
905 {
906  //throw ZblException("how do you like me now?");
907 
908  if(m_zCog)
909  throw ZblException(
910  "Zbl::ZblCog::zInstance programming error: "
911  "Singleton ZblCog object already initialized!");
912 
913  m_zCog = new ZblCog(parent);
914 
915  return *m_zCog;
916 }
917 
918 
920 {
921  if(!m_zCog)
922  throw ZblException(
923  "Zbl::ZblCog::zInstance programming error: "
924  "Singleton ZblCog object not initialized! "
925  "Call ZblCog::zInit before calling this method.");
926 
927  return *m_zCog;
928 }
929 
930 
931 } // Zbl
const QString & fileName() const
returns the Resource file&#39;s file name
Definition: ZblResource.h:82
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
This class holds the state for managing a Zuble sprocket.
Definition: ZblSprocket.h:38
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
static const int m_paramcountPlugin
Definition: ZblCog.h:411
sprocketFoundryMap m_objects
Maps object QML names to maps of sprocket object foundaries. Each foundary contains a separate object...
Definition: ZblSprocket.h:197
ZblSprockOb * findSprock(int versionMajor, int versionMinor, const char *qmlName)
Locates a version-specific Sprocket object constructor in the Sprocket&#39;s object foundry based on the ...
Definition: ZblSprocket.cpp:80
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
#define ZBL_REGISTER_LOGGED_OBJECT
Definition: zglobal.h:104
sprocketObjectMap m_objectFunctions
Maps QML type names to appropriate version-specific Sprocket object constructors. ...
Definition: ZblFactory.h:117
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
bool registerSprocketObject(const char *uri, int versionMajor, int versionMinor, const char *qmlName, sprocketObjectConstructor createFunc)
Creates a new ZblSprockOb Sprocket object constructor and adds it to the Sprocket&#39;s object foundary...
Definition: ZblSprocket.cpp:45
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
Represents a binary resource file created by Qt&#39;s resource complier.
Definition: ZblResource.h:45
#define ZBL_DEFINE_LOGGED_OBJECT(class_name)
Definition: zglobal.h:99
static int versionMajor
Definition: main.cpp:59
#define zWarning()
Definition: zglobal.h:111
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
#define zDebug()
Definition: zglobal.h:113
bool loadPlugin()
Definition: main.cpp:164
const QString sprocketTag() const
returns a string in the form of "<uri>:<majorVersion>:<minorVersion>"
Definition: ZblSprocket.h:90
static const QString m_restypePlugin
Definition: ZblCog.h:407
static const QString m_restypeFile
Definition: ZblCog.h:406
#define cStr(qStr)
Definition: zglobal.h:49
void warnInvalidResourceCommand(const QString &label, const QString &command)
Definition: ZblCog.cpp:751
Zuble&#39;s Qt Exception Object.
Definition: ZblException.h:45
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
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