1919#include < QtCore/QMetaObject>
2020#include < QtCore/QMetaProperty>
2121
22+ #include < QReadWriteLock>
23+
2224#include " direction.h"
2325#include " kitBase/kitBaseDeclSpec.h"
2426
@@ -30,12 +32,15 @@ namespace robotModel {
3032class ROBOTS_KIT_BASE_EXPORT DeviceInfo
3133{
3234public:
35+ // / Constructs invalid DeviceInfo instance.
36+ DeviceInfo ();
37+
3338 // / Creates a new instance of a Device descriptor. The resulting object will
3439 // / correspond to a given type only if Q_OBJECT macro is used inside its declaration.
3540 // / @warning Given device type must contain friendlyName() and direction() static functions
3641 // / and Q_OBJECT macro.
3742 template <typename T>
38- static DeviceInfo create ()
43+ static DeviceInfo & create ()
3944 {
4045 // This line performs Q_OBJECT macro checking in the given type declaration.
4146 // Without Q_OBJECT macro incorrect metaObject will be passed and it will lead
@@ -47,15 +52,13 @@ class ROBOTS_KIT_BASE_EXPORT DeviceInfo
4752 const bool simulated = property (metaObject, " simulated" ) == " true" ;
4853 const Direction direction = property (metaObject, " direction" ).toLower () == " input" ? input : output;
4954 DeviceInfo result (metaObject, name, friendlyName, simulated, direction);
50- mCreatedInfos [QString (metaObject->className ())] = result;
51- return result;
55+ QWriteLocker w (&mRWLock );
56+ auto &r = mCreatedInfos [QString (metaObject->className ())] = std::move (result);
57+ return r;
5258 }
5359
5460 // / Deserializes inner string representation obtained by toString().
55- static DeviceInfo fromString (const QString &string);
56-
57- // / Constructs invalid DeviceInfo instance.
58- DeviceInfo ();
61+ static DeviceInfo &fromString (const QString &string);
5962
6063 // / Serializes given device info into inner string representation.
6164 QString toString () const ;
@@ -115,6 +118,7 @@ class ROBOTS_KIT_BASE_EXPORT DeviceInfo
115118
116119 static QString property (const QMetaObject * const metaObject, const QString &name);
117120
121+ static QReadWriteLock mRWLock ;
118122 static QMap<QString, DeviceInfo> mCreatedInfos ;
119123
120124 const QMetaObject *mDeviceType ;
0 commit comments