m_api.add_listener( *this ) Problem

Forum for development in the C++ programming language.

m_api.add_listener( *this ) Problem

Postby mingxinbit » 25 Feb 2014, 08:43

Hi,

m_api.add_listener( *this ), I want to know input parameter "*this", what is meaning? In addition, whether or not I can input other type parameter? What is that?

By the way, please tell me detail about this function m_api.add_listener( *this )'s meaning.

Thank you

Mingxin
mingxinbit
 
Posts: 19
Joined: 22 Jan 2014, 05:59

Re: m_api.add_listener( *this ) Problem

Postby Martin » 25 Feb 2014, 19:08

Passing the pointer to "this" means that you are registering your class with the eye tracker client library. This enables the SDK to make callbacks when new eye data has been calculated. The callback function is:

Code: Select all
void MyClass::on_gaze_data( gtl::GazeData const & gaze_data )
{
    if( gaze_data.state & gtl::GazeData::GD_STATE_TRACKING_GAZE )
    {
        gtl::Point2D const & smoothedCoordinates = gaze_data.avg;
        // Move GUI point, do hit-testing, log coordinates, etc.
    }
}


This will only work if you implement the IGazeListner interface, your class needs to have a signature like this:
Code: Select all
class MyClass : public gtl::IGazeListener


To connect with the server you should have the following code in your constructor (or place of choice)
Code: Select all
MyClass::MyClass()
{
    // Connect to the server in push mode on the default TCP port (6555)
    if( m_api.connect( true ) )
    {
        // Enable GazeData notifications
        m_api.add_listener( *this );
    }
}


And to disconnect:
Code: Select all
MyClass::~MyClass()
{
    m_api.remove_listener( *this );
    m_api.disconnect();
}


Does that help?
Martin
 
Posts: 567
Joined: 29 Oct 2013, 15:20

Re: m_api.add_listener( *this ) Problem

Postby mingxinbit » 25 Feb 2014, 22:26

Thank you for you reply.

I have to describe my problem I faced since I got my eye tracker last night.

This eye tracker looks so cool and run well.

No, I want to use eye tracker into my project. The code I made using C plus plus.

However, I am not sure how to use the API to extract the data. In addition, no C++ samples are provided from website, it is a little pity, although the C# has.

The code I have read in the C++ Tutorials web-page. It looks easily, but I do not know well how it work. Maybe MY c++ is not well, I think.

Currently, I created a console application using C++.

the goal I want to reach is to capture the eye gaze data.

1. I click and run the EyeTribe UI software, then I calibrated my eye tracker. I found the EyeTribe Server also has been run with EyeTribe UI.

2. I shut down the EyeTribe UI software, the EyeTribe Server software still run.

3. I run my code, the easy code like this:
Code: Select all
gtl::GazeApi m_api;
if (m_api.connect(true))
{
    printf("Connected Successful");
}
return this connection is successful. It is cool, I found the near IR lights has been on. Then I have no idea to how to handle it next step.

The above steps I operate is right or wrong?

I want to understand some questions:

1. After calibration I made using your provided software and keep the Server run, I can run my software to capture calibrated eye gaze data, is that right?

2. The MyGaze class provided in this website. Can you tell me how to work in my code using console application program in the VS2010 environment?

3. If I do not want to use the MyGaze class, how to capture calibrated or right eye gaze data? In other words, like below code:
Code: Select all
#include "gazeapi.h"
#include "gazeapi_interfaces.h"
#include "gazeapi_types.h"

int main(int argc, char **argv)
{   
   gtl::GazeApi m_api;

   gtl::GazeData m_point;
   gtl::Point2D m_point2d;

   if (m_api.connect(true))
   {
                m_api.add_listener(* this);
      printf("Connected Successful");
   }

   while (1)
   {
      int x=m_point.lefteye.raw.x;
      printf("%d\n",x);
   }

   return 0;
}

However, after running this code, two errors were provided to me. one is m_api.add_listener(* this) (this is not used in this function?), another is int x=m_point.lefteye.raw.x,(need initialization for m_point?);

Whatever, I hope and better to give me a easily sample me how to use for capture gaze data. I am very looking forward to receive your message.

Thank you so much!
mingxinbit
 
Posts: 19
Joined: 22 Jan 2014, 05:59

Re: m_api.add_listener( *this ) Problem

Postby mingxinbit » 25 Feb 2014, 22:49

By the way, the callback function
Code: Select all
void MyGaze::on_gaze_data( gtl::GazeData const & gaze_data )
how to use?

The process of eye gaze tracker operation is:

1.
Code: Select all
m_api.connect( true )


2.
Code: Select all
m_api.add_listener( *this );


3. Callback function

The step 2 is necessary step? What's role of this function?

Thank you!
mingxinbit
 
Posts: 19
Joined: 22 Jan 2014, 05:59

Re: m_api.add_listener( *this ) Problem

Postby mingxinbit » 26 Feb 2014, 01:26

Also, I found this call back is private function. I do not know how to call this function in the main function?
mingxinbit
 
Posts: 19
Joined: 22 Jan 2014, 05:59

Re: m_api.add_listener( *this ) Problem

Postby mingxinbit » 26 Feb 2014, 01:58

I have another question.

If I want to use the
Code: Select all
gtl::GazeData const & gaze_data;
, the error is displayed:

"must initialize the reference", what's meaning?

Thank you!
mingxinbit
 
Posts: 19
Joined: 22 Jan 2014, 05:59

Re: m_api.add_listener( *this ) Problem

Postby Rafael » 26 Feb 2014, 05:49

Hi mingxinbit,

You should create your own class and, as Martin said, implement the IGazeListener interface. The method m_api.add_listener expects (as a parameter) a class instance which implements this interface. As you'll probably call it from that instance, you pass the *this parameter, where "this" is a pointer to the instance. The official example suggests how you could create such class.

Actually, you could also access the eyetracker without using the API. Just create a socket to connect to the eyetracker and use JSON messages to communicate. See here for more details.

Rafael
Rafael
 
Posts: 13
Joined: 20 Feb 2014, 23:33

Re: m_api.add_listener( *this ) Problem

Postby mingxinbit » 26 Feb 2014, 06:11

Thanks for Rafeal.

But I hope someone can answer my questions above. Thank you!
mingxinbit
 
Posts: 19
Joined: 22 Jan 2014, 05:59

Re: m_api.add_listener( *this ) Problem

Postby mingxinbit » 26 Feb 2014, 06:12

I hope Martin can help me understand my questions above. Thank you so much!
mingxinbit
 
Posts: 19
Joined: 22 Jan 2014, 05:59

Re: m_api.add_listener( *this ) Problem

Postby mingxinbit » 26 Feb 2014, 18:10

I found this SDK no detail about all the operation e.g. class, struct, how to build and use in C++. Why?

I have spent a day for research this code run in VC++ environment. Whatever, at least, tell users how to use you provided class and how to capture gaze data. Because you can not promise all of users are good at computer program like C++. I do hope you can help me, how to use it, could you please give me a simple example.

I am not a coder, I just want to know how to handle it, how to capture data. other thing I do not care.

I hope you can help me.

Thank you so much!
mingxinbit
 
Posts: 19
Joined: 22 Jan 2014, 05:59

Next

Return to C++