Skip to content

Commit

Permalink
fix: use cortex python engine interface (#14)
Browse files Browse the repository at this point in the history
* fix: use cortex python engine interface

* fix: reorder functions

---------

Co-authored-by: vansangpfiev <[email protected]>
  • Loading branch information
vansangpfiev and sangjanai authored May 21, 2024
1 parent d7b2063 commit 5b5ac31
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 49 deletions.
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

0 comments on commit 5b5ac31

Please sign in to comment.