HoboVR-Labs / issue_tracker

General issues to fix or features to be implemented
3 stars 0 forks source link

[FEATURE REQ]: gaze master app plugins #20

Open okawo80085 opened 2 years ago

okawo80085 commented 2 years ago

Allow plugins for gaze master to change the API it uses to comm with apps.

okawo80085 commented 2 years ago

The first version of the gaze master plugins is done, kinda, it's a bit broken on windows at the moment, but plugins looks something like this right now:

#if defined(LINUX)
    #define PLUGIN_DLL_EXPORT extern "C" __attribute__((visibility("default")))
    #define PLUGIN_DLL_IMPORT extern "C"
#elif defined(WIN)
    #define PLUGIN_DLL_EXPORT extern "C" __declspec(dllexport)
    #define PLUGIN_DLL_IMPORT extern "C" __declspec(dllimport)
#else
    #error "Unsupported Platform."
#endif

#include "gaze_master_plugin_interface.h"

#include <fstream>

class GazeLogger: public gaze::PluginBase {
public:
    GazeLogger() = default;
    virtual ~GazeLogger() = default;

    virtual bool Activate() {
        m_file = std::move(std::ofstream("/tmp/GazeLogger_out.log", std::ios::binary));
        h = 0;
        return !m_file.bad();
    }

    virtual void ProcessData(const HoboVR_GazeState_t& data) {
        if (h % 200 == 0 && m_file.is_open()) {
            m_file << "gaze data: " << data.status << ", "
                << data.age_seconds << ", ("
                << data.pupil_position_r[0] << "," << data.pupil_position_r[1] << "), "
                << data.pupil_position_l[0] << "," << data.pupil_position_l[1] << "), "
                << data.pupil_dilation_r << ", " << data.pupil_dilation_l << ", "
                << data.eye_close_r << ", " << data.eye_close_l << ";\n";
            m_file.flush();
            h = 0;
        }
        h++;
    }

    virtual std::string GetNameAndVersion() {
        return "GazeLogger_v0.0.1";
    }

    virtual std::string GetLastError() {
        return "failed to open file";
    }

private:
    std::ofstream m_file;
    int h = 0;
};

PLUGIN_DLL_EXPORT gaze::PluginBase* gazePluginFactory() {
    return new GazeLogger;
}

I think the plugin itself needs to know GazeMaster's version though, so maybe make it the arg to Activate()? @SimLeek @Minothor what do you guys think?

okawo80085 commented 2 years ago

Relates to #2

okawo80085 commented 2 years ago

Yeah im adding plugin interface version as args to activate of the plugin

Minothor commented 2 years ago

sorry, just picked up on the mention, Id say yeah, add it as an optional arg to Activate with it assuming latest on default?

okawo80085 commented 2 years ago

Not optional, cuz it can potentially break the plugin ABI, which would SEGFAULT our driver

okawo80085 commented 2 years ago

This arg is meant to tell the plugin "hey this is the version we have, compare it to yours, if you can work with that, kewl, if not gtfo"

okawo80085 commented 1 year ago

There are currently some issues with multiple plugins being loaded, almost definitely the cause is factory symbol loading, but can't test it yet.

okawo80085 commented 1 year ago

Lets try using boost's for importing dynamic libs...