PIObject Property const char *
This commit is contained in:
@@ -208,8 +208,9 @@ PIObject::~PIObject() {
|
|||||||
|
|
||||||
PIMap<PIString, PIVariant> PIObject::properties() const {
|
PIMap<PIString, PIVariant> PIObject::properties() const {
|
||||||
PIMap<PIString, PIVariant> ret;
|
PIMap<PIString, PIVariant> ret;
|
||||||
piForeachC (PropertyHash p, properties_)
|
for (const PropertyHash & p : properties_) {
|
||||||
ret[p.second.first] = p.second.second;
|
ret[PIStringAscii(p.second.first)] = p.second.second;
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -693,9 +694,12 @@ void PIObject::dump(const PIString & line_prefix) const {
|
|||||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " properties {";
|
PICout(PICoutManipulators::AddNewLine) << line_prefix << " properties {";
|
||||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << properties_.size_s();
|
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << properties_.size_s();
|
||||||
//printf("dump %d properties\n", properties_.size());
|
//printf("dump %d properties\n", properties_.size());
|
||||||
piForeachC (PropertyHash p, properties_)
|
const char * o_name = "name";
|
||||||
if (p.first != PIString("name").hash())
|
auto it = properties_.makeIterator();
|
||||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << p.second.first << ": " << p.second.second;
|
while (it.next()) {
|
||||||
|
if (it.key() != piHashData((const uchar *)o_name, strlen(o_name)))
|
||||||
|
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << it.value().first << ": " << it.value().second;
|
||||||
|
}
|
||||||
//printf("dump %d properties ok\n", properties_.size());
|
//printf("dump %d properties ok\n", properties_.size());
|
||||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
|
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
|
||||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " methods {";
|
PICout(PICoutManipulators::AddNewLine) << line_prefix << " methods {";
|
||||||
@@ -710,7 +714,7 @@ void PIObject::dump(const PIString & line_prefix) const {
|
|||||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " connections {";
|
PICout(PICoutManipulators::AddNewLine) << line_prefix << " connections {";
|
||||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << connections.size_s();
|
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << connections.size_s();
|
||||||
//printf("dump %d connections\n",connections.size());
|
//printf("dump %d connections\n",connections.size());
|
||||||
piForeachC (Connection & c, connections) {
|
for (const Connection & c : connections) {
|
||||||
PIObject * dst = c.dest_o;
|
PIObject * dst = c.dest_o;
|
||||||
__MetaFunc ef = methodEH(c.signal);
|
__MetaFunc ef = methodEH(c.signal);
|
||||||
PIString src(c.event);
|
PIString src(c.event);
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public:
|
|||||||
|
|
||||||
//! \~english Returns object name
|
//! \~english Returns object name
|
||||||
//! \~russian Возвращает имя объекта
|
//! \~russian Возвращает имя объекта
|
||||||
PIString name() const {return property(PIStringAscii("name")).toString();}
|
PIString name() const {return property("name").toString();}
|
||||||
|
|
||||||
//! \~english Returns object class name
|
//! \~english Returns object class name
|
||||||
//! \~russian Возвращает имя класса объекта
|
//! \~russian Возвращает имя класса объекта
|
||||||
@@ -131,17 +131,16 @@ public:
|
|||||||
|
|
||||||
//! \~english Return if \a piCoutObj of this object is active
|
//! \~english Return if \a piCoutObj of this object is active
|
||||||
//! \~russian Возвращает включен ли вывод \a piCoutObj для этого объекта
|
//! \~russian Возвращает включен ли вывод \a piCoutObj для этого объекта
|
||||||
bool debug() const {return property(PIStringAscii("debug")).toBool();}
|
bool debug() const {return property("debug").toBool();}
|
||||||
|
|
||||||
|
|
||||||
//! \~english Set object name
|
//! \~english Set object name
|
||||||
//! \~russian Устанавливает имя объекта
|
//! \~russian Устанавливает имя объекта
|
||||||
void setName(const PIString & name) {setProperty(PIStringAscii("name"), name);}
|
void setName(const PIString & name) {setProperty("name", name);}
|
||||||
void setName(const char * name) {setName(PIStringAscii(name));}
|
|
||||||
|
|
||||||
//! \~english Set object \a piCoutObj active
|
//! \~english Set object \a piCoutObj active
|
||||||
//! \~russian Включает или отключает вывод \a piCoutObj для этого объекта
|
//! \~russian Включает или отключает вывод \a piCoutObj для этого объекта
|
||||||
void setDebug(bool debug) {setProperty(PIStringAscii("debug"), debug);}
|
void setDebug(bool debug) {setProperty("debug", debug);}
|
||||||
|
|
||||||
//! \~english Returns properties of the object
|
//! \~english Returns properties of the object
|
||||||
//! \~russian Возвращает словарь свойств объекта
|
//! \~russian Возвращает словарь свойств объекта
|
||||||
@@ -153,18 +152,15 @@ public:
|
|||||||
|
|
||||||
//! \~english Returns property with name "name"
|
//! \~english Returns property with name "name"
|
||||||
//! \~russian Возвращает свойство объекта по имени "name"
|
//! \~russian Возвращает свойство объекта по имени "name"
|
||||||
PIVariant property(const PIString & name) const {return properties_.value(name.hash(), Property(PIString(), PIVariant())).second;}
|
PIVariant property(const char * name) const {return properties_.value(piHashData((const uchar *)name, strlen(name)), Property(nullptr, PIVariant())).second;}
|
||||||
PIVariant property(const char * name) const {return property(PIStringAscii(name));}
|
|
||||||
|
|
||||||
//! \~english Set property with name "name" to "value". If there is no such property in object it will be added
|
//! \~english Set property with name "name" to "value". If there is no such property in object it will be added
|
||||||
//! \~russian Устанавливает у объекта свойство по имени "name" в "value". Если такого свойства нет, оно добавляется
|
//! \~russian Устанавливает у объекта свойство по имени "name" в "value". Если такого свойства нет, оно добавляется
|
||||||
void setProperty(const PIString & name, const PIVariant & value) {properties_[name.hash()] = Property(name, value); propertyChanged(name);}
|
void setProperty(const char * name, const PIVariant & value) {properties_[piHashData((const uchar *)name, strlen(name))] = Property(name, value); propertyChanged(name);}
|
||||||
void setProperty(const char * name, const PIVariant & value) {setProperty(PIStringAscii(name), value);}
|
|
||||||
|
|
||||||
//! \~english Returns if property with name "name" exists
|
//! \~english Returns if property with name "name" exists
|
||||||
//! \~russian Возвращает присутствует ли свойство по имени "name"
|
//! \~russian Возвращает присутствует ли свойство по имени "name"
|
||||||
bool isPropertyExists(const PIString & name) const {return properties_.contains(name.hash());}
|
bool isPropertyExists(const char * name) const {return properties_.contains(piHashData((const uchar *)name, strlen(name)));}
|
||||||
bool isPropertyExists(const char * name) const {return isPropertyExists(PIStringAscii(name));}
|
|
||||||
|
|
||||||
void setThreadSafe(bool yes) {thread_safe_ = yes;}
|
void setThreadSafe(bool yes) {thread_safe_ = yes;}
|
||||||
bool isThreadSafe() const {return thread_safe_;}
|
bool isThreadSafe() const {return thread_safe_;}
|
||||||
@@ -520,7 +516,7 @@ protected:
|
|||||||
|
|
||||||
//! \~english Virtual function executes after property with name "name" has been changed
|
//! \~english Virtual function executes after property with name "name" has been changed
|
||||||
//! \~russian Виртуальная функция, вызывается после изменения любого свойства.
|
//! \~russian Виртуальная функция, вызывается после изменения любого свойства.
|
||||||
virtual void propertyChanged(const PIString & name) {}
|
virtual void propertyChanged(const char * name) {}
|
||||||
|
|
||||||
EVENT1(deleted, PIObject *, o)
|
EVENT1(deleted, PIObject *, o)
|
||||||
|
|
||||||
@@ -569,8 +565,8 @@ private:
|
|||||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef PIPair<PIString, PIVariant> Property;
|
typedef PIPair<const char *, PIVariant> Property;
|
||||||
typedef PIPair<uint, PIPair<PIString, PIVariant> > PropertyHash;
|
typedef PIPair<uint, Property > PropertyHash;
|
||||||
|
|
||||||
bool findSuitableMethodV(const PIString & method, int args, int & ret_args, __MetaFunc & ret);
|
bool findSuitableMethodV(const PIString & method, int args, int & ret_args, __MetaFunc & ret);
|
||||||
PIVector<__MetaFunc> findEH(const PIString & name) const;
|
PIVector<__MetaFunc> findEH(const PIString & name) const;
|
||||||
@@ -591,7 +587,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
PIVector<Connection> connections;
|
PIVector<Connection> connections;
|
||||||
PIMap<uint, PIPair<PIString, PIVariant> > properties_;
|
PIMap<uint, Property> properties_;
|
||||||
PISet<PIObject * > connectors;
|
PISet<PIObject * > connectors;
|
||||||
PIVector<__QueuedEvent> events_queue;
|
PIVector<__QueuedEvent> events_queue;
|
||||||
PIMutex mutex_, mutex_connect, mutex_queue;
|
PIMutex mutex_, mutex_connect, mutex_queue;
|
||||||
|
|||||||
@@ -257,8 +257,6 @@ public:
|
|||||||
//! \~russian Возвращает свойство с именем "name" как константу
|
//! \~russian Возвращает свойство с именем "name" как константу
|
||||||
const Property operator[](const PIString & name) const;
|
const Property operator[](const PIString & name) const;
|
||||||
|
|
||||||
static Property parsePropertyLine(PIString l);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PIVector<Property> props;
|
PIVector<Property> props;
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ const char PIString::toBaseN[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
|
|||||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
||||||
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
||||||
'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^'};
|
'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^'};
|
||||||
const int PIString::fromBaseN[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
const char PIString::fromBaseN[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
|
||||||
@@ -168,7 +168,7 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) {
|
|||||||
PIVector<int> digits;
|
PIVector<int> digits;
|
||||||
llong ret = 0, m = 1;
|
llong ret = 0, m = 1;
|
||||||
bool neg = false;
|
bool neg = false;
|
||||||
int cs;
|
char cs;
|
||||||
for (int i = 0; i < v.size_s(); ++i) {
|
for (int i = 0; i < v.size_s(); ++i) {
|
||||||
if (v[i] == PIChar('-')) {
|
if (v[i] == PIChar('-')) {
|
||||||
neg = !neg;
|
neg = !neg;
|
||||||
|
|||||||
@@ -1531,7 +1531,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static const char toBaseN[];
|
static const char toBaseN[];
|
||||||
static const int fromBaseN[];
|
static const char fromBaseN[];
|
||||||
|
|
||||||
static PIString itos(const int num);
|
static PIString itos(const int num);
|
||||||
static PIString ltos(const long num);
|
static PIString ltos(const long num);
|
||||||
|
|||||||
@@ -201,44 +201,44 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//! Set parameters to "parameters_". You should to reopen %PIEthernet to apply them
|
//! Set parameters to "parameters_". You should to reopen %PIEthernet to apply them
|
||||||
void setParameters(PIFlags<PIEthernet::Parameters> parameters_) {setProperty(PIStringAscii("parameters"), (int)parameters_);}
|
void setParameters(PIFlags<PIEthernet::Parameters> parameters_) {setProperty("parameters", (int)parameters_);}
|
||||||
|
|
||||||
//! Set parameter "parameter" to state "on". You should to reopen %PIEthernet to apply this
|
//! Set parameter "parameter" to state "on". You should to reopen %PIEthernet to apply this
|
||||||
void setParameter(PIEthernet::Parameters parameter, bool on = true);
|
void setParameter(PIEthernet::Parameters parameter, bool on = true);
|
||||||
|
|
||||||
//! Returns if parameter "parameter" is set
|
//! Returns if parameter "parameter" is set
|
||||||
bool isParameterSet(PIEthernet::Parameters parameter) const {return ((PIFlags<PIEthernet::Parameters>)(property(PIStringAscii("parameters")).toInt()))[parameter];}
|
bool isParameterSet(PIEthernet::Parameters parameter) const {return ((PIFlags<PIEthernet::Parameters>)(property("parameters").toInt()))[parameter];}
|
||||||
|
|
||||||
//! Returns parameters
|
//! Returns parameters
|
||||||
PIFlags<PIEthernet::Parameters> parameters() const {return (PIFlags<PIEthernet::Parameters>)(property(PIStringAscii("parameters")).toInt());}
|
PIFlags<PIEthernet::Parameters> parameters() const {return (PIFlags<PIEthernet::Parameters>)(property("parameters").toInt());}
|
||||||
|
|
||||||
//! Returns %PIEthernet type
|
//! Returns %PIEthernet type
|
||||||
Type type() const {return (Type)(property(PIStringAscii("type")).toInt());}
|
Type type() const {return (Type)(property("type").toInt());}
|
||||||
|
|
||||||
//! Returns read timeout
|
//! Returns read timeout
|
||||||
double readTimeout() const {return property(PIStringAscii("readTimeout")).toDouble();}
|
double readTimeout() const {return property("readTimeout").toDouble();}
|
||||||
|
|
||||||
//! Returns write timeout
|
//! Returns write timeout
|
||||||
double writeTimeout() const {return property(PIStringAscii("writeTimeout")).toDouble();}
|
double writeTimeout() const {return property("writeTimeout").toDouble();}
|
||||||
|
|
||||||
//! Set timeout for read
|
//! Set timeout for read
|
||||||
void setReadTimeout(double ms) {setProperty(PIStringAscii("readTimeout"), ms);}
|
void setReadTimeout(double ms) {setProperty("readTimeout", ms);}
|
||||||
|
|
||||||
//! Set timeout for write
|
//! Set timeout for write
|
||||||
void setWriteTimeout(double ms) {setProperty(PIStringAscii("writeTimeout"), ms);}
|
void setWriteTimeout(double ms) {setProperty("writeTimeout", ms);}
|
||||||
|
|
||||||
|
|
||||||
//! Returns TTL (Time To Live)
|
//! Returns TTL (Time To Live)
|
||||||
int TTL() const {return property(PIStringAscii("TTL")).toInt();}
|
int TTL() const {return property("TTL").toInt();}
|
||||||
|
|
||||||
//! Returns multicast TTL (Time To Live)
|
//! Returns multicast TTL (Time To Live)
|
||||||
int multicastTTL() const {return property(PIStringAscii("MulticastTTL")).toInt();}
|
int multicastTTL() const {return property("MulticastTTL").toInt();}
|
||||||
|
|
||||||
//! Set TTL (Time To Live), default is 64
|
//! Set TTL (Time To Live), default is 64
|
||||||
void setTTL(int ttl) {setProperty(PIStringAscii("TTL"), ttl);}
|
void setTTL(int ttl) {setProperty("TTL", ttl);}
|
||||||
|
|
||||||
//! Set multicast TTL (Time To Live), default is 1
|
//! Set multicast TTL (Time To Live), default is 1
|
||||||
void setMulticastTTL(int ttl) {setProperty(PIStringAscii("MulticastTTL"), ttl);}
|
void setMulticastTTL(int ttl) {setProperty("MulticastTTL", ttl);}
|
||||||
|
|
||||||
|
|
||||||
//! Join to multicast group with address "group". Use only for UDP
|
//! Join to multicast group with address "group". Use only for UDP
|
||||||
@@ -499,7 +499,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
EVENT_HANDLER1(void, clientDeleted, PIObject *, o);
|
EVENT_HANDLER1(void, clientDeleted, PIObject *, o);
|
||||||
static void server_func(void * eth);
|
static void server_func(void * eth);
|
||||||
void setType(Type t, bool reopen = true) {setProperty(PIStringAscii("type"), (int)t); if (reopen && isOpened()) {closeDevice(); init(); openDevice();}}
|
void setType(Type t, bool reopen = true) {setProperty("type", (int)t); if (reopen && isOpened()) {closeDevice(); init(); openDevice();}}
|
||||||
|
|
||||||
static int ethErrorCore();
|
static int ethErrorCore();
|
||||||
static PIString ethErrorString();
|
static PIString ethErrorString();
|
||||||
|
|||||||
@@ -109,10 +109,10 @@ public:
|
|||||||
DeviceInfoFlags infoFlags() const {return deviceInfoFlags();}
|
DeviceInfoFlags infoFlags() const {return deviceInfoFlags();}
|
||||||
|
|
||||||
//! Current path of device
|
//! Current path of device
|
||||||
PIString path() const {return property(PIStringAscii("path")).toString();}
|
PIString path() const {return property("path").toString();}
|
||||||
|
|
||||||
//! Set path of device
|
//! Set path of device
|
||||||
void setPath(const PIString & path) {setProperty(PIStringAscii("path"), path);}
|
void setPath(const PIString & path) {setProperty("path", path);}
|
||||||
|
|
||||||
//! Return \b true if mode is ReadOnly or ReadWrite
|
//! Return \b true if mode is ReadOnly or ReadWrite
|
||||||
bool isReadable() const {return (mode_ & ReadOnly);}
|
bool isReadable() const {return (mode_ & ReadOnly);}
|
||||||
@@ -134,17 +134,17 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//! Set execution of \a open enabled while threaded read on closed device
|
//! Set execution of \a open enabled while threaded read on closed device
|
||||||
void setReopenEnabled(bool yes = true) {setProperty(PIStringAscii("reopenEnabled"), yes);}
|
void setReopenEnabled(bool yes = true) {setProperty("reopenEnabled", yes);}
|
||||||
|
|
||||||
//! Set timeout in milliseconds between \a open tryings if reopen is enabled
|
//! Set timeout in milliseconds between \a open tryings if reopen is enabled
|
||||||
void setReopenTimeout(int msecs) {setProperty(PIStringAscii("reopenTimeout"), msecs);}
|
void setReopenTimeout(int msecs) {setProperty("reopenTimeout", msecs);}
|
||||||
|
|
||||||
|
|
||||||
//! Return reopen enable
|
//! Return reopen enable
|
||||||
bool isReopenEnabled() const {return property(PIStringAscii("reopenEnabled")).toBool();}
|
bool isReopenEnabled() const {return property("reopenEnabled").toBool();}
|
||||||
|
|
||||||
//! Return reopen timeout
|
//! Return reopen timeout
|
||||||
int reopenTimeout() {return property(PIStringAscii("reopenTimeout")).toInt();}
|
int reopenTimeout() {return property("reopenTimeout").toInt();}
|
||||||
|
|
||||||
|
|
||||||
/** \brief Set "threaded read slot"
|
/** \brief Set "threaded read slot"
|
||||||
|
|||||||
Reference in New Issue
Block a user