Home Forums Legacy SDKs Analytics SDK (science application) Reply To: Analytics SDK (science application)


Hi alan,
I think the JNI/JNA route is more accessible than the Python route. But I might be wrong: I don’t know the Python/Java combo well enough.

I think the fastest way to get to working code is to use Swig to create a JNI binding. Not for the whole C++ API but for a small subset. Here is a start, based on the tobiictl sample (I actually built it within the tobiictl project):

Wrapper.h (Where the wrapper class is declared)

#pragma once
#include <string>
#include "MainLoopRunner.h"
#include "tobii/sdk/cpp/GazeDataItem.hpp"

namespace tobii { namespace sdk { namespace cpp { class EyeTracker; } } }

namespace wrapper
    class EyeTracker
        static void initLibrary();

        EyeTracker(const char *trackerId);

        virtual ~EyeTracker() {}

        virtual void onGazeDataReceived(const tobii::sdk::cpp::GazeDataItem& data)
            // default implementation does nothing -- override this method to actually do something with the data

        tobii::sdk::cpp::error_code_t run();

        void onGazeDataReceivedTrampoline(tobii::sdk::cpp::GazeDataItem::pointer_t data)

        MainLoopRunner mainLoopRunner_;
        std::string trackerId_;
        boost::shared_ptr<tobii::sdk::cpp::EyeTracker> tracker_;

Wrapper.cpp (Implementation of the wrapper class)

#include "Wrapper.h"
#include "tobii/sdk/cpp/Library.hpp"
#include "tobii/sdk/cpp/EyeTrackerBrowserFactory.hpp"
#include "tobii/sdk/cpp/EyeTracker.hpp"
#include "tobii/sdk/cpp/EyeTrackerException.hpp"

using namespace wrapper;

void EyeTracker::initLibrary()

EyeTracker::EyeTracker(const char *trackerId)
: trackerId_(trackerId)

tobii::sdk::cpp::error_code_t EyeTracker::run()
        tobii::sdk::cpp::EyeTrackerFactory::pointer_t eyeTrackerFactory = tobii::sdk::cpp::EyeTrackerBrowserFactory::createEyeTrackerFactoryByIpAddressOrHostname(trackerId_, 0, 0);
        tracker_ = eyeTrackerFactory->createEyeTracker(mainLoopRunner_.getMainLoop());
        tracker_->addGazeDataReceivedListener(boost::bind(&EyeTracker::onGazeDataReceivedTrampoline, this, _1));
    catch (tobii::sdk::cpp::EyeTrackerException& ex)
        return ex.getErrorCode();

And finally the Swig interface file, wrapper.i

// enable directors for cross-language polymorphism
%module(directors="1") TobiiAnalyticsSdkModule

%include "Samples/tobiictl/Wrapper.h"

%include <typemaps.i>

// generate directors for all virtual methods in the EyeTracker class.
%feature("director") EyeTracker;

%apply int { tobii::sdk::cpp::error_code_t }
%include "enums.swg"

%include "Samples/tobiictl/Wrapper.h"
%include "Include/tobii/sdk/cpp/GazeDataItem.hpp"

I have to admit it’s not super easy to get this up and running, but it’s certainly possible.