Skip to content

Commit

Permalink
Merge 0f96587 into e01c1be
Browse files Browse the repository at this point in the history
  • Loading branch information
jya-kmu committed Sep 15, 2021
2 parents e01c1be + 0f96587 commit 7a8e6da
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 5 deletions.
6 changes: 3 additions & 3 deletions CMake/hermes-config.cmake.build.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ set(HERMES_VERSION_PATCH @HERMES_VERSION_PATCH@)
# project which has already built HERMES as a subproject
#-----------------------------------------------------------------------------
if(NOT TARGET "hermes" AND NOT HERMES_INSTALL_SKIP_TARGETS)
if(NOT TARGET "glog::glog")
include(@GLOG_DIR@/glog-config.cmake)
if(NOT TARGET "thallium")
include(@thallium_DIR@/thallium-config.cmake)
endif()
include(${SELF_DIR}/api/hermes-targets.cmake)
include(${SELF_DIR}/hermes-targets.cmake)
endif()
4 changes: 2 additions & 2 deletions CMake/hermes-config.cmake.install.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ set(HERMES_VERSION_PATCH @HERMES_VERSION_PATCH@)
# project which has already built HERMES as a subproject
#-----------------------------------------------------------------------------
if(NOT TARGET "hermes" AND NOT HERMES_INSTALL_SKIP_TARGETS)
if(NOT TARGET "glog::glog")
include(@GLOG_DIR@/glog-config.cmake)
if(NOT TARGET "thallium")
include(@thallium_DIR@/thallium-config.cmake)
endif()
include(${SELF_DIR}/hermes-targets.cmake)
endif()
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ option(HERMES_BUILD_BENCHMARKS "Build the Hermes benchmark suite." OFF)
option(HERMES_ENABLE_TIMING "Turn on timing of selected functions." OFF)
option(HERMES_ENABLE_COVERAGE "Enable code coverage." OFF)
option(HERMES_ENABLE_ADAPTERS "Enable hermes adapters." ON)
option(HERMES_ENABLE_WRAPPER "Enable hermes C API wrapper." ON)
option(HERMES_INSTALL_TESTS "Enable installation of tests." OFF)
# Calculate code coverage with debug mode
if(HERMES_ENABLE_COVERAGE)
Expand Down Expand Up @@ -335,6 +336,9 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
if(HERMES_ENABLE_ADAPTERS)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/adapter)
endif()
if(HERMES_ENABLE_WRAPPER)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/wrapper)
endif()
#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/mpi_io_adapter)
#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/hermes_vol)

Expand Down
73 changes: 73 additions & 0 deletions wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#------------------------------------------------------------------------------
# Include source and build directories
#------------------------------------------------------------------------------
include_directories(
${PROJECT_SOURCE_DIR}/src/api
${CMAKE_CURRENT_SOURCE_DIR}
${HERMES_INCLUDES_BUILD_TIME}
)

#------------------------------------------------------------------------------
# Hermes Wrapper
#------------------------------------------------------------------------------
add_library(hermes_wrapper hermes_wrapper.cpp)
target_link_libraries(hermes_wrapper ${LIBRT} hermes)
target_compile_definitions(hermes_wrapper
PRIVATE $<$<BOOL:${HERMES_RPC_THALLIUM}>:HERMES_RPC_THALLIUM>)

set(HERMES_EXPORTED_LIBS hermes_wrapper ${HERMES_EXPORTED_LIBS})

#-----------------------------------------------------------------------------
# Add file(s) to CMake Install
#-----------------------------------------------------------------------------
install(
FILES
hermes_wrapper.h
DESTINATION
${HERMES_INSTALL_INCLUDE_DIR}
COMPONENT
headers
)

#-----------------------------------------------------------------------------
# Add Target(s) to CMake Install
#-----------------------------------------------------------------------------
install(
TARGETS
hermes_wrapper
EXPORT
${HERMES_EXPORTED_TARGETS}
LIBRARY DESTINATION ${HERMES_INSTALL_LIB_DIR}
ARCHIVE DESTINATION ${HERMES_INSTALL_LIB_DIR}
RUNTIME DESTINATION ${HERMES_INSTALL_BIN_DIR}
)

#-----------------------------------------------------------------------------
# Export all exported targets to the build tree for use by parent project
#-----------------------------------------------------------------------------
if(NOT HERMES_EXTERNALLY_CONFIGURED)
EXPORT (
TARGETS
${HERMES_EXPORTED_LIBS}
FILE
${HERMES_EXPORTED_TARGETS}.cmake
)
endif()

#------------------------------------------------------------------------------
# Set variables for parent scope
#------------------------------------------------------------------------------
# Used by config.cmake.build.in and Testing
set(HERMES_INCLUDES_BUILD_TIME
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${HERMES_EXT_INCLUDE_DEPENDENCIES}
PARENT_SCOPE
)

# Used by config.cmake.install.in
set(HERMES_INCLUDES_INSTALL_TIME
${HERMES_INSTALL_INCLUDE_DIR}
${HERMES_EXT_INCLUDE_DEPENDENCIES}
PARENT_SCOPE
)
132 changes: 132 additions & 0 deletions wrapper/hermes_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Distributed under BSD 3-Clause license. *
* Copyright by The HDF Group. *
* Copyright by the Illinois Institute of Technology. *
* All rights reserved. *
* *
* This file is part of Hermes. The full Hermes copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the top directory. If you do not *
* have access to the file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "hermes_wrapper.h"

#include "hermes.h"
#include "bucket.h"
#include "vbucket.h"

extern "C" {

std::shared_ptr<hermes::api::Hermes> hermes_ptr;

int HermesInitHermes(char *hermes_config) {
int result = 0;

LOG(INFO) << "Hermes Wrapper: Initializing Hermes\n";

hermes_ptr = hermes::InitHermesDaemon(hermes_config);

return result;
}

void HermesFinalize() {
hermes_ptr->Finalize(true);
}

void HermesVBucketLink(VBucketClass *vbkt, char *blob_name) {
hermes::api::VBucket *vbucket = (hermes::api::VBucket *)vbkt;

LOG(INFO) << "Hermes Wrapper: Linking Blob " << blob_name << "to VBucket "
<< vbucket->GetName() << '\n';

hermes::api::Status status =
vbucket->Link(std::string(blob_name), vbucket->GetName());

if (status.Failed())
LOG(ERROR) << "Hermes Wrapper: HermesVBucketLink failed\n";
}

bool HermesVBucketIsValid(VBucketClass *vbkt) {
hermes::api::VBucket *vbucket = (hermes::api::VBucket *)vbkt;

LOG(INFO) << "Hermes Wrapper: Checking if VBucket is valid\n";

return vbucket->IsValid();
}

BucketClass *HermesBucketCreate(const char *name) {
LOG(INFO) << "Hermes Wrapper: Creating Bucket " << name << '\n';

try {
hermes::api::Bucket *new_bucket =
new hermes::api::Bucket(std::string(name), hermes_ptr);

return (BucketClass *)new_bucket;
}
catch (const std::runtime_error& e) {
LOG(ERROR) << "Blob runtime error\n";
return NULL;
}
catch (const std::length_error& e) {
LOG(ERROR) << "Blob length error\n";
return NULL;
}
}

void HermesBucketClose(BucketClass *bkt) {
hermes::api::Bucket *my_bkt = (hermes::api::Bucket *)bkt;

LOG(INFO) << "Hermes Wrapper: Closing Bucket " << my_bkt->GetName() << '\n';

my_bkt->Release();
delete my_bkt;
}

void HermesBucketDestroy(BucketClass *bkt) {
hermes::api::Bucket *my_bkt = (hermes::api::Bucket *)bkt;

LOG(INFO) << "Hermes Wrapper: Destroying Bucket\n";

my_bkt->Destroy();
delete my_bkt;
}

bool HermesBucketContainsBlob(BucketClass *bkt, char *name) {
hermes::api::Bucket *bucket = (hermes::api::Bucket *)bkt;

LOG(INFO) << "Hermes Wrapper: Checking if Bucket "
<< bucket->GetName()
<< " contains Blob " << name << '\n';

return bucket->ContainsBlob(name);
}

void HermesBucketPut(BucketClass *bkt, char *name, unsigned char *put_data,
size_t size) {
hermes::api::Bucket *bucket = (hermes::api::Bucket *)bkt;

LOG(INFO) << "Hermes Wrapper: Putting Blob " << name << " to bucket " <<
bucket->GetName() << '\n';

hermes::api::Status status = bucket->Put(name, put_data, size);

if (status.Failed())
LOG(ERROR) << "Hermes Wrapper: HermesBucketPut failed\n";
}

void HermesBucketGet(BucketClass *bkt, char *blob_name, size_t page_size,
unsigned char *buf) {
hermes::api::Bucket *bucket = (hermes::api::Bucket *)bkt;
const hermes::api::Context ctx;

LOG(INFO) << "Hermes Wrapper: Getting blob " << blob_name << " from Bucket "
<< bucket->GetName();

size_t blob_size = bucket->Get(blob_name, buf, page_size, ctx);
if (blob_size != page_size)
LOG(ERROR) << "Blob size error: expected to get " << page_size
<< ", but only get " << blob_size << '\n';
}

} // extern "C"
58 changes: 58 additions & 0 deletions wrapper/hermes_wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Distributed under BSD 3-Clause license. *
* Copyright by The HDF Group. *
* Copyright by the Illinois Institute of Technology. *
* All rights reserved. *
* *
* This file is part of Hermes. The full Hermes copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the top directory. If you do not *
* have access to the file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef HERMES_C_WRAPPER_H
#define HERMES_C_WRAPPER_H

#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif

struct BucketClass;
typedef struct BucketClass BucketClass;

struct VBucketClass;
typedef struct VBucketClass VBucketClass;

int HermesInitHermes(char *hermes_config);

void HermesFinalize();

VBucketClass *HermesVBucketCreate(const char *name);

void HermesVBucketLink(VBucketClass *vbkt, char *blob_name);

bool HermesVBucketIsValid(VBucketClass *vbkt);

BucketClass *HermesBucketCreate(const char *name);

void HermesBucketClose(BucketClass *bkt);

void HermesBucketDestroy(BucketClass *bucket_ptr);

bool HermesBucketContainsBlob(BucketClass *bkt, char *name);

void HermesBucketPut(BucketClass *bkt, char *name, unsigned char *put_data,
size_t size);

void HermesBucketGet(BucketClass *bkt, char *blob_name, size_t kPageSize,
unsigned char *buf);

#ifdef __cplusplus
}
#endif

#endif

0 comments on commit 7a8e6da

Please sign in to comment.