Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use cortex python engine interface #14

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions base/cortex-common/cortexpythoni.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <functional>
#include <memory>

#include "json/value.h"

class CortexPythonEngineI {
public:
virtual ~CortexPythonEngineI() {}

virtual bool IsSupported(const std::string& f) {
if (f == "ExecutePythonFile" || f == "HandlePythonFileExecutionRequest") {
return true;
}
return false;
}

virtual void ExecutePythonFile(std::string binary_execute_path,
std::string file_execution_path,
std::string python_library_path) = 0;

virtual void HandlePythonFileExecutionRequest(
std::shared_ptr<Json::Value> json_body,
std::function<void(Json::Value&&, Json::Value&&)>&& callback) = 0;
};
42 changes: 0 additions & 42 deletions base/cortex-common/enginei.h

This file was deleted.

8 changes: 4 additions & 4 deletions examples/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#include "httplib.h"
#include "json/reader.h"
#include "json/forwards.h"
#include "base/cortex-common/enginei.h"
#include "base/cortex-common/cortexpythoni.h"
#include "trantor/utils/Logger.h"

class Server {
public:
Server() {
dylib_ = std::make_unique<dylib>("./engines/cortex.python", "engine");
auto func = dylib_->get_function<EngineI*()>("get_engine");
auto func = dylib_->get_function<CortexPythonEngineI*()>("get_engine");
engine_ = func();
}

Expand All @@ -26,7 +26,7 @@ class Server {
}
}

EngineI* GetEngine() const {
CortexPythonEngineI* GetEngine() const {
return engine_;
}

Expand All @@ -53,7 +53,7 @@ class Server {

private:
std::unique_ptr<dylib> dylib_;
EngineI* engine_;
CortexPythonEngineI* engine_;

};

Expand Down
2 changes: 1 addition & 1 deletion src/python_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void PythonEngine::HandlePythonFileExecutionRequestImpl(
};

extern "C" {
EngineI* get_engine() {
CortexPythonEngineI* get_engine() {
return new PythonEngine();
}
} // extern C
4 changes: 2 additions & 2 deletions src/python_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#include <functional>
#include <memory>

#include "base/cortex-common/enginei.h"
#include "base/cortex-common/cortexpythoni.h"
#include "json/forwards.h"
#include "src/python_file_execution_request.h"

class PythonEngine : public EngineI {
class PythonEngine : public CortexPythonEngineI {
public:
~PythonEngine() final;

Expand Down
Loading