diff options
| author | Ted Ross <tross@apache.org> | 2011-01-10 14:06:16 +0000 |
|---|---|---|
| committer | Ted Ross <tross@apache.org> | 2011-01-10 14:06:16 +0000 |
| commit | 120ea440ef9d048d3bb31e6118027f5c9e890fca (patch) | |
| tree | 34e14880765c6b79c77c4fb24e834b8d67260149 /cpp/src/qmf/Schema.cpp | |
| parent | 598e5eacac716a9a3a812e9cf72b14bde57ed45a (diff) | |
| download | qpid-python-120ea440ef9d048d3bb31e6118027f5c9e890fca.tar.gz | |
Updates to the C++ implementation of QMFv2:
1) Consolidated string constants for the protocol into a definition file.
2) Added hooks for subscription handling.
3) Added checks to validate properties and arguments against the schema (if there is a schema).
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1057199 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qmf/Schema.cpp')
| -rw-r--r-- | cpp/src/qmf/Schema.cpp | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/cpp/src/qmf/Schema.cpp b/cpp/src/qmf/Schema.cpp index e003f9d06f..f25eb4635b 100644 --- a/cpp/src/qmf/Schema.cpp +++ b/cpp/src/qmf/Schema.cpp @@ -192,6 +192,55 @@ string SchemaImpl::asV1Content(uint32_t sequence) const } +bool SchemaImpl::isValidProperty(const std::string& k, const Variant& v) const +{ + for (list<SchemaProperty>::const_iterator iter = properties.begin(); iter != properties.end(); iter++) + if (iter->getName() == k) + return (isCompatibleType(iter->getType(), v.getType())); + return false; +} + + +bool SchemaImpl::isValidMethodInArg(const std::string& m, const std::string& k, const Variant& v) const +{ + for (list<SchemaMethod>::const_iterator mIter = methods.begin(); mIter != methods.end(); mIter++) { + if (mIter->getName() == m) { + uint32_t count(mIter->getArgumentCount()); + for (uint32_t i = 0; i < count; i++) { + const SchemaProperty prop(mIter->getArgument(i)); + if (prop.getName() == k) { + if (prop.getDirection() == DIR_IN || prop.getDirection() == DIR_IN_OUT) + return (isCompatibleType(prop.getType(), v.getType())); + else + return false; + } + } + } + } + return false; +} + + +bool SchemaImpl::isValidMethodOutArg(const std::string& m, const std::string& k, const Variant& v) const +{ + for (list<SchemaMethod>::const_iterator mIter = methods.begin(); mIter != methods.end(); mIter++) { + if (mIter->getName() == m) { + uint32_t count(mIter->getArgumentCount()); + for (uint32_t i = 0; i < count; i++) { + const SchemaProperty prop(mIter->getArgument(i)); + if (prop.getName() == k) { + if (prop.getDirection() == DIR_OUT || prop.getDirection() == DIR_IN_OUT) + return (isCompatibleType(prop.getType(), v.getType())); + else + return false; + } + } + } + } + return false; +} + + void SchemaImpl::finalize() { Hash hash; @@ -246,6 +295,57 @@ void SchemaImpl::checkNotFinal() const } +bool SchemaImpl::isCompatibleType(int qmfType, qpid::types::VariantType qpidType) const +{ + bool typeValid(false); + + switch (qpidType) { + case qpid::types::VAR_VOID: + if (qmfType == SCHEMA_DATA_VOID) + typeValid = true; + break; + case qpid::types::VAR_BOOL: + if (qmfType == SCHEMA_DATA_BOOL) + typeValid = true; + break; + case qpid::types::VAR_UINT8: + case qpid::types::VAR_UINT16: + case qpid::types::VAR_UINT32: + case qpid::types::VAR_UINT64: + case qpid::types::VAR_INT8: + case qpid::types::VAR_INT16: + case qpid::types::VAR_INT32: + case qpid::types::VAR_INT64: + if (qmfType == SCHEMA_DATA_INT) + typeValid = true; + break; + case qpid::types::VAR_FLOAT: + case qpid::types::VAR_DOUBLE: + if (qmfType == SCHEMA_DATA_FLOAT) + typeValid = true; + break; + case qpid::types::VAR_STRING: + if (qmfType == SCHEMA_DATA_STRING) + typeValid = true; + break; + case qpid::types::VAR_MAP: + if (qmfType == SCHEMA_DATA_BOOL) + typeValid = true; + break; + case qpid::types::VAR_LIST: + if (qmfType == SCHEMA_DATA_LIST) + typeValid = true; + break; + case qpid::types::VAR_UUID: + if (qmfType == SCHEMA_DATA_UUID) + typeValid = true; + break; + } + + return typeValid; +} + + SchemaImpl& SchemaImplAccess::get(Schema& item) { return *item.impl; |
