-
Notifications
You must be signed in to change notification settings - Fork 71
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
1 parent
302c9c8
commit 7c4bb24
Showing
6 changed files
with
122 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
// quack.c | ||
extern "C" void _PG_init(void); | ||
|
||
// quack_hooks.c | ||
extern void quack_init_hooks(void); | ||
extern void quack_init_hooks(void); | ||
|
||
// scanner.cpp | ||
void load_scanner(std::string name); |
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,28 @@ | ||
#pragma once | ||
|
||
extern "C" { | ||
#include "postgres.h" | ||
|
||
#include "utils/relcache.h" | ||
} | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
class Scanner { | ||
public: | ||
static Scanner *SetupScanner(Relation relation); | ||
virtual ~Scanner() = 0; | ||
virtual std::vector<Datum> GetNextChunk(uint32 column_id) = 0; | ||
virtual std::vector<Oid> GetTypes() = 0; | ||
virtual uint32 GetColumnCount() = 0; | ||
virtual uint64 GetCurrentRow(uint32 column_id) = 0; | ||
virtual std::string GetTableName() = 0; | ||
|
||
Relation relation; | ||
}; | ||
|
||
extern "C" void RegisterScanner(char *, void *); | ||
|
||
/* Registration function for loaded scanners. */ | ||
extern "C" void ScannerInit(); |
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,48 @@ | ||
#include <dlfcn.h> | ||
|
||
#include <string> | ||
#include <unordered_map> | ||
|
||
extern "C" { | ||
#include "postgres.h" | ||
|
||
#include "miscadmin.h" | ||
} | ||
|
||
#include "quack/scanner.hpp" | ||
|
||
std::unordered_map<std::string, Scanner *(*)(Relation)> scanners; | ||
|
||
extern "C" void | ||
RegisterScanner(char *name, void *ptr) { | ||
Scanner *(*scanner)(Relation) = (Scanner * (*)(Relation)) ptr; | ||
if (scanners[name] != nullptr) { | ||
elog(WARNING, "Registering scanner %s, which already exists.", name); | ||
} | ||
|
||
scanners[name] = scanner; | ||
} | ||
|
||
void | ||
load_scanner(std::string name) { | ||
std::string path = std::string(pkglib_path) + "/" + name + ".so"; | ||
void *shared_obj = dlopen(path.c_str(), RTLD_NOW); | ||
|
||
if (shared_obj == nullptr) { | ||
elog(WARNING, "Unable to read scanner %s: %s", name.c_str(), dlerror()); | ||
elog(WARNING, "Path: %s", path.c_str()); | ||
|
||
return; | ||
} | ||
|
||
void (*init_scanner)(void) = (void (*)(void))dlsym(shared_obj, "ScannerInit"); | ||
|
||
if (init_scanner == nullptr) { | ||
elog(WARNING, "Unable to find ScannerInit in scanner %s", name.c_str()); | ||
|
||
return; | ||
} | ||
|
||
init_scanner(); | ||
elog(DEBUG5, "Scanner %s initialized", name.c_str()); | ||
} |
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,13 @@ | ||
#include "quack/scanner.hpp" | ||
|
||
extern "C" { | ||
#include "postgres.h" | ||
} | ||
|
||
#include <string> | ||
|
||
void | ||
ScannerInit() { | ||
elog(WARNING, "registering heap"); | ||
RegisterScanner((char *)"heap", nullptr); | ||
} |