Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id EE564200AF9 for ; Thu, 5 May 2016 15:46:43 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id ED065160A0B; Thu, 5 May 2016 13:46:43 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id AC7FA160A14 for ; Thu, 5 May 2016 15:46:41 +0200 (CEST) Received: (qmail 90402 invoked by uid 500); 5 May 2016 13:46:40 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 89565 invoked by uid 99); 5 May 2016 13:46:38 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 May 2016 13:46:38 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9578FE93E5; Thu, 5 May 2016 13:46:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.apache.org Date: Thu, 05 May 2016 13:46:53 -0000 Message-Id: In-Reply-To: <6bf70c6f35704c72b4d9c64edc021f12@git.apache.org> References: <6bf70c6f35704c72b4d9c64edc021f12@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [16/31] ignite git commit: IGNITE-1786: Implemented ODBC driver. archived-at: Thu, 05 May 2016 13:46:44 -0000 http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/core/src/binary/binary_type.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/binary/binary_type.cpp b/modules/platforms/cpp/core/src/binary/binary_type.cpp deleted file mode 100644 index 19d906d..0000000 --- a/modules/platforms/cpp/core/src/binary/binary_type.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/binary/binary_type.h" - -namespace ignite -{ - namespace binary - { - int32_t GetBinaryStringHashCode(const char* val) - { - if (val) - { - int32_t hash = 0; - - int i = 0; - - while (true) - { - char c = *(val + i++); - - if (c == '\0') - break; - - if ('A' <= c && c <= 'Z') - c = c | 0x20; - - hash = 31 * hash + c; - } - - return hash; - } - else - return 0; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/core/src/binary/binary_writer.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/binary/binary_writer.cpp b/modules/platforms/cpp/core/src/binary/binary_writer.cpp deleted file mode 100644 index 3247e66..0000000 --- a/modules/platforms/cpp/core/src/binary/binary_writer.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/impl/binary/binary_writer_impl.h" -#include "ignite/binary/binary_writer.h" - -using namespace ignite::impl::binary; - -namespace ignite -{ - namespace binary - { - BinaryWriter::BinaryWriter(BinaryWriterImpl* impl) : impl(impl) - { - // No-op. - } - - void BinaryWriter::WriteInt8(const char* fieldName, int8_t val) - { - impl->WriteInt8(fieldName, val); - } - - void BinaryWriter::WriteInt8Array(const char* fieldName, const int8_t* val, int32_t len) - { - impl->WriteInt8Array(fieldName, val, len); - } - - void BinaryWriter::WriteBool(const char* fieldName, bool val) - { - impl->WriteBool(fieldName, val); - } - - void BinaryWriter::WriteBoolArray(const char* fieldName, const bool* val, int32_t len) - { - impl->WriteBoolArray(fieldName, val, len); - } - - void BinaryWriter::WriteInt16(const char* fieldName, int16_t val) - { - impl->WriteInt16(fieldName, val); - } - - void BinaryWriter::WriteInt16Array(const char* fieldName, const int16_t* val, int32_t len) - { - impl->WriteInt16Array(fieldName, val, len); - } - - void BinaryWriter::WriteUInt16(const char* fieldName, uint16_t val) - { - impl->WriteUInt16(fieldName, val); - } - - void BinaryWriter::WriteUInt16Array(const char* fieldName, const uint16_t* val, int32_t len) - { - impl->WriteUInt16Array(fieldName, val, len); - } - - void BinaryWriter::WriteInt32(const char* fieldName, int32_t val) - { - impl->WriteInt32(fieldName, val); - } - - void BinaryWriter::WriteInt32Array(const char* fieldName, const int32_t* val, int32_t len) - { - impl->WriteInt32Array(fieldName, val, len); - } - - void BinaryWriter::WriteInt64(const char* fieldName, const int64_t val) - { - impl->WriteInt64(fieldName, val); - } - - void BinaryWriter::WriteInt64Array(const char* fieldName, const int64_t* val, int32_t len) - { - impl->WriteInt64Array(fieldName, val, len); - } - - void BinaryWriter::WriteFloat(const char* fieldName, float val) - { - impl->WriteFloat(fieldName, val); - } - - void BinaryWriter::WriteFloatArray(const char* fieldName, const float* val, int32_t len) - { - impl->WriteFloatArray(fieldName, val, len); - } - - void BinaryWriter::WriteDouble(const char* fieldName, double val) - { - impl->WriteDouble(fieldName, val); - } - - void BinaryWriter::WriteDoubleArray(const char* fieldName, const double* val, int32_t len) - { - impl->WriteDoubleArray(fieldName, val, len); - } - - void BinaryWriter::WriteGuid(const char* fieldName, const Guid& val) - { - impl->WriteGuid(fieldName, val); - } - - void BinaryWriter::WriteGuidArray(const char* fieldName, const Guid* val, const int32_t len) - { - impl->WriteGuidArray(fieldName, val, len); - } - - void BinaryWriter::WriteString(const char* fieldName, const char* val) - { - if (val) - WriteString(fieldName, val, static_cast(strlen(val))); - else - WriteNull(fieldName); - } - - void BinaryWriter::WriteString(const char* fieldName, const char* val, int32_t len) - { - impl->WriteString(fieldName, val, len); - } - - BinaryStringArrayWriter BinaryWriter::WriteStringArray(const char* fieldName) - { - int32_t id = impl->WriteStringArray(fieldName); - - return BinaryStringArrayWriter(impl, id); - } - - void BinaryWriter::WriteNull(const char* fieldName) - { - impl->WriteNull(fieldName); - } - - BinaryRawWriter BinaryWriter::RawWriter() - { - impl->SetRawMode(); - - return BinaryRawWriter(impl); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/core/src/guid.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/guid.cpp b/modules/platforms/cpp/core/src/guid.cpp deleted file mode 100644 index 77997e4..0000000 --- a/modules/platforms/cpp/core/src/guid.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/guid.h" - -namespace ignite -{ - Guid::Guid() : most(0), least(0) - { - // No-op. - } - - Guid::Guid(int64_t most, int64_t least) : most(most), least(least) - { - // No-op. - } - - int64_t Guid::GetMostSignificantBits() const - { - return most; - } - - int64_t Guid::GetLeastSignificantBits() const - { - return least; - } - - int32_t Guid::GetVersion() const - { - return static_cast((most >> 12) & 0x0f); - } - - int32_t Guid::GetVariant() const - { - uint64_t least0 = static_cast(least); - - return static_cast((least0 >> (64 - (least0 >> 62))) & (least >> 63)); - } - - int32_t Guid::GetHashCode() const - { - int64_t hilo = most ^ least; - - return static_cast(hilo >> 32) ^ static_cast(hilo); - } - - bool operator==(Guid& val1, Guid& val2) - { - return val1.least == val2.least && val1.most == val2.most; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/core/src/ignite.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/ignite.cpp b/modules/platforms/cpp/core/src/ignite.cpp index 70a2c8d..0871661 100644 --- a/modules/platforms/cpp/core/src/ignite.cpp +++ b/modules/platforms/cpp/core/src/ignite.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ -#include +#include #include "ignite/impl/ignite_impl.h" #include "ignite/ignite.h" http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/core/src/ignite_error.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/ignite_error.cpp b/modules/platforms/cpp/core/src/ignite_error.cpp deleted file mode 100644 index 9963aa5..0000000 --- a/modules/platforms/cpp/core/src/ignite_error.cpp +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include - -#include "ignite/impl/utils.h" -#include "ignite/ignite_error.h" - -using namespace ignite::common::java; -using namespace ignite::impl::utils; - -namespace ignite -{ - void IgniteError::ThrowIfNeeded(IgniteError& err) - { - if (err.code != IGNITE_SUCCESS) - throw err; - } - - IgniteError::IgniteError() : - code(IGNITE_SUCCESS), - msg(NULL) - { - // No-op. - } - - IgniteError::IgniteError(int32_t code) : - code(code), - msg(NULL) - { - } - - IgniteError::IgniteError(int32_t code, const char* msg) : - code(code), - msg(CopyChars(msg)) - { - // No-op. - } - - IgniteError::IgniteError(const IgniteError& other) : - code(other.code), - msg(CopyChars(other.msg)) - { - // No-op. - } - - IgniteError& IgniteError::operator=(const IgniteError& other) - { - if (this != &other) - { - IgniteError tmp(other); - - int tmpCode = code; - char* tmpMsg = msg; - - code = tmp.code; - msg = tmp.msg; - - tmp.code = tmpCode; - tmp.msg = tmpMsg; - } - - return *this; - } - - IgniteError::~IgniteError() - { - ReleaseChars(msg); - } - - int32_t IgniteError::GetCode() const - { - return code; - } - - const char* IgniteError::GetText() const IGNITE_NO_THROW - { - if (code == IGNITE_SUCCESS) - return "Operation completed successfully."; - else if (msg) - return msg; - else - return "No additional information available."; - } - - const char* IgniteError::what() const IGNITE_NO_THROW - { - return GetText(); - } - - void IgniteError::SetError(const int jniCode, const char* jniCls, const char* jniMsg, IgniteError* err) - { - if (jniCode == IGNITE_JNI_ERR_SUCCESS) - *err = IgniteError(); - else if (jniCode == IGNITE_JNI_ERR_GENERIC) - { - // The most common case when we have Java exception "in hands" and must map it to respective code. - if (jniCls) - { - std::string jniCls0 = jniCls; - - if (jniCls0.compare("java.lang.NoClassDefFoundError") == 0) - { - std::stringstream stream; - - stream << "Java class is not found (did you set IGNITE_HOME environment variable?)"; - - if (jniMsg) - stream << ": " << jniMsg; - - *err = IgniteError(IGNITE_ERR_JVM_NO_CLASS_DEF_FOUND, stream.str().c_str()); - } - else if (jniCls0.compare("java.lang.NoSuchMethodError") == 0) - { - std::stringstream stream; - - stream << "Java method is not found (did you set IGNITE_HOME environment variable?)"; - - if (jniMsg) - stream << ": " << jniMsg; - - *err = IgniteError(IGNITE_ERR_JVM_NO_SUCH_METHOD, stream.str().c_str()); - } - else if (jniCls0.compare("java.lang.IllegalArgumentException") == 0) - *err = IgniteError(IGNITE_ERR_ILLEGAL_ARGUMENT, jniMsg); - else if (jniCls0.compare("java.lang.IllegalStateException") == 0) - *err = IgniteError(IGNITE_ERR_ILLEGAL_STATE, jniMsg); - else if (jniCls0.compare("java.lang.UnsupportedOperationException") == 0) - *err = IgniteError(IGNITE_ERR_UNSUPPORTED_OPERATION, jniMsg); - else if (jniCls0.compare("java.lang.InterruptedException") == 0) - *err = IgniteError(IGNITE_ERR_INTERRUPTED, jniMsg); - else if (jniCls0.compare("org.apache.ignite.cluster.ClusterGroupEmptyException") == 0) - *err = IgniteError(IGNITE_ERR_CLUSTER_GROUP_EMPTY, jniMsg); - else if (jniCls0.compare("org.apache.ignite.cluster.ClusterTopologyException") == 0) - *err = IgniteError(IGNITE_ERR_CLUSTER_TOPOLOGY, jniMsg); - else if (jniCls0.compare("org.apache.ignite.compute.ComputeExecutionRejectedException") == 0) - *err = IgniteError(IGNITE_ERR_COMPUTE_EXECUTION_REJECTED, jniMsg); - else if (jniCls0.compare("org.apache.ignite.compute.ComputeJobFailoverException") == 0) - *err = IgniteError(IGNITE_ERR_COMPUTE_JOB_FAILOVER, jniMsg); - else if (jniCls0.compare("org.apache.ignite.compute.ComputeTaskCancelledException") == 0) - *err = IgniteError(IGNITE_ERR_COMPUTE_TASK_CANCELLED, jniMsg); - else if (jniCls0.compare("org.apache.ignite.compute.ComputeTaskTimeoutException") == 0) - *err = IgniteError(IGNITE_ERR_COMPUTE_TASK_TIMEOUT, jniMsg); - else if (jniCls0.compare("org.apache.ignite.compute.ComputeUserUndeclaredException") == 0) - *err = IgniteError(IGNITE_ERR_COMPUTE_USER_UNDECLARED_EXCEPTION, jniMsg); - else if (jniCls0.compare("javax.cache.CacheException") == 0) - *err = IgniteError(IGNITE_ERR_CACHE, jniMsg); - else if (jniCls0.compare("javax.cache.integration.CacheLoaderException") == 0) - *err = IgniteError(IGNITE_ERR_CACHE_LOADER, jniMsg); - else if (jniCls0.compare("javax.cache.integration.CacheWriterException") == 0) - *err = IgniteError(IGNITE_ERR_CACHE_WRITER, jniMsg); - else if (jniCls0.compare("javax.cache.processor.EntryProcessorException") == 0) - *err = IgniteError(IGNITE_ERR_ENTRY_PROCESSOR, jniMsg); - else if (jniCls0.compare("org.apache.ignite.cache.CacheAtomicUpdateTimeoutException") == 0) - *err = IgniteError(IGNITE_ERR_CACHE_ATOMIC_UPDATE_TIMEOUT, jniMsg); - else if (jniCls0.compare("org.apache.ignite.cache.CachePartialUpdateException") == 0) - *err = IgniteError(IGNITE_ERR_CACHE_PARTIAL_UPDATE, jniMsg); - else if (jniCls0.compare("org.apache.ignite.transactions.TransactionOptimisticException") == 0) - *err = IgniteError(IGNITE_ERR_TX_OPTIMISTIC, jniMsg); - else if (jniCls0.compare("org.apache.ignite.transactions.TransactionTimeoutException") == 0) - *err = IgniteError(IGNITE_ERR_TX_TIMEOUT, jniMsg); - else if (jniCls0.compare("org.apache.ignite.transactions.TransactionRollbackException") == 0) - *err = IgniteError(IGNITE_ERR_TX_ROLLBACK, jniMsg); - else if (jniCls0.compare("org.apache.ignite.transactions.TransactionHeuristicException") == 0) - *err = IgniteError(IGNITE_ERR_TX_HEURISTIC, jniMsg); - else if (jniCls0.compare("org.apache.ignite.IgniteAuthenticationException") == 0) - *err = IgniteError(IGNITE_ERR_AUTHENTICATION, jniMsg); - else if (jniCls0.compare("org.apache.ignite.plugin.security.GridSecurityException") == 0) - *err = IgniteError(IGNITE_ERR_SECURITY, jniMsg); - else if (jniCls0.compare("org.apache.ignite.IgniteException") == 0) - *err = IgniteError(IGNITE_ERR_GENERIC, jniMsg); - else if (jniCls0.compare("org.apache.ignite.IgniteCheckedException") == 0) - *err = IgniteError(IGNITE_ERR_GENERIC, jniMsg); - else - { - std::stringstream stream; - - stream << "Java exception occurred [cls=" << jniCls0; - - if (jniMsg) - stream << ", msg=" << jniMsg; - - stream << "]"; - - *err = IgniteError(IGNITE_ERR_UNKNOWN, stream.str().c_str()); - } - } - else - { - // JNI class name is not available. Something really weird. - *err = IgniteError(IGNITE_ERR_UNKNOWN); - } - } - else if (jniCode == IGNITE_JNI_ERR_JVM_INIT) - { - std::stringstream stream; - - stream << "Failed to initialize JVM [errCls="; - - if (jniCls) - stream << jniCls; - else - stream << "N/A"; - - stream << ", errMsg="; - - if (jniMsg) - stream << jniMsg; - else - stream << "N/A"; - - stream << "]"; - - *err = IgniteError(IGNITE_ERR_JVM_INIT, stream.str().c_str()); - } - else if (jniCode == IGNITE_JNI_ERR_JVM_ATTACH) - *err = IgniteError(IGNITE_ERR_JVM_ATTACH, "Failed to attach to JVM."); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/core/src/ignition.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/ignition.cpp b/modules/platforms/cpp/core/src/ignition.cpp index edac373..4a7d941 100644 --- a/modules/platforms/cpp/core/src/ignition.cpp +++ b/modules/platforms/cpp/core/src/ignition.cpp @@ -19,18 +19,22 @@ #include #include -#include -#include +#include +#include +#include +#include +#include "ignite/ignition.h" #include "ignite/impl/ignite_environment.h" #include "ignite/impl/ignite_impl.h" -#include "ignite/impl/utils.h" -#include "ignite/ignition.h" +using namespace ignite::common; using namespace ignite::common::concurrent; -using namespace ignite::common::java; + +using namespace ignite::jni; +using namespace ignite::jni::java; + using namespace ignite::impl; -using namespace ignite::impl::utils; namespace ignite { http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/core/src/impl/binary/binary_reader_impl.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/binary/binary_reader_impl.cpp b/modules/platforms/cpp/core/src/impl/binary/binary_reader_impl.cpp deleted file mode 100644 index 5fcbc75..0000000 --- a/modules/platforms/cpp/core/src/impl/binary/binary_reader_impl.cpp +++ /dev/null @@ -1,760 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/impl/interop/interop.h" -#include "ignite/impl/binary/binary_common.h" -#include "ignite/impl/binary/binary_id_resolver.h" -#include "ignite/impl/binary/binary_reader_impl.h" -#include "ignite/impl/binary/binary_utils.h" -#include "ignite/binary/binary_type.h" -#include "ignite/ignite_error.h" -#include "ignite/impl/interop/interop_stream_position_guard.h" - -using namespace ignite::impl::interop; -using namespace ignite::impl::binary; -using namespace ignite::binary; - -namespace ignite -{ - namespace impl - { - namespace binary - { - BinaryReaderImpl::BinaryReaderImpl(InteropInputStream* stream, BinaryIdResolver* idRslvr, - int32_t pos, bool usrType, int32_t typeId, int32_t hashCode, int32_t len, int32_t rawOff, - int32_t footerBegin, int32_t footerEnd, BinaryOffsetType schemaType) : - stream(stream), idRslvr(idRslvr), pos(pos), usrType(usrType), typeId(typeId), - hashCode(hashCode), len(len), rawOff(rawOff), rawMode(false), elemIdGen(0), elemId(0), - elemCnt(-1), elemRead(0), footerBegin(footerBegin), footerEnd(footerEnd), schemaType(schemaType) - { - // No-op. - } - - BinaryReaderImpl::BinaryReaderImpl(InteropInputStream* stream) : - stream(stream), idRslvr(NULL), pos(0), usrType(false), typeId(0), hashCode(0), len(0), - rawOff(0), rawMode(true), elemIdGen(0), elemId(0), elemCnt(-1), elemRead(0), footerBegin(-1), - footerEnd(-1), schemaType(OFFSET_TYPE_FOUR_BYTES) - { - // No-op. - } - - int8_t BinaryReaderImpl::ReadInt8() - { - return ReadRaw(BinaryUtils::ReadInt8); - } - - int32_t BinaryReaderImpl::ReadInt8Array(int8_t* res, const int32_t len) - { - return ReadRawArray(res, len, BinaryUtils::ReadInt8Array, IGNITE_TYPE_ARRAY_BYTE); - } - - int8_t BinaryReaderImpl::ReadInt8(const char* fieldName) - { - return Read(fieldName, BinaryUtils::ReadInt8, IGNITE_TYPE_BYTE, static_cast(0)); - } - - int32_t BinaryReaderImpl::ReadInt8Array(const char* fieldName, int8_t* res, const int32_t len) - { - return ReadArray(fieldName, res, len,BinaryUtils::ReadInt8Array, IGNITE_TYPE_ARRAY_BYTE); - } - - bool BinaryReaderImpl::ReadBool() - { - return ReadRaw(BinaryUtils::ReadBool); - } - - int32_t BinaryReaderImpl::ReadBoolArray(bool* res, const int32_t len) - { - return ReadRawArray(res, len, BinaryUtils::ReadBoolArray, IGNITE_TYPE_ARRAY_BOOL); - } - - bool BinaryReaderImpl::ReadBool(const char* fieldName) - { - return Read(fieldName, BinaryUtils::ReadBool, IGNITE_TYPE_BOOL, static_cast(0)); - } - - int32_t BinaryReaderImpl::ReadBoolArray(const char* fieldName, bool* res, const int32_t len) - { - return ReadArray(fieldName, res, len,BinaryUtils::ReadBoolArray, IGNITE_TYPE_ARRAY_BOOL); - } - - int16_t BinaryReaderImpl::ReadInt16() - { - return ReadRaw(BinaryUtils::ReadInt16); - } - - int32_t BinaryReaderImpl::ReadInt16Array(int16_t* res, const int32_t len) - { - return ReadRawArray(res, len, BinaryUtils::ReadInt16Array, IGNITE_TYPE_ARRAY_SHORT); - } - - int16_t BinaryReaderImpl::ReadInt16(const char* fieldName) - { - return Read(fieldName, BinaryUtils::ReadInt16, IGNITE_TYPE_SHORT, static_cast(0)); - } - - int32_t BinaryReaderImpl::ReadInt16Array(const char* fieldName, int16_t* res, const int32_t len) - { - return ReadArray(fieldName, res, len, BinaryUtils::ReadInt16Array, IGNITE_TYPE_ARRAY_SHORT); - } - - uint16_t BinaryReaderImpl::ReadUInt16() - { - return ReadRaw(BinaryUtils::ReadUInt16); - } - - int32_t BinaryReaderImpl::ReadUInt16Array(uint16_t* res, const int32_t len) - { - return ReadRawArray(res, len, BinaryUtils::ReadUInt16Array, IGNITE_TYPE_ARRAY_CHAR); - } - - uint16_t BinaryReaderImpl::ReadUInt16(const char* fieldName) - { - return Read(fieldName, BinaryUtils::ReadUInt16, IGNITE_TYPE_CHAR, static_cast(0)); - } - - int32_t BinaryReaderImpl::ReadUInt16Array(const char* fieldName, uint16_t* res, const int32_t len) - { - return ReadArray(fieldName, res, len,BinaryUtils::ReadUInt16Array, IGNITE_TYPE_ARRAY_CHAR); - } - - int32_t BinaryReaderImpl::ReadInt32() - { - return ReadRaw(BinaryUtils::ReadInt32); - } - - int32_t BinaryReaderImpl::ReadInt32Array(int32_t* res, const int32_t len) - { - return ReadRawArray(res, len, BinaryUtils::ReadInt32Array, IGNITE_TYPE_ARRAY_INT); - } - - int32_t BinaryReaderImpl::ReadInt32(const char* fieldName) - { - return Read(fieldName, BinaryUtils::ReadInt32, IGNITE_TYPE_INT, static_cast(0)); - } - - int32_t BinaryReaderImpl::ReadInt32Array(const char* fieldName, int32_t* res, const int32_t len) - { - return ReadArray(fieldName, res, len,BinaryUtils::ReadInt32Array, IGNITE_TYPE_ARRAY_INT); - } - - int64_t BinaryReaderImpl::ReadInt64() - { - return ReadRaw(BinaryUtils::ReadInt64); - } - - int32_t BinaryReaderImpl::ReadInt64Array(int64_t* res, const int32_t len) - { - return ReadRawArray(res, len, BinaryUtils::ReadInt64Array, IGNITE_TYPE_ARRAY_LONG); - } - - int64_t BinaryReaderImpl::ReadInt64(const char* fieldName) - { - return Read(fieldName, BinaryUtils::ReadInt64, IGNITE_TYPE_LONG, static_cast(0)); - } - - int32_t BinaryReaderImpl::ReadInt64Array(const char* fieldName, int64_t* res, const int32_t len) - { - return ReadArray(fieldName, res, len,BinaryUtils::ReadInt64Array, IGNITE_TYPE_ARRAY_LONG); - } - - float BinaryReaderImpl::ReadFloat() - { - return ReadRaw(BinaryUtils::ReadFloat); - } - - int32_t BinaryReaderImpl::ReadFloatArray(float* res, const int32_t len) - { - return ReadRawArray(res, len, BinaryUtils::ReadFloatArray, IGNITE_TYPE_ARRAY_FLOAT); - } - - float BinaryReaderImpl::ReadFloat(const char* fieldName) - { - return Read(fieldName, BinaryUtils::ReadFloat, IGNITE_TYPE_FLOAT, static_cast(0)); - } - - int32_t BinaryReaderImpl::ReadFloatArray(const char* fieldName, float* res, const int32_t len) - { - return ReadArray(fieldName, res, len,BinaryUtils::ReadFloatArray, IGNITE_TYPE_ARRAY_FLOAT); - } - - double BinaryReaderImpl::ReadDouble() - { - return ReadRaw(BinaryUtils::ReadDouble); - } - - int32_t BinaryReaderImpl::ReadDoubleArray(double* res, const int32_t len) - { - return ReadRawArray(res, len, BinaryUtils::ReadDoubleArray, IGNITE_TYPE_ARRAY_DOUBLE); - } - - double BinaryReaderImpl::ReadDouble(const char* fieldName) - { - return Read(fieldName, BinaryUtils::ReadDouble, IGNITE_TYPE_DOUBLE, static_cast(0)); - } - - int32_t BinaryReaderImpl::ReadDoubleArray(const char* fieldName, double* res, const int32_t len) - { - return ReadArray(fieldName, res, len,BinaryUtils::ReadDoubleArray, IGNITE_TYPE_ARRAY_DOUBLE); - } - - Guid BinaryReaderImpl::ReadGuid() - { - CheckRawMode(true); - CheckSingleMode(true); - - return ReadNullable(stream, BinaryUtils::ReadGuid, IGNITE_TYPE_UUID); - } - - int32_t BinaryReaderImpl::ReadGuidArray(Guid* res, const int32_t len) - { - CheckRawMode(true); - CheckSingleMode(true); - - return ReadArrayInternal(res, len, stream, ReadGuidArrayInternal, IGNITE_TYPE_ARRAY_UUID); - } - - Guid BinaryReaderImpl::ReadGuid(const char* fieldName) - { - CheckRawMode(false); - CheckSingleMode(true); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - return Guid(); - - stream->Position(fieldPos); - - return ReadNullable(stream, BinaryUtils::ReadGuid, IGNITE_TYPE_UUID); - } - - int32_t BinaryReaderImpl::ReadGuidArray(const char* fieldName, Guid* res, const int32_t len) - { - CheckRawMode(false); - CheckSingleMode(true); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - return -1; - - stream->Position(fieldPos); - - int32_t realLen = ReadArrayInternal(res, len, stream, ReadGuidArrayInternal, IGNITE_TYPE_ARRAY_UUID); - - return realLen; - } - - void BinaryReaderImpl::ReadGuidArrayInternal(InteropInputStream* stream, Guid* res, const int32_t len) - { - for (int i = 0; i < len; i++) - *(res + i) = ReadNullable(stream, BinaryUtils::ReadGuid, IGNITE_TYPE_UUID); - } - - int32_t BinaryReaderImpl::ReadString(char* res, const int32_t len) - { - CheckRawMode(true); - CheckSingleMode(true); - - return ReadStringInternal(res, len); - } - - int32_t BinaryReaderImpl::ReadString(const char* fieldName, char* res, const int32_t len) - { - CheckRawMode(false); - CheckSingleMode(true); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - return -1; - - stream->Position(fieldPos); - - int32_t realLen = ReadStringInternal(res, len); - - return realLen; - } - - int32_t BinaryReaderImpl::ReadStringArray(int32_t* size) - { - return StartContainerSession(true, IGNITE_TYPE_ARRAY_STRING, size); - } - - int32_t BinaryReaderImpl::ReadStringArray(const char* fieldName, int32_t* size) - { - CheckRawMode(false); - CheckSingleMode(true); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - { - *size = -1; - - return ++elemIdGen; - } - - stream->Position(fieldPos); - - return StartContainerSession(false, IGNITE_TYPE_ARRAY_STRING, size); - } - - int32_t BinaryReaderImpl::ReadStringElement(int32_t id, char* res, const int32_t len) - { - CheckSession(id); - - int32_t posBefore = stream->Position(); - - int32_t realLen = ReadStringInternal(res, len); - - int32_t posAfter = stream->Position(); - - if (posAfter > posBefore && ++elemRead == elemCnt) { - elemId = 0; - elemCnt = -1; - elemRead = 0; - } - - return realLen; - } - - int32_t BinaryReaderImpl::ReadStringInternal(char* res, const int32_t len) - { - int8_t hdr = stream->ReadInt8(); - - if (hdr == IGNITE_TYPE_STRING) { - int32_t realLen = stream->ReadInt32(); - - if (res && len >= realLen) { - for (int i = 0; i < realLen; i++) - *(res + i) = static_cast(stream->ReadInt8()); - - if (len > realLen) - *(res + realLen) = 0; // Set NULL terminator if possible. - } - else - stream->Position(stream->Position() - 4 - 1); - - return realLen; - } - else if (hdr != IGNITE_HDR_NULL) - ThrowOnInvalidHeader(IGNITE_TYPE_ARRAY, hdr); - - return -1; - } - - int32_t BinaryReaderImpl::ReadArray(int32_t* size) - { - return StartContainerSession(true, IGNITE_TYPE_ARRAY, size); - } - - int32_t BinaryReaderImpl::ReadArray(const char* fieldName, int32_t* size) - { - CheckRawMode(false); - CheckSingleMode(true); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - { - *size = -1; - - return ++elemIdGen; - } - - stream->Position(fieldPos); - - return StartContainerSession(false, IGNITE_TYPE_ARRAY, size); - } - - int32_t BinaryReaderImpl::ReadCollection(CollectionType* typ, int32_t* size) - { - int32_t id = StartContainerSession(true, IGNITE_TYPE_COLLECTION, size); - - if (*size == -1) - *typ = IGNITE_COLLECTION_UNDEFINED; - else - *typ = static_cast(stream->ReadInt8()); - - return id; - } - - int32_t BinaryReaderImpl::ReadCollection(const char* fieldName, CollectionType* typ, int32_t* size) - { - CheckRawMode(false); - CheckSingleMode(true); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - { - *typ = IGNITE_COLLECTION_UNDEFINED; - *size = -1; - - return ++elemIdGen; - } - - stream->Position(fieldPos); - - int32_t id = StartContainerSession(false, IGNITE_TYPE_COLLECTION, size); - - if (*size == -1) - *typ = IGNITE_COLLECTION_UNDEFINED; - else - *typ = static_cast(stream->ReadInt8()); - - return id; - } - - int32_t BinaryReaderImpl::ReadMap(MapType* typ, int32_t* size) - { - int32_t id = StartContainerSession(true, IGNITE_TYPE_MAP, size); - - if (*size == -1) - *typ = IGNITE_MAP_UNDEFINED; - else - *typ = static_cast(stream->ReadInt8()); - - return id; - } - - int32_t BinaryReaderImpl::ReadMap(const char* fieldName, MapType* typ, int32_t* size) - { - CheckRawMode(false); - CheckSingleMode(true); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - { - *typ = IGNITE_MAP_UNDEFINED; - *size = -1; - - return ++elemIdGen; - } - - stream->Position(fieldPos); - - int32_t id = StartContainerSession(false, IGNITE_TYPE_MAP, size); - - if (*size == -1) - *typ = IGNITE_MAP_UNDEFINED; - else - *typ = static_cast(stream->ReadInt8()); - - return id; - } - - CollectionType BinaryReaderImpl::ReadCollectionTypeUnprotected() - { - int32_t size = ReadCollectionSizeUnprotected(); - if (size == -1) - return IGNITE_COLLECTION_UNDEFINED; - - CollectionType typ = static_cast(stream->ReadInt8()); - - return typ; - } - - CollectionType BinaryReaderImpl::ReadCollectionType() - { - InteropStreamPositionGuard positionGuard(*stream); - - return ReadCollectionTypeUnprotected(); - } - - CollectionType BinaryReaderImpl::ReadCollectionType(const char* fieldName) - { - CheckRawMode(false); - CheckSingleMode(true); - - InteropStreamPositionGuard positionGuard(*stream); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - return IGNITE_COLLECTION_UNDEFINED; - - stream->Position(fieldPos); - - return ReadCollectionTypeUnprotected(); - } - - int32_t BinaryReaderImpl::ReadCollectionSizeUnprotected() - { - int8_t hdr = stream->ReadInt8(); - - if (hdr != IGNITE_TYPE_COLLECTION) - { - if (hdr != IGNITE_HDR_NULL) - ThrowOnInvalidHeader(IGNITE_TYPE_COLLECTION, hdr); - - return -1; - } - - int32_t size = stream->ReadInt32(); - - return size; - } - - int32_t BinaryReaderImpl::ReadCollectionSize() - { - InteropStreamPositionGuard positionGuard(*stream); - - return ReadCollectionSizeUnprotected(); - } - - int32_t BinaryReaderImpl::ReadCollectionSize(const char* fieldName) - { - CheckRawMode(false); - CheckSingleMode(true); - - InteropStreamPositionGuard positionGuard(*stream); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - return -1; - - stream->Position(fieldPos); - - return ReadCollectionSizeUnprotected(); - } - - bool BinaryReaderImpl::HasNextElement(int32_t id) const - { - return elemId == id && elemRead < elemCnt; - } - - void BinaryReaderImpl::SetRawMode() - { - CheckRawMode(false); - CheckSingleMode(true); - - stream->Position(pos + rawOff); - rawMode = true; - } - - template <> - int8_t BinaryReaderImpl::ReadTopObject() - { - return ReadTopObject0(IGNITE_TYPE_BYTE, BinaryUtils::ReadInt8, static_cast(0)); - } - - template <> - bool BinaryReaderImpl::ReadTopObject() - { - return ReadTopObject0(IGNITE_TYPE_BOOL, BinaryUtils::ReadBool, static_cast(0)); - } - - template <> - int16_t BinaryReaderImpl::ReadTopObject() - { - return ReadTopObject0(IGNITE_TYPE_SHORT, BinaryUtils::ReadInt16, static_cast(0)); - } - - template <> - uint16_t BinaryReaderImpl::ReadTopObject() - { - return ReadTopObject0(IGNITE_TYPE_CHAR, BinaryUtils::ReadUInt16, static_cast(0)); - } - - template <> - int32_t BinaryReaderImpl::ReadTopObject() - { - return ReadTopObject0(IGNITE_TYPE_INT, BinaryUtils::ReadInt32, static_cast(0)); - } - - template <> - int64_t BinaryReaderImpl::ReadTopObject() - { - return ReadTopObject0(IGNITE_TYPE_LONG, BinaryUtils::ReadInt64, static_cast(0)); - } - - template <> - float BinaryReaderImpl::ReadTopObject() - { - return ReadTopObject0(IGNITE_TYPE_FLOAT, BinaryUtils::ReadFloat, static_cast(0)); - } - - template <> - double BinaryReaderImpl::ReadTopObject() - { - return ReadTopObject0(IGNITE_TYPE_DOUBLE, BinaryUtils::ReadDouble, static_cast(0)); - } - - template <> - Guid BinaryReaderImpl::ReadTopObject() - { - int8_t typeId = stream->ReadInt8(); - - if (typeId == IGNITE_TYPE_UUID) - return BinaryUtils::ReadGuid(stream); - else if (typeId == IGNITE_HDR_NULL) - return Guid(); - else { - int32_t pos = stream->Position() - 1; - - IGNITE_ERROR_FORMATTED_3(IgniteError::IGNITE_ERR_BINARY, "Invalid header", "position", pos, "expected", IGNITE_TYPE_UUID, "actual", typeId) - } - } - - InteropInputStream* BinaryReaderImpl::GetStream() - { - return stream; - } - - int32_t BinaryReaderImpl::FindField(const int32_t fieldId) - { - InteropStreamPositionGuard streamGuard(*stream); - - stream->Position(footerBegin); - - switch (schemaType) - { - case OFFSET_TYPE_ONE_BYTE: - { - for (int32_t schemaPos = footerBegin; schemaPos < footerEnd; schemaPos += 5) - { - int32_t currentFieldId = stream->ReadInt32(schemaPos); - - if (fieldId == currentFieldId) - return static_cast(stream->ReadInt8(schemaPos + 4)) + pos; - } - break; - } - - case OFFSET_TYPE_TWO_BYTES: - { - for (int32_t schemaPos = footerBegin; schemaPos < footerEnd; schemaPos += 6) - { - int32_t currentFieldId = stream->ReadInt32(schemaPos); - - if (fieldId == currentFieldId) - return static_cast(stream->ReadInt16(schemaPos + 4)) + pos; - } - break; - } - - case OFFSET_TYPE_FOUR_BYTES: - { - for (int32_t schemaPos = footerBegin; schemaPos < footerEnd; schemaPos += 8) - { - int32_t currentFieldId = stream->ReadInt32(schemaPos); - - if (fieldId == currentFieldId) - return stream->ReadInt32(schemaPos + 4) + pos; - } - break; - } - } - - return -1; - } - - void BinaryReaderImpl::CheckRawMode(bool expected) const - { - if (expected && !rawMode) { - IGNITE_ERROR_1(IgniteError::IGNITE_ERR_BINARY, "Operation can be performed only in raw mode.") - } - else if (!expected && rawMode) { - IGNITE_ERROR_1(IgniteError::IGNITE_ERR_BINARY, "Operation cannot be performed in raw mode.") - } - } - - void BinaryReaderImpl::CheckSingleMode(bool expected) const - { - if (expected && elemId != 0) { - IGNITE_ERROR_1(IgniteError::IGNITE_ERR_BINARY, "Operation cannot be performed when container is being read."); - } - else if (!expected && elemId == 0) { - IGNITE_ERROR_1(IgniteError::IGNITE_ERR_BINARY, "Operation can be performed only when container is being read."); - } - } - - int32_t BinaryReaderImpl::StartContainerSession(bool expRawMode, int8_t expHdr, int32_t* size) - { - CheckRawMode(expRawMode); - CheckSingleMode(true); - - int8_t hdr = stream->ReadInt8(); - - if (hdr == expHdr) - { - int32_t cnt = stream->ReadInt32(); - - if (cnt != 0) - { - elemId = ++elemIdGen; - elemCnt = cnt; - elemRead = 0; - - *size = cnt; - - return elemId; - } - else - { - *size = 0; - - return ++elemIdGen; - } - } - else if (hdr == IGNITE_HDR_NULL) { - *size = -1; - - return ++elemIdGen; - } - else { - ThrowOnInvalidHeader(expHdr, hdr); - - return 0; - } - } - - void BinaryReaderImpl::CheckSession(int32_t expSes) const - { - if (elemId != expSes) { - IGNITE_ERROR_1(IgniteError::IGNITE_ERR_BINARY, "Containter read session has been finished or is not started yet."); - } - } - - void BinaryReaderImpl::ThrowOnInvalidHeader(int32_t pos, int8_t expHdr, int8_t hdr) - { - IGNITE_ERROR_FORMATTED_3(IgniteError::IGNITE_ERR_BINARY, "Invalid header", "position", pos, "expected", expHdr, "actual", hdr) - } - - void BinaryReaderImpl::ThrowOnInvalidHeader(int8_t expHdr, int8_t hdr) const - { - int32_t pos = stream->Position() - 1; - - ThrowOnInvalidHeader(pos, expHdr, hdr); - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/core/src/impl/binary/binary_schema.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/binary/binary_schema.cpp b/modules/platforms/cpp/core/src/impl/binary/binary_schema.cpp deleted file mode 100644 index 0b8025a..0000000 --- a/modules/platforms/cpp/core/src/impl/binary/binary_schema.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include - -#include "ignite/impl/binary/binary_schema.h" -#include "ignite/impl/binary/binary_writer_impl.h" - -/** FNV1 hash offset basis. */ -enum { FNV1_OFFSET_BASIS = 0x811C9DC5 }; - -/** FNV1 hash prime. */ -enum { FNV1_PRIME = 0x01000193 }; - -namespace ignite -{ - namespace impl - { - namespace binary - { - BinarySchema::BinarySchema(): id(0), fieldsInfo(new FieldContainer()) - { - // No-op. - } - - BinarySchema::~BinarySchema() - { - delete fieldsInfo; - } - - void BinarySchema::AddField(int32_t fieldId, int32_t offset) - { - if (!id) - { - // Initialize offset when the first field is written. - id = FNV1_OFFSET_BASIS; - } - - // Advance schema hash. - int32_t idAccumulator = id ^ (fieldId & 0xFF); - idAccumulator *= FNV1_PRIME; - idAccumulator ^= (fieldId >> 8) & 0xFF; - idAccumulator *= FNV1_PRIME; - idAccumulator ^= (fieldId >> 16) & 0xFF; - idAccumulator *= FNV1_PRIME; - idAccumulator ^= (fieldId >> 24) & 0xFF; - idAccumulator *= FNV1_PRIME; - - id = idAccumulator; - - BinarySchemaFieldInfo info = { fieldId, offset }; - fieldsInfo->push_back(info); - } - - void BinarySchema::Write(interop::InteropOutputStream& out) const - { - switch (GetType()) - { - case OFFSET_TYPE_ONE_BYTE: - { - for (FieldContainer::const_iterator i = fieldsInfo->begin(); i != fieldsInfo->end(); ++i) - { - out.WriteInt32(i->id); - out.WriteInt8(static_cast(i->offset)); - } - break; - } - - case OFFSET_TYPE_TWO_BYTES: - { - for (FieldContainer::const_iterator i = fieldsInfo->begin(); i != fieldsInfo->end(); ++i) - { - out.WriteInt32(i->id); - out.WriteInt16(static_cast(i->offset)); - } - break; - } - - case OFFSET_TYPE_FOUR_BYTES: - { - for (FieldContainer::const_iterator i = fieldsInfo->begin(); i != fieldsInfo->end(); ++i) - { - out.WriteInt32(i->id); - out.WriteInt32(i->offset); - } - break; - } - - default: - { - assert(false); - break; - } - } - } - - bool BinarySchema::Empty() const - { - return fieldsInfo->empty(); - } - - void BinarySchema::Clear() - { - id = 0; - fieldsInfo->clear(); - } - - BinaryOffsetType BinarySchema::GetType() const - { - int32_t maxOffset = fieldsInfo->back().offset; - - if (maxOffset < 0x100) - return OFFSET_TYPE_ONE_BYTE; - else if (maxOffset < 0x10000) - return OFFSET_TYPE_TWO_BYTES; - - return OFFSET_TYPE_FOUR_BYTES; - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/core/src/impl/binary/binary_type_handler.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/binary/binary_type_handler.cpp b/modules/platforms/cpp/core/src/impl/binary/binary_type_handler.cpp deleted file mode 100644 index 5e70707..0000000 --- a/modules/platforms/cpp/core/src/impl/binary/binary_type_handler.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/impl/binary/binary_type_handler.h" - -using namespace ignite::common::concurrent; - -namespace ignite -{ - namespace impl - { - namespace binary - { - BinaryTypeHandler::BinaryTypeHandler(SPSnap snap) : snap(snap), fieldIds(NULL), fields(NULL) - { - // No-op. - } - - BinaryTypeHandler::~BinaryTypeHandler() - { - if (fieldIds) - delete fieldIds; - - if (fields) - delete fields; - } - - void BinaryTypeHandler::OnFieldWritten(int32_t fieldId, std::string fieldName, int32_t fieldTypeId) - { - if (!snap.Get() || !snap.Get()->ContainsFieldId(fieldId)) - { - if (!HasDifference()) - { - fieldIds = new std::set(); - fields = new std::map(); - } - - fieldIds->insert(fieldId); - (*fields)[fieldName] = fieldTypeId; - } - } - - SPSnap BinaryTypeHandler::GetSnapshot() - { - return snap; - } - - bool BinaryTypeHandler::HasDifference() - { - return fieldIds ? true : false; - } - - std::set* BinaryTypeHandler::GetFieldIds() - { - return fieldIds; - } - - std::map* BinaryTypeHandler::GetFields() - { - return fields; - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/core/src/impl/binary/binary_type_manager.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/binary/binary_type_manager.cpp b/modules/platforms/cpp/core/src/impl/binary/binary_type_manager.cpp deleted file mode 100644 index 9bd115c..0000000 --- a/modules/platforms/cpp/core/src/impl/binary/binary_type_manager.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "ignite/impl/binary/binary_type_manager.h" - -using namespace ignite::common::concurrent; - -namespace ignite -{ - namespace impl - { - namespace binary - { - BinaryTypeManager::BinaryTypeManager() : - snapshots(SharedPointer>(new std::map)), - pending(new std::vector()), - cs(new CriticalSection()), - pendingVer(0), ver(0) - { - // No-op. - } - - BinaryTypeManager::~BinaryTypeManager() - { - pending->erase(pending->begin(), pending->end()); - - delete pending; - delete cs; - } - - SharedPointer BinaryTypeManager::GetHandler(int32_t typeId) - { - SharedPointer> snapshots0 = snapshots; - - SPSnap snapshot = (*snapshots0.Get())[typeId]; - - return SharedPointer(new BinaryTypeHandler(snapshot)); - } - - void BinaryTypeManager::SubmitHandler(std::string typeName, int32_t typeId, - BinaryTypeHandler* hnd) - { - Snap* snap = hnd->GetSnapshot().Get(); - - // If this is the very first write of a class or difference exists, - // we need to enqueue it for write. - if (!snap || hnd->HasDifference()) - { - std::set* newFieldIds = new std::set(); - std::map* newFields = new std::map(); - - CopyFields(snap, newFieldIds, newFields); - - if (hnd->HasDifference()) - { - std::set* diffFieldIds = hnd->GetFieldIds(); - std::map* diffFields = hnd->GetFields(); - - for (std::set::iterator it = diffFieldIds->begin(); it != diffFieldIds->end(); ++it) - newFieldIds->insert(*it); - - for (std::map::iterator it = diffFields->begin(); it != diffFields->end(); ++it) - (*newFields)[it->first] = it->second; - } - - Snap* diffSnap = new Snap(typeName, typeId, newFieldIds, newFields); - - cs->Enter(); - - pending->push_back(SPSnap(diffSnap)); - - pendingVer++; - - cs->Leave(); - } - } - - int32_t BinaryTypeManager::GetVersion() - { - Memory::Fence(); - - return ver; - } - - bool BinaryTypeManager::IsUpdatedSince(int32_t oldVer) - { - Memory::Fence(); - - return pendingVer > oldVer; - } - - bool BinaryTypeManager::ProcessPendingUpdates(BinaryTypeUpdater* updater, IgniteError* err) - { - bool success = true; // Optimistically assume that all will be fine. - - cs->Enter(); - - for (std::vector::iterator it = pending->begin(); it != pending->end(); ++it) - { - Snap* pendingSnap = (*it).Get(); - - if (updater->Update(pendingSnap, err)) - { - // Perform copy-on-write update of snapshot collection. - std::map* newSnapshots = new std::map(); - - bool snapshotFound = false; - - for (std::map::iterator snapIt = snapshots.Get()->begin(); - snapIt != snapshots.Get()->end(); ++snapIt) - { - int32_t curTypeId = snapIt->first; - Snap* curSnap = snapIt->second.Get(); - - if (pendingSnap->GetTypeId() == curTypeId) - { - // Have to create snapshot with updated fields. - std::set* newFieldIds = new std::set(); - std::map* newFields = new std::map(); - - // Add old fields. - CopyFields(curSnap, newFieldIds, newFields); - - // Add new fields. - CopyFields(pendingSnap, newFieldIds, newFields); - - // Create new snapshot. - Snap* newSnap = new Snap(pendingSnap->GetTypeName(), pendingSnap->GetTypeId(), - newFieldIds, newFields); - - (*newSnapshots)[curTypeId] = SPSnap(newSnap); - - snapshotFound = true; - } - else - (*newSnapshots)[curTypeId] = snapIt->second; // Just transfer exising snapshot. - } - - // Handle situation when completely new snapshot is found. - if (!snapshotFound) - (*newSnapshots)[pendingSnap->GetTypeId()] = *it; - - snapshots = SharedPointer>(newSnapshots); - } - else - { - // Stop as we cannot move further. - success = false; - - break; - } - } - - if (success) - { - pending->erase(pending->begin(), pending->end()); - - ver = pendingVer; - } - - cs->Leave(); - - return success; - } - - void BinaryTypeManager::CopyFields(Snap* snap, std::set* fieldIds, - std::map* fields) - { - if (snap && snap->HasFields()) - { - std::set* snapFieldIds = snap->GetFieldIds(); - std::map* snapFields = snap->GetFields(); - - for (std::set::iterator oldIt = snapFieldIds->begin(); - oldIt != snapFieldIds->end(); ++oldIt) - fieldIds->insert(*oldIt); - - for (std::map::iterator newFieldsIt = snapFields->begin(); - newFieldsIt != snapFields->end(); ++newFieldsIt) - (*fields)[newFieldsIt->first] = newFieldsIt->second; - } - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/core/src/impl/binary/binary_type_snapshot.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/binary/binary_type_snapshot.cpp b/modules/platforms/cpp/core/src/impl/binary/binary_type_snapshot.cpp deleted file mode 100644 index f34732f..0000000 --- a/modules/platforms/cpp/core/src/impl/binary/binary_type_snapshot.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/impl/binary/binary_type_snapshot.h" - -namespace ignite -{ - namespace impl - { - namespace binary - { - BinaryTypeSnapshot::BinaryTypeSnapshot(std::string typeName, int32_t typeId, - std::set* fieldIds, std::map* fields) : - typeName(typeName), typeId(typeId), fieldIds(fieldIds), fields(fields) - { - // No-op. - } - - BinaryTypeSnapshot::~BinaryTypeSnapshot() - { - delete fieldIds; - delete fields; - } - - bool BinaryTypeSnapshot::ContainsFieldId(int32_t fieldId) - { - return fieldIds && fieldIds->count(fieldId) == 1; - } - - std::string BinaryTypeSnapshot::GetTypeName() - { - return typeName; - } - - int32_t BinaryTypeSnapshot::GetTypeId() - { - return typeId; - } - - bool BinaryTypeSnapshot::HasFields() - { - return !fieldIds->empty(); - } - - std::set* BinaryTypeSnapshot::GetFieldIds() - { - return fieldIds; - } - - std::map* BinaryTypeSnapshot::GetFields() - { - return fields; - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/core/src/impl/binary/binary_type_updater.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/binary/binary_type_updater.cpp b/modules/platforms/cpp/core/src/impl/binary/binary_type_updater.cpp deleted file mode 100644 index b3436e9..0000000 --- a/modules/platforms/cpp/core/src/impl/binary/binary_type_updater.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/impl/binary/binary_type_updater.h" - -namespace ignite -{ - namespace impl - { - namespace binary - { - BinaryTypeUpdater::~BinaryTypeUpdater() - { - // No-op. - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/core/src/impl/binary/binary_type_updater_impl.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/binary/binary_type_updater_impl.cpp b/modules/platforms/cpp/core/src/impl/binary/binary_type_updater_impl.cpp index aedd73b..e6375a6 100644 --- a/modules/platforms/cpp/core/src/impl/binary/binary_type_updater_impl.cpp +++ b/modules/platforms/cpp/core/src/impl/binary/binary_type_updater_impl.cpp @@ -21,7 +21,8 @@ #include "ignite/binary/binary_raw_writer.h" using namespace ignite::common::concurrent; -using namespace ignite::common::java; +using namespace ignite::jni::java; +using namespace ignite::java; using namespace ignite::impl; using namespace ignite::impl::interop; using namespace ignite::binary; http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/core/src/impl/binary/binary_utils.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/binary/binary_utils.cpp b/modules/platforms/cpp/core/src/impl/binary/binary_utils.cpp deleted file mode 100644 index 8e26ea9..0000000 --- a/modules/platforms/cpp/core/src/impl/binary/binary_utils.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/impl/interop/interop.h" -#include "ignite/impl/binary/binary_utils.h" - -using namespace ignite::impl::interop; -using namespace ignite::impl::binary; - -namespace ignite -{ - namespace impl - { - namespace binary - { - int8_t BinaryUtils::ReadInt8(InteropInputStream* stream) - { - return stream->ReadInt8(); - } - - void BinaryUtils::WriteInt8(InteropOutputStream* stream, int8_t val) - { - stream->WriteInt8(val); - } - - void BinaryUtils::ReadInt8Array(InteropInputStream* stream, int8_t* res, const int32_t len) - { - stream->ReadInt8Array(res, len); - } - - void BinaryUtils::WriteInt8Array(InteropOutputStream* stream, const int8_t* val, const int32_t len) - { - stream->WriteInt8Array(val, len); - } - - bool BinaryUtils::ReadBool(InteropInputStream* stream) - { - return stream->ReadBool(); - } - - void BinaryUtils::WriteBool(InteropOutputStream* stream, bool val) - { - stream->WriteBool(val); - } - - void BinaryUtils::ReadBoolArray(InteropInputStream* stream, bool* res, const int32_t len) - { - stream->ReadBoolArray(res, len); - } - - void BinaryUtils::WriteBoolArray(InteropOutputStream* stream, const bool* val, const int32_t len) - { - stream->WriteBoolArray(val, len); - } - - int16_t BinaryUtils::ReadInt16(InteropInputStream* stream) - { - return stream->ReadInt16(); - } - - void BinaryUtils::WriteInt16(InteropOutputStream* stream, int16_t val) - { - stream->WriteInt16(val); - } - - void BinaryUtils::ReadInt16Array(InteropInputStream* stream, int16_t* res, const int32_t len) - { - stream->ReadInt16Array(res, len); - } - - void BinaryUtils::WriteInt16Array(InteropOutputStream* stream, const int16_t* val, const int32_t len) - { - stream->WriteInt16Array(val, len); - } - - uint16_t BinaryUtils::ReadUInt16(InteropInputStream* stream) - { - return stream->ReadUInt16(); - } - - void BinaryUtils::WriteUInt16(InteropOutputStream* stream, uint16_t val) - { - stream->WriteUInt16(val); - } - - void BinaryUtils::ReadUInt16Array(InteropInputStream* stream, uint16_t* res, const int32_t len) - { - stream->ReadUInt16Array(res, len); - } - - void BinaryUtils::WriteUInt16Array(InteropOutputStream* stream, const uint16_t* val, const int32_t len) - { - stream->WriteUInt16Array(val, len); - } - - int32_t BinaryUtils::ReadInt32(InteropInputStream* stream) - { - return stream->ReadInt32(); - } - - void BinaryUtils::WriteInt32(InteropOutputStream* stream, int32_t val) - { - stream->WriteInt32(val); - } - - void BinaryUtils::ReadInt32Array(InteropInputStream* stream, int32_t* res, const int32_t len) - { - stream->ReadInt32Array(res, len); - } - - void BinaryUtils::WriteInt32Array(InteropOutputStream* stream, const int32_t* val, const int32_t len) - { - stream->WriteInt32Array(val, len); - } - - int64_t BinaryUtils::ReadInt64(InteropInputStream* stream) - { - return stream->ReadInt64(); - } - - void BinaryUtils::WriteInt64(InteropOutputStream* stream, int64_t val) - { - stream->WriteInt64(val); - } - - void BinaryUtils::ReadInt64Array(InteropInputStream* stream, int64_t* res, const int32_t len) - { - stream->ReadInt64Array(res, len); - } - - void BinaryUtils::WriteInt64Array(InteropOutputStream* stream, const int64_t* val, const int32_t len) - { - stream->WriteInt64Array(val, len); - } - - float BinaryUtils::ReadFloat(InteropInputStream* stream) - { - return stream->ReadFloat(); - } - - void BinaryUtils::WriteFloat(InteropOutputStream* stream, float val) - { - stream->WriteFloat(val); - } - - void BinaryUtils::ReadFloatArray(InteropInputStream* stream, float* res, const int32_t len) - { - stream->ReadFloatArray(res, len); - } - - void BinaryUtils::WriteFloatArray(InteropOutputStream* stream, const float* val, const int32_t len) - { - stream->WriteFloatArray(val, len); - } - - double BinaryUtils::ReadDouble(InteropInputStream* stream) - { - return stream->ReadDouble(); - } - - void BinaryUtils::WriteDouble(InteropOutputStream* stream, double val) - { - stream->WriteDouble(val); - } - - void BinaryUtils::ReadDoubleArray(InteropInputStream* stream, double* res, const int32_t len) - { - stream->ReadDoubleArray(res, len); - } - - void BinaryUtils::WriteDoubleArray(InteropOutputStream* stream, const double* val, const int32_t len) - { - stream->WriteDoubleArray(val, len); - } - - Guid BinaryUtils::ReadGuid(interop::InteropInputStream* stream) - { - int64_t most = stream->ReadInt64(); - int64_t least = stream->ReadInt64(); - - return Guid(most, least); - } - - void BinaryUtils::WriteGuid(interop::InteropOutputStream* stream, const Guid val) - { - stream->WriteInt64(val.GetMostSignificantBits()); - stream->WriteInt64(val.GetLeastSignificantBits()); - } - - void BinaryUtils::WriteString(interop::InteropOutputStream* stream, const char* val, const int32_t len) - { - stream->WriteInt32(len); - stream->WriteInt8Array(reinterpret_cast(val), len); - } - } - } -} \ No newline at end of file