Commit 440b369b authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

initial commit

parents
build/
.spack-env/
spack.lock
#
# general cmake flags:
# -DCMAKE_INSTALL_PREFIX=/usr/local -- the prefix for installing
# -DCMAKE_BUILD_TYPE=type -- type can be Debug, Release, ...
# -DCMAKE_PREFIX_PATH=/dir -- external packages
#
# note that CMAKE_PREFIX_PATH can be a list of directories:
# -DCMAKE_PREFIX_PATH='/dir1;/dir2;/dir3'
#
cmake_minimum_required (VERSION 3.0)
project (sonata C CXX)
enable_testing ()
option(ENABLE_TESTS "Build tests. May require CppUnit_ROOT" OFF)
option(ENABLE_EXAMPLES "Build examples" OFF)
# add our cmake module directory to the path
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# link shared lib with full rpath
set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# setup cache variables for ccmake
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Release
CACHE STRING "Choose the type of build." FORCE)
set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "RelWithDebInfo" "MinSizeRel")
endif ()
set (CMAKE_PREFIX_PATH "" CACHE STRING "External dependencies path")
set (BUILD_SHARED_LIBS "OFF" CACHE BOOL "Build a shared library")
# packages we depend on
include (xpkg-import)
find_package (thallium REQUIRED)
xpkg_import_module (margo REQUIRED margo)
xpkg_import_module (uuid REQUIRED uuid)
xpkg_import_module (jsoncpp REQUIRED jsoncpp)
find_package (UnQLite REQUIRED)
message(STATUS ${UNQLITE_LIBRARIES})
add_subdirectory (src)
if(${ENABLE_TESTS})
add_subdirectory (test)
endif(${ENABLE_TESTS})
if(${ENABLE_EXAMPLES})
add_subdirectory (examples)
endif(${ENABLE_EXAMPLES})
Please see [http://www.mcs.anl.gov/research/projects/mochi/contributing/] for details.
\ No newline at end of file
Copyright (c) 2018, UChicago Argonne, LLC
All Rights Reserved
SDS TOOLS (ANL-SF-16-009)
OPEN SOURCE LICENSE
Under the terms of Contract No. DE-AC02-06CH11357 with UChicago Argonne,
LLC, the U.S. Government retains certain rights in this software.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the names of UChicago Argonne, LLC or the Department of
Energy nor the names of its contributors may be used to endorse or
promote products derived from this software without specific prior
written permission.
******************************************************************************
DISCLAIMER
THE SOFTWARE IS SUPPLIED "AS IS" WITHOUT WARRANTY OF ANY KIND.
NEITHER THE UNTED STATES GOVERNMENT, NOR THE UNITED STATES DEPARTMENT
OF ENERGY, NOR UCHICAGO ARGONNE, LLC, NOR ANY OF THEIR EMPLOYEES,
MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL LIABILITY
OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR USEFULNESS OF ANY
INFORMATION, DATA, APPARATUS, PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS
THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS.
******************************************************************************
#
# Find the CppUnit includes and library
#
# This module defines
# CPPUNIT_INCLUDE_DIR, where to find tiff.h, etc.
# CPPUNIT_LIBRARIES, the libraries to link against to use CppUnit.
# CPPUNIT_FOUND, If false, do not try to use CppUnit.
# also defined, but not for general use are
# CPPUNIT_LIBRARY, where to find the CppUnit library.
# CPPUNIT_DEBUG_LIBRARY, where to find the CppUnit library in debug mode.
FIND_PATH(CPPUNIT_INCLUDE_DIR cppunit/TestCase.h HINTS
/usr/local/include
/usr/include
ENV CppUnit_ROOT
)
# With Win32, important to have both
IF(WIN32)
FIND_LIBRARY(CPPUNIT_LIBRARY cppunit
${CPPUNIT_INCLUDE_DIR}/../lib
/usr/local/lib
/usr/lib)
FIND_LIBRARY(CPPUNIT_DEBUG_LIBRARY cppunitd
${CPPUNIT_INCLUDE_DIR}/../lib
/usr/local/lib
/usr/lib)
ELSE(WIN32)
# On unix system, debug and release have the same name
FIND_LIBRARY(CPPUNIT_LIBRARY cppunit
${CPPUNIT_INCLUDE_DIR}/../lib
/usr/local/lib
/usr/lib)
FIND_LIBRARY(CPPUNIT_DEBUG_LIBRARY cppunit
${CPPUNIT_INCLUDE_DIR}/../lib
/usr/local/lib
/usr/lib)
ENDIF(WIN32)
IF(CPPUNIT_INCLUDE_DIR)
IF(CPPUNIT_LIBRARY)
SET(CPPUNIT_FOUND "YES")
SET(CPPUNIT_LIBRARIES ${CPPUNIT_LIBRARY} ${CMAKE_DL_LIBS})
SET(CPPUNIT_DEBUG_LIBRARIES ${CPPUNIT_DEBUG_LIBRARY}
${CMAKE_DL_LIBS})
ENDIF(CPPUNIT_LIBRARY)
ENDIF(CPPUNIT_INCLUDE_DIR)
#
# UNQLITE_FOUND - system has UnQLite
# UNQLITE_INCLUDE_DIR - the UnQLite include directory
# UNQLITE_LIBRARIES - UnQLite library
set(UNQLITE_LIBRARY_DIRS "")
find_library(UNQLITE_LIBRARIES NAMES unqlite)
find_path(UNQLITE_INCLUDE_DIRS NAMES unqlite.h)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(UNQLITE DEFAULT_MSG UNQLITE_LIBRARIES UNQLITE_INCLUDE_DIRS)
#
# xpkg-import.cmake cmake import for "pkg-config" based packages
# 11-Aug-2016 chuck@ece.cmu.edu
#
#
# have PkgConfig use CMAKE_PREFIX_PATH for searching for pkg config files.
# this is the default for cmake 3.1 and above, on some older versions
# you can turn it on. otherwise you'll have to manually set PKG_CONFIG_PATH
#
if (${CMAKE_MINIMUM_REQUIRED_VERSION} VERSION_LESS 3.1)
set (PKG_CONFIG_USE_CMAKE_PREFIX_PATH 1)
endif ()
find_package(PkgConfig REQUIRED)
#
# PkgConfig in newer versions of cmake (>= cmake 3.6) supports imported
# targets, but older versions do not. if we have 3.6 or better, use
# the builtin imported target unless ${OLD_XPKGIMPORT} is defined.
# otherwise use the Sam Thursfield code below...
#
if (${CMAKE_VERSION} VERSION_LESS 3.6)
set (OLD_XPKGIMPORT 1) # can also set on cmdline -DOLD_XPKGIMPORT=1
endif ()
if (NOT OLD_XPKGIMPORT)
#
# xpkg_import_module(name args)
#
# create an imported target named "name" from a pkg-config module.
# all remaining args are passed through to pkg_check_module().
#
# example:
# xpkg_import_module(glog::glog REQUIRED libglog>=3.0)
#
message (STATUS "note: using built-in pkg_check_module imported targets")
function (xpkg_import_module name)
if (NOT TARGET ${name})
# PkgConfig only adds PREFIX_PATH to PKG_CONFIG_PATH.
# seems like it should add INSTALL_PREFIX too, so we do it here.
# (this doesn't impact the parent variable scope.)
if (CMAKE_INSTALL_PREFIX)
list (APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX})
endif ()
# generate a namespace to put results of pkg_check_modules in.
# newer versions of PkgConfig don't like this to have ":" in it,
# so filter them out...
string (REPLACE ":" "_" cleanname ${name})
set (prefix _${cleanname})
pkg_check_modules("${prefix}" IMPORTED_TARGET ${ARGN})
if (${prefix}_FOUND)
add_library(${name} INTERFACE IMPORTED)
set_property (TARGET ${name} PROPERTY
INTERFACE_LINK_LIBRARIES PkgConfig::${prefix})
endif ()
endif ()
endfunction ()
else (NOT OLD_XPKGIMPORT)
#
# BEGIN:
# pkg-config stuff adapted from https://cmake.org/Bug/view.php?id=15804
# by Sam Thursfield <sam.thursfield@codethink.co.uk>
#
#.rst:
# PkgImportModule
# ---------------
#
# CMake commands to create imported targets from pkg-config modules.
#=========================================================================
# Copyright 2016 Lautsprecher Teufel GmbH
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=========================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
# ::
#
# xpkg_import_module(<name> args)
#
# Creates an imported target named <name> from a pkg-config module. All
# remaining arguments are passed through to pkg_check_module(). See the
# documentation of the FindPkgConfig module for information.
#
# Example usage:
#
# xpkg_import_module(Archive::Archive REQUIRED libarchive>=3.0)
# xpkg_import_module(Avahi::GObject REQUIRED avahi-gobject)
#
message (STATUS "note: using old xpkg_import_module imported targets")
function(xpkg_import_module name)
if (NOT TARGET ${name})
# PkgConfig only adds PREFIX_PATH to PKG_CONFIG_PATH.
# seems like it should add INSTALL_PREFIX too, so we append
# it here (doesn't impact parent scope).
if (CMAKE_INSTALL_PREFIX)
list (APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX})
endif ()
# generate a namespace to put results of pkg_check_modules in.
# newer versions of PkgConfig don't like this to have ":" in it,
# so filter them out...
string (REPLACE ":" "_" cleanname ${name})
set (prefix _${cleanname})
pkg_check_modules("${prefix}" ${ARGN})
_xpkg_import_module_add_imported_target(
${name}
"${${prefix}_CFLAGS_OTHER}"
"${${prefix}_INCLUDE_DIRS}"
"${${prefix}_LIBRARY_DIRS}"
"${${prefix}_LIBRARIES}"
"${${prefix}_STATIC_LIBRARIES}"
)
endif ()
endfunction()
#
# create imported target using info from pkg_check_modules
#
function(_xpkg_import_module_add_imported_target name compile_options include_dirs library_dirs libraries staticlibraries)
# We must pass in the absolute paths to the libraries, otherwise, when
# the library is installed in a non-standard prefix the linker won't be
# able to find the libraries. CMake doesn't provide a way for us to keep
# track of the library search path for a specific target, so we have to
# do it this way.
_xpkg_import_module_find_libraries(libraries_full_paths
${name} "${libraries}" "${library_dirs}")
list(GET libraries_full_paths 0 imported_location)
if (${imported_location} MATCHES ".a$")
# unix guess
add_library(${name} STATIC IMPORTED)
#
# XXXCDC
# static libs do not contain their depends, so we need to fetch
# them again for additional libs that are in ${staticlibraries}.
# we do this by calling _xpkg_import_module_find_libraries() again.
# libs found in the previous call should already be in the cache
# due to earlier calls to find_library() so this should not slow
# us down that much... (this call will update
# ${libraries_full_paths})
#
_xpkg_import_module_find_libraries(libraries_full_paths
${name} "${staticlibraries}" "${library_dirs}")
else ()
# FIXME: we should really detect whether it's SHARED or STATIC,
# instead of assuming SHARED. We can't just use UNKNOWN because
# nothing can link against it then.
add_library(${name} SHARED IMPORTED)
endif ()
#
# gen INTERFACE_LINK_LIBRARIES, it doesn't need the first entry on
# the list since that is already in ${imported_location}
#
set (if_link_libs ${libraries_full_paths})
list (LENGTH if_link_libs n_iflinks)
if (n_iflinks GREATER 0)
list (REMOVE_AT if_link_libs 0) # remove item 0 from list
endif ()
set_target_properties(${name} PROPERTIES
IMPORTED_LOCATION ${imported_location}
INTERFACE_COMPILE_OPTIONS "${compile_options}"
INTERFACE_INCLUDE_DIRECTORIES "${include_dirs}"
INTERFACE_LINK_LIBRARIES "${if_link_libs}"
)
endfunction()
#
# convert list of lib names and dirs into list of library files using
# find_library()
#
function(_xpkg_import_module_find_libraries output_var prefix library_names library_dirs)
foreach(libname ${library_names})
# find_library stores its result in the cache, so we must pass
# a unique variable name for each library that we look for.
set(library_path_var "${prefix}_LIBRARY_${libname}")
find_library(${library_path_var} ${libname} PATHS ${library_dirs})
mark_as_advanced (${library_path_var})
list(APPEND library_paths "${${library_path_var}}")
endforeach()
set(${output_var} ${library_paths} PARENT_SCOPE)
endfunction()
# ::
#
# xadd_object_library_dependencies(<name> <dep1> [<dep2> ...])
#
# This is a workaround for <http://public.kitware.com/Bug/view.php?id=14778>.
# It should be possible to delete this function and use target_link_libraries()
# as normal once that is fixed.
#
function(xadd_object_library_dependencies object_library)
set(dependencies ${ARGN})
foreach(dependency ${dependencies})
if(NOT TARGET ${dependency})
message(FATAL_ERROR
"xadd_object_library_dependencies(): ${dependency} is not "
"a target.")
endif()
target_compile_definitions(
${object_library} PUBLIC
$<TARGET_PROPERTY:${dependency},INTERFACE_COMPILE_DEFINITIONS>)
target_compile_options(
${object_library} PUBLIC
$<TARGET_PROPERTY:${dependency},INTERFACE_COMPILE_OPTIONS>)
target_include_directories(
${object_library} PUBLIC
$<TARGET_PROPERTY:${dependency},INTERFACE_INCLUDE_DIRECTORIES>)
endforeach()
set_property(TARGET ${object_library}
APPEND PROPERTY LINK_LIBRARIES ${dependencies})
endfunction()
#
# pkg-config stuff adapted from https://cmake.org/Bug/view.php?id=15804
# by Sam Thursfield <sam.thursfield@codethink.co.uk>
# END
#
endif (NOT OLD_XPKGIMPORT)
#
# some of the packages we want to import come with either "pkg-config"
# .pc files or with cmake config files, depending on how they were
# installed. for example, glog installed with "apt-get install" on
# "libgoogle-glog-dev" puts in a "libglog.pc" while installing glog
# from source via github installs a cmake config file for glog.
#
# this is complicated by the fact that the pkg-config .pc file names
# the package "libglog" while the cmake config file from github defines
# a library target "glog::glog" that you load with find_package(glog).
#
# we'd like to be able to use either mechanism to find glog, and we'd
# like the resulting target name to match between the two mechanisms
# (i.e. we just want to use "glog::glog" for both cases).
#
# to address this we add a wrapper function that trys both way.
# we first use "find_package()" in hopes of picking up a cmake config.
# if that fails, we fall back to "xpkg_import_module()"...
#
# xdual_import(names)
#
# Where "names" is: target-name,find-package-name,xpkg-names
#
# names can be omitted (target-name will be used)
#
# Example usage:
#
# xdual_import (foo REQUIRED)
# xdual_import (glog::glog,glog,libglog REQUIRED)
#
#
function (xdual_import names)
# parse spec
set (resid ${names})
foreach (var target cm_pkg)
string (FIND "${resid}" "," slash)
if (${slash} EQUAL -1)
set (${var} ${resid})
set (resid "")
else ()
math (EXPR slashplus ${slash}+1)
string (SUBSTRING "${resid}" 0 ${slash} ${var})
string (SUBSTRING "${resid}" ${slashplus} -1 resid)
endif ()
if ("${${var}}" STREQUAL "")
set (${var} ${target})
endif ()
endforeach ()
if ("${resid}" STREQUAL "")
set (xpkg ${target})
else ()
set (xpkg ${resid})
endif ()
# try to find it both ways
if (NOT TARGET ${target})
find_package (${cm_pkg} QUIET)
if (NOT TARGET ${target})
string (REPLACE "," " " xpkg "${xpkg}")
xpkg_import_module (${target} ${ARGN} ${xpkg})
endif ()
endif ()
endfunction ()
#ifndef __SONATA_ADMIN_HPP
#define __SONATA_ADMIN_HPP
#include <thallium.hpp>
#include <memory>
namespace sonata {
class AdminImpl;
class Admin {
public:
Admin(thallium::engine& engine, const std::string& token);
Admin(const Admin&);
Admin(Admin&&);
Admin& operator=(const Admin&);
Admin& operator=(Admin&&);
~Admin();
operator bool() const;
bool createDatabase(const std::string& address,
uint16_t provider_id,
const std::string& name,
const std::string& path) const;
private:
std::shared_ptr<AdminImpl> self;
};
}
#endif
#ifndef __SONATA_BACKEND_HPP
#define __SONATA_BACKEND_HPP
namespace sonata {
class Backend {
public:
};
}
#endif
#ifndef __SONATA_CLIENT_HPP
#define __SONATA_CLIENT_HPP
#include <sonata/Database.hpp>
#include <thallium.hpp>
#include <memory>
namespace sonata {
class ClientImpl;
class Client {
public:
Client(thallium::engine& engine);
Client(const Client&);
Client(Client&&);
Client& operator=(const Client&);
Client& operator=(Client&&);
~Client();
Database open(const std::string& address,
uint16_t provider_id,
const std::string& db_name) const;
operator bool() const;
private:
std::shared_ptr<ClientImpl> self;
};
}
#endif
#ifndef __SONATA_COLLECTION_HPP
#define __SONATA_COLLECTION_HPP
#include <json/json.h>
#include <thallium.hpp>
#include <memory>
namespace sonata {
namespace tl = thallium;
class DatabaseImpl;
class CollectionImpl;
class Collection {
friend class Database;
public:
Collection(const Collection&);
Collection(Collection&&);
Collection& operator=(const Collection&);
Collection& operator=(Collection&&);
~Collection();
operator bool() const;
bool store(const std::string& record,
uint64_t* id) const;
bool store(const Json::Value& record,
uint64_t* id) const;
bool fetch(uint64_t id,
std::string* result) const;
bool fetch(uint64_t id,
Json::Value* result) const;
bool filter(const std::string& filterCode,
std::string* result) const;
bool filter(const std::string& filterCode,
Json::Value* result) const;
bool update(uint64_t id,
const Json::Value& record) const;