Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C4D20200CA3 for ; Thu, 1 Jun 2017 15:23:23 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C3DFE160BE5; Thu, 1 Jun 2017 13:23:23 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9855F160BF6 for ; Thu, 1 Jun 2017 15:23:21 +0200 (CEST) Received: (qmail 16153 invoked by uid 500); 1 Jun 2017 13:23:20 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 14789 invoked by uid 99); 1 Jun 2017 13:23:18 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Jun 2017 13:23:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id AA957F31F7; Thu, 1 Jun 2017 13:23:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: agoncharuk@apache.org To: commits@ignite.apache.org Date: Thu, 01 Jun 2017 13:23:54 -0000 Message-Id: <337409848fb14c10915cad06ee92f73a@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [39/50] [abbrv] ignite git commit: IGNITE-5161: Implemented C++ compute example. archived-at: Thu, 01 Jun 2017 13:23:24 -0000 IGNITE-5161: Implemented C++ compute example. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d0bddfa5 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d0bddfa5 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d0bddfa5 Branch: refs/heads/ignite-5267 Commit: d0bddfa527af6c5cf4554e484ce04c078bfd69e9 Parents: 41dcce7 Author: Igor Sapego Authored: Wed May 31 18:36:52 2017 +0300 Committer: Igor Sapego Committed: Wed May 31 18:36:52 2017 +0300 ---------------------------------------------------------------------- modules/platforms/cpp/examples/Makefile.am | 1 + .../cpp/examples/compute-example/Makefile.am | 59 +++++++ .../compute-example/config/compute-example.xml | 52 ++++++ .../project/vs/compute-example.vcxproj | 102 +++++++++++ .../project/vs/compute-example.vcxproj.filters | 27 +++ .../compute-example/src/compute_example.cpp | 177 +++++++++++++++++++ modules/platforms/cpp/examples/configure.ac | 1 + .../project/vs/continuous-query-example.vcxproj | 4 - .../src/continuous_query_example.cpp | 5 +- .../examples/include/ignite/examples/address.h | 2 +- .../include/ignite/examples/organization.h | 4 +- .../cpp/examples/project/vs/ignite-examples.sln | 6 + 12 files changed, 430 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/d0bddfa5/modules/platforms/cpp/examples/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/examples/Makefile.am b/modules/platforms/cpp/examples/Makefile.am index 8cfb999..29b140b 100644 --- a/modules/platforms/cpp/examples/Makefile.am +++ b/modules/platforms/cpp/examples/Makefile.am @@ -22,5 +22,6 @@ SUBDIRS = \ odbc-example \ query-example \ continuous-query-example \ + compute-example \ include http://git-wip-us.apache.org/repos/asf/ignite/blob/d0bddfa5/modules/platforms/cpp/examples/compute-example/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/examples/compute-example/Makefile.am b/modules/platforms/cpp/examples/compute-example/Makefile.am new file mode 100644 index 0000000..d757bf7 --- /dev/null +++ b/modules/platforms/cpp/examples/compute-example/Makefile.am @@ -0,0 +1,59 @@ +## +## 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 =-I m4 + +noinst_PROGRAMS = ignite-compute-example + +AM_CPPFLAGS = \ + -I@top_srcdir@/include \ + -I@top_srcdir@/../core/include \ + -I@top_srcdir@/../core/os/linux/include \ + -I@top_srcdir@/../common/include \ + -I@top_srcdir@/../common/os/linux/include \ + -I@top_srcdir@/../binary/include \ + -I@top_srcdir@/../jni/include \ + -I@top_srcdir@/../jni/os/linux/include \ + -I$(JAVA_HOME)/include \ + -I$(JAVA_HOME)/include/linux \ + -DIGNITE_IMPL \ + -D__STDC_LIMIT_MACROS \ + -D__STDC_CONSTANT_MACROS + +AM_CXXFLAGS = \ + -Wall \ + -std=c++03 + +ignite_compute_example_LDADD = \ + @top_srcdir@/../core/libignite.la \ + -lodbc \ + -lpthread + +ignite_compute_example_LDFLAGS = \ + -static-libtool-libs + +ignite_compute_example_SOURCES = \ + src/compute_example.cpp + +run-check: check + ./ignite-compute-example -p + +clean-local: clean-check + $(RM) *.gcno *.gcda + +clean-check: + $(RM) $(ignite_compute_example_OBJECTS) http://git-wip-us.apache.org/repos/asf/ignite/blob/d0bddfa5/modules/platforms/cpp/examples/compute-example/config/compute-example.xml ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/examples/compute-example/config/compute-example.xml b/modules/platforms/cpp/examples/compute-example/config/compute-example.xml new file mode 100644 index 0000000..1348b1c --- /dev/null +++ b/modules/platforms/cpp/examples/compute-example/config/compute-example.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + 127.0.0.1:47550..47551 + + + + + + + + http://git-wip-us.apache.org/repos/asf/ignite/blob/d0bddfa5/modules/platforms/cpp/examples/compute-example/project/vs/compute-example.vcxproj ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/examples/compute-example/project/vs/compute-example.vcxproj b/modules/platforms/cpp/examples/compute-example/project/vs/compute-example.vcxproj new file mode 100644 index 0000000..1b84a9c --- /dev/null +++ b/modules/platforms/cpp/examples/compute-example/project/vs/compute-example.vcxproj @@ -0,0 +1,102 @@ + + + + + Release + Win32 + + + Release + x64 + + + + igniteexamples + {18BB0A18-8213-472A-81A0-9D9753697135} + compute-example + + + + Application + false + v100 + true + Unicode + + + Application + false + v100 + true + Unicode + + + + + + + + + + + + + false + + + false + + + + Level3 + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + $(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;..\..\..\include;..\..\..\..\jni\os\win\include;..\..\..\..\jni\include;..\..\..\..\common\os\win\include;..\..\..\..\common\include;..\..\..\..\binary\include;..\..\..\..\core\os\win\include;..\..\..\..\core\include;%(AdditionalIncludeDirectories) + + + Console + true + true + true + jvm.lib;ignite.jni.lib;ignite.binary.lib;ignite.core.lib;%(AdditionalDependencies) + ..\..\..\..\project\vs\$(Platform)\$(Configuration)\;$(JAVA_HOME)\lib;%(AdditionalLibraryDirectories) + + + copy "$(ProjectDir)..\..\..\..\project\vs\$(Platform)\$(Configuration)\ignite.common.dll" "$(OutDir)" +copy "$(ProjectDir)..\..\..\..\project\vs\$(Platform)\$(Configuration)\ignite.core.dll" "$(OutDir)" + + + + + Level3 + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + $(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;..\..\..\include;..\..\..\..\jni\os\win\include;..\..\..\..\jni\include;..\..\..\..\common\os\win\include;..\..\..\..\common\include;..\..\..\..\binary\include;..\..\..\..\core\os\win\include;..\..\..\..\core\include;%(AdditionalIncludeDirectories) + + + Console + true + true + true + jvm.lib;ignite.jni.lib;ignite.binary.lib;ignite.core.lib;%(AdditionalDependencies) + ..\..\..\..\project\vs\$(Platform)\$(Configuration)\;$(JAVA_HOME)\lib;%(AdditionalLibraryDirectories) + + + copy "$(ProjectDir)..\..\..\..\project\vs\$(Platform)\$(Configuration)\ignite.common.dll" "$(OutDir)" +copy "$(ProjectDir)..\..\..\..\project\vs\$(Platform)\$(Configuration)\ignite.core.dll" "$(OutDir)" + + + + + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/d0bddfa5/modules/platforms/cpp/examples/compute-example/project/vs/compute-example.vcxproj.filters ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/examples/compute-example/project/vs/compute-example.vcxproj.filters b/modules/platforms/cpp/examples/compute-example/project/vs/compute-example.vcxproj.filters new file mode 100644 index 0000000..d43cece --- /dev/null +++ b/modules/platforms/cpp/examples/compute-example/project/vs/compute-example.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Config + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/d0bddfa5/modules/platforms/cpp/examples/compute-example/src/compute_example.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/examples/compute-example/src/compute_example.cpp b/modules/platforms/cpp/examples/compute-example/src/compute_example.cpp new file mode 100644 index 0000000..3426475 --- /dev/null +++ b/modules/platforms/cpp/examples/compute-example/src/compute_example.cpp @@ -0,0 +1,177 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include +#include + +using namespace ignite; + +/* + * Function class. + */ +class CountWords : public compute::ComputeFunc +{ + friend struct ignite::binary::BinaryType; +public: + /* + * Default constructor. + */ + CountWords() : + text() + { + // No-op. + } + + /* + * Constructor. + * + * @param text Text. + */ + CountWords(const std::string& text) : + text(text) + { + // No-op. + } + + /** + * Callback. + * Counts number of words in provided text. + * + * @return Number of words in provided text. + */ + virtual int32_t Call() + { + std::stringstream buf(text); + std::string word; + + int32_t wordsCount = 0; + while (buf >> word) + ++wordsCount; + + return wordsCount; + } + +private: + /** Text in which to count words. */ + std::string text; +}; + +namespace ignite +{ + namespace binary + { + template<> + struct BinaryType + { + static int32_t GetTypeId() + { + return GetBinaryStringHashCode("CountWords"); + } + + static void GetTypeName(std::string& dst) + { + dst = "CountWords"; + } + + static int32_t GetFieldId(const char* name) + { + return GetBinaryStringHashCode(name); + } + + static int32_t GetHashCode(const CountWords& obj) + { + return 0; + } + + static bool IsNull(const CountWords& obj) + { + return false; + } + + static void GetNull(CountWords& dst) + { + dst = CountWords(""); + } + + static void Write(BinaryWriter& writer, const CountWords& obj) + { + writer.RawWriter().WriteString(obj.text); + } + + static void Read(BinaryReader& reader, CountWords& dst) + { + dst.text = reader.RawReader().ReadString(); + } + }; + } +} + +int main() +{ + IgniteConfiguration cfg; + + cfg.springCfgPath = "platforms/cpp/examples/compute-example/config/compute-example.xml"; + + try + { + // Start a node. + Ignite ignite = Ignition::Start(cfg); + + std::cout << std::endl; + std::cout << ">>> Compute example started." << std::endl; + std::cout << std::endl; + + // Get binding instance. + IgniteBinding binding = ignite.GetBinding(); + + // Registering our class as a compute function. + binding.RegisterComputeFunc(); + + // Get compute instance. + compute::Compute compute = ignite.GetCompute(); + + std::string testText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; + + // Declaring counter. + CountWords counter(testText); + + // Making call. + int32_t wordsCount = compute.Call(counter); + + // Printing result. + std::cout << ">>> Text contains " << wordsCount << " words" << std::endl; + + // Stop node. + Ignition::StopAll(false); + } + catch (IgniteError& err) + { + std::cout << "An error occurred: " << err.GetText() << std::endl; + } + + std::cout << std::endl; + std::cout << ">>> Example finished, press 'Enter' to exit ..." << std::endl; + std::cout << std::endl; + + std::cin.get(); + + return 0; +} http://git-wip-us.apache.org/repos/asf/ignite/blob/d0bddfa5/modules/platforms/cpp/examples/configure.ac ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/examples/configure.ac b/modules/platforms/cpp/examples/configure.ac index 7aef863..a72471d 100644 --- a/modules/platforms/cpp/examples/configure.ac +++ b/modules/platforms/cpp/examples/configure.ac @@ -57,6 +57,7 @@ AC_CONFIG_FILES([ \ odbc-example/Makefile \ query-example/Makefile \ continuous-query-example/Makefile \ + compute-example/Makefile \ ]) AC_OUTPUT http://git-wip-us.apache.org/repos/asf/ignite/blob/d0bddfa5/modules/platforms/cpp/examples/continuous-query-example/project/vs/continuous-query-example.vcxproj ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/examples/continuous-query-example/project/vs/continuous-query-example.vcxproj b/modules/platforms/cpp/examples/continuous-query-example/project/vs/continuous-query-example.vcxproj index dfc5f9d..585796b 100644 --- a/modules/platforms/cpp/examples/continuous-query-example/project/vs/continuous-query-example.vcxproj +++ b/modules/platforms/cpp/examples/continuous-query-example/project/vs/continuous-query-example.vcxproj @@ -48,8 +48,6 @@ Level3 - - MaxSpeed true true @@ -72,8 +70,6 @@ copy "$(ProjectDir)..\..\..\..\project\vs\$(Platform)\$(Configuration)\ignite.co Level3 - - MaxSpeed true true http://git-wip-us.apache.org/repos/asf/ignite/blob/d0bddfa5/modules/platforms/cpp/examples/continuous-query-example/src/continuous_query_example.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/examples/continuous-query-example/src/continuous_query_example.cpp b/modules/platforms/cpp/examples/continuous-query-example/src/continuous_query_example.cpp index 2ca3163..3b17b53 100644 --- a/modules/platforms/cpp/examples/continuous-query-example/src/continuous_query_example.cpp +++ b/modules/platforms/cpp/examples/continuous-query-example/src/continuous_query_example.cpp @@ -18,10 +18,9 @@ #include #include -#include "ignite/ignition.h" -#include "ignite/cache/query/continuous/continuous_query.h" +#include +#include -#include "ignite/examples/organization.h" #include "ignite/examples/person.h" using namespace ignite; http://git-wip-us.apache.org/repos/asf/ignite/blob/d0bddfa5/modules/platforms/cpp/examples/include/ignite/examples/address.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/examples/include/ignite/examples/address.h b/modules/platforms/cpp/examples/include/ignite/examples/address.h index 6a06f60..8f2689c 100644 --- a/modules/platforms/cpp/examples/include/ignite/examples/address.h +++ b/modules/platforms/cpp/examples/include/ignite/examples/address.h @@ -74,7 +74,7 @@ namespace ignite return GetBinaryStringHashCode(name); } - static int32_t GetHashCode(ignite::examples::Address obj) + static int32_t GetHashCode(ignite::examples::Address& obj) { return 0; } http://git-wip-us.apache.org/repos/asf/ignite/blob/d0bddfa5/modules/platforms/cpp/examples/include/ignite/examples/organization.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/examples/include/ignite/examples/organization.h b/modules/platforms/cpp/examples/include/ignite/examples/organization.h index 942897d..2701933 100644 --- a/modules/platforms/cpp/examples/include/ignite/examples/organization.h +++ b/modules/platforms/cpp/examples/include/ignite/examples/organization.h @@ -83,12 +83,12 @@ namespace ignite return GetBinaryStringHashCode(name); } - static int32_t GetHashCode(ignite::examples::Organization obj) + static int32_t GetHashCode(const ignite::examples::Organization& obj) { return 0; } - static bool IsNull(ignite::examples::Organization obj) + static bool IsNull(const ignite::examples::Organization& obj) { return false; } http://git-wip-us.apache.org/repos/asf/ignite/blob/d0bddfa5/modules/platforms/cpp/examples/project/vs/ignite-examples.sln ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/examples/project/vs/ignite-examples.sln b/modules/platforms/cpp/examples/project/vs/ignite-examples.sln index a1865e3..bf83743 100644 --- a/modules/platforms/cpp/examples/project/vs/ignite-examples.sln +++ b/modules/platforms/cpp/examples/project/vs/ignite-examples.sln @@ -9,6 +9,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "continuous-query-example", EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "put-get-example", "..\..\put-get-example\project\vs\put-get-example.vcxproj", "{34935DEC-80FC-4168-AA52-3DBFF4F79B6B}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "compute-example", "..\..\compute-example\project\vs\compute-example.vcxproj", "{18BB0A18-8213-472A-81A0-9D9753697135}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Release|x64 = Release|x64 @@ -31,6 +33,10 @@ Global {34935DEC-80FC-4168-AA52-3DBFF4F79B6B}.Release|x64.Build.0 = Release|x64 {34935DEC-80FC-4168-AA52-3DBFF4F79B6B}.Release|x86.ActiveCfg = Release|Win32 {34935DEC-80FC-4168-AA52-3DBFF4F79B6B}.Release|x86.Build.0 = Release|Win32 + {18BB0A18-8213-472A-81A0-9D9753697135}.Release|x64.ActiveCfg = Release|x64 + {18BB0A18-8213-472A-81A0-9D9753697135}.Release|x64.Build.0 = Release|x64 + {18BB0A18-8213-472A-81A0-9D9753697135}.Release|x86.ActiveCfg = Release|Win32 + {18BB0A18-8213-472A-81A0-9D9753697135}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE