-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
271 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
* 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(); | ||
} | ||
|
||
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |