This is an automated email from the ASF dual-hosted git repository. jbarrett pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/geode-native.git
The following commit(s) were added to refs/heads/develop by this push: new 5c41056 * GEODE-4284 Adding put-get-remove example. (#192) 5c41056 is described below commit 5c410564ea676a603aa10cba5e103c07779efec3 Author: mhansonp <mhan...@pivotal.io> AuthorDate: Mon Jan 29 15:16:19 2018 -0800 * GEODE-4284 Adding put-get-remove example. (#192) --- CMakeLists.txt | 6 +- cppcache/src/CMakeLists.txt | 4 +- examples/cpp/BUILDING.md | 56 +++++++++++++++ examples/cpp/cmake/Findgeode-native.cmake | 112 +++++++++++++++++++++++++++++ examples/cpp/put-get-remove/CMakeLists.txt | 35 +++++++++ examples/cpp/put-get-remove/main.cpp | 58 +++++++++++++++ examples/cpp/put-get-remove/startserver.sh | 32 +++++++++ examples/cpp/put-get-remove/stopserver.sh | 32 +++++++++ 8 files changed, 329 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bab669..5ecd4e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,6 @@ set(CPACK_SYSTEM_NAME "${PRODUCT_SYSTEM_NAME}-${PRODUCT_BITS}") set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${PRODUCT_VERSION}-${CPACK_SYSTEM_NAME}) set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0) set(CPACK_PACKAGING_INSTALL_PREFIX "/${CPACK_PACKAGE_NAME}") -#set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/dist/LICENSE") set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}") set(CPACK_GENERATOR TGZ;ZIP) @@ -243,8 +242,7 @@ if (${BUILD_CLI}) add_subdirectory(plugins/SQLiteCLI) endif() -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/quickstart/ DESTINATION SampleCode/quickstart USE_SOURCE_PERMISSIONS) -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cppcache/integration-test/keystore/ DESTINATION SampleCode/quickstart/keystore) +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/examples/ DESTINATION examples) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/xsds/ DESTINATION xsds) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/defaultSystem/ DESTINATION defaultSystem) @@ -254,5 +252,3 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/templates/ DESTINATION templates PATTERN "templates/security/CMakeLists.txt" EXCLUDE PATTERN "templates/security/CMakeLists.txt.forInstall" EXCLUDE) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/templates/security/CMakeLists.txt.forInstall RENAME CMakeLists.txt DESTINATION templates/security) - -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tests/javaobject/javaobject.jar DESTINATION SampleCode/quickstart/lib) diff --git a/cppcache/src/CMakeLists.txt b/cppcache/src/CMakeLists.txt index c055f26..5f52d49 100644 --- a/cppcache/src/CMakeLists.txt +++ b/cppcache/src/CMakeLists.txt @@ -132,9 +132,11 @@ install(TARGETS apache-geode RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib - PUBLIC_HEADER DESTINATION include/geode ) +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../include/ DESTINATION include/) + + # For Visual Studio organization source_group("Header Files" REGULAR_EXPRESSION "\.(hpp|inl)$") source_group("Configure In Files" FILES ${CONFIGURE_IN_FILES}) diff --git a/examples/cpp/BUILDING.md b/examples/cpp/BUILDING.md new file mode 100644 index 0000000..3267329 --- /dev/null +++ b/examples/cpp/BUILDING.md @@ -0,0 +1,56 @@ +# Building + +## Prerequisites (All Platforms) +* [CMake 3.5](https://cmake.org/) or newer +* C++11 compiler *(see platform specific requirements)* +* [Apache Geode](http://geode.apache.org/releases/) binaries installed or available to link against + + Running requires access to an installation of Geode. By default the value of `GEODE_HOME` is used as the path for the startserver.sh script, if gfsh is not in the path. + +## Prequisites (Windows) + +* Visual Studio 2015 + +## Steps to build + +**Mac OS X / \*nix / Windows** + + $ cd <example> + $ mkdir build + $ cd build + $ cmake .. + $ cmake --build . -- <optional parallelism parameters> + +## Steps to run + +**Mac OS X / \*nix** + + $ cd <example> + $ sh ./startserver.sh + $ build/<example name> + $ sh ./stopserver.sh + +**Windows** + + $ cd <example> + $ PATH=%PATH%;C:\Program Files\geode-native\bin (or wherever you installed the geode-native client dll) + $ gfsh -e "start locator --name=locator" -e "start server --name=server" -e "create region --name=example_userinfo --type=PARTITION" + $ build\Debug\put-get-remove.exe + $ gfsh -e "connect" -e "stop server --name=server" -e "stop locator --name=locator" + +## Generator +CMake uses a "generator" to produce configuration files for use by a variety of build tools, e.g., UNIX makefiles, Visual Studio projects. By default a system-specific generator is used by CMake during configuration. (Please see [the CMake documentation](https://cmake.org/documentation/) for further information.) However, in many cases there is a better choice. + +### Mac OS X / *nix Generator +The default generator: + + $ cmake .. + +### Windows Generator +The recommended generator on Windows is `Visual Studio 14 2015 Win64`: + + $ cmake -G "Visual Studio 14 2015 Win64" .. + + +### Building requirements +Please see the documentation for building Geode Native. \ No newline at end of file diff --git a/examples/cpp/cmake/Findgeode-native.cmake b/examples/cpp/cmake/Findgeode-native.cmake new file mode 100644 index 0000000..634c12e --- /dev/null +++ b/examples/cpp/cmake/Findgeode-native.cmake @@ -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. + +#.rst: +# Findgeode-native +# --------- +# +# Find the Geode Native headers and library. +# +# Imported Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following :prop_tgt:`IMPORTED` targets: +# +# ``apache.geode::cpp`` +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module will set the following variables in your project: +# +# ``GEODE_NATIVE_INCLUDE_DIRS`` +# where to find CacheFactory.hpp, etc. +# ``GEODE_NATIVE_LIBRARIES`` +# the libraries to link against to use Geode Native. +# ``GEODE_NATIVE_FOUND`` +# true if the Geode Native headers and libraries were found. +# + + +set(_GEODE_NATIVE_ROOT "") +if(GEODE_NATIVE_ROOT AND IS_DIRECTORY "${GEODE_NATIVE_ROOT}") + set(_GEODE_NATIVE_ROOT "${GEODE_NATIVE_ROOT}") + set(_GEODE_NATIVE_ROOT_EXPLICIT 1) +else() + set(_ENV_GEODE_NATIVE_ROOT "") + if(DEFINED ENV{GFCPP}) + file(TO_CMAKE_PATH "$ENV{GFCPP}" _ENV_GEODE_NATIVE_ROOT) + endif() + if(_ENV_GEODE_NATIVE_ROOT AND IS_DIRECTORY "${_ENV_GEODE_NATIVE_ROOT}") + set(_GEODE_NATIVE_ROOT "${_ENV_GEODE_NATIVE_ROOT}") + set(_GEODE_NATIVE_ROOT_EXPLICIT 0) + endif() + unset(_ENV_GEODE_NATIVE_ROOT) +endif() + +set(_GEODE_NATIVE_HINTS) +set(_GEODE_NATIVE_PATHS) + +if(_GEODE_NATIVE_ROOT) + set(_GEODE_NATIVE_HINTS ${_GEODE_NATIVE_ROOT}) +else() + set(_GEODE_NATIVE_PATHS ( + "/opt/local" + "/usr/local" + "../../../../" + "C:/program files" )) +endif() + +set(_GEODE_NATIVE_NAMES apache-geode) + +find_library(GEODE_NATIVE_LIBRARY + NAMES ${_GEODE_NATIVE_NAMES} + HINTS ${_GEODE_NATIVE_HINTS} + PATHS ${_GEODE_NATIVE_PATHS} + PATH_SUFFIXES geode-native/lib +) + + + +# Look for the header file. +find_path(GEODE_NATIVE_INCLUDE_DIR NAMES geode/CacheFactory.hpp + HINTS ${_GEODE_NATIVE_HINTS} + PATHS ${_GEODE_NATIVE_PATHS} + PATH_SUFFIXES geode-native/include +) + +# TODO find version +set(GEODE_NATIVE_VERSION_STRING 1.0) + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GEODE_NATIVE + REQUIRED_VARS GEODE_NATIVE_LIBRARY GEODE_NATIVE_INCLUDE_DIR + VERSION_VAR GEODE_NATIVE_VERSION_STRING) + +# Copy the results to the output variables and target. +if(GEODE_NATIVE_FOUND) + set(GEODE_NATIVE_LIBRARIES ${GEODE_NATIVE_LIBRARY}) + set(GEODE_NATIVE_INCLUDE_DIRS ${GEODE_NATIVE_INCLUDE_DIR}) + set(GEODE_NATIVE_CPP_TARGET "apache.geode::cpp") + if(NOT TARGET ${GEODE_NATIVE_CPP_TARGET}) + add_library(${GEODE_NATIVE_CPP_TARGET} UNKNOWN IMPORTED) + set_target_properties(${GEODE_NATIVE_CPP_TARGET} PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + IMPORTED_LOCATION "${GEODE_NATIVE_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${GEODE_NATIVE_INCLUDE_DIRS}") + endif() +endif() + +mark_as_advanced(GEODE_NATIVE_INCLUDE_DIR GEODE_NATIVE_LIBRARY) diff --git a/examples/cpp/put-get-remove/CMakeLists.txt b/examples/cpp/put-get-remove/CMakeLists.txt new file mode 100644 index 0000000..a79eccf --- /dev/null +++ b/examples/cpp/put-get-remove/CMakeLists.txt @@ -0,0 +1,35 @@ +# 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. + +cmake_minimum_required(VERSION 3.5) + +project(put-get-remove) + +set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake) +set(CMAKE_CXX_STANDARD 11) + +if(CMAKE_CXX_COMPILER_ID STREQUAL "SunPro") + add_compile_options(-m64) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m64") +endif() + +find_package(geode-native REQUIRED) + +add_executable(${PROJECT_NAME} main.cpp) + +target_link_libraries(${PROJECT_NAME} + PUBLIC + apache.geode::cpp +) diff --git a/examples/cpp/put-get-remove/main.cpp b/examples/cpp/put-get-remove/main.cpp new file mode 100644 index 0000000..32ad9ef --- /dev/null +++ b/examples/cpp/put-get-remove/main.cpp @@ -0,0 +1,58 @@ +/* + * 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 <iostream> + +#include <geode/CacheFactory.hpp> +#include <geode/PoolManager.hpp> + +using namespace apache::geode::client; + +int main(int argc, char** argv) { + + auto cacheFactory = CacheFactory(); + cacheFactory.set("log-level", "none"); + auto cache = cacheFactory.create(); + auto poolFactory = cache.getPoolManager().createFactory(); + + poolFactory->addLocator("localhost", 10334); + auto pool = poolFactory->create("pool"); + auto regionFactory = cache.createRegionFactory(PROXY); + auto region = regionFactory.setPoolName("pool").create("example_userinfo"); + + std::cout << "Storing id and username in the region" << std::endl; + region->put("rtimmons", "Robert Timmons"); + region->put("scharles", "Sylvia Charles"); + + std::cout << "Getting the user info from the region" << std::endl; + auto user1 = region->get("rtimmons"); + auto user2 = region->get("scharles"); + std::cout << " rtimmons = " << std::dynamic_pointer_cast<CacheableString>(user1)->value() << std::endl; + std::cout << " scharles = " << std::dynamic_pointer_cast<CacheableString>(user2)->value() << std::endl; + + std::cout << "Removing rtimmons info from the region" << std::endl; + region->remove("rtimmons"); + + if(region->existsValue("rtimmons")) { + std::cout << "rtimmons's info not deleted" << std::endl; + } + else { + std::cout << "rtimmons's info successfully deleted" << std::endl; + } + + cache.close(); +} diff --git a/examples/cpp/put-get-remove/startserver.sh b/examples/cpp/put-get-remove/startserver.sh new file mode 100755 index 0000000..e657de2 --- /dev/null +++ b/examples/cpp/put-get-remove/startserver.sh @@ -0,0 +1,32 @@ +#!/bin/env bash + +# 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. + +GFSH_PATH="" +which gfsh 2> /dev/null + +if [ $? -gt 0 ]; then + GFSH_PATH="gfsh" +else + if [ "$GEODE_HOME" == "" ]; then + echo "Could not find gfsh. Please set the GEODE_HOME path." + echo "e.g. export GEODE_HOME=<path to Geode>" + else + GFSH_PATH=$GEODE_HOME/bin/gfsh + fi +fi + +$GFSH_PATH -e "start locator --name=locator" -e "start server --name=server" -e "create region --name=example_userinfo --type=PARTITION" diff --git a/examples/cpp/put-get-remove/stopserver.sh b/examples/cpp/put-get-remove/stopserver.sh new file mode 100755 index 0000000..f04fab6 --- /dev/null +++ b/examples/cpp/put-get-remove/stopserver.sh @@ -0,0 +1,32 @@ +#!/bin/env bash + +# 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. + +GFSH_PATH="" +which gfsh 2> /dev/null + +if [ $? -gt 0 ]; then + GFSH_PATH="gfsh" +else + if [ "$GEODE_HOME" == "" ]; then + echo "Could not find gfsh. Please set the GEODE_HOME path." + echo "e.g. export GEODE_HOME=<path to Geode>" + else + GFSH_PATH=$GEODE_HOME/bin/gfsh + fi +fi + +$GFSH_PATH -e "connect" -e "stop server --name=server" -e "stop locator --name=locator" -- To stop receiving notification emails like this one, please contact jbarr...@apache.org.