You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/09/03 19:15:50 UTC
[01/11] ignite git commit: IGNITE-1364: Squashed commit from initial
branch.
Repository: ignite
Updated Branches:
refs/heads/ignite-1364-1 [created] 1fc06e013
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/impl/portable/portable_reader_impl.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/portable/portable_reader_impl.cpp b/modules/platform/src/main/cpp/core/src/impl/portable/portable_reader_impl.cpp
new file mode 100644
index 0000000..753ec25
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/portable/portable_reader_impl.cpp
@@ -0,0 +1,683 @@
+/*
+ * 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/portable/portable_common.h"
+#include "ignite/impl/portable/portable_id_resolver.h"
+#include "ignite/impl/portable/portable_reader_impl.h"
+#include "ignite/impl/portable/portable_utils.h"
+#include "ignite/portable/portable_type.h"
+#include "ignite/ignite_error.h"
+
+using namespace ignite::impl::interop;
+using namespace ignite::impl::portable;
+using namespace ignite::portable;
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ PortableReaderImpl::PortableReaderImpl(InteropInputStream* stream, PortableIdResolver* idRslvr,
+ int32_t pos, bool usrType, int32_t typeId, int32_t hashCode, int32_t len, int32_t rawOff) :
+ 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)
+ {
+ // No-op.
+ }
+
+ PortableReaderImpl::PortableReaderImpl(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)
+ {
+ // No-op.
+ }
+
+ int8_t PortableReaderImpl::ReadInt8()
+ {
+ return ReadRaw<int8_t>(PortableUtils::ReadInt8);
+ }
+
+ int32_t PortableReaderImpl::ReadInt8Array(int8_t* res, const int32_t len)
+ {
+ return ReadRawArray<int8_t>(res, len, PortableUtils::ReadInt8Array, IGNITE_TYPE_ARRAY_BYTE);
+ }
+
+ int8_t PortableReaderImpl::ReadInt8(const char* fieldName)
+ {
+ return Read(fieldName, PortableUtils::ReadInt8, IGNITE_TYPE_BYTE, static_cast<int8_t>(0));
+ }
+
+ int32_t PortableReaderImpl::ReadInt8Array(const char* fieldName, int8_t* res, const int32_t len)
+ {
+ return ReadArray<int8_t>(fieldName, res, len,PortableUtils::ReadInt8Array, IGNITE_TYPE_ARRAY_BYTE);
+ }
+
+ bool PortableReaderImpl::ReadBool()
+ {
+ return ReadRaw<bool>(PortableUtils::ReadBool);
+ }
+
+ int32_t PortableReaderImpl::ReadBoolArray(bool* res, const int32_t len)
+ {
+ return ReadRawArray<bool>(res, len, PortableUtils::ReadBoolArray, IGNITE_TYPE_ARRAY_BOOL);
+ }
+
+ bool PortableReaderImpl::ReadBool(const char* fieldName)
+ {
+ return Read(fieldName, PortableUtils::ReadBool, IGNITE_TYPE_BOOL, static_cast<bool>(0));
+ }
+
+ int32_t PortableReaderImpl::ReadBoolArray(const char* fieldName, bool* res, const int32_t len)
+ {
+ return ReadArray<bool>(fieldName, res, len,PortableUtils::ReadBoolArray, IGNITE_TYPE_ARRAY_BOOL);
+ }
+
+ int16_t PortableReaderImpl::ReadInt16()
+ {
+ return ReadRaw<int16_t>(PortableUtils::ReadInt16);
+ }
+
+ int32_t PortableReaderImpl::ReadInt16Array(int16_t* res, const int32_t len)
+ {
+ return ReadRawArray<int16_t>(res, len, PortableUtils::ReadInt16Array, IGNITE_TYPE_ARRAY_SHORT);
+ }
+
+ int16_t PortableReaderImpl::ReadInt16(const char* fieldName)
+ {
+ return Read(fieldName, PortableUtils::ReadInt16, IGNITE_TYPE_SHORT, static_cast<int16_t>(0));
+ }
+
+ int32_t PortableReaderImpl::ReadInt16Array(const char* fieldName, int16_t* res, const int32_t len)
+ {
+ return ReadArray<int16_t>(fieldName, res, len, PortableUtils::ReadInt16Array, IGNITE_TYPE_ARRAY_SHORT);
+ }
+
+ uint16_t PortableReaderImpl::ReadUInt16()
+ {
+ return ReadRaw<uint16_t>(PortableUtils::ReadUInt16);
+ }
+
+ int32_t PortableReaderImpl::ReadUInt16Array(uint16_t* res, const int32_t len)
+ {
+ return ReadRawArray<uint16_t>(res, len, PortableUtils::ReadUInt16Array, IGNITE_TYPE_ARRAY_CHAR);
+ }
+
+ uint16_t PortableReaderImpl::ReadUInt16(const char* fieldName)
+ {
+ return Read(fieldName, PortableUtils::ReadUInt16, IGNITE_TYPE_CHAR, static_cast<uint16_t>(0));
+ }
+
+ int32_t PortableReaderImpl::ReadUInt16Array(const char* fieldName, uint16_t* res, const int32_t len)
+ {
+ return ReadArray<uint16_t>(fieldName, res, len,PortableUtils::ReadUInt16Array, IGNITE_TYPE_ARRAY_CHAR);
+ }
+
+ int32_t PortableReaderImpl::ReadInt32()
+ {
+ return ReadRaw<int32_t>(PortableUtils::ReadInt32);
+ }
+
+ int32_t PortableReaderImpl::ReadInt32Array(int32_t* res, const int32_t len)
+ {
+ return ReadRawArray<int32_t>(res, len, PortableUtils::ReadInt32Array, IGNITE_TYPE_ARRAY_INT);
+ }
+
+ int32_t PortableReaderImpl::ReadInt32(const char* fieldName)
+ {
+ return Read(fieldName, PortableUtils::ReadInt32, IGNITE_TYPE_INT, static_cast<int32_t>(0));
+ }
+
+ int32_t PortableReaderImpl::ReadInt32Array(const char* fieldName, int32_t* res, const int32_t len)
+ {
+ return ReadArray<int32_t>(fieldName, res, len,PortableUtils::ReadInt32Array, IGNITE_TYPE_ARRAY_INT);
+ }
+
+ int64_t PortableReaderImpl::ReadInt64()
+ {
+ return ReadRaw<int64_t>(PortableUtils::ReadInt64);
+ }
+
+ int32_t PortableReaderImpl::ReadInt64Array(int64_t* res, const int32_t len)
+ {
+ return ReadRawArray<int64_t>(res, len, PortableUtils::ReadInt64Array, IGNITE_TYPE_ARRAY_LONG);
+ }
+
+ int64_t PortableReaderImpl::ReadInt64(const char* fieldName)
+ {
+ return Read(fieldName, PortableUtils::ReadInt64, IGNITE_TYPE_LONG, static_cast<int64_t>(0));
+ }
+
+ int32_t PortableReaderImpl::ReadInt64Array(const char* fieldName, int64_t* res, const int32_t len)
+ {
+ return ReadArray<int64_t>(fieldName, res, len,PortableUtils::ReadInt64Array, IGNITE_TYPE_ARRAY_LONG);
+ }
+
+ float PortableReaderImpl::ReadFloat()
+ {
+ return ReadRaw<float>(PortableUtils::ReadFloat);
+ }
+
+ int32_t PortableReaderImpl::ReadFloatArray(float* res, const int32_t len)
+ {
+ return ReadRawArray<float>(res, len, PortableUtils::ReadFloatArray, IGNITE_TYPE_ARRAY_FLOAT);
+ }
+
+ float PortableReaderImpl::ReadFloat(const char* fieldName)
+ {
+ return Read(fieldName, PortableUtils::ReadFloat, IGNITE_TYPE_FLOAT, static_cast<float>(0));
+ }
+
+ int32_t PortableReaderImpl::ReadFloatArray(const char* fieldName, float* res, const int32_t len)
+ {
+ return ReadArray<float>(fieldName, res, len,PortableUtils::ReadFloatArray, IGNITE_TYPE_ARRAY_FLOAT);
+ }
+
+ double PortableReaderImpl::ReadDouble()
+ {
+ return ReadRaw<double>(PortableUtils::ReadDouble);
+ }
+
+ int32_t PortableReaderImpl::ReadDoubleArray(double* res, const int32_t len)
+ {
+ return ReadRawArray<double>(res, len, PortableUtils::ReadDoubleArray, IGNITE_TYPE_ARRAY_DOUBLE);
+ }
+
+ double PortableReaderImpl::ReadDouble(const char* fieldName)
+ {
+ return Read(fieldName, PortableUtils::ReadDouble, IGNITE_TYPE_DOUBLE, static_cast<double>(0));
+ }
+
+ int32_t PortableReaderImpl::ReadDoubleArray(const char* fieldName, double* res, const int32_t len)
+ {
+ return ReadArray<double>(fieldName, res, len,PortableUtils::ReadDoubleArray, IGNITE_TYPE_ARRAY_DOUBLE);
+ }
+
+ Guid PortableReaderImpl::ReadGuid()
+ {
+ CheckRawMode(true);
+ CheckSingleMode(true);
+
+ return ReadNullable(stream, PortableUtils::ReadGuid, IGNITE_TYPE_UUID);
+ }
+
+ int32_t PortableReaderImpl::ReadGuidArray(Guid* res, const int32_t len)
+ {
+ CheckRawMode(true);
+ CheckSingleMode(true);
+
+ return ReadArrayInternal<Guid>(res, len, stream, ReadGuidArrayInternal, IGNITE_TYPE_ARRAY_UUID);
+ }
+
+ Guid PortableReaderImpl::ReadGuid(const char* fieldName)
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName);
+ int32_t fieldLen = SeekField(fieldId);
+
+ if (fieldLen > 0)
+ return ReadNullable(stream, PortableUtils::ReadGuid, IGNITE_TYPE_UUID);
+
+ return Guid();
+ }
+
+ int32_t PortableReaderImpl::ReadGuidArray(const char* fieldName, Guid* res, const int32_t len)
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ int32_t pos = stream->Position();
+
+ int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName);
+ int32_t fieldLen = SeekField(fieldId);
+
+ if (fieldLen > 0) {
+ int32_t realLen = ReadArrayInternal<Guid>(res, len, stream, ReadGuidArrayInternal, IGNITE_TYPE_ARRAY_UUID);
+
+ // If actual read didn't occur return to initial position so that we do not perform
+ // N jumps to find the field again, where N is total amount of fields.
+ if (realLen != -1 && (!res || realLen > len))
+ stream->Position(pos);
+
+ return realLen;
+ }
+
+ return -1;
+ }
+
+ void PortableReaderImpl::ReadGuidArrayInternal(InteropInputStream* stream, Guid* res, const int32_t len)
+ {
+ for (int i = 0; i < len; i++)
+ *(res + i) = ReadNullable<Guid>(stream, PortableUtils::ReadGuid, IGNITE_TYPE_UUID);
+ }
+
+ int32_t PortableReaderImpl::ReadString(char* res, const int32_t len)
+ {
+ CheckRawMode(true);
+ CheckSingleMode(true);
+
+ return ReadStringInternal(res, len);
+ }
+
+ int32_t PortableReaderImpl::ReadString(const char* fieldName, char* res, const int32_t len)
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ int32_t pos = stream->Position();
+
+ int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName);
+ int32_t fieldLen = SeekField(fieldId);
+
+ if (fieldLen > 0) {
+ int32_t realLen = ReadStringInternal(res, len);
+
+ // If actual read didn't occur return to initial position so that we do not perform
+ // N jumps to find the field again, where N is total amount of fields.
+ if (realLen != -1 && (!res || realLen > len))
+ stream->Position(pos);
+
+ return realLen;
+ }
+
+ return -1;
+ }
+
+ int32_t PortableReaderImpl::ReadStringArray(int32_t* size)
+ {
+ return StartContainerSession(true, IGNITE_TYPE_ARRAY_STRING, size);
+ }
+
+ int32_t PortableReaderImpl::ReadStringArray(const char* fieldName, int32_t* size)
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName);
+ int32_t fieldLen = SeekField(fieldId);
+
+ if (fieldLen > 0)
+ return StartContainerSession(false, IGNITE_TYPE_ARRAY_STRING, size);
+ else {
+ *size = -1;
+
+ return ++elemIdGen;
+ }
+ }
+
+ int32_t PortableReaderImpl::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 PortableReaderImpl::ReadStringInternal(char* res, const int32_t len)
+ {
+ int8_t hdr = stream->ReadInt8();
+
+ if (hdr == IGNITE_TYPE_STRING) {
+ bool utf8Mode = stream->ReadBool();
+ int32_t realLen = stream->ReadInt32();
+
+ if (res && len >= realLen) {
+ if (utf8Mode)
+ {
+ for (int i = 0; i < realLen; i++)
+ *(res + i) = static_cast<char>(stream->ReadInt8());
+ }
+ else
+ {
+ for (int i = 0; i < realLen; i++)
+ *(res + i) = static_cast<char>(stream->ReadUInt16());
+ }
+
+ if (len > realLen)
+ *(res + realLen) = 0; // Set NULL terminator if possible.
+ }
+ else
+ stream->Position(stream->Position() - 6);
+
+ return realLen;
+ }
+ else if (hdr != IGNITE_HDR_NULL)
+ ThrowOnInvalidHeader(IGNITE_TYPE_ARRAY, hdr);
+
+ return -1;
+ }
+
+ int32_t PortableReaderImpl::ReadArray(int32_t* size)
+ {
+ return StartContainerSession(true, IGNITE_TYPE_ARRAY, size);
+ }
+
+ int32_t PortableReaderImpl::ReadArray(const char* fieldName, int32_t* size)
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName);
+ int32_t fieldLen = SeekField(fieldId);
+
+ if (fieldLen > 0)
+ return StartContainerSession(false, IGNITE_TYPE_ARRAY, size);
+ else {
+ *size = -1;
+
+ return ++elemIdGen;
+ }
+ }
+
+ int32_t PortableReaderImpl::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<CollectionType>(stream->ReadInt8());
+
+ return id;
+ }
+
+ int32_t PortableReaderImpl::ReadCollection(const char* fieldName, CollectionType* typ, int32_t* size)
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName);
+ int32_t fieldLen = SeekField(fieldId);
+
+ if (fieldLen > 0)
+ {
+ int32_t id = StartContainerSession(false, IGNITE_TYPE_COLLECTION, size);
+
+ if (*size == -1)
+ *typ = IGNITE_COLLECTION_UNDEFINED;
+ else
+ *typ = static_cast<CollectionType>(stream->ReadInt8());
+
+ return id;
+ }
+ else {
+ *typ = IGNITE_COLLECTION_UNDEFINED;
+ *size = -1;
+
+ return ++elemIdGen;
+ }
+ }
+
+ int32_t PortableReaderImpl::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<MapType>(stream->ReadInt8());
+
+ return id;
+ }
+
+ int32_t PortableReaderImpl::ReadMap(const char* fieldName, MapType* typ, int32_t* size)
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName);
+ int32_t fieldLen = SeekField(fieldId);
+
+ if (fieldLen > 0)
+ {
+ int32_t id = StartContainerSession(false, IGNITE_TYPE_MAP, size);
+
+ if (*size == -1)
+ *typ = IGNITE_MAP_UNDEFINED;
+ else
+ *typ = static_cast<MapType>(stream->ReadInt8());
+
+ return id;
+ }
+ else {
+ *typ = IGNITE_MAP_UNDEFINED;
+ *size = -1;
+
+ return ++elemIdGen;
+ }
+ }
+
+ bool PortableReaderImpl::HasNextElement(int32_t id)
+ {
+ return elemId == id && elemRead < elemCnt;
+ }
+
+ void PortableReaderImpl::SetRawMode()
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ stream->Position(pos + rawOff);
+ rawMode = true;
+ }
+
+ template <>
+ int8_t PortableReaderImpl::ReadTopObject<int8_t>()
+ {
+ return ReadTopObject0(IGNITE_TYPE_BYTE, PortableUtils::ReadInt8, static_cast<int8_t>(0));
+ }
+
+ template <>
+ bool PortableReaderImpl::ReadTopObject<bool>()
+ {
+ return ReadTopObject0(IGNITE_TYPE_BOOL, PortableUtils::ReadBool, static_cast<bool>(0));
+ }
+
+ template <>
+ int16_t PortableReaderImpl::ReadTopObject<int16_t>()
+ {
+ return ReadTopObject0(IGNITE_TYPE_SHORT, PortableUtils::ReadInt16, static_cast<int16_t>(0));
+ }
+
+ template <>
+ uint16_t PortableReaderImpl::ReadTopObject<uint16_t>()
+ {
+ return ReadTopObject0(IGNITE_TYPE_CHAR, PortableUtils::ReadUInt16, static_cast<uint16_t>(0));
+ }
+
+ template <>
+ int32_t PortableReaderImpl::ReadTopObject<int32_t>()
+ {
+ return ReadTopObject0(IGNITE_TYPE_INT, PortableUtils::ReadInt32, static_cast<int32_t>(0));
+ }
+
+ template <>
+ int64_t PortableReaderImpl::ReadTopObject<int64_t>()
+ {
+ return ReadTopObject0(IGNITE_TYPE_LONG, PortableUtils::ReadInt64, static_cast<int64_t>(0));
+ }
+
+ template <>
+ float PortableReaderImpl::ReadTopObject<float>()
+ {
+ return ReadTopObject0(IGNITE_TYPE_FLOAT, PortableUtils::ReadFloat, static_cast<float>(0));
+ }
+
+ template <>
+ double PortableReaderImpl::ReadTopObject<double>()
+ {
+ return ReadTopObject0(IGNITE_TYPE_DOUBLE, PortableUtils::ReadDouble, static_cast<double>(0));
+ }
+
+ template <>
+ Guid PortableReaderImpl::ReadTopObject<Guid>()
+ {
+ int8_t typeId = stream->ReadInt8();
+
+ if (typeId == IGNITE_TYPE_UUID)
+ return PortableUtils::ReadGuid(stream);
+ else if (typeId == IGNITE_HDR_NULL)
+ return Guid();
+ else {
+ int32_t pos = stream->Position() - 1;
+
+ IGNITE_ERROR_FORMATTED_3(IgniteError::IGNITE_ERR_PORTABLE, "Invalid header", "position", pos, "expected", IGNITE_TYPE_UUID, "actual", typeId)
+ }
+ }
+
+ InteropInputStream* PortableReaderImpl::GetStream()
+ {
+ return stream;
+ }
+
+ int32_t PortableReaderImpl::SeekField(const int32_t fieldId)
+ {
+ // We assume that it is very likely that fields are read in the same
+ // order as they were initially written. So we start seeking field
+ // from current stream position making a "loop" up to this position.
+ int32_t marker = stream->Position();
+
+ for (int32_t curPos = marker; curPos < pos + rawOff;)
+ {
+ int32_t curFieldId = stream->ReadInt32();
+ int32_t curFieldLen = stream->ReadInt32();
+
+ if (fieldId == curFieldId)
+ return curFieldLen;
+ else {
+ curPos = stream->Position() + curFieldLen;
+
+ stream->Position(curPos);
+ }
+ }
+
+ stream->Position(pos + IGNITE_FULL_HDR_LEN);
+
+ for (int32_t curPos = stream->Position(); curPos < marker;)
+ {
+ int32_t curFieldId = stream->ReadInt32();
+ int32_t curFieldLen = stream->ReadInt32();
+
+ if (fieldId == curFieldId)
+ return curFieldLen;
+ else {
+ curPos = stream->Position() + curFieldLen;
+
+ stream->Position(curPos);
+ }
+ }
+
+ return -1;
+ }
+
+ void PortableReaderImpl::CheckRawMode(bool expected)
+ {
+ if (expected && !rawMode) {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Operation can be performed only in raw mode.")
+ }
+ else if (!expected && rawMode) {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Operation cannot be performed in raw mode.")
+ }
+ }
+
+ void PortableReaderImpl::CheckSingleMode(bool expected)
+ {
+ if (expected && elemId != 0) {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Operation cannot be performed when container is being read.");
+ }
+ else if (!expected && elemId == 0) {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Operation can be performed only when container is being read.");
+ }
+ }
+
+ int32_t PortableReaderImpl::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 PortableReaderImpl::CheckSession(int32_t expSes)
+ {
+ if (elemId != expSes) {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Containter read session has been finished or is not started yet.");
+ }
+ }
+
+ void PortableReaderImpl::ThrowOnInvalidHeader(int32_t pos, int8_t expHdr, int8_t hdr)
+ {
+ IGNITE_ERROR_FORMATTED_3(IgniteError::IGNITE_ERR_PORTABLE, "Invalid header", "position", pos, "expected", expHdr, "actual", hdr)
+ }
+
+ void PortableReaderImpl::ThrowOnInvalidHeader(int8_t expHdr, int8_t hdr)
+ {
+ 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/1fc06e01/modules/platform/src/main/cpp/core/src/impl/portable/portable_utils.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/portable/portable_utils.cpp b/modules/platform/src/main/cpp/core/src/impl/portable/portable_utils.cpp
new file mode 100644
index 0000000..2f9c259
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/portable/portable_utils.cpp
@@ -0,0 +1,214 @@
+/*
+ * 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/portable/portable_utils.h"
+
+using namespace ignite::impl::interop;
+using namespace ignite::impl::portable;
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ int8_t PortableUtils::ReadInt8(InteropInputStream* stream)
+ {
+ return stream->ReadInt8();
+ }
+
+ void PortableUtils::WriteInt8(InteropOutputStream* stream, int8_t val)
+ {
+ stream->WriteInt8(val);
+ }
+
+ void PortableUtils::ReadInt8Array(InteropInputStream* stream, int8_t* res, const int32_t len)
+ {
+ stream->ReadInt8Array(res, len);
+ }
+
+ void PortableUtils::WriteInt8Array(InteropOutputStream* stream, const int8_t* val, const int32_t len)
+ {
+ stream->WriteInt8Array(val, len);
+ }
+
+ bool PortableUtils::ReadBool(InteropInputStream* stream)
+ {
+ return stream->ReadBool();
+ }
+
+ void PortableUtils::WriteBool(InteropOutputStream* stream, bool val)
+ {
+ stream->WriteBool(val);
+ }
+
+ void PortableUtils::ReadBoolArray(InteropInputStream* stream, bool* res, const int32_t len)
+ {
+ stream->ReadBoolArray(res, len);
+ }
+
+ void PortableUtils::WriteBoolArray(InteropOutputStream* stream, const bool* val, const int32_t len)
+ {
+ stream->WriteBoolArray(val, len);
+ }
+
+ int16_t PortableUtils::ReadInt16(InteropInputStream* stream)
+ {
+ return stream->ReadInt16();
+ }
+
+ void PortableUtils::WriteInt16(InteropOutputStream* stream, int16_t val)
+ {
+ stream->WriteInt16(val);
+ }
+
+ void PortableUtils::ReadInt16Array(InteropInputStream* stream, int16_t* res, const int32_t len)
+ {
+ stream->ReadInt16Array(res, len);
+ }
+
+ void PortableUtils::WriteInt16Array(InteropOutputStream* stream, const int16_t* val, const int32_t len)
+ {
+ stream->WriteInt16Array(val, len);
+ }
+
+ uint16_t PortableUtils::ReadUInt16(InteropInputStream* stream)
+ {
+ return stream->ReadUInt16();
+ }
+
+ void PortableUtils::WriteUInt16(InteropOutputStream* stream, uint16_t val)
+ {
+ stream->WriteUInt16(val);
+ }
+
+ void PortableUtils::ReadUInt16Array(InteropInputStream* stream, uint16_t* res, const int32_t len)
+ {
+ stream->ReadUInt16Array(res, len);
+ }
+
+ void PortableUtils::WriteUInt16Array(InteropOutputStream* stream, const uint16_t* val, const int32_t len)
+ {
+ stream->WriteUInt16Array(val, len);
+ }
+
+ int32_t PortableUtils::ReadInt32(InteropInputStream* stream)
+ {
+ return stream->ReadInt32();
+ }
+
+ void PortableUtils::WriteInt32(InteropOutputStream* stream, int32_t val)
+ {
+ stream->WriteInt32(val);
+ }
+
+ void PortableUtils::ReadInt32Array(InteropInputStream* stream, int32_t* res, const int32_t len)
+ {
+ stream->ReadInt32Array(res, len);
+ }
+
+ void PortableUtils::WriteInt32Array(InteropOutputStream* stream, const int32_t* val, const int32_t len)
+ {
+ stream->WriteInt32Array(val, len);
+ }
+
+ int64_t PortableUtils::ReadInt64(InteropInputStream* stream)
+ {
+ return stream->ReadInt64();
+ }
+
+ void PortableUtils::WriteInt64(InteropOutputStream* stream, int64_t val)
+ {
+ stream->WriteInt64(val);
+ }
+
+ void PortableUtils::ReadInt64Array(InteropInputStream* stream, int64_t* res, const int32_t len)
+ {
+ stream->ReadInt64Array(res, len);
+ }
+
+ void PortableUtils::WriteInt64Array(InteropOutputStream* stream, const int64_t* val, const int32_t len)
+ {
+ stream->WriteInt64Array(val, len);
+ }
+
+ float PortableUtils::ReadFloat(InteropInputStream* stream)
+ {
+ return stream->ReadFloat();
+ }
+
+ void PortableUtils::WriteFloat(InteropOutputStream* stream, float val)
+ {
+ stream->WriteFloat(val);
+ }
+
+ void PortableUtils::ReadFloatArray(InteropInputStream* stream, float* res, const int32_t len)
+ {
+ stream->ReadFloatArray(res, len);
+ }
+
+ void PortableUtils::WriteFloatArray(InteropOutputStream* stream, const float* val, const int32_t len)
+ {
+ stream->WriteFloatArray(val, len);
+ }
+
+ double PortableUtils::ReadDouble(InteropInputStream* stream)
+ {
+ return stream->ReadDouble();
+ }
+
+ void PortableUtils::WriteDouble(InteropOutputStream* stream, double val)
+ {
+ stream->WriteDouble(val);
+ }
+
+ void PortableUtils::ReadDoubleArray(InteropInputStream* stream, double* res, const int32_t len)
+ {
+ stream->ReadDoubleArray(res, len);
+ }
+
+ void PortableUtils::WriteDoubleArray(InteropOutputStream* stream, const double* val, const int32_t len)
+ {
+ stream->WriteDoubleArray(val, len);
+ }
+
+ Guid PortableUtils::ReadGuid(interop::InteropInputStream* stream)
+ {
+ int64_t most = stream->ReadInt64();
+ int64_t least = stream->ReadInt64();
+
+ return Guid(most, least);
+ }
+
+ void PortableUtils::WriteGuid(interop::InteropOutputStream* stream, const Guid val)
+ {
+ stream->WriteInt64(val.GetMostSignificantBits());
+ stream->WriteInt64(val.GetLeastSignificantBits());
+ }
+
+ void PortableUtils::WriteString(interop::InteropOutputStream* stream, const char* val, const int32_t len)
+ {
+ stream->WriteBool(false);
+ stream->WriteInt32(len);
+
+ for (int i = 0; i < len; i++)
+ stream->WriteUInt16(*(val + i));
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/impl/portable/portable_writer_impl.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/portable/portable_writer_impl.cpp b/modules/platform/src/main/cpp/core/src/impl/portable/portable_writer_impl.cpp
new file mode 100644
index 0000000..93aacd9
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/portable/portable_writer_impl.cpp
@@ -0,0 +1,600 @@
+/*
+ * 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/portable/portable_writer_impl.h"
+#include "ignite/ignite_error.h"
+
+using namespace ignite::impl::interop;
+using namespace ignite::impl::portable;
+using namespace ignite::portable;
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ PortableWriterImpl::PortableWriterImpl(InteropOutputStream* stream, PortableIdResolver* idRslvr,
+ PortableMetadataManager* metaMgr, PortableMetadataHandler* metaHnd) :
+ stream(stream), idRslvr(idRslvr), metaMgr(metaMgr), metaHnd(metaHnd), typeId(idRslvr->GetTypeId()),
+ elemIdGen(0), elemId(0), elemCnt(0), elemPos(-1), rawPos(-1)
+ {
+ // No-op.
+ }
+
+ PortableWriterImpl::PortableWriterImpl(InteropOutputStream* stream, PortableMetadataManager* metaMgr) :
+ stream(stream), idRslvr(NULL), metaMgr(metaMgr), metaHnd(NULL), typeId(0),
+ elemIdGen(0), elemId(0), elemCnt(0), elemPos(-1), rawPos(0)
+ {
+ // No-op.
+ }
+
+ void PortableWriterImpl::WriteInt8(const int8_t val)
+ {
+ WritePrimitiveRaw<int8_t>(val, PortableUtils::WriteInt8);
+ }
+
+ void PortableWriterImpl::WriteInt8Array(const int8_t* val, const int32_t len)
+ {
+ WritePrimitiveArrayRaw<int8_t>(val, len, PortableUtils::WriteInt8Array, IGNITE_TYPE_ARRAY_BYTE);
+ }
+
+ void PortableWriterImpl::WriteInt8(const char* fieldName, const int8_t val)
+ {
+ WritePrimitive<int8_t>(fieldName, val, PortableUtils::WriteInt8, IGNITE_TYPE_BYTE, 1);
+ }
+
+ void PortableWriterImpl::WriteInt8Array(const char* fieldName, const int8_t* val, const int32_t len)
+ {
+ WritePrimitiveArray<int8_t>(fieldName, val, len, PortableUtils::WriteInt8Array, IGNITE_TYPE_ARRAY_BYTE, 0);
+ }
+
+ void PortableWriterImpl::WriteBool(const bool val)
+ {
+ WritePrimitiveRaw<bool>(val, PortableUtils::WriteBool);
+ }
+
+ void PortableWriterImpl::WriteBoolArray(const bool* val, const int32_t len)
+ {
+ WritePrimitiveArrayRaw<bool>(val, len, PortableUtils::WriteBoolArray, IGNITE_TYPE_ARRAY_BOOL);
+ }
+
+ void PortableWriterImpl::WriteBool(const char* fieldName, const bool val)
+ {
+ WritePrimitive<bool>(fieldName, val, PortableUtils::WriteBool, IGNITE_TYPE_BOOL, 1);
+ }
+
+ void PortableWriterImpl::WriteBoolArray(const char* fieldName, const bool* val, const int32_t len)
+ {
+ WritePrimitiveArray<bool>(fieldName, val, len, PortableUtils::WriteBoolArray, IGNITE_TYPE_ARRAY_BOOL, 0);
+ }
+
+ void PortableWriterImpl::WriteInt16(const int16_t val)
+ {
+ WritePrimitiveRaw<int16_t>(val, PortableUtils::WriteInt16);
+ }
+
+ void PortableWriterImpl::WriteInt16Array(const int16_t* val, const int32_t len)
+ {
+ WritePrimitiveArrayRaw<int16_t>(val, len, PortableUtils::WriteInt16Array, IGNITE_TYPE_ARRAY_SHORT);
+ }
+
+ void PortableWriterImpl::WriteInt16(const char* fieldName, const int16_t val)
+ {
+ WritePrimitive<int16_t>(fieldName, val, PortableUtils::WriteInt16, IGNITE_TYPE_SHORT, 2);
+ }
+
+ void PortableWriterImpl::WriteInt16Array(const char* fieldName, const int16_t* val, const int32_t len)
+ {
+ WritePrimitiveArray<int16_t>(fieldName, val, len, PortableUtils::WriteInt16Array, IGNITE_TYPE_ARRAY_SHORT, 1);
+ }
+
+ void PortableWriterImpl::WriteUInt16(const uint16_t val)
+ {
+ WritePrimitiveRaw<uint16_t>(val, PortableUtils::WriteUInt16);
+ }
+
+ void PortableWriterImpl::WriteUInt16Array(const uint16_t* val, const int32_t len)
+ {
+ WritePrimitiveArrayRaw<uint16_t>(val, len, PortableUtils::WriteUInt16Array, IGNITE_TYPE_ARRAY_CHAR);
+ }
+
+ void PortableWriterImpl::WriteUInt16(const char* fieldName, const uint16_t val)
+ {
+ WritePrimitive<uint16_t>(fieldName, val, PortableUtils::WriteUInt16, IGNITE_TYPE_CHAR, 2);
+ }
+
+ void PortableWriterImpl::WriteUInt16Array(const char* fieldName, const uint16_t* val, const int32_t len)
+ {
+ WritePrimitiveArray<uint16_t>(fieldName, val, len, PortableUtils::WriteUInt16Array, IGNITE_TYPE_ARRAY_CHAR, 1);
+ }
+
+ void PortableWriterImpl::WriteInt32(const int32_t val)
+ {
+ WritePrimitiveRaw<int32_t>(val, PortableUtils::WriteInt32);
+ }
+
+ void PortableWriterImpl::WriteInt32Array(const int32_t* val, const int32_t len)
+ {
+ WritePrimitiveArrayRaw<int32_t>(val, len, PortableUtils::WriteInt32Array, IGNITE_TYPE_ARRAY_INT);
+ }
+
+ void PortableWriterImpl::WriteInt32(const char* fieldName, const int32_t val)
+ {
+ WritePrimitive<int32_t>(fieldName, val, PortableUtils::WriteInt32, IGNITE_TYPE_INT, 4);
+ }
+
+ void PortableWriterImpl::WriteInt32Array(const char* fieldName, const int32_t* val, const int32_t len)
+ {
+ WritePrimitiveArray<int32_t>(fieldName, val, len, PortableUtils::WriteInt32Array, IGNITE_TYPE_ARRAY_INT, 2);
+ }
+
+ void PortableWriterImpl::WriteInt64(const int64_t val)
+ {
+ WritePrimitiveRaw<int64_t>(val, PortableUtils::WriteInt64);
+ }
+
+ void PortableWriterImpl::WriteInt64Array(const int64_t* val, const int32_t len)
+ {
+ WritePrimitiveArrayRaw<int64_t>(val, len, PortableUtils::WriteInt64Array, IGNITE_TYPE_ARRAY_LONG);
+ }
+
+ void PortableWriterImpl::WriteInt64(const char* fieldName, const int64_t val)
+ {
+ WritePrimitive<int64_t>(fieldName, val, PortableUtils::WriteInt64, IGNITE_TYPE_LONG, 8);
+ }
+
+ void PortableWriterImpl::WriteInt64Array(const char* fieldName, const int64_t* val, const int32_t len)
+ {
+ WritePrimitiveArray<int64_t>(fieldName, val, len, PortableUtils::WriteInt64Array, IGNITE_TYPE_ARRAY_LONG, 3);
+ }
+
+ void PortableWriterImpl::WriteFloat(const float val)
+ {
+ WritePrimitiveRaw<float>(val, PortableUtils::WriteFloat);
+ }
+
+ void PortableWriterImpl::WriteFloatArray(const float* val, const int32_t len)
+ {
+ WritePrimitiveArrayRaw<float>(val, len, PortableUtils::WriteFloatArray, IGNITE_TYPE_ARRAY_FLOAT);
+ }
+
+ void PortableWriterImpl::WriteFloat(const char* fieldName, const float val)
+ {
+ WritePrimitive<float>(fieldName, val, PortableUtils::WriteFloat, IGNITE_TYPE_FLOAT, 4);
+ }
+
+ void PortableWriterImpl::WriteFloatArray(const char* fieldName, const float* val, const int32_t len)
+ {
+ WritePrimitiveArray<float>(fieldName, val, len, PortableUtils::WriteFloatArray, IGNITE_TYPE_ARRAY_FLOAT, 2);
+ }
+
+ void PortableWriterImpl::WriteDouble(const double val)
+ {
+ WritePrimitiveRaw<double>(val, PortableUtils::WriteDouble);
+ }
+
+ void PortableWriterImpl::WriteDoubleArray(const double* val, const int32_t len)
+ {
+ WritePrimitiveArrayRaw<double>(val, len, PortableUtils::WriteDoubleArray, IGNITE_TYPE_ARRAY_DOUBLE);
+ }
+
+ void PortableWriterImpl::WriteDouble(const char* fieldName, const double val)
+ {
+ WritePrimitive<double>(fieldName, val, PortableUtils::WriteDouble, IGNITE_TYPE_DOUBLE, 8);
+ }
+
+ void PortableWriterImpl::WriteDoubleArray(const char* fieldName, const double* val, const int32_t len)
+ {
+ WritePrimitiveArray<double>(fieldName, val, len, PortableUtils::WriteDoubleArray, IGNITE_TYPE_ARRAY_DOUBLE, 3);
+ }
+
+ void PortableWriterImpl::WriteGuid(const Guid val)
+ {
+ CheckRawMode(true);
+ CheckSingleMode(true);
+
+ stream->WriteInt8(IGNITE_TYPE_UUID);
+
+ PortableUtils::WriteGuid(stream, val);
+ }
+
+ void PortableWriterImpl::WriteGuidArray(const Guid* val, const int32_t len)
+ {
+ CheckRawMode(true);
+ CheckSingleMode(true);
+
+ if (val)
+ {
+ stream->WriteInt8(IGNITE_TYPE_ARRAY_UUID);
+ stream->WriteInt32(len);
+
+ for (int i = 0; i < len; i++)
+ {
+ Guid elem = *(val + i);
+
+ stream->WriteInt8(IGNITE_TYPE_UUID);
+ PortableUtils::WriteGuid(stream, elem);
+ }
+ }
+ else
+ stream->WriteInt8(IGNITE_HDR_NULL);
+ }
+
+ void PortableWriterImpl::WriteGuid(const char* fieldName, const Guid val)
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ WriteFieldIdAndLength(fieldName, IGNITE_TYPE_UUID, 1 + 16);
+
+ stream->WriteInt8(IGNITE_TYPE_UUID);
+
+ PortableUtils::WriteGuid(stream, val);
+ }
+
+ void PortableWriterImpl::WriteGuidArray(const char* fieldName, const Guid* val, const int32_t len)
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ WriteFieldId(fieldName, IGNITE_TYPE_ARRAY_UUID);
+
+ if (val)
+ {
+ stream->WriteInt32(5 + len * 17);
+ stream->WriteInt8(IGNITE_TYPE_ARRAY_UUID);
+ stream->WriteInt32(len);
+
+ for (int i = 0; i < len; i++)
+ {
+ Guid elem = *(val + i);
+
+ WriteTopObject(elem);
+ }
+ }
+ else
+ {
+ stream->WriteInt32(1);
+ stream->WriteInt8(IGNITE_HDR_NULL);
+ }
+ }
+
+ void PortableWriterImpl::WriteString(const char* val, const int32_t len)
+ {
+ CheckRawMode(true);
+ CheckSingleMode(true);
+
+ if (val)
+ {
+ stream->WriteInt8(IGNITE_TYPE_STRING);
+
+ PortableUtils::WriteString(stream, val, len);
+ }
+ else
+ stream->WriteInt8(IGNITE_HDR_NULL);
+ }
+
+ void PortableWriterImpl::WriteString(const char* fieldName, const char* val, const int32_t len)
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ WriteFieldId(fieldName, IGNITE_TYPE_STRING);
+
+ if (val)
+ {
+ int32_t lenPos = stream->Position();
+ stream->Position(lenPos + 4);
+
+ stream->WriteInt8(IGNITE_TYPE_STRING);
+ stream->WriteBool(false);
+ stream->WriteInt32(len);
+
+ for (int i = 0; i < len; i++)
+ stream->WriteUInt16(*(val + i));
+
+ stream->WriteInt32(lenPos, stream->Position() - lenPos - 4);
+ }
+ else
+ {
+ stream->WriteInt32(1);
+ stream->WriteInt8(IGNITE_HDR_NULL);
+ }
+ }
+
+ int32_t PortableWriterImpl::WriteStringArray()
+ {
+ StartContainerSession(true);
+
+ stream->WriteInt8(IGNITE_TYPE_ARRAY_STRING);
+ stream->Position(stream->Position() + 4);
+
+ return elemId;
+ }
+
+ int32_t PortableWriterImpl::WriteStringArray(const char* fieldName)
+ {
+ StartContainerSession(false);
+
+ WriteFieldIdSkipLength(fieldName, IGNITE_TYPE_ARRAY_STRING);
+
+ stream->WriteInt8(IGNITE_TYPE_ARRAY_STRING);
+ stream->Position(stream->Position() + 4);
+
+ return elemId;
+ }
+
+ void PortableWriterImpl::WriteStringElement(int32_t id, const char* val, int32_t len)
+ {
+ CheckSession(id);
+
+ if (val)
+ {
+ stream->WriteInt8(IGNITE_TYPE_STRING);
+
+ PortableUtils::WriteString(stream, val, len);
+ }
+ else
+ stream->WriteInt8(IGNITE_HDR_NULL);
+
+ elemCnt++;
+ }
+
+ void PortableWriterImpl::WriteNull()
+ {
+ CheckRawMode(true);
+ CheckSingleMode(true);
+
+ stream->WriteInt8(IGNITE_HDR_NULL);
+ }
+
+ void PortableWriterImpl::WriteNull(const char* fieldName)
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ WriteFieldIdAndLength(fieldName, IGNITE_TYPE_OBJECT, 1);
+ stream->WriteInt8(IGNITE_HDR_NULL);
+ }
+
+ int32_t PortableWriterImpl::WriteArray()
+ {
+ StartContainerSession(true);
+
+ stream->WriteInt8(IGNITE_TYPE_ARRAY);
+ stream->Position(stream->Position() + 4);
+
+ return elemId;
+ }
+
+ int32_t PortableWriterImpl::WriteArray(const char* fieldName)
+ {
+ StartContainerSession(false);
+
+ WriteFieldIdSkipLength(fieldName, IGNITE_TYPE_ARRAY);
+
+ stream->WriteInt8(IGNITE_TYPE_ARRAY);
+ stream->Position(stream->Position() + 4);
+
+ return elemId;
+ }
+
+ int32_t PortableWriterImpl::WriteCollection(CollectionType typ)
+ {
+ StartContainerSession(true);
+
+ stream->WriteInt8(IGNITE_TYPE_COLLECTION);
+ stream->Position(stream->Position() + 4);
+ stream->WriteInt8(typ);
+
+ return elemId;
+ }
+
+ int32_t PortableWriterImpl::WriteCollection(const char* fieldName, CollectionType typ)
+ {
+ StartContainerSession(false);
+
+ WriteFieldIdSkipLength(fieldName, IGNITE_TYPE_COLLECTION);
+
+ stream->WriteInt8(IGNITE_TYPE_COLLECTION);
+ stream->Position(stream->Position() + 4);
+ stream->WriteInt8(typ);
+
+ return elemId;
+ }
+
+ int32_t PortableWriterImpl::WriteMap(ignite::portable::MapType typ)
+ {
+ StartContainerSession(true);
+
+ stream->WriteInt8(IGNITE_TYPE_MAP);
+ stream->Position(stream->Position() + 4);
+ stream->WriteInt8(typ);
+
+ return elemId;
+ }
+
+ int32_t PortableWriterImpl::WriteMap(const char* fieldName, ignite::portable::MapType typ)
+ {
+ StartContainerSession(false);
+
+ WriteFieldIdSkipLength(fieldName, IGNITE_TYPE_MAP);
+
+ stream->WriteInt8(IGNITE_TYPE_MAP);
+ stream->Position(stream->Position() + 4);
+ stream->WriteInt8(typ);
+
+ return elemId;
+ }
+
+ void PortableWriterImpl::CommitContainer(int32_t id)
+ {
+ CheckSession(id);
+
+ if (rawPos == -1)
+ {
+ int32_t len = stream->Position() - elemPos - 4;
+
+ stream->WriteInt32(elemPos + 4, len);
+ stream->WriteInt32(elemPos + 9, elemCnt);
+ }
+ else
+ stream->WriteInt32(elemPos + 1, elemCnt);
+
+ elemId = 0;
+ elemCnt = 0;
+ elemPos = -1;
+ }
+
+ void PortableWriterImpl::SetRawMode()
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ rawPos = stream->Position();
+ }
+
+ int32_t PortableWriterImpl::GetRawPosition()
+ {
+ return rawPos == -1 ? stream->Position() : rawPos;
+ }
+
+ void PortableWriterImpl::CheckRawMode(bool expected)
+ {
+ bool rawMode = rawPos != -1;
+
+ if (expected && !rawMode) {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Operation can be performed only in raw mode.");
+ }
+ else if (!expected && rawMode) {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Operation cannot be performed in raw mode.");
+ }
+ }
+
+ void PortableWriterImpl::CheckSingleMode(bool expected)
+ {
+ if (expected && elemId != 0) {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Operation cannot be performed when container is being written.");
+ }
+ else if (!expected && elemId == 0) {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Operation can be performed only when container is being written.");
+ }
+ }
+
+ void PortableWriterImpl::StartContainerSession(bool expRawMode)
+ {
+ CheckRawMode(expRawMode);
+ CheckSingleMode(true);
+
+ elemId = ++elemIdGen;
+ elemPos = stream->Position();
+ }
+
+ void PortableWriterImpl::CheckSession(int32_t expSes)
+ {
+ if (elemId != expSes)
+ {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Containter write session has been finished or is not started yet.");
+ }
+ }
+
+ void PortableWriterImpl::WriteFieldId(const char* fieldName, int32_t fieldTypeId)
+ {
+ int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName);
+
+ stream->WriteInt32(fieldId);
+
+ if (metaHnd)
+ metaHnd->OnFieldWritten(fieldId, fieldName, fieldTypeId);
+ }
+
+ void PortableWriterImpl::WriteFieldIdSkipLength(const char* fieldName, int32_t fieldTypeId)
+ {
+ WriteFieldId(fieldName, fieldTypeId);
+
+ stream->Position(stream->Position() + 4);
+ }
+
+ void PortableWriterImpl::WriteFieldIdAndLength(const char* fieldName, int32_t fieldTypeId, int32_t len)
+ {
+ WriteFieldId(fieldName, fieldTypeId);
+
+ stream->WriteInt32(len);
+ }
+
+ template <>
+ void PortableWriterImpl::WriteTopObject<int8_t>(const int8_t& obj)
+ {
+ WriteTopObject0<int8_t>(obj, PortableUtils::WriteInt8, IGNITE_TYPE_BYTE);
+ }
+
+ template <>
+ void PortableWriterImpl::WriteTopObject<bool>(const bool& obj)
+ {
+ WriteTopObject0<bool>(obj, PortableUtils::WriteBool, IGNITE_TYPE_BOOL);
+ }
+
+ template <>
+ void PortableWriterImpl::WriteTopObject<int16_t>(const int16_t& obj)
+ {
+ WriteTopObject0<int16_t>(obj, PortableUtils::WriteInt16, IGNITE_TYPE_SHORT);
+ }
+
+ template <>
+ void PortableWriterImpl::WriteTopObject<uint16_t>(const uint16_t& obj)
+ {
+ WriteTopObject0<uint16_t>(obj, PortableUtils::WriteUInt16, IGNITE_TYPE_CHAR);
+ }
+
+ template <>
+ void PortableWriterImpl::WriteTopObject<int32_t>(const int32_t& obj)
+ {
+ WriteTopObject0<int32_t>(obj, PortableUtils::WriteInt32, IGNITE_TYPE_INT);
+ }
+
+ template <>
+ void PortableWriterImpl::WriteTopObject<int64_t>(const int64_t& obj)
+ {
+ WriteTopObject0<int64_t>(obj, PortableUtils::WriteInt64, IGNITE_TYPE_LONG);
+ }
+
+ template <>
+ void PortableWriterImpl::WriteTopObject<float>(const float& obj)
+ {
+ WriteTopObject0<float>(obj, PortableUtils::WriteFloat, IGNITE_TYPE_FLOAT);
+ }
+
+ template <>
+ void PortableWriterImpl::WriteTopObject<double>(const double& obj)
+ {
+ WriteTopObject0<double>(obj, PortableUtils::WriteDouble, IGNITE_TYPE_DOUBLE);
+ }
+
+ template <>
+ void PortableWriterImpl::WriteTopObject<Guid>(const Guid& obj)
+ {
+ WriteTopObject0<Guid>(obj, PortableUtils::WriteGuid, IGNITE_TYPE_UUID);
+ }
+
+ InteropOutputStream* PortableWriterImpl::GetStream()
+ {
+ return stream;
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/portable/portable_containers.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/portable/portable_containers.cpp b/modules/platform/src/main/cpp/core/src/portable/portable_containers.cpp
new file mode 100644
index 0000000..8270a13
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/portable/portable_containers.cpp
@@ -0,0 +1,76 @@
+/*
+ * 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/portable/portable_containers.h"
+
+using namespace ignite::impl::portable;
+
+namespace ignite
+{
+ namespace portable
+ {
+ PortableStringArrayWriter::PortableStringArrayWriter(PortableWriterImpl* impl, const int32_t id) :
+ impl(impl), id(id)
+ {
+ // No-op.
+ }
+
+ void PortableStringArrayWriter::Write(const char* val)
+ {
+ if (val)
+ Write(val, static_cast<int32_t>(strlen(val)));
+ else
+ Write(NULL, -1);
+ }
+
+ void PortableStringArrayWriter::Write(const char* val, const int32_t len)
+ {
+ impl->WriteStringElement(id, val, len);
+ }
+
+ void PortableStringArrayWriter::Close()
+ {
+ impl->CommitContainer(id);
+ }
+
+ PortableStringArrayReader::PortableStringArrayReader(impl::portable::PortableReaderImpl* impl,
+ int32_t id, int32_t size) : impl(impl), id(id), size(size)
+ {
+ // No-op.
+ }
+
+ bool PortableStringArrayReader::HasNext()
+ {
+ return impl->HasNextElement(id);
+ }
+
+ int32_t PortableStringArrayReader::GetNext(char* res, const int32_t len)
+ {
+ return impl->ReadStringElement(id, res, len);
+ }
+
+ int32_t PortableStringArrayReader::GetSize()
+ {
+ return size;
+ }
+
+ bool PortableStringArrayReader::IsNull()
+ {
+ return size == -1;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/portable/portable_raw_reader.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/portable/portable_raw_reader.cpp b/modules/platform/src/main/cpp/core/src/portable/portable_raw_reader.cpp
new file mode 100644
index 0000000..f659913
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/portable/portable_raw_reader.cpp
@@ -0,0 +1,135 @@
+/*
+ * 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/portable/portable_reader_impl.h"
+#include "ignite/portable/portable_raw_reader.h"
+
+using namespace ignite::impl::portable;
+
+namespace ignite
+{
+ namespace portable
+ {
+ PortableRawReader::PortableRawReader(PortableReaderImpl* impl) : impl(impl)
+ {
+ // No-op.
+ }
+
+ int8_t PortableRawReader::ReadInt8()
+ {
+ return impl->ReadInt8();
+ }
+
+ int32_t PortableRawReader::ReadInt8Array(int8_t* res, const int32_t len)
+ {
+ return impl->ReadInt8Array(res, len);
+ }
+
+ bool PortableRawReader::ReadBool()
+ {
+ return impl->ReadBool();
+ }
+
+ int32_t PortableRawReader::ReadBoolArray(bool* res, const int32_t len)
+ {
+ return impl->ReadBoolArray(res, len);
+ }
+
+ int16_t PortableRawReader::ReadInt16()
+ {
+ return impl->ReadInt16();
+ }
+
+ int32_t PortableRawReader::ReadInt16Array(int16_t* res, const int32_t len)
+ {
+ return impl->ReadInt16Array(res, len);
+ }
+
+ uint16_t PortableRawReader::ReadUInt16()
+ {
+ return impl->ReadUInt16();
+ }
+
+ int32_t PortableRawReader::ReadUInt16Array(uint16_t* res, const int32_t len)
+ {
+ return impl->ReadUInt16Array(res, len);
+ }
+
+ int32_t PortableRawReader::ReadInt32()
+ {
+ return impl->ReadInt32();
+ }
+
+ int32_t PortableRawReader::ReadInt32Array(int32_t* res, const int32_t len)
+ {
+ return impl->ReadInt32Array(res, len);
+ }
+
+ int64_t PortableRawReader::ReadInt64()
+ {
+ return impl->ReadInt64();
+ }
+
+ int32_t PortableRawReader::ReadInt64Array(int64_t* res, const int32_t len)
+ {
+ return impl->ReadInt64Array(res, len);
+ }
+
+ float PortableRawReader::ReadFloat()
+ {
+ return impl->ReadFloat();
+ }
+
+ int32_t PortableRawReader::ReadFloatArray(float* res, const int32_t len)
+ {
+ return impl->ReadFloatArray(res, len);
+ }
+
+ double PortableRawReader::ReadDouble()
+ {
+ return impl->ReadDouble();
+ }
+
+ int32_t PortableRawReader::ReadDoubleArray(double* res, const int32_t len)
+ {
+ return impl->ReadDoubleArray(res, len);
+ }
+
+ Guid PortableRawReader::ReadGuid()
+ {
+ return impl->ReadGuid();
+ }
+
+ int32_t PortableRawReader::ReadGuidArray(Guid* res, const int32_t len)
+ {
+ return impl->ReadGuidArray(res, len);
+ }
+
+ int32_t PortableRawReader::ReadString(char* res, const int32_t len)
+ {
+ return impl->ReadString(res, len);
+ }
+
+ PortableStringArrayReader PortableRawReader::ReadStringArray()
+ {
+ int32_t size;
+
+ int32_t id = impl->ReadStringArray(&size);
+
+ return PortableStringArrayReader(impl, id, size);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/portable/portable_raw_writer.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/portable/portable_raw_writer.cpp b/modules/platform/src/main/cpp/core/src/portable/portable_raw_writer.cpp
new file mode 100644
index 0000000..c682abe
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/portable/portable_raw_writer.cpp
@@ -0,0 +1,147 @@
+/*
+ * 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/portable/portable_writer_impl.h"
+#include "ignite/portable/portable_raw_writer.h"
+
+using namespace ignite::impl::portable;
+
+namespace ignite
+{
+ namespace portable
+ {
+ PortableRawWriter::PortableRawWriter(PortableWriterImpl* impl) : impl(impl)
+ {
+ // No-op.
+ }
+
+ void PortableRawWriter::WriteInt8(const int8_t val)
+ {
+ impl->WriteInt8(val);
+ }
+
+ void PortableRawWriter::WriteInt8Array(const int8_t* val, const int32_t len)
+ {
+ impl->WriteInt8Array(val, len);
+ }
+
+ void PortableRawWriter::WriteBool(const bool val)
+ {
+ impl->WriteBool(val);
+ }
+
+ void PortableRawWriter::WriteBoolArray(const bool* val, const int32_t len)
+ {
+ impl->WriteBoolArray(val, len);
+ }
+
+ void PortableRawWriter::WriteInt16(const int16_t val)
+ {
+ impl->WriteInt16(val);
+ }
+
+ void PortableRawWriter::WriteInt16Array(const int16_t* val, const int32_t len)
+ {
+ impl->WriteInt16Array(val, len);
+ }
+
+ void PortableRawWriter::WriteUInt16(const uint16_t val)
+ {
+ impl->WriteUInt16(val);
+ }
+
+ void PortableRawWriter::WriteUInt16Array(const uint16_t* val, const int32_t len)
+ {
+ impl->WriteUInt16Array(val, len);
+ }
+
+ void PortableRawWriter::WriteInt32(const int32_t val)
+ {
+ impl->WriteInt32(val);
+ }
+
+ void PortableRawWriter::WriteInt32Array(const int32_t* val, const int32_t len)
+ {
+ impl->WriteInt32Array(val, len);
+ }
+
+ void PortableRawWriter::WriteInt64(const int64_t val)
+ {
+ impl->WriteInt64(val);
+ }
+
+ void PortableRawWriter::WriteInt64Array(const int64_t* val, const int32_t len)
+ {
+ impl->WriteInt64Array(val, len);
+ }
+
+ void PortableRawWriter::WriteFloat(const float val)
+ {
+ impl->WriteFloat(val);
+ }
+
+ void PortableRawWriter::WriteFloatArray(const float* val, const int32_t len)
+ {
+ impl->WriteFloatArray(val, len);
+ }
+
+ void PortableRawWriter::WriteDouble(const double val)
+ {
+ impl->WriteDouble(val);
+ }
+
+ void PortableRawWriter::WriteDoubleArray(const double* val, const int32_t len)
+ {
+ impl->WriteDoubleArray(val, len);
+ }
+
+ void PortableRawWriter::WriteGuid(const Guid val)
+ {
+ impl->WriteGuid(val);
+ }
+
+ void PortableRawWriter::WriteGuidArray(const Guid* val, const int32_t len)
+ {
+ impl->WriteGuidArray(val, len);
+ }
+
+ void PortableRawWriter::WriteString(const char* val)
+ {
+ if (val)
+ WriteString(val, static_cast<int32_t>(strlen(val)));
+ else
+ WriteNull();
+ }
+
+ void PortableRawWriter::WriteString(const char* val, const int32_t len)
+ {
+ impl->WriteString(val, len);
+ }
+
+ PortableStringArrayWriter PortableRawWriter::WriteStringArray()
+ {
+ int32_t id = impl->WriteStringArray();
+
+ return PortableStringArrayWriter(impl, id);
+ }
+
+ void PortableRawWriter::WriteNull()
+ {
+ impl->WriteNull();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/portable/portable_reader.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/portable/portable_reader.cpp b/modules/platform/src/main/cpp/core/src/portable/portable_reader.cpp
new file mode 100644
index 0000000..515216d
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/portable/portable_reader.cpp
@@ -0,0 +1,142 @@
+/*
+ * 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/portable/portable_reader_impl.h"
+#include "ignite/portable/portable_reader.h"
+
+using namespace ignite::impl::portable;
+
+namespace ignite
+{
+ namespace portable
+ {
+ PortableReader::PortableReader(PortableReaderImpl* impl) : impl(impl)
+ {
+ // No-op.
+ }
+
+ int8_t PortableReader::ReadInt8(const char* fieldName)
+ {
+ return impl->ReadInt8(fieldName);
+ }
+
+ int32_t PortableReader::ReadInt8Array(const char* fieldName, int8_t* res, const int32_t len)
+ {
+ return impl->ReadInt8Array(fieldName, res, len);
+ }
+
+ bool PortableReader::ReadBool(const char* fieldName)
+ {
+ return impl->ReadBool(fieldName);
+ }
+
+ int32_t PortableReader::ReadBoolArray(const char* fieldName, bool* res, const int32_t len)
+ {
+ return impl->ReadBoolArray(fieldName, res, len);
+ }
+
+ int16_t PortableReader::ReadInt16(const char* fieldName)
+ {
+ return impl->ReadInt16(fieldName);
+ }
+
+ int32_t PortableReader::ReadInt16Array(const char* fieldName, int16_t* res, const int32_t len)
+ {
+ return impl->ReadInt16Array(fieldName, res, len);
+ }
+
+ uint16_t PortableReader::ReadUInt16(const char* fieldName)
+ {
+ return impl->ReadUInt16(fieldName);
+ }
+
+ int32_t PortableReader::ReadUInt16Array(const char* fieldName, uint16_t* res, const int32_t len)
+ {
+ return impl->ReadUInt16Array(fieldName, res, len);
+ }
+
+ int32_t PortableReader::ReadInt32(const char* fieldName)
+ {
+ return impl->ReadInt32(fieldName);
+ }
+
+ int32_t PortableReader::ReadInt32Array(const char* fieldName, int32_t* res, const int32_t len)
+ {
+ return impl->ReadInt32Array(fieldName, res, len);
+ }
+
+ int64_t PortableReader::ReadInt64(const char* fieldName)
+ {
+ return impl->ReadInt64(fieldName);
+ }
+
+ int32_t PortableReader::ReadInt64Array(const char* fieldName, int64_t* res, const int32_t len)
+ {
+ return impl->ReadInt64Array(fieldName, res, len);
+ }
+
+ float PortableReader::ReadFloat(const char* fieldName)
+ {
+ return impl->ReadFloat(fieldName);
+ }
+
+ int32_t PortableReader::ReadFloatArray(const char* fieldName, float* res, const int32_t len)
+ {
+ return impl->ReadFloatArray(fieldName, res, len);
+ }
+
+ double PortableReader::ReadDouble(const char* fieldName)
+ {
+ return impl->ReadDouble(fieldName);
+ }
+
+ int32_t PortableReader::ReadDoubleArray(const char* fieldName, double* res, const int32_t len)
+ {
+ return impl->ReadDoubleArray(fieldName, res, len);
+ }
+
+ Guid PortableReader::ReadGuid(const char* fieldName)
+ {
+ return impl->ReadGuid(fieldName);
+ }
+
+ int32_t PortableReader::ReadGuidArray(const char* fieldName, Guid* res, const int32_t len)
+ {
+ return impl->ReadGuidArray(fieldName, res, len);
+ }
+
+ int32_t PortableReader::ReadString(const char* fieldName, char* res, const int32_t len)
+ {
+ return impl->ReadString(fieldName, res, len);
+ }
+
+ PortableStringArrayReader PortableReader::ReadStringArray(const char* fieldName)
+ {
+ int32_t size;
+
+ int32_t id = impl->ReadStringArray(fieldName, &size);
+
+ return PortableStringArrayReader(impl, id, size);
+ }
+
+ PortableRawReader PortableReader::RawReader()
+ {
+ impl->SetRawMode();
+
+ return PortableRawReader(impl);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/portable/portable_type.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/portable/portable_type.cpp b/modules/platform/src/main/cpp/core/src/portable/portable_type.cpp
new file mode 100644
index 0000000..e22f869
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/portable/portable_type.cpp
@@ -0,0 +1,51 @@
+/*
+ * 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/portable/portable_type.h"
+
+namespace ignite
+{
+ namespace portable
+ {
+ int32_t GetPortableStringHashCode(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/1fc06e01/modules/platform/src/main/cpp/core/src/portable/portable_writer.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/portable/portable_writer.cpp b/modules/platform/src/main/cpp/core/src/portable/portable_writer.cpp
new file mode 100644
index 0000000..f31b9dd
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/portable/portable_writer.cpp
@@ -0,0 +1,154 @@
+/*
+ * 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/portable/portable_writer_impl.h"
+#include "ignite/portable/portable_writer.h"
+
+using namespace ignite::impl::portable;
+
+namespace ignite
+{
+ namespace portable
+ {
+ PortableWriter::PortableWriter(PortableWriterImpl* impl) : impl(impl)
+ {
+ // No-op.
+ }
+
+ void PortableWriter::WriteInt8(const char* fieldName, const int8_t val)
+ {
+ impl->WriteInt8(fieldName, val);
+ }
+
+ void PortableWriter::WriteInt8Array(const char* fieldName, const int8_t* val, const int32_t len)
+ {
+ impl->WriteInt8Array(fieldName, val, len);
+ }
+
+ void PortableWriter::WriteBool(const char* fieldName, const bool val)
+ {
+ impl->WriteBool(fieldName, val);
+ }
+
+ void PortableWriter::WriteBoolArray(const char* fieldName, const bool* val, const int32_t len)
+ {
+ impl->WriteBoolArray(fieldName, val, len);
+ }
+
+ void PortableWriter::WriteInt16(const char* fieldName, const int16_t val)
+ {
+ impl->WriteInt16(fieldName, val);
+ }
+
+ void PortableWriter::WriteInt16Array(const char* fieldName, const int16_t* val, const int32_t len)
+ {
+ impl->WriteInt16Array(fieldName, val, len);
+ }
+
+ void PortableWriter::WriteUInt16(const char* fieldName, const uint16_t val)
+ {
+ impl->WriteUInt16(fieldName, val);
+ }
+
+ void PortableWriter::WriteUInt16Array(const char* fieldName, const uint16_t* val, const int32_t len)
+ {
+ impl->WriteUInt16Array(fieldName, val, len);
+ }
+
+ void PortableWriter::WriteInt32(const char* fieldName, const int32_t val)
+ {
+ impl->WriteInt32(fieldName, val);
+ }
+
+ void PortableWriter::WriteInt32Array(const char* fieldName, const int32_t* val, const int32_t len)
+ {
+ impl->WriteInt32Array(fieldName, val, len);
+ }
+
+ void PortableWriter::WriteInt64(const char* fieldName, const int64_t val)
+ {
+ impl->WriteInt64(fieldName, val);
+ }
+
+ void PortableWriter::WriteInt64Array(const char* fieldName, const int64_t* val, const int32_t len)
+ {
+ impl->WriteInt64Array(fieldName, val, len);
+ }
+
+ void PortableWriter::WriteFloat(const char* fieldName, const float val)
+ {
+ impl->WriteFloat(fieldName, val);
+ }
+
+ void PortableWriter::WriteFloatArray(const char* fieldName, const float* val, const int32_t len)
+ {
+ impl->WriteFloatArray(fieldName, val, len);
+ }
+
+ void PortableWriter::WriteDouble(const char* fieldName, const double val)
+ {
+ impl->WriteDouble(fieldName, val);
+ }
+
+ void PortableWriter::WriteDoubleArray(const char* fieldName, const double* val, const int32_t len)
+ {
+ impl->WriteDoubleArray(fieldName, val, len);
+ }
+
+ void PortableWriter::WriteGuid(const char* fieldName, const Guid val)
+ {
+ impl->WriteGuid(fieldName, val);
+ }
+
+ void PortableWriter::WriteGuidArray(const char* fieldName, const Guid* val, const int32_t len)
+ {
+ impl->WriteGuidArray(fieldName, val, len);
+ }
+
+ void PortableWriter::WriteString(const char* fieldName, const char* val)
+ {
+ if (val)
+ WriteString(fieldName, val, static_cast<int32_t>(strlen(val)));
+ else
+ WriteNull(fieldName);
+ }
+
+ void PortableWriter::WriteString(const char* fieldName, const char* val, const int32_t len)
+ {
+ impl->WriteString(fieldName, val, len);
+ }
+
+ PortableStringArrayWriter PortableWriter::WriteStringArray(const char* fieldName)
+ {
+ int32_t id = impl->WriteStringArray(fieldName);
+
+ return PortableStringArrayWriter(impl, id);
+ }
+
+ void PortableWriter::WriteNull(const char* fieldName)
+ {
+ impl->WriteNull(fieldName);
+ }
+
+ PortableRawWriter PortableWriter::RawWriter()
+ {
+ impl->SetRawMode();
+
+ return PortableRawWriter(impl);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index ebe691f..d003cff 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -739,15 +739,19 @@
<exclude>src/main/dotnet/Apache.Ignite.sln</exclude>
<exclude>src/main/dotnet/Apache.Ignite.sln.DotSettings</exclude>
<exclude>src/main/java/META-INF/services/org.apache.ignite.internal.processors.platform.PlatformBootstrapFactory</exclude>
+ <exclude>src/main/resources/META-INF/services/org.apache.ignite.internal.processors.platform.PlatformBootstrapFactory</exclude>
<exclude>src/test/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj</exclude>
<exclude>src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.jar</exclude>
<exclude>src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.jar</exclude>
<exclude>**/Makefile.am</exclude>
<exclude>**/configure.ac</exclude>
+ <exclude>**/*.pc.in</exclude>
<exclude>**/*.vcxproj</exclude>
+ <exclude>**/*.vcxprojrel</exclude>
<exclude>**/*.vcxproj.filters</exclude>
+ <exclude>**/*.sln</exclude>
+ <exclude>**/*.slnrel</exclude>
<exclude>**/module.def</exclude>
- <exclude>**/ignite-common.pc.in</exclude>
</excludes>
</configuration>
</execution>
[06/11] ignite git commit: IGNITE-1364: Squashed commit from initial
branch.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/operations.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/operations.h b/modules/platform/src/main/cpp/core/include/ignite/impl/operations.h
new file mode 100644
index 0000000..8f32922
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/operations.h
@@ -0,0 +1,452 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL_OPERATION
+#define _IGNITE_IMPL_OPERATION
+
+#include <map>
+#include <set>
+#include <vector>
+
+#include <ignite/common/common.h>
+
+#include "ignite/cache/cache_entry.h"
+#include "ignite/impl/portable/portable_reader_impl.h"
+#include "ignite/impl/portable/portable_writer_impl.h"
+#include "ignite/portable/portable.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ /**
+ * Input operation.
+ */
+ class InputOperation
+ {
+ public:
+ /**
+ * Destructor.
+ */
+ virtual ~InputOperation()
+ {
+ // No-op.
+ }
+
+ /**
+ * Process input.
+ *
+ * @param writer Writer.
+ */
+ virtual void ProcessInput(ignite::impl::portable::PortableWriterImpl& writer) = 0;
+ };
+
+ /**
+ * Input operation accepting a single argument.
+ */
+ template<typename T>
+ class In1Operation : public InputOperation
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param val Value.
+ */
+ In1Operation(const T* val) : val(val)
+ {
+ // No-op.
+ }
+
+ virtual void ProcessInput(ignite::impl::portable::PortableWriterImpl& writer)
+ {
+ writer.WriteTopObject<T>(*val);
+ }
+ private:
+ /** Value. */
+ const T* val;
+
+ IGNITE_NO_COPY_ASSIGNMENT(In1Operation)
+ };
+
+ /**
+ * Input operation accepting two single objects.
+ */
+ template<typename T1, typename T2>
+ class In2Operation : public InputOperation
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param val1 First value.
+ * @param val2 Second value.
+ */
+ In2Operation(const T1* val1, const T2* val2) : val1(val1), val2(val2)
+ {
+ // No-op.
+ }
+
+ virtual void ProcessInput(ignite::impl::portable::PortableWriterImpl& writer)
+ {
+ writer.WriteTopObject<T1>(*val1);
+ writer.WriteTopObject<T2>(*val2);
+ }
+ private:
+ /** First value. */
+ const T1* val1;
+
+ /** Second value. */
+ const T2* val2;
+
+ IGNITE_NO_COPY_ASSIGNMENT(In2Operation)
+ };
+
+ /**
+ * Input operation accepting three single objects.
+ */
+ template<typename T1, typename T2, typename T3>
+ class In3Operation : public InputOperation
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param val1 First value.
+ * @param val2 Second value.
+ * @param val3 Third value.
+ */
+ In3Operation(const T1* val1, const T2* val2, const T3* val3) : val1(val1), val2(val2), val3(val3)
+ {
+ // No-op.
+ }
+
+ virtual void ProcessInput(ignite::impl::portable::PortableWriterImpl& writer)
+ {
+ writer.WriteTopObject<T1>(*val1);
+ writer.WriteTopObject<T2>(*val2);
+ writer.WriteTopObject<T3>(*val3);
+ }
+ private:
+ /** First value. */
+ const T1* val1;
+
+ /** Second value. */
+ const T2* val2;
+
+ /** Third value. */
+ const T3* val3;
+
+ IGNITE_NO_COPY_ASSIGNMENT(In3Operation)
+ };
+
+ /*
+ * Input set operation.
+ */
+ template<typename T>
+ class InSetOperation : public InputOperation
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param val Value.
+ */
+ InSetOperation(const std::set<T>* val) : val(val)
+ {
+ // No-op.
+ }
+
+ virtual void ProcessInput(ignite::impl::portable::PortableWriterImpl& writer)
+ {
+ writer.GetStream()->WriteInt32(static_cast<int32_t>(val->size()));
+
+ for (typename std::set<T>::const_iterator it = val->begin(); it != val->end(); ++it)
+ writer.WriteTopObject<T>(*it);
+ }
+ private:
+ /** Value. */
+ const std::set<T>* val;
+
+ IGNITE_NO_COPY_ASSIGNMENT(InSetOperation)
+ };
+
+ /**
+ * Input map operation.
+ */
+ template<typename K, typename V>
+ class InMapOperation : public InputOperation
+ {
+ public:
+ /*
+ * Constructor.
+ *
+ * @param val Value.
+ */
+ InMapOperation(const std::map<K, V>* val) : val(val)
+ {
+ // No-op.
+ }
+
+ virtual void ProcessInput(ignite::impl::portable::PortableWriterImpl& writer)
+ {
+ writer.GetStream()->WriteInt32(static_cast<int32_t>(val->size()));
+
+ for (typename std::map<K, V>::const_iterator it = val->begin(); it != val->end(); ++it) {
+ writer.WriteTopObject<K>(it->first);
+ writer.WriteTopObject<V>(it->second);
+ }
+ }
+ private:
+ /** Value. */
+ const std::map<K, V>* val;
+
+ IGNITE_NO_COPY_ASSIGNMENT(InMapOperation)
+ };
+
+ /**
+ * Cache LocalPeek input operation.
+ */
+ template<typename T>
+ class InCacheLocalPeekOperation : public InputOperation
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param key Key.
+ * @param peekModes Peek modes.
+ */
+ InCacheLocalPeekOperation(const T* key, int32_t peekModes) : key(key), peekModes(peekModes)
+ {
+ // No-op.
+ }
+
+ virtual void ProcessInput(ignite::impl::portable::PortableWriterImpl& writer)
+ {
+ writer.WriteTopObject<T>(*key);
+ writer.GetStream()->WriteInt32(peekModes);
+ }
+ private:
+ /** Key. */
+ const T* key;
+
+ /** Peek modes. */
+ int32_t peekModes;
+
+ IGNITE_NO_COPY_ASSIGNMENT(InCacheLocalPeekOperation)
+ };
+
+ /**
+ * Output operation.
+ */
+ class OutputOperation
+ {
+ public:
+ /**
+ * Destructor.
+ */
+ virtual ~OutputOperation()
+ {
+ // No-op.
+ }
+
+ /**
+ * Process output.
+ *
+ * @param reader Reader.
+ */
+ virtual void ProcessOutput(ignite::impl::portable::PortableReaderImpl& reader) = 0;
+ };
+
+ /**
+ * Output operation returning single object.
+ */
+ template<typename T>
+ class Out1Operation : public OutputOperation
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ Out1Operation()
+ {
+ // No-op.
+ }
+
+ virtual void ProcessOutput(ignite::impl::portable::PortableReaderImpl& reader)
+ {
+ val = reader.ReadTopObject<T>();
+ }
+
+ /**
+ * Get value.
+ *
+ * @param Value.
+ */
+ T GetResult()
+ {
+ return val;
+ }
+ private:
+ /** Value. */
+ T val;
+
+ IGNITE_NO_COPY_ASSIGNMENT(Out1Operation)
+ };
+
+ /**
+ * Output operation returning single object.
+ */
+ template<typename T1, typename T2>
+ class Out2Operation : public OutputOperation
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ Out2Operation()
+ {
+ // No-op.
+ }
+
+ virtual void ProcessOutput(ignite::impl::portable::PortableReaderImpl& reader)
+ {
+ val1 = reader.ReadTopObject<T1>();
+ val2 = reader.ReadTopObject<T2>();
+ }
+
+ /**
+ * Get value 1.
+ *
+ * @param Value 1.
+ */
+ T1& Get1()
+ {
+ return val1;
+ }
+
+ /**
+ * Get value 2.
+ *
+ * @param Value 2.
+ */
+ T2& Get2()
+ {
+ return val2;
+ }
+
+ private:
+ /** Value 1. */
+ T1 val1;
+
+ /** Value 2. */
+ T2 val2;
+
+ IGNITE_NO_COPY_ASSIGNMENT(Out2Operation)
+ };
+
+ /*
+ * Output map operation.
+ */
+ template<typename T1, typename T2>
+ class OutMapOperation :public OutputOperation
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ OutMapOperation()
+ {
+ // No-op.
+ }
+
+ virtual void ProcessOutput(ignite::impl::portable::PortableReaderImpl& reader)
+ {
+ bool exists = reader.GetStream()->ReadBool();
+
+ if (exists)
+ {
+ int32_t cnt = reader.GetStream()->ReadInt32();
+
+ std::map<T1, T2> val0;
+
+ for (int i = 0; i < cnt; i++) {
+ T1 t1 = reader.ReadTopObject<T1>();
+ T2 t2 = reader.ReadTopObject<T2>();
+
+ val0[t1] = t2;
+ }
+
+ val = val0;
+ }
+ }
+
+ /**
+ * Get value.
+ *
+ * @param Value.
+ */
+ std::map<T1, T2> GetResult()
+ {
+ return val;
+ }
+ private:
+ /** Value. */
+ std::map<T1, T2> val;
+
+ IGNITE_NO_COPY_ASSIGNMENT(OutMapOperation)
+ };
+
+ /*
+ * Output query GET ALL operation.
+ */
+ template<typename K, typename V>
+ class OutQueryGetAllOperation : public OutputOperation
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ OutQueryGetAllOperation(std::vector<ignite::cache::CacheEntry<K, V>>* res) : res(res)
+ {
+ // No-op.
+ }
+
+ virtual void ProcessOutput(ignite::impl::portable::PortableReaderImpl& reader)
+ {
+ int32_t cnt = reader.ReadInt32();
+
+ for (int i = 0; i < cnt; i++)
+ {
+ K key = reader.ReadTopObject<K>();
+ V val = reader.ReadTopObject<V>();
+
+ res->push_back(ignite::cache::CacheEntry<K, V>(key, val));
+ }
+ }
+
+ private:
+ /** Entries. */
+ std::vector<ignite::cache::CacheEntry<K, V>>* res;
+
+ IGNITE_NO_COPY_ASSIGNMENT(OutQueryGetAllOperation)
+ };
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_common.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_common.h b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_common.h
new file mode 100644
index 0000000..622cb54
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_common.h
@@ -0,0 +1,146 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL_PORTABLE_COMMON
+#define _IGNITE_IMPL_PORTABLE_COMMON
+
+#include <stdint.h>
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ /** Header: null. */
+ const int8_t IGNITE_HDR_NULL = 101;
+
+ /** Header: handle. */
+ const int8_t IGNITE_HDR_HND = 102;
+
+ /** Header: fulle form. */
+ const int8_t IGNITE_HDR_FULL = 103;
+
+ /** Full header length. */
+ const int32_t IGNITE_FULL_HDR_LEN = 18;
+
+ /** Type: object. */
+ const int8_t IGNITE_TYPE_OBJECT = IGNITE_HDR_FULL;
+
+ /** Type: unsigned byte. */
+ const int8_t IGNITE_TYPE_BYTE = 1;
+
+ /** Type: short. */
+ const int8_t IGNITE_TYPE_SHORT = 2;
+
+ /** Type: int. */
+ const int8_t IGNITE_TYPE_INT = 3;
+
+ /** Type: long. */
+ const int8_t IGNITE_TYPE_LONG = 4;
+
+ /** Type: float. */
+ const int8_t IGNITE_TYPE_FLOAT = 5;
+
+ /** Type: double. */
+ const int8_t IGNITE_TYPE_DOUBLE = 6;
+
+ /** Type: char. */
+ const int8_t IGNITE_TYPE_CHAR = 7;
+
+ /** Type: boolean. */
+ const int8_t IGNITE_TYPE_BOOL = 8;
+
+ /** Type: decimal. */
+ const int8_t IGNITE_TYPE_DECIMAL = 30;
+
+ /** Type: string. */
+ const int8_t IGNITE_TYPE_STRING = 9;
+
+ /** Type: UUID. */
+ const int8_t IGNITE_TYPE_UUID = 10;
+
+ /** Type: date. */
+ const int8_t IGNITE_TYPE_DATE = 11;
+
+ /** Type: unsigned byte array. */
+ const int8_t IGNITE_TYPE_ARRAY_BYTE = 12;
+
+ /** Type: short array. */
+ const int8_t IGNITE_TYPE_ARRAY_SHORT = 13;
+
+ /** Type: int array. */
+ const int8_t IGNITE_TYPE_ARRAY_INT = 14;
+
+ /** Type: long array. */
+ const int8_t IGNITE_TYPE_ARRAY_LONG = 15;
+
+ /** Type: float array. */
+ const int8_t IGNITE_TYPE_ARRAY_FLOAT = 16;
+
+ /** Type: double array. */
+ const int8_t IGNITE_TYPE_ARRAY_DOUBLE = 17;
+
+ /** Type: char array. */
+ const int8_t IGNITE_TYPE_ARRAY_CHAR = 18;
+
+ /** Type: boolean array. */
+ const int8_t IGNITE_TYPE_ARRAY_BOOL = 19;
+
+ /** Type: decimal array. */
+ const int8_t IGNITE_TYPE_ARRAY_DECIMAL = 31;
+
+ /** Type: string array. */
+ const int8_t IGNITE_TYPE_ARRAY_STRING = 20;
+
+ /** Type: UUID array. */
+ const int8_t IGNITE_TYPE_ARRAY_UUID = 21;
+
+ /** Type: date array. */
+ const int8_t IGNITE_TYPE_ARRAY_DATE = 22;
+
+ /** Type: object array. */
+ const int8_t IGNITE_TYPE_ARRAY = 23;
+
+ /** Type: collection. */
+ const int8_t IGNITE_TYPE_COLLECTION = 24;
+
+ /** Type: map. */
+ const int8_t IGNITE_TYPE_MAP = 25;
+
+ /** Type: map entry. */
+ const int8_t IGNITE_TYPE_MAP_ENTRY = 26;
+
+ /** Type: portable object. */
+ const int8_t IGNITE_TYPE_PORTABLE = 27;
+
+ /** Read/write single object. */
+ const int32_t IGNITE_PORTABLE_MODE_SINGLE = 0;
+
+ /** Read/write array. */
+ const int32_t IGNITE_PORTABLE_MODE_ARRAY = 1;
+
+ /** Read/write collection. */
+ const int32_t IGNITE_PORTABLE_MODE_COL = 2;
+
+ /** Read/write map. */
+ const int32_t IGNITE_PORTABLE_MODE_MAP = 3;
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_id_resolver.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_id_resolver.h b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_id_resolver.h
new file mode 100644
index 0000000..d8f7883
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_id_resolver.h
@@ -0,0 +1,106 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL_PORTABLE_ID_RESOLVER
+#define _IGNITE_IMPL_PORTABLE_ID_RESOLVER
+
+#include "ignite/portable/portable_type.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ /**
+ * Portable type id resolver.
+ */
+ class PortableIdResolver
+ {
+ public:
+ /**
+ * Destructor.
+ */
+ virtual ~PortableIdResolver()
+ {
+ // No-op.
+ }
+
+ /**
+ * Get portable object type ID.
+ *
+ * @return Type ID.
+ */
+ virtual int32_t GetTypeId() = 0;
+
+ /**
+ * Get portable object field ID.
+ *
+ * @param typeId Type ID.
+ * @param name Field name.
+ * @return Field ID.
+ */
+ virtual int32_t GetFieldId(const int32_t typeId, const char* name) = 0;
+ };
+
+ /**
+ * Templated portable type descriptor.
+ */
+ template<typename T>
+ class TemplatedPortableIdResolver : public PortableIdResolver
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ TemplatedPortableIdResolver()
+ {
+ type = ignite::portable::PortableType<T>();
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param type Portable type.
+ */
+ TemplatedPortableIdResolver(ignite::portable::PortableType<T> type) : type(type)
+ {
+ // No-op.
+ }
+
+ virtual int32_t GetTypeId()
+ {
+ return type.GetTypeId();
+ }
+
+ virtual int32_t GetFieldId(const int32_t typeId, const char* name) {
+ if (!name)
+ {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Field name cannot be NULL.");
+ }
+
+ return type.GetFieldId(name);
+ }
+ private:
+ /** Actual type. */
+ ignite::portable::PortableType<T> type;
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_handler.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_handler.h b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_handler.h
new file mode 100644
index 0000000..a557129
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_handler.h
@@ -0,0 +1,102 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL_PORTABLE_METADATA_HANDLER
+#define _IGNITE_IMPL_PORTABLE_METADATA_HANDLER
+
+#include <ignite/common/concurrent.h>
+
+#include "ignite/impl/portable/portable_metadata_snapshot.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ /**
+ * Metadata handler. Tracks all metadata updates during write session.
+ */
+ class PortableMetadataHandler
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param snap Snapshot.
+ */
+ PortableMetadataHandler(SPSnap snap);
+
+ /**
+ * Destructor.
+ */
+ ~PortableMetadataHandler();
+
+ /**
+ * Callback invoked when field is being written.
+ *
+ * @param fieldId Field ID.
+ * @param fieldName Field name.
+ * @param fieldTypeId Field type ID.
+ */
+ void OnFieldWritten(int32_t fieldId, std::string fieldName, int32_t fieldTypeId);
+
+ /**
+ * Get initial snapshot.
+ *
+ * @param Snapshot.
+ */
+ SPSnap GetSnapshot();
+
+ /**
+ * Whether any difference exists.
+ *
+ * @param True if difference exists.
+ */
+ bool HasDifference();
+
+ /**
+ * Get recorded field IDs difference.
+ *
+ * @param Recorded field IDs difference.
+ */
+ std::set<int32_t>* GetFieldIds();
+
+ /**
+ * Get recorded fields difference.
+ *
+ * @param Recorded fields difference.
+ */
+ std::map<std::string, int32_t>* GetFields();
+
+ private:
+ /** Snapshot. */
+ SPSnap snap;
+
+ /** Recorded field IDs difference. */
+ std::set<int32_t>* fieldIds;
+
+ /** Recorded fields difference. */
+ std::map<std::string, int32_t>* fields;
+
+ IGNITE_NO_COPY_ASSIGNMENT(PortableMetadataHandler)
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_manager.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_manager.h b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_manager.h
new file mode 100644
index 0000000..3e2b770
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_manager.h
@@ -0,0 +1,120 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL_PORTABLE_METADATA_MANAGER
+#define _IGNITE_IMPL_PORTABLE_METADATA_MANAGER
+
+#include <vector>
+
+#include "ignite/ignite_error.h"
+#include "ignite/impl/portable/portable_metadata_handler.h"
+#include "ignite/impl/portable/portable_metadata_updater.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ /**
+ * Metadata manager.
+ */
+ class IGNITE_IMPORT_EXPORT PortableMetadataManager
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ PortableMetadataManager();
+
+ /**
+ * Destructor.
+ */
+ ~PortableMetadataManager();
+
+ /**
+ * Get handler.
+ *
+ * @param typeId Type ID.
+ */
+ ignite::common::concurrent::SharedPointer<PortableMetadataHandler> GetHandler(int32_t typeId);
+
+ /**
+ * Submit handler for processing.
+ *
+ * @param typeName Type name.
+ * @param typeId Type ID.
+ * @param hnd Handler.
+ */
+ void SubmitHandler(std::string typeName, int32_t typeId, PortableMetadataHandler* hnd);
+
+ /**
+ * Get current metadata manager version.
+ *
+ * @param Version.
+ */
+ int32_t GetVersion();
+
+ /**
+ * Check whether something is updated since the given version.
+ *
+ * @param oldVer Old version.
+ * @return True if updated and it is very likely that pending metadata exists.
+ */
+ bool IsUpdatedSince(int32_t oldVer);
+
+ /**
+ * Process pending updates.
+ *
+ * @param updated Updater.
+ * @param err Error.
+ * @return In case of success.
+ */
+ bool ProcessPendingUpdates(PortableMetadataUpdater* updater, IgniteError* err);
+
+ private:
+ /** Current snapshots. */
+ ignite::common::concurrent::SharedPointer<std::map<int32_t, SPSnap>> snapshots;
+
+ /** Pending snapshots. */
+ std::vector<SPSnap>* pending;
+
+ /** Critical section. */
+ ignite::common::concurrent::CriticalSection* cs;
+
+ /** Version of pending changes. */
+ int32_t pendingVer;
+
+ /** Latest version. */
+ int32_t ver;
+
+ IGNITE_NO_COPY_ASSIGNMENT(PortableMetadataManager);
+
+ /**
+ * Copy fields from a snapshot into relevant collections.
+ *
+ * @param snap Target snapshot.
+ * @param fieldIds Field IDs.
+ * @param fields Fields.
+ */
+ void CopyFields(Snap* snap, std::set<int32_t>* fieldIds, std::map<std::string, int32_t>* fields);
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_snapshot.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_snapshot.h b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_snapshot.h
new file mode 100644
index 0000000..1e000fc
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_snapshot.h
@@ -0,0 +1,122 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL_PORTABLE_METADATA_SNAPSHOT
+#define _IGNITE_IMPL_PORTABLE_METADATA_SNAPSHOT
+
+#include <map>
+#include <set>
+#include <stdint.h>
+#include <string>
+
+#include <ignite/common/common.h>
+#include <ignite/common/concurrent.h>
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ /**
+ * Metadata snapshot.
+ */
+ class PortableMetadataSnapshot
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param typeName Type name.
+ * @param typeId Type ID.
+ * @param fieldIds Field IDs.
+ * @param fields Fields.
+ */
+ PortableMetadataSnapshot(std::string typeName, int32_t typeId, std::set<int32_t>* fieldIds,
+ std::map<std::string, int32_t>* fields);
+
+ /**
+ * Destructor.
+ */
+ ~PortableMetadataSnapshot();
+
+ /**
+ * Check whether snapshot contains a field with the given ID.
+ *
+ * @param fieldId Field ID.
+ * @return True if contains, false otherwise.
+ */
+ bool ContainsFieldId(int32_t fieldId);
+
+ /**
+ * Get type name.
+ *
+ * @param Type name.
+ */
+ std::string GetTypeName();
+
+ /**
+ * Get type ID.
+ *
+ * @return Type ID.
+ */
+ int32_t GetTypeId();
+
+ /**
+ * Whether snapshot contains any fields.
+ *
+ * @param True if fields exist.
+ */
+ bool HasFields();
+
+ /**
+ * Get field IDs.
+ *
+ * @param Field IDs.
+ */
+ std::set<int32_t>* GetFieldIds();
+
+ /**
+ * Get fields.
+ *
+ * @return Fields.
+ */
+ std::map<std::string, int32_t>* GetFields();
+
+ private:
+ /** Type name. */
+ std::string typeName;
+
+ /** Type ID. */
+ int32_t typeId;
+
+ /** Known field IDs. */
+ std::set<int32_t>* fieldIds;
+
+ /** Field name-type mappings. */
+ std::map<std::string, int32_t>* fields;
+
+ IGNITE_NO_COPY_ASSIGNMENT(PortableMetadataSnapshot)
+ };
+
+ typedef PortableMetadataSnapshot Snap;
+ typedef ignite::common::concurrent::SharedPointer<Snap> SPSnap;
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_updater.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_updater.h b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_updater.h
new file mode 100644
index 0000000..a734db7
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_updater.h
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL_PORTABLE_METADATA_UPDATER
+#define _IGNITE_IMPL_PORTABLE_METADATA_UPDATER
+
+#include "ignite/ignite_error.h"
+#include "ignite/impl/portable/portable_metadata_snapshot.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ /**
+ * Metadata updater interface.
+ */
+ class IGNITE_IMPORT_EXPORT PortableMetadataUpdater
+ {
+ public:
+ /**
+ * Destructor.
+ */
+ virtual ~PortableMetadataUpdater();
+
+ /**
+ * Update metadata using provided snapshot.
+ *
+ * @param snapshot Snapshot.
+ * @param err Error.
+ */
+ virtual bool Update(Snap* snapshot, IgniteError* err) = 0;
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_updater_impl.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_updater_impl.h b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_updater_impl.h
new file mode 100644
index 0000000..832c2a3
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_metadata_updater_impl.h
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL_PORTABLE_METADATA_UPDATER_IMPL
+#define _IGNITE_IMPL_PORTABLE_METADATA_UPDATER_IMPL
+
+#include <ignite/common/exports.h>
+
+#include "ignite/impl/ignite_environment.h"
+#include "ignite/impl/portable/portable_metadata_updater.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ /**
+ * Metadata updater implementation.
+ */
+ class IGNITE_IMPORT_EXPORT PortableMetadataUpdaterImpl : public PortableMetadataUpdater
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param env Environment.
+ * @param javaRef Reference to Java object which is able to process metadata request.
+ */
+ PortableMetadataUpdaterImpl(ignite::common::concurrent::SharedPointer<IgniteEnvironment> env, jobject javaRef);
+
+ /**
+ * Destructor.
+ */
+ ~PortableMetadataUpdaterImpl();
+
+ bool Update(Snap* snapshot, IgniteError* err);
+ private:
+ /** Environment. */
+ ignite::common::concurrent::SharedPointer<IgniteEnvironment> env;
+
+ /** Handle to Java object. */
+ jobject javaRef;
+
+ IGNITE_NO_COPY_ASSIGNMENT(PortableMetadataUpdaterImpl)
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_reader_impl.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_reader_impl.h b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_reader_impl.h
new file mode 100644
index 0000000..7d82aa2
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_reader_impl.h
@@ -0,0 +1,1130 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL_PORTABLE_READER
+#define _IGNITE_IMPL_PORTABLE_READER
+
+#include <stdint.h>
+
+#include <ignite/common/common.h>
+
+#include "ignite/impl/interop/interop_input_stream.h"
+#include "ignite/impl/portable/portable_common.h"
+#include "ignite/impl/portable/portable_id_resolver.h"
+#include "ignite/impl/portable/portable_utils.h"
+#include "ignite/impl/utils.h"
+#include "ignite/portable/portable_consts.h"
+#include "ignite/portable/portable_type.h"
+#include "ignite/guid.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ /**
+ * Internal implementation of portable reader.
+ */
+ class IGNITE_IMPORT_EXPORT PortableReaderImpl
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param stream Interop stream.
+ * @param idRslvr Portable ID resolver.
+ * @param pos Object position in the stream.
+ * @param usrType user type flag.
+ * @param typeId Type ID.
+ * @param hashcode Hash code.
+ * @param len Length in bytes.
+ * @param rawOff Raw data offset.
+ */
+ PortableReaderImpl(interop::InteropInputStream* stream, PortableIdResolver* idRslvr,
+ int32_t pos, bool usrType, int32_t typeId, int32_t hashCode, int32_t len, int32_t rawOff);
+
+ /**
+ * Constructor used to construct light-weight reader allowing only raw operations
+ * and read of primitives.
+ *
+ * @param stream Interop stream.
+ */
+ PortableReaderImpl(interop::InteropInputStream* stream);
+
+ /**
+ * Read 8-byte signed integer. Maps to "byte" type in Java.
+ *
+ * @return Result.
+ */
+ int8_t ReadInt8();
+
+ /**
+ * Read array of 8-byte signed integers. Maps to "byte[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt8Array(int8_t* res, const int32_t len);
+
+ /**
+ * Read 8-byte signed integer. Maps to "byte" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ int8_t ReadInt8(const char* fieldName);
+
+ /**
+ * Read array of 8-byte signed integers. Maps to "byte[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt8Array(const char* fieldName, int8_t* res, const int32_t len);
+
+ /**
+ * Read bool. Maps to "boolean" type in Java.
+ *
+ * @return Result.
+ */
+ bool ReadBool();
+
+ /**
+ * Read bool array. Maps to "boolean[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadBoolArray(bool* res, const int32_t len);
+
+ /**
+ * Read bool. Maps to "short" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ bool ReadBool(const char* fieldName);
+
+ /**
+ * Read bool array. Maps to "bool[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadBoolArray(const char* fieldName, bool* res, const int32_t len);
+
+ /**
+ * Read 16-byte signed integer. Maps to "short" type in Java.
+ *
+ * @return Result.
+ */
+ int16_t ReadInt16();
+
+ /**
+ * Read array of 16-byte signed integers. Maps to "short[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt16Array(int16_t* res, const int32_t len);
+
+ /**
+ * Read 16-byte signed integer. Maps to "short" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ int16_t ReadInt16(const char* fieldName);
+
+ /**
+ * Read array of 16-byte signed integers. Maps to "short[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt16Array(const char* fieldName, int16_t* res, const int32_t len);
+
+ /**
+ * Read 16-byte unsigned integer. Maps to "char" type in Java.
+ *
+ * @return Result.
+ */
+ uint16_t ReadUInt16();
+
+ /**
+ * Read array of 16-byte unsigned integers. Maps to "char[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadUInt16Array(uint16_t* res, const int32_t len);
+
+ /**
+ * Read 16-byte unsigned integer. Maps to "char" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ uint16_t ReadUInt16(const char* fieldName);
+
+ /**
+ * Read array of 16-byte unsigned integers. Maps to "char[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadUInt16Array(const char* fieldName, uint16_t* res, const int32_t len);
+
+ /**
+ * Read 32-byte signed integer. Maps to "int" type in Java.
+ *
+ * @return Result.
+ */
+ int32_t ReadInt32();
+
+ /**
+ * Read array of 32-byte signed integers. Maps to "int[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt32Array(int32_t* res, const int32_t len);
+
+ /**
+ * Read 32-byte signed integer. Maps to "int" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ int32_t ReadInt32(const char* fieldName);
+
+ /**
+ * Read array of 32-byte signed integers. Maps to "int[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt32Array(const char* fieldName, int32_t* res, const int32_t len);
+
+ /**
+ * Read 64-byte signed integer. Maps to "long" type in Java.
+ *
+ * @return Result.
+ */
+ int64_t ReadInt64();
+
+ /**
+ * Read array of 64-byte signed integers. Maps to "long[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt64Array(int64_t* res, const int32_t len);
+
+ /**
+ * Read 64-byte signed integer. Maps to "long" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ int64_t ReadInt64(const char* fieldName);
+
+ /**
+ * Read array of 64-byte signed integers. Maps to "long[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt64Array(const char* fieldName, int64_t* res, const int32_t len);
+
+ /**
+ * Read float. Maps to "float" type in Java.
+ *
+ * @return Result.
+ */
+ float ReadFloat();
+
+ /**
+ * Read float array. Maps to "float[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadFloatArray(float* res, const int32_t len);
+
+ /**
+ * Read float. Maps to "float" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ float ReadFloat(const char* fieldName);
+
+ /**
+ * Read float array. Maps to "float[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadFloatArray(const char* fieldName, float* res, const int32_t len);
+
+ /**
+ * Read double. Maps to "double" type in Java.
+ *
+ * @return Result.
+ */
+ double ReadDouble();
+
+ /**
+ * Read double array. Maps to "double[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadDoubleArray(double* res, const int32_t len);
+
+ /**
+ * Read double. Maps to "double" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ double ReadDouble(const char* fieldName);
+
+ /**
+ * Read double array. Maps to "double[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadDoubleArray(const char* fieldName, double* res, const int32_t len);
+
+ /**
+ * Read Guid. Maps to "UUID" type in Java.
+ *
+ * @return Result.
+ */
+ Guid ReadGuid();
+
+ /**
+ * Read array of Guids. Maps to "UUID[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadGuidArray(Guid* res, const int32_t len);
+
+ /**
+ * Read Guid. Maps to "UUID" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ Guid ReadGuid(const char* fieldName);
+
+ /**
+ * Read array of Guids. Maps to "UUID[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadGuidArray(const char* fieldName, Guid* res, const int32_t len);
+
+ /**
+ * Read string.
+ *
+ * @param len Expected length of string.
+ * @param res Array to store data to (should be able to acocmodate null-terminator).
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadString(char* res, const int32_t len);
+
+ /**
+ * Read string.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to (should be able to acocmodate null-terminator).
+ * @param len Expected length of string.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadString(const char* fieldName, char* res, const int32_t len);
+
+ /**
+ * Start string array read.
+ *
+ * @param size Array size.
+ * @return Read session ID.
+ */
+ int32_t ReadStringArray(int32_t* size);
+
+ /**
+ * Start string array read.
+ *
+ * @param fieldName Field name.
+ * @param size Array size.
+ * @return Read session ID.
+ */
+ int32_t ReadStringArray(const char* fieldName, int32_t* size);
+
+ /**
+ * Read string element.
+ *
+ * @param id Session ID.
+ * @param len Expected length of string.
+ * @param res Array to store data to (should be able to acocmodate null-terminator).
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadStringElement(int32_t id, char* res, const int32_t len);
+
+ /**
+ * Start array read.
+ *
+ * @param size Array size.
+ * @return Read session ID.
+ */
+ int32_t ReadArray(int32_t* size);
+
+ /**
+ * Start array read.
+ *
+ * @param fieldName Field name.
+ * @param size Array size.
+ * @return Read session ID.
+ */
+ int32_t ReadArray(const char* fieldName, int32_t* size);
+
+ /**
+ * Start collection read.
+ *
+ * @param typ Collection type.
+ * @param size Collection size.
+ * @return Read session ID.
+ */
+ int32_t ReadCollection(ignite::portable::CollectionType* typ, int32_t* size);
+
+ /**
+ * Start collection read.
+ *
+ * @param fieldName Field name.
+ * @param typ Collection type.
+ * @param size Collection size.
+ * @return Read session ID.
+ */
+ int32_t ReadCollection(const char* fieldName, ignite::portable::CollectionType* typ, int32_t* size);
+
+ /**
+ * Start map read.
+ *
+ * @param typ Map type.
+ * @param size Map size.
+ * @return Read session ID.
+ */
+ int32_t ReadMap(ignite::portable::MapType* typ, int32_t* size);
+
+ /**
+ * Start map read.
+ *
+ * @param fieldName Field name.
+ * @param typ Map type.
+ * @param size Map size.
+ * @return Read session ID.
+ */
+ int32_t ReadMap(const char* fieldName, ignite::portable::MapType* typ, int32_t* size);
+
+ /**
+ * Check whether next value exists.
+ *
+ * @param id Session ID.
+ * @return True if next element exists for the given session.
+ */
+ bool HasNextElement(int32_t id);
+
+ /**
+ * Read element.
+ *
+ * @param id Session ID.
+ * @return Value.
+ */
+ template<typename T>
+ T ReadElement(const int32_t id)
+ {
+ CheckSession(id);
+
+ if (++elemRead == elemCnt) {
+ elemId = 0;
+ elemCnt = -1;
+ elemRead = 0;
+ }
+
+ return ReadTopObject<T>();
+ }
+
+ /**
+ * Read element.
+ *
+ * @param id Session ID.
+ * @param key Key.
+ * @param val Value.
+ */
+ template<typename K, typename V>
+ void ReadElement(const int32_t id, K* key, V* val)
+ {
+ CheckSession(id);
+
+ if (++elemRead == elemCnt) {
+ elemId = 0;
+ elemCnt = -1;
+ elemRead = 0;
+ }
+
+ *key = ReadTopObject<K>();
+ *val = ReadTopObject<V>();
+ }
+
+ /**
+ * Read object.
+ *
+ * @return Object.
+ */
+ template<typename T>
+ T ReadObject()
+ {
+ CheckRawMode(true);
+
+ return ReadTopObject<T>();
+ }
+
+ /**
+ * Read object.
+ *
+ * @param fieldName Field name.
+ * @return Object.
+ */
+ template<typename T>
+ T ReadObject(const char* fieldName)
+ {
+ CheckRawMode(false);
+
+ int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName);
+
+ int32_t fieldLen = SeekField(fieldId);
+
+ if (fieldLen > 0)
+ return ReadTopObject<T>();
+
+ return GetNull<T>();
+ }
+
+ /**
+ * Set raw mode.
+ */
+ void SetRawMode();
+
+ /**
+ * Read object.
+ *
+ * @param obj Object to write.
+ */
+ template<typename T>
+ T ReadTopObject()
+ {
+ int32_t pos = stream->Position();
+ int8_t hdr = stream->ReadInt8();
+
+ if (hdr == IGNITE_HDR_NULL)
+ return GetNull<T>();
+ else if (hdr == IGNITE_HDR_HND) {
+ IGNITE_ERROR_1(ignite::IgniteError::IGNITE_ERR_PORTABLE, "Circular references are not supported.");
+ }
+ else if (hdr == IGNITE_TYPE_PORTABLE)
+ {
+ int32_t portLen = stream->ReadInt32(); // Total length of portable object.
+ int32_t curPos = stream->Position();
+ int32_t portOff = stream->ReadInt32(curPos + portLen);
+
+ stream->Position(curPos + portOff); // Position stream right on the object.
+
+ T val = ReadTopObject<T>();
+
+ stream->Position(curPos + portLen + 4); // Position stream after portable.
+
+ return val;
+ }
+ else
+ {
+ bool usrType = stream->ReadBool();
+ int32_t typeId = stream->ReadInt32();
+ int32_t hashCode = stream->ReadInt32();
+ int32_t len = stream->ReadInt32();
+ int32_t rawOff = stream->ReadInt32();
+
+ ignite::portable::PortableType<T> type;
+ TemplatedPortableIdResolver<T> idRslvr(type);
+ PortableReaderImpl readerImpl(stream, &idRslvr, pos, usrType, typeId, hashCode, len, rawOff);
+ ignite::portable::PortableReader reader(&readerImpl);
+
+ T val = type.Read(reader);
+
+ stream->Position(pos + len);
+
+ return val;
+ }
+ }
+
+ /**
+ * Get NULL value for the given type.
+ */
+ template<typename T>
+ T GetNull()
+ {
+ ignite::portable::PortableType<T> type;
+
+ return type.GetNull();
+ }
+
+ /**
+ * Get underlying stream.
+ *
+ * @return Stream.
+ */
+ impl::interop::InteropInputStream* GetStream();
+ private:
+ /** Underlying stream. */
+ interop::InteropInputStream* stream;
+
+ /** ID resolver. */
+ PortableIdResolver* idRslvr;
+
+ /** Position in the stream where this object starts. */
+ int32_t pos;
+
+ /** Whether this is user type or system type. */
+ bool usrType;
+
+ /** Type ID as defined in the stream. */
+ int32_t typeId;
+
+ /** Hash code. */
+ int32_t hashCode;
+
+ /** Total object length in the stream. */
+ int32_t len;
+
+ /** Raw data offset. */
+ int32_t rawOff;
+
+ /** Raw mode flag. */
+ bool rawMode;
+
+ /** Elements read session ID generator. */
+ int32_t elemIdGen;
+
+ /** Elements read session ID. */
+ int32_t elemId;
+
+ /** Total amount of elements in collection. */
+ int32_t elemCnt;
+
+ /** Amount of elements read. */
+ int32_t elemRead;
+
+ IGNITE_NO_COPY_ASSIGNMENT(PortableReaderImpl)
+
+ /**
+ * Internal routine to read Guid array.
+ *
+ * @param stream Stream.
+ * @param res Resulting array.
+ * @param len Length.
+ */
+ static void ReadGuidArrayInternal(
+ interop::InteropInputStream* stream,
+ Guid* res,
+ const int32_t len
+ );
+
+ /**
+ * Read single value in raw mode.
+ *
+ * @param stream Stream.
+ * @param func Function to be invoked on stream.
+ * @return Result.
+ */
+ template<typename T>
+ T ReadRaw(
+ T(*func) (interop::InteropInputStream*)
+ )
+ {
+ {
+ CheckRawMode(true);
+ CheckSingleMode(true);
+
+ return func(stream);
+ }
+ }
+
+ /**
+ * Read single value.
+ *
+ * @param fieldName Field name.
+ * @param func Function to be invoked on stream.
+ * @param epxHdr Expected header.
+ * @param dflt Default value returned if field is not found.
+ * @return Result.
+ */
+ template<typename T>
+ T Read(
+ const char* fieldName,
+ T(*func) (interop::InteropInputStream*),
+ const int8_t expHdr,
+ T dflt
+ )
+ {
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName);
+ int32_t fieldLen = SeekField(fieldId);
+
+ if (fieldLen > 0)
+ {
+ int8_t typeId = stream->ReadInt8();
+
+ if (typeId == expHdr)
+ return func(stream);
+ else if (typeId != IGNITE_HDR_NULL)
+ {
+ int32_t pos = stream->Position();
+
+ IGNITE_ERROR_FORMATTED_3(IgniteError::IGNITE_ERR_PORTABLE, "Invalid type ID",
+ "position", pos, "expected", expHdr, "actual", typeId)
+ }
+ }
+
+ return dflt;
+ }
+ }
+
+ /**
+ * Read array in raw mode.
+ *
+ * @param res Resulting array.
+ * @param len Length.
+ * @param func Function to be invoked on stream.
+ * @param expHdr Expected header.
+ * @return Length.
+ */
+ template<typename T>
+ int32_t ReadRawArray(
+ T* res,
+ const int32_t len,
+ void(*func)(interop::InteropInputStream*, T* const, const int32_t),
+ const int8_t expHdr
+ )
+ {
+ {
+ CheckRawMode(true);
+ CheckSingleMode(true);
+
+ return ReadArrayInternal(res, len, stream, func, expHdr);
+ }
+ }
+
+ /**
+ * Read array.
+ *
+ * @param fieldName Field name.
+ * @param res Resulting array.
+ * @param len Length.
+ * @param func Function to be invoked on stream.
+ * @param expHdr Expected header.
+ * @return Length.
+ */
+ template<typename T>
+ int32_t ReadArray(
+ const char* fieldName,
+ T* res,
+ const int32_t len,
+ void(*func)(interop::InteropInputStream*, T* const, const int32_t),
+ const int8_t expHdr
+ )
+ {
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ int32_t pos = stream->Position();
+
+ int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName);
+ int32_t fieldLen = SeekField(fieldId);
+
+ if (fieldLen > 0) {
+ int32_t realLen = ReadArrayInternal(res, len, stream, func, expHdr);
+
+ // If actual read didn't occur return to initial position so that we do not perform
+ // N jumps to find the field again, where N is total amount of fields.
+ if (realLen != -1 && (!res || realLen > len))
+ stream->Position(pos);
+
+ return realLen;
+ }
+
+ return -1;
+ }
+ }
+
+ /**
+ * Internal read array routine.
+ *
+ * @param res Resulting array.
+ * @param len Length.
+ * @param stream Stream.
+ * @param func Function to be invoked on stream.
+ * @param expHdr Expected header.
+ * @return Length.
+ */
+ template<typename T>
+ static int32_t ReadArrayInternal(
+ T* res,
+ const int32_t len,
+ interop::InteropInputStream* stream,
+ void(*func)(interop::InteropInputStream*, T* const, const int32_t),
+ const int8_t expHdr
+ )
+ {
+ {
+ int8_t hdr = stream->ReadInt8();
+
+ if (hdr == expHdr)
+ {
+ int32_t realLen = stream->ReadInt32();
+
+ if (realLen == 0 || (res && len >= realLen))
+ func(stream, res, realLen);
+ else
+ stream->Position(stream->Position() - 5);
+
+ return realLen;
+ }
+ else if (hdr != IGNITE_HDR_NULL)
+ ThrowOnInvalidHeader(stream->Position() - 1, expHdr, hdr);
+
+ return -1;
+ }
+ }
+
+ /**
+ * Read nullable value.
+ *
+ * @param stream Stream.
+ * @param func Function to be invoked on stream.
+ * @param expHdr Expected header.
+ */
+ template<typename T>
+ static T ReadNullable(
+ interop::InteropInputStream* stream,
+ T(*func)(interop::InteropInputStream*),
+ const int8_t expHdr
+ )
+ {
+ {
+ int8_t hdr = stream->ReadInt8();
+
+ if (hdr == expHdr)
+ return func(stream);
+ else if (hdr == IGNITE_HDR_NULL)
+ return Guid();
+ else {
+ ThrowOnInvalidHeader(stream->Position() - 1, expHdr, hdr);
+
+ return Guid();
+ }
+ }
+ }
+
+ /**
+ * Seek field with the given ID.
+ *
+ * @param fieldId Field ID.
+ * @return Field length or -1 if field is not found.
+ */
+ int32_t SeekField(const int32_t fieldId);
+
+ /**
+ * Check raw mode.
+ *
+ * @param expected Expected raw mode of the reader.
+ */
+ void CheckRawMode(bool expected);
+
+ /**
+ * Check whether reader is currently operating in single mode.
+ *
+ * @param expected Expected value.
+ */
+ void CheckSingleMode(bool expected);
+
+ /**
+ * Start new container reader session.
+ *
+ * @param expRawMode Expected raw mode.
+ * @param expHdr Expected header.
+ * @param size Container size.
+ * @return Session ID.
+ */
+ int32_t StartContainerSession(const bool expRawMode, const int8_t expHdr, int32_t* size);
+
+ /**
+ * Check whether session ID matches.
+ *
+ * @param ses Expected session ID.
+ */
+ void CheckSession(int32_t expSes);
+
+ /**
+ * Throw an error due to invalid header.
+ *
+ * @param pos Position in the stream.
+ * @param expHdr Expected header.
+ * @param hdr Actual header.
+ */
+ static void ThrowOnInvalidHeader(int32_t pos, int8_t expHdr, int8_t hdr);
+
+ /**
+ * Throw an error due to invalid header.
+ *
+ * @param expHdr Expected header.
+ * @param hdr Actual header.
+ */
+ void ThrowOnInvalidHeader(int8_t expHdr, int8_t hdr);
+
+ /**
+ * Internal string read routine.
+ *
+ * @param res Resulting array.
+ * @param len Length of array.
+ * @return Real array length.
+ */
+ int32_t ReadStringInternal(char* res, const int32_t len);
+
+ /**
+ * Read value.
+ *
+ * @param expHdr Expected header.
+ * @param func Function to be applied to the stream.
+ */
+ template<typename T>
+ T ReadTopObject0(const int8_t expHdr, T(*func) (ignite::impl::interop::InteropInputStream*))
+ {
+ int8_t typeId = stream->ReadInt8();
+
+ if (typeId == expHdr)
+ return func(stream);
+ else if (typeId == IGNITE_HDR_NULL)
+ return GetNull<T>();
+ else {
+ int32_t pos = stream->Position() - 1;
+
+ IGNITE_ERROR_FORMATTED_3(IgniteError::IGNITE_ERR_PORTABLE, "Invalid header", "position", pos, "expected", expHdr, "actual", typeId)
+ }
+ }
+
+ /**
+ * Read value.
+ *
+ * @param expHdr Expected header.
+ * @param func Function to be applied to the stream.
+ * @param dflt Default value.
+ */
+ template<typename T>
+ T ReadTopObject0(const int8_t expHdr, T(*func) (ignite::impl::interop::InteropInputStream*), T dflt)
+ {
+ int8_t typeId = stream->ReadInt8();
+
+ if (typeId == expHdr)
+ return func(stream);
+ else if (typeId == IGNITE_HDR_NULL)
+ return dflt;
+ else {
+ int32_t pos = stream->Position() - 1;
+
+ IGNITE_ERROR_FORMATTED_3(IgniteError::IGNITE_ERR_PORTABLE, "Invalid header", "position", pos, "expected", expHdr, "actual", typeId)
+ }
+ }
+ };
+
+ template<>
+ int8_t IGNITE_IMPORT_EXPORT PortableReaderImpl::ReadTopObject<int8_t>();
+
+ template<>
+ bool IGNITE_IMPORT_EXPORT PortableReaderImpl::ReadTopObject<bool>();
+
+ template<>
+ int16_t IGNITE_IMPORT_EXPORT PortableReaderImpl::ReadTopObject<int16_t>();
+
+ template<>
+ uint16_t IGNITE_IMPORT_EXPORT PortableReaderImpl::ReadTopObject<uint16_t>();
+
+ template<>
+ int32_t IGNITE_IMPORT_EXPORT PortableReaderImpl::ReadTopObject<int32_t>();
+
+ template<>
+ int64_t IGNITE_IMPORT_EXPORT PortableReaderImpl::ReadTopObject<int64_t>();
+
+ template<>
+ float IGNITE_IMPORT_EXPORT PortableReaderImpl::ReadTopObject<float>();
+
+ template<>
+ double IGNITE_IMPORT_EXPORT PortableReaderImpl::ReadTopObject<double>();
+
+
+ template<>
+ Guid IGNITE_IMPORT_EXPORT PortableReaderImpl::ReadTopObject<Guid>();
+
+ template<>
+ inline std::string IGNITE_IMPORT_EXPORT PortableReaderImpl::ReadTopObject<std::string>()
+ {
+ int8_t typeId = stream->ReadInt8();
+
+ if (typeId == IGNITE_TYPE_STRING)
+ {
+ bool utf8Mode = stream->ReadBool();
+ int32_t realLen = stream->ReadInt32();
+
+ ignite::impl::utils::SafeArray<char> arr(realLen + 1);
+
+ if (utf8Mode)
+ {
+ for (int i = 0; i < realLen; i++)
+ *(arr.target + i) = static_cast<char>(stream->ReadInt8());
+ }
+ else
+ {
+ for (int i = 0; i < realLen; i++)
+ *(arr.target + i) = static_cast<char>(stream->ReadUInt16());
+ }
+
+ *(arr.target + realLen) = 0;
+
+ return std::string(arr.target);
+ }
+
+ else if (typeId == IGNITE_HDR_NULL)
+ return std::string();
+ else {
+ int32_t pos = stream->Position() - 1;
+
+ IGNITE_ERROR_FORMATTED_3(IgniteError::IGNITE_ERR_PORTABLE, "Invalid header", "position", pos, "expected", IGNITE_TYPE_STRING, "actual", typeId)
+ }
+ }
+ }
+ }
+}
+
+#endif
\ No newline at end of file
[08/11] ignite git commit: IGNITE-1364: Squashed commit from initial
branch.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/cache/cache.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/cache.h b/modules/platform/src/main/cpp/core/include/ignite/cache/cache.h
new file mode 100644
index 0000000..dcc837b
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/cache/cache.h
@@ -0,0 +1,1153 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_CACHE
+#define _IGNITE_CACHE
+
+#include <map>
+#include <set>
+
+#include <ignite/common/common.h>
+#include <ignite/common/concurrent.h>
+
+#include "ignite/cache/cache_peek_mode.h"
+#include "ignite/cache/query/query_cursor.h"
+#include "ignite/cache/query/query_scan.h"
+#include "ignite/cache/query/query_sql.h"
+#include "ignite/cache/query/query_text.h"
+#include "ignite/impl/cache/cache_impl.h"
+#include "ignite/impl/operations.h"
+#include "ignite/ignite_error.h"
+
+namespace ignite
+{
+ namespace cache
+ {
+ /**
+ * Main entry point for all Data Grid APIs.
+ */
+ template<typename K, typename V>
+ class IGNITE_IMPORT_EXPORT Cache
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ Cache(impl::cache::CacheImpl* impl) : impl(ignite::common::concurrent::SharedPointer<impl::cache::CacheImpl>(impl))
+ {
+ // No-op.
+ }
+
+ /**
+ * Name of this cache (null for default cache).
+ */
+ char* GetName()
+ {
+ return impl.Get()->GetName();
+ }
+
+ /**
+ * Checks whether this cache contains no key-value mappings.
+ * Semantically equals to Cache.Size(IGNITE_PEEK_MODE_PRIMARY) == 0.
+ *
+ * @return True if cache is empty.
+ */
+ bool IsEmpty()
+ {
+ IgniteError err;
+
+ bool res = IsEmpty(err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Checks whether this cache contains no key-value mappings.
+ * Semantically equals to Cache.Size(IGNITE_PEEK_MODE_PRIMARY) == 0.
+ *
+ * @param err Error.
+ * @return True if cache is empty.
+ */
+ bool IsEmpty(IgniteError& err)
+ {
+ return impl.Get()->IsEmpty(&err);
+ }
+
+ /**
+ * Check if cache contains mapping for this key.
+ *
+ * @param key Key.
+ * @return True if cache contains mapping for this key.
+ */
+ bool ContainsKey(const K& key)
+ {
+ IgniteError err;
+
+ bool res = ContainsKey(key, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Check if cache contains mapping for this key.
+ *
+ * @param key Key.
+ * @param err Error.
+ * @return True if cache contains mapping for this key.
+ */
+ bool ContainsKey(const K& key, IgniteError& err)
+ {
+ impl::In1Operation<K> op(&key);
+
+ return impl.Get()->ContainsKey(op, &err);
+ }
+
+ /**
+ * Check if cache contains mapping for these keys.
+ *
+ * @param keys Keys.
+ * @return True if cache contains mapping for all these keys.
+ */
+ bool ContainsKeys(const std::set<K>& keys)
+ {
+ IgniteError err;
+
+ bool res = ContainsKeys(keys, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Check if cache contains mapping for these keys.
+ *
+ * @param keys Keys.
+ * @param err Error.
+ * @return True if cache contains mapping for all these keys.
+ */
+ bool ContainsKeys(const std::set<K>& keys, IgniteError& err)
+ {
+ impl::InSetOperation<K> op(&keys);
+
+ return impl.Get()->ContainsKeys(op, &err);
+ }
+
+ /**
+ * Peeks at cached value using optional set of peek modes. This method will sequentially
+ * iterate over given peek modes, and try to peek at value using each peek mode. Once a
+ * non-null value is found, it will be immediately returned.
+ * This method does not participate in any transactions, however, it may peek at transactional
+ * value depending on the peek modes used.
+ *
+ * @param key Key.
+ * @param peekModes Peek modes.
+ * @return Value.
+ */
+ V LocalPeek(const K& key, int32_t peekModes)
+ {
+ IgniteError err;
+
+ V res = LocalPeek(key, peekModes, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Peeks at cached value using optional set of peek modes. This method will sequentially
+ * iterate over given peek modes, and try to peek at value using each peek mode. Once a
+ * non-null value is found, it will be immediately returned.
+ * This method does not participate in any transactions, however, it may peek at transactional
+ * value depending on the peek modes used.
+ *
+ * @param key Key.
+ * @param peekModes Peek modes.
+ * @param err Error.
+ * @return Value.
+ */
+ V LocalPeek(const K& key, int32_t peekModes, IgniteError& err)
+ {
+ impl::InCacheLocalPeekOperation<K> inOp(&key, peekModes);
+ impl::Out1Operation<V> outOp;
+
+ impl.Get()->LocalPeek(inOp, outOp, peekModes, &err);
+
+ return outOp.GetResult();
+ }
+
+ /**
+ * Retrieves value mapped to the specified key from cache.
+ * If the value is not present in cache, then it will be looked up from swap storage. If
+ * it's not present in swap, or if swap is disabled, and if read-through is allowed, value
+ * will be loaded from persistent store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key.
+ * @return Value.
+ */
+ V Get(const K& key)
+ {
+ IgniteError err;
+
+ V res = Get(key, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Retrieves value mapped to the specified key from cache.
+ * If the value is not present in cache, then it will be looked up from swap storage. If
+ * it's not present in swap, or if swap is disabled, and if read-through is allowed, value
+ * will be loaded from persistent store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key.
+ * @param err Error.
+ * @return Value.
+ */
+ V Get(const K& key, IgniteError& err)
+ {
+ impl::In1Operation<K> inOp(&key);
+ impl::Out1Operation<V> outOp;
+
+ impl.Get()->Get(inOp, outOp, &err);
+
+ return outOp.GetResult();
+ }
+
+ /**
+ * Retrieves values mapped to the specified keys from cache.
+ * If some value is not present in cache, then it will be looked up from swap storage. If
+ * it's not present in swap, or if swap is disabled, and if read-through is allowed, value
+ * will be loaded from persistent store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param keys Keys.
+ * @return Map of key-value pairs.
+ */
+ std::map<K, V> GetAll(const std::set<K>& keys)
+ {
+ IgniteError err;
+
+ std::map<K, V> res = GetAll(keys, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Retrieves values mapped to the specified keys from cache.
+ * If some value is not present in cache, then it will be looked up from swap storage. If
+ * it's not present in swap, or if swap is disabled, and if read-through is allowed, value
+ * will be loaded from persistent store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param keys Keys.
+ * @param err Error.
+ * @return Map of key-value pairs.
+ */
+ std::map<K, V> GetAll(const std::set<K>& keys, IgniteError& err)
+ {
+ impl::InSetOperation<K> inOp(&keys);
+ impl::OutMapOperation<K, V> outOp;
+
+ impl.Get()->GetAll(inOp, outOp, &err);
+
+ return outOp.GetResult();
+ }
+
+ /**
+ * Associates the specified value with the specified key in the cache.
+ * If the cache previously contained a mapping for the key,
+ * the old value is replaced by the specified value.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ */
+ void Put(const K& key, const V& val)
+ {
+ IgniteError err;
+
+ Put(key, val, err);
+
+ IgniteError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Associates the specified value with the specified key in the cache.
+ * If the cache previously contained a mapping for the key,
+ * the old value is replaced by the specified value.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ * @param err Error.
+ */
+ void Put(const K& key, const V& val, IgniteError& err)
+ {
+ impl::In2Operation<K, V> op(&key, &val);
+
+ impl.Get()->Put(op, &err);
+ }
+
+ /**
+ * Stores given key-value pairs in cache.
+ * If write-through is enabled, the stored values will be persisted to store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param vals Key-value pairs to store in cache.
+ */
+ void PutAll(const std::map<K, V>& vals)
+ {
+ IgniteError err;
+
+ PutAll(vals, err);
+
+ IgniteError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Stores given key-value pairs in cache.
+ * If write-through is enabled, the stored values will be persisted to store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param vals Key-value pairs to store in cache.
+ * @param err Error.
+ */
+ void PutAll(const std::map<K, V>& vals, IgniteError& err)
+ {
+ impl::InMapOperation<K, V> op(&vals);
+
+ impl.Get()->PutAll(op, &err);
+ }
+
+ /**
+ * Associates the specified value with the specified key in this cache,
+ * returning an existing value if one existed.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ * @return The value associated with the key at the start of the
+ * operation or null if none was associated.
+ */
+ V GetAndPut(const K& key, const V& val)
+ {
+ IgniteError err;
+
+ V res = GetAndPut(key, val, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Associates the specified value with the specified key in this cache,
+ * returning an existing value if one existed.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ * @param err Error.
+ * @return The value associated with the key at the start of the
+ * operation or null if none was associated.
+ */
+ V GetAndPut(const K& key, const V& val, IgniteError& err)
+ {
+ impl::In2Operation<K, V> inOp(&key, &val);
+ impl::Out1Operation<V> outOp;
+
+ impl.Get()->GetAndPut(inOp, outOp, &err);
+
+ return outOp.GetResult();
+ }
+
+ /**
+ * Atomically replaces the value for a given key if and only if there is
+ * a value currently mapped by the key.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ * @return The previous value associated with the specified key, or
+ * null if there was no mapping for the key.
+ */
+ V GetAndReplace(const K& key, const V& val)
+ {
+ IgniteError err;
+
+ V res = GetAndReplace(key, val, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Atomically replaces the value for a given key if and only if there is
+ * a value currently mapped by the key.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ * @param err Error.
+ * @return The previous value associated with the specified key, or
+ * null if there was no mapping for the key.
+ */
+ V GetAndReplace(const K& key, const V& val, IgniteError& err)
+ {
+ impl::In2Operation<K, V> inOp(&key, &val);
+ impl::Out1Operation<V> outOp;
+
+ impl.Get()->GetAndReplace(inOp, outOp, &err);
+
+ return outOp.GetResult();
+ }
+
+ /**
+ * Atomically removes the entry for a key only if currently mapped to some value.
+ *
+ * @param key Key with which the specified value is associated.
+ * @return The value if one existed or null if no mapping existed for this key.
+ */
+ V GetAndRemove(const K& key)
+ {
+ IgniteError err;
+
+ V res = GetAndRemove(key, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Atomically removes the entry for a key only if currently mapped to some value.
+ *
+ * @param key Key with which the specified value is associated.
+ * @param err Error.
+ * @return The value if one existed or null if no mapping existed for this key.
+ */
+ V GetAndRemove(const K& key, IgniteError& err)
+ {
+ impl::In1Operation<K> inOp(&key);
+ impl::Out1Operation<V> outOp;
+
+ impl.Get()->GetAndRemove(inOp, outOp, &err);
+
+ return outOp.GetResult();
+ }
+
+ /**
+ * Atomically associates the specified key with the given value if it is not
+ * already associated with a value.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ * @return True if a value was set.
+ */
+ bool PutIfAbsent(const K& key, const V& val)
+ {
+ IgniteError err;
+
+ bool res = PutIfAbsent(key, val, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Atomically associates the specified key with the given value if it is not
+ * already associated with a value.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ * @param err Error.
+ * @return True if a value was set.
+ */
+ bool PutIfAbsent(const K& key, const V& val, IgniteError& err)
+ {
+ impl::In2Operation<K, V> op(&key, &val);
+
+ return impl.Get()->PutIfAbsent(op, &err);
+ }
+
+ /**
+ * Stores given key-value pair in cache only if cache had no previous mapping for it.
+ * If cache previously contained value for the given key, then this value is returned.
+ * In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node,
+ * which in its turn may load the value from the swap storage, and consecutively, if it's not
+ * in swap, from the underlying persistent storage.
+ * If the returned value is not needed, method putxIfAbsent() should be used instead of this one to
+ * avoid the overhead associated with returning of the previous value.
+ * If write-through is enabled, the stored value will be persisted to store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key to store in cache.
+ * @param val Value to be associated with the given key.
+ * @return Previously contained value regardless of whether put happened or not
+ * (null if there was no previous value).
+ */
+ V GetAndPutIfAbsent(const K& key, const V& val)
+ {
+ IgniteError err;
+
+ V res = GetAndPutIfAbsent(key, val, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Stores given key-value pair in cache only if cache had no previous mapping for it.
+ * If cache previously contained value for the given key, then this value is returned.
+ * In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node,
+ * which in its turn may load the value from the swap storage, and consecutively, if it's not
+ * in swap, from the underlying persistent storage.
+ * If the returned value is not needed, method putxIfAbsent() should be used instead of this one to
+ * avoid the overhead associated with returning of the previous value.
+ * If write-through is enabled, the stored value will be persisted to store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key to store in cache.
+ * @param val Value to be associated with the given key.
+ * @param err Error.
+ * @return Previously contained value regardless of whether put happened or not
+ * (null if there was no previous value).
+ */
+ V GetAndPutIfAbsent(const K& key, const V& val, IgniteError& err)
+ {
+ impl::In2Operation<K, V> inOp(&key, &val);
+ impl::Out1Operation<V> outOp;
+
+ impl.Get()->GetAndPutIfAbsent(inOp, outOp, &err);
+
+ return outOp.GetResult();
+ }
+
+ /**
+ * Stores given key-value pair in cache only if there is a previous mapping for it.
+ * If cache previously contained value for the given key, then this value is returned.
+ * In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node,
+ * which in its turn may load the value from the swap storage, and consecutively, if it's not
+ * in swap, rom the underlying persistent storage.
+ * If write-through is enabled, the stored value will be persisted to store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key to store in cache.
+ * @param val Value to be associated with the given key.
+ * @return True if the value was replaced.
+ */
+ bool Replace(const K& key, const V& val)
+ {
+ IgniteError err;
+
+ bool res = Replace(key, val, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Stores given key-value pair in cache only if there is a previous mapping for it.
+ * If cache previously contained value for the given key, then this value is returned.
+ * In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node,
+ * which in its turn may load the value from the swap storage, and consecutively, if it's not
+ * in swap, rom the underlying persistent storage.
+ * If write-through is enabled, the stored value will be persisted to store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key to store in cache.
+ * @param val Value to be associated with the given key.
+ * @param err Error.
+ * @return True if the value was replaced.
+ */
+ bool Replace(const K& key, const V& val, IgniteError& err)
+ {
+ impl::In2Operation<K, V> op(&key, &val);
+
+ return impl.Get()->Replace(op, &err);
+ }
+
+ /**
+ * Stores given key-value pair in cache only if only if the previous value is equal to the
+ * old value passed as argument.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key to store in cache.
+ * @param oldVal Old value to match.
+ * @param newVal Value to be associated with the given key.
+ * @return True if replace happened, false otherwise.
+ */
+ bool Replace(const K& key, const V& oldVal, const V& newVal)
+ {
+ IgniteError err;
+
+ bool res = Replace(key, oldVal, newVal, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Stores given key-value pair in cache only if only if the previous value is equal to the
+ * old value passed as argument.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key to store in cache.
+ * @param oldVal Old value to match.
+ * @param newVal Value to be associated with the given key.
+ * @param err Error.
+ * @return True if replace happened, false otherwise.
+ */
+ bool Replace(const K& key, const V& oldVal, const V& newVal, IgniteError& err)
+ {
+ impl::In3Operation<K, V, V> op(&key, &oldVal, &newVal);
+
+ return impl.Get()->ReplaceIfEqual(op, &err);
+ }
+
+ /**
+ * Attempts to evict all entries associated with keys. Note, that entry will be evicted only
+ * if it's not used (not participating in any locks or transactions).
+ *
+ * @param keys Keys to evict from cache.
+ */
+ void LocalEvict(const std::set<K>& keys)
+ {
+ IgniteError err;
+
+ LocalEvict(keys, err);
+
+ IgniteError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Attempts to evict all entries associated with keys. Note, that entry will be evicted only
+ * if it's not used (not participating in any locks or transactions).
+ *
+ * @param keys Keys to evict from cache.
+ * @param err Error.
+ */
+ void LocalEvict(const std::set<K>& keys, IgniteError& err)
+ {
+ impl::InSetOperation<K> op(&keys);
+
+ impl.Get()->LocalEvict(op, &err);
+ }
+
+ /**
+ * Clear cache.
+ */
+ void Clear()
+ {
+ IgniteError err;
+
+ Clear(err);
+
+ IgniteError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Clear cache.
+ *
+ * @param err Error.
+ */
+ void Clear(IgniteError& err)
+ {
+ impl.Get()->Clear(&err);
+ }
+
+ /**
+ * Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ *
+ * @param key Key to clear.
+ */
+ void Clear(const K& key)
+ {
+ IgniteError err;
+
+ Clear(key, err);
+
+ IgniteError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ *
+ * @param key Key to clear.
+ * @param err Error.
+ */
+ void Clear(const K& key, IgniteError& err)
+ {
+ impl::In1Operation<K> op(&key);
+
+ impl.Get()->Clear(op, &err);
+ }
+
+ /**
+ * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ *
+ * @param keys Keys to clear.
+ */
+ void ClearAll(const std::set<K>& keys)
+ {
+ IgniteError err;
+
+ ClearAll(keys, err);
+
+ IgniteError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ *
+ * @param keys Keys to clear.
+ * @param err Error.
+ */
+ void ClearAll(const std::set<K>& keys, IgniteError& err)
+ {
+ impl::InSetOperation<K> op(&keys);
+
+ impl.Get()->ClearAll(op, &err);
+ }
+
+ /**
+ * Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ * Note that this operation is local as it merely clears an entry from local cache, it does not
+ * remove entries from remote caches.
+ *
+ * @param key Key to clear.
+ */
+ void LocalClear(const K& key)
+ {
+ IgniteError err;
+
+ LocalClear(key, err);
+
+ IgniteError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ * Note that this operation is local as it merely clears an entry from local cache, it does not
+ * remove entries from remote caches.
+ *
+ * @param key Key to clear.
+ * @param err Error.
+ */
+ void LocalClear(const K& key, IgniteError& err)
+ {
+ impl::In1Operation<K> op(&key);
+
+ impl.Get()->LocalClear(op, &err);
+ }
+
+ /**
+ * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ * Note that this operation is local as it merely clears entries from local cache, it does not
+ * remove entries from remote caches.
+ *
+ * @param keys Keys to clear.
+ */
+ void LocalClearAll(const std::set<K>& keys)
+ {
+ IgniteError err;
+
+ LocalClearAll(keys, err);
+
+ IgniteError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ * Note that this operation is local as it merely clears entries from local cache, it does not
+ * remove entries from remote caches.
+ *
+ * @param keys Keys to clear.
+ * @param err Error.
+ */
+ void LocalClearAll(const std::set<K>& keys, IgniteError& err)
+ {
+ impl::InSetOperation<K> op(&keys);
+
+ impl.Get()->LocalClearAll(op, &err);
+ }
+
+ /**
+ * Removes given key mapping from cache. If cache previously contained value for the given key,
+ * then this value is returned. In case of PARTITIONED or REPLICATED caches, the value will be
+ * loaded from the primary node, which in its turn may load the value from the disk-based swap
+ * storage, and consecutively, if it's not in swap, from the underlying persistent storage.
+ * If the returned value is not needed, method removex() should always be used instead of this
+ * one to avoid the overhead associated with returning of the previous value.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key whose mapping is to be removed from cache.
+ * @return False if there was no matching key.
+ */
+ bool Remove(const K& key)
+ {
+ IgniteError err;
+
+ bool res = Remove(key, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Removes given key mapping from cache. If cache previously contained value for the given key,
+ * then this value is returned. In case of PARTITIONED or REPLICATED caches, the value will be
+ * loaded from the primary node, which in its turn may load the value from the disk-based swap
+ * storage, and consecutively, if it's not in swap, from the underlying persistent storage.
+ * If the returned value is not needed, method removex() should always be used instead of this
+ * one to avoid the overhead associated with returning of the previous value.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key whose mapping is to be removed from cache.
+ * @param err Error.
+ * @return False if there was no matching key.
+ */
+ bool Remove(const K& key, IgniteError& err)
+ {
+ impl::In1Operation<K> op(&key);
+
+ return impl.Get()->Remove(op, &err);
+ }
+
+ /**
+ * Removes given key mapping from cache if one exists and value is equal to the passed in value.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key whose mapping is to be removed from cache.
+ * @param val Value to match against currently cached value.
+ * @return True if entry was removed, false otherwise.
+ */
+ bool Remove(const K& key, const V& val)
+ {
+ IgniteError err;
+
+ bool res = Remove(key, val, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Removes given key mapping from cache if one exists and value is equal to the passed in value.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key whose mapping is to be removed from cache.
+ * @param val Value to match against currently cached value.
+ * @param err Error.
+ * @return True if entry was removed, false otherwise.
+ */
+ bool Remove(const K& key, const V& val, IgniteError& err)
+ {
+ impl::In2Operation<K, V> op(&key, &val);
+
+ return impl.Get()->RemoveIfEqual(op, &err);
+ }
+
+ /**
+ * Removes given key mappings from cache.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param keys Keys whose mappings are to be removed from cache.
+ */
+ void RemoveAll(const std::set<K>& keys)
+ {
+ IgniteError err;
+
+ RemoveAll(keys, err);
+
+ IgniteError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Removes given key mappings from cache.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param keys Keys whose mappings are to be removed from cache.
+ * @param err Error.
+ */
+ void RemoveAll(const std::set<K>& keys, IgniteError& err)
+ {
+ impl::InSetOperation<K> op(&keys);
+
+ impl.Get()->RemoveAll(op, &err);
+ }
+
+ /**
+ * Removes all mappings from cache.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param err Error.
+ */
+ void RemoveAll()
+ {
+ IgniteError err;
+
+ RemoveAll(err);
+
+ IgniteError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Removes all mappings from cache.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param err Error.
+ */
+ void RemoveAll(IgniteError& err)
+ {
+ return impl.Get()->RemoveAll(&err);
+ }
+
+ /**
+ * Gets the number of all entries cached on this node.
+ *
+ * @return Cache size on this node.
+ */
+ int32_t LocalSize()
+ {
+ return LocalSize(IGNITE_PEEK_MODE_ALL);
+ }
+
+ /**
+ * Gets the number of all entries cached on this node.
+ *
+ * @param err Error.
+ * @return Cache size on this node.
+ */
+ int32_t LocalSize(IgniteError& err)
+ {
+ return LocalSize(IGNITE_PEEK_MODE_ALL, err);
+ }
+
+ /**
+ * Gets the number of all entries cached on this node.
+ *
+ * @param Peek modes.
+ * @return Cache size on this node.
+ */
+ int32_t LocalSize(int32_t peekModes)
+ {
+ IgniteError err;
+
+ int32_t res = LocalSize(peekModes, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Gets the number of all entries cached on this node.
+ *
+ * @param Peek modes.
+ * @param err Error.
+ * @return Cache size on this node.
+ */
+ int32_t LocalSize(int32_t peekModes, IgniteError& err)
+ {
+ return impl.Get()->LocalSize(peekModes, &err);
+ }
+
+ /**
+ * Gets the number of all entries cached across all nodes.
+ * NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
+ *
+ * @return Cache size across all nodes.
+ */
+ int32_t Size()
+ {
+ return Size(ignite::cache::IGNITE_PEEK_MODE_ALL);
+ }
+
+ /**
+ * Gets the number of all entries cached across all nodes.
+ * NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
+ *
+ * @param err Error.
+ * @return Cache size across all nodes.
+ */
+ int32_t Size(IgniteError& err)
+ {
+ return Size(ignite::cache::IGNITE_PEEK_MODE_ALL, err);
+ }
+
+ /**
+ * Gets the number of all entries cached across all nodes.
+ * NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
+ *
+ * @param Peek modes.
+ * @return Cache size across all nodes.
+ */
+ int32_t Size(int32_t peekModes)
+ {
+ IgniteError err;
+
+ int32_t res = Size(peekModes, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Gets the number of all entries cached across all nodes.
+ * NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
+ *
+ * @param Peek modes.
+ * @param err Error.
+ * @return Cache size across all nodes.
+ */
+ int32_t Size(int32_t peekModes, IgniteError& err)
+ {
+ return impl.Get()->Size(peekModes, &err);
+ }
+
+ /**
+ * Perform SQL query.
+ *
+ * @param qry Query.
+ * @return Query cursor.
+ */
+ query::QueryCursor<K, V> Query(const query::SqlQuery& qry)
+ {
+ IgniteError err;
+
+ query::QueryCursor<K, V> res = Query(qry, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Perform SQL query.
+ *
+ * @param qry Query.
+ * @param err Error.
+ * @return Query cursor.
+ */
+ query::QueryCursor<K, V> Query(const query::SqlQuery& qry, IgniteError& err)
+ {
+ impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QuerySql(qry, &err);
+
+ return query::QueryCursor<K, V>(cursorImpl);
+ }
+
+ /*
+ * Perform text query.
+ *
+ * @param qry Query.
+ * @return Query cursor.
+ */
+ query::QueryCursor<K, V> Query(const query::TextQuery& qry)
+ {
+ IgniteError err;
+
+ query::QueryCursor<K, V> res = Query(qry, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /*
+ * Perform text query.
+ *
+ * @param qry Query.
+ * @param err Error.
+ * @return Query cursor.
+ */
+ query::QueryCursor<K, V> Query(const query::TextQuery& qry, IgniteError& err)
+ {
+ impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryText(qry, &err);
+
+ return query::QueryCursor<K, V>(cursorImpl);
+ }
+
+ /*
+ * Perform scan query.
+ *
+ * @param qry Query.
+ * @return Query cursor.
+ */
+ query::QueryCursor<K, V> Query(const query::ScanQuery& qry)
+ {
+ IgniteError err;
+
+ query::QueryCursor<K, V> res = Query(qry, err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /*
+ * Perform scan query.
+ *
+ * @param qry Query.
+ * @param err Error.
+ * @return Query cursor.
+ */
+ query::QueryCursor<K, V> Query(const query::ScanQuery& qry, IgniteError& err)
+ {
+ impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryScan(qry, &err);
+
+ return query::QueryCursor<K, V>(cursorImpl);
+ }
+
+ private:
+ /** Implementation delegate. */
+ ignite::common::concurrent::SharedPointer<impl::cache::CacheImpl> impl;
+ };
+ }
+}
+
+#endif
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/cache/cache_entry.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/cache_entry.h b/modules/platform/src/main/cpp/core/include/ignite/cache/cache_entry.h
new file mode 100644
index 0000000..2b6c785
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/cache/cache_entry.h
@@ -0,0 +1,118 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_CACHE_ENTRY
+#define _IGNITE_CACHE_ENTRY
+
+#include <ignite/common/common.h>
+
+namespace ignite
+{
+ namespace cache
+ {
+ /**
+ * Cache entry.
+ */
+ template<typename K, typename V>
+ class IGNITE_IMPORT_EXPORT CacheEntry
+ {
+ public:
+ /**
+ * Default constructor.
+ */
+ CacheEntry() : key(K()), val(V())
+ {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param key Key.
+ * @param val Value.
+ */
+ CacheEntry(const K& key, const V& val) : key(key), val(val)
+ {
+ // No-op.
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other Other instance.
+ */
+ CacheEntry(const CacheEntry& other)
+ {
+ key = other.key;
+ val = other.val;
+ }
+
+ /**
+ * Assignment operator.
+ *
+ * @param other Other instance.
+ */
+ CacheEntry& operator=(const CacheEntry& other)
+ {
+ if (this != &other)
+ {
+ CacheEntry tmp(other);
+
+ K& key0 = key;
+ V& val0 = val;
+
+ key = tmp.key;
+ val = tmp.val;
+
+ tmp.key = key0;
+ tmp.val = val0;
+ }
+
+ return *this;
+ }
+
+ /**
+ * Get key.
+ *
+ * @return Key.
+ */
+ K GetKey()
+ {
+ return key;
+ }
+
+ /**
+ * Get value.
+ *
+ * @return Value.
+ */
+ V GetValue()
+ {
+ return val;
+ }
+
+ private:
+ /** Key. */
+ K key;
+
+ /** Value. */
+ V val;
+ };
+ }
+}
+
+#endif
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/cache/cache_peek_mode.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/cache_peek_mode.h b/modules/platform/src/main/cpp/core/include/ignite/cache/cache_peek_mode.h
new file mode 100644
index 0000000..be61887
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/cache/cache_peek_mode.h
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_CACHE_PEEK_MODE
+#define _IGNITE_CACHE_PEEK_MODE
+
+namespace ignite
+{
+ namespace cache
+ {
+ /**
+ * Enumeration of all supported cache peek modes.
+ */
+ enum CachePeekMode
+ {
+ /**
+ * Peeks into all available cache storages.
+ */
+ IGNITE_PEEK_MODE_ALL = 0x01,
+
+ /**
+ * Peek into near cache only (don't peek into partitioned cache).
+ * In case of LOCAL cache, behaves as IGNITE_PEEK_MODE_ALL mode.
+ */
+ IGNITE_PEEK_MODE_NEAR = 0x02,
+
+ /**
+ * Peek value from primary copy of partitioned cache only (skip near cache).
+ * In case of LOCAL cache, behaves as IGNITE_PEEK_MODE_ALL mode.
+ */
+ IGNITE_PEEK_MODE_PRIMARY = 0x04,
+
+ /**
+ * Peek value from backup copies of partitioned cache only (skip near cache).
+ * In case of LOCAL cache, behaves as IGNITE_PEEK_MODE_ALL mode.
+ */
+ IGNITE_PEEK_MODE_BACKUP = 0x08,
+
+ /**
+ * Peeks value from the on-heap storage only.
+ */
+ IGNITE_PEEK_MODE_ONHEAP = 0x10,
+
+ /**
+ * Peeks value from the off-heap storage only, without loading off-heap value into cache.
+ */
+ IGNITE_PEEK_MODE_OFFHEAP = 0x20,
+
+ /**
+ * Peeks value from the swap storage only, without loading swapped value into cache.
+ */
+ IGNITE_PEEK_MODE_SWAP = 0x40
+ };
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/cache/query/query.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/query/query.h b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query.h
new file mode 100644
index 0000000..f2d19cd
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query.h
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_QUERY
+#define _IGNITE_QUERY
+
+#include "ignite/cache/query/query_argument.h"
+#include "ignite/cache/query/query_cursor.h"
+#include "ignite/cache/query/query_scan.h"
+#include "ignite/cache/query/query_sql.h"
+#include "ignite/cache/query/query_text.h"
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_argument.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_argument.h b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_argument.h
new file mode 100644
index 0000000..0f41c56
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_argument.h
@@ -0,0 +1,125 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_CACHE_QUERY_ARGUMENT
+#define _IGNITE_CACHE_QUERY_ARGUMENT
+
+#include "ignite/portable/portable_raw_writer.h"
+
+namespace ignite
+{
+ namespace cache
+ {
+ namespace query
+ {
+ /**
+ * Base class for all query arguments.
+ */
+ class QueryArgumentBase
+ {
+ public:
+ /**
+ * Destructor.
+ */
+ virtual ~QueryArgumentBase()
+ {
+ // No-op.
+ }
+
+ /**
+ * Copy argument.
+ *
+ * @return Copy.
+ */
+ virtual QueryArgumentBase* Copy() = 0;
+
+ /**
+ * Write argument.
+ */
+ virtual void Write(ignite::portable::PortableRawWriter& writer) = 0;
+ };
+
+ /**
+ * Query argument.
+ */
+ template<typename T>
+ class QueryArgument : public QueryArgumentBase
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param val Value.
+ */
+ QueryArgument(const T& val) : val(val)
+ {
+ // No-op.
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other Other instance.
+ */
+ QueryArgument(const QueryArgument& other)
+ {
+ val = other.val;
+ }
+
+ /**
+ * Assignment operator.
+ *
+ * @param other Other instance.
+ */
+ QueryArgument& operator=(const QueryArgument& other)
+ {
+ if (this != &other)
+ {
+ QueryArgument tmp(other);
+
+ T val0 = val;
+ val = tmp.val;
+ tmp.val = val0;
+ }
+
+ return *this;
+ }
+
+ ~QueryArgument()
+ {
+ // No-op.
+ }
+
+ QueryArgumentBase* Copy()
+ {
+ return new QueryArgument(val);
+ }
+
+ void Write(ignite::portable::PortableRawWriter& writer)
+ {
+ writer.WriteObject<T>(val);
+ }
+
+ private:
+ /** Value. */
+ T val;
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_cursor.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_cursor.h b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_cursor.h
new file mode 100644
index 0000000..23133e1
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_cursor.h
@@ -0,0 +1,191 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_CACHE_QUERY_CURSOR
+#define _IGNITE_CACHE_QUERY_CURSOR
+
+#include <vector>
+
+#include <ignite/common/concurrent.h>
+
+#include "ignite/cache/cache_entry.h"
+#include "ignite/ignite_error.h"
+#include "ignite/impl/cache/query/query_impl.h"
+#include "ignite/impl/operations.h"
+
+namespace ignite
+{
+ namespace cache
+ {
+ namespace query
+ {
+ /**
+ * Query cursor.
+ */
+ template<typename K, typename V>
+ class QueryCursor
+ {
+ public:
+ /**
+ * Default constructor.
+ */
+ QueryCursor() : impl(NULL)
+ {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param impl Implementation.
+ */
+ QueryCursor(impl::cache::query::QueryCursorImpl* impl) :
+ impl(ignite::common::concurrent::SharedPointer<impl::cache::query::QueryCursorImpl>(impl))
+ {
+ // No-op.
+ }
+
+ /**
+ * Check whether next entry exists.
+ *
+ * @return True if next entry exists.
+ */
+ bool HasNext()
+ {
+ IgniteError err;
+
+ bool res = HasNext(err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Check whether next entry exists.
+ *
+ * @param err Error.
+ * @return True if next entry exists.
+ */
+ bool HasNext(IgniteError& err)
+ {
+ impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
+
+ if (impl0)
+ return impl0->HasNext(&err);
+ else
+ {
+ err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
+ "Instance is not usable (did you check for error?).");
+
+ return false;
+ }
+ }
+
+ /**
+ * Get next entry.
+ *
+ * @return Next entry.
+ */
+ CacheEntry<K, V> GetNext()
+ {
+ IgniteError err;
+
+ CacheEntry<K, V> res = GetNext(err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Get next entry.
+ *
+ * @param err Error.
+ * @return Next entry.
+ */
+ CacheEntry<K, V> GetNext(IgniteError& err)
+ {
+ impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
+
+ if (impl0) {
+ impl::Out2Operation<K, V> outOp;
+
+ impl0->GetNext(outOp, &err);
+
+ if (err.GetCode() == IgniteError::IGNITE_SUCCESS)
+ {
+ K& key = outOp.Get1();
+ V& val = outOp.Get2();
+
+ return CacheEntry<K, V>(key, val);
+ }
+ else
+ return CacheEntry<K, V>();
+ }
+ else
+ {
+ err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
+ "Instance is not usable (did you check for error?).");
+
+ return CacheEntry<K, V>();
+ }
+ }
+
+ /**
+ * Get all entries.
+ *
+ * @param Vector where query entries will be stored.
+ */
+ void GetAll(std::vector<CacheEntry<K, V>>& res)
+ {
+ IgniteError err;
+
+ GetAll(res, err);
+
+ IgniteError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Get all entries.
+ *
+ * @param Vector where query entries will be stored.
+ * @param err Error.
+ */
+ void GetAll(std::vector<CacheEntry<K, V>>& res, IgniteError& err)
+ {
+ impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
+
+ if (impl0) {
+ impl::OutQueryGetAllOperation<K, V> outOp(&res);
+
+ impl0->GetAll(outOp, &err);
+ }
+ else
+ err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
+ "Instance is not usable (did you check for error?).");
+ }
+
+ private:
+ /** Implementation delegate. */
+ ignite::common::concurrent::SharedPointer<impl::cache::query::QueryCursorImpl> impl;
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_scan.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_scan.h b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_scan.h
new file mode 100644
index 0000000..c3ec845
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_scan.h
@@ -0,0 +1,151 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_CACHE_QUERY_SCAN
+#define _IGNITE_CACHE_QUERY_SCAN
+
+#include <stdint.h>
+#include <string>
+
+#include "ignite/portable/portable_raw_writer.h"
+
+namespace ignite
+{
+ namespace cache
+ {
+ namespace query
+ {
+ /*
+ * Scab query.
+ */
+ class ScanQuery
+ {
+ public:
+ /*
+ * Constructor.
+ */
+ ScanQuery() : part(-1), pageSize(1024), loc(false)
+ {
+ // No-op.
+ }
+
+ /*
+ * Constructor.
+ *
+ * @param part Partition.
+ */
+ ScanQuery(int32_t part) : part(part), pageSize(1024), loc(false)
+ {
+ // No-op.
+ }
+
+ /*
+ * Get partition to scan.
+ *
+ * @return Partition to scan.
+ */
+ int32_t GetPartition()
+ {
+ return part;
+ }
+
+ /*
+ * Set partition to scan.
+ *
+ * @param part Partition to scan.
+ */
+ void SetPartition(int32_t part)
+ {
+ this->part = part;
+ }
+
+ /*
+ * Get page size.
+ *
+ * @return Page size.
+ */
+ int32_t GetPageSize()
+ {
+ return pageSize;
+ }
+
+ /*
+ * Set page size.
+ *
+ * @param pageSize Page size.
+ */
+ void SetPageSize(int32_t pageSize)
+ {
+ this->pageSize = pageSize;
+ }
+
+ /*
+ * Get local flag.
+ *
+ * @return Local flag.
+ */
+ bool IsLocal()
+ {
+ return loc;
+ }
+
+ /*
+ * Set local flag.
+ *
+ * @param loc Local flag.
+ */
+ void SetLocal(bool loc)
+ {
+ this->loc = loc;
+ }
+
+ /*
+ * Write query info to the stream.
+ *
+ * @param writer Writer.
+ */
+ void Write(portable::PortableRawWriter& writer) const
+ {
+ writer.WriteBool(loc);
+ writer.WriteInt32(pageSize);
+
+ if (part < 0)
+ writer.WriteBool(false);
+ else
+ {
+ writer.WriteBool(true);
+ writer.WriteInt32(part);
+ }
+
+ writer.WriteNull(); // Predicates are not supported yet.
+ }
+
+ private:
+ /* Partition. */
+ int32_t part;
+
+ /* Page size. */
+ int32_t pageSize;
+
+ /* Local flag. */
+ bool loc;
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_sql.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_sql.h b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_sql.h
new file mode 100644
index 0000000..a2e0f33
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_sql.h
@@ -0,0 +1,253 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_CACHE_QUERY_SQL
+#define _IGNITE_CACHE_QUERY_SQL
+
+#include <stdint.h>
+#include <string>
+#include <vector>
+
+#include "ignite/cache/query/query_argument.h"
+#include "ignite/portable/portable_raw_writer.h"
+
+namespace ignite
+{
+ namespace cache
+ {
+ namespace query
+ {
+ /**
+ * Sql query.
+ */
+ class SqlQuery
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param type Type name.
+ * @param sql SQL string.
+ */
+ SqlQuery(std::string type, std::string sql) : type(type), sql(sql), pageSize(1024),
+ loc(false), args(NULL)
+ {
+ // No-op.
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other Other instance.
+ */
+ SqlQuery(const SqlQuery& other)
+ {
+ type = other.type;
+ sql = other.sql;
+ pageSize = other.pageSize;
+ loc = other.loc;
+
+ if (other.args)
+ {
+ args = new std::vector<QueryArgumentBase*>();
+
+ for (std::vector<QueryArgumentBase*>::iterator it = other.args->begin();
+ it != other.args->end(); ++it)
+ args->push_back((*it)->Copy());
+ }
+ else
+ args = NULL;
+ }
+
+ /**
+ * Assignment operator.
+ *
+ * @param other Other instance.
+ */
+ SqlQuery& operator=(const SqlQuery& other)
+ {
+ if (this != &other)
+ {
+ type = other.type;
+ sql = other.sql;
+ pageSize = other.pageSize;
+ loc = other.loc;
+
+ SqlQuery tmp(other);
+
+ std::vector<QueryArgumentBase*>* args0 = args;
+
+ args = tmp.args;
+
+ tmp.args = args0;
+ }
+
+ return *this;
+ }
+
+ /**
+ * Destructor.
+ */
+ ~SqlQuery()
+ {
+ if (args)
+ {
+ for (std::vector<QueryArgumentBase*>::iterator it = args->begin(); it != args->end(); ++it)
+ delete (*it);
+
+ delete args;
+ }
+ }
+
+ /**
+ * Get type name.
+ *
+ * @return Type name.
+ */
+ std::string GetType()
+ {
+ return type;
+ }
+
+ /**
+ * Set type name.
+ *
+ * @param sql Type name.
+ */
+ void SetType(std::string type)
+ {
+ this->type = type;
+ }
+
+ /**
+ * Get SQL string.
+ *
+ * @return SQL string.
+ */
+ std::string GetSql()
+ {
+ return sql;
+ }
+
+ /**
+ * Set SQL string.
+ *
+ * @param sql SQL string.
+ */
+ void SetSql(std::string sql)
+ {
+ this->sql = sql;
+ }
+
+ /**
+ * Get page size.
+ *
+ * @return Page size.
+ */
+ int32_t GetPageSize()
+ {
+ return pageSize;
+ }
+
+ /**
+ * Set page size.
+ *
+ * @param pageSize Page size.
+ */
+ void SetPageSize(int32_t pageSize)
+ {
+ this->pageSize = pageSize;
+ }
+
+ /**
+ * Get local flag.
+ *
+ * @return Local flag.
+ */
+ bool IsLocal()
+ {
+ return loc;
+ }
+
+ /**
+ * Set local flag.
+ *
+ * @param loc Local flag.
+ */
+ void SetLocal(bool loc)
+ {
+ this->loc = loc;
+ }
+
+ /**
+ * Add argument.
+ *
+ * @param arg Argument.
+ */
+ template<typename T>
+ void AddArgument(const T& arg)
+ {
+ if (!args)
+ args = new std::vector<QueryArgumentBase*>();
+
+ args->push_back(new QueryArgument<T>(arg));
+ }
+
+ /**
+ * Write query info to the stream.
+ *
+ * @param writer Writer.
+ */
+ void Write(portable::PortableRawWriter& writer) const
+ {
+ writer.WriteBool(loc);
+ writer.WriteString(sql);
+ writer.WriteString(type);
+ writer.WriteInt32(pageSize);
+
+ if (args)
+ {
+ writer.WriteInt32(static_cast<int32_t>(args->size()));
+
+ for (std::vector<QueryArgumentBase*>::iterator it = args->begin(); it != args->end(); ++it)
+ (*it)->Write(writer);
+ }
+ else
+ writer.WriteInt32(0);
+ }
+
+ private:
+ /** Type name. */
+ std::string type;
+
+ /** SQL string. */
+ std::string sql;
+
+ /** Page size. */
+ int32_t pageSize;
+
+ /** Local flag. */
+ bool loc;
+
+ /** Arguments. */
+ std::vector<QueryArgumentBase*>* args;
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_text.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_text.h b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_text.h
new file mode 100644
index 0000000..67d3ecc
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_text.h
@@ -0,0 +1,159 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_CACHE_QUERY_TEXT
+#define _IGNITE_CACHE_QUERY_TEXT
+
+#include <stdint.h>
+#include <string>
+
+#include "ignite/portable/portable_raw_writer.h"
+
+namespace ignite
+{
+ namespace cache
+ {
+ namespace query
+ {
+ /*
+ * Text query.
+ */
+ class TextQuery
+ {
+ public:
+ /*
+ * Constructor.
+ *
+ * @param type Type name.
+ * @param text Text string.
+ */
+ TextQuery(std::string type, std::string text) : type(type), text(text), pageSize(1024), loc(false)
+ {
+ // No-op.
+ }
+
+ /*
+ * Get type name.
+ *
+ * @return Type name.
+ */
+ std::string GetType()
+ {
+ return type;
+ }
+
+ /*
+ * Set type name.
+ *
+ * @param sql Type name.
+ */
+ void SetType(std::string type)
+ {
+ this->type = type;
+ }
+
+ /*
+ * Get text string.
+ *
+ * @return text string.
+ */
+ std::string GetText()
+ {
+ return text;
+ }
+
+ /*
+ * Set text string.
+ *
+ * @param text Text string.
+ */
+ void SetText(std::string text)
+ {
+ this->text = text;
+ }
+
+ /*
+ * Get page size.
+ *
+ * @return Page size.
+ */
+ int32_t GetPageSize()
+ {
+ return pageSize;
+ }
+
+ /*
+ * Set page size.
+ *
+ * @param pageSize Page size.
+ */
+ void SetPageSize(int32_t pageSize)
+ {
+ this->pageSize = pageSize;
+ }
+
+ /*
+ * Get local flag.
+ *
+ * @return Local flag.
+ */
+ bool IsLocal()
+ {
+ return loc;
+ }
+
+ /*
+ * Set local flag.
+ *
+ * @param loc Local flag.
+ */
+ void SetLocal(bool loc)
+ {
+ this->loc = loc;
+ }
+
+ /*
+ * Write query info to the stream.
+ *
+ * @param writer Writer.
+ */
+ void Write(portable::PortableRawWriter& writer) const
+ {
+ writer.WriteBool(loc);
+ writer.WriteString(text);
+ writer.WriteString(type);
+ writer.WriteInt32(pageSize);
+ }
+
+ private:
+ /* Type name. */
+ std::string type;
+
+ /* Text string. */
+ std::string text;
+
+ /* Page size. */
+ int32_t pageSize;
+
+ /* Local flag. */
+ bool loc;
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/guid.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/guid.h b/modules/platform/src/main/cpp/core/include/ignite/guid.h
new file mode 100644
index 0000000..9469769
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/guid.h
@@ -0,0 +1,112 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_GUID
+#define _IGNITE_GUID
+
+#include <stdint.h>
+
+#include <ignite/common/common.h>
+
+namespace ignite
+{
+ /**
+ * Global universally unique identifier (GUID).
+ */
+ class IGNITE_IMPORT_EXPORT Guid
+ {
+ public:
+ /**
+ * Default constructor.
+ */
+ Guid();
+
+ /**
+ * Constructor.
+ *
+ * @param most Most significant bits.
+ * @param least Least significant bits.
+ */
+ Guid(int64_t most, int64_t least);
+
+ /**
+ * Returns the most significant 64 bits of this instance.
+ *
+ * @return The most significant 64 bits of this instance.
+ */
+ int64_t GetMostSignificantBits() const;
+
+ /**
+ * Returns the least significant 64 bits of this instance.
+ *
+ * @return The least significant 64 bits of this instance.
+ */
+ int64_t GetLeastSignificantBits() const;
+
+ /**
+ * The version number associated with this instance. The version
+ * number describes how this Guid was generated.
+ *
+ * The version number has the following meaning:
+ * 1 Time-based UUID;
+ * 2 DCE security UUID;
+ * 3 Name-based UUID;
+ * 4 Randomly generated UUID.
+ *
+ * @return The version number of this instance.
+ */
+ int32_t GetVersion() const;
+
+ /**
+ * The variant number associated with this instance. The variant
+ * number describes the layout of the Guid.
+ *
+ * The variant number has the following meaning:
+ * 0 Reserved for NCS backward compatibility;
+ * 2 IETF RFC 4122 (Leach-Salz), used by this class;
+ * 6 Reserved, Microsoft Corporation backward compatibility;
+ * 7 Reserved for future definition.
+ *
+ * @return The variant number of this instance.
+ */
+ int32_t GetVariant() const;
+
+ /**
+ * Get hash code of this instance (used in serialization).
+ *
+ * @return Hash code.
+ */
+ int32_t GetHashCode() const;
+
+ /**
+ * Comparison operator override.
+ *
+ * @param val1 First value.
+ * @param val2 Second value.
+ * @return True if equal.
+ */
+ friend bool IGNITE_IMPORT_EXPORT operator== (Guid& val1, Guid& val2);
+ private:
+ /** Most significant bits. */
+ int64_t most;
+
+ /** Least significant bits. */
+ int64_t least;
+ };
+}
+
+#endif
\ No newline at end of file
[03/11] ignite git commit: IGNITE-1364: Squashed commit from initial
branch.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/project/vs/core.vcxproj
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/project/vs/core.vcxproj b/modules/platform/src/main/cpp/core/project/vs/core.vcxproj
new file mode 100644
index 0000000..58fa283
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/project/vs/core.vcxproj
@@ -0,0 +1,272 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{E2DEA693-F2EA-43C2-A813-053378F6E4DB}</ProjectGuid>
+ <RootNamespace>core</RootNamespace>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v100</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v100</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v100</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v100</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <TargetName>ignite.core</TargetName>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <TargetName>ignite.core</TargetName>
+ <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
+ <IntDir>$(Platform)\$(Configuration)\</IntDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <TargetName>ignite.core</TargetName>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <TargetName>ignite.core</TargetName>
+ <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
+ <IntDir>$(Platform)\$(Configuration)\</IntDir>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>false</SDLCheck>
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include</AdditionalIncludeDirectories>
+ <InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
+ <IntrinsicFunctions>false</IntrinsicFunctions>
+ <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
+ <OmitFramePointers>false</OmitFramePointers>
+ <StringPooling>true</StringPooling>
+ <MinimalRebuild>false</MinimalRebuild>
+ <BasicRuntimeChecks>Default</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalLibraryDirectories>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <OptimizeReferences>false</OptimizeReferences>
+ <EnableCOMDATFolding>false</EnableCOMDATFolding>
+ <LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>false</SDLCheck>
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include</AdditionalIncludeDirectories>
+ <InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
+ <IntrinsicFunctions>false</IntrinsicFunctions>
+ <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
+ <OmitFramePointers>false</OmitFramePointers>
+ <StringPooling>true</StringPooling>
+ <MinimalRebuild>false</MinimalRebuild>
+ <BasicRuntimeChecks>Default</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalLibraryDirectories>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <OptimizeReferences>false</OptimizeReferences>
+ <EnableCOMDATFolding>false</EnableCOMDATFolding>
+ <LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Full</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>false</SDLCheck>
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include</AdditionalIncludeDirectories>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
+ <OmitFramePointers>true</OmitFramePointers>
+ <StringPooling>true</StringPooling>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <AdditionalLibraryDirectories>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Full</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>false</SDLCheck>
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include</AdditionalIncludeDirectories>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
+ <OmitFramePointers>true</OmitFramePointers>
+ <StringPooling>true</StringPooling>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <AdditionalLibraryDirectories>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\include\ignite\cache\cache.h" />
+ <ClInclude Include="..\..\include\ignite\cache\cache_entry.h" />
+ <ClInclude Include="..\..\include\ignite\cache\cache_peek_mode.h" />
+ <ClInclude Include="..\..\include\ignite\cache\query\query.h" />
+ <ClInclude Include="..\..\include\ignite\cache\query\query_argument.h" />
+ <ClInclude Include="..\..\include\ignite\cache\query\query_cursor.h" />
+ <ClInclude Include="..\..\include\ignite\cache\query\query_scan.h" />
+ <ClInclude Include="..\..\include\ignite\cache\query\query_sql.h" />
+ <ClInclude Include="..\..\include\ignite\cache\query\query_text.h" />
+ <ClInclude Include="..\..\include\ignite\ignite.h" />
+ <ClInclude Include="..\..\include\ignite\ignite_configuration.h" />
+ <ClInclude Include="..\..\include\ignite\ignite_error.h" />
+ <ClInclude Include="..\..\include\ignite\ignition.h" />
+ <ClInclude Include="..\..\include\ignite\guid.h" />
+ <ClInclude Include="..\..\include\ignite\impl\cache\cache_impl.h" />
+ <ClInclude Include="..\..\include\ignite\impl\cache\query\query_impl.h" />
+ <ClInclude Include="..\..\include\ignite\impl\ignite_environment.h" />
+ <ClInclude Include="..\..\include\ignite\impl\ignite_impl.h" />
+ <ClInclude Include="..\..\include\ignite\impl\handle_registry.h" />
+ <ClInclude Include="..\..\include\ignite\impl\interop\interop.h" />
+ <ClInclude Include="..\..\include\ignite\impl\interop\interop_input_stream.h" />
+ <ClInclude Include="..\..\include\ignite\impl\interop\interop_memory.h" />
+ <ClInclude Include="..\..\include\ignite\impl\interop\interop_output_stream.h" />
+ <ClInclude Include="..\..\include\ignite\impl\operations.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_common.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_id_resolver.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_metadata_handler.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_metadata_manager.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_metadata_snapshot.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_metadata_updater.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_metadata_updater_impl.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_reader_impl.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_utils.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_writer_impl.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable_consts.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable_containers.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable_type.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable_raw_reader.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable_raw_writer.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable_reader.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable_writer.h" />
+ <ClInclude Include="..\..\os\win\include\ignite\impl\utils.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\os\win\src\impl\utils.cpp" />
+ <ClCompile Include="..\..\src\ignite.cpp" />
+ <ClCompile Include="..\..\src\ignite_error.cpp" />
+ <ClCompile Include="..\..\src\ignition.cpp" />
+ <ClCompile Include="..\..\src\guid.cpp" />
+ <ClCompile Include="..\..\src\impl\cache\cache_impl.cpp" />
+ <ClCompile Include="..\..\src\impl\cache\query\query_impl.cpp" />
+ <ClCompile Include="..\..\src\impl\ignite_environment.cpp" />
+ <ClCompile Include="..\..\src\impl\ignite_impl.cpp" />
+ <ClCompile Include="..\..\src\impl\handle_registry.cpp" />
+ <ClCompile Include="..\..\src\impl\interop\interop_input_stream.cpp" />
+ <ClCompile Include="..\..\src\impl\interop\interop_memory.cpp" />
+ <ClCompile Include="..\..\src\impl\interop\interop_output_stream.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_metadata_handler.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_metadata_manager.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_metadata_snapshot.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_metadata_updater.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_metadata_updater_impl.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_reader_impl.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_utils.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_writer_impl.cpp" />
+ <ClCompile Include="..\..\src\portable\portable_containers.cpp" />
+ <ClCompile Include="..\..\src\portable\portable_type.cpp" />
+ <ClCompile Include="..\..\src\portable\portable_raw_reader.cpp" />
+ <ClCompile Include="..\..\src\portable\portable_raw_writer.cpp" />
+ <ClCompile Include="..\..\src\portable\portable_reader.cpp" />
+ <ClCompile Include="..\..\src\portable\portable_writer.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\..\common\project\vs\common.vcxproj">
+ <Project>{4f7e4917-4612-4b96-9838-025711ade391}</Project>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/project/vs/core.vcxproj.filters
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/project/vs/core.vcxproj.filters b/modules/platform/src/main/cpp/core/project/vs/core.vcxproj.filters
new file mode 100644
index 0000000..d18599d
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/project/vs/core.vcxproj.filters
@@ -0,0 +1,246 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <ClCompile Include="..\..\src\impl\cache\cache_impl.cpp">
+ <Filter>Code\impl\cache</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\impl\interop\interop_input_stream.cpp">
+ <Filter>Code\impl\interop</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\impl\interop\interop_memory.cpp">
+ <Filter>Code\impl\interop</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\impl\interop\interop_output_stream.cpp">
+ <Filter>Code\impl\interop</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\impl\ignite_environment.cpp">
+ <Filter>Code\impl</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\impl\ignite_impl.cpp">
+ <Filter>Code\impl</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\portable\portable_containers.cpp">
+ <Filter>Code\portable</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\portable\portable_raw_reader.cpp">
+ <Filter>Code\portable</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\portable\portable_raw_writer.cpp">
+ <Filter>Code\portable</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\portable\portable_reader.cpp">
+ <Filter>Code\portable</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\portable\portable_writer.cpp">
+ <Filter>Code\portable</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\impl\portable\portable_reader_impl.cpp">
+ <Filter>Code\impl\portable</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\impl\portable\portable_utils.cpp">
+ <Filter>Code\impl\portable</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\impl\portable\portable_writer_impl.cpp">
+ <Filter>Code\impl\portable</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\os\win\src\impl\utils.cpp">
+ <Filter>Code\impl</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\ignite.cpp">
+ <Filter>Code</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\ignite_error.cpp">
+ <Filter>Code</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\ignition.cpp">
+ <Filter>Code</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\guid.cpp">
+ <Filter>Code</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\impl\handle_registry.cpp">
+ <Filter>Code\impl</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\impl\cache\query\query_impl.cpp">
+ <Filter>Code\impl\cache\query</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\impl\portable\portable_metadata_snapshot.cpp">
+ <Filter>Code\impl\portable</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\impl\portable\portable_metadata_handler.cpp">
+ <Filter>Code\impl\portable</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\portable\portable_type.cpp">
+ <Filter>Code\portable</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\impl\portable\portable_metadata_manager.cpp">
+ <Filter>Code\impl\portable</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\impl\portable\portable_metadata_updater.cpp">
+ <Filter>Code\impl\portable</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\impl\portable\portable_metadata_updater_impl.cpp">
+ <Filter>Code\impl\portable</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\include\ignite\impl\cache\cache_impl.h">
+ <Filter>Code\impl\cache</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\cache\cache.h">
+ <Filter>Code\cache</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\cache\cache_peek_mode.h">
+ <Filter>Code\cache</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\interop\interop.h">
+ <Filter>Code\impl\interop</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\interop\interop_input_stream.h">
+ <Filter>Code\impl\interop</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\interop\interop_memory.h">
+ <Filter>Code\impl\interop</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\interop\interop_output_stream.h">
+ <Filter>Code\impl\interop</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\ignite_environment.h">
+ <Filter>Code\impl</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\ignite_impl.h">
+ <Filter>Code\impl</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\operations.h">
+ <Filter>Code\impl</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_common.h">
+ <Filter>Code\impl\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\portable\portable_consts.h">
+ <Filter>Code\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\portable\portable.h">
+ <Filter>Code\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\portable\portable_containers.h">
+ <Filter>Code\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_id_resolver.h">
+ <Filter>Code\impl\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\portable\portable_raw_reader.h">
+ <Filter>Code\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\portable\portable_raw_writer.h">
+ <Filter>Code\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\portable\portable_reader.h">
+ <Filter>Code\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\portable\portable_writer.h">
+ <Filter>Code\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_reader_impl.h">
+ <Filter>Code\impl\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_utils.h">
+ <Filter>Code\impl\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_writer_impl.h">
+ <Filter>Code\impl\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\os\win\include\ignite\impl\utils.h">
+ <Filter>Code\impl</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\ignite.h">
+ <Filter>Code</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\ignite_configuration.h">
+ <Filter>Code</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\ignite_error.h">
+ <Filter>Code</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\ignition.h">
+ <Filter>Code</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\guid.h">
+ <Filter>Code</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\handle_registry.h">
+ <Filter>Code\impl</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\cache\cache_entry.h">
+ <Filter>Code\cache</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\cache\query\query_impl.h">
+ <Filter>Code\impl\cache\query</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_metadata_snapshot.h">
+ <Filter>Code\impl\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_metadata_handler.h">
+ <Filter>Code\impl\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_metadata_manager.h">
+ <Filter>Code\impl\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\portable\portable_type.h">
+ <Filter>Code\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_metadata_updater.h">
+ <Filter>Code\impl\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_metadata_updater_impl.h">
+ <Filter>Code\impl\portable</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\cache\query\query_argument.h">
+ <Filter>Code\cache\query</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\cache\query\query_cursor.h">
+ <Filter>Code\cache\query</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\cache\query\query_sql.h">
+ <Filter>Code\cache\query</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\cache\query\query.h">
+ <Filter>Code\cache\query</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\cache\query\query_text.h">
+ <Filter>Code\cache\query</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\cache\query\query_scan.h">
+ <Filter>Code\cache\query</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <Filter Include="Code">
+ <UniqueIdentifier>{91873c79-a64f-4786-ab25-d03ef2db9dc8}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Code\impl">
+ <UniqueIdentifier>{9bede404-e1b1-44d6-b54d-e9b2441c5f13}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Code\impl\cache">
+ <UniqueIdentifier>{b013b0f6-c4b8-4b88-89bc-8b394971788e}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Code\impl\portable">
+ <UniqueIdentifier>{883773bd-085d-4eb5-81ee-f11188134faf}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Code\impl\interop">
+ <UniqueIdentifier>{d4cc8aeb-6e7b-47e6-9b83-cba925844d96}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Code\cache">
+ <UniqueIdentifier>{8b7e32c0-e222-4f3a-af31-19df380c369f}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Code\portable">
+ <UniqueIdentifier>{24b7134c-9335-44e1-9604-4093d0e3bbf5}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Code\cache\query">
+ <UniqueIdentifier>{4658a0ff-0d2d-45a6-b8de-93eeec0cc081}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Code\impl\cache\query">
+ <UniqueIdentifier>{b6e57294-120a-46f2-b0ad-c3595e2cf789}</UniqueIdentifier>
+ </Filter>
+ </ItemGroup>
+</Project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/project/vs/core.vcxprojrel
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/project/vs/core.vcxprojrel b/modules/platform/src/main/cpp/core/project/vs/core.vcxprojrel
new file mode 100644
index 0000000..58fa283
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/project/vs/core.vcxprojrel
@@ -0,0 +1,272 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{E2DEA693-F2EA-43C2-A813-053378F6E4DB}</ProjectGuid>
+ <RootNamespace>core</RootNamespace>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v100</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v100</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v100</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v100</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <TargetName>ignite.core</TargetName>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <TargetName>ignite.core</TargetName>
+ <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
+ <IntDir>$(Platform)\$(Configuration)\</IntDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <TargetName>ignite.core</TargetName>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <TargetName>ignite.core</TargetName>
+ <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
+ <IntDir>$(Platform)\$(Configuration)\</IntDir>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>false</SDLCheck>
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include</AdditionalIncludeDirectories>
+ <InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
+ <IntrinsicFunctions>false</IntrinsicFunctions>
+ <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
+ <OmitFramePointers>false</OmitFramePointers>
+ <StringPooling>true</StringPooling>
+ <MinimalRebuild>false</MinimalRebuild>
+ <BasicRuntimeChecks>Default</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalLibraryDirectories>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <OptimizeReferences>false</OptimizeReferences>
+ <EnableCOMDATFolding>false</EnableCOMDATFolding>
+ <LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>false</SDLCheck>
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include</AdditionalIncludeDirectories>
+ <InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
+ <IntrinsicFunctions>false</IntrinsicFunctions>
+ <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
+ <OmitFramePointers>false</OmitFramePointers>
+ <StringPooling>true</StringPooling>
+ <MinimalRebuild>false</MinimalRebuild>
+ <BasicRuntimeChecks>Default</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalLibraryDirectories>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <OptimizeReferences>false</OptimizeReferences>
+ <EnableCOMDATFolding>false</EnableCOMDATFolding>
+ <LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Full</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>false</SDLCheck>
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include</AdditionalIncludeDirectories>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
+ <OmitFramePointers>true</OmitFramePointers>
+ <StringPooling>true</StringPooling>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <AdditionalLibraryDirectories>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Full</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>false</SDLCheck>
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\os\win\include</AdditionalIncludeDirectories>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
+ <OmitFramePointers>true</OmitFramePointers>
+ <StringPooling>true</StringPooling>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;IGNITE_IMPL;IGNITE_FRIEND;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <AdditionalLibraryDirectories>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalDependencies>$(JAVA_HOME)\lib\jvm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\include\ignite\cache\cache.h" />
+ <ClInclude Include="..\..\include\ignite\cache\cache_entry.h" />
+ <ClInclude Include="..\..\include\ignite\cache\cache_peek_mode.h" />
+ <ClInclude Include="..\..\include\ignite\cache\query\query.h" />
+ <ClInclude Include="..\..\include\ignite\cache\query\query_argument.h" />
+ <ClInclude Include="..\..\include\ignite\cache\query\query_cursor.h" />
+ <ClInclude Include="..\..\include\ignite\cache\query\query_scan.h" />
+ <ClInclude Include="..\..\include\ignite\cache\query\query_sql.h" />
+ <ClInclude Include="..\..\include\ignite\cache\query\query_text.h" />
+ <ClInclude Include="..\..\include\ignite\ignite.h" />
+ <ClInclude Include="..\..\include\ignite\ignite_configuration.h" />
+ <ClInclude Include="..\..\include\ignite\ignite_error.h" />
+ <ClInclude Include="..\..\include\ignite\ignition.h" />
+ <ClInclude Include="..\..\include\ignite\guid.h" />
+ <ClInclude Include="..\..\include\ignite\impl\cache\cache_impl.h" />
+ <ClInclude Include="..\..\include\ignite\impl\cache\query\query_impl.h" />
+ <ClInclude Include="..\..\include\ignite\impl\ignite_environment.h" />
+ <ClInclude Include="..\..\include\ignite\impl\ignite_impl.h" />
+ <ClInclude Include="..\..\include\ignite\impl\handle_registry.h" />
+ <ClInclude Include="..\..\include\ignite\impl\interop\interop.h" />
+ <ClInclude Include="..\..\include\ignite\impl\interop\interop_input_stream.h" />
+ <ClInclude Include="..\..\include\ignite\impl\interop\interop_memory.h" />
+ <ClInclude Include="..\..\include\ignite\impl\interop\interop_output_stream.h" />
+ <ClInclude Include="..\..\include\ignite\impl\operations.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_common.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_id_resolver.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_metadata_handler.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_metadata_manager.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_metadata_snapshot.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_metadata_updater.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_metadata_updater_impl.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_reader_impl.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_utils.h" />
+ <ClInclude Include="..\..\include\ignite\impl\portable\portable_writer_impl.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable_consts.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable_containers.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable_type.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable_raw_reader.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable_raw_writer.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable_reader.h" />
+ <ClInclude Include="..\..\include\ignite\portable\portable_writer.h" />
+ <ClInclude Include="..\..\os\win\include\ignite\impl\utils.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\os\win\src\impl\utils.cpp" />
+ <ClCompile Include="..\..\src\ignite.cpp" />
+ <ClCompile Include="..\..\src\ignite_error.cpp" />
+ <ClCompile Include="..\..\src\ignition.cpp" />
+ <ClCompile Include="..\..\src\guid.cpp" />
+ <ClCompile Include="..\..\src\impl\cache\cache_impl.cpp" />
+ <ClCompile Include="..\..\src\impl\cache\query\query_impl.cpp" />
+ <ClCompile Include="..\..\src\impl\ignite_environment.cpp" />
+ <ClCompile Include="..\..\src\impl\ignite_impl.cpp" />
+ <ClCompile Include="..\..\src\impl\handle_registry.cpp" />
+ <ClCompile Include="..\..\src\impl\interop\interop_input_stream.cpp" />
+ <ClCompile Include="..\..\src\impl\interop\interop_memory.cpp" />
+ <ClCompile Include="..\..\src\impl\interop\interop_output_stream.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_metadata_handler.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_metadata_manager.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_metadata_snapshot.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_metadata_updater.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_metadata_updater_impl.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_reader_impl.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_utils.cpp" />
+ <ClCompile Include="..\..\src\impl\portable\portable_writer_impl.cpp" />
+ <ClCompile Include="..\..\src\portable\portable_containers.cpp" />
+ <ClCompile Include="..\..\src\portable\portable_type.cpp" />
+ <ClCompile Include="..\..\src\portable\portable_raw_reader.cpp" />
+ <ClCompile Include="..\..\src\portable\portable_raw_writer.cpp" />
+ <ClCompile Include="..\..\src\portable\portable_reader.cpp" />
+ <ClCompile Include="..\..\src\portable\portable_writer.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\..\common\project\vs\common.vcxproj">
+ <Project>{4f7e4917-4612-4b96-9838-025711ade391}</Project>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/guid.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/guid.cpp b/modules/platform/src/main/cpp/core/src/guid.cpp
new file mode 100644
index 0000000..77997e4
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/guid.cpp
@@ -0,0 +1,65 @@
+/*
+ * 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<int32_t>((most >> 12) & 0x0f);
+ }
+
+ int32_t Guid::GetVariant() const
+ {
+ uint64_t least0 = static_cast<uint64_t>(least);
+
+ return static_cast<int32_t>((least0 >> (64 - (least0 >> 62))) & (least >> 63));
+ }
+
+ int32_t Guid::GetHashCode() const
+ {
+ int64_t hilo = most ^ least;
+
+ return static_cast<int32_t>(hilo >> 32) ^ static_cast<int32_t>(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/1fc06e01/modules/platform/src/main/cpp/core/src/ignite.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/ignite.cpp b/modules/platform/src/main/cpp/core/src/ignite.cpp
new file mode 100644
index 0000000..665383b
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/ignite.cpp
@@ -0,0 +1,43 @@
+/*
+ * 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/common/java.h>
+
+#include "ignite/impl/ignite_impl.h"
+#include "ignite/ignite.h"
+
+using namespace ignite::common::concurrent;
+using namespace ignite::impl;
+
+namespace ignite
+{
+ Ignite::Ignite() : impl(SharedPointer<IgniteImpl>())
+ {
+ // No-op.
+ }
+
+ Ignite::Ignite(IgniteImpl* impl) : impl(SharedPointer<IgniteImpl>(impl))
+ {
+ // No-op.
+ }
+
+ char* Ignite::GetName()
+ {
+ return impl.Get()->GetName();
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/ignite_error.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/ignite_error.cpp b/modules/platform/src/main/cpp/core/src/ignite_error.cpp
new file mode 100644
index 0000000..65cd291
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/ignite_error.cpp
@@ -0,0 +1,222 @@
+/*
+ * 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/common/java.h>
+
+#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)
+ {
+ // No-op.
+ }
+
+ IgniteError::IgniteError(int32_t code, const char* msg)
+ {
+ this->code = code;
+ this->msg = CopyChars(msg);
+ }
+
+ IgniteError::IgniteError(const IgniteError& other)
+ {
+ this->code = other.code;
+ this->msg = CopyChars(other.msg);
+ }
+
+ 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()
+ {
+ return code;
+ }
+
+ const char* IgniteError::GetText()
+ {
+ if (code == IGNITE_SUCCESS)
+ return "Operation completed successfully.";
+ else if (msg)
+ return msg;
+ else
+ return "No additional information available.";
+ }
+
+ 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/1fc06e01/modules/platform/src/main/cpp/core/src/ignition.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/ignition.cpp b/modules/platform/src/main/cpp/core/src/ignition.cpp
new file mode 100644
index 0000000..a0e3367
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/ignition.cpp
@@ -0,0 +1,468 @@
+/*
+ * 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 <sstream>
+
+#include <ignite/common/common.h>
+#include <ignite/common/concurrent.h>
+#include <ignite/common/exports.h>
+#include <ignite/common/java.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::concurrent;
+using namespace ignite::common::java;
+using namespace ignite::impl;
+using namespace ignite::impl::utils;
+
+namespace ignite
+{
+ /** Default configuration. */
+ const char* DFLT_CFG = "config/default-config.xml";
+
+ /** Whether JVM library is loaded to the process. */
+ bool JVM_LIB_LOADED;
+
+ /** Critical section for factory methods. */
+ CriticalSection factoryLock;
+
+ /** Flag indicating that at least one Ignite instance has started. */
+ bool started = false;
+
+ /**
+ * Convert integer value to string.
+ */
+ std::string JvmMemoryString(const std::string& prefix, int32_t val)
+ {
+ std::ostringstream ss;
+ ss << val;
+
+ std::string valStr = ss.str();
+
+ std::string res = std::string(prefix);
+ res.append(valStr);
+ res.append("m");
+
+ return res;
+ }
+
+ /**
+ * Create JVM options.
+ *
+ * @param cfg Configuration.
+ * @param home Optional GG home.
+ * @param cp Classpath.
+ * @param opts Options.
+ * @param optsLen Options length.
+ * @return Options.
+ */
+ char** CreateJvmOptions(const IgniteConfiguration& cfg, const std::string* home, const std::string& cp, int* optsLen)
+ {
+ *optsLen = 3 + (home ? 1 : 0) + cfg.jvmOptsLen;
+ char** opts = new char*[*optsLen];
+
+ int idx = 0;
+
+ // 1. Set classpath.
+ std::string cpFull = std::string("-Djava.class.path=") + cp;
+
+ *(opts + idx++) = CopyChars(cpFull.c_str());
+
+ // 2. Set home.
+ if (home) {
+ std::string homeFull = std::string("-DIGNITE_HOME=") + *home;
+
+ *(opts + idx++) = CopyChars(homeFull.c_str());
+ }
+
+ // 3. Set Xms, Xmx.
+ std::string xmsStr = JvmMemoryString(std::string("-Xms"), cfg.jvmInitMem);
+ std::string xmxStr = JvmMemoryString(std::string("-Xmx"), cfg.jvmMaxMem);
+
+ *(opts + idx++) = CopyChars(xmsStr.c_str());
+ *(opts + idx++) = CopyChars(xmxStr.c_str());
+
+ // 4. Set the rest options.
+ for (int i = 0; i < cfg.jvmOptsLen; i++) {
+ char* optCopy = CopyChars(cfg.jvmOpts[i].opt);
+
+ opts[idx++] = optCopy;
+ }
+
+ return opts;
+ }
+
+ Ignite Ignition::Start(const IgniteConfiguration& cfg)
+ {
+ return Start(cfg, static_cast<const char*>(NULL));
+ }
+
+ Ignite Ignition::Start(const IgniteConfiguration& cfg, IgniteError* err)
+ {
+ return Start(cfg, NULL, err);
+ }
+
+ Ignite Ignition::Start(const IgniteConfiguration& cfg, const char* name)
+ {
+ IgniteError err;
+
+ Ignite res = Start(cfg, name, &err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ Ignite Ignition::Start(const IgniteConfiguration& cfg, const char* name, IgniteError* err)
+ {
+ bool failed = false;
+
+ SharedPointer<IgniteEnvironment> env;
+ SharedPointer<IgniteEnvironment>* envTarget = NULL;
+
+ jobject javaRef = NULL;
+
+ factoryLock.Enter();
+
+ // 1. Load JVM library if needed.
+ if (!JVM_LIB_LOADED)
+ {
+ bool jvmLibFound;
+ std::string jvmLib;
+
+ if (cfg.jvmLibPath)
+ {
+ std::string jvmLibPath = std::string(cfg.jvmLibPath);
+
+ jvmLib = FindJvmLibrary(&jvmLibPath, &jvmLibFound);
+ }
+ else
+ jvmLib = FindJvmLibrary(NULL, &jvmLibFound);
+
+ if (!jvmLibFound)
+ {
+ *err = IgniteError(IgniteError::IGNITE_ERR_JVM_LIB_NOT_FOUND,
+ "JVM library is not found (did you set JAVA_HOME environment variable?)");
+
+ failed = true;
+ }
+
+ if (!failed) {
+ if (!LoadJvmLibrary(jvmLib))
+ {
+ *err = IgniteError(IgniteError::IGNITE_ERR_JVM_LIB_LOAD_FAILED, "Failed to load JVM library.");
+
+ failed = true;
+ }
+ }
+
+ JVM_LIB_LOADED = true;
+ }
+
+ if (!failed)
+ {
+ // 2. Resolve IGNITE_HOME.
+ bool homeFound;
+ std::string home;
+
+ if (cfg.igniteHome)
+ {
+ std::string homePath = std::string(cfg.igniteHome);
+
+ home = ResolveIgniteHome(&homePath, &homeFound);
+ }
+ else
+ home = ResolveIgniteHome(NULL, &homeFound);
+
+ // 3. Create classpath.
+ std::string cp;
+
+ if (cfg.jvmClassPath)
+ {
+ std::string usrCp = cfg.jvmClassPath;
+
+ cp = CreateIgniteClasspath(&usrCp, homeFound ? &home : NULL);
+ }
+ else
+ cp = CreateIgniteClasspath(NULL, homeFound ? &home : NULL);
+
+ if (!cp.empty())
+ {
+ // 4. Start JVM if needed.
+ JniErrorInfo jniErr;
+
+ env = SharedPointer<IgniteEnvironment>(new IgniteEnvironment());
+
+ int optsLen;
+ char** opts = CreateJvmOptions(cfg, homeFound ? &home : NULL, cp, &optsLen);
+
+ envTarget = new SharedPointer<IgniteEnvironment>(env);
+
+ SharedPointer<JniContext> ctx(
+ JniContext::Create(opts, optsLen, env.Get()->GetJniHandlers(envTarget), &jniErr));
+
+ for (int i = 0; i < optsLen; i++)
+ ReleaseChars(*(opts + i));
+
+ delete[] opts;
+
+ if (!ctx.Get())
+ {
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ failed = true;
+ }
+
+ // 5. Start Ignite.
+ if (!failed)
+ {
+ char* springCfgPath0 = CopyChars(cfg.springCfgPath);
+
+ if (!springCfgPath0)
+ springCfgPath0 = CopyChars(DFLT_CFG);
+
+ char* name0 = CopyChars(name);
+
+ interop::InteropUnpooledMemory mem(16);
+ interop::InteropOutputStream stream(&mem);
+ stream.WriteBool(false);
+ stream.Synchronize();
+
+ javaRef = ctx.Get()->IgnitionStart(springCfgPath0, name0, 2, mem.PointerLong(), &jniErr);
+
+ ReleaseChars(springCfgPath0);
+ ReleaseChars(name0);
+
+ if (!javaRef) {
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ failed = true;
+ }
+ else {
+ // 6. Ignite is started at this point.
+ env.Get()->Initialize(ctx);
+
+ started = true;
+ }
+ }
+ }
+ else {
+ *err = IgniteError(IgniteError::IGNITE_ERR_JVM_NO_CLASSPATH,
+ "Java classpath is empty (did you set IGNITE_HOME environment variable?)");
+
+ failed = true;
+ }
+ }
+
+ factoryLock.Leave();
+
+ if (failed)
+ {
+ if (envTarget)
+ delete envTarget;
+
+ return Ignite();
+ }
+ else
+ {
+ IgniteImpl* impl = new IgniteImpl(env, javaRef);
+
+ return Ignite(impl);
+ }
+ }
+
+ Ignite Ignition::Get()
+ {
+ return Get(static_cast<const char*>(NULL));
+ }
+
+ Ignite Ignition::Get(IgniteError* err)
+ {
+ return Get(NULL, err);
+ }
+
+ Ignite Ignition::Get(const char* name)
+ {
+ IgniteError err;
+
+ Ignite res = Get(name, &err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ Ignite Ignition::Get(const char* name, IgniteError* err)
+ {
+ Ignite res;
+
+ factoryLock.Enter();
+
+ if (started)
+ {
+ char* name0 = CopyChars(name);
+
+ // 1. Create context for this operation.
+ JniErrorInfo jniErr;
+
+ SharedPointer<JniContext> ctx(JniContext::Create(NULL, 0, JniHandlers(), &jniErr));
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ if (err->GetCode() == IgniteError::IGNITE_SUCCESS)
+ {
+ // 2. Get environment pointer.
+ long long ptr = ctx.Get()->IgnitionEnvironmentPointer(name0, &jniErr);
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ if (err->GetCode() == IgniteError::IGNITE_SUCCESS)
+ {
+ if (ptr != 0)
+ {
+ // 3. Obtain real environment for this instance.
+ JniHandlers* hnds = reinterpret_cast<JniHandlers*>(ptr);
+
+ SharedPointer<IgniteEnvironment>* env =
+ static_cast<SharedPointer<IgniteEnvironment>*>(hnds->target);
+
+ // 4. Get fresh node reference.
+ jobject ref = ctx.Get()->IgnitionInstance(name0, &jniErr);
+
+ if (err->GetCode() == IgniteError::IGNITE_SUCCESS) {
+ if (ref)
+ {
+ IgniteImpl* impl = new IgniteImpl(*env, ref);
+
+ res = Ignite(impl);
+ }
+ else
+ // Error: concurrent node stop.
+ *err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
+ "Failed to get Ignite instance because it was stopped concurrently.");
+
+ }
+ }
+ else
+ // Error: no node with the given name.
+ *err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
+ "Failed to get Ignite instance because it is either not started yet or already stopped.");
+ }
+ }
+
+ ReleaseChars(name0);
+ }
+ else
+ // Error: no node with the given name.
+ *err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
+ "Failed to get Ignite instance because it is either not started yet or already stopped.");
+
+ factoryLock.Leave();
+
+ return res;
+ }
+
+ bool Ignition::Stop(const bool cancel)
+ {
+ return Stop(NULL, cancel);
+ }
+
+ bool Ignition::Stop(const bool cancel, IgniteError* err)
+ {
+ return Stop(NULL, cancel, err);
+ }
+
+ bool Ignition::Stop(const char* name, const bool cancel)
+ {
+ IgniteError err;
+
+ bool res = Stop(name, cancel, &err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ bool Ignition::Stop(const char* name, const bool cancel, IgniteError* err)
+ {
+ bool res = false;
+
+ factoryLock.Enter();
+
+ if (started)
+ {
+ JniErrorInfo jniErr;
+
+ SharedPointer<JniContext> ctx(JniContext::Create(NULL, 0, JniHandlers(), &jniErr));
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ if (err->GetCode() == IgniteError::IGNITE_SUCCESS)
+ {
+ char* name0 = CopyChars(name);
+
+ bool res0 = ctx.Get()->IgnitionStop(name0, cancel, &jniErr);
+
+ ReleaseChars(name0);
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ if (err->GetCode() == IgniteError::IGNITE_SUCCESS)
+ res = res0;
+ }
+ }
+
+ factoryLock.Leave();
+
+ return res;
+ }
+
+ void Ignition::StopAll(const bool cancel)
+ {
+ IgniteError err;
+
+ StopAll(cancel, &err);
+
+ IgniteError::ThrowIfNeeded(err);
+ }
+
+ void Ignition::StopAll(const bool cancel, IgniteError* err)
+ {
+ factoryLock.Enter();
+
+ if (started)
+ {
+ JniErrorInfo jniErr;
+
+ SharedPointer<JniContext> ctx(JniContext::Create(NULL, 0, JniHandlers(), &jniErr));
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ if (err->GetCode() == IgniteError::IGNITE_SUCCESS)
+ {
+ ctx.Get()->IgnitionStopAll(cancel, &jniErr);
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+ }
+ }
+
+ factoryLock.Leave();
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/impl/cache/cache_impl.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/cache/cache_impl.cpp b/modules/platform/src/main/cpp/core/src/impl/cache/cache_impl.cpp
new file mode 100644
index 0000000..2f211e7
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/cache/cache_impl.cpp
@@ -0,0 +1,388 @@
+/*
+ * 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/cache/cache_peek_mode.h"
+#include "ignite/impl/cache/cache_impl.h"
+#include "ignite/impl/interop/interop.h"
+#include "ignite/impl/portable/portable_reader_impl.h"
+#include "ignite/impl/utils.h"
+#include "ignite/impl/portable/portable_metadata_updater_impl.h"
+#include "ignite/portable/portable.h"
+
+using namespace ignite::common::concurrent;
+using namespace ignite::common::java;
+using namespace ignite::cache;
+using namespace ignite::cache::query;
+using namespace ignite::impl;
+using namespace ignite::impl::cache::query;
+using namespace ignite::impl::interop;
+using namespace ignite::impl::portable;
+using namespace ignite::impl::utils;
+using namespace ignite::portable;
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace cache
+ {
+ /** Operation: Clear. */
+ const int32_t OP_CLEAR = 1;
+
+ /** Operation: ClearAll. */
+ const int32_t OP_CLEAR_ALL = 2;
+
+ /** Operation: ContainsKey. */
+ const int32_t OP_CONTAINS_KEY = 3;
+
+ /** Operation: ContainsKeys. */
+ const int32_t OP_CONTAINS_KEYS = 4;
+
+ /** Operation: Get. */
+ const int32_t OP_GET = 5;
+
+ /** Operation: GetAll. */
+ const int32_t OP_GET_ALL = 6;
+
+ /** Operation: GetAndPut. */
+ const int32_t OP_GET_AND_PUT = 7;
+
+ /** Operation: GetAndPutIfAbsent. */
+ const int32_t OP_GET_AND_PUT_IF_ABSENT = 8;
+
+ /** Operation: GetAndRemove. */
+ const int32_t OP_GET_AND_REMOVE = 9;
+
+ /** Operation: GetAndReplace. */
+ const int32_t OP_GET_AND_REPLACE = 10;
+
+ /** Operation: LocalEvict. */
+ const int32_t OP_LOCAL_EVICT = 16;
+
+ /** Operation: LocalClear. */
+ const int32_t OP_LOCAL_CLEAR = 20;
+
+ /** Operation: LocalClearAll. */
+ const int32_t OP_LOCAL_CLEAR_ALL = 21;
+
+ /** Operation: LocalPeek. */
+ const int32_t OP_LOCAL_PEEK = 25;
+
+ /** Operation: Put. */
+ const int32_t OP_PUT = 26;
+
+ /** Operation: PutAll. */
+ const int32_t OP_PUT_ALL = 27;
+
+ /** Operation: PutIfAbsent. */
+ const int32_t OP_PUT_IF_ABSENT = 28;
+
+ /** Operation: SCAN query. */
+ const int32_t OP_QRY_SCAN = 30;
+
+ /** Operation: SQL query. */
+ const int32_t OP_QRY_SQL = 31;
+
+ /** Operation: SQL fields query. */
+ const int32_t OP_QRY_SQL_FIELDS = 32;
+
+ /** Operation: TEXT query. */
+ const int32_t OP_QRY_TEXT = 33;
+
+ /** Operation: RemoveAll. */
+ const int32_t OP_REMOVE_ALL = 34;
+
+ /** Operation: Remove(K, V). */
+ const int32_t OP_REMOVE_2 = 35;
+
+ /** Operation: Remove(K). */
+ const int32_t OP_REMOVE_1 = 36;
+
+ /** Operation: Replace(K, V). */
+ const int32_t OP_REPLACE_2 = 37;
+
+ /** Operation: Replace(K, V, V). */
+ const int32_t OP_REPLACE_3 = 38;
+
+ CacheImpl::CacheImpl(char* name, SharedPointer<IgniteEnvironment> env, jobject javaRef) :
+ name(name), env(env), javaRef(javaRef)
+ {
+ // No-op.
+ }
+
+ CacheImpl::~CacheImpl()
+ {
+ ReleaseChars(name);
+
+ JniContext::Release(javaRef);
+ }
+
+ char* CacheImpl::GetName()
+ {
+ return name;
+ }
+
+ bool CacheImpl::IsEmpty(IgniteError* err)
+ {
+ return Size(IGNITE_PEEK_MODE_ALL, err) == 0;
+ }
+
+ bool CacheImpl::ContainsKey(InputOperation& inOp, IgniteError* err)
+ {
+ return OutOpInternal(OP_CONTAINS_KEY, inOp, err);
+ }
+
+ bool CacheImpl::ContainsKeys(InputOperation& inOp, IgniteError* err)
+ {
+ return OutOpInternal(OP_CONTAINS_KEYS, inOp, err);
+ }
+
+ void CacheImpl::LocalPeek(InputOperation& inOp, OutputOperation& outOp, int32_t peekModes, IgniteError* err)
+ {
+ OutInOpInternal(OP_LOCAL_PEEK, inOp, outOp, err);
+ }
+
+ void CacheImpl::Get(InputOperation& inOp, OutputOperation& outOp, IgniteError* err)
+ {
+ OutInOpInternal(OP_GET, inOp, outOp, err);
+ }
+
+ void CacheImpl::GetAll(InputOperation& inOp, OutputOperation& outOp, IgniteError* err)
+ {
+ OutInOpInternal(OP_GET_ALL, inOp, outOp, err);
+ }
+
+ void CacheImpl::Put(InputOperation& inOp, IgniteError* err)
+ {
+ OutOpInternal(OP_PUT, inOp, err);
+ }
+
+ void CacheImpl::PutAll(ignite::impl::InputOperation& inOp, IgniteError* err)
+ {
+ OutOpInternal(OP_PUT_ALL, inOp, err);
+ }
+
+ void CacheImpl::GetAndPut(InputOperation& inOp, OutputOperation& outOp, IgniteError* err)
+ {
+ OutInOpInternal(OP_GET_AND_PUT, inOp, outOp, err);
+ }
+
+ void CacheImpl::GetAndReplace(InputOperation& inOp, OutputOperation& outOp, IgniteError* err)
+ {
+ OutInOpInternal(OP_GET_AND_REPLACE, inOp, outOp, err);
+ }
+
+ void CacheImpl::GetAndRemove(InputOperation& inOp, OutputOperation& outOp, IgniteError* err)
+ {
+ OutInOpInternal(OP_GET_AND_REMOVE, inOp, outOp, err);
+ }
+
+ bool CacheImpl::PutIfAbsent(InputOperation& inOp, IgniteError* err)
+ {
+ return OutOpInternal(OP_PUT_IF_ABSENT, inOp, err);
+ }
+
+ void CacheImpl::GetAndPutIfAbsent(InputOperation& inOp, OutputOperation& outOp, IgniteError* err)
+ {
+ OutInOpInternal(OP_GET_AND_PUT_IF_ABSENT, inOp, outOp, err);
+ }
+
+ bool CacheImpl::Replace(InputOperation& inOp, IgniteError* err)
+ {
+ return OutOpInternal(OP_REPLACE_2, inOp, err);
+ }
+
+ bool CacheImpl::ReplaceIfEqual(InputOperation& inOp, IgniteError* err)
+ {
+ return OutOpInternal(OP_REPLACE_3, inOp, err);
+ }
+
+ void CacheImpl::LocalEvict(InputOperation& inOp, IgniteError* err)
+ {
+ OutOpInternal(OP_LOCAL_EVICT, inOp, err);
+ }
+
+ void CacheImpl::Clear(IgniteError* err)
+ {
+ JniErrorInfo jniErr;
+
+ env.Get()->Context()->CacheClear(javaRef, &jniErr);
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+ }
+
+ void CacheImpl::Clear(InputOperation& inOp, IgniteError* err)
+ {
+ OutOpInternal(OP_CLEAR, inOp, err);
+ }
+
+ void CacheImpl::ClearAll(InputOperation& inOp, IgniteError* err)
+ {
+ OutOpInternal(OP_CLEAR_ALL, inOp, err);
+ }
+
+ void CacheImpl::LocalClear(InputOperation& inOp, IgniteError* err)
+ {
+ OutOpInternal(OP_LOCAL_CLEAR, inOp, err);
+ }
+
+ void CacheImpl::LocalClearAll(InputOperation& inOp, IgniteError* err)
+ {
+ OutOpInternal(OP_LOCAL_CLEAR_ALL, inOp, err);
+ }
+
+ bool CacheImpl::Remove(InputOperation& inOp, IgniteError* err)
+ {
+ return OutOpInternal(OP_REMOVE_1, inOp, err);
+ }
+
+ bool CacheImpl::RemoveIfEqual(InputOperation& inOp, IgniteError* err)
+ {
+ return OutOpInternal(OP_REMOVE_2, inOp, err);
+ }
+
+ void CacheImpl::RemoveAll(InputOperation& inOp, IgniteError* err)
+ {
+ OutOpInternal(OP_REMOVE_ALL, inOp, err);
+ }
+
+ void CacheImpl::RemoveAll(IgniteError* err)
+ {
+ JniErrorInfo jniErr;
+
+ env.Get()->Context()->CacheRemoveAll(javaRef, &jniErr);
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+ }
+
+ int32_t CacheImpl::Size(const int32_t peekModes, IgniteError* err)
+ {
+ return SizeInternal(peekModes, false, err);
+ }
+
+ int32_t CacheImpl::LocalSize(const int32_t peekModes, IgniteError* err)
+ {
+ return SizeInternal(peekModes, true, err);
+ }
+
+ QueryCursorImpl* CacheImpl::QuerySql(const SqlQuery& qry, IgniteError* err)
+ {
+ return QueryInternal(qry, OP_QRY_SQL, err);
+ }
+
+ QueryCursorImpl* CacheImpl::QueryText(const TextQuery& qry, IgniteError* err)
+ {
+ return QueryInternal(qry, OP_QRY_TEXT, err);
+ }
+
+ QueryCursorImpl* CacheImpl::QueryScan(const ScanQuery& qry, IgniteError* err)
+ {
+ return QueryInternal(qry, OP_QRY_SCAN, err);
+ }
+
+ int64_t CacheImpl::WriteTo(InteropMemory* mem, InputOperation& inOp, IgniteError* err)
+ {
+ PortableMetadataManager* metaMgr = env.Get()->GetMetadataManager();
+
+ int32_t metaVer = metaMgr->GetVersion();
+
+ InteropOutputStream out(mem);
+ PortableWriterImpl writer(&out, metaMgr);
+
+ inOp.ProcessInput(writer);
+
+ out.Synchronize();
+
+ if (metaMgr->IsUpdatedSince(metaVer))
+ {
+ PortableMetadataUpdaterImpl metaUpdater(env, javaRef);
+
+ if (!metaMgr->ProcessPendingUpdates(&metaUpdater, err))
+ return 0;
+ }
+
+ return mem->PointerLong();
+ }
+
+ void CacheImpl::ReadFrom(InteropMemory* mem, OutputOperation& outOp)
+ {
+ InteropInputStream in(mem);
+
+ PortableReaderImpl reader(&in);
+
+ outOp.ProcessOutput(reader);
+ }
+
+ int CacheImpl::SizeInternal(const int32_t peekModes, const bool loc, IgniteError* err)
+ {
+ JniErrorInfo jniErr;
+
+ int res = env.Get()->Context()->CacheSize(javaRef, peekModes, loc, &jniErr);
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ if (jniErr.code == IGNITE_JNI_ERR_SUCCESS)
+ return res;
+ else
+ return -1;
+ }
+
+ bool CacheImpl::OutOpInternal(const int32_t opType, InputOperation& inOp, IgniteError* err)
+ {
+ JniErrorInfo jniErr;
+
+ SharedPointer<InteropMemory> mem = env.Get()->AllocateMemory();
+
+ int64_t outPtr = WriteTo(mem.Get(), inOp, err);
+
+ if (outPtr)
+ {
+ long long res = env.Get()->Context()->TargetInStreamOutLong(javaRef, opType, outPtr, &jniErr);
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ if (jniErr.code == IGNITE_JNI_ERR_SUCCESS)
+ return res == 1;
+ }
+
+ return false;
+ }
+
+ void CacheImpl::OutInOpInternal(const int32_t opType, InputOperation& inOp, OutputOperation& outOp,
+ IgniteError* err)
+ {
+ JniErrorInfo jniErr;
+
+ SharedPointer<InteropMemory> outMem = env.Get()->AllocateMemory();
+ SharedPointer<InteropMemory> inMem = env.Get()->AllocateMemory();
+
+ int64_t outPtr = WriteTo(outMem.Get(), inOp, err);
+
+ if (outPtr)
+ {
+ env.Get()->Context()->TargetInStreamOutStream(javaRef, opType, WriteTo(outMem.Get(), inOp, err),
+ inMem.Get()->PointerLong(), &jniErr);
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ if (jniErr.code == IGNITE_JNI_ERR_SUCCESS)
+ ReadFrom(inMem.Get(), outOp);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
[04/11] ignite git commit: IGNITE-1364: Squashed commit from initial
branch.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/portable/portable_reader.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/portable/portable_reader.h b/modules/platform/src/main/cpp/core/include/ignite/portable/portable_reader.h
new file mode 100644
index 0000000..5e4b7ad
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/portable/portable_reader.h
@@ -0,0 +1,355 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_PORTABLE_READER
+#define _IGNITE_PORTABLE_READER
+
+#include <stdint.h>
+#include <string>
+
+#include <ignite/common/common.h>
+
+#include "ignite/portable/portable_raw_reader.h"
+#include "ignite/guid.h"
+
+namespace ignite
+{
+ namespace portable
+ {
+ /**
+ * Portable reader.
+ */
+ class IGNITE_IMPORT_EXPORT PortableReader
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param impl Implementation.
+ */
+ PortableReader(ignite::impl::portable::PortableReaderImpl* impl);
+
+ /**
+ * Read 8-byte signed integer. Maps to "byte" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ int8_t ReadInt8(const char* fieldName);
+
+ /**
+ * Read array of 8-byte signed integers. Maps to "byte[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt8Array(const char* fieldName, int8_t* res, const int32_t len);
+
+ /**
+ * Read bool. Maps to "short" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ bool ReadBool(const char* fieldName);
+
+ /**
+ * Read array of bools. Maps to "bool[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadBoolArray(const char* fieldName, bool* res, const int32_t len);
+
+ /**
+ * Read 16-byte signed integer. Maps to "short" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ int16_t ReadInt16(const char* fieldName);
+
+ /**
+ * Read array of 16-byte signed integers. Maps to "short[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt16Array(const char* fieldName, int16_t* res, const int32_t len);
+
+ /**
+ * Read 16-byte unsigned integer. Maps to "char" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ uint16_t ReadUInt16(const char* fieldName);
+
+ /**
+ * Read array of 16-byte unsigned integers. Maps to "char[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadUInt16Array(const char* fieldName, uint16_t* res, const int32_t len);
+
+ /**
+ * Read 32-byte signed integer. Maps to "int" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ int32_t ReadInt32(const char* fieldName);
+
+ /**
+ * Read array of 32-byte signed integers. Maps to "int[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt32Array(const char* fieldName, int32_t* res, const int32_t len);
+
+ /**
+ * Read 64-byte signed integer. Maps to "long" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ int64_t ReadInt64(const char* fieldName);
+
+ /**
+ * Read array of 64-byte signed integers. Maps to "long[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt64Array(const char* fieldName, int64_t* res, const int32_t len);
+
+ /**
+ * Read float. Maps to "float" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ float ReadFloat(const char* fieldName);
+
+ /**
+ * Read array of floats. Maps to "float[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadFloatArray(const char* fieldName, float* res, const int32_t len);
+
+ /**
+ * Read double. Maps to "double" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ double ReadDouble(const char* fieldName);
+
+ /**
+ * Read array of doubles. Maps to "double[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadDoubleArray(const char* fieldName, double* res, const int32_t len);
+
+ /**
+ * Read Guid. Maps to "UUID" type in Java.
+ *
+ * @param fieldName Field name.
+ * @return Result.
+ */
+ Guid ReadGuid(const char* fieldName);
+
+ /**
+ * Read array of Guids. Maps to "UUID[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadGuidArray(const char* fieldName, Guid* res, const int32_t len);
+
+ /**
+ * Read string.
+ *
+ * @param fieldName Field name.
+ * @param res Array to store data to.
+ * @param len Expected length of string. NULL terminator will be set in case len is
+ * greater than real string length.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadString(const char* fieldName, char* res, const int32_t len);
+
+ /**
+ * Read string from the stream.
+ *
+ * @param fieldName Field name.
+ * @return String.
+ */
+ std::string ReadString(const char* fieldName)
+ {
+ int32_t len = ReadString(fieldName, NULL, 0);
+
+ if (len != -1)
+ {
+ ignite::impl::utils::SafeArray<char> arr(len + 1);
+
+ ReadString(fieldName, arr.target, len + 1);
+
+ return std::string(arr.target);
+ }
+ else
+ return std::string();
+ }
+
+ /**
+ * Start string array read.
+ *
+ * @param fieldName Field name.
+ * @return String array reader.
+ */
+ PortableStringArrayReader ReadStringArray(const char* fieldName);
+
+ /**
+ * Start array read.
+ *
+ * @param fieldName Field name.
+ * @return Array reader.
+ */
+ template<typename T>
+ PortableArrayReader<T> ReadArray(const char* fieldName)
+ {
+ int32_t size;
+
+ int32_t id = impl->ReadArray(fieldName, &size);
+
+ return PortableArrayReader<T>(impl, id, size);
+ }
+
+ /**
+ * Start collection read.
+ *
+ * @param fieldName Field name.
+ * @return Collection reader.
+ */
+ template<typename T>
+ PortableCollectionReader<T> ReadCollection(const char* fieldName)
+ {
+ CollectionType typ;
+ int32_t size;
+
+ int32_t id = impl->ReadCollection(fieldName, &typ, &size);
+
+ return PortableCollectionReader<T>(impl, id, typ, size);
+ }
+
+ /**
+ * Start map read.
+ *
+ * @param fieldName Field name.
+ * @return Map reader.
+ */
+ template<typename K, typename V>
+ PortableMapReader<K, V> ReadMap(const char* fieldName)
+ {
+ MapType typ;
+ int32_t size;
+
+ int32_t id = impl->ReadMap(fieldName, &typ, &size);
+
+ return PortableMapReader<K, V>(impl, id, typ, size);
+ }
+
+ /**
+ * Read object.
+ *
+ * @param fieldName Field name.
+ * @return Object.
+ */
+ template<typename T>
+ T ReadObject(const char* fieldName)
+ {
+ return impl->ReadObject<T>(fieldName);
+ }
+
+ /**
+ * Get raw reader for this reader.
+ *
+ * @return Raw reader.
+ */
+ PortableRawReader RawReader();
+ private:
+ /** Implementation delegate. */
+ ignite::impl::portable::PortableReaderImpl* impl;
+ };
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/portable/portable_type.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/portable/portable_type.h b/modules/platform/src/main/cpp/core/include/ignite/portable/portable_type.h
new file mode 100644
index 0000000..fb086ef
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/portable/portable_type.h
@@ -0,0 +1,293 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_PORTABLE_TYPE
+#define _IGNITE_PORTABLE_TYPE
+
+#include <stdint.h>
+
+#include <ignite/common/common.h>
+
+#include "ignite/ignite_error.h"
+
+/**
+ * Start portable type definition.
+ */
+#define IGNITE_PORTABLE_TYPE_START(T) \
+template<> \
+struct PortableType<T> \
+{
+
+/**
+ * End portable type definition.
+ */
+#define IGNITE_PORTABLE_TYPE_END \
+};
+
+/**
+ * Implementation of GetTypeId() which returns predefined constant.
+ */
+#define IGNITE_PORTABLE_GET_TYPE_ID_AS_CONST(id) \
+int32_t GetTypeId() \
+{ \
+ return id; \
+}
+
+/**
+ * Implementation of GetTypeId() which returns hash of passed type name.
+ */
+#define IGNITE_PORTABLE_GET_TYPE_ID_AS_HASH(typeName) \
+int32_t GetTypeId() \
+{ \
+ return GetPortableStringHashCode(#typeName); \
+}
+
+/**
+ * Implementation of GetTypeName() which returns type name as is.
+ */
+#define IGNITE_PORTABLE_GET_TYPE_NAME_AS_IS(typeName) \
+std::string GetTypeName() \
+{ \
+ return #typeName; \
+}
+
+/**
+ * Default implementation of GetFieldId() function which returns Java-way hash code of the string.
+ */
+#define IGNITE_PORTABLE_GET_FIELD_ID_AS_HASH \
+int32_t GetFieldId(const char* name) \
+{ \
+ return GetPortableStringHashCode(name); \
+}
+
+/**
+ * Implementation of GetHashCode() function which always returns 0.
+ */
+#define IGNITE_PORTABLE_GET_HASH_CODE_ZERO(T) \
+int32_t GetHashCode(const T& obj) \
+{ \
+ return 0; \
+}
+
+/**
+ * Implementation of IsNull() function which always returns false.
+ */
+#define IGNITE_PORTABLE_IS_NULL_FALSE(T) \
+bool IsNull(const T& obj) \
+{ \
+ return false; \
+}
+
+/**
+ * Implementation of IsNull() function which return true if passed object is null pointer.
+ */
+#define IGNITE_PORTABLE_IS_NULL_IF_NULLPTR(T) \
+bool IsNull(const T& obj) \
+{ \
+ return obj; \
+}
+
+/**
+ * Implementation of GetNull() function which returns an instance created with defult constructor.
+ */
+#define IGNITE_PORTABLE_GET_NULL_DEFAULT_CTOR(T) \
+T GetNull() \
+{ \
+ return T(); \
+}
+
+/**
+ * Implementation of GetNull() function which returns NULL pointer.
+ */
+#define IGNITE_PORTABLE_GET_NULL_NULLPTR(T) \
+T GetNull() \
+{ \
+ return NULL; \
+}
+
+namespace ignite
+{
+ namespace portable
+ {
+ class PortableWriter;
+ class PortableReader;
+
+ /**
+ * Get portable string hash code.
+ *
+ * @param val Value.
+ * @return Hash code.
+ */
+ IGNITE_IMPORT_EXPORT int32_t GetPortableStringHashCode(const char* val);
+
+ /**
+ * Portable type structure. Defines a set of functions required for type to be serialized and deserialized.
+ */
+ template<typename T>
+ struct IGNITE_IMPORT_EXPORT PortableType
+ {
+ /**
+ * Get portable object type ID.
+ *
+ * @return Type ID.
+ */
+ int32_t GetTypeId()
+ {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "GetTypeId function is not defined for portable type.");
+ }
+
+ /**
+ * Get portable object type name.
+ *
+ * @return Type name.
+ */
+ std::string GetTypeName()
+ {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "GetTypeName function is not defined for portable type.");
+ }
+
+ /**
+ * Get portable object field ID.
+ *
+ * @param name Field name.
+ * @return Field ID.
+ */
+ int32_t GetFieldId(const char* name)
+ {
+ return GetPortableStringHashCode(name);
+ }
+
+ /**
+ * Get portable object hash code.
+ *
+ * @param obj Portable object.
+ * @return Hash code.
+ */
+ int32_t GetHashCode(const T& obj)
+ {
+ return 0;
+ }
+
+ /**
+ * Write portable object.
+ *
+ * @param writer Writer.
+ * @param obj Object.
+ */
+ void Write(PortableWriter& writer, const T& obj)
+ {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Write function is not defined for portable type.");
+ }
+
+ /**
+ * Read portable object.
+ *
+ * @param reader Reader.
+ * @return Object.
+ */
+ T Read(PortableReader& reader)
+ {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Read function is not defined for portable type.");
+ }
+
+ /**
+ * Check whether passed portable object should be interpreted as NULL.
+ *
+ * @param obj Portable object to test.
+ * @return True if portable object should be interpreted as NULL.
+ */
+ bool IsNull(const T& obj)
+ {
+ return false;
+ }
+
+ /**
+ * Get NULL value for the given portable type.
+ *
+ * @return NULL value.
+ */
+ T GetNull()
+ {
+ IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "GetNull function is not defined for portable type.");
+ }
+ };
+
+ /*
+ * Templated portable type for pointers.
+ */
+ template <typename T>
+ struct IGNITE_IMPORT_EXPORT PortableType<T*>
+ {
+ /** Actual type. */
+ PortableType<T> typ;
+
+ /**
+ * Constructor.
+ */
+ PortableType()
+ {
+ typ = PortableType<T>();
+ }
+
+ int32_t GetTypeId()
+ {
+ return typ.GetTypeId();
+ }
+
+ std::string GetTypeName()
+ {
+ return typ.GetTypeName();
+ }
+
+ int32_t GetFieldId(const char* name)
+ {
+ return typ.GetFieldId(name);
+ }
+
+ int32_t GetHashCode(T* const& obj)
+ {
+ return typ.GetHashCode(*obj);
+ }
+
+ void Write(PortableWriter& writer, T* const& obj)
+ {
+ typ.Write(writer, *obj);
+ }
+
+ T* Read(PortableReader& reader)
+ {
+ T* res = new T();
+
+ *res = typ.Read(reader);
+
+ return res;
+ }
+
+ bool IsNull(T* const& obj)
+ {
+ return !obj || typ.IsNull(*obj);
+ }
+
+ T* GetNull()
+ {
+ return NULL;
+ }
+ };
+ }
+}
+
+#endif
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/portable/portable_writer.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/portable/portable_writer.h b/modules/platform/src/main/cpp/core/include/ignite/portable/portable_writer.h
new file mode 100644
index 0000000..5dc9494
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/portable/portable_writer.h
@@ -0,0 +1,335 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_PORTABLE_WRITER
+#define _IGNITE_PORTABLE_WRITER
+
+#include <string>
+#include <stdint.h>
+
+#include <ignite/common/common.h>
+
+#include "ignite/portable/portable_raw_writer.h"
+
+namespace ignite
+{
+ namespace portable
+ {
+ /**
+ * Portable writer.
+ */
+ class IGNITE_IMPORT_EXPORT PortableWriter
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param impl Implementation.
+ */
+ PortableWriter(ignite::impl::portable::PortableWriterImpl* impl);
+
+ /**
+ * Write 8-byte signed integer. Maps to "byte" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteInt8(const char* fieldName, const int8_t val);
+
+ /**
+ * Write array of 8-byte signed integers. Maps to "byte[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt8Array(const char* fieldName, const int8_t* val, const int32_t len);
+
+ /**
+ * Write bool. Maps to "short" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteBool(const char* fieldName, const bool val);
+
+ /**
+ * Write array of bools. Maps to "bool[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteBoolArray(const char* fieldName, const bool* val, const int32_t len);
+
+ /**
+ * Write 16-byte signed integer. Maps to "short" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteInt16(const char* fieldName, const int16_t val);
+
+ /**
+ * Write array of 16-byte signed integers. Maps to "short[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt16Array(const char* fieldName, const int16_t* val, const int32_t len);
+
+ /**
+ * Write 16-byte unsigned integer. Maps to "char" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteUInt16(const char* fieldName, const uint16_t val);
+
+ /**
+ * Write array of 16-byte unsigned integers. Maps to "char[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteUInt16Array(const char* fieldName, const uint16_t* val, const int32_t len);
+
+ /**
+ * Write 32-byte signed integer. Maps to "int" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteInt32(const char* fieldName, const int32_t val);
+
+ /**
+ * Write array of 32-byte signed integers. Maps to "int[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt32Array(const char* fieldName, const int32_t* val, const int32_t len);
+
+ /**
+ * Write 64-byte signed integer. Maps to "long" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteInt64(const char* fieldName, const int64_t val);
+
+ /**
+ * Write array of 64-byte signed integers. Maps to "long[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt64Array(const char* fieldName, const int64_t* val, const int32_t len);
+
+ /**
+ * Write float. Maps to "float" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteFloat(const char* fieldName, const float val);
+
+ /**
+ * Write array of floats. Maps to "float[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteFloatArray(const char* fieldName, const float* val, const int32_t len);
+
+ /**
+ * Write double. Maps to "double" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteDouble(const char* fieldName, const double val);
+
+ /**
+ * Write array of doubles. Maps to "double[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteDoubleArray(const char* fieldName, const double* val, const int32_t len);
+
+ /**
+ * Write Guid. Maps to "UUID" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteGuid(const char* fieldName, const Guid val);
+
+ /**
+ * Write array of Guids. Maps to "UUID[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteGuidArray(const char* fieldName, const Guid* val, const int32_t len);
+
+ /**
+ * Write string.
+ *
+ * @param fieldName Field name.
+ * @param val Null-terminated character sequence.
+ */
+ void WriteString(const char* fieldName, const char* val);
+
+ /**
+ * Write string.
+ *
+ * @param fieldName Field name.
+ * @param val String.
+ * @param len String length (characters).
+ */
+ void WriteString(const char* fieldName, const char* val, const int32_t len);
+
+ /**
+ * Write string.
+ *
+ * @param fieldName Field name.
+ * @param val String.
+ */
+ void WriteString(const char* fieldName, const std::string& val)
+ {
+ WriteString(fieldName, val.c_str());
+ }
+
+ /**
+ * Start string array write.
+ *
+ * @param fieldName Field name.
+ * @return String array writer.
+ */
+ PortableStringArrayWriter WriteStringArray(const char* fieldName);
+
+ /**
+ * Write NULL value.
+ *
+ * @param fieldName Field name.
+ */
+ void WriteNull(const char* fieldName);
+
+ /**
+ * Start array write.
+ *
+ * @param fieldName Field name.
+ * @return Array writer.
+ */
+ template<typename T>
+ PortableArrayWriter<T> WriteArray(const char* fieldName)
+ {
+ int32_t id = impl->WriteArray(fieldName);
+
+ return PortableArrayWriter<T>(impl, id);
+ }
+
+ /**
+ * Start collection write.
+ *
+ * @param fieldName Field name.
+ * @return Collection writer.
+ */
+ template<typename T>
+ PortableCollectionWriter<T> WriteCollection(const char* fieldName)
+ {
+ return WriteCollection<T>(fieldName, IGNITE_COLLECTION_UNDEFINED);
+ }
+
+ /**
+ * Start collection write.
+ *
+ * @param fieldName Field name.
+ * @param type Collection type.
+ * @return Collection writer.
+ */
+ template<typename T>
+ PortableCollectionWriter<T> WriteCollection(const char* fieldName, ignite::portable::CollectionType typ)
+ {
+ int32_t id = impl->WriteCollection(fieldName, typ);
+
+ return PortableCollectionWriter<T>(impl, id);
+ }
+
+ /**
+ * Start map write.
+ *
+ * @param fieldName Field name.
+ * @param typ Map type.
+ * @return Map writer.
+ */
+ template<typename K, typename V>
+ PortableMapWriter<K, V> WriteMap(const char* fieldName)
+ {
+ return WriteMap<K, V>(fieldName, IGNITE_MAP_UNDEFINED);
+ }
+
+ /**
+ * Start map write.
+ *
+ * @param fieldName Field name.
+ * @param typ Map type.
+ * @return Map writer.
+ */
+ template<typename K, typename V>
+ PortableMapWriter<K, V> WriteMap(const char* fieldName, ignite::portable::MapType typ)
+ {
+ int32_t id = impl->WriteMap(fieldName, typ);
+
+ return PortableMapWriter<K, V>(impl, id);
+ }
+
+ /**
+ * Write object.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ template<typename T>
+ void WriteObject(const char* fieldName, T val)
+ {
+ impl->WriteObject<T>(fieldName, val);
+ }
+
+ /**
+ * Get raw writer for this reader.
+ *
+ * @return Raw writer.
+ */
+ PortableRawWriter RawWriter();
+ private:
+ /** Implementation delegate. */
+ ignite::impl::portable::PortableWriterImpl* impl;
+ };
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/os/linux/include/Makefile.am
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/os/linux/include/Makefile.am b/modules/platform/src/main/cpp/core/os/linux/include/Makefile.am
new file mode 100644
index 0000000..2ee13eff
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/os/linux/include/Makefile.am
@@ -0,0 +1,20 @@
+##
+## 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.
+##
+
+ACLOCAL_AMFLAGS = "-Im4"
+
+nobase_include_HEADERS = ignite/impl/utils.h
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/os/linux/include/ignite/impl/utils.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/os/linux/include/ignite/impl/utils.h b/modules/platform/src/main/cpp/core/os/linux/include/ignite/impl/utils.h
new file mode 100644
index 0000000..8bbd2f7
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/os/linux/include/ignite/impl/utils.h
@@ -0,0 +1,155 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_UTILS
+#define _IGNITE_UTILS
+
+#include <cstring>
+#include <string>
+
+#include <ignite/common/common.h>
+
+#ifdef IGNITE_FRIEND
+ #define IGNITE_FRIEND_EXPORT IGNITE_EXPORT
+#else
+ #define IGNITE_FRIEND_EXPORT
+#endif
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace utils
+ {
+ /**
+ * Copy characters.
+ *
+ * @param val Value.
+ * @return Result.
+ */
+ IGNITE_FRIEND_EXPORT char* CopyChars(const char* val);
+
+ /**
+ * Release characters.
+ *
+ * @param val Value.
+ */
+ IGNITE_FRIEND_EXPORT void ReleaseChars(char* val);
+
+ /**
+ * Read system environment variable taking thread-safety in count.
+ *
+ * @param name Environment variable name.
+ * @param found Whether environment variable with such name was found.
+ * @return Environment variable value.
+ */
+ IGNITE_FRIEND_EXPORT std::string GetEnv(const std::string& name, bool* found);
+
+ /**
+ * Ensure that file on the given path exists in the system.
+ *
+ * @param path Path.
+ * @return True if file exists, false otherwise.
+ */
+ IGNITE_FRIEND_EXPORT bool FileExists(const std::string& path);
+
+ /**
+ * Attempts to find JVM library to load it into the process later.
+ * First search is performed using the passed path argument (is not NULL).
+ * Then JRE_HOME is evaluated. Last, JAVA_HOME is evaluated.
+ *
+ * @param Explicitly defined path (optional).
+ * @param found Whether library was found.
+ * @return Path to the file.
+ */
+ IGNITE_FRIEND_EXPORT std::string FindJvmLibrary(const std::string* path, bool* found);
+
+ /**
+ * Load JVM library into the process.
+ *
+ * @param path Optional path to the library.
+ * @return Whether load was successful.
+ */
+ IGNITE_FRIEND_EXPORT bool LoadJvmLibrary(const std::string& path);
+
+ /**
+ * Resolve IGNITE_HOME directory. Resolution is performed in several
+ * steps:
+ * 1) Check for path provided as argument.
+ * 2) Check for environment variable.
+ * 3) Check for current working directory.
+ * Result of these 3 checks are evaluated based on existence of certain
+ * predefined folders inside possible GG home. If they are found,
+ * IGNITE_HOME is considered resolved.
+ *
+ * @param path Optional path to evaluate.
+ * @param found Whether IGNITE_HOME home was found.
+ * @return Resolved GG home.
+ */
+ IGNITE_FRIEND_EXPORT std::string ResolveIgniteHome(const std::string* path, bool* found);
+
+ /**
+ * Create Ignite classpath based on user input and home directory.
+ *
+ * @param usrCp User's classpath.
+ * @param home Ignite home directory.
+ * @return Classpath.
+ */
+ IGNITE_FRIEND_EXPORT std::string CreateIgniteClasspath(const std::string* usrCp, const std::string* home);
+
+ /**
+ * Create Ignite classpath based on user input and home directory.
+ *
+ * @param usrCp User's classpath.
+ * @param home Ignite home directory.
+ * @param test Whether test classpath must be used.
+ * @return Classpath.
+ */
+ IGNITE_FRIEND_EXPORT std::string CreateIgniteClasspath(const std::string* usrCp, const std::string* home, bool test);
+
+ /**
+ * Safe array which automatically reclaims occupied memory when out of scope.
+ */
+ template<typename T>
+ struct IGNITE_FRIEND_EXPORT SafeArray
+ {
+ /**
+ * Constructor.
+ */
+ SafeArray(int cap)
+ {
+ target = new T[cap];
+ }
+
+ /**
+ * Destructor.
+ */
+ ~SafeArray()
+ {
+ delete[] target;
+ }
+
+ IGNITE_NO_COPY_ASSIGNMENT(SafeArray);
+
+ /** Target array. */
+ T* target;
+ };
+ }
+ }
+}
+
+#endif
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/os/linux/src/impl/utils.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/os/linux/src/impl/utils.cpp b/modules/platform/src/main/cpp/core/os/linux/src/impl/utils.cpp
new file mode 100644
index 0000000..ec45eb6
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/os/linux/src/impl/utils.cpp
@@ -0,0 +1,439 @@
+/*
+ * 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 <sys/stat.h>
+#include <dirent.h>
+#include <dlfcn.h>
+
+#include "ignite/impl/utils.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace utils
+ {
+ const char* JAVA_HOME = "JAVA_HOME";
+ const char* JAVA_DLL = "/jre/lib/amd64/server/libjvm.so";
+
+ const char* IGNITE_HOME = "IGNITE_HOME";
+
+ const char* PROBE_BIN = "/bin";
+ const char* PROBE_EXAMPLES = "/examples";
+
+ const char* IGNITE_NATIVE_TEST_CLASSPATH = "IGNITE_NATIVE_TEST_CLASSPATH";
+
+ /**
+ * Helper method to set boolean result to reference with proper NULL-check.
+ *
+ * @param res Result.
+ * @param outRes Where to set the result.
+ */
+ inline void SetBoolResult(bool res, bool* outRes)
+ {
+ if (outRes)
+ *outRes = res;
+ }
+
+ /**
+ * Check if string ends with the given ending.
+ *
+ * @param str String to check.
+ * @param ending Ending.
+ * @return Result.
+ */
+ inline bool StringEndsWith(const std::string& str, const std::string& ending)
+ {
+ if (str.length() > ending.length())
+ return str.compare(str.length() - ending.length(), ending.length(), ending) == 0;
+
+ return false;
+ }
+
+ /**
+ * Helper function for GG home resolution. Checks whether certain folders
+ * exist in the path. Optionally goes upwards in directory hierarchy.
+ *
+ * @param path Path to evaluate.
+ * @param up Whether to go upwards.
+ * @res Resolution result.
+ * @return Resolved directory.
+ */
+ std::string ResolveIgniteHome0(const std::string& path, bool up, bool* res)
+ {
+ struct stat pathStat;
+
+ if (stat(path.c_str(), &pathStat) != -1 && S_ISDIR(pathStat.st_mode))
+ {
+ // Remove trailing slashes, otherwise we will have an infinite loop.
+ std::string path0 = path;
+
+ while (true) {
+ char lastChar = *path0.rbegin();
+
+ if (lastChar == '/' || lastChar == ' ') {
+ size_t off = path0.find_last_of(lastChar);
+
+ path0.erase(off, 1);
+ }
+ else
+ break;
+ }
+
+ std::string binStr = path0 + PROBE_BIN;
+ struct stat binStat;
+
+ std::string examplesStr = path0 + PROBE_EXAMPLES;
+ struct stat examplesStat;
+
+ if (stat(binStr.c_str(), &binStat) != -1 && S_ISDIR(binStat.st_mode) &&
+ stat(examplesStr.c_str(), &examplesStat) != -1 && S_ISDIR(examplesStat.st_mode))
+ {
+ SetBoolResult(true, res);
+
+ return std::string(path0);
+ }
+
+ if (up)
+ {
+ // Evaluate parent directory.
+ size_t slashPos = path0.find_last_of("/");
+
+ if (slashPos != std::string::npos)
+ {
+ std::string parent = path0.substr(0, slashPos);
+
+ return ResolveIgniteHome0(parent, true, res);
+ }
+ }
+
+ }
+
+ SetBoolResult(false, res);
+
+ return std::string();
+ }
+
+ /**
+ * Create classpath picking JARs from the given path.
+ *
+ * @path Path.
+ * @return Classpath;
+ */
+ std::string ClasspathJars(const std::string& path)
+ {
+ std::string res = std::string();
+
+ DIR* dir = opendir(path.c_str());
+
+ if (dir)
+ {
+ struct dirent* entry;
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ if (strstr(entry->d_name, ".jar"))
+ {
+ res.append(path);
+ res.append("/");
+ res.append(entry->d_name);
+ res.append(":");
+ }
+ }
+
+ closedir(dir);
+ }
+
+ return res;
+ }
+
+ /**
+ * Create classpath picking compiled classes from the given path.
+ *
+ * @path Path.
+ * @return Classpath;
+ */
+ std::string ClasspathExploded(const std::string& path, bool down)
+ {
+ std::string res = std::string();
+
+ if (FileExists(path))
+ {
+ // 1. Append "target\classes".
+ std::string classesPath = path + "/target/classes";
+
+ if (FileExists(classesPath)) {
+ res += classesPath;
+ res += ":";
+ }
+
+ // 2. Append "target\test-classes"
+ std::string testClassesPath = path + "/target/test-classes";
+
+ if (FileExists(testClassesPath)) {
+ res += testClassesPath;
+ res += ":";
+ }
+
+ // 3. Append "target\libs"
+ std::string libsPath = path + "/target/libs";
+
+ if (FileExists(libsPath)) {
+ std::string libsCp = ClasspathJars(libsPath);
+ res += libsCp;
+ }
+
+ // 4. Do the same for child if needed.
+ if (down)
+ {
+ DIR* dir = opendir(path.c_str());
+
+ if (dir)
+ {
+ struct dirent* entry;
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ std::string entryPath = entry->d_name;
+
+ if (entryPath.compare(".") != 0 && entryPath.compare("..") != 0)
+ {
+ std::string entryFullPath = path + "/" + entryPath;
+
+ struct stat entryFullStat;
+
+ if (stat(entryFullPath.c_str(), &entryFullStat) != -1 && S_ISDIR(entryFullStat.st_mode))
+ {
+ std::string childCp = ClasspathExploded(entryFullPath, false);
+
+ res += childCp;
+ }
+ }
+ }
+
+ closedir(dir);
+ }
+ }
+ }
+
+ return res;
+ }
+
+ /**
+ * Helper function to create classpath based on Ignite home directory.
+ *
+ * @param home Home directory; expected to be valid.
+ * @param forceTest Force test classpath.
+ */
+ std::string CreateIgniteHomeClasspath(const std::string& home, bool forceTest)
+ {
+ std::string res = std::string();
+
+ // 1. Add exploded test directories.
+ if (forceTest)
+ {
+ std::string examplesPath = home + "/examples";
+ std::string examplesCp = ClasspathExploded(examplesPath, true);
+ res.append(examplesCp);
+
+ std::string modulesPath = home + "/modules";
+ std::string modulesCp = ClasspathExploded(modulesPath, true);
+ res.append(modulesCp);
+ }
+
+ // 2. Add regular jars from "libs" folder excluding "optional".
+ std::string libsPath = home + "/libs";
+
+ if (FileExists(libsPath))
+ {
+ res.append(ClasspathJars(libsPath));
+
+ // Append inner directories.
+ DIR* dir = opendir(libsPath.c_str());
+
+ if (dir)
+ {
+ struct dirent* entry;
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ std::string entryPath = entry->d_name;
+
+ if (entryPath.compare(".") != 0 && entryPath.compare("..") != 0 &&
+ entryPath.compare("optional") != 0)
+ {
+ std::string entryFullPath = libsPath;
+
+ entryFullPath.append("/");
+ entryFullPath.append(entryPath);
+
+ struct stat entryFullStat;
+
+ if (stat(entryFullPath.c_str(), &entryFullStat) != -1 &&
+ S_ISDIR(entryFullStat.st_mode))
+ res.append(ClasspathJars(entryFullPath));
+ }
+ }
+
+ closedir(dir);
+ }
+ }
+
+ // 3. Return.
+ return res;
+ }
+
+ char* CopyChars(const char* val)
+ {
+ if (val) {
+ size_t len = strlen(val);
+ char* dest = new char[len + 1];
+ strcpy(dest, val);
+ *(dest + len) = 0;
+ return dest;
+ }
+ else
+ return NULL;
+ }
+
+ void ReleaseChars(char* val)
+ {
+ if (val)
+ delete[] val;
+ }
+
+ std::string GetEnv(const std::string& name, bool* found)
+ {
+ char* val = std::getenv(name.c_str());
+
+ if (val) {
+ SetBoolResult(true, found);
+
+ return std::string(val);
+ }
+ else {
+ SetBoolResult(false, found);
+
+ return std::string();
+ }
+ }
+
+ bool FileExists(const std::string& path)
+ {
+ struct stat s;
+
+ int res = stat(path.c_str(), &s);
+
+ return res != -1;
+ }
+
+ std::string FindJvmLibrary(const std::string* path, bool* found)
+ {
+ SetBoolResult(true, found); // Optimistically assume that we will find it.
+
+ if (path) {
+ // If path is provided explicitly, then check only it.
+ if (FileExists(*path))
+ return std::string(path->data());
+ }
+ else
+ {
+ bool javaEnvFound;
+ std::string javaEnv = GetEnv(JAVA_HOME, &javaEnvFound);
+
+ if (javaEnvFound)
+ {
+ std::string javaDll = javaEnv + JAVA_DLL;
+
+ if (FileExists(javaDll))
+ return std::string(javaDll);
+ }
+ }
+
+ SetBoolResult(false, found);
+
+ return std::string();
+ }
+
+ bool LoadJvmLibrary(const std::string& path)
+ {
+ void* hnd = dlopen(path.c_str(), RTLD_LAZY);
+
+ return hnd != NULL;
+ }
+
+ std::string ResolveIgniteHome(const std::string* path, bool* found)
+ {
+ if (path)
+ // 1. Check passed argument.
+ return ResolveIgniteHome0(*path, false, found);
+ else
+ {
+ // 2. Check environment variable.
+ bool envFound;
+ std::string env = GetEnv(IGNITE_HOME, &envFound);
+
+ if (envFound)
+ return ResolveIgniteHome0(env, false, found);
+ }
+
+ SetBoolResult(false, found);
+
+ return std::string();
+ }
+
+ std::string CreateIgniteClasspath(const std::string* usrCp, const std::string* home)
+ {
+ bool forceTest = false;
+
+ if (home)
+ {
+ bool envFound;
+ std::string env = GetEnv(IGNITE_NATIVE_TEST_CLASSPATH, &envFound);
+
+ forceTest = envFound && env.compare("true") == 0;
+ }
+
+ return CreateIgniteClasspath(usrCp, home, forceTest);
+ }
+
+ std::string CreateIgniteClasspath(const std::string* usrCp, const std::string* home, bool forceTest)
+ {
+ // 1. Append user classpath if it exists.
+ std::string cp = std::string();
+
+ if (usrCp)
+ {
+ cp.append(*usrCp);
+
+ if (*cp.rbegin() != ':')
+ cp.append(":");
+ }
+
+ // 2. Append home classpath if home is defined.
+ if (home)
+ {
+ std::string homeCp = CreateIgniteHomeClasspath(*home, forceTest);
+
+ cp.append(homeCp);
+ }
+
+ // 3. Return.
+ return cp;
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/os/win/include/ignite/impl/utils.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/os/win/include/ignite/impl/utils.h b/modules/platform/src/main/cpp/core/os/win/include/ignite/impl/utils.h
new file mode 100644
index 0000000..08e76ee
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/os/win/include/ignite/impl/utils.h
@@ -0,0 +1,155 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_UTILS
+#define _IGNITE_UTILS
+
+#include <cstring>
+#include <string>
+
+#include <ignite/common/common.h>
+
+#ifdef IGNITE_FRIEND
+ #define IGNITE_FRIEND_EXPORT IGNITE_EXPORT
+#else
+ #define IGNITE_FRIEND_EXPORT
+#endif
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace utils
+ {
+ /**
+ * Copy characters.
+ *
+ * @param val Value.
+ * @return Result.
+ */
+ IGNITE_FRIEND_EXPORT char* CopyChars(const char* val);
+
+ /**
+ * Release characters.
+ *
+ * @param val Value.
+ */
+ IGNITE_FRIEND_EXPORT void ReleaseChars(char* val);
+
+ /**
+ * Read system environment variable taking thread-safety in count.
+ *
+ * @param name Environment variable name.
+ * @param found Whether environment variable with such name was found.
+ * @return Environment variable value.
+ */
+ IGNITE_FRIEND_EXPORT std::string GetEnv(const std::string& name, bool* found);
+
+ /**
+ * Ensure that file on the given path exists in the system.
+ *
+ * @param path Path.
+ * @return True if file exists, false otherwise.
+ */
+ IGNITE_FRIEND_EXPORT bool FileExists(const std::string& path);
+
+ /**
+ * Attempts to find JVM library to load it into the process later.
+ * First search is performed using the passed path argument (is not NULL).
+ * Then JRE_HOME is evaluated. Last, JAVA_HOME is evaluated.
+ *
+ * @param Explicitly defined path (optional).
+ * @param found Whether library was found.
+ * @return Path to the file.
+ */
+ IGNITE_FRIEND_EXPORT std::string FindJvmLibrary(const std::string* path, bool* found);
+
+ /**
+ * Load JVM library into the process.
+ *
+ * @param path Optional path to the library.
+ * @return Whether load was successful.
+ */
+ IGNITE_FRIEND_EXPORT bool LoadJvmLibrary(const std::string& path);
+
+ /**
+ * Resolve IGNITE_HOME directory. Resolution is performed in several
+ * steps:
+ * 1) Check for path provided as argument.
+ * 2) Check for environment variable.
+ * 3) Check for current working directory.
+ * Result of these 3 checks are evaluated based on existence of certain
+ * predefined folders inside possible GG home. If they are found,
+ * IGNITE_HOME is considered resolved.
+ *
+ * @param path Optional path to evaluate.
+ * @param found Whether IGNITE_HOME home was found.
+ * @return Resolved GG home.
+ */
+ IGNITE_FRIEND_EXPORT std::string ResolveIgniteHome(const std::string* path, bool* found);
+
+ /**
+ * Create Ignite classpath based on user input and home directory.
+ *
+ * @param usrCp User's classpath.
+ * @param home Ignite home directory.
+ * @return Classpath.
+ */
+ IGNITE_FRIEND_EXPORT std::string CreateIgniteClasspath(const std::string* usrCp, const std::string* home);
+
+ /**
+ * Create Ignite classpath based on user input and home directory.
+ *
+ * @param usrCp User's classpath.
+ * @param home Ignite home directory.
+ * @param test Whether test classpath must be used.
+ * @return Classpath.
+ */
+ IGNITE_FRIEND_EXPORT std::string CreateIgniteClasspath(const std::string* usrCp, const std::string* home, bool test);
+
+ /**
+ * Safe array which automatically reclaims occupied memory when out of scope.
+ */
+ template<typename T>
+ struct IGNITE_FRIEND_EXPORT SafeArray
+ {
+ /** Target array. */
+ T* target;
+
+ /**
+ * Constructor.
+ */
+ SafeArray(int cap)
+ {
+ target = new T[cap];
+ }
+
+ /**
+ * Destructor.
+ */
+ ~SafeArray()
+ {
+ delete[] target;
+ }
+
+ IGNITE_NO_COPY_ASSIGNMENT(SafeArray);
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/os/win/src/impl/utils.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/os/win/src/impl/utils.cpp b/modules/platform/src/main/cpp/core/os/win/src/impl/utils.cpp
new file mode 100644
index 0000000..5a450c3
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/os/win/src/impl/utils.cpp
@@ -0,0 +1,453 @@
+/*
+ * 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 <windows.h>
+
+#include "ignite/impl/utils.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace utils
+ {
+ const char* JAVA_HOME = "JAVA_HOME";
+ const char* JAVA_DLL = "\\jre\\bin\\server\\jvm.dll";
+
+ const char* IGNITE_HOME = "IGNITE_HOME";
+
+ const char* PROBE_BIN = "\\bin";
+ const char* PROBE_EXAMPLES = "\\examples";
+
+ const char* IGNITE_NATIVE_TEST_CLASSPATH = "IGNITE_NATIVE_TEST_CLASSPATH";
+
+ /**
+ * Helper method to set boolean result to reference with proper NULL-check.
+ *
+ * @param res Result.
+ * @param outRes Where to set the result.
+ */
+ inline void SetBoolResult(bool res, bool* outRes)
+ {
+ if (outRes)
+ *outRes = res;
+ }
+
+ /**
+ * Check if string ends with the given ending.
+ *
+ * @param str String to check.
+ * @param ending Ending.
+ * @return Result.
+ */
+ inline bool StringEndsWith(const std::string& str, const std::string& ending)
+ {
+ if (str.length() > ending.length())
+ return str.compare(str.length() - ending.length(), ending.length(), ending) == 0;
+
+ return false;
+ }
+
+ /**
+ * Helper function for GG home resolution. Checks whether certain folders
+ * exist in the path. Optionally goes upwards in directory hierarchy.
+ *
+ * @param path Path to evaluate.
+ * @param up Whether to go upwards.
+ * @res Resolution result.
+ * @return Resolved directory.
+ */
+ std::string ResolveIgniteHome0(const std::string& path, bool up, bool* res)
+ {
+ DWORD attrs = GetFileAttributesA(path.c_str());
+
+ if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY))
+ {
+ // Remove trailing slashes, otherwise we will have an infinite loop.
+ std::string path0 = path;
+
+ while (true) {
+ char lastChar = *path0.rbegin();
+
+ if (lastChar == '/' || lastChar == '\\' || lastChar == ' ') {
+ size_t off = path0.find_last_of(lastChar);
+
+ path0.erase(off, 1);
+ }
+ else
+ break;
+ }
+
+ std::string binStr = path0 + PROBE_BIN;
+ DWORD binAttrs = GetFileAttributesA(binStr.c_str());
+
+ std::string examplesStr = path0 + PROBE_EXAMPLES;
+ DWORD examplesAttrs = GetFileAttributesA(examplesStr.c_str());
+
+ if (binAttrs != INVALID_FILE_ATTRIBUTES && (binAttrs & FILE_ATTRIBUTE_DIRECTORY) &&
+ examplesAttrs != INVALID_FILE_ATTRIBUTES && (examplesAttrs & FILE_ATTRIBUTE_DIRECTORY))
+ {
+ SetBoolResult(true, res);
+ return std::string(path0);
+ }
+
+ if (up)
+ {
+ // Evaluate parent directory.
+ size_t slashPos = path0.find_last_of("/\\");
+
+ if (slashPos != std::string::npos)
+ {
+ std::string parent = path0.substr(0, slashPos);
+
+ return ResolveIgniteHome0(parent, true, res);
+ }
+ }
+ }
+
+ SetBoolResult(false, res);
+
+ return std::string();
+ }
+
+ /**
+ * Create classpath picking JARs from the given path.
+ *
+ * @path Path.
+ * @return Classpath;
+ */
+ std::string ClasspathJars(const std::string& path)
+ {
+ std::string searchPath = path + "\\*.jar";
+
+ std::string res = std::string();
+
+ WIN32_FIND_DATAA findData;
+
+ HANDLE hnd = FindFirstFileA(searchPath.c_str(), &findData);
+
+ if (hnd != INVALID_HANDLE_VALUE)
+ {
+ do
+ {
+ res.append(path);
+ res.append("\\");
+ res.append(findData.cFileName);
+ res.append(";");
+ } while (FindNextFileA(hnd, &findData) != 0);
+
+ FindClose(hnd);
+ }
+
+ return res;
+ }
+
+ /**
+ * Create classpath picking compiled classes from the given path.
+ *
+ * @path Path.
+ * @return Classpath;
+ */
+ std::string ClasspathExploded(const std::string& path, bool down)
+ {
+ std::string res = std::string();
+
+ if (FileExists(path))
+ {
+ // 1. Append "target\classes".
+ std::string classesPath = path + "\\target\\classes";
+
+ if (FileExists(classesPath)) {
+ res.append(classesPath);
+ res.append(";");
+ }
+
+ // 2. Append "target\test-classes"
+ std::string testClassesPath = path + "\\target\\test-classes";
+
+ if (FileExists(testClassesPath)) {
+ res.append(testClassesPath);
+ res.append(";");
+ }
+
+ // 3. Append "target\libs"
+ std::string libsPath = path + "\\target\\libs";
+
+ if (FileExists(libsPath)) {
+ std::string libsCp = ClasspathJars(libsPath);
+ res.append(libsCp);
+ }
+
+ // 4. Do the same for child if needed.
+ if (down)
+ {
+ std::string searchPath = path + "\\*";
+
+ WIN32_FIND_DATAA findData;
+
+ HANDLE hnd = FindFirstFileA(searchPath.c_str(), &findData);
+
+ if (hnd != INVALID_HANDLE_VALUE)
+ {
+ do
+ {
+ if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ {
+ std::string childPath = findData.cFileName;
+
+ if (childPath.compare(".") != 0 &&
+ childPath.compare("..") != 0)
+ {
+ std::string childCp =
+ ClasspathExploded(path + "\\" + childPath, false);
+
+ res.append(childCp);
+ }
+ }
+ } while (FindNextFileA(hnd, &findData) != 0);
+
+ FindClose(hnd);
+ }
+ }
+ }
+
+ return res;
+ }
+
+ /**
+ * Helper function to create classpath based on Ignite home directory.
+ *
+ * @param home Home directory; expected to be valid.
+ * @param forceTest Force test classpath.
+ */
+ std::string CreateIgniteHomeClasspath(const std::string& home, bool forceTest)
+ {
+ std::string res = std::string();
+
+ // 1. Add exploded test directories.
+ if (forceTest)
+ {
+ std::string examplesPath = home + "\\examples";
+ std::string examplesCp = ClasspathExploded(examplesPath, true);
+ res.append(examplesCp);
+
+ std::string modulesPath = home + "\\modules";
+ std::string modulesCp = ClasspathExploded(modulesPath, true);
+ res.append(modulesCp);
+ }
+
+ // 2. Add regular jars from "libs" folder excluding "optional".
+ std::string libsPath = home + "\\libs";
+
+ if (FileExists(libsPath))
+ {
+ res.append(ClasspathJars(libsPath));
+
+ // Append inner directories.
+ std::string libsSearchPath = libsPath + "\\*";
+
+ WIN32_FIND_DATAA libsFindData;
+
+ HANDLE libsHnd = FindFirstFileA(libsSearchPath.c_str(), &libsFindData);
+
+ if (libsHnd != INVALID_HANDLE_VALUE)
+ {
+ do
+ {
+ if (libsFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ {
+ std::string libsChildPath = libsFindData.cFileName;
+
+ if (libsChildPath.compare(".") != 0 &&
+ libsChildPath.compare("..") != 0 &&
+ libsChildPath.compare("optional") != 0) {
+ std::string libsFolder = libsPath + "\\" + libsChildPath;
+
+ res.append(ClasspathJars(libsFolder));
+ }
+ }
+ } while (FindNextFileA(libsHnd, &libsFindData) != 0);
+
+ FindClose(libsHnd);
+ }
+ }
+
+ // 3. Return.
+ return res;
+ }
+
+ char* CopyChars(const char* val)
+ {
+ if (val) {
+ size_t len = strlen(val);
+ char* dest = new char[len + 1];
+ strcpy(dest, val);
+ *(dest + len) = 0;
+ return dest;
+ }
+ else
+ return NULL;
+ }
+
+ void ReleaseChars(char* val)
+ {
+ if (val)
+ delete[] val;
+ }
+
+ std::string GetEnv(const std::string& name, bool* found)
+ {
+ char res0[32767];
+
+ DWORD envRes = GetEnvironmentVariableA(name.c_str(), res0, 32767);
+
+ if (envRes != 0)
+ {
+ SetBoolResult(true, found);
+
+ return std::string(res0);
+ }
+ else
+ {
+ SetBoolResult(false, found);
+
+ return std::string();
+ }
+ }
+
+ bool FileExists(const std::string& path)
+ {
+ WIN32_FIND_DATAA findres;
+
+ HANDLE hnd = FindFirstFileA(path.c_str(), &findres);
+
+ if (hnd == INVALID_HANDLE_VALUE)
+ return false;
+ else
+ {
+ FindClose(hnd);
+
+ return true;
+ }
+ }
+
+ std::string FindJvmLibrary(const std::string* path, bool* found)
+ {
+ SetBoolResult(true, found); // Optimistically assume that we will find it.
+
+ if (path) {
+ // If path is provided explicitly, then check only it.
+ if (FileExists(*path))
+ return std::string(path->data());
+ }
+ else
+ {
+ bool javaEnvFound;
+ std::string javaEnv = GetEnv(JAVA_HOME, &javaEnvFound);
+
+ if (javaEnvFound)
+ {
+ std::string javaDll = javaEnv + JAVA_DLL;
+
+ if (FileExists(javaDll))
+ return std::string(javaDll);
+ }
+ }
+
+ *found = false;
+
+ return std::string();
+ }
+
+ bool LoadJvmLibrary(const std::string& path)
+ {
+ HMODULE mod = LoadLibraryA(path.c_str());
+
+ return mod != NULL;
+ }
+
+ std::string ResolveIgniteHome(const std::string* path, bool* found)
+ {
+ if (path)
+ // 1. Check passed argument.
+ return ResolveIgniteHome0(*path, false, found);
+ else
+ {
+ // 2. Check environment variable.
+ bool envFound;
+ std::string env = GetEnv(IGNITE_HOME, &envFound);
+
+ if (envFound)
+ return ResolveIgniteHome0(env, false, found);
+
+ // 3. Check current work dir.
+ const DWORD curDirLen = GetCurrentDirectory(0, NULL);
+
+ char* curDir = new char[curDirLen];
+
+ GetCurrentDirectoryA(curDirLen, curDir);
+
+ std::string curDirStr = curDir;
+
+ delete[] curDir;
+
+ return ResolveIgniteHome0(curDirStr, true, found);
+ }
+ }
+
+ std::string CreateIgniteClasspath(const std::string* usrCp, const std::string* home)
+ {
+ bool forceTest = false;
+
+ if (home)
+ {
+ bool envFound;
+ std::string env = GetEnv(IGNITE_NATIVE_TEST_CLASSPATH, &envFound);
+
+ forceTest = envFound && env.compare("true") == 0;
+ }
+
+ return CreateIgniteClasspath(usrCp, home, forceTest);
+ }
+
+ std::string CreateIgniteClasspath(const std::string* usrCp, const std::string* home, bool forceTest)
+ {
+ // 1. Append user classpath if it exists.
+ std::string cp = std::string();
+
+ if (usrCp)
+ {
+ cp.append(*usrCp);
+
+ if (*cp.rbegin() != ';')
+ cp.append(";");
+ }
+
+ // 2. Append home classpath if home is defined.
+ if (home)
+ {
+ std::string homeCp = CreateIgniteHomeClasspath(*home, forceTest);
+
+ cp.append(homeCp);
+ }
+
+ // 3. Return.
+ return cp;
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/project/README.TXT
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/project/README.TXT b/modules/platform/src/main/cpp/core/project/README.TXT
new file mode 100644
index 0000000..97f4c64
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/project/README.TXT
@@ -0,0 +1 @@
+Contains IDE projects artifacts.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/project/vs/README.TXT
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/project/vs/README.TXT b/modules/platform/src/main/cpp/core/project/vs/README.TXT
new file mode 100644
index 0000000..f4fb456
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/project/vs/README.TXT
@@ -0,0 +1 @@
+Contains Visual Studio project artifacts.
\ No newline at end of file
[09/11] ignite git commit: IGNITE-1364: Squashed commit from initial
branch.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/src/portable_reader_writer_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/src/portable_reader_writer_test.cpp b/modules/platform/src/main/cpp/core-test/src/portable_reader_writer_test.cpp
new file mode 100644
index 0000000..aff929b
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/src/portable_reader_writer_test.cpp
@@ -0,0 +1,1951 @@
+/*
+ * 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.
+ */
+
+#ifndef _MSC_VER
+ #define BOOST_TEST_DYN_LINK
+#endif
+
+#include <boost/test/unit_test.hpp>
+
+#include "ignite/impl/interop/interop.h"
+#include "ignite/portable/portable.h"
+
+#include "ignite/portable_test_defs.h"
+#include "ignite/portable_test_utils.h"
+
+using namespace ignite;
+using namespace ignite::impl::interop;
+using namespace ignite::impl::portable;
+using namespace ignite::portable;
+using namespace ignite_test::core::portable;
+
+template<typename T>
+void CheckPrimitive(T val)
+{
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ out.Position(18);
+
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ try
+ {
+ Write<T>(writer, NULL, val);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ Write<T>(writer, "test", val);
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+
+ in.Position(18);
+
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100);
+ PortableReader reader(&readerImpl);
+
+ try
+ {
+ Read<T>(reader, NULL);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ T readVal = Read<T>(reader, "test");
+
+ BOOST_REQUIRE(readVal == val);
+}
+
+template<typename T>
+void CheckPrimitiveArray(T dflt, T val1, T val2)
+{
+ const char* fieldName = "test";
+
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100);
+ PortableReader reader(&readerImpl);
+
+ out.Position(18);
+
+ try
+ {
+ T nullFieldArr[2];
+
+ nullFieldArr[0] = val1;
+ nullFieldArr[1] = val2;
+
+ WriteArray<T>(writer, NULL, nullFieldArr, 2);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ // 1. Write NULL and see what happens.
+ WriteArray<T>(writer, fieldName, NULL, 0);
+
+ out.Synchronize();
+ in.Synchronize();
+
+ in.Position(18);
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, NULL, 0) == -1);
+
+ in.Position(18);
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, NULL, 2) == -1);
+
+ T arr1[2];
+ arr1[0] = dflt;
+ arr1[1] = dflt;
+
+ in.Position(18);
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, arr1, 1) == -1);
+
+ BOOST_REQUIRE(arr1[0] == dflt);
+ BOOST_REQUIRE(arr1[1] == dflt);
+
+ // 2. Write empty array.
+ T arr2[2];
+ arr2[0] = val1;
+ arr2[1] = val2;
+
+ out.Position(18);
+
+ WriteArray<T>(writer, fieldName, arr2, 0);
+
+ out.Synchronize();
+ in.Synchronize();
+
+ in.Position(18);
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, NULL, 0) == 0);
+
+ in.Position(18);
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, NULL, 2) == 0);
+
+ in.Position(18);
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, arr1, 0) == 0);
+ BOOST_REQUIRE(arr1[0] == dflt);
+ BOOST_REQUIRE(arr1[1] == dflt);
+
+ in.Position(18);
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, arr1, 2) == 0);
+ BOOST_REQUIRE(arr1[0] == dflt);
+ BOOST_REQUIRE(arr1[1] == dflt);
+
+ // 3. Partial array write.
+ out.Position(18);
+
+ WriteArray<T>(writer, fieldName, arr2, 1);
+
+ out.Synchronize();
+ in.Synchronize();
+
+ in.Position(18);
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, NULL, 0) == 1);
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, NULL, 2) == 1);
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, arr1, 0) == 1);
+ BOOST_REQUIRE(arr1[0] == dflt);
+ BOOST_REQUIRE(arr1[1] == dflt);
+
+ in.Position(18);
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, arr1, 1) == 1);
+ BOOST_REQUIRE(arr1[0] == val1);
+ BOOST_REQUIRE(arr1[1] == dflt);
+ arr1[0] = dflt;
+
+ in.Position(18);
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, arr1, 2) == 1);
+ BOOST_REQUIRE(arr1[0] == val1);
+ BOOST_REQUIRE(arr1[1] == dflt);
+ arr1[0] = dflt;
+
+ // 4. Full array write.
+ out.Position(18);
+
+ WriteArray<T>(writer, fieldName, arr2, 2);
+
+ out.Synchronize();
+ in.Synchronize();
+
+ in.Position(18);
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, NULL, 0) == 2);
+
+ in.Position(18);
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, NULL, 2) == 2);
+
+ try
+ {
+ ReadArray<T>(reader, NULL, arr1, 2);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, arr1, 0) == 2);
+ BOOST_REQUIRE(arr1[0] == dflt);
+ BOOST_REQUIRE(arr1[1] == dflt);
+
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, arr1, 1) == 2);
+ BOOST_REQUIRE(arr1[0] == dflt);
+ BOOST_REQUIRE(arr1[1] == dflt);
+
+ BOOST_REQUIRE(ReadArray<T>(reader, fieldName, arr1, 2) == 2);
+ BOOST_REQUIRE(arr1[0] == val1);
+ BOOST_REQUIRE(arr1[1] == val2);
+}
+
+void CheckWritesRestricted(PortableWriter& writer)
+{
+ try
+ {
+ writer.WriteInt8("field", 1);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ int8_t arr[1];
+
+ writer.WriteInt8Array("field", arr, 1);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ Guid val(1, 1);
+
+ writer.WriteGuid("field", val);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ writer.WriteString("field", "test");
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ writer.WriteArray<int8_t>("field");
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ writer.WriteCollection<int8_t>("field");
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ writer.WriteMap<int8_t, int8_t>("field");
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+}
+
+void CheckReadsRestricted(PortableReader& reader)
+{
+ try
+ {
+ reader.ReadInt8("field");
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ int8_t arr[1];
+
+ reader.ReadInt8Array("field", arr, 1);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ reader.ReadGuid("field");
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ reader.ReadString("field");
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ reader.ReadArray<int8_t>("field");
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ reader.ReadCollection<int8_t>("field");
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ reader.ReadMap<int8_t, int8_t>("field");
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+}
+
+void CheckCollectionEmpty(CollectionType* colType)
+{
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ PortableCollectionWriter<PortableInner> colWriter = colType ?
+ writer.WriteCollection<PortableInner>("field1", *colType) : writer.WriteCollection<PortableInner>("field1");
+
+ CheckWritesRestricted(writer);
+
+ colWriter.Close();
+
+ writer.WriteInt8("field2", 1);
+
+ try
+ {
+ colWriter.Write(1);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ colWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ PortableCollectionReader<PortableInner> colReader = reader.ReadCollection<PortableInner>("field1");
+
+ if (colType)
+ BOOST_REQUIRE(colReader.GetType() == *colType);
+ else
+ BOOST_REQUIRE(colReader.GetType() == IGNITE_COLLECTION_UNDEFINED);
+
+ BOOST_REQUIRE(colReader.GetSize() == 0);
+ BOOST_REQUIRE(!colReader.HasNext());
+ BOOST_REQUIRE(!colReader.IsNull());
+
+ try
+ {
+ colReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(reader.ReadInt8("field2") == 1);
+}
+
+void CheckCollection(CollectionType* colType)
+{
+ PortableInner writeVal1 = PortableInner(1);
+ PortableInner writeVal2 = PortableInner(0);
+ PortableInner writeVal3 = PortableInner(2);
+
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ PortableCollectionWriter<PortableInner> colWriter = colType ?
+ writer.WriteCollection<PortableInner>("field1", *colType) : writer.WriteCollection<PortableInner>("field1");
+
+ colWriter.Write(writeVal1);
+ colWriter.Write(writeVal2);
+ colWriter.Write(writeVal3);
+
+ CheckWritesRestricted(writer);
+
+ colWriter.Close();
+
+ writer.WriteInt8("field2", 1);
+
+ try
+ {
+ colWriter.Write(1);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ colWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ PortableCollectionReader<PortableInner> colReader = reader.ReadCollection<PortableInner>("field1");
+
+ CheckReadsRestricted(reader);
+
+ if (colType)
+ BOOST_REQUIRE(colReader.GetType() == *colType);
+ else
+ BOOST_REQUIRE(colReader.GetType() == IGNITE_COLLECTION_UNDEFINED);
+
+ BOOST_REQUIRE(colReader.GetSize() == 3);
+ BOOST_REQUIRE(!colReader.IsNull());
+
+ BOOST_REQUIRE(colReader.HasNext());
+ BOOST_REQUIRE(colReader.GetNext().GetValue() == writeVal1.GetValue());
+
+ BOOST_REQUIRE(colReader.HasNext());
+ BOOST_REQUIRE(colReader.GetNext().GetValue() == writeVal2.GetValue());
+
+ BOOST_REQUIRE(colReader.HasNext());
+ BOOST_REQUIRE(colReader.GetNext().GetValue() == writeVal3.GetValue());
+
+ BOOST_REQUIRE(!colReader.HasNext());
+
+ try
+ {
+ colReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(reader.ReadInt8("field2") == 1);
+}
+
+void CheckMapEmpty(MapType* mapType)
+{
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ PortableMapWriter<int8_t, PortableInner> mapWriter = mapType ?
+ writer.WriteMap<int8_t, PortableInner>("field1", *mapType) : writer.WriteMap<int8_t, PortableInner>("field1");
+
+ CheckWritesRestricted(writer);
+
+ mapWriter.Close();
+
+ writer.WriteInt8("field2", 1);
+
+ try
+ {
+ mapWriter.Write(1, PortableInner(1));
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ mapWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ PortableMapReader<int8_t, PortableInner> mapReader = reader.ReadMap<int8_t, PortableInner>("field1");
+
+ if (mapType)
+ BOOST_REQUIRE(mapReader.GetType() == *mapType);
+ else
+ BOOST_REQUIRE(mapReader.GetType() == IGNITE_MAP_UNDEFINED);
+
+ BOOST_REQUIRE(mapReader.GetSize() == 0);
+ BOOST_REQUIRE(!mapReader.HasNext());
+ BOOST_REQUIRE(!mapReader.IsNull());
+
+ try
+ {
+ int8_t key;
+ PortableInner val;
+
+ mapReader.GetNext(&key, &val);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(reader.ReadInt8("field2") == 1);
+}
+
+void CheckMap(MapType* mapType)
+{
+ PortableInner writeVal1 = PortableInner(1);
+ PortableInner writeVal2 = PortableInner(0);
+ PortableInner writeVal3 = PortableInner(2);
+
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ PortableMapWriter<int8_t, PortableInner> mapWriter = mapType ?
+ writer.WriteMap<int8_t, PortableInner>("field1", *mapType) : writer.WriteMap<int8_t, PortableInner>("field1");
+
+ mapWriter.Write(1, writeVal1);
+ mapWriter.Write(2, writeVal2);
+ mapWriter.Write(3, writeVal3);
+
+ CheckWritesRestricted(writer);
+
+ mapWriter.Close();
+
+ writer.WriteInt8("field2", 1);
+
+ try
+ {
+ mapWriter.Write(4, PortableInner(4));
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ mapWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ PortableMapReader<int8_t, PortableInner> mapReader = reader.ReadMap<int8_t, PortableInner>("field1");
+
+ CheckReadsRestricted(reader);
+
+ if (mapType)
+ BOOST_REQUIRE(mapReader.GetType() == *mapType);
+ else
+ BOOST_REQUIRE(mapReader.GetType() == IGNITE_MAP_UNDEFINED);
+
+ BOOST_REQUIRE(mapReader.GetSize() == 3);
+ BOOST_REQUIRE(!mapReader.IsNull());
+
+ int8_t key;
+ PortableInner val;
+
+ BOOST_REQUIRE(mapReader.HasNext());
+
+ mapReader.GetNext(&key, &val);
+ BOOST_REQUIRE(key == 1);
+ BOOST_REQUIRE(val.GetValue() == writeVal1.GetValue());
+
+ mapReader.GetNext(&key, &val);
+ BOOST_REQUIRE(key == 2);
+ BOOST_REQUIRE(val.GetValue() == writeVal2.GetValue());
+
+ mapReader.GetNext(&key, &val);
+ BOOST_REQUIRE(key == 3);
+ BOOST_REQUIRE(val.GetValue() == writeVal3.GetValue());
+
+ BOOST_REQUIRE(!mapReader.HasNext());
+
+ try
+ {
+ mapReader.GetNext(&key, &val);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(reader.ReadInt8("field2") == 1);
+}
+
+BOOST_AUTO_TEST_SUITE(PortableReaderWriterTestSuite)
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveInt8)
+{
+ CheckPrimitive<int8_t>(1);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveBool)
+{
+ CheckPrimitive<bool>(true);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveInt16)
+{
+ CheckPrimitive<int16_t>(1);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveUInt16)
+{
+ CheckPrimitive<uint16_t>(1);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveInt32)
+{
+ CheckPrimitive<int32_t>(1);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveInt64)
+{
+ CheckPrimitive<int64_t>(1);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveFloat)
+{
+ CheckPrimitive<float>(1.1f);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveDouble)
+{
+ CheckPrimitive<double>(1.1);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveGuid)
+{
+ Guid val(1, 2);
+
+ CheckPrimitive<Guid>(val);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayInt8)
+{
+ CheckPrimitiveArray<int8_t>(1, 2, 3);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayBool)
+{
+ CheckPrimitiveArray<bool>(false, true, false);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayInt16)
+{
+ CheckPrimitiveArray<int16_t>(1, 2, 3);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayUInt16)
+{
+ CheckPrimitiveArray<uint16_t>(1, 2, 3);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayInt32)
+{
+ CheckPrimitiveArray<int32_t>(1, 2, 3);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayInt64)
+{
+ CheckPrimitiveArray<int64_t>(1, 2, 3);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayFloat)
+{
+ CheckPrimitiveArray<float>(1.1f, 2.2f, 3.3f);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayDouble)
+{
+ CheckPrimitiveArray<double>(1.1, 2.2, 3.3);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayGuid)
+{
+ Guid dflt(1, 2);
+ Guid val1(3, 4);
+ Guid val2(5, 6);
+
+ CheckPrimitiveArray<Guid>(dflt, val1, val2);
+}
+
+BOOST_AUTO_TEST_CASE(TestGuidNull)
+{
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ try
+ {
+ writer.WriteNull(NULL);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ writer.WriteNull("test");
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ try
+ {
+ reader.ReadGuid(NULL);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ Guid expVal;
+ Guid actualVal = reader.ReadGuid("test");
+
+ BOOST_REQUIRE(actualVal == expVal);
+}
+
+BOOST_AUTO_TEST_CASE(TestString) {
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ const char* writeVal1 = "testtest";
+ const char* writeVal2 = "test";
+ std::string writeVal3 = writeVal1;
+
+ try
+ {
+ writer.WriteString(NULL, writeVal1);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ writer.WriteString(NULL, writeVal1, 4);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ writer.WriteString(NULL, writeVal3);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ writer.WriteString("field1", writeVal1);
+ writer.WriteString("field2", writeVal1, 4);
+ writer.WriteString("field3", writeVal3);
+ writer.WriteString("field4", NULL);
+ writer.WriteString("field5", NULL, 4);
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ try
+ {
+ char nullCheckRes[9];
+
+ reader.ReadString(NULL, nullCheckRes, 9);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ reader.ReadString(NULL);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ char readVal1[9];
+ char readVal2[5];
+
+ BOOST_REQUIRE(reader.ReadString("field1", NULL, 0) == 8);
+ BOOST_REQUIRE(reader.ReadString("field1", NULL, 8) == 8);
+ BOOST_REQUIRE(reader.ReadString("field1", readVal1, 0) == 8);
+ BOOST_REQUIRE(reader.ReadString("field1", readVal1, 4) == 8);
+
+ BOOST_REQUIRE(reader.ReadString("field1", readVal1, 9) == 8);
+ std::string writeVal1Str = writeVal1;
+ std::string readVal1Str = readVal1;
+ BOOST_REQUIRE(readVal1Str.compare(writeVal1Str) == 0);
+
+ BOOST_REQUIRE(reader.ReadString("field2", readVal2, 5) == 4);
+ std::string writeVal2Str = writeVal2;
+ std::string readVal2Str = readVal2;
+ BOOST_REQUIRE(readVal2Str.compare(writeVal2Str) == 0);
+
+ std::string readVal3 = reader.ReadString("field3");
+ BOOST_REQUIRE(readVal3.compare(writeVal3) == 0);
+
+ BOOST_REQUIRE(reader.ReadString("field4", readVal1, 9) == -1);
+ BOOST_REQUIRE(reader.ReadString("field5", readVal1, 9) == -1);
+}
+
+BOOST_AUTO_TEST_CASE(TestStringArrayNull)
+{
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ writer.WriteNull("field1");
+ writer.WriteInt8("field2", 1);
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ PortableStringArrayReader arrReader = reader.ReadStringArray("field1");
+
+ BOOST_REQUIRE(arrReader.GetSize() == -1);
+ BOOST_REQUIRE(!arrReader.HasNext());
+ BOOST_REQUIRE(arrReader.IsNull());
+
+ try
+ {
+ char res[100];
+
+ arrReader.GetNext(res, 100);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ arrReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(reader.ReadInt8("field2") == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestStringArrayEmpty)
+{
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ PortableStringArrayWriter arrWriter = writer.WriteStringArray("field1");
+
+ CheckWritesRestricted(writer);
+
+ arrWriter.Close();
+
+ writer.WriteInt8("field2", 1);
+
+ try
+ {
+ const char* val = "test";
+
+ arrWriter.Write(val, 4);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ const char* val = "test";
+
+ arrWriter.Write(val);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ std::string val = "test";
+
+ arrWriter.Write(val);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ arrWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ PortableStringArrayReader arrReader = reader.ReadStringArray("field1");
+
+ BOOST_REQUIRE(arrReader.GetSize() == 0);
+ BOOST_REQUIRE(!arrReader.HasNext());
+ BOOST_REQUIRE(!arrReader.IsNull());
+
+ try
+ {
+ char res[100];
+
+ arrReader.GetNext(res, 100);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ arrReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(reader.ReadInt8("field2") == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestStringArray)
+{
+ const char* writeVal1 = "testtest";
+ const char* writeVal2 = "test";
+ std::string writeVal3 = "test2";
+
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ PortableStringArrayWriter arrWriter = writer.WriteStringArray("field1");
+
+ arrWriter.Write(writeVal1);
+ arrWriter.Write(writeVal1, 4);
+ arrWriter.Write(NULL); // NULL value.
+ arrWriter.Write(NULL, 100); // NULL value again.
+ arrWriter.Write(writeVal3);
+
+ CheckWritesRestricted(writer);
+
+ arrWriter.Close();
+
+ writer.WriteInt8("field2", 1);
+
+ try
+ {
+ const char* val = "test";
+
+ arrWriter.Write(val, 4);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ const char* val = "test";
+
+ arrWriter.Write(val);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ std::string val = "test";
+
+ arrWriter.Write(val);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ arrWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ PortableStringArrayReader arrReader = reader.ReadStringArray("field1");
+
+ CheckReadsRestricted(reader);
+
+ BOOST_REQUIRE(arrReader.GetSize() == 5);
+ BOOST_REQUIRE(!arrReader.IsNull());
+
+ // 1. Read first value.
+ BOOST_REQUIRE(arrReader.HasNext());
+
+ char readVal1[9];
+
+ BOOST_REQUIRE(arrReader.GetNext(NULL, 0) == 8);
+ BOOST_REQUIRE(arrReader.GetNext(NULL, 8) == 8);
+ BOOST_REQUIRE(arrReader.GetNext(readVal1, 0) == 8);
+ BOOST_REQUIRE(arrReader.GetNext(readVal1, 4) == 8);
+
+ BOOST_REQUIRE(arrReader.GetNext(readVal1, 9) == 8);
+ std::string writeVal1Str = writeVal1;
+ std::string readVal1Str = readVal1;
+ BOOST_REQUIRE(readVal1Str.compare(writeVal1Str) == 0);
+
+ // 2. Read second value.
+ BOOST_REQUIRE(arrReader.HasNext());
+
+ char readVal2[5];
+
+ BOOST_REQUIRE(arrReader.GetNext(readVal2, 5) == 4);
+ std::string writeVal2Str = writeVal2;
+ std::string readVal2Str = readVal2;
+ BOOST_REQUIRE(readVal2Str.compare(writeVal2Str) == 0);
+
+ // 3. Read NULL.
+ BOOST_REQUIRE(arrReader.HasNext());
+
+ BOOST_REQUIRE(arrReader.GetNext(readVal1, 4) == -1);
+ readVal1Str = readVal1;
+ BOOST_REQUIRE(readVal1Str.compare(writeVal1Str) == 0);
+
+ // 4. Read NULL again, this time through another method.
+ BOOST_REQUIRE(arrReader.HasNext());
+
+ std::string readNullVal = arrReader.GetNext();
+
+ BOOST_REQUIRE(readNullVal.length() == 0);
+
+ // 5. Read third value.
+ BOOST_REQUIRE(arrReader.HasNext());
+
+ std::string readVal3 = arrReader.GetNext();
+ BOOST_REQUIRE(readVal3.compare(writeVal3) == 0);
+
+ BOOST_REQUIRE(!arrReader.HasNext());
+
+ try
+ {
+ char res[100];
+
+ arrReader.GetNext(res, 100);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ arrReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(reader.ReadInt8("field2") == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestObject)
+{
+ PortableInner writeVal1(1);
+ PortableInner writeVal2(0);
+
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ writer.WriteObject("field1", writeVal1);
+ writer.WriteObject("field2", writeVal2);
+ writer.WriteNull("field3");
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ PortableInner readVal1 = reader.ReadObject<PortableInner>("field1");
+ BOOST_REQUIRE(writeVal1.GetValue() == readVal1.GetValue());
+
+ PortableInner readVal2 = reader.ReadObject<PortableInner>("field2");
+ BOOST_REQUIRE(writeVal2.GetValue() == readVal2.GetValue());
+
+ PortableInner readVal3 = reader.ReadObject<PortableInner>("field3");
+ BOOST_REQUIRE(0 == readVal3.GetValue());
+}
+
+BOOST_AUTO_TEST_CASE(TestNestedObject)
+{
+ PortableOuter writeVal1(1, 2);
+ PortableOuter writeVal2(0, 0);
+
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ writer.WriteObject("field1", writeVal1);
+ writer.WriteObject("field2", writeVal2);
+ writer.WriteNull("field3");
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ PortableOuter readVal1 = reader.ReadObject<PortableOuter>("field1");
+ BOOST_REQUIRE(writeVal1.GetValue() == readVal1.GetValue());
+ BOOST_REQUIRE(writeVal1.GetInner().GetValue() == readVal1.GetInner().GetValue());
+
+ PortableOuter readVal2 = reader.ReadObject<PortableOuter>("field2");
+ BOOST_REQUIRE(writeVal2.GetValue() == readVal2.GetValue());
+ BOOST_REQUIRE(writeVal2.GetInner().GetValue() == readVal2.GetInner().GetValue());
+
+ PortableOuter readVal3 = reader.ReadObject<PortableOuter>("field3");
+ BOOST_REQUIRE(0 == readVal3.GetValue());
+ BOOST_REQUIRE(0 == readVal3.GetInner().GetValue());
+}
+
+BOOST_AUTO_TEST_CASE(TestArrayNull)
+{
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ writer.WriteNull("field1");
+ writer.WriteInt8("field2", 1);
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ PortableArrayReader<PortableInner> arrReader = reader.ReadArray<PortableInner>("field1");
+
+ BOOST_REQUIRE(arrReader.GetSize() == -1);
+ BOOST_REQUIRE(!arrReader.HasNext());
+ BOOST_REQUIRE(arrReader.IsNull());
+
+ try
+ {
+ arrReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(reader.ReadInt8("field2") == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestArrayEmpty)
+{
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ PortableArrayWriter<PortableInner> arrWriter = writer.WriteArray<PortableInner>("field1");
+
+ CheckWritesRestricted(writer);
+
+ arrWriter.Close();
+
+ writer.WriteInt8("field2", 1);
+
+ try
+ {
+ arrWriter.Write(1);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ arrWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ PortableArrayReader<PortableInner> arrReader = reader.ReadArray<PortableInner>("field1");
+
+ BOOST_REQUIRE(arrReader.GetSize() == 0);
+ BOOST_REQUIRE(!arrReader.HasNext());
+ BOOST_REQUIRE(!arrReader.IsNull());
+
+ try
+ {
+ arrReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(reader.ReadInt8("field2") == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestArray)
+{
+ PortableInner writeVal1 = PortableInner(1);
+ PortableInner writeVal2 = PortableInner(0);
+ PortableInner writeVal3 = PortableInner(2);
+
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ PortableArrayWriter<PortableInner> arrWriter = writer.WriteArray<PortableInner>("field1");
+
+ arrWriter.Write(writeVal1);
+ arrWriter.Write(writeVal2);
+ arrWriter.Write(writeVal3);
+
+ CheckWritesRestricted(writer);
+
+ arrWriter.Close();
+
+ writer.WriteInt8("field2", 1);
+
+ try
+ {
+ arrWriter.Write(1);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ arrWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ PortableArrayReader<PortableInner> arrReader = reader.ReadArray<PortableInner>("field1");
+
+ CheckReadsRestricted(reader);
+
+ BOOST_REQUIRE(arrReader.GetSize() == 3);
+ BOOST_REQUIRE(!arrReader.IsNull());
+
+ BOOST_REQUIRE(arrReader.HasNext());
+ BOOST_REQUIRE(arrReader.GetNext().GetValue() == writeVal1.GetValue());
+
+ BOOST_REQUIRE(arrReader.HasNext());
+ BOOST_REQUIRE(arrReader.GetNext().GetValue() == writeVal2.GetValue());
+
+ BOOST_REQUIRE(arrReader.HasNext());
+ BOOST_REQUIRE(arrReader.GetNext().GetValue() == writeVal3.GetValue());
+
+ BOOST_REQUIRE(!arrReader.HasNext());
+
+ try
+ {
+ arrReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(reader.ReadInt8("field2") == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestCollectionNull)
+{
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ writer.WriteNull("field1");
+ writer.WriteInt8("field2", 1);
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ PortableCollectionReader<PortableInner> colReader = reader.ReadCollection<PortableInner>("field1");
+
+ BOOST_REQUIRE(colReader.GetType() == IGNITE_COLLECTION_UNDEFINED);
+ BOOST_REQUIRE(colReader.GetSize() == -1);
+ BOOST_REQUIRE(!colReader.HasNext());
+ BOOST_REQUIRE(colReader.IsNull());
+
+ try
+ {
+ colReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(reader.ReadInt8("field2") == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestCollectionEmpty)
+{
+ CheckCollectionEmpty(NULL);
+}
+
+BOOST_AUTO_TEST_CASE(TestCollectionEmptyTyped)
+{
+ CollectionType typ = IGNITE_COLLECTION_CONCURRENT_SKIP_LIST_SET;
+
+ CheckCollectionEmpty(&typ);
+}
+
+BOOST_AUTO_TEST_CASE(TestCollection)
+{
+ CheckCollection(NULL);
+}
+
+BOOST_AUTO_TEST_CASE(testCollectionTyped)
+{
+ CollectionType typ = IGNITE_COLLECTION_CONCURRENT_SKIP_LIST_SET;
+
+ CheckCollection(&typ);
+}
+
+BOOST_AUTO_TEST_CASE(TestMapNull)
+{
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ writer.WriteNull("field1");
+ writer.WriteInt8("field2", 1);
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ PortableMapReader<int8_t, PortableInner> mapReader = reader.ReadMap<int8_t, PortableInner>("field1");
+
+ BOOST_REQUIRE(mapReader.GetType() == IGNITE_MAP_UNDEFINED);
+ BOOST_REQUIRE(mapReader.GetSize() == -1);
+ BOOST_REQUIRE(!mapReader.HasNext());
+ BOOST_REQUIRE(mapReader.IsNull());
+
+ try
+ {
+ int8_t key;
+ PortableInner val;
+
+ mapReader.GetNext(&key, &val);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(reader.ReadInt8("field2") == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestMapEmpty)
+{
+ CheckMapEmpty(NULL);
+}
+
+BOOST_AUTO_TEST_CASE(TestMapEmptyTyped)
+{
+ MapType typ = IGNITE_MAP_CONCURRENT_HASH_MAP;
+
+ CheckMapEmpty(&typ);
+}
+
+BOOST_AUTO_TEST_CASE(TestMap)
+{
+ CheckMap(NULL);
+}
+
+BOOST_AUTO_TEST_CASE(TestMapTyped)
+{
+ MapType typ = IGNITE_MAP_CONCURRENT_HASH_MAP;
+
+ CheckMap(&typ);
+}
+
+BOOST_AUTO_TEST_CASE(TestRawMode)
+{
+ TemplatedPortableIdResolver<PortableDummy> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL);
+ PortableWriter writer(&writerImpl);
+
+ out.Position(18);
+
+ PortableRawWriter rawWriter = writer.RawWriter();
+
+ try
+ {
+ writer.RawWriter();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ rawWriter.WriteInt8(1);
+
+ CheckWritesRestricted(writer);
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 18);
+ PortableReader reader(&readerImpl);
+
+ in.Position(18);
+
+ PortableRawReader rawReader = reader.RawReader();
+
+ try
+ {
+ reader.RawReader();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(rawReader.ReadInt8() == 1);
+
+ CheckReadsRestricted(reader);
+}
+
+BOOST_AUTO_TEST_CASE(TestFieldSeek)
+{
+ TemplatedPortableIdResolver<PortableFields> idRslvr;
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+
+ PortableFields writeVal(1, 2, 3, 4);
+
+ writer.WriteTopObject<PortableFields>(writeVal);
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+
+ int32_t pos = in.Position();
+ in.ReadInt8(); // We do not need a header here.
+ bool usrType = in.ReadBool();
+ int32_t typeId = in.ReadInt32();
+ int32_t hashCode = in.ReadInt32();
+ int32_t len = in.ReadInt32();
+ int32_t rawOff = in.ReadInt32();
+
+ PortableReaderImpl readerImpl(&in, &idRslvr, pos, usrType, typeId, hashCode, len, rawOff);
+ PortableReader reader(&readerImpl);
+
+ // 1. Clockwise.
+ BOOST_REQUIRE(reader.ReadInt32("val1") == 1);
+ BOOST_REQUIRE(reader.ReadInt32("val2") == 2);
+ BOOST_REQUIRE(reader.ReadInt32("val1") == 1);
+ BOOST_REQUIRE(reader.ReadInt32("val2") == 2);
+
+ // 2. Counter closkwise.
+ in.Position(18);
+ BOOST_REQUIRE(reader.ReadInt32("val2") == 2);
+ BOOST_REQUIRE(reader.ReadInt32("val1") == 1);
+ BOOST_REQUIRE(reader.ReadInt32("val2") == 2);
+ BOOST_REQUIRE(reader.ReadInt32("val1") == 1);
+
+ // 3. Same field twice.
+ in.Position(18);
+ BOOST_REQUIRE(reader.ReadInt32("val1") == 1);
+ BOOST_REQUIRE(reader.ReadInt32("val1") == 1);
+
+ in.Position(18);
+ BOOST_REQUIRE(reader.ReadInt32("val2") == 2);
+ BOOST_REQUIRE(reader.ReadInt32("val2") == 2);
+
+ // 4. Read missing field in between.
+ in.Position(18);
+ BOOST_REQUIRE(reader.ReadInt32("val1") == 1);
+ BOOST_REQUIRE(reader.ReadInt32("missing") == 0);
+ BOOST_REQUIRE(reader.ReadInt32("val2") == 2);
+
+ in.Position(18);
+ BOOST_REQUIRE(reader.ReadInt32("val2") == 2);
+ BOOST_REQUIRE(reader.ReadInt32("missing") == 0);
+ BOOST_REQUIRE(reader.ReadInt32("val1") == 1);
+
+ // 5. Invalid field type.
+ in.Position(18);
+ BOOST_REQUIRE(reader.ReadInt32("val1") == 1);
+
+ try
+ {
+ reader.ReadInt64("val2");
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(reader.ReadInt32("val2") == 2);
+
+ // 6. Read missing primitive fields.
+ BOOST_REQUIRE(reader.ReadInt8("missing") == 0);
+ BOOST_REQUIRE(reader.ReadBool("missing") == false);
+ BOOST_REQUIRE(reader.ReadInt16("missing") == 0);
+ BOOST_REQUIRE(reader.ReadUInt16("missing") == 0);
+ BOOST_REQUIRE(reader.ReadInt32("missing") == 0);
+ BOOST_REQUIRE(reader.ReadInt64("missing") == 0);
+ BOOST_REQUIRE(reader.ReadFloat("missing") == 0);
+ BOOST_REQUIRE(reader.ReadDouble("missing") == 0);
+
+ BOOST_REQUIRE(reader.ReadGuid("missing").GetMostSignificantBits() == 0);
+ BOOST_REQUIRE(reader.ReadGuid("missing").GetLeastSignificantBits() == 0);
+
+ // 7. Read missing primitive array fields.
+ BOOST_REQUIRE(reader.ReadInt8Array("missing", NULL, 1) == -1);
+ BOOST_REQUIRE(reader.ReadBoolArray("missing", NULL, 1) == -1);
+ BOOST_REQUIRE(reader.ReadInt16Array("missing", NULL, 1) == -1);
+ BOOST_REQUIRE(reader.ReadUInt16Array("missing", NULL, 1) == -1);
+ BOOST_REQUIRE(reader.ReadInt32Array("missing", NULL, 1) == -1);
+ BOOST_REQUIRE(reader.ReadInt64Array("missing", NULL, 1) == -1);
+ BOOST_REQUIRE(reader.ReadFloatArray("missing", NULL, 1) == -1);
+ BOOST_REQUIRE(reader.ReadDoubleArray("missing", NULL, 1) == -1);
+
+ BOOST_REQUIRE(reader.ReadGuidArray("missing", NULL, 1) == -1);
+
+ // 8. Read missing string fields.
+ BOOST_REQUIRE(reader.ReadString("missing", NULL, 1) == -1);
+ BOOST_REQUIRE(reader.ReadString("missing").length() == 0);
+
+ // 9. Read missing object fields.
+ BOOST_REQUIRE(reader.ReadObject<PortableFields*>("missing") == NULL);
+
+ // 10. Read missing container fields.
+ PortableStringArrayReader stringArrReader = reader.ReadStringArray("missing");
+ BOOST_REQUIRE(stringArrReader.IsNull());
+
+ PortableArrayReader<PortableFields> arrReader = reader.ReadArray<PortableFields>("missing");
+ BOOST_REQUIRE(arrReader.IsNull());
+
+ PortableCollectionReader<PortableFields> colReader = reader.ReadCollection<PortableFields>("missing");
+ BOOST_REQUIRE(colReader.IsNull());
+
+ PortableMapReader<int32_t, PortableFields> mapReader = reader.ReadMap<int32_t, PortableFields>("missing");
+ BOOST_REQUIRE(mapReader.IsNull());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/src/portable_session_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/src/portable_session_test.cpp b/modules/platform/src/main/cpp/core-test/src/portable_session_test.cpp
new file mode 100644
index 0000000..9d84e48
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/src/portable_session_test.cpp
@@ -0,0 +1,257 @@
+/*
+ * 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.
+ */
+
+#ifndef _MSC_VER
+ #define BOOST_TEST_DYN_LINK
+#endif
+
+#include <boost/test/unit_test.hpp>
+
+#include "ignite/impl/interop/interop.h"
+#include "ignite/impl/portable/portable_reader_impl.h"
+#include "ignite/impl/portable/portable_writer_impl.h"
+
+#include "ignite/portable_test_defs.h"
+
+using namespace ignite;
+using namespace ignite::impl::interop;
+using namespace ignite::impl::portable;
+using namespace ignite::portable;
+using namespace ignite_test::core::portable;
+
+/*
+ * Check primitive value serialization-deserialization.
+ */
+template<typename T>
+void CheckRawPrimitive(T writeVal)
+{
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writeSes(&out, NULL);
+ writeSes.WriteTopObject<T>(writeVal);
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ T readVal = reader.ReadTopObject<T>();
+
+ BOOST_REQUIRE(readVal == writeVal);
+}
+
+BOOST_AUTO_TEST_SUITE(PortableSessionTestSuite)
+
+BOOST_AUTO_TEST_CASE(TestByte)
+{
+ CheckRawPrimitive<int8_t>(-128);
+ CheckRawPrimitive<int8_t>(-1);
+ CheckRawPrimitive<int8_t>(0);
+ CheckRawPrimitive<int8_t>(1);
+ CheckRawPrimitive<int8_t>(127);
+}
+
+BOOST_AUTO_TEST_CASE(TestBool)
+{
+ CheckRawPrimitive<bool>(true);
+ CheckRawPrimitive<bool>(false);
+}
+
+BOOST_AUTO_TEST_CASE(TestShort)
+{
+ //CheckRawPrimitive<int16_t>(std::numeric_limits<int16_t>::min());
+ CheckRawPrimitive<int16_t>(-1);
+ CheckRawPrimitive<int16_t>(0);
+ CheckRawPrimitive<int16_t>(1);
+ //CheckRawPrimitive<int16_t>(std::numeric_limits<int16_t>::max());
+}
+
+BOOST_AUTO_TEST_CASE(TestChar)
+{
+ //CheckRawPrimitive<uint16_t>(std::numeric_limits<uint16_t>::min());
+ CheckRawPrimitive<uint16_t>(1);
+ //CheckRawPrimitive<uint16_t>(std::numeric_limits<uint16_t>::max());
+}
+
+BOOST_AUTO_TEST_CASE(TestInt)
+{
+ //CheckRawPrimitive<int32_t>(std::numeric_limits<int32_t>::min());
+ CheckRawPrimitive<int32_t>(-1);
+ CheckRawPrimitive<int32_t>(0);
+ CheckRawPrimitive<int32_t>(1);
+ //CheckRawPrimitive<int32_t>(std::numeric_limits<int32_t>::max());
+}
+
+BOOST_AUTO_TEST_CASE(TestLong)
+{
+ //CheckRawPrimitive<int64_t>(std::numeric_limits<int64_t>::min());
+ CheckRawPrimitive<int64_t>(-1);
+ CheckRawPrimitive<int64_t>(0);
+ CheckRawPrimitive<int64_t>(1);
+ //CheckRawPrimitive<int64_t>(std::numeric_limits<int64_t>::max());
+}
+
+BOOST_AUTO_TEST_CASE(TestFloat)
+{
+ CheckRawPrimitive<float>(-1.1f);
+ CheckRawPrimitive<float>(0);
+ CheckRawPrimitive<float>(1.1f);
+}
+
+BOOST_AUTO_TEST_CASE(TestDouble)
+{
+ CheckRawPrimitive<double>(-1.1);
+ CheckRawPrimitive<double>(0);
+ CheckRawPrimitive<double>(1.1);
+}
+
+BOOST_AUTO_TEST_CASE(TestGuid)
+{
+ Guid writeVal = Guid(1, 1);
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writeSes(&out, NULL);
+ writeSes.WriteTopObject<Guid>(writeVal);
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ Guid readVal = reader.ReadTopObject<Guid>();
+
+ BOOST_REQUIRE(readVal.GetMostSignificantBits() == writeVal.GetMostSignificantBits());
+ BOOST_REQUIRE(readVal.GetLeastSignificantBits() == writeVal.GetLeastSignificantBits());
+}
+
+BOOST_AUTO_TEST_CASE(TestString)
+{
+ std::string writeVal = "MyString";
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writeSes(&out, NULL);
+ writeSes.WriteTopObject<std::string>(writeVal);
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ std::string readVal = reader.ReadTopObject<std::string>();
+
+ BOOST_REQUIRE(readVal.compare(writeVal) == 0);
+}
+
+BOOST_AUTO_TEST_CASE(TestObject)
+{
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+
+ // 1. Test null object.
+ PortableInner writeVal(0);
+
+ writer.WriteTopObject<PortableInner>(writeVal);
+ out.Synchronize();
+
+ in.Synchronize();
+ PortableInner readVal = reader.ReadTopObject<PortableInner>();
+
+ BOOST_REQUIRE(readVal.GetValue() == 0);
+
+ // 2. Test non-null object.
+ out.Position(0);
+ in.Position(0);
+
+ writeVal = PortableInner(1);
+
+ writer.WriteTopObject<PortableInner>(writeVal);
+ out.Synchronize();
+
+ in.Synchronize();
+ readVal = reader.ReadTopObject<PortableInner>();
+
+ BOOST_REQUIRE(readVal.GetValue() == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestObjectWithRawFields)
+{
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+
+ out.Position(0);
+ in.Position(0);
+
+ PortableFields writeVal = PortableFields(1, 2, 3, 4);
+
+ writer.WriteTopObject<PortableFields>(writeVal);
+ out.Synchronize();
+
+ in.Synchronize();
+ PortableFields readVal = reader.ReadTopObject<PortableFields>();
+
+ BOOST_REQUIRE(readVal.val1 == 1);
+ BOOST_REQUIRE(readVal.val2 == 2);
+ BOOST_REQUIRE(readVal.rawVal1 == 3);
+ BOOST_REQUIRE(readVal.rawVal2 == 4);
+}
+
+BOOST_AUTO_TEST_CASE(TestPointer)
+{
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+
+ // 1. Test null object.
+ writer.WriteTopObject<PortableInner*>(NULL);
+ out.Synchronize();
+
+ in.Synchronize();
+ PortableInner* readVal = reader.ReadTopObject<PortableInner*>();
+
+ BOOST_REQUIRE(readVal == NULL);
+
+ // 2. Test non-null object.
+ out.Position(0);
+ in.Position(0);
+
+ PortableInner writeVal = PortableInner(1);
+
+ writer.WriteTopObject<PortableInner*>(&writeVal);
+ out.Synchronize();
+
+ in.Synchronize();
+ readVal = reader.ReadTopObject<PortableInner*>();
+
+ BOOST_REQUIRE(readVal->GetValue() == 1);
+
+ delete readVal;
+}
+
+BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/src/portable_test_defs.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/src/portable_test_defs.cpp b/modules/platform/src/main/cpp/core-test/src/portable_test_defs.cpp
new file mode 100644
index 0000000..e818711
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/src/portable_test_defs.cpp
@@ -0,0 +1,65 @@
+/*
+ * 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/portable/portable.h"
+
+#include "ignite/portable_test_defs.h"
+
+using namespace ignite;
+using namespace ignite::impl::interop;
+using namespace ignite::impl::portable;
+using namespace ignite::portable;
+
+namespace ignite_test
+{
+ namespace core
+ {
+ namespace portable
+ {
+ PortableInner::PortableInner() : val(0)
+ {
+ // No-op.
+ }
+
+ PortableInner::PortableInner(int32_t val) : val(val)
+ {
+ // No-op.
+ }
+
+ int32_t PortableInner::GetValue() const
+ {
+ return val;
+ }
+
+ PortableOuter::PortableOuter(int32_t valIn, int32_t valOut) : inner(valIn), val(valOut)
+ {
+ // No-op.
+ }
+
+ PortableInner PortableOuter::GetInner() const
+ {
+ return inner;
+ }
+
+ int32_t PortableOuter::GetValue() const
+ {
+ return val;
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/src/teamcity_boost.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/src/teamcity_boost.cpp b/modules/platform/src/main/cpp/core-test/src/teamcity_boost.cpp
new file mode 100644
index 0000000..45c666d
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/src/teamcity_boost.cpp
@@ -0,0 +1,159 @@
+/* Copyright 2011 JetBrains s.r.o.
+ *
+ * Licensed 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.
+ *
+ * $Revision: 88625 $
+*/
+
+#define BOOST_TEST_MODULE IgniteCoreTest
+
+#include <sstream>
+
+#include <boost/test/unit_test_suite_impl.hpp>
+#include <boost/test/results_collector.hpp>
+#include <boost/test/utils/basic_cstring/io.hpp>
+#include <boost/test/unit_test_log.hpp>
+#include <boost/test/included/unit_test.hpp>
+
+#include "teamcity_messages.h"
+
+using namespace boost::unit_test;
+using namespace std;
+
+namespace JetBrains {
+
+// Custom formatter for TeamCity messages
+class TeamcityBoostLogFormatter: public boost::unit_test::unit_test_log_formatter {
+ TeamcityMessages messages;
+ std::string currentDetails;
+ std::string flowId;
+
+public:
+ TeamcityBoostLogFormatter(const std::string &_flowId);
+ TeamcityBoostLogFormatter();
+
+ void log_start(std::ostream&, boost::unit_test::counter_t test_cases_amount);
+ void log_finish(std::ostream&);
+ void log_build_info(std::ostream&);
+
+ void test_unit_start(std::ostream&, boost::unit_test::test_unit const& tu);
+ void test_unit_finish(std::ostream&,
+ boost::unit_test::test_unit const& tu,
+ unsigned long elapsed);
+ void test_unit_skipped(std::ostream&, boost::unit_test::test_unit const& tu);
+
+ void log_exception(std::ostream&,
+ boost::unit_test::log_checkpoint_data const&,
+ boost::unit_test::const_string explanation);
+
+ void log_entry_start(std::ostream&,
+ boost::unit_test::log_entry_data const&,
+ log_entry_types let);
+ void log_entry_value(std::ostream&, boost::unit_test::const_string value);
+ void log_entry_finish(std::ostream&);
+};
+
+// Fake fixture to register formatter
+struct TeamcityFormatterRegistrar {
+ TeamcityFormatterRegistrar() {
+ if (JetBrains::underTeamcity()) {
+ boost::unit_test::unit_test_log.set_formatter(new JetBrains::TeamcityBoostLogFormatter());
+ boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_successful_tests);
+ }
+ }
+};
+BOOST_GLOBAL_FIXTURE(TeamcityFormatterRegistrar);
+
+// Formatter implementation
+string toString(const_string bstr) {
+ stringstream ss;
+
+ ss << bstr;
+
+ return ss.str();
+}
+
+TeamcityBoostLogFormatter::TeamcityBoostLogFormatter(const std::string &_flowId)
+: flowId(_flowId)
+{}
+
+TeamcityBoostLogFormatter::TeamcityBoostLogFormatter()
+: flowId(getFlowIdFromEnvironment())
+{}
+
+void TeamcityBoostLogFormatter::log_start(ostream &out, counter_t test_cases_amount)
+{}
+
+void TeamcityBoostLogFormatter::log_finish(ostream &out)
+{}
+
+void TeamcityBoostLogFormatter::log_build_info(ostream &out)
+{}
+
+void TeamcityBoostLogFormatter::test_unit_start(ostream &out, test_unit const& tu) {
+ messages.setOutput(out);
+
+ if (tu.p_type == tut_case) {
+ messages.testStarted(tu.p_name, flowId);
+ } else {
+ messages.suiteStarted(tu.p_name, flowId);
+ }
+
+ currentDetails.clear();
+}
+
+void TeamcityBoostLogFormatter::test_unit_finish(ostream &out, test_unit const& tu, unsigned long elapsed) {
+ messages.setOutput(out);
+
+ test_results const& tr = results_collector.results(tu.p_id);
+ if (tu.p_type == tut_case) {
+ if(!tr.passed()) {
+ if(tr.p_skipped) {
+ messages.testIgnored(tu.p_name, "ignored", flowId);
+ } else if (tr.p_aborted) {
+ messages.testFailed(tu.p_name, "aborted", currentDetails, flowId);
+ } else {
+ messages.testFailed(tu.p_name, "failed", currentDetails, flowId);
+ }
+ }
+
+ messages.testFinished(tu.p_name, elapsed / 1000, flowId);
+ } else {
+ messages.suiteFinished(tu.p_name, flowId);
+ }
+}
+
+void TeamcityBoostLogFormatter::test_unit_skipped(ostream &out, test_unit const& tu)
+{}
+
+void TeamcityBoostLogFormatter::log_exception(ostream &out, log_checkpoint_data const&, const_string explanation) {
+ string what = toString(explanation);
+
+ out << what << endl;
+ currentDetails += what + "\n";
+}
+
+void TeamcityBoostLogFormatter::log_entry_start(ostream&, log_entry_data const&, log_entry_types let)
+{}
+
+void TeamcityBoostLogFormatter::log_entry_value(ostream &out, const_string value) {
+ out << value;
+ currentDetails += toString(value);
+}
+
+void TeamcityBoostLogFormatter::log_entry_finish(ostream &out) {
+ out << endl;
+ currentDetails += "\n";
+}
+
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/src/teamcity_messages.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/src/teamcity_messages.cpp b/modules/platform/src/main/cpp/core-test/src/teamcity_messages.cpp
new file mode 100644
index 0000000..087409e
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/src/teamcity_messages.cpp
@@ -0,0 +1,150 @@
+/* Copyright 2011 JetBrains s.r.o.
+ *
+ * Licensed 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.
+ *
+ * $Revision: 88625 $
+*/
+
+#include <stdlib.h>
+#include <sstream>
+
+#include "teamcity_messages.h"
+
+using namespace std;
+
+namespace JetBrains {
+
+std::string getFlowIdFromEnvironment() {
+ const char *flowId = getenv("TEAMCITY_PROCESS_FLOW_ID");
+ return flowId == NULL ? "" : flowId;
+}
+
+bool underTeamcity() {
+ return getenv("TEAMCITY_PROJECT_NAME") != NULL;
+}
+
+TeamcityMessages::TeamcityMessages()
+: m_out(&cout)
+{}
+
+void TeamcityMessages::setOutput(ostream &out) {
+ m_out = &out;
+}
+
+string TeamcityMessages::escape(string s) {
+ string result;
+
+ for (size_t i = 0; i < s.length(); i++) {
+ char c = s[i];
+
+ switch (c) {
+ case '\n': result.append("|n"); break;
+ case '\r': result.append("|r"); break;
+ case '\'': result.append("|'"); break;
+ case '|': result.append("||"); break;
+ case ']': result.append("|]"); break;
+ default: result.append(&c, 1);
+ }
+ }
+
+ return result;
+}
+
+void TeamcityMessages::openMsg(const string &name) {
+ // endl for http://jetbrains.net/tracker/issue/TW-4412
+ *m_out << endl << "##teamcity[" << name;
+}
+
+void TeamcityMessages::closeMsg() {
+ *m_out << "]";
+ // endl for http://jetbrains.net/tracker/issue/TW-4412
+ *m_out << endl;
+ m_out->flush();
+}
+
+void TeamcityMessages::writeProperty(string name, string value) {
+ *m_out << " " << name << "='" << escape(value) << "'";
+}
+
+void TeamcityMessages::suiteStarted(string name, string flowid) {
+ openMsg("testSuiteStarted");
+ writeProperty("name", name);
+ if(flowid.length() > 0) {
+ writeProperty("flowId", flowid);
+ }
+
+ closeMsg();
+}
+
+void TeamcityMessages::suiteFinished(string name, string flowid) {
+ openMsg("testSuiteFinished");
+ writeProperty("name", name);
+ if(flowid.length() > 0) {
+ writeProperty("flowId", flowid);
+ }
+
+ closeMsg();
+}
+
+void TeamcityMessages::testStarted(string name, string flowid) {
+ openMsg("testStarted");
+ writeProperty("name", name);
+ if(flowid.length() > 0) {
+ writeProperty("flowId", flowid);
+ }
+
+ closeMsg();
+}
+
+void TeamcityMessages::testFinished(string name, int durationMs, string flowid) {
+ openMsg("testFinished");
+
+ writeProperty("name", name);
+
+ if(flowid.length() > 0) {
+ writeProperty("flowId", flowid);
+ }
+
+ if(durationMs >= 0) {
+ stringstream out;
+ out << durationMs;
+ writeProperty("duration", out.str());
+ }
+
+ closeMsg();
+}
+
+void TeamcityMessages::testFailed(string name, string message, string details, string flowid) {
+ openMsg("testFailed");
+ writeProperty("name", name);
+ writeProperty("message", message);
+ writeProperty("details", details);
+ if(flowid.length() > 0) {
+ writeProperty("flowId", flowid);
+ }
+
+ closeMsg();
+}
+
+void TeamcityMessages::testIgnored(std::string name, std::string message, string flowid) {
+ openMsg("testIgnored");
+ writeProperty("name", name);
+ writeProperty("message", message);
+ if(flowid.length() > 0) {
+ writeProperty("flowId", flowid);
+ }
+
+ closeMsg();
+}
+
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/Makefile.am
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/Makefile.am b/modules/platform/src/main/cpp/core/Makefile.am
new file mode 100644
index 0000000..db50326
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/Makefile.am
@@ -0,0 +1,66 @@
+##
+## 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.
+##
+
+ACLOCAL_AMFLAGS = "-Im4"
+
+SUBDIRS = . include os/linux/include
+DIST_SUBDIRS = . include os/linux/include
+
+AM_CPPFLAGS = -I$(srcdir)/include -I$(srcdir)/os/linux/include -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -DIGNITE_IMPL
+AM_CXXFLAGS = -Wall -std=c++0x
+LIB_LDFLAGS = -no-undefined -version-info 1
+
+COMMON_SRC = os/linux/src/impl/utils.cpp \
+ src/ignite_error.cpp \
+ src/guid.cpp \
+ src/impl/handle_registry.cpp \
+ src/impl/interop/interop_memory.cpp \
+ src/impl/interop/interop_input_stream.cpp \
+ src/impl/interop/interop_output_stream.cpp \
+ src/portable/portable_type.cpp \
+ src/impl/portable/portable_metadata_snapshot.cpp \
+ src/impl/portable/portable_metadata_handler.cpp \
+ src/impl/portable/portable_metadata_updater.cpp \
+ src/impl/portable/portable_metadata_manager.cpp \
+ src/impl/portable/portable_utils.cpp \
+ src/impl/portable/portable_reader_impl.cpp \
+ src/impl/portable/portable_writer_impl.cpp \
+ src/portable/portable_containers.cpp \
+ src/portable/portable_raw_reader.cpp \
+ src/portable/portable_raw_writer.cpp \
+ src/portable/portable_reader.cpp \
+ src/portable/portable_writer.cpp \
+ src/impl/portable/portable_metadata_updater_impl.cpp \
+ src/impl/ignite_environment.cpp \
+ src/impl/cache/query/query_impl.cpp \
+ src/impl/cache/cache_impl.cpp \
+ src/impl/ignite_impl.cpp \
+ src/ignite.cpp \
+ src/ignition.cpp
+
+lib_LTLIBRARIES = libignite.la
+libignite_la_SOURCES = $(COMMON_SRC)
+libignite_la_LDFLAGS = $(LIB_LDFLAGS) -L/usr/local/lib -lignite-common -ldl -version-info 0:0:0 -release $(PACKAGE_VERSION)
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = ignite.pc
+
+clean-local:
+ $(RM) *.gcno *.gcda
+
+clean-docs:
+ $(RM) $(DX_CLEANFILES)
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/configure.ac
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/configure.ac b/modules/platform/src/main/cpp/core/configure.ac
new file mode 100644
index 0000000..cdd238f
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/configure.ac
@@ -0,0 +1,62 @@
+#
+# 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.
+#
+
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.69])
+AC_INIT([Apache Ignite C++], [1.4.0], [dev@ignite.apache.org], [ignite], [ignite.apache.org])
+AC_CONFIG_SRCDIR(src)
+
+AC_CANONICAL_SYSTEM
+AC_CONFIG_MACRO_DIR([m4])
+AC_LANG([C++])
+
+# Initialize automake
+AM_INIT_AUTOMAKE([-Wall foreign subdir-objects])
+AC_CONFIG_HEADER(config.h)
+
+AM_PROG_AR
+
+# Checks for programs.
+GXX="-g -O2"
+
+AC_PROG_CXX
+
+# Initialize Libtool
+LT_INIT
+
+# Checks for libraries.
+AC_CHECK_LIB([pthread], [pthread_mutex_lock])
+
+# Checks for header files.
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_INLINE
+AC_TYPE_INT16_T
+AC_TYPE_INT32_T
+AC_TYPE_INT64_T
+AC_TYPE_INT8_T
+AC_TYPE_PID_T
+AC_TYPE_SIZE_T
+
+# Checks for library functions.
+AC_FUNC_ERROR_AT_LINE
+
+AC_CONFIG_FILES(Makefile include/Makefile os/linux/include/Makefile ignite.pc)
+
+AC_OUTPUT
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/ignite.pc.in
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/ignite.pc.in b/modules/platform/src/main/cpp/core/ignite.pc.in
new file mode 100644
index 0000000..613fd1a
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/ignite.pc.in
@@ -0,0 +1,9 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: ignite
+Description: Apache Ignite C++.
+Version: @PACKAGE_VERSION@
+Libs: -L${libdir} -lignite
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/Makefile.am
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/Makefile.am b/modules/platform/src/main/cpp/core/include/Makefile.am
new file mode 100644
index 0000000..da9d95e
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/Makefile.am
@@ -0,0 +1,61 @@
+##
+## 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.
+##
+
+ACLOCAL_AMFLAGS = "-Im4"
+
+nobase_include_HEADERS = ignite/cache/cache.h \
+ ignite/cache/cache_entry.h \
+ ignite/cache/cache_peek_mode.h \
+ ignite/cache/query/query_argument.h \
+ ignite/cache/query/query_cursor.h \
+ ignite/cache/query/query_scan.h \
+ ignite/cache/query/query_sql.h \
+ ignite/cache/query/query_text.h \
+ ignite/cache/query/query.h \
+ ignite/impl/cache/cache_impl.h \
+ ignite/impl/cache/query/query_impl.h \
+ ignite/impl/interop/interop.h \
+ ignite/impl/interop/interop_input_stream.h \
+ ignite/impl/interop/interop_memory.h \
+ ignite/impl/interop/interop_output_stream.h \
+ ignite/impl/portable/portable_metadata_handler.h \
+ ignite/impl/portable/portable_metadata_manager.h \
+ ignite/impl/portable/portable_metadata_snapshot.h \
+ ignite/impl/portable/portable_metadata_updater.h \
+ ignite/impl/portable/portable_metadata_updater_impl.h \
+ ignite/impl/portable/portable_common.h \
+ ignite/impl/portable/portable_id_resolver.h \
+ ignite/impl/portable/portable_reader_impl.h \
+ ignite/impl/portable/portable_utils.h \
+ ignite/impl/portable/portable_writer_impl.h \
+ ignite/impl/ignite_environment.h \
+ ignite/impl/ignite_impl.h \
+ ignite/impl/handle_registry.h \
+ ignite/impl/operations.h \
+ ignite/portable/portable.h \
+ ignite/portable/portable_consts.h \
+ ignite/portable/portable_containers.h \
+ ignite/portable/portable_type.h \
+ ignite/portable/portable_raw_reader.h \
+ ignite/portable/portable_raw_writer.h \
+ ignite/portable/portable_reader.h \
+ ignite/portable/portable_writer.h \
+ ignite/ignite.h \
+ ignite/ignite_configuration.h \
+ ignite/ignite_error.h \
+ ignite/ignition.h \
+ ignite/guid.h
[07/11] ignite git commit: IGNITE-1364: Squashed commit from initial
branch.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/ignite.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/ignite.h b/modules/platform/src/main/cpp/core/include/ignite/ignite.h
new file mode 100644
index 0000000..6c1263e
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/ignite.h
@@ -0,0 +1,154 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE
+#define _IGNITE
+
+#include "ignite/cache/cache.h"
+#include "ignite/impl/ignite_impl.h"
+#include "ignite/ignite_configuration.h"
+
+namespace ignite
+{
+ /**
+ * Main interface to operate with Ignite.
+ */
+ class IGNITE_IMPORT_EXPORT Ignite
+ {
+ public:
+ /**
+ * Default constructor.
+ */
+ Ignite();
+
+ /**
+ * Constructor.
+ */
+ Ignite(impl::IgniteImpl* impl);
+
+ /**
+ * Get Ignite instance name.
+ *
+ * @return Name.
+ */
+ char* GetName();
+
+ /**
+ * Get cache.
+ *
+ * @param name Cache name.
+ * @return Cache.
+ */
+ template<typename K, typename V>
+ cache::Cache<K, V> GetCache(const char* name)
+ {
+ IgniteError err;
+
+ cache::Cache<K, V> res = GetCache<K, V>(name, &err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Get cache.
+ *
+ * @param name Cache name.
+ * @param err Error;
+ * @return Cache.
+ */
+ template<typename K, typename V>
+ cache::Cache<K, V> GetCache(const char* name, IgniteError* err)
+ {
+ impl::cache::CacheImpl* cacheImpl = impl.Get()->GetCache<K, V>(name, err);
+
+ return cache::Cache<K, V>(cacheImpl);
+ }
+
+ /**
+ * Get or create cache.
+ *
+ * @param name Cache name.
+ * @return Cache.
+ */
+ template<typename K, typename V>
+ cache::Cache<K, V> GetOrCreateCache(const char* name)
+ {
+ IgniteError err;
+
+ cache::Cache<K, V> res = GetOrCreateCache<K, V>(name, &err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Get or create cache.
+ *
+ * @param name Cache name.
+ * @param err Error;
+ * @return Cache.
+ */
+ template<typename K, typename V>
+ cache::Cache<K, V> GetOrCreateCache(const char* name, IgniteError* err)
+ {
+ impl::cache::CacheImpl* cacheImpl = impl.Get()->GetOrCreateCache<K, V>(name, err);
+
+ return cache::Cache<K, V>(cacheImpl);
+ }
+
+ /**
+ * Create cache.
+ *
+ * @param name Cache name.
+ * @return Cache.
+ */
+ template<typename K, typename V>
+ cache::Cache<K, V> CreateCache(const char* name)
+ {
+ IgniteError err;
+
+ cache::Cache<K, V> res = CreateCache<K, V>(name, &err);
+
+ IgniteError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Create cache.
+ *
+ * @param name Cache name.
+ * @param err Error;
+ * @return Cache.
+ */
+ template<typename K, typename V>
+ cache::Cache<K, V> CreateCache(const char* name, IgniteError* err)
+ {
+ impl::cache::CacheImpl* cacheImpl = impl.Get()->CreateCache<K, V>(name, err);
+
+ return cache::Cache<K, V>(cacheImpl);
+ }
+ private:
+ /** Implementation delegate. */
+ ignite::common::concurrent::SharedPointer<impl::IgniteImpl> impl;
+ };
+}
+
+#endif
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/ignite_configuration.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/ignite_configuration.h b/modules/platform/src/main/cpp/core/include/ignite/ignite_configuration.h
new file mode 100644
index 0000000..ce2d730
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/ignite_configuration.h
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_CONFIGURATION
+#define _IGNITE_CONFIGURATION
+
+#include <stdint.h>
+
+namespace ignite
+{
+ /**
+ * Single JVM option.
+ */
+ struct IgniteJvmOption
+ {
+ /** Option. */
+ char* opt;
+
+ /**
+ * Default constructor.
+ */
+ IgniteJvmOption() : opt(NULL)
+ {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param opt Option.
+ */
+ IgniteJvmOption(char* opt) : opt(opt)
+ {
+ // No-op.
+ }
+ };
+
+ /**
+ * Ignite configuration.
+ */
+ struct IgniteConfiguration
+ {
+ /** Path to Ignite home. */
+ char* igniteHome;
+
+ /** Path to Spring configuration file. */
+ char* springCfgPath;
+
+ /** Path ot JVM libbrary. */
+ char* jvmLibPath;
+
+ /** JVM classpath. */
+ char* jvmClassPath;
+
+ /** Initial amount of JVM memory. */
+ int32_t jvmInitMem;
+
+ /** Maximum amount of JVM memory. */
+ int32_t jvmMaxMem;
+
+ /** Additional JVM options. */
+ IgniteJvmOption* jvmOpts;
+
+ /** Additional JVM options count. */
+ int32_t jvmOptsLen;
+
+ /**
+ * Constructor.
+ */
+ IgniteConfiguration() : igniteHome(NULL), springCfgPath(NULL), jvmLibPath(NULL), jvmClassPath(NULL),
+ jvmInitMem(512), jvmMaxMem(1024), jvmOpts(NULL), jvmOptsLen(0)
+ {
+ // No-op.
+ }
+ };
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/ignite_error.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/ignite_error.h b/modules/platform/src/main/cpp/core/include/ignite/ignite_error.h
new file mode 100644
index 0000000..4438a0e
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/ignite_error.h
@@ -0,0 +1,260 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_ERROR
+#define _IGNITE_ERROR
+
+#include <sstream>
+#include <stdint.h>
+
+#include <ignite/common/common.h>
+
+#define IGNITE_ERROR_1(code, part1) { \
+ std::stringstream stream; \
+ stream << (part1); \
+ throw ignite::IgniteError(code, stream.str().c_str()); \
+}
+
+#define IGNITE_ERROR_2(code, part1, part2) { \
+ std::stringstream stream; \
+ stream << (part1) << (part2); \
+ throw ignite::IgniteError(code, stream.str().c_str()); \
+}
+
+#define IGNITE_ERROR_3(code, part1, part2, part3) { \
+ std::stringstream stream; \
+ stream << (part1) << (part2) << (part3); \
+ throw ignite::IgniteError(code, stream.str().c_str()); \
+}
+
+#define IGNITE_ERROR_FORMATTED_1(code, msg, key1, val1) { \
+ std::stringstream stream; \
+ stream << msg << " [" << key1 << "=" << (val1) << "]"; \
+ throw ignite::IgniteError(code, stream.str().c_str()); \
+}
+
+#define IGNITE_ERROR_FORMATTED_2(code, msg, key1, val1, key2, val2) { \
+ std::stringstream stream; \
+ stream << msg << " [" << key1 << "=" << (val1) << ", " << key2 << "=" << (val2) << "]"; \
+ throw ignite::IgniteError(code, stream.str().c_str()); \
+}
+
+#define IGNITE_ERROR_FORMATTED_3(code, msg, key1, val1, key2, val2, key3, val3) { \
+ std::stringstream stream; \
+ stream << msg << " [" << key1 << "=" << (val1) << ", " << key2 << "=" << (val2) << ", " << key3 << "=" << (val3) << "]"; \
+ throw ignite::IgniteError(code, stream.str().c_str()); \
+}
+
+#define IGNITE_ERROR_FORMATTED_4(code, msg, key1, val1, key2, val2, key3, val3, key4, val4) { \
+ std::stringstream stream; \
+ stream << msg << " [" << key1 << "=" << (val1) << ", " << key2 << "=" << (val2) << ", " << key3 << "=" << (val3) << ", " << key4 << "=" << (val4) << "]"; \
+ throw ignite::IgniteError(code, stream.str().c_str()); \
+}
+
+namespace ignite
+{
+ /**
+ * Ignite error information.
+ */
+ class IGNITE_IMPORT_EXPORT IgniteError
+ {
+ public:
+ /** Success. */
+ static const int IGNITE_SUCCESS = 0;
+
+ /** Failed to initialize JVM. */
+ static const int IGNITE_ERR_JVM_INIT = 1;
+
+ /** Failed to attach to JVM. */
+ static const int IGNITE_ERR_JVM_ATTACH = 2;
+
+ /** JVM library is not found. */
+ static const int IGNITE_ERR_JVM_LIB_NOT_FOUND = 3;
+
+ /** Failed to load JVM library. */
+ static const int IGNITE_ERR_JVM_LIB_LOAD_FAILED = 4;
+
+ /** JVM classpath is not provided. */
+ static const int IGNITE_ERR_JVM_NO_CLASSPATH = 5;
+
+ /** JVM error: no class definition found. */
+ static const int IGNITE_ERR_JVM_NO_CLASS_DEF_FOUND = 6;
+
+ /** JVM error: no such method. */
+ static const int IGNITE_ERR_JVM_NO_SUCH_METHOD = 7;
+
+ /** Memory operation error. */
+ static const int IGNITE_ERR_MEMORY = 1001;
+
+ /** Portable error. */
+ static const int IGNITE_ERR_PORTABLE = 1002;
+
+ /** Generic Ignite error. */
+ static const int IGNITE_ERR_GENERIC = 2000;
+
+ /** Illegal argument passed. */
+ static const int IGNITE_ERR_ILLEGAL_ARGUMENT = 2001;
+
+ /** Illegal state. */
+ static const int IGNITE_ERR_ILLEGAL_STATE = 2002;
+
+ /** Unsupported operation. */
+ static const int IGNITE_ERR_UNSUPPORTED_OPERATION = 2003;
+
+ /** Thread has been interrup. */
+ static const int IGNITE_ERR_INTERRUPTED = 2004;
+
+ /** Cluster group is empty. */
+ static const int IGNITE_ERR_CLUSTER_GROUP_EMPTY = 2005;
+
+ /** Cluster topology problem. */
+ static const int IGNITE_ERR_CLUSTER_TOPOLOGY = 2006;
+
+ /** Compute execution rejected. */
+ static const int IGNITE_ERR_COMPUTE_EXECUTION_REJECTED = 2007;
+
+ /** Compute job failover. */
+ static const int IGNITE_ERR_COMPUTE_JOB_FAILOVER = 2008;
+
+ /** Compute task cancelled. */
+ static const int IGNITE_ERR_COMPUTE_TASK_CANCELLED = 2009;
+
+ /** Compute task timeout. */
+ static const int IGNITE_ERR_COMPUTE_TASK_TIMEOUT = 2010;
+
+ /** Compute user undeclared exception. */
+ static const int IGNITE_ERR_COMPUTE_USER_UNDECLARED_EXCEPTION = 2011;
+
+ /** Generic cache error. */
+ static const int IGNITE_ERR_CACHE = 2012;
+
+ /** Generic cache loader error. */
+ static const int IGNITE_ERR_CACHE_LOADER = 2013;
+
+ /** Generic cache writer error. */
+ static const int IGNITE_ERR_CACHE_WRITER = 2014;
+
+ /** Generic cache entry processor error. */
+ static const int IGNITE_ERR_ENTRY_PROCESSOR = 2015;
+
+ /** Cache atomic update timeout. */
+ static const int IGNITE_ERR_CACHE_ATOMIC_UPDATE_TIMEOUT = 2016;
+
+ /** Cache partial update. */
+ static const int IGNITE_ERR_CACHE_PARTIAL_UPDATE = 2017;
+
+ /** Transaction optimisitc exception. */
+ static const int IGNITE_ERR_TX_OPTIMISTIC = 2018;
+
+ /** Transaction timeout. */
+ static const int IGNITE_ERR_TX_TIMEOUT = 2019;
+
+ /** Transaction rollback. */
+ static const int IGNITE_ERR_TX_ROLLBACK = 2020;
+
+ /** Transaction heuristic exception. */
+ static const int IGNITE_ERR_TX_HEURISTIC = 2021;
+
+ /** Authentication error. */
+ static const int IGNITE_ERR_AUTHENTICATION = 2022;
+
+ /** Security error. */
+ static const int IGNITE_ERR_SECURITY = 2023;
+
+ /** Unknown error. */
+ static const int IGNITE_ERR_UNKNOWN = -1;
+
+ /**
+ * Throw an error if code is not IGNITE_SUCCESS.
+ *
+ * @param err Error.
+ */
+ static void ThrowIfNeeded(IgniteError& err);
+
+ /**
+ * Create empty error.
+ */
+ IgniteError();
+
+ /**
+ * Create error with specific code.
+ *
+ * @param code Error code.
+ */
+ IgniteError(const int32_t code);
+
+ /**
+ * Create error with specific code and message.
+ *
+ * @param code Error code.
+ * @param msg Message.
+ */
+ IgniteError(const int32_t code, const char* msg);
+
+ /**
+ * Copy constructor.
+ *
+ * @param other Other instance.
+ */
+ IgniteError(const IgniteError& other);
+
+ /**
+ * Assignment operator.
+ *
+ * @param other Other instance.
+ * @return Assignment result.
+ */
+ IgniteError& operator=(const IgniteError& other);
+
+ /**
+ * Destructor.
+ */
+ ~IgniteError();
+
+ /**
+ * Get error code.
+ *
+ * @return Error code.
+ */
+ int32_t GetCode();
+
+ /**
+ * Get error message.
+ *
+ * @return Error message.
+ */
+ const char* GetText();
+
+ /**
+ * Set error.
+ *
+ * @param jniCode Error code.
+ * @param jniCls Error class.
+ * @param jniMsg Error message.
+ * @param err Error.
+ */
+ static void SetError(const int jniCode, const char* jniCls, const char* jniMsg, IgniteError* err);
+ private:
+ /** Error code. */
+ int32_t code;
+
+ /** Error message. */
+ char* msg;
+ };
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/ignition.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/ignition.h b/modules/platform/src/main/cpp/core/include/ignite/ignition.h
new file mode 100644
index 0000000..8d32448
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/ignition.h
@@ -0,0 +1,195 @@
+/*
+ * 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.
+ */
+
+/**
+ * \mainpage Apache Ignite C++ Library
+ *
+ * The Apache Ignite is a proven software solution, which delivers unprecedented speed
+ * and unlimited scale to accelerate your business and time to insights. It enables high-performance transactions,
+ * real-time streaming and fast analytics in a single, comprehensive data access and processing layer. The In-Memory
+ * Data Fabric is designed to easily power both existing and new applications in a distributed, massively
+ * parallel architecture on affordable, industry-standard hardware.
+ * <p>
+ * The Apache Ignite provides a unified API that spans all key types of applications
+ * (Java, .NET, C++) and connects them with multiple data stores containing structured, semi-structured and
+ * unstructured data (SQL, NoSQL, Hadoop). It offers a secure, highly available and manageable data environment
+ * that allows companies to process full ACID transactions and generate valuable insights from real-time,
+ * interactive and batch queries.
+ * <p>
+ * The In-Memory Data Fabric offers a strategic approach to in-memory computing that delivers performance,
+ * scale and comprehensive capabilities far above and beyond what traditional in-memory databases,
+ * data grids or other in-memory-based point solutions can offer by themselves.
+ *
+ * \section ultimate_speed_and_scale Ultimate Speed and Scale
+ *
+ * The Apache Ignite accesses and processes data from distributed enterprise and
+ * cloud-based data stores orders of magnitudes faster, and shares them with today's most demanding transactional,
+ * analytical and hybrid applications. The In-Memory Data Fabric delivers unprecedented throughput
+ * and low latency performance in a virtually unlimited, global scale-out architecture for both new and
+ * existing applications.
+ *
+ * \section comprehensive_and_proven Comprehensive and Proven
+ *
+ * The Apache Ignite is the product of seven years of meticulous research and development,
+ * built from the ground up (i.e. no bolt-on's), and run successfully by hundreds of organizations worldwide.
+ * It is a comprehensive in-memory solution that includes a clustering and compute grid, a database-agnostic data grid,
+ * a real-time streaming engine as well as plug-and-play Hadoop acceleration. The In-Memory Data Fabric
+ * connects multiple data sources (relational, NoSQL, Hadoop) with Java, .NET and C++ applications, and offers
+ * a secure and highly available architecture; it also provides a fully-featured, graphical management interface.
+ * <p>
+ * The Apache Ignite is used today by Fortune 500 companies, top government agencies as well as
+ * innovative mobile and web companies in a broad range of business scenarios, such as automated trading systems,
+ * fraud detection, big data analytics, social networks, online gaming, and bioinformatics.
+ */
+
+#ifndef _IGNITE_IGNITION
+#define _IGNITE_IGNITION
+
+#include "ignite/ignite.h"
+#include "ignite/ignite_configuration.h"
+#include "ignite/ignite_error.h"
+
+namespace ignite
+{
+ /**
+ * This class defines a factory for the main Ignite API.
+ */
+ class IGNITE_IMPORT_EXPORT Ignition
+ {
+ public:
+ /**
+ * Start Ignite instance.
+ *
+ * @param cfg Configuration.
+ * @return Ignite instance or null in case of error.
+ */
+ static Ignite Start(const IgniteConfiguration& cfg);
+
+ /*
+ * Start Ignite instance.
+ *
+ * @param cfg Configuration.
+ * @param err Error.
+ * @return Ignite instance or null in case of error.
+ */
+ static Ignite Start(const IgniteConfiguration& cfg, IgniteError* err);
+
+ /**
+ * Start Ignite instance with specific name.
+ *
+ * @param cfg Configuration.
+ * @param name Ignite name.
+ * @return Ignite instance or null in case of error.
+ */
+ static Ignite Start(const IgniteConfiguration& cfg, const char* name);
+
+ /**
+ * Start Ignite instance with specific name.
+ *
+ * @param cfg Configuration.
+ * @param name Ignite name.
+ * @param err Error.
+ * @return Ignite instance or null in case of error.
+ */
+ static Ignite Start(const IgniteConfiguration& cfg, const char* name, IgniteError* err);
+
+ /**
+ * Get default Ignite instance.
+ *
+ * @return Default Ignite instance.
+ */
+ static Ignite Get();
+
+ /**
+ * Get default Ignite instance.
+ *
+ * @param err Error.
+ * @return Default Ignite instance.
+ */
+ static Ignite Get(IgniteError* err);
+
+ /**
+ * Get Ignite instance with the given name.
+ *
+ * @param name Ignite name.
+ * @return Ignite instance.
+ */
+ static Ignite Get(const char* name);
+
+ /**
+ * Get Ignite instance with the given name.
+ *
+ * @param name Ignite name.
+ * @param err Error.
+ * @return Ignite instance.
+ */
+ static Ignite Get(const char* name, IgniteError* err);
+
+ /**
+ * Stop default Ignite instance.
+ *
+ * @param cancel Cancel flag.
+ * @return True if default Ignite instance was stopped by this call.
+ */
+ static bool Stop(const bool cancel);
+
+ /**
+ * Stop default Ignite instance.
+ *
+ * @param cancel Cancel flag.
+ * @param err Error.
+ * @return True if Ignite instance was stopped by this call.
+ */
+ static bool Stop(const bool cancel, IgniteError* err);
+
+ /**
+ * Stop Ignite instance with the given name.
+ *
+ * @param name Ignite name.
+ * @param cancel Cancel flag.
+ * @return True if Ignite instance was stopped by this call.
+ */
+ static bool Stop(const char* name, const bool cancel);
+
+ /**
+ * Stop Ignite instance with the given name.
+ *
+ * @param name Ignite name.
+ * @param cancel Cancel flag.
+ * @param err Error.
+ * @return True if Ignite instance was stopped by this call.
+ */
+ static bool Stop(const char* name, const bool cancel, IgniteError* err);
+
+ /**
+ * Stop all running Ignite instances.
+ *
+ * @param cancel Cancel flag.
+ */
+ static void StopAll(const bool cancel);
+
+ /**
+ * Stop all running Ignite instances.
+ *
+ * @param cancel Cancel flag.
+ * @param err Error.
+ */
+ static void StopAll(const bool cancel, IgniteError* err);
+ };
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/cache/cache_impl.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/cache/cache_impl.h b/modules/platform/src/main/cpp/core/include/ignite/impl/cache/cache_impl.h
new file mode 100644
index 0000000..8c744e0
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/cache/cache_impl.h
@@ -0,0 +1,418 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_CACHE_IMPL
+#define _IGNITE_CACHE_IMPL
+
+#include "ignite/cache/query/query_scan.h"
+#include "ignite/cache/query/query_sql.h"
+#include "ignite/cache/query/query_text.h"
+#include "ignite/impl/ignite_environment.h"
+#include "ignite/impl/cache/query/query_impl.h"
+#include "ignite/impl/operations.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace cache
+ {
+ /**
+ * Cache implementation.
+ */
+ class IGNITE_IMPORT_EXPORT CacheImpl
+ {
+ public:
+ /**
+ * Constructor used to create new instance.
+ *
+ * @param name Name.
+ * @param env Environment.
+ * @param javaRef Reference to java object.
+ */
+ CacheImpl(char* name, ignite::common::concurrent::SharedPointer<IgniteEnvironment> env, jobject javaRef);
+
+ /**
+ * Destructor.
+ */
+ ~CacheImpl();
+
+ /**
+ * Get name.
+ *
+ * @return Cache name.
+ */
+ char* GetName();
+
+ /**
+ * Perform IsEmpty.
+ *
+ * @param err Error.
+ * @return Result.
+ */
+ bool IsEmpty(IgniteError* err);
+
+ /**
+ * Perform ContainsKey.
+ *
+ * @param inOp Input.
+ * @param err Error.
+ * @return Result.
+ */
+ bool ContainsKey(InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Perform ContainsKeys.
+ *
+ * @param inOp Input.
+ * @param err Error.
+ * @return Result.
+ */
+ bool ContainsKeys(InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Perform LocalPeek.
+ *
+ * @param inOp Input.
+ * @param outOp Output.
+ * @param peekModes Peek modes.
+ * @param err Error.
+ */
+ void LocalPeek(InputOperation& inOp, OutputOperation& outOp,
+ int32_t peekModes, IgniteError* err);
+
+ /**
+ * Perform Get.
+ *
+ * @param inOp Input.
+ * @param outOp Output.
+ * @param err Error.
+ */
+ void Get(InputOperation& inOp, OutputOperation& outOp, IgniteError* err);
+
+ /**
+ * Perform GetAll.
+ *
+ * @param inOp Input.
+ * @param outOp Output.
+ * @param err Error.
+ */
+ void GetAll(InputOperation& inOp, OutputOperation& outOp, IgniteError* err);
+
+ /**
+ * Perform Put.
+ *
+ * @param inOp Input.
+ * @param err Error.
+ */
+ void Put(InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Perform PutAll.
+ *
+ * @param inOp Input.
+ * @param err Error.
+ */
+ void PutAll(InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Perform GetAndPut.
+ *
+ * @param inOp Input.
+ * @param outOp Output.
+ * @param err Error.
+ */
+ void GetAndPut(InputOperation& inOp, OutputOperation& outOp, IgniteError* err);
+
+ /**
+ * Perform GetAndReplace.
+ *
+ * @param inOp Input.
+ * @param outOp Output.
+ * @param err Error.
+ */
+ void GetAndReplace(InputOperation& inOp, OutputOperation& outOp, IgniteError* err);
+
+ /**
+ * Perform GetAndRemove.
+ *
+ * @param inOp Input.
+ * @param outOp Output.
+ * @param err Error.
+ */
+ void GetAndRemove(InputOperation& inOp, OutputOperation& outOp, IgniteError* err);
+
+ /**
+ * Perform PutIfAbsent.
+ *
+ * @param inOp Input.
+ * @param err Error.
+ * @return Result
+ */
+ bool PutIfAbsent(InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Perform GetAndPutIfAbsent.
+ *
+ * @param inOp Input.
+ * @param outOp Output.
+ * @param err Error.
+ */
+ void GetAndPutIfAbsent(InputOperation& inOp, OutputOperation& outOp, IgniteError* err);
+
+ /**
+ * Perform Replace(K, V).
+ *
+ * @param inOp Input.
+ * @param err Error.
+ * @return Result
+ */
+ bool Replace(InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Perform Replace(K, V, V).
+ *
+ * @param inOp Input.
+ * @param err Error.
+ * @return Result
+ */
+ bool ReplaceIfEqual(InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Perform LocalEvict.
+ *
+ * @param inOp Input.
+ * @param err Error.
+ */
+ void LocalEvict(InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Perform Clear.
+ *
+ * @param err Error.
+ */
+ void Clear(IgniteError* err);
+
+ /**
+ * Perform Clear.
+ *
+ * @param inOp Input.
+ * @param err Error.
+ */
+ void Clear(InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Perform ClearAll.
+ *
+ * @param inOp Input.
+ * @param err Error.
+ */
+ void ClearAll(InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Perform LocalClear.
+ *
+ * @param inOp Input.
+ * @param err Error.
+ */
+ void LocalClear(InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Perform LocalClearAll.
+ *
+ * @param inOp Input.
+ * @param err Error.
+ */
+ void LocalClearAll(InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Perform Remove(K).
+ *
+ * @param inOp Input.
+ * @param err Error.
+ * @return Result
+ */
+ bool Remove(InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Perform Remove(K, V).
+ *
+ * @param inOp Input.
+ * @param err Error.
+ * @return Result
+ */
+ bool RemoveIfEqual(InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Perform RemoveAll.
+ *
+ * @param inOp Input.
+ * @param err Error.
+ */
+ void RemoveAll(InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Perform RemoveAll.
+ *
+ * @param err Error.
+ */
+ void RemoveAll(IgniteError* err);
+
+ /**
+ * Perform Size.
+ *
+ * @param peekModes Peek modes.
+ * @param err Error.
+ * @return Result.
+ */
+ int32_t Size(const int32_t peekModes, IgniteError* err);
+
+ /**
+ * Perform LocalSize.
+ *
+ * @param peekModes Peek modes.
+ * @param err Error.
+ * @return Result.
+ */
+ int32_t LocalSize(const int32_t peekModes, IgniteError* err);
+
+ /**
+ * Invoke query.
+ *
+ * @param qry Query.
+ * @param err Error.
+ * @return Query cursor.
+ */
+ query::QueryCursorImpl* QuerySql(const ignite::cache::query::SqlQuery& qry, IgniteError* err);
+
+ /*
+ * Invoke text query.
+ *
+ * @param qry Query.
+ * @param err Error.
+ * @return Query cursor.
+ */
+ query::QueryCursorImpl* QueryText(const ignite::cache::query::TextQuery& qry, IgniteError* err);
+
+ /*
+ * Invoke scan query.
+ *
+ * @param qry Query.
+ * @param err Error.
+ * @return Query cursor.
+ */
+ query::QueryCursorImpl* QueryScan(const ignite::cache::query::ScanQuery& qry, IgniteError* err);
+
+ private:
+ /** Name. */
+ char* name;
+
+ /** Environment. */
+ ignite::common::concurrent::SharedPointer<IgniteEnvironment> env;
+
+ /** Handle to Java object. */
+ jobject javaRef;
+
+ IGNITE_NO_COPY_ASSIGNMENT(CacheImpl)
+
+ /**
+ * Write data to memory.
+ *
+ * @param mem Memory.
+ * @param inOp Input opeartion.
+ * @param err Error.
+ * @return Memory pointer.
+ */
+ int64_t WriteTo(interop::InteropMemory* mem, InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Read data from memory.
+ *
+ * @param mem Memory.
+ * @param outOp Output operation.
+ */
+ void ReadFrom(interop::InteropMemory* mem, OutputOperation& outOp);
+
+ /**
+ * Internal cache size routine.
+ *
+ * @param peekModes Peek modes.
+ * @param loc Local flag.
+ * @param err Error.
+ * @return Size.
+ */
+ int SizeInternal(const int32_t peekModes, const bool loc, IgniteError* err);
+
+ /**
+ * Internal out operation.
+ *
+ * @param opType Operation type.
+ * @param inOp Input.
+ * @param err Error.
+ * @return Result.
+ */
+ bool OutOpInternal(const int32_t opType, InputOperation& inOp, IgniteError* err);
+
+ /**
+ * Internal out-in operation.
+ *
+ * @param opType Operation type.
+ * @param inOp Input.
+ * @param outOp Output.
+ * @param err Error.
+ */
+ void OutInOpInternal(const int32_t opType, InputOperation& inOp, OutputOperation& outOp,
+ IgniteError* err);
+
+ /**
+ * Internal query execution routine.
+ *
+ * @param qry Query.
+ * @param typ Query type.
+ * @param err Error.
+ */
+ template<typename T>
+ query::QueryCursorImpl* QueryInternal(const T& qry, int32_t typ, IgniteError* err)
+ {
+ ignite::common::java::JniErrorInfo jniErr;
+
+ ignite::common::concurrent::SharedPointer<interop::InteropMemory> mem = env.Get()->AllocateMemory();
+ interop::InteropMemory* mem0 = mem.Get();
+ interop::InteropOutputStream out(mem0);
+ portable::PortableWriterImpl writer(&out, env.Get()->GetMetadataManager());
+ ignite::portable::PortableRawWriter rawWriter(&writer);
+
+ qry.Write(rawWriter);
+
+ out.Synchronize();
+
+ jobject qryJavaRef = env.Get()->Context()->CacheOutOpQueryCursor(javaRef, typ, mem.Get()->PointerLong(),
+ &jniErr);
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ if (jniErr.code == ignite::common::java::IGNITE_JNI_ERR_SUCCESS)
+ return new query::QueryCursorImpl(env, qryJavaRef);
+ else
+ return NULL;
+ }
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/cache/query/query_impl.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/cache/query/query_impl.h b/modules/platform/src/main/cpp/core/include/ignite/impl/cache/query/query_impl.h
new file mode 100644
index 0000000..e65eeb6
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/cache/query/query_impl.h
@@ -0,0 +1,115 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_CACHE_QUERY_IMPL
+#define _IGNITE_CACHE_QUERY_IMPL
+
+#include "ignite/ignite_error.h"
+#include "ignite/impl/ignite_environment.h"
+#include "ignite/impl/operations.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace cache
+ {
+ namespace query
+ {
+ /**
+ * Query cursor implementation.
+ */
+ class IGNITE_IMPORT_EXPORT QueryCursorImpl
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param env Environment.
+ * @param javaRef Java reference.
+ */
+ QueryCursorImpl(ignite::common::concurrent::SharedPointer<IgniteEnvironment> env, jobject javaRef);
+
+ /**
+ * Destructor.
+ */
+ ~QueryCursorImpl();
+
+ /**
+ * Check whether next result exists.
+ *
+ * @param err Error.
+ * @return True if exists.
+ */
+ bool HasNext(IgniteError* err);
+
+ /**
+ * Get next object.
+ *
+ * @param op Operation.
+ * @param err Error.
+ */
+ void GetNext(OutputOperation& op, IgniteError* err);
+
+ /**
+ * Get all cursor entries.
+ *
+ * @param op Operation.
+ * @param err Error.
+ */
+ void GetAll(OutputOperation& op, IgniteError* err);
+
+ private:
+ /** Environment. */
+ ignite::common::concurrent::SharedPointer<impl::IgniteEnvironment> env;
+
+ /** Handle to Java object. */
+ jobject javaRef;
+
+ /** Whether iteration methods were called. */
+ bool iterCalled;
+
+ /** Whether GetAll() method was called. */
+ bool getAllCalled;
+
+ /** Whether next entry is available. */
+ bool hasNext;
+
+ IGNITE_NO_COPY_ASSIGNMENT(QueryCursorImpl);
+
+ /**
+ * Create Java-side iterator if needed.
+ *
+ * @param err Error.
+ * @return True in case of success, false if an error is thrown.
+ */
+ bool CreateIteratorIfNeeded(IgniteError* err);
+
+ /**
+ * Check whether Java-side iterator has next element.
+ *
+ * @param err Error.
+ * @return True if the next element is available.
+ */
+ bool IteratorHasNext(IgniteError* err);
+ };
+ }
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/handle_registry.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/handle_registry.h b/modules/platform/src/main/cpp/core/include/ignite/impl/handle_registry.h
new file mode 100644
index 0000000..5e1b60a
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/handle_registry.h
@@ -0,0 +1,202 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_HANDLE_REGISTRY
+#define _IGNITE_HANDLE_REGISTRY
+
+#include <map>
+#include <stdint.h>
+
+#include <ignite/common/concurrent.h>
+
+namespace ignite
+{
+ namespace impl
+ {
+ /**
+ * Something what can be registered inside handle registry.
+ */
+ class IGNITE_IMPORT_EXPORT HandleRegistryEntry
+ {
+ public:
+ /**
+ * Destructor.
+ */
+ virtual ~HandleRegistryEntry();
+ };
+
+ /**
+ * Handle registry segment containing thread-specific data for slow-path access.
+ */
+ class IGNITE_IMPORT_EXPORT HandleRegistrySegment
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ HandleRegistrySegment();
+
+ /**
+ * Destructor.
+ */
+ ~HandleRegistrySegment();
+
+ /**
+ * Get entry from segment.
+ *
+ * @param hnd Handle.
+ * @return Associated entry or NULL if it doesn't exists.
+ */
+ ignite::common::concurrent::SharedPointer<HandleRegistryEntry> Get(int64_t hnd);
+
+ /**
+ * Put entry into segment.
+ *
+ * @param hnd Handle.
+ * @param entry Associated entry (cannot be NULL).
+ */
+ void Put(int64_t hnd, const ignite::common::concurrent::SharedPointer<HandleRegistryEntry>& entry);
+
+ /**
+ * Remove entry from the segment.
+ *
+ * @param hnd Handle.
+ */
+ void Remove(int64_t hnd);
+
+ /**
+ * Clear all entries from the segment.
+ */
+ void Clear();
+ private:
+ /** Map with data. */
+ std::map<int64_t, ignite::common::concurrent::SharedPointer<HandleRegistryEntry>>* map;
+
+ /** Mutex. */
+ ignite::common::concurrent::CriticalSection* mux;
+
+ IGNITE_NO_COPY_ASSIGNMENT(HandleRegistrySegment);
+ };
+
+ /**
+ * Handle registry.
+ */
+ class IGNITE_IMPORT_EXPORT HandleRegistry
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param fastCap Fast-path capacity.
+ * @param segmentCnt Slow-path segments count.
+ */
+ HandleRegistry(int32_t fastCap, int32_t slowSegmentCnt);
+
+ /**
+ * Destructor.
+ */
+ ~HandleRegistry();
+
+ /**
+ * Allocate handle.
+ *
+ * @param target Target.
+ * @return Handle.
+ */
+ int64_t Allocate(const ignite::common::concurrent::SharedPointer<HandleRegistryEntry>& target);
+
+ /**
+ * Allocate handle in critical mode.
+ *
+ * @param target Target.
+ * @return Handle.
+ */
+ int64_t AllocateCritical(const ignite::common::concurrent::SharedPointer<HandleRegistryEntry>& target);
+
+ /**
+ * Allocate handle in safe mode.
+ *
+ * @param target Target.
+ * @return Handle.
+ */
+ int64_t AllocateSafe(const ignite::common::concurrent::SharedPointer<HandleRegistryEntry>& target);
+
+ /**
+ * Allocate handle in critical and safe modes.
+ *
+ * @param target Target.
+ * @return Handle.
+ */
+ int64_t AllocateCriticalSafe(const ignite::common::concurrent::SharedPointer<HandleRegistryEntry>& target);
+
+ /**
+ * Release handle.
+ *
+ * @param hnd Handle.
+ */
+ void Release(int64_t hnd);
+
+ /**
+ * Get target.
+ *
+ * @param hnd Handle.
+ * @param Target.
+ */
+ ignite::common::concurrent::SharedPointer<HandleRegistryEntry> Get(int64_t hnd);
+
+ /**
+ * Close the registry.
+ */
+ void Close();
+ private:
+ /** Fast-path container capacity. */
+ int32_t fastCap;
+
+ /** Fast-path counter. */
+ int32_t fastCtr;
+
+ /** Fast-path container. */
+ ignite::common::concurrent::SharedPointer<HandleRegistryEntry>* fast;
+
+ /** Amount of slow-path segments. */
+ int32_t slowSegmentCnt;
+
+ /** Slow-path counter. */
+ int64_t slowCtr;
+
+ /** Slow-path segments. */
+ HandleRegistrySegment** slow;
+
+ /** Close flag. */
+ int32_t closed;
+
+ IGNITE_NO_COPY_ASSIGNMENT(HandleRegistry);
+
+ /**
+ * Internal allocation routine.
+ *
+ * @param target Target.
+ * @param Critical mode flag.
+ * @param Safe mode flag.
+ */
+ int64_t Allocate0(const ignite::common::concurrent::SharedPointer<HandleRegistryEntry>& target,
+ bool critical, bool safe);
+ };
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/ignite_environment.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/ignite_environment.h b/modules/platform/src/main/cpp/core/include/ignite/impl/ignite_environment.h
new file mode 100644
index 0000000..2f195b2
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/ignite_environment.h
@@ -0,0 +1,130 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_ENVIRONMENT
+#define _IGNITE_ENVIRONMENT
+
+#include <ignite/common/concurrent.h>
+#include <ignite/common/java.h>
+
+#include "ignite/impl/interop/interop_memory.h"
+#include "portable/portable_metadata_manager.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ /**
+ * Defines environment in which Ignite operates.
+ */
+ class IGNITE_IMPORT_EXPORT IgniteEnvironment
+ {
+ public:
+ /**
+ * Default constructor.
+ */
+ IgniteEnvironment();
+
+ /**
+ * Destructor.
+ */
+ ~IgniteEnvironment();
+
+ /**
+ * Populate callback handlers.
+ *
+ * @param Target (current env wrapped into a shared pointer).
+ * @return JNI handlers.
+ */
+ ignite::common::java::JniHandlers GetJniHandlers(ignite::common::concurrent::SharedPointer<IgniteEnvironment>* target);
+
+ /**
+ * Perform initialization on successful start.
+ *
+ * @param ctx Context.
+ */
+ void Initialize(ignite::common::concurrent::SharedPointer<ignite::common::java::JniContext> ctx);
+
+ /**
+ * Start callback.
+ *
+ * @param memPtr Memory pointer.
+ */
+ void OnStartCallback(long long memPtr);
+
+ /**
+ * Get name of Ignite instance.
+ *
+ * @return Name.
+ */
+ char* InstanceName();
+
+ /**
+ * Get JNI context.
+ *
+ * @return Context.
+ */
+ ignite::common::java::JniContext* Context();
+
+ /**
+ * Get memory for interop operations.
+ *
+ * @return Memory.
+ */
+ ignite::common::concurrent::SharedPointer<interop::InteropMemory> AllocateMemory();
+
+ /**
+ * Get memory chunk for interop operations with desired capacity.
+ *
+ * @param cap Capacity.
+ * @return Memory.
+ */
+ ignite::common::concurrent::SharedPointer<interop::InteropMemory> AllocateMemory(int32_t cap);
+
+ /**
+ * Get memory chunk located at the given pointer.
+ *
+ * @param memPtr Memory pointer.
+ * @retrun Memory.
+ */
+ ignite::common::concurrent::SharedPointer<interop::InteropMemory> GetMemory(int64_t memPtr);
+
+ /**
+ * Get metadata manager.
+ *
+ * @param Metadata manager.
+ */
+ portable::PortableMetadataManager* GetMetadataManager();
+ private:
+ /** Context to access Java. */
+ ignite::common::concurrent::SharedPointer<ignite::common::java::JniContext> ctx;
+
+ /** Startup latch. */
+ ignite::common::concurrent::SingleLatch* latch;
+
+ /** Ignite name. */
+ char* name;
+
+ /** Metadata manager. */
+ portable::PortableMetadataManager* metaMgr;
+
+ IGNITE_NO_COPY_ASSIGNMENT(IgniteEnvironment);
+ };
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/ignite_impl.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/ignite_impl.h b/modules/platform/src/main/cpp/core/include/ignite/impl/ignite_impl.h
new file mode 100644
index 0000000..52472c6
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/ignite_impl.h
@@ -0,0 +1,146 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL
+#define _IGNITE_IMPL
+
+#include <ignite/common/concurrent.h>
+#include <ignite/common/java.h>
+
+#include "ignite/impl/cache/cache_impl.h"
+#include "ignite/impl/ignite_environment.h"
+#include "ignite/impl/utils.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ /**
+ * Ignite implementation.
+ */
+ class IgniteImpl
+ {
+ friend class Ignite;
+ public:
+ /**
+ * Constructor used to create new instance.
+ *
+ * @param env Environment.
+ * @param javaRef Reference to java object.
+ */
+ IgniteImpl(ignite::common::concurrent::SharedPointer<IgniteEnvironment> env, jobject javaRef);
+
+ /**
+ * Destructor.
+ */
+ ~IgniteImpl();
+
+ /**
+ * Get name of the Ignite.
+ *
+ * @param Name.
+ */
+ char* GetName();
+
+ /**
+ * Get cache.
+ *
+ * @param name Cache name.
+ * @param err Error.
+ */
+ template<typename K, typename V>
+ cache::CacheImpl* GetCache(const char* name, IgniteError* err)
+ {
+ ignite::common::java::JniErrorInfo jniErr;
+
+ jobject cacheJavaRef = env.Get()->Context()->ProcessorCache(javaRef, name, &jniErr);
+
+ if (!cacheJavaRef)
+ {
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ return NULL;
+ }
+
+ char* name0 = utils::CopyChars(name);
+
+ return new cache::CacheImpl(name0, env, cacheJavaRef);
+ }
+
+ /**
+ * Get or create cache.
+ *
+ * @param name Cache name.
+ * @param err Error.
+ */
+ template<typename K, typename V>
+ cache::CacheImpl* GetOrCreateCache(const char* name, IgniteError* err)
+ {
+ ignite::common::java::JniErrorInfo jniErr;
+
+ jobject cacheJavaRef = env.Get()->Context()->ProcessorGetOrCreateCache(javaRef, name, &jniErr);
+
+ if (!cacheJavaRef)
+ {
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ return NULL;
+ }
+
+ char* name0 = utils::CopyChars(name);
+
+ return new cache::CacheImpl(name0, env, cacheJavaRef);
+ }
+
+ /**
+ * Create cache.
+ *
+ * @param name Cache name.
+ * @param err Error.
+ */
+ template<typename K, typename V>
+ cache::CacheImpl* CreateCache(const char* name, IgniteError* err)
+ {
+ ignite::common::java::JniErrorInfo jniErr;
+
+ jobject cacheJavaRef = env.Get()->Context()->ProcessorCreateCache(javaRef, name, &jniErr);
+
+ if (!cacheJavaRef)
+ {
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ return NULL;
+ }
+
+ char* name0 = utils::CopyChars(name);
+
+ return new cache::CacheImpl(name0, env, cacheJavaRef);
+ }
+ private:
+ /** Environment. */
+ ignite::common::concurrent::SharedPointer<IgniteEnvironment> env;
+
+ /** Native Java counterpart. */
+ jobject javaRef;
+
+ IGNITE_NO_COPY_ASSIGNMENT(IgniteImpl)
+ };
+ }
+
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop.h b/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop.h
new file mode 100644
index 0000000..da4fdb9
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop.h
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL_INTEROP
+#define _IGNITE_IMPL_INTEROP
+
+#include "ignite/impl/interop/interop_memory.h"
+#include "ignite/impl/interop/interop_output_stream.h"
+#include "ignite/impl/interop/interop_input_stream.h"
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop_input_stream.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop_input_stream.h b/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop_input_stream.h
new file mode 100644
index 0000000..d8fcfc3
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop_input_stream.h
@@ -0,0 +1,234 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL_INTEROP_INPUT_STREAM
+#define _IGNITE_IMPL_INTEROP_INPUT_STREAM
+
+#include "ignite/impl/interop/interop_memory.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace interop
+ {
+ /**
+ * Interop input stream implementation.
+ */
+ class IGNITE_IMPORT_EXPORT InteropInputStream {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param mem Memory.
+ */
+ InteropInputStream(InteropMemory* mem);
+
+ /**
+ * Read signed 8-byte int.
+ *
+ * @return Value.
+ */
+ int8_t ReadInt8();
+
+ /**
+ * Read signed 8-byte int array.
+ *
+ * @param res Allocated array.
+ * @param len Length.
+ */
+ void ReadInt8Array(int8_t* const res, const int32_t len);
+
+ /**
+ * Read bool.
+ *
+ * @return Value.
+ */
+ bool ReadBool();
+
+ /**
+ * Read bool array.
+ *
+ * @param res Allocated array.
+ * @param len Length.
+ */
+ void ReadBoolArray(bool* const res, const int32_t len);
+
+ /**
+ * Read signed 16-byte int.
+ *
+ * @return Value.
+ */
+ int16_t ReadInt16();
+
+ /**
+ * Read signed 16-byte int array.
+ *
+ * @param res Allocated array.
+ * @param len Length.
+ */
+ void ReadInt16Array(int16_t* const res, const int32_t len);
+
+ /**
+ * Read unsigned 16-byte int.
+ *
+ * @return Value.
+ */
+ uint16_t ReadUInt16();
+
+ /**
+ * Read unsigned 16-byte int array.
+ *
+ * @param res Allocated array.
+ * @param len Length.
+ */
+ void ReadUInt16Array(uint16_t* const res, const int32_t len);
+
+ /**
+ * Read signed 32-byte int.
+ *
+ * @return Value.
+ */
+ int32_t ReadInt32();
+
+ /**
+ * Read signed 32-byte int at the given position.
+ *
+ * @param pos Position.
+ * @return Value.
+ */
+ int32_t ReadInt32(int32_t pos);
+
+ /**
+ * Read signed 32-byte int array.
+ *
+ * @param res Allocated array.
+ * @param len Length.
+ */
+ void ReadInt32Array(int32_t* const res, const int32_t len);
+
+ /**
+ * Read signed 64-byte int.
+ *
+ * @return Value.
+ */
+ int64_t ReadInt64();
+
+ /**
+ * Read signed 64-byte int array.
+ *
+ * @param res Allocated array.
+ * @param len Length.
+ */
+ void ReadInt64Array(int64_t* const res, const int32_t len);
+
+ /**
+ * Read float.
+ *
+ * @return Value.
+ */
+ float ReadFloat();
+
+ /**
+ * Read float array.
+ *
+ * @param res Allocated array.
+ * @param len Length.
+ */
+ void ReadFloatArray(float* const res, const int32_t len);
+
+ /**
+ * Read double.
+ *
+ * @return Value.
+ */
+ double ReadDouble();
+
+ /**
+ * Read double array.
+ *
+ * @param res Allocated array.
+ * @param len Length.
+ */
+ void ReadDoubleArray(double* const res, const int32_t len);
+
+ /**
+ * Get remaining bytes.
+ *
+ * @return Remaining bytes.
+ */
+ int32_t Remaining();
+
+ /**
+ * Get position.
+ *
+ * @return Position.
+ */
+ int32_t Position();
+
+ /**
+ * Set position.
+ *
+ * @param Position.
+ */
+ void Position(int32_t pos);
+
+ /**
+ * Synchronize data from underlying memory.
+ */
+ void Synchronize();
+ private:
+ /** Memory. */
+ InteropMemory* mem;
+
+ /** Pointer to data. */
+ int8_t* data;
+
+ /** Length. */
+ int len;
+
+ /** Current position. */
+ int pos;
+
+ /**
+ * Ensure there is enough data in the stream.
+ *
+ * @param cnt Amount of byte expected to be available.
+ */
+ void EnsureEnoughData(int32_t cnt);
+
+ /**
+ * Copy data from the stream shifting it along the way.
+ *
+ * @param ptr Pointer to data.
+ * @param off Offset.
+ * @param cnt Amount of data to copy.
+ */
+ void CopyAndShift(int8_t* dest, int32_t off, int32_t cnt);
+
+ /**
+ * Shift stream to the right.
+ *
+ * @param cnt Amount of bytes to shift the stream to.
+ */
+ void Shift(int32_t cnt);
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop_memory.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop_memory.h b/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop_memory.h
new file mode 100644
index 0000000..00cba43
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop_memory.h
@@ -0,0 +1,280 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL_INTEROP_MEMORY
+#define _IGNITE_IMPL_INTEROP_MEMORY
+
+#include <stdint.h>
+
+#include <ignite/common/common.h>
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace interop
+ {
+ /** Memory header length. */
+ const int IGNITE_MEM_HDR_LEN = 20;
+
+ /** Memory header offset: capacity. */
+ const int IGNITE_MEM_HDR_OFF_CAP = 8;
+
+ /** Memory header offset: length. */
+ const int IGNITE_MEM_HDR_OFF_LEN = 12;
+
+ /** Memory header offset: flags. */
+ const int IGNITE_MEM_HDR_OFF_FLAGS = 16;
+
+ /** Flag: external. */
+ const int IGNITE_MEM_FLAG_EXT = 0x1;
+
+ /** Flag: pooled. */
+ const int IGNITE_MEM_FLAG_POOLED = 0x2;
+
+ /** Flag: acquired. */
+ const int IGNITE_MEM_FLAG_ACQUIRED = 0x4;
+
+ /**
+ * Interop memory.
+ */
+ class IGNITE_IMPORT_EXPORT InteropMemory
+ {
+ public:
+ /**
+ * Get raw data pointer.
+ *
+ * @param memPtr Memory pointer.
+ * @return Raw data pointer.
+ */
+ static int8_t* Data(int8_t* memPtr);
+
+ /**
+ * Set raw data pointer.
+ *
+ * @param memPtr Memory pointer.
+ * @param ptr Raw data pointer.
+ */
+ static void Data(int8_t* memPtr, void* ptr);
+
+ /**
+ * Get capacity.
+ *
+ * @param memPtr Memory pointer.
+ * @return Capacity.
+ */
+ static int32_t Capacity(int8_t* memPtr);
+
+ /**
+ * Set capacity.
+ *
+ * @param memPtr Memory pointer.
+ * @param val Value.
+ */
+ static void Capacity(int8_t* memPtr, int32_t val);
+
+ /**
+ * Get length.
+ *
+ * @param memPtr Memory pointer.
+ * @return Length.
+ */
+ static int32_t Length(int8_t* memPtr);
+
+ /**
+ * Set length.
+ *
+ * @param memPtr Memory pointer.
+ * @param val Value.
+ */
+ static void Length(int8_t* memPtr, int32_t val);
+
+ /**
+ * Get flags.
+ *
+ * @param memPtr Memory pointer.
+ * @return Flags.
+ */
+ static int32_t Flags(int8_t* memPtr);
+
+ /**
+ * Set flags.
+ *
+ * @param memPtr Memory pointer.
+ * @param val Value.
+ */
+ static void Flags(int8_t* memPtr, int32_t val);
+
+ /**
+ * Get "external" flag state.
+ *
+ * @param memPtr Memory pointer.
+ * @return Flag state.
+ */
+ static bool IsExternal(int8_t* memPtr);
+
+ /**
+ * Get "external" flag state.
+ *
+ * @param flags Flags.
+ * @return Flag state.
+ */
+ static bool IsExternal(int32_t flags);
+
+ /**
+ * Get "pooled" flag state.
+ *
+ * @param memPtr Memory pointer.
+ * @return Flag state.
+ */
+ static bool IsPooled(int8_t* memPtr);
+
+ /**
+ * Get "pooled" flag state.
+ *
+ * @param flags Flags.
+ * @return Flag state.
+ */
+ static bool IsPooled(int32_t flags);
+
+ /**
+ * Get "acquired" flag state.
+ *
+ * @param memPtr Memory pointer.
+ * @return Flag state.
+ */
+ static bool IsAcquired(int8_t* memPtr);
+
+ /**
+ * Get "acquired" flag state.
+ *
+ * @param flags Flags.
+ * @return Flag state.
+ */
+ static bool IsAcquired(int32_t flags);
+
+ /**
+ * Destructor.
+ */
+ virtual ~InteropMemory() { }
+
+ /**
+ * Get cross-platform memory pointer.
+ *
+ * @return Memory pointer.
+ */
+ int8_t* Pointer();
+
+ /**
+ * Get cross-platform pointer in long form.
+ */
+ int64_t PointerLong();
+
+ /**
+ * Get raw data pointer.
+ *
+ * @return Data pointer.
+ */
+ int8_t* Data();
+
+ /**
+ * Get capacity.
+ *
+ * @return Capacity.
+ */
+ int32_t Capacity();
+
+ /**
+ * Get length.
+ *
+ * @return Length.
+ */
+ int32_t Length();
+
+ /**
+ * Set length.
+ *
+ * @param val Length.
+ */
+ void Length(int32_t val);
+
+ /**
+ * Reallocate memory.
+ *
+ * @param cap Desired capactiy.
+ */
+ virtual void Reallocate(int32_t cap) = 0;
+ protected:
+ /** Memory pointer. */
+ int8_t* memPtr;
+ };
+
+ /**
+ * Interop unpooled memory.
+ */
+ class IGNITE_IMPORT_EXPORT InteropUnpooledMemory : public InteropMemory
+ {
+ public:
+ /**
+ * Constructor create new unpooled memory object from scratch.
+ *
+ * @param cap Capacity.
+ */
+ explicit InteropUnpooledMemory(int32_t cap);
+
+ /**
+ * Constructor creating unpooled memory object from existing memory pointer.
+ *
+ * @param memPtr Memory pointer.
+ */
+ explicit InteropUnpooledMemory(int8_t* memPtr);
+
+ /**
+ * Destructor.
+ */
+ ~InteropUnpooledMemory();
+
+ virtual void Reallocate(int32_t cap);
+ private:
+ /** Whether this instance is owner of memory chunk. */
+ bool owning;
+
+ IGNITE_NO_COPY_ASSIGNMENT(InteropUnpooledMemory)
+ };
+
+ /**
+ * Interop external memory.
+ */
+ class IGNITE_IMPORT_EXPORT InteropExternalMemory : public InteropMemory
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param memPtr External memory pointer.
+ */
+ explicit InteropExternalMemory(int8_t* memPtr);
+
+ virtual void Reallocate(int32_t cap);
+ private:
+ IGNITE_NO_COPY_ASSIGNMENT(InteropExternalMemory)
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop_output_stream.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop_output_stream.h b/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop_output_stream.h
new file mode 100644
index 0000000..5a08aed
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/interop/interop_output_stream.h
@@ -0,0 +1,234 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL_INTEROP_OUTPUT_STREAM
+#define _IGNITE_IMPL_INTEROP_OUTPUT_STREAM
+
+#include "ignite/impl/interop/interop_memory.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace interop
+ {
+ /**
+ * Interop output stream.
+ */
+ class IGNITE_IMPORT_EXPORT InteropOutputStream {
+ public:
+ /**
+ * Create new output stream with the given capacity.
+ *
+ * @param mem Memory.
+ */
+ InteropOutputStream(InteropMemory* mem);
+
+ /**
+ * Write signed 8-byte integer.
+ *
+ * @param val Value.
+ */
+ void WriteInt8(const int8_t val);
+
+ /**
+ * Write signed 8-byte integer at the given position.
+ *
+ * @param val Value.
+ */
+ void WriteInt8(const int8_t val, const int32_t pos);
+
+ /**
+ * Write signed 8-byte integer array.
+ *
+ * @param val Value.
+ * @param len Length.
+ */
+ void WriteInt8Array(const int8_t* val, const int32_t len);
+
+ /**
+ * Write bool.
+ *
+ * @param val Value.
+ */
+ void WriteBool(const bool val);
+
+ /**
+ * Write bool array.
+ *
+ * @param val Value.
+ * @param len Length.
+ */
+ void WriteBoolArray(const bool* val, const int32_t len);
+
+ /**
+ * Write signed 16-byte integer.
+ *
+ * @param val Value.
+ */
+ void WriteInt16(const int16_t val);
+
+ /**
+ * Write signed 16-byte integer array.
+ *
+ * @param val Value.
+ * @param len Length.
+ */
+ void WriteInt16Array(const int16_t* val, const int32_t len);
+
+ /**
+ * Write unsigned 16-byte integer.
+ *
+ * @param val Value.
+ */
+ void WriteUInt16(const uint16_t val);
+
+ /**
+ * Write unsigned 16-byte integer array.
+ *
+ * @param val Value.
+ * @param len Length.
+ */
+ void WriteUInt16Array(const uint16_t* val, const int32_t len);
+
+ /**
+ * Write signed 32-byte integer.
+ *
+ * @param val Value.
+ */
+ void WriteInt32(const int32_t val);
+
+ /**
+ * Write signed 32-byte integer at the given position.
+ *
+ * @param pos Position.
+ * @param val Value.
+ */
+ void WriteInt32(const int32_t pos, const int32_t val);
+
+ /**
+ * Write signed 32-byte integer array.
+ *
+ * @param val Value.
+ * @param len Length.
+ */
+ void WriteInt32Array(const int32_t* val, const int32_t len);
+
+ /**
+ * Write signed 64-byte integer.
+ *
+ * @param val Value.
+ */
+ void WriteInt64(const int64_t val);
+
+ /**
+ * Write signed 64-byte integer array.
+ *
+ * @param val Value.
+ * @param len Length.
+ */
+ void WriteInt64Array(const int64_t* val, const int32_t len);
+
+ /**
+ * Write float.
+ *
+ * @param val Value.
+ */
+ void WriteFloat(const float val);
+
+ /**
+ * Write float array.
+ *
+ * @param val Value.
+ * @param len Length.
+ */
+ void WriteFloatArray(const float* val, const int32_t len);
+
+ /**
+ * Write double.
+ *
+ * @param val Value.
+ */
+ void WriteDouble(const double val);
+
+ /**
+ * Write double array.
+ *
+ * @param val Value.
+ * @param len Length.
+ */
+ void WriteDoubleArray(const double* val, const int32_t len);
+
+ /**
+ * Get current stream position.
+ */
+ int32_t Position();
+
+ /**
+ * Set current stream position (absolute).
+ *
+ * @param val Position (absolute).
+ */
+ void Position(const int32_t val);
+
+ /**
+ * Synchronize data with underlying memory.
+ */
+ void Synchronize();
+ private:
+ /** Memory. */
+ InteropMemory* mem;
+
+ /** Pointer to data. */
+ int8_t* data;
+
+ /** Capacity. */
+ int cap;
+
+ /** Current position. */
+ int pos;
+
+ IGNITE_NO_COPY_ASSIGNMENT(InteropOutputStream)
+
+ /**
+ * Ensure that stream enough capacity optionally extending it.
+ *
+ * @param reqCap Requsted capacity.
+ */
+ void EnsureCapacity(int32_t reqCap);
+
+ /**
+ * Shift stream to the right.
+ *
+ * @param cnt Amount of bytes to shift the stream to.
+ */
+ void Shift(int32_t cnt);
+
+ /**
+ * Copy data to the stream shifting it along the way.
+ *
+ * @param ptr Pointer to data.
+ * @param off Offset.
+ * @param len Length.
+ */
+ void CopyAndShift(const int8_t* src, int32_t off, int32_t len);
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
[11/11] ignite git commit: IGNITE-1364: Squashed commit from initial
branch.
Posted by vo...@apache.org.
IGNITE-1364: Squashed commit from initial branch.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1fc06e01
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1fc06e01
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1fc06e01
Branch: refs/heads/ignite-1364-1
Commit: 1fc06e0135c01ffe5dd94c8f4a1e7f65d8deca97
Parents: b1a9771
Author: thatcoach <pp...@list.ru>
Authored: Thu Sep 3 20:09:01 2015 +0300
Committer: thatcoach <pp...@list.ru>
Committed: Thu Sep 3 20:09:01 2015 +0300
----------------------------------------------------------------------
.../platform/src/main/cpp/common/configure.ac | 2 +-
.../src/main/cpp/common/ignite-common.pc.in | 2 +-
.../cpp/common/include/ignite/common/exports.h | 8 +-
.../cpp/common/include/ignite/common/java.h | 16 +-
.../src/main/cpp/common/src/exports.cpp | 16 +-
.../platform/src/main/cpp/common/src/java.cpp | 45 +-
.../platform/src/main/cpp/core-test/Makefile.am | 49 +
.../main/cpp/core-test/config/cache-query.xml | 91 +
.../main/cpp/core-test/config/cache-test.xml | 129 ++
.../src/main/cpp/core-test/configure.ac | 62 +
.../src/main/cpp/core-test/include/Makefile.am | 22 +
.../include/ignite/portable_test_defs.h | 320 +++
.../include/ignite/portable_test_utils.h | 516 +++++
.../cpp/core-test/include/teamcity_messages.h | 55 +
.../src/main/cpp/core-test/project/README.TXT | 1 +
.../main/cpp/core-test/project/vs/README.TXT | 1 +
.../cpp/core-test/project/vs/core-test.vcxproj | 174 ++
.../project/vs/core-test.vcxproj.filters | 68 +
.../main/cpp/core-test/src/cache_query_test.cpp | 651 ++++++
.../src/main/cpp/core-test/src/cache_test.cpp | 481 +++++
.../main/cpp/core-test/src/concurrent_test.cpp | 186 ++
.../cpp/core-test/src/handle_registry_test.cpp | 176 ++
.../main/cpp/core-test/src/ignition_test.cpp | 97 +
.../src/portable_reader_writer_raw_test.cpp | 1532 ++++++++++++++
.../src/portable_reader_writer_test.cpp | 1951 ++++++++++++++++++
.../cpp/core-test/src/portable_session_test.cpp | 257 +++
.../cpp/core-test/src/portable_test_defs.cpp | 65 +
.../main/cpp/core-test/src/teamcity_boost.cpp | 159 ++
.../cpp/core-test/src/teamcity_messages.cpp | 150 ++
modules/platform/src/main/cpp/core/Makefile.am | 66 +
modules/platform/src/main/cpp/core/configure.ac | 62 +
modules/platform/src/main/cpp/core/ignite.pc.in | 9 +
.../src/main/cpp/core/include/Makefile.am | 61 +
.../main/cpp/core/include/ignite/cache/cache.h | 1153 +++++++++++
.../cpp/core/include/ignite/cache/cache_entry.h | 118 ++
.../core/include/ignite/cache/cache_peek_mode.h | 71 +
.../cpp/core/include/ignite/cache/query/query.h | 27 +
.../include/ignite/cache/query/query_argument.h | 125 ++
.../include/ignite/cache/query/query_cursor.h | 191 ++
.../include/ignite/cache/query/query_scan.h | 151 ++
.../core/include/ignite/cache/query/query_sql.h | 253 +++
.../include/ignite/cache/query/query_text.h | 159 ++
.../src/main/cpp/core/include/ignite/guid.h | 112 +
.../src/main/cpp/core/include/ignite/ignite.h | 154 ++
.../core/include/ignite/ignite_configuration.h | 92 +
.../main/cpp/core/include/ignite/ignite_error.h | 260 +++
.../src/main/cpp/core/include/ignite/ignition.h | 195 ++
.../core/include/ignite/impl/cache/cache_impl.h | 418 ++++
.../ignite/impl/cache/query/query_impl.h | 115 ++
.../core/include/ignite/impl/handle_registry.h | 202 ++
.../include/ignite/impl/ignite_environment.h | 130 ++
.../cpp/core/include/ignite/impl/ignite_impl.h | 146 ++
.../core/include/ignite/impl/interop/interop.h | 25 +
.../ignite/impl/interop/interop_input_stream.h | 234 +++
.../ignite/impl/interop/interop_memory.h | 280 +++
.../ignite/impl/interop/interop_output_stream.h | 234 +++
.../cpp/core/include/ignite/impl/operations.h | 452 ++++
.../ignite/impl/portable/portable_common.h | 146 ++
.../ignite/impl/portable/portable_id_resolver.h | 106 +
.../impl/portable/portable_metadata_handler.h | 102 +
.../impl/portable/portable_metadata_manager.h | 120 ++
.../impl/portable/portable_metadata_snapshot.h | 122 ++
.../impl/portable/portable_metadata_updater.h | 53 +
.../portable/portable_metadata_updater_impl.h | 65 +
.../ignite/impl/portable/portable_reader_impl.h | 1130 ++++++++++
.../ignite/impl/portable/portable_utils.h | 344 +++
.../ignite/impl/portable/portable_writer_impl.h | 859 ++++++++
.../cpp/core/include/ignite/portable/portable.h | 29 +
.../include/ignite/portable/portable_consts.h | 106 +
.../ignite/portable/portable_containers.h | 525 +++++
.../ignite/portable/portable_raw_reader.h | 324 +++
.../ignite/portable/portable_raw_writer.h | 300 +++
.../include/ignite/portable/portable_reader.h | 355 ++++
.../include/ignite/portable/portable_type.h | 293 +++
.../include/ignite/portable/portable_writer.h | 335 +++
.../main/cpp/core/os/linux/include/Makefile.am | 20 +
.../core/os/linux/include/ignite/impl/utils.h | 155 ++
.../main/cpp/core/os/linux/src/impl/utils.cpp | 439 ++++
.../cpp/core/os/win/include/ignite/impl/utils.h | 155 ++
.../src/main/cpp/core/os/win/src/impl/utils.cpp | 453 ++++
.../src/main/cpp/core/project/README.TXT | 1 +
.../src/main/cpp/core/project/vs/README.TXT | 1 +
.../src/main/cpp/core/project/vs/core.vcxproj | 272 +++
.../cpp/core/project/vs/core.vcxproj.filters | 246 +++
.../main/cpp/core/project/vs/core.vcxprojrel | 272 +++
modules/platform/src/main/cpp/core/src/guid.cpp | 65 +
.../platform/src/main/cpp/core/src/ignite.cpp | 43 +
.../src/main/cpp/core/src/ignite_error.cpp | 222 ++
.../platform/src/main/cpp/core/src/ignition.cpp | 468 +++++
.../main/cpp/core/src/impl/cache/cache_impl.cpp | 388 ++++
.../core/src/impl/cache/query/query_impl.cpp | 193 ++
.../main/cpp/core/src/impl/handle_registry.cpp | 234 +++
.../cpp/core/src/impl/ignite_environment.cpp | 166 ++
.../src/main/cpp/core/src/impl/ignite_impl.cpp | 42 +
.../src/impl/interop/interop_input_stream.cpp | 215 ++
.../core/src/impl/interop/interop_memory.cpp | 182 ++
.../src/impl/interop/interop_output_stream.cpp | 215 ++
.../impl/portable/portable_metadata_handler.cpp | 78 +
.../impl/portable/portable_metadata_manager.cpp | 201 ++
.../portable/portable_metadata_snapshot.cpp | 70 +
.../impl/portable/portable_metadata_updater.cpp | 32 +
.../portable/portable_metadata_updater_impl.cpp | 94 +
.../src/impl/portable/portable_reader_impl.cpp | 683 ++++++
.../core/src/impl/portable/portable_utils.cpp | 214 ++
.../src/impl/portable/portable_writer_impl.cpp | 600 ++++++
.../core/src/portable/portable_containers.cpp | 76 +
.../core/src/portable/portable_raw_reader.cpp | 135 ++
.../core/src/portable/portable_raw_writer.cpp | 147 ++
.../cpp/core/src/portable/portable_reader.cpp | 142 ++
.../cpp/core/src/portable/portable_type.cpp | 51 +
.../cpp/core/src/portable/portable_writer.cpp | 154 ++
parent/pom.xml | 6 +-
112 files changed, 25176 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/common/configure.ac
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/common/configure.ac b/modules/platform/src/main/cpp/common/configure.ac
index 7706737..b34d7d8 100644
--- a/modules/platform/src/main/cpp/common/configure.ac
+++ b/modules/platform/src/main/cpp/common/configure.ac
@@ -19,7 +19,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
-AC_INIT([Ignite JNI bridge for C++], [7.4.1], [dev@ignite.apache.org], [ignite-common], [ignite.apache.org])
+AC_INIT([Apache Ignite JNI bridge for C++], [1.4.0], [dev@ignite.apache.org], [ignite-common], [ignite.apache.org])
AC_CONFIG_SRCDIR(src)
AC_CANONICAL_SYSTEM
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/common/ignite-common.pc.in
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/common/ignite-common.pc.in b/modules/platform/src/main/cpp/common/ignite-common.pc.in
index 3cd3cec..b8c40d2 100644
--- a/modules/platform/src/main/cpp/common/ignite-common.pc.in
+++ b/modules/platform/src/main/cpp/common/ignite-common.pc.in
@@ -4,6 +4,6 @@ libdir=@libdir@
includedir=@includedir@
Name: ignite-common
-Description: Ignite JNI bridge for C++.
+Description: Apache Ignite JNI bridge for C++.
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lignite-common
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/common/include/ignite/common/exports.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/common/include/ignite/common/exports.h b/modules/platform/src/main/cpp/common/include/ignite/common/exports.h
index 48e86f0..930fad3 100644
--- a/modules/platform/src/main/cpp/common/include/ignite/common/exports.h
+++ b/modules/platform/src/main/cpp/common/include/ignite/common/exports.h
@@ -25,10 +25,10 @@ namespace gcj = ignite::common::java;
extern "C" {
int IGNITE_CALL IgniteReallocate(long long memPtr, int cap);
- void* IGNITE_CALL IgniteIgnitionStart(gcj::JniContext* ctx, char* cfgPath, char* gridName, int factoryId, long long dataPtr);
- void* IGNITE_CALL IgniteIgnitionInstance(gcj::JniContext* ctx, char* gridName);
- long long IGNITE_CALL IgniteIgnitionEnvironmentPointer(gcj::JniContext* ctx, char* gridName);
- bool IGNITE_CALL IgniteIgnitionStop(gcj::JniContext* ctx, char* gridName, bool cancel);
+ void* IGNITE_CALL IgniteIgnitionStart(gcj::JniContext* ctx, char* cfgPath, char* name, int factoryId, long long dataPtr);
+ void* IGNITE_CALL IgniteIgnitionInstance(gcj::JniContext* ctx, char* name);
+ long long IGNITE_CALL IgniteIgnitionEnvironmentPointer(gcj::JniContext* ctx, char* name);
+ bool IGNITE_CALL IgniteIgnitionStop(gcj::JniContext* ctx, char* name, bool cancel);
void IGNITE_CALL IgniteIgnitionStopAll(gcj::JniContext* ctx, bool cancel);
void IGNITE_CALL IgniteProcessorReleaseStart(gcj::JniContext* ctx, void* obj);
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/common/include/ignite/common/java.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/common/include/ignite/common/java.h b/modules/platform/src/main/cpp/common/include/ignite/common/java.h
index 426ac68..e2d23b2 100644
--- a/modules/platform/src/main/cpp/common/include/ignite/common/java.h
+++ b/modules/platform/src/main/cpp/common/include/ignite/common/java.h
@@ -449,14 +449,14 @@ namespace ignite
static void Detach();
static void Release(jobject obj);
- jobject IgnitionStart(char* cfgPath, char* gridName, int factoryId, long long dataPtr);
- jobject IgnitionStart(char* cfgPath, char* gridName, int factoryId, long long dataPtr, JniErrorInfo* errInfo);
- jobject IgnitionInstance(char* gridName);
- jobject IgnitionInstance(char* gridName, JniErrorInfo* errInfo);
- long long IgnitionEnvironmentPointer(char* gridName);
- long long IgnitionEnvironmentPointer(char* gridName, JniErrorInfo* errInfo);
- bool IgnitionStop(char* gridName, bool cancel);
- bool IgnitionStop(char* gridName, bool cancel, JniErrorInfo* errInfo);
+ jobject IgnitionStart(char* cfgPath, char* name, int factoryId, long long dataPtr);
+ jobject IgnitionStart(char* cfgPath, char* name, int factoryId, long long dataPtr, JniErrorInfo* errInfo);
+ jobject IgnitionInstance(char* name);
+ jobject IgnitionInstance(char* name, JniErrorInfo* errInfo);
+ long long IgnitionEnvironmentPointer(char* name);
+ long long IgnitionEnvironmentPointer(char* name, JniErrorInfo* errInfo);
+ bool IgnitionStop(char* name, bool cancel);
+ bool IgnitionStop(char* name, bool cancel, JniErrorInfo* errInfo);
void IgnitionStopAll(bool cancel);
void IgnitionStopAll(bool cancel, JniErrorInfo* errInfo);
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/common/src/exports.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/common/src/exports.cpp b/modules/platform/src/main/cpp/common/src/exports.cpp
index 10e4801..2ac3340 100644
--- a/modules/platform/src/main/cpp/common/src/exports.cpp
+++ b/modules/platform/src/main/cpp/common/src/exports.cpp
@@ -26,20 +26,20 @@ extern "C" {
return gcj::JniContext::Reallocate(memPtr, cap);
}
- void* IGNITE_CALL IgniteIgnitionStart(gcj::JniContext* ctx, char* cfgPath, char* gridName, int factoryId, long long dataPtr) {
- return ctx->IgnitionStart(cfgPath, gridName, factoryId, dataPtr);
+ void* IGNITE_CALL IgniteIgnitionStart(gcj::JniContext* ctx, char* cfgPath, char* name, int factoryId, long long dataPtr) {
+ return ctx->IgnitionStart(cfgPath, name, factoryId, dataPtr);
}
- void* IGNITE_CALL IgniteIgnitionInstance(gcj::JniContext* ctx, char* gridName) {
- return ctx->IgnitionInstance(gridName);
+ void* IGNITE_CALL IgniteIgnitionInstance(gcj::JniContext* ctx, char* name) {
+ return ctx->IgnitionInstance(name);
}
- long long IGNITE_CALL IgniteIgnitionEnvironmentPointer(gcj::JniContext* ctx, char* gridName) {
- return ctx->IgnitionEnvironmentPointer(gridName);
+ long long IGNITE_CALL IgniteIgnitionEnvironmentPointer(gcj::JniContext* ctx, char* name) {
+ return ctx->IgnitionEnvironmentPointer(name);
}
- bool IGNITE_CALL IgniteIgnitionStop(gcj::JniContext* ctx, char* gridName, bool cancel) {
- return ctx->IgnitionStop(gridName, cancel);
+ bool IGNITE_CALL IgniteIgnitionStop(gcj::JniContext* ctx, char* name, bool cancel) {
+ return ctx->IgnitionStop(name, cancel);
}
void IGNITE_CALL IgniteIgnitionStopAll(gcj::JniContext* ctx, bool cancel) {
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/common/src/java.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/common/src/java.cpp b/modules/platform/src/main/cpp/common/src/java.cpp
index 0c6524b..5c5911a 100644
--- a/modules/platform/src/main/cpp/common/src/java.cpp
+++ b/modules/platform/src/main/cpp/common/src/java.cpp
@@ -919,22 +919,22 @@ namespace ignite
}
}
- jobject JniContext::IgnitionStart(char* cfgPath, char* gridName, int factoryId, long long dataPtr) {
- return IgnitionStart(cfgPath, gridName, factoryId, dataPtr, NULL);
+ jobject JniContext::IgnitionStart(char* cfgPath, char* name, int factoryId, long long dataPtr) {
+ return IgnitionStart(cfgPath, name, factoryId, dataPtr, NULL);
}
- jobject JniContext::IgnitionStart(char* cfgPath, char* gridName, int factoryId, long long dataPtr, JniErrorInfo* errInfo)
+ jobject JniContext::IgnitionStart(char* cfgPath, char* name, int factoryId, long long dataPtr, JniErrorInfo* errInfo)
{
JNIEnv* env = Attach();
jstring cfgPath0 = env->NewStringUTF(cfgPath);
- jstring gridName0 = env->NewStringUTF(gridName);
+ jstring name0 = env->NewStringUTF(name);
jobject interop = env->CallStaticObjectMethod(
jvm->GetMembers().c_PlatformIgnition,
jvm->GetMembers().m_PlatformIgnition_start,
cfgPath0,
- gridName0,
+ name0,
factoryId,
reinterpret_cast<long long>(&hnds),
dataPtr
@@ -946,57 +946,57 @@ namespace ignite
}
- jobject JniContext::IgnitionInstance(char* gridName)
+ jobject JniContext::IgnitionInstance(char* name)
{
- return IgnitionInstance(gridName, NULL);
+ return IgnitionInstance(name, NULL);
}
- jobject JniContext::IgnitionInstance(char* gridName, JniErrorInfo* errInfo)
+ jobject JniContext::IgnitionInstance(char* name, JniErrorInfo* errInfo)
{
JNIEnv* env = Attach();
- jstring gridName0 = env->NewStringUTF(gridName);
+ jstring name0 = env->NewStringUTF(name);
jobject interop = env->CallStaticObjectMethod(jvm->GetMembers().c_PlatformIgnition,
- jvm->GetMembers().m_PlatformIgnition_instance, gridName0);
+ jvm->GetMembers().m_PlatformIgnition_instance, name0);
ExceptionCheck(env, errInfo);
return LocalToGlobal(env, interop);
}
- long long JniContext::IgnitionEnvironmentPointer(char* gridName)
+ long long JniContext::IgnitionEnvironmentPointer(char* name)
{
- return IgnitionEnvironmentPointer(gridName, NULL);
+ return IgnitionEnvironmentPointer(name, NULL);
}
- long long JniContext::IgnitionEnvironmentPointer(char* gridName, JniErrorInfo* errInfo)
+ long long JniContext::IgnitionEnvironmentPointer(char* name, JniErrorInfo* errInfo)
{
JNIEnv* env = Attach();
- jstring gridName0 = env->NewStringUTF(gridName);
+ jstring name0 = env->NewStringUTF(name);
long long res = env->CallStaticLongMethod(jvm->GetMembers().c_PlatformIgnition,
- jvm->GetMembers().m_PlatformIgnition_environmentPointer, gridName0);
+ jvm->GetMembers().m_PlatformIgnition_environmentPointer, name0);
ExceptionCheck(env, errInfo);
return res;
}
- bool JniContext::IgnitionStop(char* gridName, bool cancel)
+ bool JniContext::IgnitionStop(char* name, bool cancel)
{
- return IgnitionStop(gridName, cancel, NULL);
+ return IgnitionStop(name, cancel, NULL);
}
- bool JniContext::IgnitionStop(char* gridName, bool cancel, JniErrorInfo* errInfo)
+ bool JniContext::IgnitionStop(char* name, bool cancel, JniErrorInfo* errInfo)
{
JNIEnv* env = Attach();
- jstring gridName0 = env->NewStringUTF(gridName);
+ jstring name0 = env->NewStringUTF(name);
- jboolean res = env->CallStaticBooleanMethod(jvm->GetMembers().c_PlatformIgnition, jvm->GetMembers().m_PlatformIgnition_stop,
- gridName0, cancel);
+ jboolean res = env->CallStaticBooleanMethod(jvm->GetMembers().c_PlatformIgnition,
+ jvm->GetMembers().m_PlatformIgnition_stop, name0, cancel);
ExceptionCheck(env, errInfo);
@@ -1012,7 +1012,8 @@ namespace ignite
{
JNIEnv* env = Attach();
- env->CallStaticVoidMethod(jvm->GetMembers().c_PlatformIgnition, jvm->GetMembers().m_PlatformIgnition_stopAll, cancel);
+ env->CallStaticVoidMethod(jvm->GetMembers().c_PlatformIgnition,
+ jvm->GetMembers().m_PlatformIgnition_stopAll, cancel);
ExceptionCheck(env, errInfo);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/Makefile.am
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/Makefile.am b/modules/platform/src/main/cpp/core-test/Makefile.am
new file mode 100644
index 0000000..9ed3111
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/Makefile.am
@@ -0,0 +1,49 @@
+##
+## 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.
+##
+
+ACLOCAL_AMFLAGS = "-Im4"
+
+SUBDIRS = . include
+DIST_SUBDIRS = . include
+
+AM_CPPFLAGS = -I$(srcdir)/include -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -DIGNITE_IMPL
+AM_CXXFLAGS = -Wall -std=c++0x
+
+noinst_PROGRAMS = ignite-tests
+
+ignite_tests_SOURCES = src/cache_test.cpp \
+ src/cache_query_test.cpp \
+ src/concurrent_test.cpp \
+ src/ignition_test.cpp \
+ src/handle_registry_test.cpp \
+ src/portable_test_defs.cpp \
+ src/portable_reader_writer_raw_test.cpp \
+ src/portable_reader_writer_test.cpp \
+ src/portable_session_test.cpp \
+ src/teamcity_messages.cpp \
+ src/teamcity_boost.cpp
+
+ignite_tests_LDFLAGS = -static-libtool-libs -L/usr/local/lib -lignite
+
+run-check: check
+ ./ignite-tests -p
+
+clean-local: clean-check
+ $(RM) *.gcno *.gcda
+
+clean-check:
+ $(RM) $(ignite_tests_OBJECTS)
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/config/cache-query.xml
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/config/cache-query.xml b/modules/platform/src/main/cpp/core-test/config/cache-query.xml
new file mode 100644
index 0000000..160fe49
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/config/cache-query.xml
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<!--
+ Ignite Spring configuration file to startup grid cache.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util.xsd">
+ <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+ <property name="localHost" value="127.0.0.1"/>
+ <property name="connectorConfiguration"><null/></property>
+
+ <property name="cacheConfiguration">
+ <list>
+ <bean class="org.apache.ignite.configuration.CacheConfiguration">
+ <property name="name" value="cache"/>
+ <property name="cacheMode" value="PARTITIONED"/>
+ <property name="atomicityMode" value="TRANSACTIONAL"/>
+ <property name="writeSynchronizationMode" value="FULL_SYNC"/>
+
+ <property name="affinity">
+ <bean class="org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction">
+ <property name="partitions" value="256"/>
+ </bean>
+ </property>
+
+ <property name="typeMetadata">
+ <list>
+ <bean class="org.apache.ignite.cache.CacheTypeMetadata">
+ <property name="valueType" value="QueryPerson"/>
+ <property name="ascendingFields">
+ <map>
+ <entry key="age" value="java.lang.Integer"/>
+ </map>
+ </property>
+ <property name="queryFields">
+ <map>
+ <entry key="name" value="java.lang.String"/>
+ <entry key="age" value="java.lang.Integer"/>
+ </map>
+ </property>
+ <property name="textFields">
+ <list>
+ <value>name</value>
+ </list>
+ </property>
+ </bean>
+ </list>
+ </property>
+ </bean>
+ </list>
+ </property>
+
+ <property name="discoverySpi">
+ <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+ <property name="ipFinder">
+ <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+ <property name="addresses">
+ <list>
+ <!-- In distributed environment, replace with actual host IP address. -->
+ <value>127.0.0.1:47500..47501</value>
+ </list>
+ </property>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ </bean>
+</beans>
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/config/cache-test.xml
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/config/cache-test.xml b/modules/platform/src/main/cpp/core-test/config/cache-test.xml
new file mode 100644
index 0000000..f239ba9
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/config/cache-test.xml
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<!--
+ Ignite Spring configuration file to startup grid cache.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util.xsd">
+ <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+ <property name="localHost" value="127.0.0.1"/>
+ <property name="connectorConfiguration"><null/></property>
+
+ <property name="includeEventTypes">
+ <util:constant static-field="org.apache.ignite.events.EventType.EVTS_CACHE"/>
+ </property>
+
+ <property name="cacheConfiguration">
+ <list>
+ <bean parent="cache-template">
+ <property name="name" value="local"/>
+ <property name="cacheMode" value="LOCAL"/>
+ <property name="atomicityMode" value="TRANSACTIONAL"/>
+ </bean>
+
+ <bean parent="cache-template">
+ <property name="name" value="local_atomic"/>
+ <property name="cacheMode" value="LOCAL"/>
+ <property name="atomicityMode" value="ATOMIC"/>
+ </bean>
+
+ <bean parent="cache-template">
+ <property name="name" value="partitioned"/>
+ <property name="cacheMode" value="PARTITIONED"/>
+ <property name="atomicityMode" value="TRANSACTIONAL"/>
+ </bean>
+
+ <bean parent="cache-template">
+ <property name="name" value="partitioned_atomic"/>
+ <property name="cacheMode" value="PARTITIONED"/>
+ <property name="atomicityMode" value="ATOMIC"/>
+ <property name="atomicWriteOrderMode" value="PRIMARY"/>
+ </bean>
+
+ <bean parent="cache-template">
+ <property name="name" value="partitioned_near"/>
+ <property name="cacheMode" value="PARTITIONED"/>
+ <property name="atomicityMode" value="TRANSACTIONAL"/>
+ <property name="nearConfiguration">
+ <bean class="org.apache.ignite.configuration.NearCacheConfiguration" />
+ </property>
+ </bean>
+
+ <bean parent="cache-template">
+ <property name="name" value="partitioned_atomic_near"/>
+ <property name="cacheMode" value="PARTITIONED"/>
+ <property name="atomicityMode" value="ATOMIC"/>
+ <property name="atomicWriteOrderMode" value="PRIMARY"/>
+ <property name="nearConfiguration">
+ <bean class="org.apache.ignite.configuration.NearCacheConfiguration" />
+ </property>
+ </bean>
+
+ <bean parent="cache-template">
+ <property name="name" value="replicated"/>
+ <property name="cacheMode" value="REPLICATED"/>
+ <property name="atomicityMode" value="TRANSACTIONAL"/>
+ </bean>
+
+ <bean parent="cache-template">
+ <property name="name" value="replicated_atomic"/>
+ <property name="cacheMode" value="REPLICATED"/>
+ <property name="atomicityMode" value="ATOMIC"/>
+ <property name="atomicWriteOrderMode" value="PRIMARY"/>
+ </bean>
+ </list>
+ </property>
+
+ <property name="discoverySpi">
+ <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+ <property name="ipFinder">
+ <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+ <property name="addresses">
+ <list>
+ <!-- In distributed environment, replace with actual host IP address. -->
+ <value>127.0.0.1:47500..47501</value>
+ </list>
+ </property>
+ </bean>
+ </property>
+ </bean>
+ </property>
+
+ <property name="transactionConfiguration">
+ <bean class="org.apache.ignite.configuration.TransactionConfiguration">
+ <property name="txSerializableEnabled" value="true"/>
+ </bean>
+ </property>
+ </bean>
+
+ <bean id="cache-template" abstract="true" class="org.apache.ignite.configuration.CacheConfiguration">
+ <property name="rebalanceMode" value="SYNC"/>
+ <property name="writeSynchronizationMode" value="FULL_SYNC"/>
+ <property name="swapEnabled" value="true"/>
+ <property name="backups" value="1"/>
+ <property name="eagerTtl" value="true"/>
+ </bean>
+</beans>
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/configure.ac
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/configure.ac b/modules/platform/src/main/cpp/core-test/configure.ac
new file mode 100644
index 0000000..3a1b660
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/configure.ac
@@ -0,0 +1,62 @@
+#
+# 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.
+#
+
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.69])
+AC_INIT([Apache Ignite C++ Test], [1.4.0], [dev@ignite.apache.org], [ignite], [ignite.apache.org])
+AC_CONFIG_SRCDIR(src)
+
+AC_CANONICAL_SYSTEM
+AC_CONFIG_MACRO_DIR([m4])
+AC_LANG([C++])
+
+# Initialize automake
+AM_INIT_AUTOMAKE([-Wall foreign subdir-objects])
+AC_CONFIG_HEADER(config.h)
+
+AM_PROG_AR
+
+# Checks for programs.
+GXX="-g -O2"
+
+AC_PROG_CXX
+
+# Initialize Libtool
+LT_INIT
+
+# Checks for libraries.
+AC_CHECK_LIB([pthread], [pthread_mutex_lock])
+
+# Checks for header files.
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_INLINE
+AC_TYPE_INT16_T
+AC_TYPE_INT32_T
+AC_TYPE_INT64_T
+AC_TYPE_INT8_T
+AC_TYPE_PID_T
+AC_TYPE_SIZE_T
+
+# Checks for library functions.
+AC_FUNC_ERROR_AT_LINE
+
+AC_CONFIG_FILES(Makefile include/Makefile)
+
+AC_OUTPUT
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/include/Makefile.am
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/include/Makefile.am b/modules/platform/src/main/cpp/core-test/include/Makefile.am
new file mode 100644
index 0000000..c43103e
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/include/Makefile.am
@@ -0,0 +1,22 @@
+##
+## 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.
+##
+
+ACLOCAL_AMFLAGS = "-Im4"
+
+nobase_include_HEADERS = teamcity_messages.h \
+ ignite/portable_test_defs.h \
+ ignite/portable_test_utils.h
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/include/ignite/portable_test_defs.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/include/ignite/portable_test_defs.h b/modules/platform/src/main/cpp/core-test/include/ignite/portable_test_defs.h
new file mode 100644
index 0000000..bae0118
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/include/ignite/portable_test_defs.h
@@ -0,0 +1,320 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_PORTABLE_TEST_DEFS
+#define _IGNITE_PORTABLE_TEST_DEFS
+
+#include <stdexcept>
+#include <stdint.h>
+
+#include "ignite/portable/portable.h"
+
+namespace ignite_test
+{
+ namespace core
+ {
+ namespace portable
+ {
+ class PortableDummy
+ {
+ // No-op.
+ };
+
+ class PortableInner
+ {
+ public:
+ PortableInner();
+
+ PortableInner(int32_t val);
+
+ int32_t GetValue() const;
+ private:
+ int32_t val;
+ };
+
+ class PortableOuter
+ {
+ public:
+ PortableOuter(int32_t valIn, int32_t valOut);
+
+ PortableInner GetInner() const;
+
+ int32_t GetValue() const;
+ private:
+ PortableInner inner;
+ int32_t val;
+ };
+
+ struct PortableFields
+ {
+ int32_t val1;
+ int32_t val2;
+ int32_t rawVal1;
+ int32_t rawVal2;
+
+ PortableFields() : val1(0), val2(0), rawVal1(0), rawVal2(0)
+ {
+ // No-op.
+ }
+
+ PortableFields(int32_t val1, int32_t val2, int32_t rawVal1, int32_t rawVal2) :
+ val1(val1), val2(val2), rawVal1(rawVal1), rawVal2(rawVal2)
+ {
+ // No-op.
+ }
+ };
+ }
+ }
+}
+
+namespace ignite
+{
+ namespace portable
+ {
+ namespace gt = ignite_test::core::portable;
+
+ template<>
+ struct PortableType<gt::PortableDummy>
+ {
+ /** <inheritdoc /> */
+ int32_t GetTypeId()
+ {
+ return GetPortableStringHashCode("PortableDummy");
+ }
+
+ /** <inheritdoc /> */
+ std::string GetTypeName()
+ {
+ return "PortableDummy";
+ }
+
+ /** <inheritdoc /> */
+ int32_t GetFieldId(const char* name)
+ {
+ return GetPortableStringHashCode(name);
+ }
+
+ /** <inheritdoc /> */
+ int32_t GetHashCode(const gt::PortableInner& obj)
+ {
+ return obj.GetValue();
+ }
+
+ /** <inheritdoc /> */
+ bool IsNull(const gt::PortableInner& obj)
+ {
+ return obj.GetValue() == 0;
+ }
+
+ /** <inheritdoc /> */
+ gt::PortableInner GetNull()
+ {
+ return gt::PortableInner(0);
+ }
+
+ /** <inheritdoc /> */
+ void Write(PortableWriter& writer, const gt::PortableDummy& obj)
+ {
+ // No-op.
+ }
+
+ /** <inheritdoc /> */
+ gt::PortableDummy Read(PortableReader& reader)
+ {
+ return gt::PortableDummy();
+ }
+ };
+
+ template<>
+ struct PortableType<gt::PortableInner>
+ {
+ /** <inheritdoc /> */
+ int32_t GetTypeId()
+ {
+ return GetPortableStringHashCode("PortableInner");
+ }
+
+ /** <inheritdoc /> */
+ std::string GetTypeName()
+ {
+ return "PortableInner";
+ }
+
+ /** <inheritdoc /> */
+ int32_t GetFieldId(const char* name)
+ {
+ return GetPortableStringHashCode(name);
+ }
+
+ /** <inheritdoc /> */
+ int32_t GetHashCode(const gt::PortableInner& obj)
+ {
+ return obj.GetValue();
+ }
+
+ /** <inheritdoc /> */
+ bool IsNull(const gt::PortableInner& obj)
+ {
+ return obj.GetValue() == 0;
+ }
+
+ /** <inheritdoc /> */
+ gt::PortableInner GetNull()
+ {
+ return gt::PortableInner(0);
+ }
+
+ /** <inheritdoc /> */
+ void Write(PortableWriter& writer, const gt::PortableInner& obj)
+ {
+ writer.WriteInt32("val", obj.GetValue());
+ }
+
+ /** <inheritdoc /> */
+ gt::PortableInner Read(PortableReader& reader)
+ {
+ int val = reader.ReadInt32("val");
+
+ return gt::PortableInner(val);
+ }
+ };
+
+ template<>
+ struct PortableType<gt::PortableOuter>
+ {
+ /** <inheritdoc /> */
+ int32_t GetTypeId()
+ {
+ return GetPortableStringHashCode("PortableOuter");
+ }
+
+ /** <inheritdoc /> */
+ std::string GetTypeName()
+ {
+ return "PortableOuter";
+ }
+
+ /** <inheritdoc /> */
+ int32_t GetFieldId(const char* name)
+ {
+ return GetPortableStringHashCode(name);
+ }
+
+ /** <inheritdoc /> */
+ int32_t GetHashCode(const gt::PortableOuter& obj)
+ {
+ return obj.GetValue() + obj.GetInner().GetValue();
+ }
+
+ /** <inheritdoc /> */
+ bool IsNull(const gt::PortableOuter& obj)
+ {
+ return obj.GetValue() == 0 && obj.GetInner().GetValue();
+ }
+
+ /** <inheritdoc /> */
+ gt::PortableOuter GetNull()
+ {
+ return gt::PortableOuter(0, 0);
+ }
+
+ /** <inheritdoc /> */
+ void Write(PortableWriter& writer, const gt::PortableOuter& obj)
+ {
+ writer.WriteObject("inner", obj.GetInner());
+ writer.WriteInt32("val", obj.GetValue());
+ }
+
+ /** <inheritdoc /> */
+ gt::PortableOuter Read(PortableReader& reader)
+ {
+ gt::PortableInner inner = reader.ReadObject<gt::PortableInner>("inner");
+ int val = reader.ReadInt32("val");
+
+ return gt::PortableOuter(inner.GetValue(), val);
+ }
+ };
+
+ template<>
+ struct PortableType<gt::PortableFields>
+ {
+ /** <inheritdoc /> */
+ int32_t GetTypeId()
+ {
+ return GetPortableStringHashCode("PortableFields");
+ }
+
+ /** <inheritdoc /> */
+ std::string GetTypeName()
+ {
+ return "PortableFields";
+ }
+
+ /** <inheritdoc /> */
+ int32_t GetFieldId(const char* name)
+ {
+ return GetPortableStringHashCode(name);
+ }
+
+ /** <inheritdoc /> */
+ int32_t GetHashCode(const gt::PortableFields& obj)
+ {
+ return obj.val1 + obj.val2 + obj.rawVal1 + obj.rawVal2;
+ }
+
+ /** <inheritdoc /> */
+ bool IsNull(const gt::PortableFields& obj)
+ {
+ return false;
+ }
+
+ /** <inheritdoc /> */
+ gt::PortableFields GetNull()
+ {
+ throw std::runtime_error("Must not be called.");
+ }
+
+ /** <inheritdoc /> */
+ void Write(PortableWriter& writer, const gt::PortableFields& obj)
+ {
+ writer.WriteInt32("val1", obj.val1);
+ writer.WriteInt32("val2", obj.val2);
+
+ PortableRawWriter rawWriter = writer.RawWriter();
+
+ rawWriter.WriteInt32(obj.rawVal1);
+ rawWriter.WriteInt32(obj.rawVal2);
+ }
+
+ /** <inheritdoc /> */
+ gt::PortableFields Read(PortableReader& reader)
+ {
+ int32_t val1 = reader.ReadInt32("val1");
+ int32_t val2 = reader.ReadInt32("val2");
+
+ PortableRawReader rawReader = reader.RawReader();
+
+ int32_t rawVal1 = rawReader.ReadInt32();
+ int32_t rawVal2 = rawReader.ReadInt32();
+
+ return gt::PortableFields(val1, val2, rawVal1, rawVal2);
+ }
+ };
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/include/ignite/portable_test_utils.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/include/ignite/portable_test_utils.h b/modules/platform/src/main/cpp/core-test/include/ignite/portable_test_utils.h
new file mode 100644
index 0000000..62f99f9
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/include/ignite/portable_test_utils.h
@@ -0,0 +1,516 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_PORTABLE_TEST_UTILS
+#define _IGNITE_PORTABLE_TEST_UTILS
+
+#include "ignite/portable/portable.h"
+
+using namespace ignite;
+using namespace ignite::portable;
+using namespace ignite::impl::portable;
+
+namespace ignite_test
+{
+ namespace core
+ {
+ namespace portable
+ {
+ template<typename T>
+ inline void Write(PortableRawWriter& writer, T val)
+ {
+ throw std::runtime_error("Function is not defined");
+ }
+
+ template<typename T>
+ inline T Read(PortableRawReader& reader)
+ {
+ throw std::runtime_error("Function is not defined");
+ }
+
+ template<>
+ inline void Write(PortableRawWriter& writer, int8_t val)
+ {
+ writer.WriteInt8(val);
+ }
+
+ template<>
+ inline int8_t Read(PortableRawReader& reader)
+ {
+ return reader.ReadInt8();
+ }
+
+ template<>
+ inline void Write(PortableRawWriter& writer, bool val)
+ {
+ writer.WriteBool(val);
+ }
+
+ template<>
+ inline bool Read(PortableRawReader& reader)
+ {
+ return reader.ReadBool();
+ }
+
+ template<>
+ inline void Write(PortableRawWriter& writer, int16_t val)
+ {
+ writer.WriteInt16(val);
+ }
+
+ template<>
+ inline int16_t Read(PortableRawReader& reader)
+ {
+ return reader.ReadInt16();
+ }
+
+ template<>
+ inline void Write(PortableRawWriter& writer, uint16_t val)
+ {
+ writer.WriteUInt16(val);
+ }
+
+ template<>
+ inline uint16_t Read(PortableRawReader& reader)
+ {
+ return reader.ReadUInt16();
+ }
+
+ template<>
+ inline void Write(PortableRawWriter& writer, int32_t val)
+ {
+ writer.WriteInt32(val);
+ }
+
+ template<>
+ inline int32_t Read(PortableRawReader& reader)
+ {
+ return reader.ReadInt32();
+ }
+
+ template<>
+ inline void Write(PortableRawWriter& writer, int64_t val)
+ {
+ writer.WriteInt64(val);
+ }
+
+ template<>
+ inline int64_t Read(PortableRawReader& reader)
+ {
+ return reader.ReadInt64();
+ }
+
+ template<>
+ inline void Write(PortableRawWriter& writer, float val)
+ {
+ writer.WriteFloat(val);
+ }
+
+ template<>
+ inline float Read(PortableRawReader& reader)
+ {
+ return reader.ReadFloat();
+ }
+
+ template<>
+ inline void Write(PortableRawWriter& writer, double val)
+ {
+ writer.WriteDouble(val);
+ }
+
+ template<>
+ inline double Read(PortableRawReader& reader)
+ {
+ return reader.ReadDouble();
+ }
+
+ template<>
+ inline void Write(PortableRawWriter& writer, Guid val)
+ {
+ writer.WriteGuid(val);
+ }
+
+ template<>
+ inline Guid Read(PortableRawReader& reader)
+ {
+ return reader.ReadGuid();
+ }
+
+ template<typename T>
+ inline void WriteArray(PortableRawWriter& writer, T* val, int32_t len)
+ {
+ throw std::runtime_error("Function is not defined");
+ }
+
+ template<typename T>
+ inline int32_t ReadArray(PortableRawReader& reader, T* val, int32_t len)
+ {
+ throw std::runtime_error("Function is not defined");
+ }
+
+ template<>
+ inline void WriteArray(PortableRawWriter& writer, int8_t* val, int32_t len)
+ {
+ writer.WriteInt8Array(val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableRawReader& reader, int8_t* val, int32_t len)
+ {
+ return reader.ReadInt8Array(val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableRawWriter& writer, bool* val, int32_t len)
+ {
+ writer.WriteBoolArray(val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableRawReader& reader, bool* val, int32_t len)
+ {
+ return reader.ReadBoolArray(val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableRawWriter& writer, int16_t* val, int32_t len)
+ {
+ writer.WriteInt16Array(val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableRawReader& reader, int16_t* val, int32_t len)
+ {
+ return reader.ReadInt16Array(val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableRawWriter& writer, uint16_t* val, int32_t len)
+ {
+ writer.WriteUInt16Array(val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableRawReader& reader, uint16_t* val, int32_t len)
+ {
+ return reader.ReadUInt16Array(val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableRawWriter& writer, int32_t* val, int32_t len)
+ {
+ writer.WriteInt32Array(val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableRawReader& reader, int32_t* val, int32_t len)
+ {
+ return reader.ReadInt32Array(val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableRawWriter& writer, int64_t* val, int32_t len)
+ {
+ writer.WriteInt64Array(val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableRawReader& reader, int64_t* val, int32_t len)
+ {
+ return reader.ReadInt64Array(val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableRawWriter& writer, float* val, int32_t len)
+ {
+ writer.WriteFloatArray(val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableRawReader& reader, float* val, int32_t len)
+ {
+ return reader.ReadFloatArray(val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableRawWriter& writer, double* val, int32_t len)
+ {
+ writer.WriteDoubleArray(val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableRawReader& reader, double* val, int32_t len)
+ {
+ return reader.ReadDoubleArray(val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableRawWriter& writer, Guid* val, int32_t len)
+ {
+ writer.WriteGuidArray(val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableRawReader& reader, Guid* val, int32_t len)
+ {
+ return reader.ReadGuidArray(val, len);
+ }
+
+ template<typename T>
+ inline void Write(PortableWriter& writer, const char* fieldName, T val)
+ {
+ throw std::runtime_error("Function is not defined");
+ }
+
+ template<typename T>
+ inline T Read(PortableReader& reader, const char* fieldName)
+ {
+ throw std::runtime_error("Function is not defined");
+ }
+
+ template<>
+ inline void Write(PortableWriter& writer, const char* fieldName, int8_t val)
+ {
+ writer.WriteInt8(fieldName, val);
+ }
+
+ template<>
+ inline int8_t Read(PortableReader& reader, const char* fieldName)
+ {
+ return reader.ReadInt8(fieldName);
+ }
+
+ template<>
+ inline void Write(PortableWriter& writer, const char* fieldName, bool val)
+ {
+ writer.WriteBool(fieldName, val);
+ }
+
+ template<>
+ inline bool Read(PortableReader& reader, const char* fieldName)
+ {
+ return reader.ReadBool(fieldName);
+ }
+
+ template<>
+ inline void Write(PortableWriter& writer, const char* fieldName, int16_t val)
+ {
+ writer.WriteInt16(fieldName, val);
+ }
+
+ template<>
+ inline int16_t Read(PortableReader& reader, const char* fieldName)
+ {
+ return reader.ReadInt16(fieldName);
+ }
+
+ template<>
+ inline void Write(PortableWriter& writer, const char* fieldName, uint16_t val)
+ {
+ writer.WriteUInt16(fieldName, val);
+ }
+
+ template<>
+ inline uint16_t Read(PortableReader& reader, const char* fieldName)
+ {
+ return reader.ReadUInt16(fieldName);
+ }
+
+ template<>
+ inline void Write(PortableWriter& writer, const char* fieldName, int32_t val)
+ {
+ writer.WriteInt32(fieldName, val);
+ }
+
+ template<>
+ inline int32_t Read(PortableReader& reader, const char* fieldName)
+ {
+ return reader.ReadInt32(fieldName);
+ }
+
+ template<>
+ inline void Write(PortableWriter& writer, const char* fieldName, int64_t val)
+ {
+ writer.WriteInt64(fieldName, val);
+ }
+
+ template<>
+ inline int64_t Read(PortableReader& reader, const char* fieldName)
+ {
+ return reader.ReadInt64(fieldName);
+ }
+
+ template<>
+ inline void Write(PortableWriter& writer, const char* fieldName, float val)
+ {
+ writer.WriteFloat(fieldName, val);
+ }
+
+ template<>
+ inline float Read(PortableReader& reader, const char* fieldName)
+ {
+ return reader.ReadFloat(fieldName);
+ }
+
+ template<>
+ inline void Write(PortableWriter& writer, const char* fieldName, double val)
+ {
+ writer.WriteDouble(fieldName, val);
+ }
+
+ template<>
+ inline double Read(PortableReader& reader, const char* fieldName)
+ {
+ return reader.ReadDouble(fieldName);
+ }
+
+ template<>
+ inline void Write(PortableWriter& writer, const char* fieldName, Guid val)
+ {
+ writer.WriteGuid(fieldName, val);
+ }
+
+ template<>
+ inline Guid Read(PortableReader& reader, const char* fieldName)
+ {
+ return reader.ReadGuid(fieldName);
+ }
+
+ template<typename T>
+ inline void WriteArray(PortableWriter& writer, const char* fieldName, T* val, int32_t len)
+ {
+ throw std::runtime_error("Function is not defined");
+ }
+
+ template<typename T>
+ inline int32_t ReadArray(PortableReader& reader, const char* fieldName, T* val, int32_t len)
+ {
+ throw std::runtime_error("Function is not defined");
+ }
+
+ template<>
+ inline void WriteArray(PortableWriter& writer, const char* fieldName, int8_t* val, int32_t len)
+ {
+ writer.WriteInt8Array(fieldName, val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableReader& reader, const char* fieldName, int8_t* val, int32_t len)
+ {
+ return reader.ReadInt8Array(fieldName, val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableWriter& writer, const char* fieldName, bool* val, int32_t len)
+ {
+ writer.WriteBoolArray(fieldName, val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableReader& reader, const char* fieldName, bool* val, int32_t len)
+ {
+ return reader.ReadBoolArray(fieldName, val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableWriter& writer, const char* fieldName, int16_t* val, int32_t len)
+ {
+ writer.WriteInt16Array(fieldName, val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableReader& reader, const char* fieldName, int16_t* val, int32_t len)
+ {
+ return reader.ReadInt16Array(fieldName, val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableWriter& writer, const char* fieldName, uint16_t* val, int32_t len)
+ {
+ writer.WriteUInt16Array(fieldName, val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableReader& reader, const char* fieldName, uint16_t* val, int32_t len)
+ {
+ return reader.ReadUInt16Array(fieldName, val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableWriter& writer, const char* fieldName, int32_t* val, int32_t len)
+ {
+ writer.WriteInt32Array(fieldName, val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableReader& reader, const char* fieldName, int32_t* val, int32_t len)
+ {
+ return reader.ReadInt32Array(fieldName, val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableWriter& writer, const char* fieldName, int64_t* val, int32_t len)
+ {
+ writer.WriteInt64Array(fieldName, val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableReader& reader, const char* fieldName, int64_t* val, int32_t len)
+ {
+ return reader.ReadInt64Array(fieldName, val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableWriter& writer, const char* fieldName, float* val, int32_t len)
+ {
+ writer.WriteFloatArray(fieldName, val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableReader& reader, const char* fieldName, float* val, int32_t len)
+ {
+ return reader.ReadFloatArray(fieldName, val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableWriter& writer, const char* fieldName, double* val, int32_t len)
+ {
+ writer.WriteDoubleArray(fieldName, val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableReader& reader, const char* fieldName, double* val, int32_t len)
+ {
+ return reader.ReadDoubleArray(fieldName, val, len);
+ }
+
+ template<>
+ inline void WriteArray(PortableWriter& writer, const char* fieldName, Guid* val, int32_t len)
+ {
+ writer.WriteGuidArray(fieldName, val, len);
+ }
+
+ template<>
+ inline int32_t ReadArray(PortableReader& reader, const char* fieldName, Guid* val, int32_t len)
+ {
+ return reader.ReadGuidArray(fieldName, val, len);
+ }
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/include/teamcity_messages.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/include/teamcity_messages.h b/modules/platform/src/main/cpp/core-test/include/teamcity_messages.h
new file mode 100644
index 0000000..8cf23d0
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/include/teamcity_messages.h
@@ -0,0 +1,55 @@
+/* Copyright 2011 JetBrains s.r.o.
+ *
+ * Licensed 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.
+ *
+ * $Revision: 88625 $
+*/
+
+#ifndef H_TEAMCITY_MESSAGES
+#define H_TEAMCITY_MESSAGES
+
+#include <string>
+#include <iostream>
+
+namespace JetBrains {
+
+std::string getFlowIdFromEnvironment();
+bool underTeamcity();
+
+class TeamcityMessages {
+ std::ostream *m_out;
+
+protected:
+ std::string escape(std::string s);
+
+ void openMsg(const std::string &name);
+ void writeProperty(std::string name, std::string value);
+ void closeMsg();
+
+public:
+ TeamcityMessages();
+
+ void setOutput(std::ostream &);
+
+ void suiteStarted(std::string name, std::string flowid = "");
+ void suiteFinished(std::string name, std::string flowid = "");
+
+ void testStarted(std::string name, std::string flowid = "");
+ void testFailed(std::string name, std::string message, std::string details, std::string flowid = "");
+ void testIgnored(std::string name, std::string message, std::string flowid = "");
+ void testFinished(std::string name, int durationMs = -1, std::string flowid = "");
+};
+
+}
+
+#endif /* H_TEAMCITY_MESSAGES */
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/project/README.TXT
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/project/README.TXT b/modules/platform/src/main/cpp/core-test/project/README.TXT
new file mode 100644
index 0000000..97f4c64
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/project/README.TXT
@@ -0,0 +1 @@
+Contains IDE projects artifacts.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/project/vs/README.TXT
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/project/vs/README.TXT b/modules/platform/src/main/cpp/core-test/project/vs/README.TXT
new file mode 100644
index 0000000..f4fb456
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/project/vs/README.TXT
@@ -0,0 +1 @@
+Contains Visual Studio project artifacts.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/project/vs/core-test.vcxproj
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/project/vs/core-test.vcxproj b/modules/platform/src/main/cpp/core-test/project/vs/core-test.vcxproj
new file mode 100644
index 0000000..aa8cb98
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/project/vs/core-test.vcxproj
@@ -0,0 +1,174 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\..\common\project\vs\common.vcxproj">
+ <Project>{4f7e4917-4612-4b96-9838-025711ade391}</Project>
+ </ProjectReference>
+ <ProjectReference Include="..\..\..\core\project\vs\core.vcxproj">
+ <Project>{e2dea693-f2ea-43c2-a813-053378f6e4db}</Project>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="..\..\config\cache-query.xml" />
+ <None Include="..\..\config\cache-test.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\src\cache_test.cpp" />
+ <ClCompile Include="..\..\src\concurrent_test.cpp" />
+ <ClCompile Include="..\..\src\ignition_test.cpp" />
+ <ClCompile Include="..\..\src\handle_registry_test.cpp" />
+ <ClCompile Include="..\..\src\portable_reader_writer_raw_test.cpp" />
+ <ClCompile Include="..\..\src\portable_reader_writer_test.cpp" />
+ <ClCompile Include="..\..\src\portable_session_test.cpp" />
+ <ClCompile Include="..\..\src\portable_test_defs.cpp" />
+ <ClCompile Include="..\..\src\cache_query_test.cpp" />
+ <ClCompile Include="..\..\src\teamcity_boost.cpp" />
+ <ClCompile Include="..\..\src\teamcity_messages.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\include\ignite\portable_test_defs.h" />
+ <ClInclude Include="..\..\include\ignite\portable_test_utils.h" />
+ <ClInclude Include="..\..\include\teamcity_messages.h" />
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{133A22DB-FD60-44B9-B5E3-6CBB3EA5ABF0}</ProjectGuid>
+ <RootNamespace>coretest</RootNamespace>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v100</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v100</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v100</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v100</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
+ <IntDir>$(Platform)\$(Configuration)\</IntDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
+ <IntDir>$(Platform)\$(Configuration)\</IntDir>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\core\include;$(ProjectDir)\..\..\..\core\os\win\include;$(ProjectDir)\..\..\include;$(BOOST_HOME)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>_DEBUG;IGNITE_IMPL;BOOST_DATE_TIME_NO_LIB;BOOST_REGEX_NO_LIB;_CRT_SECURE_NO_WARNINGS;IGNITE_FRIEND;_CRTDBG_MAP_ALLOC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <ExceptionHandling>Async</ExceptionHandling>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalDependencies>$(BOOST_HOME)\lib64-msvc-10.0\libboost_unit_test_framework-vc100-mt-gd-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <SubSystem>Console</SubSystem>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\core\include;$(ProjectDir)\..\..\..\core\os\win\include;$(ProjectDir)\..\..\include;$(BOOST_HOME)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>_DEBUG;IGNITE_IMPL;BOOST_DATE_TIME_NO_LIB;BOOST_REGEX_NO_LIB;_CRT_SECURE_NO_WARNINGS;IGNITE_FRIEND;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <ExceptionHandling>Async</ExceptionHandling>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalDependencies>$(BOOST_HOME)\lib64-msvc-10.0\libboost_unit_test_framework-vc100-mt-gd-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\core\include;$(ProjectDir)\..\..\..\core\os\win\include;$(ProjectDir)\..\..\include;$(BOOST_HOME)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>NDEBUG;IGNITE_IMPL;BOOST_DATE_TIME_NO_LIB;BOOST_REGEX_NO_LIB;_CRT_SECURE_NO_WARNINGS;IGNITE_FRIEND;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <ExceptionHandling>Async</ExceptionHandling>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <AdditionalDependencies>$(BOOST_HOME)\lib64-msvc-10.0\libboost_unit_test_framework-vc100-mt-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\..\core\include;$(ProjectDir)\..\..\..\core\os\win\include;$(ProjectDir)\..\..\include;$(BOOST_HOME)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>NDEBUG;IGNITE_IMPL;BOOST_DATE_TIME_NO_LIB;BOOST_REGEX_NO_LIB;_CRT_SECURE_NO_WARNINGS;IGNITE_FRIEND;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <ExceptionHandling>Async</ExceptionHandling>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <AdditionalDependencies>$(BOOST_HOME)\lib64-msvc-10.0\libboost_unit_test_framework-vc100-mt-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ </Link>
+ </ItemDefinitionGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/project/vs/core-test.vcxproj.filters
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/project/vs/core-test.vcxproj.filters b/modules/platform/src/main/cpp/core-test/project/vs/core-test.vcxproj.filters
new file mode 100644
index 0000000..7e8dd95
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/project/vs/core-test.vcxproj.filters
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <ClCompile Include="..\..\src\cache_test.cpp">
+ <Filter>Code</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\concurrent_test.cpp">
+ <Filter>Code</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\ignition_test.cpp">
+ <Filter>Code</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\handle_registry_test.cpp">
+ <Filter>Code</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\portable_reader_writer_raw_test.cpp">
+ <Filter>Code</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\portable_reader_writer_test.cpp">
+ <Filter>Code</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\portable_session_test.cpp">
+ <Filter>Code</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\portable_test_defs.cpp">
+ <Filter>Code</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\cache_query_test.cpp">
+ <Filter>Code</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\teamcity_boost.cpp">
+ <Filter>TeamCity</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\teamcity_messages.cpp">
+ <Filter>TeamCity</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\include\ignite\portable_test_defs.h">
+ <Filter>Code</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\ignite\portable_test_utils.h">
+ <Filter>Code</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\include\teamcity_messages.h">
+ <Filter>TeamCity</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <Filter Include="Code">
+ <UniqueIdentifier>{486c367c-57e9-430a-80f0-39fd5b09bc64}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Configs">
+ <UniqueIdentifier>{a46d9d4c-44eb-40da-b4f6-89cc43b70c12}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="TeamCity">
+ <UniqueIdentifier>{76bceab0-e251-445f-88c3-3f6f8739423b}</UniqueIdentifier>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="..\..\config\cache-test.xml">
+ <Filter>Configs</Filter>
+ </None>
+ <None Include="..\..\config\cache-query.xml">
+ <Filter>Configs</Filter>
+ </None>
+ </ItemGroup>
+</Project>
\ No newline at end of file
[10/11] ignite git commit: IGNITE-1364: Squashed commit from initial
branch.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/src/cache_query_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/src/cache_query_test.cpp b/modules/platform/src/main/cpp/core-test/src/cache_query_test.cpp
new file mode 100644
index 0000000..6ccfd51
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/src/cache_query_test.cpp
@@ -0,0 +1,651 @@
+/*
+ * 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.
+ */
+
+#ifndef _MSC_VER
+ #define BOOST_TEST_DYN_LINK
+#endif
+
+#include <sstream>
+
+#include <boost/test/unit_test.hpp>
+
+#include "ignite/impl/utils.h"
+#include "ignite/cache/cache.h"
+#include "ignite/cache/query/query_cursor.h"
+#include "ignite/cache/query/query_sql.h"
+#include "ignite/cache/query/query_text.h"
+#include "ignite/ignite.h"
+#include "ignite/ignition.h"
+
+using namespace boost::unit_test;
+
+using namespace ignite;
+using namespace ignite::cache;
+using namespace ignite::cache::query;
+using namespace ignite::impl::utils;
+
+/**
+ * Person class for query tests.
+ */
+class IGNITE_IMPORT_EXPORT QueryPerson
+{
+public:
+ /**
+ * Constructor.
+ */
+ QueryPerson() : name(NULL), age(0)
+ {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param name Name.
+ * @param age Age.
+ */
+ QueryPerson(std::string name, int age) : name(CopyChars(name.c_str())), age(age)
+ {
+ // No-op.
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other Other instance.
+ */
+ QueryPerson(const QueryPerson& other)
+ {
+ name = CopyChars(other.name);
+ age = other.age;
+ }
+
+ /**
+ * Assignment operator.
+ *
+ * @param other Other instance.
+ * @return This instance.
+ */
+ QueryPerson& operator=(const QueryPerson& other)
+ {
+ if (&other != this)
+ {
+ QueryPerson tmp(other);
+
+ char* name0 = name;
+ int age0 = age;
+
+ name = tmp.name;
+ age = tmp.age;
+
+ tmp.name = name0;
+ tmp.age = age0;
+ }
+
+ return *this;
+ }
+
+ /**
+ * Destructor.
+ */
+ ~QueryPerson()
+ {
+ ReleaseChars(name);
+ }
+
+ /**
+ * Get name.
+ *
+ * @return Name.
+ */
+ std::string GetName()
+ {
+ return name ? std::string(name) : std::string();
+ }
+
+ /**
+ * Get age.
+ *
+ * @return Age.
+ */
+ int32_t GetAge()
+ {
+ return age;
+ }
+
+private:
+ /** Name. */
+ char* name;
+
+ /** Age. */
+ int age;
+};
+
+namespace ignite
+{
+ namespace portable
+ {
+ /**
+ * Portable type definition.
+ */
+ IGNITE_PORTABLE_TYPE_START(QueryPerson)
+ IGNITE_PORTABLE_GET_TYPE_ID_AS_HASH(QueryPerson)
+ IGNITE_PORTABLE_GET_TYPE_NAME_AS_IS(QueryPerson)
+ IGNITE_PORTABLE_GET_FIELD_ID_AS_HASH
+ IGNITE_PORTABLE_GET_HASH_CODE_ZERO(QueryPerson)
+ IGNITE_PORTABLE_IS_NULL_FALSE(QueryPerson)
+ IGNITE_PORTABLE_GET_NULL_DEFAULT_CTOR(QueryPerson)
+
+ void Write(PortableWriter& writer, QueryPerson obj)
+ {
+ writer.WriteString("name", obj.GetName());
+ writer.WriteInt32("age", obj.GetAge());
+ }
+
+ QueryPerson Read(PortableReader& reader)
+ {
+ std::string name = reader.ReadString("name");
+ int age = reader.ReadInt32("age");
+
+ return QueryPerson(name, age);
+ }
+
+ IGNITE_PORTABLE_TYPE_END
+ }
+}
+
+/** Node started during the test. */
+Ignite grid = Ignite();
+
+/** Cache accessor. */
+Cache<int, QueryPerson> GetCache()
+{
+ return grid.GetCache<int, QueryPerson>("cache");
+}
+
+/**
+ * Test setup fixture.
+ */
+struct CacheQueryTestSuiteFixture {
+ /**
+ * Constructor.
+ */
+ CacheQueryTestSuiteFixture()
+ {
+ IgniteConfiguration cfg;
+
+ IgniteJvmOption opts[5];
+
+ opts[0] = IgniteJvmOption("-Xdebug");
+ opts[1] = IgniteJvmOption("-Xnoagent");
+ opts[2] = IgniteJvmOption("-Djava.compiler=NONE");
+ opts[3] = IgniteJvmOption("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005");
+ opts[4] = IgniteJvmOption("-XX:+HeapDumpOnOutOfMemoryError");
+
+ cfg.jvmOptsLen = 5;
+ cfg.jvmOpts = opts;
+
+ cfg.jvmInitMem = 1024;
+ cfg.jvmMaxMem = 4096;
+
+ char* cfgPath = getenv("IGNITE_NATIVE_TEST_CPP_CONFIG_PATH");
+
+ std::string cfgPathStr = std::string(cfgPath).append("/").append("cache-query.xml");
+
+ cfg.springCfgPath = const_cast<char*>(cfgPathStr.c_str());
+
+ IgniteError err;
+
+ Ignite grid0 = Ignition::Start(cfg, &err);
+
+ if (err.GetCode() != IgniteError::IGNITE_SUCCESS)
+ BOOST_ERROR(err.GetText());
+
+ grid = grid0;
+ }
+
+ /**
+ * Destructor.
+ */
+ ~CacheQueryTestSuiteFixture()
+ {
+ Ignition::Stop(grid.GetName(), true);
+ }
+};
+
+/**
+ * Ensure that HasNext() fails.
+ *
+ * @param cur Cursor.
+ */
+void CheckHasNextFail(QueryCursor<int, QueryPerson>& cur)
+{
+ try
+ {
+ cur.HasNext();
+
+ BOOST_FAIL("Must fail.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_GENERIC);
+ }
+}
+
+/**
+ * Ensure that GetNext() fails.
+ *
+ * @param cur Cursor.
+ */
+void CheckGetNextFail(QueryCursor<int, QueryPerson>& cur)
+{
+ try
+ {
+ cur.GetNext();
+
+ BOOST_FAIL("Must fail.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_GENERIC);
+ }
+}
+
+/**
+ * Ensure that GetAll() fails.
+ *
+ * @param cur Cursor.
+ */
+void CheckGetAllFail(QueryCursor<int, QueryPerson>& cur)
+{
+ try
+ {
+ std::vector<CacheEntry<int, QueryPerson>> res;
+
+ cur.GetAll(res);
+
+ BOOST_FAIL("Must fail.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_GENERIC);
+ }
+}
+
+/**
+ * Check empty result through iteration.
+ *
+ * @param cur Cursor.
+ */
+void CheckEmpty(QueryCursor<int, QueryPerson>& cur)
+{
+ BOOST_REQUIRE(!cur.HasNext());
+
+ CheckGetNextFail(cur);
+ CheckGetAllFail(cur);
+}
+
+/**
+ * Check empty result through GetAll().
+ *
+ * @param cur Cursor.
+ */
+void CheckEmptyGetAll(QueryCursor<int, QueryPerson>& cur)
+{
+ std::vector<CacheEntry<int, QueryPerson>> res;
+
+ cur.GetAll(res);
+
+ BOOST_REQUIRE(res.size() == 0);
+
+ CheckHasNextFail(cur);
+ CheckGetNextFail(cur);
+}
+
+/**
+ * Check single result through iteration.
+ *
+ * @param cur Cursor.
+ * @param key1 Key.
+ * @param name1 Name.
+ * @param age1 Age.
+ */
+void CheckSingle(QueryCursor<int, QueryPerson>& cur, int key, std::string name, int age)
+{
+ BOOST_REQUIRE(cur.HasNext());
+
+ CheckGetAllFail(cur);
+
+ CacheEntry<int, QueryPerson> entry = cur.GetNext();
+
+ CheckGetAllFail(cur);
+
+ BOOST_REQUIRE(entry.GetKey() == key);
+ BOOST_REQUIRE(entry.GetValue().GetName().compare(name) == 0);
+ BOOST_REQUIRE(entry.GetValue().GetAge() == age);
+
+ BOOST_REQUIRE(!cur.HasNext());
+
+ CheckGetNextFail(cur);
+ CheckGetAllFail(cur);
+}
+
+/**
+ * Check single result through GetAll().
+ *
+ * @param cur Cursor.
+ * @param key1 Key.
+ * @param name1 Name.
+ * @param age1 Age.
+ */
+void CheckSingleGetAll(QueryCursor<int, QueryPerson>& cur, int key, std::string name, int age)
+{
+ std::vector<CacheEntry<int, QueryPerson>> res;
+
+ cur.GetAll(res);
+
+ CheckHasNextFail(cur);
+ CheckGetNextFail(cur);
+ CheckGetAllFail(cur);
+
+ BOOST_REQUIRE(res.size() == 1);
+
+ BOOST_REQUIRE(res[0].GetKey() == 1);
+ BOOST_REQUIRE(res[0].GetValue().GetName().compare(name) == 0);
+ BOOST_REQUIRE(res[0].GetValue().GetAge() == age);
+
+ CheckHasNextFail(cur);
+ CheckGetNextFail(cur);
+ CheckGetAllFail(cur);
+}
+
+/**
+ * Check multiple results through iteration.
+ *
+ * @param cur Cursor.
+ * @param key1 Key 1.
+ * @param name1 Name 1.
+ * @param age1 Age 1.
+ * @param key2 Key 2.
+ * @param name2 Name 2.
+ * @param age2 Age 2.
+ */
+void CheckMultiple(QueryCursor<int, QueryPerson>& cur, int key1, std::string name1,
+ int age1, int key2, std::string name2, int age2)
+{
+ for (int i = 0; i < 2; i++)
+ {
+ BOOST_REQUIRE(cur.HasNext());
+
+ CheckGetAllFail(cur);
+
+ CacheEntry<int, QueryPerson> entry = cur.GetNext();
+
+ CheckGetAllFail(cur);
+
+ if (entry.GetKey() == key1)
+ {
+ BOOST_REQUIRE(entry.GetValue().GetName().compare(name1) == 0);
+ BOOST_REQUIRE(entry.GetValue().GetAge() == age1);
+ }
+ else if (entry.GetKey() == key2)
+ {
+ BOOST_REQUIRE(entry.GetValue().GetName().compare(name2) == 0);
+ BOOST_REQUIRE(entry.GetValue().GetAge() == age2);
+ }
+ else
+ BOOST_FAIL("Unexpected entry.");
+ }
+
+ BOOST_REQUIRE(!cur.HasNext());
+
+ CheckGetNextFail(cur);
+ CheckGetAllFail(cur);
+}
+
+/**
+ * Check multiple results through GetAll().
+ *
+ * @param cur Cursor.
+ * @param key1 Key 1.
+ * @param name1 Name 1.
+ * @param age1 Age 1.
+ * @param key2 Key 2.
+ * @param name2 Name 2.
+ * @param age2 Age 2.
+ */
+void CheckMultipleGetAll(QueryCursor<int, QueryPerson>& cur, int key1, std::string name1, int age1,
+ int key2, std::string name2, int age2)
+{
+ std::vector<CacheEntry<int, QueryPerson>> res;
+
+ cur.GetAll(res);
+
+ CheckHasNextFail(cur);
+ CheckGetNextFail(cur);
+ CheckGetAllFail(cur);
+
+ BOOST_REQUIRE(res.size() == 2);
+
+ for (int i = 0; i < 2; i++)
+ {
+ CacheEntry<int, QueryPerson> entry = res[i];
+
+ if (entry.GetKey() == key1)
+ {
+ BOOST_REQUIRE(entry.GetValue().GetName().compare(name1) == 0);
+ BOOST_REQUIRE(entry.GetValue().GetAge() == age1);
+ }
+ else if (entry.GetKey() == key2)
+ {
+ BOOST_REQUIRE(entry.GetValue().GetName().compare(name2) == 0);
+ BOOST_REQUIRE(entry.GetValue().GetAge() == age2);
+ }
+ else
+ BOOST_FAIL("Unexpected entry.");
+ }
+}
+
+BOOST_FIXTURE_TEST_SUITE(CacheQueryTestSuite, CacheQueryTestSuiteFixture)
+
+/**
+ * Test SQL query.
+ */
+BOOST_AUTO_TEST_CASE(TestSqlQuery)
+{
+ Cache<int, QueryPerson> cache = GetCache();
+
+ // Test query with no results.
+ SqlQuery qry("QueryPerson", "age < 20");
+
+ QueryCursor<int, QueryPerson> cursor = cache.Query(qry);
+ CheckEmpty(cursor);
+
+ cursor = cache.Query(qry);
+ CheckEmptyGetAll(cursor);
+
+ // Test simple query.
+ cache.Put(1, QueryPerson("A1", 10));
+ cache.Put(2, QueryPerson("A2", 20));
+
+ cursor = cache.Query(qry);
+ CheckSingle(cursor, 1, "A1", 10);
+
+ cursor = cache.Query(qry);
+ CheckSingleGetAll(cursor, 1, "A1", 10);
+
+ // Test simple local query.
+ qry.SetLocal(true);
+
+ cursor = cache.Query(qry);
+ CheckSingle(cursor, 1, "A1", 10);
+
+ cursor = cache.Query(qry);
+ CheckSingleGetAll(cursor, 1, "A1", 10);
+
+ // Test query with arguments.
+ qry.SetSql("age < ? AND name = ?");
+ qry.AddArgument<int>(20);
+ qry.AddArgument<std::string>("A1");
+
+ cursor = cache.Query(qry);
+ CheckSingle(cursor, 1, "A1", 10);
+
+ cursor = cache.Query(qry);
+ CheckSingleGetAll(cursor, 1, "A1", 10);
+
+ // Test query returning multiple entries.
+ qry = SqlQuery("QueryPerson", "age < 30");
+
+ cursor = cache.Query(qry);
+ CheckMultiple(cursor, 1, "A1", 10, 2, "A2", 20);
+
+ cursor = cache.Query(qry);
+ CheckMultipleGetAll(cursor, 1, "A1", 10, 2, "A2", 20);
+}
+
+/**
+ * Test text query.
+ */
+BOOST_AUTO_TEST_CASE(TestTextQuery)
+{
+ Cache<int, QueryPerson> cache = GetCache();
+
+ // Test query with no results.
+ TextQuery qry("QueryPerson", "A1");
+
+ QueryCursor<int, QueryPerson> cursor = cache.Query(qry);
+ CheckEmpty(cursor);
+
+ cursor = cache.Query(qry);
+ CheckEmptyGetAll(cursor);
+
+ // Test simple query.
+ cache.Put(1, QueryPerson("A1", 10));
+ cache.Put(2, QueryPerson("A2", 20));
+
+ cursor = cache.Query(qry);
+ CheckSingle(cursor, 1, "A1", 10);
+
+ cursor = cache.Query(qry);
+ CheckSingleGetAll(cursor, 1, "A1", 10);
+
+ // Test simple local query.
+ qry.SetLocal(true);
+
+ cursor = cache.Query(qry);
+ CheckSingle(cursor, 1, "A1", 10);
+
+ cursor = cache.Query(qry);
+ CheckSingleGetAll(cursor, 1, "A1", 10);
+
+ // Test query returning multiple entries.
+ qry = TextQuery("QueryPerson", "A*");
+
+ cursor = cache.Query(qry);
+ CheckMultiple(cursor, 1, "A1", 10, 2, "A2", 20);
+
+ cursor = cache.Query(qry);
+ CheckMultipleGetAll(cursor, 1, "A1", 10, 2, "A2", 20);
+}
+
+/**
+ * Test scan query.
+ */
+BOOST_AUTO_TEST_CASE(TestScanQuery)
+{
+ // Test simple query.
+ Cache<int, QueryPerson> cache = GetCache();
+
+ // Test query with no results.
+ ScanQuery qry;
+
+ QueryCursor<int, QueryPerson> cursor = cache.Query(qry);
+ CheckEmpty(cursor);
+
+ cursor = cache.Query(qry);
+ CheckEmptyGetAll(cursor);
+
+ // Test simple query.
+ cache.Put(1, QueryPerson("A1", 10));
+
+ cursor = cache.Query(qry);
+ CheckSingle(cursor, 1, "A1", 10);
+
+ cursor = cache.Query(qry);
+ CheckSingleGetAll(cursor, 1, "A1", 10);
+
+ // Test query returning multiple entries.
+ cache.Put(2, QueryPerson("A2", 20));
+
+ cursor = cache.Query(qry);
+ CheckMultiple(cursor, 1, "A1", 10, 2, "A2", 20);
+
+ cursor = cache.Query(qry);
+ CheckMultipleGetAll(cursor, 1, "A1", 10, 2, "A2", 20);
+}
+
+/**
+ * Test scan query over partitions.
+ */
+BOOST_AUTO_TEST_CASE(TestScanQueryPartitioned)
+{
+ // Populate cache with data.
+ Cache<int, QueryPerson> cache = GetCache();
+
+ int32_t partCnt = 256; // Defined in configuration explicitly.
+ int32_t entryCnt = 1000; // Should be greater than partCnt.
+
+ for (int i = 0; i < entryCnt; i++)
+ {
+ std::stringstream stream;
+
+ stream << "A" << i;
+
+ cache.Put(i, QueryPerson(stream.str(), i * 10));
+ }
+
+ // Iterate over all partitions and collect data.
+ std::set<int> keys;
+
+ for (int i = 0; i < partCnt; i++)
+ {
+ ScanQuery qry(i);
+
+ QueryCursor<int, QueryPerson> cur = cache.Query(qry);
+
+ while (cur.HasNext())
+ {
+ CacheEntry<int, QueryPerson> entry = cur.GetNext();
+
+ int key = entry.GetKey();
+
+ keys.insert(key);
+
+ std::stringstream stream;
+ stream << "A" << key;
+ BOOST_REQUIRE(entry.GetValue().GetName().compare(stream.str()) == 0);
+
+ BOOST_REQUIRE(entry.GetValue().GetAge() == key * 10);
+ }
+ }
+
+ // Ensure that all keys were read.
+ BOOST_REQUIRE(keys.size() == entryCnt);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/src/cache_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/src/cache_test.cpp b/modules/platform/src/main/cpp/core-test/src/cache_test.cpp
new file mode 100644
index 0000000..b69caab
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/src/cache_test.cpp
@@ -0,0 +1,481 @@
+/*
+ * 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.
+ */
+
+#ifndef _MSC_VER
+ #define BOOST_TEST_DYN_LINK
+#endif
+
+#include <boost/test/unit_test.hpp>
+
+#include "ignite/cache/cache_peek_mode.h"
+#include "ignite/ignite.h"
+#include "ignite/ignition.h"
+
+using namespace ignite;
+using namespace boost::unit_test;
+
+/* Nodes started during the test. */
+Ignite grid0 = Ignite();
+Ignite grid1 = Ignite();
+
+/** Cache accessor. */
+cache::Cache<int, int> Cache()
+{
+ return grid0.GetCache<int, int>("partitioned");
+}
+
+struct Person
+{
+ std::string name;
+ int age;
+
+ Person() : name(""), age(0)
+ {
+ // No-op.
+ }
+
+ Person(std::string name, int age) : name(name), age(age)
+ {
+ // No-op.
+ }
+};
+
+namespace ignite
+{
+ namespace portable
+ {
+ IGNITE_PORTABLE_TYPE_START(Person)
+ IGNITE_PORTABLE_GET_TYPE_ID_AS_HASH(Person)
+ IGNITE_PORTABLE_GET_TYPE_NAME_AS_IS(Person)
+ IGNITE_PORTABLE_GET_FIELD_ID_AS_HASH
+ IGNITE_PORTABLE_GET_HASH_CODE_ZERO(Person)
+ IGNITE_PORTABLE_IS_NULL_FALSE(Person)
+ IGNITE_PORTABLE_GET_NULL_DEFAULT_CTOR(Person)
+
+ void Write(PortableWriter& writer, Person obj)
+ {
+ writer.WriteString("name", obj.name);
+ writer.WriteInt32("age", obj.age);
+ }
+
+ Person Read(PortableReader& reader)
+ {
+ std::string name = reader.ReadString("name");
+ int age = reader.ReadInt32("age");
+
+ return Person(name, age);
+ }
+
+ IGNITE_PORTABLE_TYPE_END
+ }
+}
+
+/*
+ * Test setup fixture.
+ */
+struct CacheTestSuiteFixture {
+ /*
+ * Constructor.
+ */
+ CacheTestSuiteFixture()
+ {
+ IgniteConfiguration cfg;
+
+ IgniteJvmOption opts[5];
+
+ opts[0] = IgniteJvmOption("-Xdebug");
+ opts[1] = IgniteJvmOption("-Xnoagent");
+ opts[2] = IgniteJvmOption("-Djava.compiler=NONE");
+ opts[3] = IgniteJvmOption("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005");
+ opts[4] = IgniteJvmOption("-XX:+HeapDumpOnOutOfMemoryError");
+
+ cfg.jvmOptsLen = 5;
+ cfg.jvmOpts = opts;
+
+ cfg.jvmInitMem = 1024;
+ cfg.jvmMaxMem = 4096;
+
+ char* cfgPath = getenv("IGNITE_NATIVE_TEST_CPP_CONFIG_PATH");
+
+ std::string cfgPathStr = std::string(cfgPath).append("/").append("cache-test.xml");
+
+ cfg.springCfgPath = const_cast<char*>(cfgPathStr.c_str());
+
+ for (int i = 0; i < 2; i++)
+ {
+ std::stringstream stream;
+
+ stream << "grid-" << i;
+
+ IgniteError err;
+
+ Ignite grid = Ignition::Start(cfg, stream.str().c_str(), &err);
+
+ if (err.GetCode() != IgniteError::IGNITE_SUCCESS)
+ BOOST_FAIL(err.GetText());
+
+ if (i == 0)
+ grid0 = grid;
+ else
+ grid1 = grid;
+ }
+ }
+
+ /*
+ * Destructor.
+ */
+ ~CacheTestSuiteFixture()
+ {
+ Ignition::Stop(grid0.GetName(), true);
+ Ignition::Stop(grid1.GetName(), true);
+
+ grid0 = Ignite();
+ grid1 = Ignite();
+ }
+};
+
+BOOST_FIXTURE_TEST_SUITE(CacheTestSuite, CacheTestSuiteFixture)
+
+BOOST_AUTO_TEST_CASE(TestRemoveAllKeys)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ cache.Put(1, 1);
+ cache.Put(2, 2);
+ cache.Put(3, 3);
+
+ int size = cache.Size(cache::IGNITE_PEEK_MODE_PRIMARY);
+
+ BOOST_REQUIRE(3 == size);
+
+ cache.RemoveAll();
+
+ size = cache.Size(cache::IGNITE_PEEK_MODE_ALL);
+
+ BOOST_REQUIRE(0 == size);
+
+ cache.Put(1, 1);
+ cache.Put(2, 2);
+ cache.Put(3, 3);
+
+ int keys[] = { 1, 2, 4, 5 };
+
+ std::set<int> keySet(keys, keys + 4);
+
+ cache.RemoveAll(keySet);
+
+ size = cache.Size(cache::IGNITE_PEEK_MODE_PRIMARY);
+
+ BOOST_REQUIRE(1 == size);
+}
+
+BOOST_AUTO_TEST_CASE(TestPut)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ cache.Put(1, 1);
+
+ BOOST_REQUIRE(1 == cache.Get(1));
+}
+
+BOOST_AUTO_TEST_CASE(TestPutAll)
+{
+ std::map<int, int> map;
+
+ for (int i = 0; i < 100; i++)
+ map[i] = i + 1;
+
+ cache::Cache<int, int> cache = Cache();
+
+ cache.PutAll(map);
+
+ for (int i = 0; i < 100; i++)
+ BOOST_REQUIRE(i + 1 == cache.Get(i));
+}
+
+BOOST_AUTO_TEST_CASE(TestPutIfAbsent)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ BOOST_REQUIRE(true == cache.PutIfAbsent(1, 3));
+ BOOST_REQUIRE(false == cache.PutIfAbsent(1, 3));
+}
+
+BOOST_AUTO_TEST_CASE(TestGet)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ cache.Put(1, 1);
+ cache.Put(2, 2);
+
+ BOOST_REQUIRE(1 == cache.Get(1));
+ BOOST_REQUIRE(2 == cache.Get(2));
+
+ BOOST_REQUIRE(0 == cache.Get(3));
+}
+
+BOOST_AUTO_TEST_CASE(TestGetAll)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ int keys[] = { 1, 2, 3, 4, 5 };
+
+ std::set<int> keySet (keys, keys + 5);
+
+ for (int i = 0; i < keySet.size(); i++)
+ cache.Put(i + 1, i + 1);
+
+ std::map<int, int> map = cache.GetAll(keySet);
+
+ for (int i = 0; i < keySet.size(); i++)
+ BOOST_REQUIRE(i + 1 == map[i + 1]);
+}
+
+BOOST_AUTO_TEST_CASE(TestGetAndPut)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ BOOST_REQUIRE(0 == cache.GetAndPut(1, 3));
+ BOOST_REQUIRE(3 == cache.GetAndPut(1, 1));
+ BOOST_REQUIRE(1 == cache.GetAndPut(1, 0));
+}
+
+BOOST_AUTO_TEST_CASE(TestGetAndPutIfAbsent)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ BOOST_REQUIRE(0 == cache.GetAndPutIfAbsent(1, 3));
+ BOOST_REQUIRE(3 == cache.GetAndPutIfAbsent(1, 1));
+ BOOST_REQUIRE(3 == cache.GetAndPutIfAbsent(1, 1));
+}
+
+BOOST_AUTO_TEST_CASE(TestGetAndRemove)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ cache.Put(1, 3);
+
+ BOOST_REQUIRE(3 == cache.GetAndRemove(1));
+ BOOST_REQUIRE(0 == cache.GetAndRemove(1));
+}
+
+BOOST_AUTO_TEST_CASE(TestGetAndReplace)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ BOOST_REQUIRE(0 == cache.GetAndReplace(1, 3));
+ BOOST_REQUIRE(0 == cache.GetAndReplace(1, 3));
+
+ cache.Put(1, 5);
+
+ BOOST_REQUIRE(5 == cache.GetAndReplace(1, 3));
+ BOOST_REQUIRE(3 == cache.GetAndReplace(1, 3));
+}
+
+BOOST_AUTO_TEST_CASE(TestContainsKey)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ BOOST_REQUIRE(false == cache.ContainsKey(1));
+
+ cache.Put(1, 1);
+
+ BOOST_REQUIRE(true == cache.ContainsKey(1));
+
+ BOOST_REQUIRE(true == cache.Remove(1));
+
+ BOOST_REQUIRE(false == cache.ContainsKey(1));
+}
+
+BOOST_AUTO_TEST_CASE(TestContainsKeys)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ int keys[] = { 1, 2 };
+
+ std::set<int> keySet(keys, keys + 2);
+
+ BOOST_REQUIRE(false == cache.ContainsKeys(keySet));
+
+ cache.Put(1, 1);
+ cache.Put(2, 2);
+
+ BOOST_REQUIRE(true == cache.ContainsKeys(keySet));
+
+ cache.Remove(1);
+
+ BOOST_REQUIRE(false == cache.ContainsKeys(keySet));
+}
+
+BOOST_AUTO_TEST_CASE(TestIsEmpty)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ BOOST_REQUIRE(true == cache.IsEmpty());
+
+ cache.Put(1, 1);
+
+ BOOST_REQUIRE(false == cache.IsEmpty());
+
+ cache.Remove(1);
+
+ BOOST_REQUIRE(true == cache.IsEmpty());
+}
+
+BOOST_AUTO_TEST_CASE(TestRemove)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ BOOST_REQUIRE(false == cache.Remove(1));
+
+ cache.Put(1, 1);
+
+ BOOST_REQUIRE(true == cache.Remove(1));
+ BOOST_REQUIRE(false == cache.Remove(1));
+ BOOST_REQUIRE(false == cache.ContainsKey(1));
+}
+
+BOOST_AUTO_TEST_CASE(TestClear)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ cache.Put(1, 1);
+
+ BOOST_REQUIRE(true == cache.ContainsKey(1));
+
+ cache.Clear(1);
+
+ BOOST_REQUIRE(false == cache.ContainsKey(1));
+}
+
+BOOST_AUTO_TEST_CASE(TestLocalClear)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ cache.Put(0, 2);
+
+ BOOST_REQUIRE(2 == cache.LocalPeek(0, cache::IGNITE_PEEK_MODE_PRIMARY));
+
+ cache.LocalClear(0);
+
+ BOOST_REQUIRE(0 == cache.LocalPeek(0, cache::IGNITE_PEEK_MODE_PRIMARY));
+}
+
+BOOST_AUTO_TEST_CASE(TestLocalClearAll)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ cache.Put(0, 3);
+ cache.Put(1, 3);
+
+ int keys[] = { 0, 1 };
+
+ std::set<int> keySet(keys, keys + 2);
+
+ BOOST_REQUIRE(3 == cache.LocalPeek(0, cache::IGNITE_PEEK_MODE_PRIMARY));
+ BOOST_REQUIRE(3 == cache.LocalPeek(1, cache::IGNITE_PEEK_MODE_PRIMARY));
+
+ cache.LocalClearAll(keySet);
+
+ BOOST_REQUIRE(0 == cache.LocalPeek(0, cache::IGNITE_PEEK_MODE_PRIMARY));
+ BOOST_REQUIRE(0 == cache.LocalPeek(1, cache::IGNITE_PEEK_MODE_PRIMARY));
+}
+
+BOOST_AUTO_TEST_CASE(TestSizes)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ BOOST_REQUIRE(0 == cache.Size());
+
+ cache.Put(1, 1);
+ cache.Put(2, 2);
+
+ BOOST_REQUIRE(2 <= cache.Size());
+
+ BOOST_REQUIRE(1 <= cache.LocalSize(cache::IGNITE_PEEK_MODE_PRIMARY));
+}
+
+BOOST_AUTO_TEST_CASE(TestLocalEvict)
+{
+ cache::Cache<int, int> cache = Cache();
+
+ cache.Put(1, 5);
+
+ BOOST_REQUIRE(5 == cache.LocalPeek(1, cache::IGNITE_PEEK_MODE_ONHEAP));
+
+ int keys[] = { 0, 1 };
+
+ std::set<int> keySet(keys, keys + 2);
+
+ cache.LocalEvict(keySet);
+
+ BOOST_REQUIRE(0 == cache.LocalPeek(1, cache::IGNITE_PEEK_MODE_ONHEAP));
+
+ BOOST_REQUIRE(5 == cache.Get(1));
+
+ BOOST_REQUIRE(5 == cache.LocalPeek(1, cache::IGNITE_PEEK_MODE_ONHEAP));
+}
+
+BOOST_AUTO_TEST_CASE(TestPortable)
+{
+ cache::Cache<int, Person> cache = grid0.GetCache<int, Person>("partitioned");
+
+ Person person("John Johnson", 3);
+
+ cache.Put(1, person);
+
+ Person person0 = cache.Get(1);
+
+ BOOST_REQUIRE(person.age == person0.age);
+ BOOST_REQUIRE(person.name.compare(person0.name) == 0);
+}
+
+BOOST_AUTO_TEST_CASE(TestCreateCache)
+{
+ // Create new cache
+ cache::Cache<int, int> cache = grid0.CreateCache<int, int>("dynamic_cache");
+
+ cache.Put(5, 7);
+
+ BOOST_REQUIRE(7 == cache.Get(5));
+
+ // Attempt to create cache with existing name
+ IgniteError err;
+
+ grid0.CreateCache<int, int>("dynamic_cache", &err);
+
+ BOOST_REQUIRE(err.GetCode() != IgniteError::IGNITE_SUCCESS);
+}
+
+BOOST_AUTO_TEST_CASE(TestGetOrCreateCache)
+{
+ // Get existing cache
+ cache::Cache<int, int> cache = grid0.GetOrCreateCache<int, int>("partitioned");
+
+ cache.Put(5, 7);
+
+ BOOST_REQUIRE(7 == cache.Get(5));
+
+ // Create new cache
+ cache::Cache<int, int> cache2 = grid0.GetOrCreateCache<int, int>("partitioned_new");
+
+ cache2.Put(5, 7);
+
+ BOOST_REQUIRE(7 == cache2.Get(5));
+}
+
+BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/src/concurrent_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/src/concurrent_test.cpp b/modules/platform/src/main/cpp/core-test/src/concurrent_test.cpp
new file mode 100644
index 0000000..2d89b7a
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/src/concurrent_test.cpp
@@ -0,0 +1,186 @@
+/*
+ * 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.
+ */
+
+#ifndef _MSC_VER
+ #define BOOST_TEST_DYN_LINK
+#endif
+
+#include <boost/test/unit_test.hpp>
+
+#include <ignite/common/concurrent.h>
+
+using namespace ignite::common::concurrent;
+
+BOOST_AUTO_TEST_SUITE(ConcurrentTestSuite)
+
+BOOST_AUTO_TEST_CASE(TestAtomic32)
+{
+ int32_t val = 1;
+
+ BOOST_REQUIRE(Atomics::CompareAndSet32(&val, 1, 2));
+ BOOST_REQUIRE(val == 2);
+
+ BOOST_REQUIRE(!Atomics::CompareAndSet32(&val, 3, 1));
+ BOOST_REQUIRE(val == 2);
+
+ BOOST_REQUIRE(Atomics::CompareAndSet32Val(&val, 2, 3) == 2);
+ BOOST_REQUIRE(val == 3);
+
+ BOOST_REQUIRE(Atomics::CompareAndSet32Val(&val, 4, 2) == 3);
+ BOOST_REQUIRE(val == 3);
+
+ BOOST_REQUIRE(Atomics::IncrementAndGet32(&val) == 4);
+ BOOST_REQUIRE(val == 4);
+
+ BOOST_REQUIRE(Atomics::DecrementAndGet32(&val) == 3);
+ BOOST_REQUIRE(val == 3);
+}
+
+BOOST_AUTO_TEST_CASE(TestAtomic64)
+{
+ int64_t val = 1;
+
+ BOOST_REQUIRE(Atomics::CompareAndSet64(&val, 1, 2));
+ BOOST_REQUIRE(val == 2);
+
+ BOOST_REQUIRE(!Atomics::CompareAndSet64(&val, 3, 1));
+ BOOST_REQUIRE(val == 2);
+
+ BOOST_REQUIRE(Atomics::CompareAndSet64Val(&val, 2, 3) == 2);
+ BOOST_REQUIRE(val == 3);
+
+ BOOST_REQUIRE(Atomics::CompareAndSet64Val(&val, 4, 2) == 3);
+ BOOST_REQUIRE(val == 3);
+
+ BOOST_REQUIRE(Atomics::IncrementAndGet64(&val) == 4);
+ BOOST_REQUIRE(val == 4);
+
+ BOOST_REQUIRE(Atomics::DecrementAndGet64(&val) == 3);
+ BOOST_REQUIRE(val == 3);
+}
+
+BOOST_AUTO_TEST_CASE(TestThreadLocal)
+{
+ int32_t idx1 = ThreadLocal::NextIndex();
+ int32_t idx2 = ThreadLocal::NextIndex();
+ BOOST_REQUIRE(idx2 > idx1);
+
+ BOOST_REQUIRE(ThreadLocal::Get<int32_t>(idx1) == 0);
+
+ ThreadLocal::Set(idx1, 1);
+ BOOST_REQUIRE(ThreadLocal::Get<int32_t>(idx1) == 1);
+
+ ThreadLocal::Set(idx1, 2);
+ BOOST_REQUIRE(ThreadLocal::Get<int32_t>(idx1) == 2);
+
+ ThreadLocal::Remove(idx1);
+ BOOST_REQUIRE(ThreadLocal::Get<int32_t>(idx1) == 0);
+
+ ThreadLocal::Set(idx1, 1);
+ BOOST_REQUIRE(ThreadLocal::Get<int32_t>(idx1) == 1);
+
+ ThreadLocal::Remove(idx1);
+}
+
+BOOST_AUTO_TEST_CASE(TestThreadLocalInstance)
+{
+ ThreadLocalInstance<int32_t> val;
+
+ BOOST_REQUIRE(val.Get() == 0);
+
+ val.Set(1);
+ BOOST_REQUIRE(val.Get() == 1);
+
+ val.Set(2);
+ BOOST_REQUIRE(val.Get() == 2);
+
+ val.Remove();
+ BOOST_REQUIRE(val.Get() == 0);
+
+ val.Set(1);
+ BOOST_REQUIRE(val.Get() == 1);
+
+ val.Remove();
+}
+
+struct SharedPointerTarget
+{
+ bool deleted;
+
+ SharedPointerTarget() : deleted(false)
+ {
+ // No-op.
+ }
+};
+
+void DeleteSharedPointerTarget(SharedPointerTarget* ptr)
+{
+ ptr->deleted = true;
+}
+
+BOOST_AUTO_TEST_CASE(TestSharedPointer)
+{
+ // 1. Test the simples scenario.
+ SharedPointerTarget* target = new SharedPointerTarget();
+
+ SharedPointer<SharedPointerTarget>* ptr1 =
+ new SharedPointer<SharedPointerTarget>(target, DeleteSharedPointerTarget);
+
+ delete ptr1;
+ BOOST_REQUIRE(target->deleted);
+
+ target->deleted = false;
+
+ // 2. Test copy ctor.
+ ptr1 = new SharedPointer<SharedPointerTarget>(target, DeleteSharedPointerTarget);
+ SharedPointer<SharedPointerTarget>* ptr2 = new SharedPointer<SharedPointerTarget>(*ptr1);
+
+ delete ptr1;
+ BOOST_REQUIRE(!target->deleted);
+
+ delete ptr2;
+ BOOST_REQUIRE(target->deleted);
+
+ target->deleted = false;
+
+ // 3. Test assignment logic.
+ ptr1 = new SharedPointer<SharedPointerTarget>(target, DeleteSharedPointerTarget);
+
+ SharedPointer<SharedPointerTarget> ptr3 = *ptr1;
+
+ delete ptr1;
+ BOOST_REQUIRE(!target->deleted);
+
+ ptr3 = SharedPointer<SharedPointerTarget>();
+ BOOST_REQUIRE(target->deleted);
+
+ target->deleted = false;
+
+ // 4. Test self-assignment.
+ ptr1 = new SharedPointer<SharedPointerTarget>(target, DeleteSharedPointerTarget);
+
+ *ptr1 = *ptr1;
+
+ delete ptr1;
+
+ BOOST_REQUIRE(target->deleted);
+
+ // 5. Tear-down.
+ delete target;
+}
+
+BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/src/handle_registry_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/src/handle_registry_test.cpp b/modules/platform/src/main/cpp/core-test/src/handle_registry_test.cpp
new file mode 100644
index 0000000..bc4a654
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/src/handle_registry_test.cpp
@@ -0,0 +1,176 @@
+/*
+ * 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.
+ */
+
+#ifndef _MSC_VER
+ #define BOOST_TEST_DYN_LINK
+#endif
+
+#include <boost/test/unit_test.hpp>
+
+#include "ignite/impl/handle_registry.h"
+
+using namespace ignite::common::concurrent;
+using namespace ignite::impl;
+
+struct HandleRegistryTestProbe
+{
+ bool deleted;
+
+ HandleRegistryTestProbe()
+ {
+ deleted = false;
+ }
+};
+
+class HandleRegistryTestEntry : public HandleRegistryEntry
+{
+public:
+ HandleRegistryTestEntry(HandleRegistryTestProbe* probe) : probe(probe)
+ {
+ // No-op.
+ }
+
+ virtual ~HandleRegistryTestEntry()
+ {
+ probe->deleted = true;
+ }
+
+private:
+ HandleRegistryTestProbe* probe;
+};
+
+BOOST_AUTO_TEST_SUITE(HandleRegistryTestSuite)
+
+BOOST_AUTO_TEST_CASE(TestCritical)
+{
+ HandleRegistry reg(2, 1);
+
+ HandleRegistryTestProbe probe0;
+ HandleRegistryTestProbe probe1;
+ HandleRegistryTestProbe probe2;
+
+ HandleRegistryTestEntry* entry0 = new HandleRegistryTestEntry(&probe0);
+ HandleRegistryTestEntry* entry1 = new HandleRegistryTestEntry(&probe1);
+ HandleRegistryTestEntry* entry2 = new HandleRegistryTestEntry(&probe2);
+
+ int64_t hnd0 = reg.AllocateCritical(SharedPointer<HandleRegistryEntry>(entry0));
+ int64_t hnd1 = reg.AllocateCritical(SharedPointer<HandleRegistryEntry>(entry1));
+ int64_t hnd2 = reg.AllocateCritical(SharedPointer<HandleRegistryEntry>(entry2));
+
+ BOOST_REQUIRE(reg.Get(hnd0).Get() == entry0);
+ BOOST_REQUIRE(!probe0.deleted);
+
+ BOOST_REQUIRE(reg.Get(hnd1).Get() == entry1);
+ BOOST_REQUIRE(!probe1.deleted);
+
+ BOOST_REQUIRE(reg.Get(hnd2).Get() == entry2);
+ BOOST_REQUIRE(!probe2.deleted);
+
+ reg.Release(hnd0);
+
+ BOOST_REQUIRE(reg.Get(hnd0).Get() == NULL);
+ BOOST_REQUIRE(probe0.deleted);
+
+ BOOST_REQUIRE(reg.Get(hnd1).Get() == entry1);
+ BOOST_REQUIRE(!probe1.deleted);
+
+ BOOST_REQUIRE(reg.Get(hnd2).Get() == entry2);
+ BOOST_REQUIRE(!probe2.deleted);
+
+ reg.Close();
+
+ BOOST_REQUIRE(reg.Get(hnd0).Get() == NULL);
+ BOOST_REQUIRE(probe0.deleted);
+
+ BOOST_REQUIRE(reg.Get(hnd1).Get() == NULL);
+ BOOST_REQUIRE(probe1.deleted);
+
+ BOOST_REQUIRE(reg.Get(hnd2).Get() == NULL);
+ BOOST_REQUIRE(probe2.deleted);
+
+ HandleRegistry closedReg(2, 1);
+
+ closedReg.Close();
+
+ HandleRegistryTestProbe closedProbe;
+ HandleRegistryTestEntry* closedEntry = new HandleRegistryTestEntry(&closedProbe);
+
+ int64_t closedHnd = closedReg.AllocateCritical(SharedPointer<HandleRegistryEntry>(closedEntry));
+ BOOST_REQUIRE(closedHnd == -1);
+ BOOST_REQUIRE(closedProbe.deleted);
+}
+
+BOOST_AUTO_TEST_CASE(TestNonCritical)
+{
+ HandleRegistry reg(0, 2);
+
+ HandleRegistryTestProbe probe0;
+ HandleRegistryTestProbe probe1;
+ HandleRegistryTestProbe probe2;
+
+ HandleRegistryTestEntry* entry0 = new HandleRegistryTestEntry(&probe0);
+ HandleRegistryTestEntry* entry1 = new HandleRegistryTestEntry(&probe1);
+ HandleRegistryTestEntry* entry2 = new HandleRegistryTestEntry(&probe2);
+
+ int64_t hnd0 = reg.AllocateCritical(SharedPointer<HandleRegistryEntry>(entry0));
+ int64_t hnd1 = reg.Allocate(SharedPointer<HandleRegistryEntry>(entry1));
+ int64_t hnd2 = reg.Allocate(SharedPointer<HandleRegistryEntry>(entry2));
+
+ BOOST_REQUIRE(reg.Get(hnd0).Get() == entry0);
+ BOOST_REQUIRE(!probe0.deleted);
+
+ BOOST_REQUIRE(reg.Get(hnd1).Get() == entry1);
+ BOOST_REQUIRE(!probe1.deleted);
+
+ BOOST_REQUIRE(reg.Get(hnd2).Get() == entry2);
+ BOOST_REQUIRE(!probe2.deleted);
+
+ reg.Release(hnd0);
+
+ BOOST_REQUIRE(reg.Get(hnd0).Get() == NULL);
+ BOOST_REQUIRE(probe0.deleted);
+
+ BOOST_REQUIRE(reg.Get(hnd1).Get() == entry1);
+ BOOST_REQUIRE(!probe1.deleted);
+
+ BOOST_REQUIRE(reg.Get(hnd2).Get() == entry2);
+ BOOST_REQUIRE(!probe2.deleted);
+
+ reg.Close();
+
+ BOOST_REQUIRE(reg.Get(hnd0).Get() == NULL);
+ BOOST_REQUIRE(probe0.deleted);
+
+ BOOST_REQUIRE(reg.Get(hnd1).Get() == NULL);
+ BOOST_REQUIRE(probe1.deleted);
+
+ BOOST_REQUIRE(reg.Get(hnd2).Get() == NULL);
+ BOOST_REQUIRE(probe2.deleted);
+
+ HandleRegistry closedReg(0, 2);
+
+ closedReg.Close();
+
+ HandleRegistryTestProbe closedProbe;
+ HandleRegistryTestEntry* closedEntry = new HandleRegistryTestEntry(&closedProbe);
+
+ int64_t closedHnd = closedReg.Allocate(SharedPointer<HandleRegistryEntry>(closedEntry));
+ BOOST_REQUIRE(closedHnd == -1);
+ BOOST_REQUIRE(closedProbe.deleted);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/src/ignition_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/src/ignition_test.cpp b/modules/platform/src/main/cpp/core-test/src/ignition_test.cpp
new file mode 100644
index 0000000..f55977a
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/src/ignition_test.cpp
@@ -0,0 +1,97 @@
+/*
+ * 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.
+ */
+
+#ifndef _MSC_VER
+ #define BOOST_TEST_DYN_LINK
+#endif
+
+#include <boost/test/unit_test.hpp>
+
+#include "ignite/ignite.h"
+#include "ignite/ignition.h"
+
+using namespace ignite;
+using namespace boost::unit_test;
+
+BOOST_AUTO_TEST_SUITE(IgnitionTestSuite)
+
+BOOST_AUTO_TEST_CASE(TestIgnition)
+{
+ IgniteConfiguration cfg;
+
+ IgniteJvmOption opts[5];
+
+ opts[0] = IgniteJvmOption("-Xdebug");
+ opts[1] = IgniteJvmOption("-Xnoagent");
+ opts[2] = IgniteJvmOption("-Djava.compiler=NONE");
+ opts[3] = IgniteJvmOption("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005");
+ opts[4] = IgniteJvmOption("-XX:+HeapDumpOnOutOfMemoryError");
+
+ cfg.jvmOptsLen = 5;
+ cfg.jvmOpts = opts;
+
+ cfg.jvmInitMem = 1024;
+ cfg.jvmMaxMem = 4096;
+
+ char* cfgPath = getenv("IGNITE_NATIVE_TEST_CPP_CONFIG_PATH");
+
+ std::string cfgPathStr = std::string(cfgPath).append("/").append("cache-test.xml");
+
+ cfg.springCfgPath = const_cast<char*>(cfgPathStr.c_str());
+
+ IgniteError err;
+
+ // Start two Ignite instances.
+ Ignite grid1 = Ignition::Start(cfg, "ignitionTest-1", &err);
+
+ if (err.GetCode() != IgniteError::IGNITE_SUCCESS)
+ BOOST_ERROR(err.GetText());
+
+ BOOST_REQUIRE(strcmp(grid1.GetName(), "ignitionTest-1") == 0);
+
+ Ignite grid2 = Ignition::Start(cfg, "ignitionTest-2", &err);
+
+ if (err.GetCode() != IgniteError::IGNITE_SUCCESS)
+ BOOST_ERROR(err.GetText());
+
+ BOOST_REQUIRE(strcmp(grid2.GetName(), "ignitionTest-2") == 0);
+
+ // Test get
+ Ignite grid0 = Ignition::Get("ignitionTest-1", &err);
+
+ if (err.GetCode() != IgniteError::IGNITE_SUCCESS)
+ BOOST_ERROR(err.GetText());
+
+ BOOST_REQUIRE(strcmp(grid0.GetName(), grid1.GetName()) == 0);
+
+ // Stop one grid
+ Ignition::Stop(grid1.GetName(), true);
+
+ Ignition::Get("ignitionTest-1", &err);
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_GENERIC);
+
+ Ignition::Get("ignitionTest-2", &err);
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_SUCCESS);
+
+ // Stop all
+ Ignition::StopAll(true);
+
+ Ignition::Get("ignitionTest-2", &err);
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_GENERIC);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core-test/src/portable_reader_writer_raw_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core-test/src/portable_reader_writer_raw_test.cpp b/modules/platform/src/main/cpp/core-test/src/portable_reader_writer_raw_test.cpp
new file mode 100644
index 0000000..c3a98aa
--- /dev/null
+++ b/modules/platform/src/main/cpp/core-test/src/portable_reader_writer_raw_test.cpp
@@ -0,0 +1,1532 @@
+/*
+ * 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.
+ */
+
+#ifndef _MSC_VER
+ #define BOOST_TEST_DYN_LINK
+#endif
+
+#include <boost/test/unit_test.hpp>
+
+#include "ignite/impl/interop/interop.h"
+#include "ignite/portable/portable.h"
+
+#include "ignite/portable_test_defs.h"
+#include "ignite/portable_test_utils.h"
+
+using namespace ignite;
+using namespace ignite::impl::interop;
+using namespace ignite::impl::portable;
+using namespace ignite::portable;
+using namespace ignite_test::core::portable;
+
+template<typename T>
+void CheckRawPrimitive(T val)
+{
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ Write<T>(rawWriter, val);
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ T readVal = Read<T>(rawReader);
+
+ BOOST_REQUIRE(readVal == val);
+}
+
+template<typename T>
+void CheckRawPrimitiveArray(T dflt, T val1, T val2)
+{
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ // 1. Write NULL and see what happens.
+ WriteArray<T>(rawWriter, NULL, 0);
+
+ out.Synchronize();
+ in.Synchronize();
+
+ BOOST_REQUIRE(ReadArray<T>(rawReader, NULL, 0) == -1);
+
+ in.Position(0);
+ BOOST_REQUIRE(ReadArray<T>(rawReader, NULL, 2) == -1);
+
+ T arr1[2];
+ arr1[0] = dflt;
+ arr1[1] = dflt;
+
+ in.Position(0);
+ BOOST_REQUIRE(ReadArray<T>(rawReader, arr1, 1) == -1);
+
+ BOOST_REQUIRE(arr1[0] == dflt);
+ BOOST_REQUIRE(arr1[1] == dflt);
+
+ // 2. Write empty array.
+ T arr2[2];
+ arr2[0] = val1;
+ arr2[1] = val2;
+
+ out.Position(0);
+ in.Position(0);
+
+ WriteArray<T>(rawWriter, arr2, 0);
+
+ out.Synchronize();
+ in.Synchronize();
+
+ BOOST_REQUIRE(ReadArray<T>(rawReader, NULL, 0) == 0);
+
+ in.Position(0);
+ BOOST_REQUIRE(ReadArray<T>(rawReader, NULL, 2) == 0);
+
+ in.Position(0);
+ BOOST_REQUIRE(ReadArray<T>(rawReader, arr1, 0) == 0);
+ BOOST_REQUIRE(arr1[0] == dflt);
+ BOOST_REQUIRE(arr1[1] == dflt);
+
+ in.Position(0);
+ BOOST_REQUIRE(ReadArray<T>(rawReader, arr1, 2) == 0);
+ BOOST_REQUIRE(arr1[0] == dflt);
+ BOOST_REQUIRE(arr1[1] == dflt);
+
+ // 3. Partial array write.
+ out.Position(0);
+ in.Position(0);
+
+ WriteArray<T>(rawWriter, arr2, 1);
+
+ out.Synchronize();
+ in.Synchronize();
+
+ BOOST_REQUIRE(ReadArray<T>(rawReader, NULL, 0) == 1);
+ BOOST_REQUIRE(ReadArray<T>(rawReader, NULL, 2) == 1);
+
+ BOOST_REQUIRE(ReadArray<T>(rawReader, arr1, 0) == 1);
+ BOOST_REQUIRE(arr1[0] == dflt);
+ BOOST_REQUIRE(arr1[1] == dflt);
+
+ BOOST_REQUIRE(ReadArray<T>(rawReader, arr1, 1) == 1);
+ BOOST_REQUIRE(arr1[0] == val1);
+ BOOST_REQUIRE(arr1[1] == dflt);
+ arr1[0] = dflt;
+
+ in.Position(0);
+ BOOST_REQUIRE(ReadArray<T>(rawReader, arr1, 2) == 1);
+ BOOST_REQUIRE(arr1[0] == val1);
+ BOOST_REQUIRE(arr1[1] == dflt);
+ arr1[0] = dflt;
+
+ // 4. Full array write.
+ out.Position(0);
+ in.Position(0);
+
+ WriteArray<T>(rawWriter, arr2, 2);
+
+ out.Synchronize();
+ in.Synchronize();
+
+ BOOST_REQUIRE(ReadArray<T>(rawReader, NULL, 0) == 2);
+ BOOST_REQUIRE(ReadArray<T>(rawReader, NULL, 2) == 2);
+
+ BOOST_REQUIRE(ReadArray<T>(rawReader, arr1, 0) == 2);
+ BOOST_REQUIRE(arr1[0] == dflt);
+ BOOST_REQUIRE(arr1[1] == dflt);
+
+ BOOST_REQUIRE(ReadArray<T>(rawReader, arr1, 1) == 2);
+ BOOST_REQUIRE(arr1[0] == dflt);
+ BOOST_REQUIRE(arr1[1] == dflt);
+
+ BOOST_REQUIRE(ReadArray<T>(rawReader, arr1, 2) == 2);
+ BOOST_REQUIRE(arr1[0] == val1);
+ BOOST_REQUIRE(arr1[1] == val2);
+}
+
+void CheckRawWritesRestricted(PortableRawWriter& writer)
+{
+ try
+ {
+ writer.WriteInt8(1);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ int8_t arr[1];
+
+ writer.WriteInt8Array(arr, 1);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ Guid val(1, 1);
+
+ writer.WriteGuid(val);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ writer.WriteString("test");
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ writer.WriteArray<int8_t>();
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ writer.WriteCollection<int8_t>();
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ writer.WriteMap<int8_t, int8_t>();
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+}
+
+void CheckRawReadsRestricted(PortableRawReader& reader)
+{
+ try
+ {
+ reader.ReadInt8();
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ int8_t arr[1];
+
+ reader.ReadInt8Array(arr, 1);
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ reader.ReadGuid();
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ reader.ReadString();
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ reader.ReadArray<int8_t>();
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ reader.ReadCollection<int8_t>();
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ reader.ReadMap<int8_t, int8_t>();
+
+ BOOST_FAIL("Not restricted.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+}
+
+void CheckRawCollectionEmpty(CollectionType* colType)
+{
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ PortableCollectionWriter<PortableInner> colWriter = colType ?
+ rawWriter.WriteCollection<PortableInner>(*colType) : rawWriter.WriteCollection<PortableInner>();
+
+ CheckRawWritesRestricted(rawWriter);
+
+ colWriter.Close();
+
+ rawWriter.WriteInt8(1);
+
+ try
+ {
+ colWriter.Write(1);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ colWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ PortableCollectionReader<PortableInner> colReader = rawReader.ReadCollection<PortableInner>();
+
+ if (colType)
+ BOOST_REQUIRE(colReader.GetType() == *colType);
+ else
+ BOOST_REQUIRE(colReader.GetType() == IGNITE_COLLECTION_UNDEFINED);
+
+ BOOST_REQUIRE(colReader.GetSize() == 0);
+ BOOST_REQUIRE(!colReader.HasNext());
+ BOOST_REQUIRE(!colReader.IsNull());
+
+ try
+ {
+ colReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(rawReader.ReadInt8() == 1);
+}
+
+void CheckRawCollection(CollectionType* colType)
+{
+ PortableInner writeVal1 = PortableInner(1);
+ PortableInner writeVal2 = PortableInner(0);
+ PortableInner writeVal3 = PortableInner(2);
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ PortableCollectionWriter<PortableInner> colWriter = colType ?
+ rawWriter.WriteCollection<PortableInner>(*colType) : rawWriter.WriteCollection<PortableInner>();
+
+ colWriter.Write(writeVal1);
+ colWriter.Write(writeVal2);
+ colWriter.Write(writeVal3);
+
+ CheckRawWritesRestricted(rawWriter);
+
+ colWriter.Close();
+
+ rawWriter.WriteInt8(1);
+
+ try
+ {
+ colWriter.Write(1);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ colWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ PortableCollectionReader<PortableInner> colReader = rawReader.ReadCollection<PortableInner>();
+
+ CheckRawReadsRestricted(rawReader);
+
+ if (colType)
+ BOOST_REQUIRE(colReader.GetType() == *colType);
+ else
+ BOOST_REQUIRE(colReader.GetType() == IGNITE_COLLECTION_UNDEFINED);
+
+ BOOST_REQUIRE(colReader.GetSize() == 3);
+ BOOST_REQUIRE(!colReader.IsNull());
+
+ BOOST_REQUIRE(colReader.HasNext());
+ BOOST_REQUIRE(colReader.GetNext().GetValue() == writeVal1.GetValue());
+
+ BOOST_REQUIRE(colReader.HasNext());
+ BOOST_REQUIRE(colReader.GetNext().GetValue() == writeVal2.GetValue());
+
+ BOOST_REQUIRE(colReader.HasNext());
+ BOOST_REQUIRE(colReader.GetNext().GetValue() == writeVal3.GetValue());
+
+ BOOST_REQUIRE(!colReader.HasNext());
+
+ try
+ {
+ colReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(rawReader.ReadInt8() == 1);
+}
+
+void CheckRawMapEmpty(MapType* mapType)
+{
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ PortableMapWriter<int8_t, PortableInner> mapWriter = mapType ?
+ rawWriter.WriteMap<int8_t, PortableInner>(*mapType) : rawWriter.WriteMap<int8_t, PortableInner>();
+
+ CheckRawWritesRestricted(rawWriter);
+
+ mapWriter.Close();
+
+ rawWriter.WriteInt8(1);
+
+ try
+ {
+ mapWriter.Write(1, PortableInner(1));
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ mapWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ PortableMapReader<int8_t, PortableInner> mapReader = rawReader.ReadMap<int8_t, PortableInner>();
+
+ if (mapType)
+ BOOST_REQUIRE(mapReader.GetType() == *mapType);
+ else
+ BOOST_REQUIRE(mapReader.GetType() == IGNITE_MAP_UNDEFINED);
+
+ BOOST_REQUIRE(mapReader.GetSize() == 0);
+ BOOST_REQUIRE(!mapReader.HasNext());
+ BOOST_REQUIRE(!mapReader.IsNull());
+
+ try
+ {
+ int8_t key;
+ PortableInner val;
+
+ mapReader.GetNext(&key, &val);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(rawReader.ReadInt8() == 1);
+}
+
+void CheckRawMap(MapType* mapType)
+{
+ PortableInner writeVal1 = PortableInner(1);
+ PortableInner writeVal2 = PortableInner(0);
+ PortableInner writeVal3 = PortableInner(2);
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ PortableMapWriter<int8_t, PortableInner> mapWriter = mapType ?
+ rawWriter.WriteMap<int8_t, PortableInner>(*mapType) : rawWriter.WriteMap<int8_t, PortableInner>();
+
+ mapWriter.Write(1, writeVal1);
+ mapWriter.Write(2, writeVal2);
+ mapWriter.Write(3, writeVal3);
+
+ CheckRawWritesRestricted(rawWriter);
+
+ mapWriter.Close();
+
+ rawWriter.WriteInt8(1);
+
+ try
+ {
+ mapWriter.Write(4, PortableInner(4));
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ mapWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ PortableMapReader<int8_t, PortableInner> mapReader = rawReader.ReadMap<int8_t, PortableInner>();
+
+ CheckRawReadsRestricted(rawReader);
+
+ if (mapType)
+ BOOST_REQUIRE(mapReader.GetType() == *mapType);
+ else
+ BOOST_REQUIRE(mapReader.GetType() == IGNITE_MAP_UNDEFINED);
+
+ BOOST_REQUIRE(mapReader.GetSize() == 3);
+ BOOST_REQUIRE(!mapReader.IsNull());
+
+ int8_t key;
+ PortableInner val;
+
+ BOOST_REQUIRE(mapReader.HasNext());
+
+ mapReader.GetNext(&key, &val);
+ BOOST_REQUIRE(key == 1);
+ BOOST_REQUIRE(val.GetValue() == writeVal1.GetValue());
+
+ mapReader.GetNext(&key, &val);
+ BOOST_REQUIRE(key == 2);
+ BOOST_REQUIRE(val.GetValue() == writeVal2.GetValue());
+
+ mapReader.GetNext(&key, &val);
+ BOOST_REQUIRE(key == 3);
+ BOOST_REQUIRE(val.GetValue() == writeVal3.GetValue());
+
+ BOOST_REQUIRE(!mapReader.HasNext());
+
+ try
+ {
+ mapReader.GetNext(&key, &val);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(rawReader.ReadInt8() == 1);
+}
+
+BOOST_AUTO_TEST_SUITE(PortableReaderWriterRawTestSuite)
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveInt8)
+{
+ CheckRawPrimitive<int8_t>(1);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveBool)
+{
+ CheckRawPrimitive<bool>(true);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveInt16)
+{
+ CheckRawPrimitive<int16_t>(1);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveUInt16)
+{
+ CheckRawPrimitive<uint16_t>(1);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveInt32)
+{
+ CheckRawPrimitive<int32_t>(1);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveInt64)
+{
+ CheckRawPrimitive<int64_t>(1);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveFloat)
+{
+ CheckRawPrimitive<float>(1.1f);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveDouble)
+{
+ CheckRawPrimitive<double>(1.1);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveGuid)
+{
+ Guid val(1, 2);
+
+ CheckRawPrimitive<Guid>(val);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayInt8)
+{
+ CheckRawPrimitiveArray<int8_t>(1, 2, 3);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayBool)
+{
+ CheckRawPrimitiveArray<bool>(false, true, false);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayInt16)
+{
+ CheckRawPrimitiveArray<int16_t>(1, 2, 3);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayUInt16)
+{
+ CheckRawPrimitiveArray<uint16_t>(1, 2, 3);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayInt32)
+{
+ CheckRawPrimitiveArray<int32_t>(1, 2, 3);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayInt64)
+{
+ CheckRawPrimitiveArray<int64_t>(1, 2, 3);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayFloat)
+{
+ CheckRawPrimitiveArray<float>(1.1f, 2.2f, 3.3f);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayDouble)
+{
+ CheckRawPrimitiveArray<double>(1.1, 2.2, 3.3);
+}
+
+BOOST_AUTO_TEST_CASE(TestPrimitiveArrayGuid)
+{
+ Guid dflt(1, 2);
+ Guid val1(3, 4);
+ Guid val2(5, 6);
+
+ CheckRawPrimitiveArray<Guid>(dflt, val1, val2);
+}
+
+BOOST_AUTO_TEST_CASE(TestGuidNull)
+{
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ rawWriter.WriteNull();
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ Guid expVal;
+ Guid actualVal = rawReader.ReadGuid();
+
+ BOOST_REQUIRE(actualVal == expVal);
+}
+
+BOOST_AUTO_TEST_CASE(TestString) {
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ const char* writeVal1 = "testtest";
+ const char* writeVal2 = "test";
+ std::string writeVal3 = writeVal1;
+
+ rawWriter.WriteString(writeVal1);
+ rawWriter.WriteString(writeVal1, 4);
+ rawWriter.WriteString(writeVal3);
+ rawWriter.WriteString(NULL);
+ rawWriter.WriteString(NULL, 4);
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ char readVal1[9];
+ char readVal2[5];
+
+ BOOST_REQUIRE(rawReader.ReadString(NULL, 0) == 8);
+ BOOST_REQUIRE(rawReader.ReadString(NULL, 8) == 8);
+ BOOST_REQUIRE(rawReader.ReadString(readVal1, 0) == 8);
+ BOOST_REQUIRE(rawReader.ReadString(readVal1, 4) == 8);
+
+ BOOST_REQUIRE(rawReader.ReadString(readVal1, 9) == 8);
+ std::string writeVal1Str = writeVal1;
+ std::string readVal1Str = readVal1;
+ BOOST_REQUIRE(readVal1Str.compare(writeVal1Str) == 0);
+
+ BOOST_REQUIRE(rawReader.ReadString(readVal2, 5) == 4);
+ std::string writeVal2Str = writeVal2;
+ std::string readVal2Str = readVal2;
+ BOOST_REQUIRE(readVal2Str.compare(writeVal2Str) == 0);
+
+ std::string readVal3 = rawReader.ReadString();
+ BOOST_REQUIRE(readVal3.compare(writeVal3) == 0);
+
+ BOOST_REQUIRE(rawReader.ReadString(readVal1, 9) == -1);
+ BOOST_REQUIRE(rawReader.ReadString(readVal1, 9) == -1);
+}
+
+BOOST_AUTO_TEST_CASE(TestStringArrayNull)
+{
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ rawWriter.WriteNull();
+ rawWriter.WriteInt8(1);
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ PortableStringArrayReader arrReader = rawReader.ReadStringArray();
+
+ BOOST_REQUIRE(arrReader.GetSize() == -1);
+ BOOST_REQUIRE(!arrReader.HasNext());
+ BOOST_REQUIRE(arrReader.IsNull());
+
+ try
+ {
+ char res[100];
+
+ arrReader.GetNext(res, 100);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ arrReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(rawReader.ReadInt8() == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestStringArrayEmpty)
+{
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ PortableStringArrayWriter arrWriter = rawWriter.WriteStringArray();
+
+ CheckRawWritesRestricted(rawWriter);
+
+ arrWriter.Close();
+
+ rawWriter.WriteInt8(1);
+
+ try
+ {
+ const char* val = "test";
+
+ arrWriter.Write(val, 4);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ const char* val = "test";
+
+ arrWriter.Write(val);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ std::string val = "test";
+
+ arrWriter.Write(val);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ arrWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ PortableStringArrayReader arrReader = rawReader.ReadStringArray();
+
+ BOOST_REQUIRE(arrReader.GetSize() == 0);
+ BOOST_REQUIRE(!arrReader.HasNext());
+ BOOST_REQUIRE(!arrReader.IsNull());
+
+ try
+ {
+ char res[100];
+
+ arrReader.GetNext(res, 100);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ arrReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(rawReader.ReadInt8() == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestStringArray)
+{
+ const char* writeVal1 = "testtest";
+ const char* writeVal2 = "test";
+ std::string writeVal3 = "test2";
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ PortableStringArrayWriter arrWriter = rawWriter.WriteStringArray();
+
+ arrWriter.Write(writeVal1);
+ arrWriter.Write(writeVal1, 4);
+ arrWriter.Write(NULL); // NULL value.
+ arrWriter.Write(NULL, 100); // NULL value again.
+ arrWriter.Write(writeVal3);
+
+ CheckRawWritesRestricted(rawWriter);
+
+ arrWriter.Close();
+
+ rawWriter.WriteInt8(1);
+
+ try
+ {
+ const char* val = "test";
+
+ arrWriter.Write(val, 4);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ const char* val = "test";
+
+ arrWriter.Write(val);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ std::string val = "test";
+
+ arrWriter.Write(val);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ arrWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ PortableStringArrayReader arrReader = rawReader.ReadStringArray();
+
+ CheckRawReadsRestricted(rawReader);
+
+ BOOST_REQUIRE(arrReader.GetSize() == 5);
+ BOOST_REQUIRE(!arrReader.IsNull());
+
+ // 1. Read first value.
+ BOOST_REQUIRE(arrReader.HasNext());
+
+ char readVal1[9];
+
+ BOOST_REQUIRE(arrReader.GetNext(NULL, 0) == 8);
+ BOOST_REQUIRE(arrReader.GetNext(NULL, 8) == 8);
+ BOOST_REQUIRE(arrReader.GetNext(readVal1, 0) == 8);
+ BOOST_REQUIRE(arrReader.GetNext(readVal1, 4) == 8);
+
+ BOOST_REQUIRE(arrReader.GetNext(readVal1, 9) == 8);
+ std::string writeVal1Str = writeVal1;
+ std::string readVal1Str = readVal1;
+ BOOST_REQUIRE(readVal1Str.compare(writeVal1Str) == 0);
+
+ // 2. Read second value.
+ BOOST_REQUIRE(arrReader.HasNext());
+
+ char readVal2[5];
+
+ BOOST_REQUIRE(arrReader.GetNext(readVal2, 5) == 4);
+ std::string writeVal2Str = writeVal2;
+ std::string readVal2Str = readVal2;
+ BOOST_REQUIRE(readVal2Str.compare(writeVal2Str) == 0);
+
+ // 3. Read NULL.
+ BOOST_REQUIRE(arrReader.HasNext());
+
+ BOOST_REQUIRE(arrReader.GetNext(readVal1, 4) == -1);
+ readVal1Str = readVal1;
+ BOOST_REQUIRE(readVal1Str.compare(writeVal1Str) == 0);
+
+ // 4. Read NULL again, this time through another method.
+ BOOST_REQUIRE(arrReader.HasNext());
+
+ std::string readNullVal = arrReader.GetNext();
+
+ BOOST_REQUIRE(readNullVal.length() == 0);
+
+ // 5. Read third value.
+ BOOST_REQUIRE(arrReader.HasNext());
+
+ std::string readVal3 = arrReader.GetNext();
+ BOOST_REQUIRE(readVal3.compare(writeVal3) == 0);
+
+ BOOST_REQUIRE(!arrReader.HasNext());
+
+ try
+ {
+ char res[100];
+
+ arrReader.GetNext(res, 100);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ arrReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(rawReader.ReadInt8() == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestObject)
+{
+ PortableInner writeVal1(1);
+ PortableInner writeVal2(0);
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ rawWriter.WriteObject(writeVal1);
+ rawWriter.WriteObject(writeVal2);
+ rawWriter.WriteNull();
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ PortableInner readVal1 = rawReader.ReadObject<PortableInner>();
+ BOOST_REQUIRE(writeVal1.GetValue() == readVal1.GetValue());
+
+ PortableInner readVal2 = rawReader.ReadObject<PortableInner>();
+ BOOST_REQUIRE(writeVal2.GetValue() == readVal2.GetValue());
+
+ PortableInner readVal3 = rawReader.ReadObject<PortableInner>();
+ BOOST_REQUIRE(0 == readVal3.GetValue());
+}
+
+BOOST_AUTO_TEST_CASE(TestNestedObject)
+{
+ PortableOuter writeVal1(1, 2);
+ PortableOuter writeVal2(0, 0);
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ rawWriter.WriteObject(writeVal1);
+ rawWriter.WriteObject(writeVal2);
+ rawWriter.WriteNull();
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ PortableOuter readVal1 = rawReader.ReadObject<PortableOuter>();
+ BOOST_REQUIRE(writeVal1.GetValue() == readVal1.GetValue());
+ BOOST_REQUIRE(writeVal1.GetInner().GetValue() == readVal1.GetInner().GetValue());
+
+ PortableOuter readVal2 = rawReader.ReadObject<PortableOuter>();
+ BOOST_REQUIRE(writeVal2.GetValue() == readVal2.GetValue());
+ BOOST_REQUIRE(writeVal2.GetInner().GetValue() == readVal2.GetInner().GetValue());
+
+ PortableOuter readVal3 = rawReader.ReadObject<PortableOuter>();
+ BOOST_REQUIRE(0 == readVal3.GetValue());
+ BOOST_REQUIRE(0 == readVal3.GetInner().GetValue());
+}
+
+BOOST_AUTO_TEST_CASE(TestArrayNull)
+{
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ rawWriter.WriteNull();
+ rawWriter.WriteInt8(1);
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ PortableArrayReader<PortableInner> arrReader = rawReader.ReadArray<PortableInner>();
+
+ BOOST_REQUIRE(arrReader.GetSize() == -1);
+ BOOST_REQUIRE(!arrReader.HasNext());
+ BOOST_REQUIRE(arrReader.IsNull());
+
+ try
+ {
+ arrReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(rawReader.ReadInt8() == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestArrayEmpty)
+{
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ PortableArrayWriter<PortableInner> arrWriter = rawWriter.WriteArray<PortableInner>();
+
+ CheckRawWritesRestricted(rawWriter);
+
+ arrWriter.Close();
+
+ rawWriter.WriteInt8(1);
+
+ try
+ {
+ arrWriter.Write(1);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ arrWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ PortableArrayReader<PortableInner> arrReader = rawReader.ReadArray<PortableInner>();
+
+ BOOST_REQUIRE(arrReader.GetSize() == 0);
+ BOOST_REQUIRE(!arrReader.HasNext());
+ BOOST_REQUIRE(!arrReader.IsNull());
+
+ try
+ {
+ arrReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(rawReader.ReadInt8() == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestArray)
+{
+ PortableInner writeVal1 = PortableInner(1);
+ PortableInner writeVal2 = PortableInner(0);
+ PortableInner writeVal3 = PortableInner(2);
+
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ PortableArrayWriter<PortableInner> arrWriter = rawWriter.WriteArray<PortableInner>();
+
+ arrWriter.Write(writeVal1);
+ arrWriter.Write(writeVal2);
+ arrWriter.Write(writeVal3);
+
+ CheckRawWritesRestricted(rawWriter);
+
+ arrWriter.Close();
+
+ rawWriter.WriteInt8(1);
+
+ try
+ {
+ arrWriter.Write(1);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ try
+ {
+ arrWriter.Close();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ PortableArrayReader<PortableInner> arrReader = rawReader.ReadArray<PortableInner>();
+
+ CheckRawReadsRestricted(rawReader);
+
+ BOOST_REQUIRE(arrReader.GetSize() == 3);
+ BOOST_REQUIRE(!arrReader.IsNull());
+
+ BOOST_REQUIRE(arrReader.HasNext());
+ BOOST_REQUIRE(arrReader.GetNext().GetValue() == writeVal1.GetValue());
+
+ BOOST_REQUIRE(arrReader.HasNext());
+ BOOST_REQUIRE(arrReader.GetNext().GetValue() == writeVal2.GetValue());
+
+ BOOST_REQUIRE(arrReader.HasNext());
+ BOOST_REQUIRE(arrReader.GetNext().GetValue() == writeVal3.GetValue());
+
+ BOOST_REQUIRE(!arrReader.HasNext());
+
+ try
+ {
+ arrReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(rawReader.ReadInt8() == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestCollectionNull)
+{
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ rawWriter.WriteNull();
+ rawWriter.WriteInt8(1);
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ PortableCollectionReader<PortableInner> colReader = rawReader.ReadCollection<PortableInner>();
+
+ BOOST_REQUIRE(colReader.GetType() == IGNITE_COLLECTION_UNDEFINED);
+ BOOST_REQUIRE(colReader.GetSize() == -1);
+ BOOST_REQUIRE(!colReader.HasNext());
+ BOOST_REQUIRE(colReader.IsNull());
+
+ try
+ {
+ colReader.GetNext();
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(rawReader.ReadInt8() == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestCollectionEmpty)
+{
+ CheckRawCollectionEmpty(NULL);
+}
+
+BOOST_AUTO_TEST_CASE(TestCollectionEmptyTyped)
+{
+ CollectionType typ = IGNITE_COLLECTION_CONCURRENT_SKIP_LIST_SET;
+
+ CheckRawCollectionEmpty(&typ);
+}
+
+BOOST_AUTO_TEST_CASE(TestCollection)
+{
+ CheckRawCollection(NULL);
+}
+
+BOOST_AUTO_TEST_CASE(testCollectionTyped)
+{
+ CollectionType typ = IGNITE_COLLECTION_CONCURRENT_SKIP_LIST_SET;
+
+ CheckRawCollection(&typ);
+}
+
+BOOST_AUTO_TEST_CASE(TestMapNull)
+{
+ InteropUnpooledMemory mem(1024);
+
+ InteropOutputStream out(&mem);
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ rawWriter.WriteNull();
+ rawWriter.WriteInt8(1);
+
+ out.Synchronize();
+
+ InteropInputStream in(&mem);
+ PortableReaderImpl reader(&in);
+ PortableRawReader rawReader(&reader);
+
+ PortableMapReader<int8_t, PortableInner> mapReader = rawReader.ReadMap<int8_t, PortableInner>();
+
+ BOOST_REQUIRE(mapReader.GetType() == IGNITE_MAP_UNDEFINED);
+ BOOST_REQUIRE(mapReader.GetSize() == -1);
+ BOOST_REQUIRE(!mapReader.HasNext());
+ BOOST_REQUIRE(mapReader.IsNull());
+
+ try
+ {
+ int8_t key;
+ PortableInner val;
+
+ mapReader.GetNext(&key, &val);
+
+ BOOST_FAIL("Error expected.");
+ }
+ catch (IgniteError& err)
+ {
+ BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE);
+ }
+
+ BOOST_REQUIRE(rawReader.ReadInt8() == 1);
+}
+
+BOOST_AUTO_TEST_CASE(TestMapEmpty)
+{
+ CheckRawMapEmpty(NULL);
+}
+
+BOOST_AUTO_TEST_CASE(TestMapEmptyTyped)
+{
+ MapType typ = IGNITE_MAP_CONCURRENT_HASH_MAP;
+
+ CheckRawMapEmpty(&typ);
+}
+
+BOOST_AUTO_TEST_CASE(TestMap)
+{
+ CheckRawMap(NULL);
+}
+
+BOOST_AUTO_TEST_CASE(TestMapTyped)
+{
+ MapType typ = IGNITE_MAP_CONCURRENT_HASH_MAP;
+
+ CheckRawMap(&typ);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
[05/11] ignite git commit: IGNITE-1364: Squashed commit from initial
branch.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_utils.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_utils.h b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_utils.h
new file mode 100644
index 0000000..dd16686
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_utils.h
@@ -0,0 +1,344 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL_PORTABLE_UTILS
+#define _IGNITE_IMPL_PORTABLE_UTILS
+
+#include <stdint.h>
+
+#include "ignite/guid.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace interop
+ {
+ class InteropInputStream;
+ class InteropOutputStream;
+ }
+
+ namespace portable
+ {
+ /**
+ * Portable uilts.
+ */
+ class IGNITE_IMPORT_EXPORT PortableUtils
+ {
+ public:
+ /**
+ * Utility method to read signed 8-bit integer from stream.
+ *
+ * @param stream Stream.
+ * @return Value.
+ */
+ static int8_t ReadInt8(interop::InteropInputStream* stream);
+
+ /**
+ * Utility method to write signed 8-bit integer to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ */
+ static void WriteInt8(interop::InteropOutputStream* stream, int8_t val);
+
+ /**
+ * Utility method to read signed 8-bit integer array from stream.
+ *
+ * @param stream Stream.
+ * @param res Target array.
+ * @param len Array length.
+ */
+ static void ReadInt8Array(interop::InteropInputStream* stream, int8_t* res, const int32_t len);
+
+ /**
+ * Utility method to write signed 8-bit integer array to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ * @param len Array length.
+ */
+ static void WriteInt8Array(interop::InteropOutputStream* stream, const int8_t* val, const int32_t len);
+
+ /**
+ * Utility method to read boolean from stream.
+ *
+ * @param stream Stream.
+ * @return Value.
+ */
+ static bool ReadBool(interop::InteropInputStream* stream);
+
+ /**
+ * Utility method to write bool to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ */
+ static void WriteBool(interop::InteropOutputStream* stream, bool val);
+
+ /**
+ * Utility method to read bool array from stream.
+ *
+ * @param stream Stream.
+ * @param res Target array.
+ * @param len Array length.
+ */
+ static void ReadBoolArray(interop::InteropInputStream* stream, bool* res, const int32_t len);
+
+ /**
+ * Utility method to write bool array to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ * @param len Array length.
+ */
+ static void WriteBoolArray(interop::InteropOutputStream* stream, const bool* val, const int32_t len);
+
+ /**
+ * Utility method to read signed 16-bit integer from stream.
+ *
+ * @param stream Stream.
+ * @return Value.
+ */
+ static int16_t ReadInt16(interop::InteropInputStream* stream);
+
+ /**
+ * Utility method to write signed 16-bit integer to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ */
+ static void WriteInt16(interop::InteropOutputStream* stream, int16_t val);
+
+ /**
+ * Utility method to read signed 16-bit integer array from stream.
+ *
+ * @param stream Stream.
+ * @param res Target array.
+ * @param len Array length.
+ */
+ static void ReadInt16Array(interop::InteropInputStream* stream, int16_t* res, const int32_t len);
+
+ /**
+ * Utility method to write signed 16-bit integer array to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ * @param len Array length.
+ */
+ static void WriteInt16Array(interop::InteropOutputStream* stream, const int16_t* val, const int32_t len);
+
+ /**
+ * Utility method to read unsigned 16-bit integer from stream.
+ *
+ * @param stream Stream.
+ * @return Value.
+ */
+ static uint16_t ReadUInt16(interop::InteropInputStream* stream);
+
+ /**
+ * Utility method to write unsigned 16-bit integer to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ */
+ static void WriteUInt16(interop::InteropOutputStream* stream, uint16_t val);
+
+ /**
+ * Utility method to read unsigned 16-bit integer array from stream.
+ *
+ * @param stream Stream.
+ * @param res Target array.
+ * @param len Array length.
+ */
+ static void ReadUInt16Array(interop::InteropInputStream* stream, uint16_t* res, const int32_t len);
+
+ /**
+ * Utility method to write unsigned 16-bit integer array to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ * @param len Array length.
+ */
+ static void WriteUInt16Array(interop::InteropOutputStream* stream, const uint16_t* val, const int32_t len);
+
+ /**
+ * Utility method to read signed 32-bit integer from stream.
+ *
+ * @param stream Stream.
+ * @return Value.
+ */
+ static int32_t ReadInt32(interop::InteropInputStream* stream);
+
+ /**
+ * Utility method to write signed 32-bit integer to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ */
+ static void WriteInt32(interop::InteropOutputStream* stream, int32_t val);
+
+ /**
+ * Utility method to read signed 32-bit integer array from stream.
+ *
+ * @param stream Stream.
+ * @param res Target array.
+ * @param len Array length.
+ */
+ static void ReadInt32Array(interop::InteropInputStream* stream, int32_t* res, const int32_t len);
+
+ /**
+ * Utility method to write signed 32-bit integer array to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ * @param len Array length.
+ */
+ static void WriteInt32Array(interop::InteropOutputStream* stream, const int32_t* val, const int32_t len);
+
+ /**
+ * Utility method to read signed 64-bit integer from stream.
+ *
+ * @param stream Stream.
+ * @return Value.
+ */
+ static int64_t ReadInt64(interop::InteropInputStream* stream);
+
+ /**
+ * Utility method to write signed 64-bit integer to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ */
+ static void WriteInt64(interop::InteropOutputStream* stream, int64_t val);
+
+ /**
+ * Utility method to read signed 64-bit integer array from stream.
+ *
+ * @param stream Stream.
+ * @param res Target array.
+ * @param len Array length.
+ */
+ static void ReadInt64Array(interop::InteropInputStream* stream, int64_t* res, const int32_t len);
+
+ /**
+ * Utility method to write signed 64-bit integer array to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ * @param len Array length.
+ */
+ static void WriteInt64Array(interop::InteropOutputStream* stream, const int64_t* val, const int32_t len);
+
+ /**
+ * Utility method to read float from stream.
+ *
+ * @param stream Stream.
+ * @return Value.
+ */
+ static float ReadFloat(interop::InteropInputStream* stream);
+
+ /**
+ * Utility method to write float to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ */
+ static void WriteFloat(interop::InteropOutputStream* stream, float val);
+
+ /**
+ * Utility method to read float array from stream.
+ *
+ * @param stream Stream.
+ * @param res Target array.
+ * @param len Array length.
+ */
+ static void ReadFloatArray(interop::InteropInputStream* stream, float* res, const int32_t len);
+
+ /**
+ * Utility method to write float array to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ * @param len Array length.
+ */
+ static void WriteFloatArray(interop::InteropOutputStream* stream, const float* val, const int32_t len);
+
+ /**
+ * Utility method to read double from stream.
+ *
+ * @param stream Stream.
+ * @return Value.
+ */
+ static double ReadDouble(interop::InteropInputStream* stream);
+
+ /**
+ * Utility method to write double to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ */
+ static void WriteDouble(interop::InteropOutputStream* stream, double val);
+
+ /**
+ * Utility method to read double array from stream.
+ *
+ * @param stream Stream.
+ * @param res Target array.
+ * @param len Array length.
+ */
+ static void ReadDoubleArray(interop::InteropInputStream* stream, double* res, const int32_t len);
+
+ /**
+ * Utility method to write double array to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ * @param len Array length.
+ */
+ static void WriteDoubleArray(interop::InteropOutputStream* stream, const double* val, const int32_t len);
+
+ /**
+ * Utility method to read Guid from stream.
+ *
+ * @param stream Stream.
+ * @param res Value.
+ */
+ static Guid ReadGuid(interop::InteropInputStream* stream);
+
+ /**
+ * Utility method to write Guid to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ */
+ static void WriteGuid(interop::InteropOutputStream* stream, const Guid val);
+
+ /**
+ * Utility method to write string to stream.
+ *
+ * @param stream Stream.
+ * @param val Value.
+ * @param len Length.
+ */
+ static void WriteString(interop::InteropOutputStream* stream, const char* val, const int32_t len);
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_writer_impl.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_writer_impl.h b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_writer_impl.h
new file mode 100644
index 0000000..b38dc1f
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/impl/portable/portable_writer_impl.h
@@ -0,0 +1,859 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_IMPL_PORTABLE_WRITER
+#define _IGNITE_IMPL_PORTABLE_WRITER
+
+#include <cstring>
+#include <string>
+#include <stdint.h>
+
+#include <ignite/common/common.h>
+#include <ignite/common/concurrent.h>
+
+#include "ignite/impl/interop/interop_output_stream.h"
+#include "ignite/impl/portable/portable_common.h"
+#include "ignite/impl/portable/portable_id_resolver.h"
+#include "ignite/impl/portable/portable_metadata_manager.h"
+#include "ignite/impl/portable/portable_utils.h"
+#include "ignite/portable/portable_consts.h"
+#include "ignite/portable/portable_type.h"
+#include "ignite/guid.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ /**
+ * Internal implementation of portable reader.
+ */
+ class IGNITE_IMPORT_EXPORT PortableWriterImpl
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param stream Interop stream.
+ * @param idRslvr Portable ID resolver.
+ * @param metaMgr Metadata manager.
+ * @param metaHnd Metadata handler.
+ */
+ PortableWriterImpl(ignite::impl::interop::InteropOutputStream* stream, PortableIdResolver* idRslvr,
+ PortableMetadataManager* metaMgr, PortableMetadataHandler* metaHnd);
+
+ /**
+ * Constructor used to construct light-weight writer allowing only raw operations
+ * and primitive objects.
+ *
+ * @param stream Interop stream.
+ * @param metaMgr Metadata manager.
+ */
+ PortableWriterImpl(ignite::impl::interop::InteropOutputStream* stream, PortableMetadataManager* metaMgr);
+
+ /**
+ * Write 8-byte signed integer. Maps to "byte" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteInt8(const int8_t val);
+
+ /**
+ * Write array of 8-byte signed integers. Maps to "byte[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt8Array(const int8_t* val, const int32_t len);
+
+ /**
+ * Write 8-byte signed integer. Maps to "byte" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteInt8(const char* fieldName, const int8_t val);
+
+ /**
+ * Write array of 8-byte signed integers. Maps to "byte[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt8Array(const char* fieldName, const int8_t* val, const int32_t len);
+
+ /**
+ * Write bool. Maps to "short" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteBool(const bool val);
+
+ /**
+ * Write array of bools. Maps to "bool[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteBoolArray(const bool* val, const int32_t len);
+
+ /**
+ * Write bool. Maps to "short" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteBool(const char* fieldName, const bool val);
+
+ /**
+ * Write array of bools. Maps to "bool[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteBoolArray(const char* fieldName, const bool* val, const int32_t len);
+
+ /**
+ * Write 16-byte signed integer. Maps to "short" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteInt16(const int16_t val);
+
+ /**
+ * Write array of 16-byte signed integers. Maps to "short[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt16Array(const int16_t* val, const int32_t len);
+
+ /**
+ * Write 16-byte signed integer. Maps to "short" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteInt16(const char* fieldName, const int16_t val);
+
+ /**
+ * Write array of 16-byte signed integers. Maps to "short[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt16Array(const char* fieldName, const int16_t* val, const int32_t len);
+
+ /**
+ * Write 16-byte unsigned integer. Maps to "char" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteUInt16(const uint16_t val);
+
+ /**
+ * Write array of 16-byte unsigned integers. Maps to "char[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteUInt16Array(const uint16_t* val, const int32_t len);
+
+ /**
+ * Write 16-byte unsigned integer. Maps to "char" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteUInt16(const char* fieldName, const uint16_t val);
+
+ /**
+ * Write array of 16-byte unsigned integers. Maps to "char[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteUInt16Array(const char* fieldName, const uint16_t* val, const int32_t len);
+
+ /**
+ * Write 32-byte signed integer. Maps to "int" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteInt32(const int32_t val);
+
+ /**
+ * Write array of 32-byte signed integers. Maps to "int[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt32Array(const int32_t* val, const int32_t len);
+
+ /**
+ * Write 32-byte signed integer. Maps to "int" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteInt32(const char* fieldName, const int32_t val);
+
+ /**
+ * Write array of 32-byte signed integers. Maps to "int[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt32Array(const char* fieldName, const int32_t* val, const int32_t len);
+
+ /**
+ * Write 64-byte signed integer. Maps to "long" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteInt64(const int64_t val);
+
+ /**
+ * Write array of 64-byte signed integers. Maps to "long[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt64Array(const int64_t* val, const int32_t len);
+
+ /**
+ * Write 64-byte signed integer. Maps to "long" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteInt64(const char* fieldName, const int64_t val);
+
+ /**
+ * Write array of 64-byte signed integers. Maps to "long[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt64Array(const char* fieldName, const int64_t* val, const int32_t len);
+
+ /**
+ * Write float. Maps to "float" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteFloat(const float val);
+
+ /**
+ * Write array of floats. Maps to "float[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteFloatArray(const float* val, const int32_t len);
+
+ /**
+ * Write float. Maps to "float" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteFloat(const char* fieldName, const float val);
+
+ /**
+ * Write array of floats. Maps to "float[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteFloatArray(const char* fieldName, const float* val, const int32_t len);
+
+ /**
+ * Write double. Maps to "double" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteDouble(const double val);
+
+ /**
+ * Write array of doubles. Maps to "double[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteDoubleArray(const double* val, const int32_t len);
+
+ /**
+ * Write double. Maps to "double" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteDouble(const char* fieldName, const double val);
+
+ /**
+ * Write array of doubles. Maps to "double[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteDoubleArray(const char* fieldName, const double* val, const int32_t len);
+
+ /**
+ * Write Guid. Maps to "UUID" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteGuid(const Guid val);
+
+ /**
+ * Write array of Guids. Maps to "UUID[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteGuidArray(const Guid* val, const int32_t len);
+
+ /**
+ * Write Guid. Maps to "UUID" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ */
+ void WriteGuid(const char* fieldName, const Guid val);
+
+ /**
+ * Write array of Guids. Maps to "UUID[]" type in Java.
+ *
+ * @param fieldName Field name.
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteGuidArray(const char* fieldName, const Guid* val, const int32_t len);
+
+ /**
+ * Write string.
+ *
+ * @param val String.
+ * @param len String length (characters).
+ */
+ void WriteString(const char* val, const int32_t len);
+
+ /**
+ * Write string.
+ *
+ * @param fieldName Field name.
+ * @param val String.
+ * @param len String length (characters).
+ */
+ void WriteString(const char* fieldName, const char* val, const int32_t len);
+
+ /**
+ * Start string array write.
+ *
+ * @param typ Collection type.
+ * @return Session ID.
+ */
+ int32_t WriteStringArray();
+
+ /**
+ * Start string array write.
+ *
+ * @param fieldName Field name.
+ * @return Session ID.
+ */
+ int32_t WriteStringArray(const char* fieldName);
+
+ /**
+ * Write string element.
+ *
+ * @param id Session ID.
+ * @param val Value.
+ * @param len Length.
+ */
+ void WriteStringElement(int32_t id, const char* val, int32_t len);
+
+ /**
+ * Write NULL value.
+ */
+ void WriteNull();
+
+ /**
+ * Write NULL value.
+ *
+ * @param fieldName Field name.
+ */
+ void WriteNull(const char* fieldName);
+
+ /**
+ * Start array write.
+ *
+ * @param typ Collection type.
+ * @return Session ID.
+ */
+ int32_t WriteArray();
+
+ /**
+ * Start array write.
+ *
+ * @param fieldName Field name.
+ * @return Session ID.
+ */
+ int32_t WriteArray(const char* fieldName);
+
+ /**
+ * Start collection write.
+ *
+ * @param typ Collection type.
+ * @return Session ID.
+ */
+ int32_t WriteCollection(ignite::portable::CollectionType typ);
+
+ /**
+ * Start collection write.
+ *
+ * @param fieldName Field name.
+ * @param typ Collection type.
+ * @return Session ID.
+ */
+ int32_t WriteCollection(const char* fieldName, ignite::portable::CollectionType typ);
+
+ /**
+ * Start map write.
+ *
+ * @param typ Map type.
+ * @return Session ID.
+ */
+ int32_t WriteMap(ignite::portable::MapType typ);
+
+ /**
+ * Start map write.
+ *
+ * @param fieldName Field name.
+ * @param typ Map type.
+ * @return Session ID.
+ */
+ int32_t WriteMap(const char* fieldName, ignite::portable::MapType typ);
+
+ /**
+ * Write collection element.
+ *
+ * @param id Session ID.
+ * @param val Value.
+ */
+ template<typename T>
+ void WriteElement(int32_t id, T val)
+ {
+ CheckSession(id);
+
+ WriteTopObject<T>(val);
+
+ elemCnt++;
+ }
+
+ /**
+ * Write map element.
+ *
+ * @param id Session ID.
+ * @param key Key.
+ * @param val Value.
+ */
+ template<typename K, typename V>
+ void WriteElement(int32_t id, K key, V val)
+ {
+ CheckSession(id);
+
+ WriteTopObject<K>(key);
+ WriteTopObject<V>(val);
+
+ elemCnt++;
+ }
+
+ /**
+ * Commit container write session.
+ *
+ * @param id Session ID.
+ */
+ void CommitContainer(int32_t id);
+
+ /**
+ * Write object.
+ *
+ * @param val Object.
+ */
+ template<typename T>
+ void WriteObject(T val)
+ {
+ CheckRawMode(true);
+
+ WriteTopObject(val);
+ }
+
+ /**
+ * Write object.
+ *
+ * @param fieldName Field name.
+ * @param val Object.
+ */
+ template<typename T>
+ void WriteObject(const char* fieldName, T val)
+ {
+ CheckRawMode(false);
+
+ // 1. Write field ID.
+ WriteFieldId(fieldName, IGNITE_TYPE_OBJECT);
+
+ // 2. Preserve space for length.
+ int32_t lenPos = stream->Position();
+ stream->Position(lenPos + 4);
+
+ // 3. Actual write.
+ WriteTopObject(val);
+
+ // 4. Write field length.
+ int32_t len = stream->Position() - lenPos - 4;
+ stream->WriteInt32(lenPos, len);
+ }
+
+ /**
+ * Set raw mode.
+ */
+ void SetRawMode();
+
+ /**
+ * Get raw position.
+ */
+ int32_t GetRawPosition();
+
+ /**
+ * Write object.
+ *
+ * @param obj Object to write.
+ */
+ template<typename T>
+ void WriteTopObject(const T& obj)
+ {
+ ignite::portable::PortableType<T> type;
+
+ if (type.IsNull(obj))
+ stream->WriteInt8(IGNITE_HDR_NULL);
+ else
+ {
+ TemplatedPortableIdResolver<T> idRslvr(type);
+ ignite::common::concurrent::SharedPointer<PortableMetadataHandler> metaHnd;
+
+ if (metaMgr)
+ metaHnd = metaMgr->GetHandler(idRslvr.GetTypeId());
+
+ PortableWriterImpl writerImpl(stream, &idRslvr, metaMgr, metaHnd.Get());
+ ignite::portable::PortableWriter writer(&writerImpl);
+
+ int32_t pos = stream->Position();
+
+ stream->WriteInt8(IGNITE_HDR_FULL);
+ stream->WriteBool(true);
+ stream->WriteInt32(idRslvr.GetTypeId());
+ stream->WriteInt32(type.GetHashCode(obj));
+
+ stream->Position(pos + IGNITE_FULL_HDR_LEN);
+
+ type.Write(writer, obj);
+
+ int32_t len = stream->Position() - pos;
+
+ stream->WriteInt32(pos + 10, len);
+ stream->WriteInt32(pos + 14, writerImpl.GetRawPosition() - pos);
+
+ if (metaMgr)
+ metaMgr->SubmitHandler(type.GetTypeName(), idRslvr.GetTypeId(), metaHnd.Get());
+ }
+ }
+
+ /**
+ * Get underlying stream.
+ *
+ * @return Stream.
+ */
+ impl::interop::InteropOutputStream* GetStream();
+ private:
+ /** Underlying stream. */
+ ignite::impl::interop::InteropOutputStream* stream;
+
+ /** ID resolver. */
+ PortableIdResolver* idRslvr;
+
+ /** Metadata manager. */
+ PortableMetadataManager* metaMgr;
+
+ /** Metadata handler. */
+ PortableMetadataHandler* metaHnd;
+
+ /** Type ID. */
+ int32_t typeId;
+
+ /** Elements write session ID generator. */
+ int32_t elemIdGen;
+
+ /** Elements write session ID. */
+ int32_t elemId;
+
+ /** Elements count. */
+ int32_t elemCnt;
+
+ /** Elements start position. */
+ int32_t elemPos;
+
+ /** Raw data offset. */
+ int32_t rawPos;
+
+ IGNITE_NO_COPY_ASSIGNMENT(PortableWriterImpl)
+
+ /**
+ * Write a primitive value to stream in raw mode.
+ *
+ * @param val Value.
+ * @param func Stream function.
+ */
+ template<typename T>
+ void WritePrimitiveRaw(
+ const T val,
+ void(*func)(interop::InteropOutputStream*, T)
+ )
+ {
+ CheckRawMode(true);
+ CheckSingleMode(true);
+
+ func(stream, val);
+ }
+
+ /**
+ * Write a primitive array to stream in raw mode.
+ *
+ * @param val Value.
+ * @param len Array length.
+ * @param func Stream function.
+ * @param hdr Header.
+ */
+ template<typename T>
+ void WritePrimitiveArrayRaw(
+ const T* val,
+ const int32_t len,
+ void(*func)(interop::InteropOutputStream*, const T*, const int32_t),
+ const int8_t hdr
+ )
+ {
+ CheckRawMode(true);
+ CheckSingleMode(true);
+
+ if (val)
+ {
+ stream->WriteInt8(hdr);
+ stream->WriteInt32(len);
+ func(stream, val, len);
+ }
+ else
+ stream->WriteInt8(IGNITE_HDR_NULL);
+ }
+
+ /**
+ * Write a primitive value to stream.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ * @param func Stream function.
+ * @param typ Field type ID.
+ * @param len Field length.
+ */
+ template<typename T>
+ void WritePrimitive(
+ const char* fieldName,
+ const T val,
+ void(*func)(interop::InteropOutputStream*, T),
+ const int8_t typ,
+ const int32_t len
+ )
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ WriteFieldId(fieldName, typ);
+
+ stream->WriteInt32(1 + len);
+ stream->WriteInt8(typ);
+
+ func(stream, val);
+ }
+
+ /**
+ * Write a primitive array to stream.
+ *
+ * @param fieldName Field name.
+ * @param val Value.
+ * @param len Array length.
+ * @param func Stream function.
+ * @param hdr Header.
+ * @param lenShift Length shift.
+ */
+ template<typename T>
+ void WritePrimitiveArray(
+ const char* fieldName,
+ const T* val,
+ const int32_t len,
+ void(*func)(interop::InteropOutputStream*, const T*, const int32_t),
+ const int8_t hdr,
+ const int32_t lenShift
+ )
+ {
+ CheckRawMode(false);
+ CheckSingleMode(true);
+
+ WriteFieldId(fieldName, hdr);
+
+ if (val)
+ {
+ stream->WriteInt32(5 + (len << lenShift));
+ stream->WriteInt8(hdr);
+ stream->WriteInt32(len);
+ func(stream, val, len);
+ }
+ else
+ {
+ stream->WriteInt32(1);
+ stream->WriteInt8(IGNITE_HDR_NULL);
+ }
+ }
+
+ /**
+ * Check raw mode.
+ *
+ * @param expected Expected raw mode of the reader.
+ */
+ void CheckRawMode(bool expected);
+
+ /**
+ * Check whether writer is currently operating in single mode.
+ *
+ * @param expected Expected value.
+ */
+ void CheckSingleMode(bool expected);
+
+ /**
+ * Start new container writer session.
+ *
+ * @param expRawMode Expected raw mode.
+ */
+ void StartContainerSession(bool expRawMode);
+
+ /**
+ * Check whether session ID matches.
+ *
+ * @param ses Expected session ID.
+ */
+ void CheckSession(int32_t expSes);
+
+ /**
+ * Write field ID.
+ *
+ * @param fieldName Field name.
+ * @param fieldTypeId Field type ID.
+ */
+ void WriteFieldId(const char* fieldName, int32_t fieldTypeId);
+
+ /**
+ * Write field ID and skip field length.
+ *
+ * @param fieldName Field name.
+ * @param fieldTypeId Field type ID.
+ */
+ void WriteFieldIdSkipLength(const char* fieldName, int32_t fieldTypeId);
+
+ /**
+ * Write field ID and length.
+ *
+ * @param fieldName Field name.
+ * @param fieldTypeId Field type ID.
+ * @param len Length.
+ */
+ void WriteFieldIdAndLength(const char* fieldName, int32_t fieldTypeId, int32_t len);
+
+ /**
+ * Write primitive value.
+ *
+ * @param obj Value.
+ * @param func Stream function.
+ * @param hdr Header.
+ */
+ template<typename T>
+ void WriteTopObject0(const T obj, void(*func)(impl::interop::InteropOutputStream*, T), const int8_t hdr)
+ {
+ stream->WriteInt8(hdr);
+ func(stream, obj);
+ }
+ };
+
+ template<>
+ void IGNITE_IMPORT_EXPORT PortableWriterImpl::WriteTopObject(const int8_t& obj);
+
+ template<>
+ void IGNITE_IMPORT_EXPORT PortableWriterImpl::WriteTopObject(const bool& obj);
+
+ template<>
+ void IGNITE_IMPORT_EXPORT PortableWriterImpl::WriteTopObject(const int16_t& obj);
+
+ template<>
+ void IGNITE_IMPORT_EXPORT PortableWriterImpl::WriteTopObject(const uint16_t& obj);
+
+ template<>
+ void IGNITE_IMPORT_EXPORT PortableWriterImpl::WriteTopObject(const int32_t& obj);
+
+ template<>
+ void IGNITE_IMPORT_EXPORT PortableWriterImpl::WriteTopObject(const int64_t& obj);
+
+ template<>
+ void IGNITE_IMPORT_EXPORT PortableWriterImpl::WriteTopObject(const float& obj);
+
+ template<>
+ void IGNITE_IMPORT_EXPORT PortableWriterImpl::WriteTopObject(const double& obj);
+
+ template<>
+ void IGNITE_IMPORT_EXPORT PortableWriterImpl::WriteTopObject(const Guid& obj);
+
+ template<>
+ inline void IGNITE_IMPORT_EXPORT PortableWriterImpl::WriteTopObject(const std::string& obj)
+ {
+ const char* obj0 = obj.c_str();
+
+ int32_t len = static_cast<int32_t>(strlen(obj0));
+
+ stream->WriteInt8(IGNITE_TYPE_STRING);
+
+ PortableUtils::WriteString(stream, obj0, len);
+ }
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/portable/portable.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/portable/portable.h b/modules/platform/src/main/cpp/core/include/ignite/portable/portable.h
new file mode 100644
index 0000000..1a7c3dd
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/portable/portable.h
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_PORTABLE
+#define _IGNITE_PORTABLE
+
+#include "ignite/portable/portable_consts.h"
+#include "ignite/portable/portable_containers.h"
+#include "ignite/portable/portable_type.h"
+#include "ignite/portable/portable_raw_reader.h"
+#include "ignite/portable/portable_raw_writer.h"
+#include "ignite/portable/portable_reader.h"
+#include "ignite/portable/portable_writer.h"
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/portable/portable_consts.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/portable/portable_consts.h b/modules/platform/src/main/cpp/core/include/ignite/portable/portable_consts.h
new file mode 100644
index 0000000..ef6db45
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/portable/portable_consts.h
@@ -0,0 +1,106 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_PORTABLE_CONSTS
+#define _IGNITE_PORTABLE_CONSTS
+
+#include <ignite/common/common.h>
+
+namespace ignite
+{
+ namespace portable
+ {
+ /**
+ * Portable collection types.
+ */
+ enum CollectionType
+ {
+ /**
+ * Undefined. Maps to ArrayList in Java.
+ */
+ IGNITE_COLLECTION_UNDEFINED = 0,
+
+ /**
+ * Array list. Maps to ArrayList in Java.
+ */
+ IGNITE_COLLECTION_ARRAY_LIST = 1,
+
+ /**
+ * Linked list. Maps to LinkedList in Java.
+ */
+ IGNITE_COLLECTION_LINKED_LIST = 2,
+
+ /**
+ * Hash set. Maps to HashSet in Java.
+ */
+ IGNITE_COLLECTION_HASH_SET = 3,
+
+ /**
+ * Linked hash set. Maps to LinkedHashSet in Java.
+ */
+ IGNITE_COLLECTION_LINKED_HASH_SET = 4,
+
+ /**
+ * Tree set. Maps to TreeSet in Java.
+ */
+ IGNITE_COLLECTION_TREE_SET = 5,
+
+ /**
+ * Concurrent skip list set. Maps to ConcurrentSkipListSet in Java.
+ */
+ IGNITE_COLLECTION_CONCURRENT_SKIP_LIST_SET = 6
+ };
+
+ /**
+ * Portable map types.
+ */
+ enum MapType
+ {
+ /**
+ * Undefined. Maps to HashMap in Java.
+ */
+ IGNITE_MAP_UNDEFINED = 0,
+
+ /**
+ * Hash map. Maps to HashMap in Java.
+ */
+ IGNITE_MAP_HASH_MAP = 1,
+
+ /**
+ * Linked hash map. Maps to LinkedHashMap in Java.
+ */
+ IGNITE_MAP_LINKED_HASH_MAP = 2,
+
+ /**
+ * Tree map. Maps to TreeMap in Java.
+ */
+ IGNITE_MAP_TREE_MAP = 3,
+
+ /**
+ * Concurrent hash map. Maps to ConcurrentHashMap in Java.
+ */
+ IGNITE_MAP_CONCURRENT_HASH_MAP = 4,
+
+ /**
+ * Properties map. Maps to Properties in Java.
+ */
+ IGNITE_MAP_PROPERTIES_MAP = 5
+ };
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/portable/portable_containers.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/portable/portable_containers.h b/modules/platform/src/main/cpp/core/include/ignite/portable/portable_containers.h
new file mode 100644
index 0000000..f93a11a
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/portable/portable_containers.h
@@ -0,0 +1,525 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_PORTABLE_CONTAINERS
+#define _IGNITE_PORTABLE_CONTAINERS
+
+#include <stdint.h>
+
+#include "ignite/impl/portable/portable_writer_impl.h"
+#include "ignite/impl/portable/portable_reader_impl.h"
+#include "ignite/impl/utils.h"
+#include "ignite/portable/portable_consts.h"
+
+namespace ignite
+{
+ namespace portable
+ {
+ /**
+ * Portable string array writer.
+ */
+ class IGNITE_IMPORT_EXPORT PortableStringArrayWriter
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param id Identifier.
+ * @param impl Writer.
+ */
+ PortableStringArrayWriter(impl::portable::PortableWriterImpl* impl, const int32_t id);
+
+ /**
+ * Write string.
+ *
+ * @param val Null-terminated character sequence.
+ */
+ void Write(const char* val);
+
+ /**
+ * Write string.
+ *
+ * @param val String.
+ * @param len String length (characters).
+ */
+ void Write(const char* val, const int32_t len);
+
+ /**
+ * Write string.
+ *
+ * @param val String.
+ */
+ void Write(const std::string& val)
+ {
+ Write(val.c_str());
+ }
+
+ /**
+ * Close the writer.
+ */
+ void Close();
+ private:
+ /** Implementation delegate. */
+ impl::portable::PortableWriterImpl* impl;
+
+ /** Idnetifier. */
+ const int32_t id;
+ };
+
+ /**
+ * Portable collection writer.
+ */
+ template<typename T>
+ class IGNITE_IMPORT_EXPORT PortableArrayWriter
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param impl Writer.
+ * @param id Identifier.
+ */
+ PortableArrayWriter(impl::portable::PortableWriterImpl* impl, const int32_t id) : impl(impl), id(id)
+ {
+ // No-op.
+ }
+
+ /**
+ * Write a value.
+ *
+ * @param val Value.
+ */
+ void Write(const T& val)
+ {
+ impl->WriteElement<T>(id, val);
+ }
+
+ /**
+ * Close the writer.
+ */
+ void Close()
+ {
+ impl->CommitContainer(id);
+ }
+ private:
+ /** Implementation delegate. */
+ impl::portable::PortableWriterImpl* impl;
+
+ /** Idnetifier. */
+ const int32_t id;
+ };
+
+ /**
+ * Portable collection writer.
+ */
+ template<typename T>
+ class IGNITE_IMPORT_EXPORT PortableCollectionWriter
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param impl Writer.
+ * @param id Identifier.
+ */
+ PortableCollectionWriter(impl::portable::PortableWriterImpl* impl, const int32_t id) : impl(impl), id(id)
+ {
+ // No-op.
+ }
+
+ /**
+ * Write a value.
+ *
+ * @param val Value.
+ */
+ void Write(const T& val)
+ {
+ impl->WriteElement<T>(id, val);
+ }
+
+ /**
+ * Close the writer.
+ */
+ void Close()
+ {
+ impl->CommitContainer(id);
+ }
+ private:
+ /** Implementation delegate. */
+ impl::portable::PortableWriterImpl* impl;
+
+ /** Identifier. */
+ const int32_t id;
+ };
+
+ /**
+ * Portable map writer.
+ */
+ template<typename K, typename V>
+ class IGNITE_IMPORT_EXPORT PortableMapWriter
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param impl Writer.
+ */
+ PortableMapWriter(impl::portable::PortableWriterImpl* impl, const int32_t id) : impl(impl), id(id)
+ {
+ // No-op.
+ }
+
+ /**
+ * Write a value.
+ *
+ * @param key Key.
+ * @param val Value.
+ */
+ void Write(const K& key, const V& val)
+ {
+ impl->WriteElement<K, V>(id, key, val);
+ }
+
+ /**
+ * Close the writer.
+ */
+ void Close()
+ {
+ impl->CommitContainer(id);
+ }
+ private:
+ /** Implementation delegate. */
+ impl::portable::PortableWriterImpl* impl;
+
+ /** Identifier. */
+ const int32_t id;
+ };
+
+ /**
+ * Portable string array reader.
+ */
+ class IGNITE_IMPORT_EXPORT PortableStringArrayReader
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param impl Reader.
+ * @param id Identifier.
+ * @param size Array size.
+ */
+ PortableStringArrayReader(impl::portable::PortableReaderImpl* impl, const int32_t id, const int32_t size);
+
+ /**
+ * Check whether next element is available for read.
+ *
+ * @return True if available.
+ */
+ bool HasNext();
+
+ /**
+ * Get next element.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of string. NULL terminator will be set in case len is
+ * greater than real string length.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t GetNext(char* res, const int32_t len);
+
+ /**
+ * Get next element.
+ *
+ * @return String.
+ */
+ std::string GetNext()
+ {
+ int32_t len = GetNext(NULL, 0);
+
+ if (len != -1)
+ {
+ impl::utils::SafeArray<char> arr(len + 1);
+
+ GetNext(arr.target, len + 1);
+
+ return std::string(arr.target);
+ }
+ else
+ return std::string();
+ }
+
+ /**
+ * Get array size.
+ *
+ * @return Size or -1 if array is NULL.
+ */
+ int32_t GetSize();
+
+ /**
+ * Whether array is NULL.
+ */
+ bool IsNull();
+ private:
+ /** Implementation delegate. */
+ impl::portable::PortableReaderImpl* impl;
+
+ /** Identifier. */
+ const int32_t id;
+
+ /** Size. */
+ const int32_t size;
+ };
+
+ /**
+ * Portable array reader.
+ */
+ template<typename T>
+ class PortableArrayReader
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param impl Reader.
+ * @param id Identifier.
+ * @param size Array size.
+ */
+ PortableArrayReader(impl::portable::PortableReaderImpl* impl, const int32_t id, const int32_t size) :
+ impl(impl), id(id), size(size)
+ {
+ // No-op.
+ }
+
+ /**
+ * Check whether next element is available for read.
+ *
+ * @return True if available.
+ */
+ bool HasNext()
+ {
+ return impl->HasNextElement(id);
+ }
+
+ /**
+ * Read next element.
+ *
+ * @return Next element.
+ */
+ T GetNext()
+ {
+ return impl->ReadElement<T>(id);
+ }
+
+ /**
+ * Get array size.
+ *
+ * @return Size or -1 if array is NULL.
+ */
+ int32_t GetSize()
+ {
+ return size;
+ }
+
+ /**
+ * Whether array is NULL.
+ */
+ bool IsNull()
+ {
+ return size == -1;
+ }
+ private:
+ /** Implementation delegate. */
+ impl::portable::PortableReaderImpl* impl;
+
+ /** Identifier. */
+ const int32_t id;
+
+ /** Size. */
+ const int32_t size;
+ };
+
+ /**
+ * Portable collection reader.
+ */
+ template<typename T>
+ class PortableCollectionReader
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param impl Reader.
+ * @param id Identifier.
+ * @param type Collection type.
+ * @param size Collection size.
+ */
+ PortableCollectionReader(impl::portable::PortableReaderImpl* impl, const int32_t id,
+ const CollectionType type, const int32_t size) : impl(impl), id(id), type(type), size(size)
+ {
+ // No-op.
+ }
+
+ /**
+ * Check whether next element is available for read.
+ *
+ * @return True if available.
+ */
+ bool HasNext()
+ {
+ return impl->HasNextElement(id);
+ }
+
+ /**
+ * Read next element.
+ *
+ * @return Next element.
+ */
+ T GetNext()
+ {
+ return impl->ReadElement<T>(id);
+ }
+
+ /**
+ * Get collection type.
+ *
+ * @return Type.
+ */
+ CollectionType GetType()
+ {
+ return type;
+ }
+
+ /**
+ * Get collection size.
+ *
+ * @return Size or -1 if collection is NULL.
+ */
+ int32_t GetSize()
+ {
+ return size;
+ }
+
+ /**
+ * Whether collection is NULL.
+ */
+ bool IsNull()
+ {
+ return size == -1;
+ }
+ private:
+ /** Implementation delegate. */
+ impl::portable::PortableReaderImpl* impl;
+
+ /** Identifier. */
+ const int32_t id;
+
+ /** Collection type. */
+ const CollectionType type;
+
+ /** Size. */
+ const int32_t size;
+ };
+
+ /**
+ * Portable map reader.
+ */
+ template<typename K, typename V>
+ class PortableMapReader
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param impl Reader.
+ * @param id Identifier.
+ * @param type Map type.
+ * @param size Map size.
+ */
+ PortableMapReader(impl::portable::PortableReaderImpl* impl, const int32_t id, const MapType type,
+ const int32_t size) : impl(impl), id(id), type(type), size(size)
+ {
+ // No-op.
+ }
+
+ /**
+ * Check whether next element is available for read.
+ *
+ * @return True if available.
+ */
+ bool HasNext()
+ {
+ return impl->HasNextElement(id);
+ }
+
+ /**
+ * Read next element.
+ *
+ * @param key Key.
+ * @param val Value.
+ */
+ void GetNext(K* key, V* val)
+ {
+ return impl->ReadElement<K, V>(id, key, val);
+ }
+
+ /**
+ * Get map type.
+ *
+ * @return Type.
+ */
+ MapType GetType()
+ {
+ return type;
+ }
+
+ /**
+ * Get map size.
+ *
+ * @return Size or -1 if map is NULL.
+ */
+ int32_t GetSize()
+ {
+ return size;
+ }
+
+ /**
+ * Whether map is NULL.
+ */
+ bool IsNull()
+ {
+ return size == -1;
+ }
+ private:
+ /** Implementation delegate. */
+ impl::portable::PortableReaderImpl* impl;
+
+ /** Identifier. */
+ const int32_t id;
+
+ /** Map type. */
+ const MapType type;
+
+ /** Size. */
+ const int32_t size;
+ };
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/portable/portable_raw_reader.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/portable/portable_raw_reader.h b/modules/platform/src/main/cpp/core/include/ignite/portable/portable_raw_reader.h
new file mode 100644
index 0000000..9f1d74c
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/portable/portable_raw_reader.h
@@ -0,0 +1,324 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_PORTABLE_RAW_READER
+#define _IGNITE_PORTABLE_RAW_READER
+
+#include <stdint.h>
+#include <string>
+
+#include <ignite/common/common.h>
+
+#include "ignite/impl/portable/portable_reader_impl.h"
+#include "ignite/portable/portable_consts.h"
+#include "ignite/portable/portable_containers.h"
+#include "ignite/guid.h"
+
+namespace ignite
+{
+ namespace portable
+ {
+ /**
+ * Portable raw reader.
+ */
+ class IGNITE_IMPORT_EXPORT PortableRawReader
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param impl Implementation.
+ */
+ PortableRawReader(ignite::impl::portable::PortableReaderImpl* impl);
+
+ /**
+ * Read 8-byte signed integer. Maps to "byte" type in Java.
+ *
+ * @return Result.
+ */
+ int8_t ReadInt8();
+
+ /**
+ * Read array of 8-byte signed integers. Maps to "byte[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt8Array(int8_t* res, const int32_t len);
+
+ /**
+ * Read bool. Maps to "boolean" type in Java.
+ *
+ * @return Result.
+ */
+ bool ReadBool();
+
+ /**
+ * Read array of bools. Maps to "boolean[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadBoolArray(bool* res, const int32_t len);
+
+ /**
+ * Read 16-byte signed integer. Maps to "short" type in Java.
+ *
+ * @return Result.
+ */
+ int16_t ReadInt16();
+
+ /**
+ * Read array of 16-byte signed integers. Maps to "short[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt16Array(int16_t* res, const int32_t len);
+
+ /**
+ * Read 16-byte unsigned integer. Maps to "char" type in Java.
+ *
+ * @return Result.
+ */
+ uint16_t ReadUInt16();
+
+ /**
+ * Read array of 16-byte unsigned integers. Maps to "char[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadUInt16Array(uint16_t* res, const int32_t len);
+
+ /**
+ * Read 32-byte signed integer. Maps to "int" type in Java.
+ *
+ * @return Result.
+ */
+ int32_t ReadInt32();
+
+ /**
+ * Read array of 32-byte signed integers. Maps to "int[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt32Array(int32_t* res, const int32_t len);
+
+ /**
+ * Read 64-byte signed integer. Maps to "long" type in Java.
+ *
+ * @return Result.
+ */
+ int64_t ReadInt64();
+
+ /**
+ * Read array of 64-byte signed integers. Maps to "long[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadInt64Array(int64_t* res, const int32_t len);
+
+ /**
+ * Read float. Maps to "float" type in Java.
+ *
+ * @return Result.
+ */
+ float ReadFloat();
+
+ /**
+ * Read array of floats. Maps to "float[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadFloatArray(float* res, const int32_t len);
+
+ /**
+ * Read double. Maps to "double" type in Java.
+ *
+ * @return Result.
+ */
+ double ReadDouble();
+
+ /**
+ * Read array of doubles. Maps to "double[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadDoubleArray(double* res, const int32_t len);
+
+ /**
+ * Read Guid. Maps to "UUID" type in Java.
+ *
+ * @return Result.
+ */
+ Guid ReadGuid();
+
+ /**
+ * Read array of Guids. Maps to "UUID[]" type in Java.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of array.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadGuidArray(Guid* res, const int32_t len);
+
+ /**
+ * Read string.
+ *
+ * @param res Array to store data to.
+ * @param len Expected length of string. NULL terminator will be set in case len is
+ * greater than real string length.
+ * @return Actual amount of elements read. If "len" argument is less than actual
+ * array size or resulting array is set to null, nothing will be written
+ * to resulting array and returned value will contain required array length.
+ * -1 will be returned in case array in stream was null.
+ */
+ int32_t ReadString(char* res, const int32_t len);
+
+ /**
+ * Read string from the stream.
+ *
+ * @return String.
+ */
+ std::string ReadString()
+ {
+ int32_t len = ReadString(NULL, 0);
+
+ if (len != -1)
+ {
+ ignite::impl::utils::SafeArray<char> arr(len + 1);
+
+ ReadString(arr.target, len + 1);
+
+ return std::string(arr.target);
+ }
+ else
+ return std::string();
+ }
+
+ /**
+ * Start string array read.
+ *
+ * @return String array reader.
+ */
+ PortableStringArrayReader ReadStringArray();
+
+ /**
+ * Start array read.
+ *
+ * @return Array reader.
+ */
+ template<typename T>
+ PortableArrayReader<T> ReadArray()
+ {
+ int32_t size;
+
+ int32_t id = impl->ReadArray(&size);
+
+ return PortableArrayReader<T>(impl, id, size);
+ }
+
+ /**
+ * Start collection read.
+ *
+ * @return Collection reader.
+ */
+ template<typename T>
+ PortableCollectionReader<T> ReadCollection()
+ {
+ CollectionType typ;
+ int32_t size;
+
+ int32_t id = impl->ReadCollection(&typ, &size);
+
+ return PortableCollectionReader<T>(impl, id, typ, size);
+ }
+
+ /**
+ * Start map read.
+ *
+ * @return Map reader.
+ */
+ template<typename K, typename V>
+ PortableMapReader<K, V> ReadMap()
+ {
+ MapType typ;
+ int32_t size;
+
+ int32_t id = impl->ReadMap(&typ, &size);
+
+ return PortableMapReader<K, V>(impl, id, typ, size);
+ }
+
+ /**
+ * Read object.
+ *
+ * @return Object.
+ */
+ template<typename T>
+ T ReadObject()
+ {
+ return impl->ReadObject<T>();
+ }
+ private:
+ /** Implementation delegate. */
+ ignite::impl::portable::PortableReaderImpl* impl;
+ };
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/include/ignite/portable/portable_raw_writer.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/ignite/portable/portable_raw_writer.h b/modules/platform/src/main/cpp/core/include/ignite/portable/portable_raw_writer.h
new file mode 100644
index 0000000..47b5880
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/ignite/portable/portable_raw_writer.h
@@ -0,0 +1,300 @@
+/*
+ * 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.
+ */
+
+#ifndef _IGNITE_PORTABLE_RAW_WRITER
+#define _IGNITE_PORTABLE_RAW_WRITER
+
+#include <stdint.h>
+
+#include <ignite/common/common.h>
+
+#include "ignite/impl/portable/portable_writer_impl.h"
+#include "ignite/portable/portable_consts.h"
+#include "ignite/portable/portable_containers.h"
+#include "ignite/guid.h"
+
+namespace ignite
+{
+ namespace portable
+ {
+ /**
+ * Portable raw writer.
+ */
+ class IGNITE_IMPORT_EXPORT PortableRawWriter
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param impl Implementation.
+ */
+ PortableRawWriter(ignite::impl::portable::PortableWriterImpl* impl);
+
+ /**
+ * Write 8-byte signed integer. Maps to "byte" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteInt8(const int8_t val);
+
+ /**
+ * Write array of 8-byte signed integers. Maps to "byte[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt8Array(const int8_t* val, const int32_t len);
+
+ /**
+ * Write bool. Maps to "short" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteBool(const bool val);
+
+ /**
+ * Write array of bools. Maps to "bool[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteBoolArray(const bool* val, const int32_t len);
+
+ /**
+ * Write 16-byte signed integer. Maps to "short" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteInt16(const int16_t val);
+
+ /**
+ * Write array of 16-byte signed integers. Maps to "short[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt16Array(const int16_t* val, const int32_t len);
+
+ /**
+ * Write 16-byte unsigned integer. Maps to "char" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteUInt16(const uint16_t val);
+
+ /**
+ * Write array of 16-byte unsigned integers. Maps to "char[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteUInt16Array(const uint16_t* val, const int32_t len);
+
+ /**
+ * Write 32-byte signed integer. Maps to "int" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteInt32(const int32_t val);
+
+ /**
+ * Write array of 32-byte signed integers. Maps to "int[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt32Array(const int32_t* val, const int32_t len);
+
+ /**
+ * Write 64-byte signed integer. Maps to "long" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteInt64(const int64_t val);
+
+ /**
+ * Write array of 64-byte signed integers. Maps to "long[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteInt64Array(const int64_t* val, const int32_t len);
+
+ /**
+ * Write float. Maps to "float" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteFloat(const float val);
+
+ /**
+ * Write array of floats. Maps to "float[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteFloatArray(const float* val, const int32_t len);
+
+ /**
+ * Write double. Maps to "double" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteDouble(const double val);
+
+ /**
+ * Write array of doubles. Maps to "double[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteDoubleArray(const double* val, const int32_t len);
+
+ /**
+ * Write Guid. Maps to "UUID" type in Java.
+ *
+ * @param val Value.
+ */
+ void WriteGuid(const Guid val);
+
+ /**
+ * Write array of Guids. Maps to "UUID[]" type in Java.
+ *
+ * @param val Array.
+ * @param len Array length.
+ */
+ void WriteGuidArray(const Guid* val, const int32_t len);
+
+ /**
+ * Write string.
+ *
+ * @param val Null-terminated character array.
+ */
+ void WriteString(const char* val);
+
+ /**
+ * Write string.
+ *
+ * @param val String.
+ * @param len String length (characters).
+ */
+ void WriteString(const char* val, const int32_t len);
+
+ /**
+ * Write string.
+ *
+ * @param val String.
+ */
+ void WriteString(const std::string& val)
+ {
+ WriteString(val.c_str());
+ }
+
+ /**
+ * Start string array write.
+ *
+ * @return String array writer.
+ */
+ PortableStringArrayWriter WriteStringArray();
+
+ /**
+ * Write NULL value.
+ */
+ void WriteNull();
+
+ /**
+ * Start array write.
+ *
+ * @return Array writer.
+ */
+ template<typename T>
+ PortableArrayWriter<T> WriteArray()
+ {
+ int32_t id = impl->WriteArray();
+
+ return PortableArrayWriter<T>(impl, id);
+ }
+
+ /**
+ * Start collection write.
+ *
+ * @return Collection writer.
+ */
+ template<typename T>
+ PortableCollectionWriter<T> WriteCollection()
+ {
+ return WriteCollection<T>(IGNITE_COLLECTION_UNDEFINED);
+ }
+
+ /**
+ * Start collection write.
+ *
+ * @param type Collection type.
+ * @return Collection writer.
+ */
+ template<typename T>
+ PortableCollectionWriter<T> WriteCollection(ignite::portable::CollectionType typ)
+ {
+ int32_t id = impl->WriteCollection(typ);
+
+ return PortableCollectionWriter<T>(impl, id);
+ }
+
+ /**
+ * Start map write.
+ *
+ * @param typ Map type.
+ * @return Map writer.
+ */
+ template<typename K, typename V>
+ PortableMapWriter<K, V> WriteMap()
+ {
+ return WriteMap<K, V>(IGNITE_MAP_UNDEFINED);
+ }
+
+ /**
+ * Start map write.
+ *
+ * @param typ Map type.
+ * @return Map writer.
+ */
+ template<typename K, typename V>
+ PortableMapWriter<K, V> WriteMap(ignite::portable::MapType typ)
+ {
+ int32_t id = impl->WriteMap(typ);
+
+ return PortableMapWriter<K, V>(impl, id);
+ }
+
+ /**
+ * Write object.
+ *
+ * @param val Object.
+ */
+ template<typename T>
+ void WriteObject(T val)
+ {
+ impl->WriteObject<T>(val);
+ }
+ private:
+ /** Implementation delegate. */
+ ignite::impl::portable::PortableWriterImpl* impl;
+ };
+ }
+}
+
+#endif
\ No newline at end of file
[02/11] ignite git commit: IGNITE-1364: Squashed commit from initial
branch.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/impl/cache/query/query_impl.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/cache/query/query_impl.cpp b/modules/platform/src/main/cpp/core/src/impl/cache/query/query_impl.cpp
new file mode 100644
index 0000000..7d89321
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/cache/query/query_impl.cpp
@@ -0,0 +1,193 @@
+/*
+ * 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/cache/query/query_impl.h"
+
+using namespace ignite::common::concurrent;
+using namespace ignite::common::java;
+using namespace ignite::impl::interop;
+using namespace ignite::impl::portable;
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace cache
+ {
+ namespace query
+ {
+ /** Operation: get all entries. */
+ const int32_t OP_GET_ALL = 1;
+
+ /** Operation: get single entry. */
+ const int32_t OP_GET_SINGLE = 3;
+
+ QueryCursorImpl::QueryCursorImpl(SharedPointer<IgniteEnvironment> env, jobject javaRef) :
+ env(env), javaRef(javaRef), iterCalled(false), getAllCalled(false), hasNext(false)
+ {
+ // No-op.
+ }
+
+ QueryCursorImpl::~QueryCursorImpl()
+ {
+ // 1. Close the cursor.
+ env.Get()->Context()->QueryCursorClose(javaRef);
+
+ // 2. Release Java reference.
+ JniContext::Release(javaRef);
+ }
+
+ bool QueryCursorImpl::HasNext(IgniteError* err)
+ {
+ // Check whether GetAll() was called earlier.
+ if (getAllCalled)
+ {
+ *err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
+ "Cannot use HasNext() method because GetAll() was called.");
+
+ return false;
+ }
+
+ // Create iterator in Java if needed.
+ if (!CreateIteratorIfNeeded(err))
+ return false;
+
+ return hasNext;
+ }
+
+ void QueryCursorImpl::GetNext(OutputOperation& op, IgniteError* err)
+ {
+ // Check whether GetAll() was called earlier.
+ if (getAllCalled)
+ {
+ *err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
+ "Cannot use GetNext() method because GetAll() was called.");
+
+ return;
+ }
+
+ // Create iterator in Java if needed.
+ if (!CreateIteratorIfNeeded(err))
+ return;
+
+ if (hasNext)
+ {
+ JniErrorInfo jniErr;
+
+ SharedPointer<InteropMemory> inMem = env.Get()->AllocateMemory();
+
+ env.Get()->Context()->TargetOutStream(javaRef, OP_GET_SINGLE, inMem.Get()->PointerLong(), &jniErr);
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ if (jniErr.code == IGNITE_JNI_ERR_SUCCESS)
+ {
+ InteropInputStream in(inMem.Get());
+
+ portable::PortableReaderImpl reader(&in);
+
+ op.ProcessOutput(reader);
+
+ hasNext = IteratorHasNext(err);
+ }
+ }
+ else
+ {
+ // Ensure we do not overwrite possible previous error.
+ if (err->GetCode() == IgniteError::IGNITE_SUCCESS)
+ *err = IgniteError(IgniteError::IGNITE_ERR_GENERIC, "No more elements available.");
+ }
+ }
+
+ void QueryCursorImpl::GetAll(OutputOperation& op, IgniteError* err)
+ {
+ // Check whether any of iterator methods were called.
+ if (iterCalled)
+ {
+ *err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
+ "Cannot use GetAll() method because an iteration method was called.");
+
+ return;
+ }
+
+ // Check whether GetAll was called before.
+ if (getAllCalled)
+ {
+ *err = IgniteError(IgniteError::IGNITE_ERR_GENERIC,
+ "Cannot use GetNext() method because GetAll() was called.");
+
+ return;
+ }
+
+ // Get data.
+ JniErrorInfo jniErr;
+
+ SharedPointer<InteropMemory> inMem = env.Get()->AllocateMemory();
+
+ env.Get()->Context()->TargetOutStream(javaRef, OP_GET_ALL, inMem.Get()->PointerLong(), &jniErr);
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ if (jniErr.code == IGNITE_JNI_ERR_SUCCESS)
+ {
+ getAllCalled = true;
+
+ InteropInputStream in(inMem.Get());
+
+ portable::PortableReaderImpl reader(&in);
+
+ op.ProcessOutput(reader);
+ }
+ }
+
+ bool QueryCursorImpl::CreateIteratorIfNeeded(IgniteError* err)
+ {
+ if (!iterCalled)
+ {
+ JniErrorInfo jniErr;
+
+ env.Get()->Context()->QueryCursorIterator(javaRef, &jniErr);
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ if (jniErr.code == IGNITE_JNI_ERR_SUCCESS)
+ {
+ iterCalled = true;
+
+ hasNext = IteratorHasNext(err);
+ }
+ else
+ return false;
+ }
+
+ return true;
+ }
+
+ bool QueryCursorImpl::IteratorHasNext(IgniteError* err)
+ {
+ JniErrorInfo jniErr;
+
+ bool res = env.Get()->Context()->QueryCursorIteratorHasNext(javaRef, &jniErr);
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ return jniErr.code == IGNITE_JNI_ERR_SUCCESS && res;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/impl/handle_registry.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/handle_registry.cpp b/modules/platform/src/main/cpp/core/src/impl/handle_registry.cpp
new file mode 100644
index 0000000..c447faa
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/handle_registry.cpp
@@ -0,0 +1,234 @@
+/*
+ * 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/handle_registry.h"
+
+using namespace ignite::common::concurrent;
+
+namespace ignite
+{
+ namespace impl
+ {
+ HandleRegistryEntry::~HandleRegistryEntry()
+ {
+ // No-op.
+ }
+
+ HandleRegistrySegment::HandleRegistrySegment() :
+ map(new std::map<int64_t, SharedPointer<HandleRegistryEntry>>()), mux(new CriticalSection())
+ {
+ // No-op.
+ }
+
+ HandleRegistrySegment::~HandleRegistrySegment()
+ {
+ delete map;
+ delete mux;
+ }
+
+ SharedPointer<HandleRegistryEntry> HandleRegistrySegment::Get(int64_t hnd)
+ {
+ mux->Enter();
+
+ SharedPointer<HandleRegistryEntry> res = (*map)[hnd];
+
+ mux->Leave();
+
+ return res;
+ }
+
+ void HandleRegistrySegment::Put(int64_t hnd, const SharedPointer<HandleRegistryEntry>& entry)
+ {
+ mux->Enter();
+
+ (*map)[hnd] = entry;
+
+ mux->Leave();
+ }
+
+ void HandleRegistrySegment::Remove(int64_t hnd)
+ {
+ mux->Enter();
+
+ map->erase(hnd);
+
+ mux->Leave();
+ }
+
+ void HandleRegistrySegment::Clear()
+ {
+ mux->Enter();
+
+ map->erase(map->begin(), map->end());
+
+ mux->Leave();
+ }
+
+ HandleRegistry::HandleRegistry(int32_t fastCap, int32_t slowSegmentCnt)
+ {
+ this->fastCap = fastCap;
+
+ fastCtr = 0;
+
+ fast = new SharedPointer<HandleRegistryEntry>[fastCap];
+
+ for (int i = 0; i < fastCap; i++)
+ fast[i] = SharedPointer<HandleRegistryEntry>();
+
+ this->slowSegmentCnt = slowSegmentCnt;
+
+ slowCtr = fastCap;
+
+ slow = new HandleRegistrySegment*[slowSegmentCnt];
+
+ for (int i = 0; i < slowSegmentCnt; i++)
+ slow[i] = new HandleRegistrySegment();
+
+ closed = 0;
+
+ Memory::Fence();
+ }
+
+ HandleRegistry::~HandleRegistry()
+ {
+ Close();
+
+ delete[] fast;
+
+ for (int i = 0; i < slowSegmentCnt; i++)
+ delete slow[i];
+
+ delete[] slow;
+ }
+
+ int64_t HandleRegistry::Allocate(const SharedPointer<HandleRegistryEntry>& target)
+ {
+ return Allocate0(target, false, false);
+ }
+
+ int64_t HandleRegistry::AllocateCritical(const SharedPointer<HandleRegistryEntry>& target)
+ {
+ return Allocate0(target, true, false);
+ }
+
+ int64_t HandleRegistry::AllocateSafe(const SharedPointer<HandleRegistryEntry>& target)
+ {
+ return Allocate0(target, false, true);
+ }
+
+ int64_t HandleRegistry::AllocateCriticalSafe(const SharedPointer<HandleRegistryEntry>& target)
+ {
+ return Allocate0(target, true, true);
+ }
+
+ void HandleRegistry::Release(int64_t hnd)
+ {
+ if (hnd < fastCap)
+ fast[static_cast<int32_t>(hnd)] = SharedPointer<HandleRegistryEntry>();
+ else
+ {
+ HandleRegistrySegment* segment = *(slow + hnd % slowSegmentCnt);
+
+ segment->Remove(hnd);
+ }
+
+ Memory::Fence();
+ }
+
+ SharedPointer<HandleRegistryEntry> HandleRegistry::Get(int64_t hnd)
+ {
+ Memory::Fence();
+
+ if (hnd < fastCap)
+ return fast[static_cast<int32_t>(hnd)];
+ else
+ {
+ HandleRegistrySegment* segment = *(slow + hnd % slowSegmentCnt);
+
+ return segment->Get(hnd);
+ }
+ }
+
+ void HandleRegistry::Close()
+ {
+ if (Atomics::CompareAndSet32(&closed, 0, 1))
+ {
+ // Cleanup fast-path handles.
+ for (int i = 0; i < fastCap; i++)
+ fast[i] = SharedPointer<HandleRegistryEntry>();
+
+ // Cleanup slow-path handles.
+ for (int i = 0; i < slowSegmentCnt; i++)
+ (*(slow + i))->Clear();
+ }
+ }
+
+ int64_t HandleRegistry::Allocate0(const SharedPointer<HandleRegistryEntry>& target, bool critical, bool safe)
+ {
+ // Check closed state.
+ Memory::Fence();
+
+ if (closed == 1)
+ return -1;
+
+ // Try allocating entry on critical path.
+ if (critical)
+ {
+ if (fastCtr < fastCap)
+ {
+ int32_t fastIdx = Atomics::IncrementAndGet32(&fastCtr) - 1;
+
+ if (fastIdx < fastCap)
+ {
+ fast[fastIdx] = target;
+
+ // Double-check for closed state if safe mode is on.
+ Memory::Fence();
+
+ if (safe && closed == 1)
+ {
+ fast[fastIdx] = SharedPointer<HandleRegistryEntry>();
+
+ return -1;
+ }
+ else
+ return fastIdx;
+ }
+ }
+ }
+
+ // Either allocating on slow-path, or fast-path can no longer accomodate more entries.
+ int64_t slowIdx = Atomics::IncrementAndGet64(&slowCtr) - 1;
+
+ HandleRegistrySegment* segment = *(slow + slowIdx % slowSegmentCnt);
+
+ segment->Put(slowIdx, target);
+
+ // Double-check for closed state if safe mode is on.
+ Memory::Fence();
+
+ if (safe && closed == 1)
+ {
+ segment->Remove(slowIdx);
+
+ return -1;
+ }
+
+ return slowIdx;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/impl/ignite_environment.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/ignite_environment.cpp b/modules/platform/src/main/cpp/core/src/impl/ignite_environment.cpp
new file mode 100644
index 0000000..b20c543
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/ignite_environment.cpp
@@ -0,0 +1,166 @@
+/*
+ * 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/portable/portable_reader_impl.h"
+#include "ignite/impl/ignite_environment.h"
+#include "ignite/portable/portable.h"
+
+using namespace ignite::common::concurrent;
+using namespace ignite::common::java;
+using namespace ignite::impl::interop;
+using namespace ignite::impl::portable;
+using namespace ignite::portable;
+
+namespace ignite
+{
+ namespace impl
+ {
+ /**
+ * OnStart callback.
+ *
+ * @param target Target environment.
+ * @param memPtr Memory pointer.
+ */
+ void IGNITE_CALL OnStart(void* target, long long memPtr)
+ {
+ SharedPointer<IgniteEnvironment>* ptr = static_cast<SharedPointer<IgniteEnvironment>*>(target);
+
+ ptr->Get()->OnStartCallback(memPtr);
+ }
+
+ /**
+ * OnStop callback.
+ *
+ * @param target Target environment.
+ */
+ void IGNITE_CALL OnStop(void* target)
+ {
+ SharedPointer<IgniteEnvironment>* ptr = static_cast<SharedPointer<IgniteEnvironment>*>(target);
+
+ delete ptr;
+ }
+
+ IgniteEnvironment::IgniteEnvironment() : ctx(SharedPointer<JniContext>()), latch(new SingleLatch), name(NULL),
+ metaMgr(new PortableMetadataManager())
+ {
+ // No-op.
+ }
+
+ IgniteEnvironment::~IgniteEnvironment()
+ {
+ delete latch;
+
+ if (name)
+ delete name;
+
+ delete metaMgr;
+ }
+
+ JniHandlers IgniteEnvironment::GetJniHandlers(SharedPointer<IgniteEnvironment>* target)
+ {
+ JniHandlers hnds = JniHandlers();
+
+ hnds.target = target;
+
+ hnds.onStart = OnStart;
+ hnds.onStop = OnStop;
+
+ hnds.error = NULL;
+
+ return hnds;
+ }
+
+ void IgniteEnvironment::Initialize(SharedPointer<JniContext> ctx)
+ {
+ this->ctx = ctx;
+
+ latch->CountDown();
+ }
+
+ char* IgniteEnvironment::InstanceName()
+ {
+ return name;
+ }
+
+ JniContext* IgniteEnvironment::Context()
+ {
+ return ctx.Get();
+ }
+
+ SharedPointer<InteropMemory> IgniteEnvironment::AllocateMemory()
+ {
+ SharedPointer<InteropMemory> ptr(new InteropUnpooledMemory(1024));
+
+ return ptr;
+ }
+
+ SharedPointer<InteropMemory> IgniteEnvironment::AllocateMemory(int32_t cap)
+ {
+ SharedPointer<InteropMemory> ptr(new InteropUnpooledMemory(cap));
+
+ return ptr;
+ }
+
+ SharedPointer<InteropMemory> IgniteEnvironment::GetMemory(int64_t memPtr)
+ {
+ int8_t* memPtr0 = reinterpret_cast<int8_t*>(memPtr);
+
+ int32_t flags = InteropMemory::Flags(memPtr0);
+
+ if (InteropMemory::IsExternal(flags))
+ {
+ SharedPointer<InteropMemory> ptr(new InteropExternalMemory(memPtr0));
+
+ return ptr;
+ }
+ else
+ {
+ SharedPointer<InteropMemory> ptr(new InteropUnpooledMemory(memPtr0));
+
+ return ptr;
+ }
+ }
+
+ PortableMetadataManager* IgniteEnvironment::GetMetadataManager()
+ {
+ return metaMgr;
+ }
+
+ void IgniteEnvironment::OnStartCallback(long long memPtr)
+ {
+ InteropExternalMemory mem(reinterpret_cast<int8_t*>(memPtr));
+ InteropInputStream stream(&mem);
+
+ PortableReaderImpl reader(&stream);
+
+ int32_t nameLen = reader.ReadString(NULL, 0);
+
+ if (nameLen >= 0)
+ {
+ name = new char[nameLen + 1];
+ reader.ReadString(name, nameLen + 1);
+ }
+ else
+ name = NULL;
+ }
+ }
+}
+
+
+
+
+
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/impl/ignite_impl.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/ignite_impl.cpp b/modules/platform/src/main/cpp/core/src/impl/ignite_impl.cpp
new file mode 100644
index 0000000..1aad309
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/ignite_impl.cpp
@@ -0,0 +1,42 @@
+/*
+ * 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/ignite_impl.h"
+
+using namespace ignite::common::concurrent;
+using namespace ignite::common::java;
+
+namespace ignite
+{
+ namespace impl
+ {
+ IgniteImpl::IgniteImpl(SharedPointer<IgniteEnvironment> env, jobject javaRef) : env(env), javaRef(javaRef)
+ {
+ // No-op.
+ }
+
+ IgniteImpl::~IgniteImpl()
+ {
+ JniContext::Release(javaRef);
+ }
+
+ char* IgniteImpl::GetName()
+ {
+ return env.Get()->InstanceName();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/impl/interop/interop_input_stream.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/interop/interop_input_stream.cpp b/modules/platform/src/main/cpp/core/src/impl/interop/interop_input_stream.cpp
new file mode 100644
index 0000000..72340ee
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/interop/interop_input_stream.cpp
@@ -0,0 +1,215 @@
+/*
+ * 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 <cstring>
+
+#include "ignite/impl/interop/interop_input_stream.h"
+#include "ignite/ignite_error.h"
+
+/**
+ * Common macro to read a single value.
+ */
+#define IGNITE_INTEROP_IN_READ(type, len) { \
+ EnsureEnoughData(len); \
+ type res = *reinterpret_cast<type*>(data + pos); \
+ Shift(len); \
+ return res; \
+}
+
+/**
+ * Common macro to read an array.
+ */
+#define IGNITE_INTEROP_IN_READ_ARRAY(len, shift) { \
+ CopyAndShift(reinterpret_cast<int8_t*>(res), 0, len << shift); \
+}
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace interop
+ {
+ union PortableInt32Float
+ {
+ int32_t i;
+ float f;
+ };
+
+ union PortableInt64Double
+ {
+ int64_t i;
+ double d;
+ };
+
+ InteropInputStream::InteropInputStream(InteropMemory* mem)
+ {
+ this->mem = mem;
+
+ data = mem->Data();
+ len = mem->Length();
+ pos = 0;
+ }
+
+ int8_t InteropInputStream::ReadInt8()
+ {
+ IGNITE_INTEROP_IN_READ(int8_t, 1);
+ }
+
+ void InteropInputStream::ReadInt8Array(int8_t* const res, const int32_t len)
+ {
+ IGNITE_INTEROP_IN_READ_ARRAY(len, 0);
+ }
+
+ bool InteropInputStream::ReadBool()
+ {
+ return ReadInt8() == 1;
+ }
+
+ void InteropInputStream::ReadBoolArray(bool* const res, const int32_t len)
+ {
+ for (int i = 0; i < len; i++)
+ *(res + i) = ReadBool();
+ }
+
+ int16_t InteropInputStream::ReadInt16()
+ {
+ IGNITE_INTEROP_IN_READ(int16_t, 2);
+ }
+
+ void InteropInputStream::ReadInt16Array(int16_t* const res, const int32_t len)
+ {
+ IGNITE_INTEROP_IN_READ_ARRAY(len, 1);
+ }
+
+ uint16_t InteropInputStream::ReadUInt16()
+ {
+ IGNITE_INTEROP_IN_READ(uint16_t, 2);
+ }
+
+ void InteropInputStream::ReadUInt16Array(uint16_t* const res, const int32_t len)
+ {
+ IGNITE_INTEROP_IN_READ_ARRAY(len, 1);
+ }
+
+ int32_t InteropInputStream::ReadInt32()
+ {
+ IGNITE_INTEROP_IN_READ(int32_t, 4);
+ }
+
+ int32_t InteropInputStream::ReadInt32(int32_t pos)
+ {
+ int delta = pos + 4 - this->pos;
+
+ if (delta > 0)
+ EnsureEnoughData(delta);
+
+ return *reinterpret_cast<int32_t*>(data + pos);
+ }
+
+ void InteropInputStream::ReadInt32Array(int32_t* const res, const int32_t len)
+ {
+ IGNITE_INTEROP_IN_READ_ARRAY(len, 2);
+ }
+
+ int64_t InteropInputStream::ReadInt64()
+ {
+ IGNITE_INTEROP_IN_READ(int64_t, 8);
+ }
+
+ void InteropInputStream::ReadInt64Array(int64_t* const res, const int32_t len)
+ {
+ IGNITE_INTEROP_IN_READ_ARRAY(len, 3);
+ }
+
+ float InteropInputStream::ReadFloat()
+ {
+ PortableInt32Float u;
+
+ u.i = ReadInt32();
+
+ return u.f;
+ }
+
+ void InteropInputStream::ReadFloatArray(float* const res, const int32_t len)
+ {
+ IGNITE_INTEROP_IN_READ_ARRAY(len, 2);
+ }
+
+ double InteropInputStream::ReadDouble()
+ {
+ PortableInt64Double u;
+
+ u.i = ReadInt64();
+
+ return u.d;
+ }
+
+ void InteropInputStream::ReadDoubleArray(double* const res, const int32_t len)
+ {
+ IGNITE_INTEROP_IN_READ_ARRAY(len, 3);
+ }
+
+ int32_t InteropInputStream::Remaining()
+ {
+ return len - pos;
+ }
+
+ int32_t InteropInputStream::Position()
+ {
+ return pos;
+ }
+
+ void InteropInputStream::Position(int32_t pos)
+ {
+ if (pos > len) {
+ IGNITE_ERROR_FORMATTED_3(IgniteError::IGNITE_ERR_MEMORY, "Requested input stream position is out of bounds",
+ "memPtr", mem->PointerLong(), "len", len, "pos", pos);
+ }
+
+ this->pos = pos;
+ }
+
+ void InteropInputStream::Synchronize()
+ {
+ data = mem->Data();
+ len = mem->Length();
+ }
+
+ void InteropInputStream::EnsureEnoughData(int32_t cnt)
+ {
+ if (len - pos < cnt) {
+ IGNITE_ERROR_FORMATTED_4(IgniteError::IGNITE_ERR_MEMORY, "Not enough data in the stream",
+ "memPtr", mem->PointerLong(), "len", len, "pos", pos, "requested", cnt);
+ }
+ }
+
+ void InteropInputStream::CopyAndShift(int8_t* dest, int32_t off, int32_t cnt)
+ {
+ EnsureEnoughData(cnt);
+
+ memcpy(dest + off, data + pos, cnt);
+
+ Shift(cnt);
+ }
+
+ void InteropInputStream::Shift(int32_t cnt)
+ {
+ pos += cnt;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/impl/interop/interop_memory.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/interop/interop_memory.cpp b/modules/platform/src/main/cpp/core/src/impl/interop/interop_memory.cpp
new file mode 100644
index 0000000..05ba8b6
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/interop/interop_memory.cpp
@@ -0,0 +1,182 @@
+/*
+ * 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/common/java.h>
+
+#include "ignite/impl/interop/interop_memory.h"
+#include "ignite/ignite_error.h"
+
+using namespace ignite::common::java;
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace interop
+ {
+ int8_t* InteropMemory::Data(int8_t* memPtr)
+ {
+ return reinterpret_cast<int8_t*>(*reinterpret_cast<int64_t*>(memPtr));
+ }
+
+ void InteropMemory::Data(int8_t* memPtr, void* ptr)
+ {
+ *reinterpret_cast<int64_t*>(memPtr) = reinterpret_cast<int64_t>(ptr);
+ }
+
+ int32_t InteropMemory::Capacity(int8_t* memPtr)
+ {
+ return *reinterpret_cast<int32_t*>(memPtr + IGNITE_MEM_HDR_OFF_CAP);
+ }
+
+ void InteropMemory::Capacity(int8_t* memPtr, int32_t val)
+ {
+ *reinterpret_cast<int32_t*>(memPtr + IGNITE_MEM_HDR_OFF_CAP) = val;
+ }
+
+ int32_t InteropMemory::Length(int8_t* memPtr)
+ {
+ return *reinterpret_cast<int32_t*>(memPtr + IGNITE_MEM_HDR_OFF_LEN);
+ }
+
+ void InteropMemory::Length(int8_t* memPtr, int32_t val)
+ {
+ *reinterpret_cast<int32_t*>(memPtr + IGNITE_MEM_HDR_OFF_LEN) = val;
+ }
+
+ int32_t InteropMemory::Flags(int8_t* memPtr)
+ {
+ return *reinterpret_cast<int32_t*>(memPtr + IGNITE_MEM_HDR_OFF_FLAGS);
+ }
+
+ void InteropMemory::Flags(int8_t* memPtr, int32_t val)
+ {
+ *reinterpret_cast<int32_t*>(memPtr + IGNITE_MEM_HDR_OFF_FLAGS) = val;
+ }
+
+ bool InteropMemory::IsExternal(int8_t* memPtr)
+ {
+ return IsExternal(Flags(memPtr));
+ }
+
+ bool InteropMemory::IsExternal(int32_t flags)
+ {
+ return (flags & IGNITE_MEM_FLAG_EXT) != IGNITE_MEM_FLAG_EXT;
+ }
+
+ bool InteropMemory::IsPooled(int8_t* memPtr)
+ {
+ return IsPooled(Flags(memPtr));
+ }
+
+ bool InteropMemory::IsPooled(int32_t flags)
+ {
+ return (flags & IGNITE_MEM_FLAG_POOLED) != 0;
+ }
+
+ bool InteropMemory::IsAcquired(int8_t* memPtr)
+ {
+ return IsAcquired(Flags(memPtr));
+ }
+
+ bool InteropMemory::IsAcquired(int32_t flags)
+ {
+ return (flags & IGNITE_MEM_FLAG_ACQUIRED) != 0;
+ }
+
+ int8_t* InteropMemory::Pointer()
+ {
+ return memPtr;
+ }
+
+ int64_t InteropMemory::PointerLong()
+ {
+ return reinterpret_cast<int64_t>(memPtr);
+ }
+
+ int8_t* InteropMemory::Data()
+ {
+ return Data(memPtr);
+ }
+
+ int32_t InteropMemory::Capacity()
+ {
+ return Capacity(memPtr);
+ }
+
+ int32_t InteropMemory::Length()
+ {
+ return Length(memPtr);
+ }
+
+ void InteropMemory::Length(int32_t val)
+ {
+ Length(memPtr, val);
+ }
+
+ InteropUnpooledMemory::InteropUnpooledMemory(int32_t cap)
+ {
+ memPtr = static_cast<int8_t*>(malloc(IGNITE_MEM_HDR_LEN));
+
+ Data(memPtr, malloc(cap));
+ Capacity(memPtr, cap);
+ Length(memPtr, 0);
+ Flags(memPtr, IGNITE_MEM_FLAG_EXT);
+
+ owning = true;
+ }
+
+ InteropUnpooledMemory::InteropUnpooledMemory(int8_t* memPtr)
+ {
+ this->memPtr = memPtr;
+ this->owning = false;
+ }
+
+ InteropUnpooledMemory::~InteropUnpooledMemory()
+ {
+ if (owning) {
+ free(Data());
+ free(memPtr);
+ }
+ }
+
+ void InteropUnpooledMemory::Reallocate(int32_t cap)
+ {
+ int doubledCap = Capacity() << 1;
+
+ if (doubledCap > cap)
+ cap = doubledCap;
+
+ Data(memPtr, realloc(Data(memPtr), cap));
+ Capacity(memPtr, cap);
+ }
+
+ InteropExternalMemory::InteropExternalMemory(int8_t* memPtr)
+ {
+ this->memPtr = memPtr;
+ }
+
+ void InteropExternalMemory::Reallocate(int32_t cap)
+ {
+ if (JniContext::Reallocate(reinterpret_cast<int64_t>(memPtr), cap) == -1) {
+ IGNITE_ERROR_FORMATTED_2(IgniteError::IGNITE_ERR_MEMORY, "Failed to reallocate external memory",
+ "memPtr", PointerLong(), "requestedCapacity", cap)
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/impl/interop/interop_output_stream.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/interop/interop_output_stream.cpp b/modules/platform/src/main/cpp/core/src/impl/interop/interop_output_stream.cpp
new file mode 100644
index 0000000..ecdfd42
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/interop/interop_output_stream.cpp
@@ -0,0 +1,215 @@
+/*
+ * 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 <cstring>
+
+#include "ignite/impl/interop/interop_output_stream.h"
+#include "ignite/ignite_error.h"
+
+/**
+ * Common macro to write a single value.
+ */
+#define IGNITE_INTEROP_OUT_WRITE(val, type, len) { \
+ EnsureCapacity(pos + len); \
+ *reinterpret_cast<type*>(data + pos) = val; \
+ Shift(len); \
+}
+
+/**
+ * Common macro to write an array.
+ */
+#define IGNITE_INTEROP_OUT_WRITE_ARRAY(val, len) { \
+ CopyAndShift(reinterpret_cast<const int8_t*>(val), 0, len); \
+}
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace interop
+ {
+ union PortableFloatInt32
+ {
+ float f;
+ int32_t i;
+ };
+
+ union PortableDoubleInt64
+ {
+ double d;
+ int64_t i;
+ };
+
+ InteropOutputStream::InteropOutputStream(InteropMemory* mem)
+ {
+ this->mem = mem;
+
+ data = mem->Data();
+ cap = mem->Capacity();
+ pos = 0;
+ }
+
+ void InteropOutputStream::WriteInt8(const int8_t val)
+ {
+ IGNITE_INTEROP_OUT_WRITE(val, int8_t, 1);
+ }
+
+ void InteropOutputStream::WriteInt8(const int8_t val, const int32_t pos)
+ {
+ EnsureCapacity(pos + 1);
+
+ *(data + pos) = val;
+ }
+
+ void InteropOutputStream::WriteInt8Array(const int8_t* val, const int32_t len)
+ {
+ IGNITE_INTEROP_OUT_WRITE_ARRAY(val, len);
+ }
+
+ void InteropOutputStream::WriteBool(const bool val)
+ {
+ WriteInt8(val ? 1 : 0);
+ }
+
+ void InteropOutputStream::WriteBoolArray(const bool* val, const int32_t len)
+ {
+ for (int i = 0; i < len; i++)
+ WriteBool(*(val + i));
+ }
+
+ void InteropOutputStream::WriteInt16(const int16_t val)
+ {
+ IGNITE_INTEROP_OUT_WRITE(val, int16_t, 2);
+ }
+
+ void InteropOutputStream::WriteInt16Array(const int16_t* val, const int32_t len)
+ {
+ IGNITE_INTEROP_OUT_WRITE_ARRAY(val, len << 1);
+ }
+
+ void InteropOutputStream::WriteUInt16(const uint16_t val)
+ {
+ IGNITE_INTEROP_OUT_WRITE(val, uint16_t, 2);
+ }
+
+ void InteropOutputStream::WriteUInt16Array(const uint16_t* val, const int32_t len)
+ {
+ IGNITE_INTEROP_OUT_WRITE_ARRAY(val, len << 1);
+ }
+
+ void InteropOutputStream::WriteInt32(const int32_t val)
+ {
+ IGNITE_INTEROP_OUT_WRITE(val, int32_t, 4);
+ }
+
+ void InteropOutputStream::WriteInt32(const int32_t pos, const int32_t val)
+ {
+ EnsureCapacity(pos + 4);
+
+ *reinterpret_cast<int32_t*>(data + pos) = val;
+ }
+
+ void InteropOutputStream::WriteInt32Array(const int32_t* val, const int32_t len)
+ {
+ IGNITE_INTEROP_OUT_WRITE_ARRAY(val, len << 2);
+ }
+
+ void InteropOutputStream::WriteInt64(const int64_t val)
+ {
+ IGNITE_INTEROP_OUT_WRITE(val, int64_t, 8);
+ }
+
+ void InteropOutputStream::WriteInt64Array(const int64_t* val, const int32_t len)
+ {
+ IGNITE_INTEROP_OUT_WRITE_ARRAY(val, len << 3);
+ }
+
+ void InteropOutputStream::WriteFloat(const float val)
+ {
+ PortableFloatInt32 u;
+
+ u.f = val;
+
+ WriteInt32(u.i);
+ }
+
+ void InteropOutputStream::WriteFloatArray(const float* val, const int32_t len)
+ {
+ for (int i = 0; i < len; i++)
+ WriteFloat(*(val + i));
+ }
+
+ void InteropOutputStream::WriteDouble(const double val)
+ {
+ PortableDoubleInt64 u;
+
+ u.d = val;
+
+ WriteInt64(u.i);
+ }
+
+ void InteropOutputStream::WriteDoubleArray(const double* val, const int32_t len)
+ {
+ for (int i = 0; i < len; i++)
+ WriteDouble(*(val + i));
+ }
+
+ int32_t InteropOutputStream::Position()
+ {
+ return pos;
+ }
+
+ void InteropOutputStream::Position(const int32_t val)
+ {
+ EnsureCapacity(val);
+
+ pos = val;
+ }
+
+ void InteropOutputStream::Synchronize()
+ {
+ mem->Length(pos);
+ }
+
+ void InteropOutputStream::EnsureCapacity(int32_t reqCap) {
+ if (reqCap > cap) {
+ int newCap = cap << 1;
+
+ if (newCap < reqCap)
+ newCap = reqCap;
+
+ mem->Reallocate(newCap);
+ data = mem->Data();
+ cap = newCap;
+ }
+ }
+
+ void InteropOutputStream::Shift(int32_t cnt) {
+ pos += cnt;
+ }
+
+ void InteropOutputStream::CopyAndShift(const int8_t* src, int32_t off, int32_t len) {
+ EnsureCapacity(pos + len);
+
+ memcpy(data + pos, src + off, len);
+
+ Shift(len);
+ }
+ }
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_handler.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_handler.cpp b/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_handler.cpp
new file mode 100644
index 0000000..5ca91dc
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_handler.cpp
@@ -0,0 +1,78 @@
+/*
+ * 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/portable/portable_metadata_handler.h"
+
+using namespace ignite::common::concurrent;
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ PortableMetadataHandler::PortableMetadataHandler(SPSnap snap) : snap(snap), fieldIds(NULL), fields(NULL)
+ {
+ // No-op.
+ }
+
+ PortableMetadataHandler::~PortableMetadataHandler()
+ {
+ if (fieldIds)
+ delete fieldIds;
+
+ if (fields)
+ delete fields;
+ }
+
+ void PortableMetadataHandler::OnFieldWritten(int32_t fieldId, std::string fieldName, int32_t fieldTypeId)
+ {
+ if (!snap.Get() || !snap.Get()->ContainsFieldId(fieldId))
+ {
+ if (!HasDifference())
+ {
+ fieldIds = new std::set<int32_t>();
+ fields = new std::map<std::string, int32_t>();
+ }
+
+ fieldIds->insert(fieldId);
+ (*fields)[fieldName] = fieldTypeId;
+ }
+ }
+
+ SPSnap PortableMetadataHandler::GetSnapshot()
+ {
+ return snap;
+ }
+
+ bool PortableMetadataHandler::HasDifference()
+ {
+ return fieldIds ? true : false;
+ }
+
+ std::set<int32_t>* PortableMetadataHandler::GetFieldIds()
+ {
+ return fieldIds;
+ }
+
+ std::map<std::string, int32_t>* PortableMetadataHandler::GetFields()
+ {
+ return fields;
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_manager.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_manager.cpp b/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_manager.cpp
new file mode 100644
index 0000000..63e92a9
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_manager.cpp
@@ -0,0 +1,201 @@
+/*
+ * 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/common/concurrent.h>
+
+#include "ignite/impl/portable/portable_metadata_manager.h"
+
+using namespace ignite::common::concurrent;
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ PortableMetadataManager::PortableMetadataManager() :
+ snapshots(SharedPointer<std::map<int32_t, SPSnap>>(new std::map<int32_t, SPSnap>)),
+ pending(new std::vector<SPSnap>()),
+ cs(new CriticalSection()),
+ pendingVer(0), ver(0)
+ {
+ // No-op.
+ }
+
+ PortableMetadataManager::~PortableMetadataManager()
+ {
+ pending->erase(pending->begin(), pending->end());
+
+ delete pending;
+ delete cs;
+ }
+
+ SharedPointer<PortableMetadataHandler> PortableMetadataManager::GetHandler(int32_t typeId)
+ {
+ SharedPointer<std::map<int32_t, SPSnap>> snapshots0 = snapshots;
+
+ SPSnap snapshot = (*snapshots0.Get())[typeId];
+
+ return SharedPointer<PortableMetadataHandler>(new PortableMetadataHandler(snapshot));
+ }
+
+ void PortableMetadataManager::SubmitHandler(std::string typeName, int32_t typeId,
+ PortableMetadataHandler* 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<int32_t>* newFieldIds = new std::set<int32_t>();
+ std::map<std::string, int32_t>* newFields = new std::map<std::string, int32_t>();
+
+ CopyFields(snap, newFieldIds, newFields);
+
+ if (hnd->HasDifference())
+ {
+ std::set<int32_t>* diffFieldIds = hnd->GetFieldIds();
+ std::map<std::string, int32_t>* diffFields = hnd->GetFields();
+
+ for (std::set<int32_t>::iterator it = diffFieldIds->begin(); it != diffFieldIds->end(); ++it)
+ newFieldIds->insert(*it);
+
+ for (std::map<std::string, int32_t>::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 PortableMetadataManager::GetVersion()
+ {
+ Memory::Fence();
+
+ return ver;
+ }
+
+ bool PortableMetadataManager::IsUpdatedSince(int32_t oldVer)
+ {
+ Memory::Fence();
+
+ return pendingVer > oldVer;
+ }
+
+ bool PortableMetadataManager::ProcessPendingUpdates(PortableMetadataUpdater* updater, IgniteError* err)
+ {
+ bool success = true; // Optimistically assume that all will be fine.
+
+ cs->Enter();
+
+ for (std::vector<SPSnap>::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<int32_t, SPSnap>* newSnapshots = new std::map<int32_t, SPSnap>();
+
+ bool snapshotFound = false;
+
+ for (std::map<int32_t, SPSnap>::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<int32_t>* newFieldIds = new std::set<int32_t>();
+ std::map<std::string, int32_t>* newFields = new std::map<std::string, int32_t>();
+
+ // 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<std::map<int32_t, SPSnap>>(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 PortableMetadataManager::CopyFields(Snap* snap, std::set<int32_t>* fieldIds,
+ std::map<std::string, int32_t>* fields)
+ {
+ if (snap && snap->HasFields())
+ {
+ std::set<int32_t>* snapFieldIds = snap->GetFieldIds();
+ std::map<std::string, int32_t>* snapFields = snap->GetFields();
+
+ for (std::set<int32_t>::iterator oldIt = snapFieldIds->begin();
+ oldIt != snapFieldIds->end(); ++oldIt)
+ fieldIds->insert(*oldIt);
+
+ for (std::map<std::string, int32_t>::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/1fc06e01/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_snapshot.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_snapshot.cpp b/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_snapshot.cpp
new file mode 100644
index 0000000..6ce5ab5
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_snapshot.cpp
@@ -0,0 +1,70 @@
+/*
+ * 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/portable/portable_metadata_snapshot.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ PortableMetadataSnapshot::PortableMetadataSnapshot(std::string typeName, int32_t typeId,
+ std::set<int32_t>* fieldIds, std::map<std::string, int32_t>* fields) :
+ typeName(typeName), typeId(typeId), fieldIds(fieldIds), fields(fields)
+ {
+ // No-op.
+ }
+
+ PortableMetadataSnapshot::~PortableMetadataSnapshot()
+ {
+ delete fieldIds;
+ delete fields;
+ }
+
+ bool PortableMetadataSnapshot::ContainsFieldId(int32_t fieldId)
+ {
+ return fieldIds && fieldIds->count(fieldId) == 1;
+ }
+
+ std::string PortableMetadataSnapshot::GetTypeName()
+ {
+ return typeName;
+ }
+
+ int32_t PortableMetadataSnapshot::GetTypeId()
+ {
+ return typeId;
+ }
+
+ bool PortableMetadataSnapshot::HasFields()
+ {
+ return !fieldIds->empty();
+ }
+
+ std::set<int32_t>* PortableMetadataSnapshot::GetFieldIds()
+ {
+ return fieldIds;
+ }
+
+ std::map<std::string, int32_t>* PortableMetadataSnapshot::GetFields()
+ {
+ return fields;
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_updater.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_updater.cpp b/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_updater.cpp
new file mode 100644
index 0000000..81c96d7
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_updater.cpp
@@ -0,0 +1,32 @@
+/*
+ * 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/portable/portable_metadata_updater.h"
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ PortableMetadataUpdater::~PortableMetadataUpdater()
+ {
+ // No-op.
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1fc06e01/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_updater_impl.cpp
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_updater_impl.cpp b/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_updater_impl.cpp
new file mode 100644
index 0000000..07a1758
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/src/impl/portable/portable_metadata_updater_impl.cpp
@@ -0,0 +1,94 @@
+/*
+ * 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/portable/portable_metadata_updater_impl.h"
+#include "ignite/impl/interop/interop_output_stream.h"
+#include "ignite/impl/portable/portable_writer_impl.h"
+#include "ignite/portable/portable_raw_writer.h"
+
+using namespace ignite::common::concurrent;
+using namespace ignite::common::java;
+using namespace ignite::impl;
+using namespace ignite::impl::interop;
+using namespace ignite::portable;
+
+namespace ignite
+{
+ namespace impl
+ {
+ namespace portable
+ {
+ /** Operation: Clear. */
+ const int32_t OP_METADATA = -1;
+
+ PortableMetadataUpdaterImpl::PortableMetadataUpdaterImpl(SharedPointer<IgniteEnvironment> env,
+ jobject javaRef) : env(env), javaRef(javaRef)
+ {
+ // No-op.
+ }
+
+ PortableMetadataUpdaterImpl::~PortableMetadataUpdaterImpl()
+ {
+ // No-op.
+ }
+
+ bool PortableMetadataUpdaterImpl::Update(Snap* snap, IgniteError* err)
+ {
+ JniErrorInfo jniErr;
+
+ SharedPointer<InteropMemory> mem = env.Get()->AllocateMemory();
+
+ InteropOutputStream out(mem.Get());
+ PortableWriterImpl writer(&out, NULL);
+ PortableRawWriter rawWriter(&writer);
+
+ // We always pass only one meta at a time in current implementation for simplicity.
+ rawWriter.WriteInt32(1);
+
+ rawWriter.WriteInt32(snap->GetTypeId());
+ rawWriter.WriteString(snap->GetTypeName());
+ rawWriter.WriteString(NULL); // Affinity key is not supported for now.
+
+ if (snap->HasFields())
+ {
+ std::map<std::string, int32_t>* fields = snap->GetFields();
+
+ rawWriter.WriteInt32(static_cast<int32_t>(fields->size()));
+
+ for (std::map<std::string, int32_t>::iterator it = fields->begin(); it != fields->end(); ++it)
+ {
+ rawWriter.WriteString(it->first);
+ rawWriter.WriteInt32(it->second);
+ }
+ }
+ else
+ rawWriter.WriteInt32(0);
+
+ out.Synchronize();
+
+ long long res = env.Get()->Context()->TargetInStreamOutLong(javaRef, OP_METADATA, mem.Get()->PointerLong(), &jniErr);
+
+ IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err);
+
+ if (jniErr.code == IGNITE_JNI_ERR_SUCCESS)
+ return res == 1;
+ else
+ return false;
+ }
+ }
+ }
+}
\ No newline at end of file