-
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
21 changed files
with
818 additions
and
197 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ GTAGS | |
|
||
/cmake-build-debug/ | ||
/.idea/ | ||
/.clang-format | ||
__pycache__/ |
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,52 @@ | ||
#include "traits.h" | ||
|
||
#include <functional> | ||
|
||
namespace hermes { | ||
namespace api { | ||
Trait::Trait(TraitID id, TraitIdArray conflict_traits, TraitType type) | ||
: id(id), | ||
conflict_traits(conflict_traits), | ||
type(type), | ||
onAttachFn(nullptr), | ||
onDetachFn(nullptr), | ||
onLinkFn(nullptr), | ||
onUnlinkFn(nullptr) {} | ||
|
||
FileMappingTrait::FileMappingTrait( | ||
std::string &filename, std::unordered_map<std::string, u64> &offset_map, | ||
TraitCallback flush_cb, TraitCallback load_cb) | ||
: Trait(FILE_TRAIT, TraitIdArray(), TraitType::FILE_MAPPING), | ||
flush_cb(flush_cb), | ||
load_cb(load_cb), | ||
filename(filename), | ||
offset_map(offset_map) { | ||
this->onAttachFn = std::bind(&FileMappingTrait::onAttach, this, | ||
std::placeholders::_1, std::placeholders::_2); | ||
this->onDetachFn = std::bind(&FileMappingTrait::onDetach, this, | ||
std::placeholders::_1, std::placeholders::_2); | ||
this->onLinkFn = std::bind(&FileMappingTrait::onLink, this, | ||
std::placeholders::_1, std::placeholders::_2); | ||
this->onUnlinkFn = std::bind(&FileMappingTrait::onUnlink, this, | ||
std::placeholders::_1, std::placeholders::_2); | ||
} | ||
void FileMappingTrait::onAttach(TraitInput &input, Trait *trait) { | ||
if (load_cb) { | ||
load_cb(input, trait); | ||
// TODO(hari): @errorhandling Check if load was successful | ||
} | ||
} | ||
void FileMappingTrait::onDetach(TraitInput &input, Trait *trait) { | ||
if (flush_cb) { | ||
flush_cb(input, trait); | ||
// TODO(hari): @errorhandling Check if flush was successful | ||
} | ||
} | ||
void FileMappingTrait::onLink(TraitInput &input, Trait *trait) { | ||
onAttach(input, trait); | ||
} | ||
void FileMappingTrait::onUnlink(TraitInput &input, Trait *trait) { | ||
onDetach(input, trait); | ||
} | ||
} // namespace api | ||
} // namespace hermes |
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,50 @@ | ||
#ifndef HERMES_TRAITS_H | ||
#define HERMES_TRAITS_H | ||
|
||
#include <unordered_map> | ||
|
||
#include "hermes_types.h" | ||
|
||
namespace hermes { | ||
namespace api { | ||
struct BlobInfo { | ||
std::string bucket_name; | ||
std::string blob_name; | ||
}; | ||
typedef BlobInfo TraitInput; | ||
// typedef void* TraitCallback; | ||
|
||
struct Trait; | ||
typedef std::function<void(TraitInput &, Trait *)> TraitCallback; | ||
// typedef void(*TraitCallback)(TraitInput &, Trait *); | ||
struct Trait { | ||
TraitID id; | ||
TraitIdArray conflict_traits; | ||
TraitType type; | ||
TraitCallback onAttachFn; | ||
TraitCallback onDetachFn; | ||
TraitCallback onLinkFn; | ||
TraitCallback onUnlinkFn; | ||
Trait(TraitID id, TraitIdArray conflict_traits, TraitType type); | ||
}; | ||
|
||
#define FILE_TRAIT 10 | ||
|
||
struct FileMappingTrait : public Trait { | ||
public: | ||
TraitCallback flush_cb; | ||
TraitCallback load_cb; | ||
std::string filename; | ||
std::unordered_map<std::string, u64> offset_map; | ||
FileMappingTrait(std::string &filename, | ||
std::unordered_map<std::string, u64> &offset_map, | ||
TraitCallback flush_cb, TraitCallback load_cb); | ||
void onAttach(TraitInput &blob, Trait *trait); | ||
void onDetach(TraitInput &blob, Trait *trait); | ||
void onLink(TraitInput &blob, Trait *trait); | ||
void onUnlink(TraitInput &blob, Trait *trait); | ||
}; | ||
} // namespace api | ||
} // namespace hermes | ||
|
||
#endif // HERMES_TRAITS_H |
Oops, something went wrong.