Skip to content

Commit

Permalink
[api] Add API for retreiving the process info
Browse files Browse the repository at this point in the history
  • Loading branch information
pajama-coder committed Aug 30, 2023
1 parent 4c65686 commit 19cc58f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/api/pipy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "context.hpp"
#include "worker.hpp"
#include "worker-thread.hpp"
#include "status.hpp"
#include "net.hpp"
#include "outbound.hpp"
#include "utils.hpp"
Expand Down Expand Up @@ -147,6 +148,32 @@ template<> void ClassDef<Pipy>::init() {

variable("outbound", class_of<Pipy::Outbound>());

accessor("pid", [](Object *, Value &ret) {
ret.set((int)getpid());
});

accessor("since", [](Object *, Value &ret) {
ret.set(Status::LocalInstance::since);
});

accessor("source", [](Object *, Value &ret) {
thread_local static pjs::Ref<pjs::Str> str;
if (!str) str = pjs::Str::make(Status::LocalInstance::source);
ret.set(str);
});

accessor("name", [](Object *, Value &ret) {
thread_local static pjs::Ref<pjs::Str> str;
if (!str) str = pjs::Str::make(Status::LocalInstance::name);
ret.set(str);
});

accessor("uuid", [](Object *, Value &ret) {
thread_local static pjs::Ref<pjs::Str> str;
if (!str) str = pjs::Str::make(Status::LocalInstance::uuid);
ret.set(str);
});

method("load", [](Context &ctx, Object*, Value &ret) {
std::string filename;
if (!ctx.arguments(1, &filename)) return;
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ int main(int argc, char *argv[]) {
}

Status::LocalInstance::since = utils::now();
Status::LocalInstance::source = opts.filename;
Status::LocalInstance::name = opts.instance_name;

if (opts.instance_uuid.empty()) {
Expand Down
1 change: 1 addition & 0 deletions src/status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
namespace pipy {

double Status::LocalInstance::since;
std::string Status::LocalInstance::source;
std::string Status::LocalInstance::uuid;
std::string Status::LocalInstance::name;

Expand Down
1 change: 1 addition & 0 deletions src/status.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Status {

struct LocalInstance {
static double since;
static std::string source;
static std::string uuid;
static std::string name;
};
Expand Down

0 comments on commit 19cc58f

Please sign in to comment.