Integratin photon project and C++ classes

Hi!!

I’m very new to Photon & QNX, so be patient… :slight_smile:)

I’ve done my first steps in photon, and I have designed the interface of my
application (in fact, just a window and a pair of buttons inside).

In the other hand I have 4 classes written in C++ (developed under unix)
that implement a genetic algorithm.

The big point now is that I want to use this classes in my project. For
example, I would like to call the algorithm when I press one of the buttons
in my window.

Is this integration possible?? What steps do I have to follow?? Do I have to
modify a ‘makefile’ or similar?? And the most important… will my c++ code
compile under photon??

Thanks all.

Jordi Garcia.

Photon has never been very C++ friendly. Which is unfortunate because is
essentially very object oriented itself.

Nonetheless, (and who the hell made up that word?), you can call C++ methods
from Photon callbacks.

The first problem is that Photon won’t use a ‘this’ pointer for you. So,
the first step is to write static method cover functions into your class for
any class methods that you want to call.

I.E.

class myclass
{
public:
void fn_X();
static void fn_X_cover( myclass * mcPtr );
};

static void myclass::fn_X_cover( myclass * mcPtr )
{
mcPtr->fn_X(); // this line fakes a this pointer
};

This way your photon code can call myclass::fn_X_cover( ) and pass in a
pointer to the object to be treated as this and your cover function will do
the call to the real C++ method with a real this.

The second gimmick is that when you tell photon the name of your callback
functions you need to make sure that they will be in a C++ module so that
all of the appropriate name mangling will happen and the linker can find
everything. You do this by adding a file name to the function name in a
callback in the callback editor.

I.E.
Instead of entering a callback function in the callback editor in PhAB as:
“my_callback()”, enter it as “my_callback()@my_callback.cc”. The ‘@’ tells
PhAB that your giving it the exact name of the file that has the function
and the .cc extension tells it that this is a C++ file.

Important Notes:
Make sure that you tell PhAB that your app is a C++ app before you generate
it the first time (by specifying at least one callback with “@*.cc”)
otherwise there will me many assumption that PhAB will make that are invalid
that you will have to hand fix.

Also, I’ve found that .cc works better than .cpp or .C file extensions. I
realize that this should be a matter of personal taste but the .cpp & .C
extensions have both exhibited problems at some point in a project life
cycle.

Good luck.

“Jordi Garcia” <jgbusquets@yahoo.com> wrote in message
news:abc7lu$8c9$1@inn.qnx.com

Hi!!

I’m very new to Photon & QNX, so be patient… > :slight_smile:> )

I’ve done my first steps in photon, and I have designed the interface of
my
application (in fact, just a window and a pair of buttons inside).

In the other hand I have 4 classes written in C++ (developed under unix)
that implement a genetic algorithm.

The big point now is that I want to use this classes in my project. For
example, I would like to call the algorithm when I press one of the
buttons
in my window.

Is this integration possible?? What steps do I have to follow?? Do I have
to
modify a ‘makefile’ or similar?? And the most important… will my c++
code
compile under photon??

Thanks all.

Jordi Garcia.

Thank you very much for the information. After reading your answer I think
it will not be as easy to do as I thought…

Jordi Garcia.


Bill Caroselli (Q-TPS) <QTPS@EarthLink.net> escribió en el mensaje de
noticias abcbm1$as4$1@inn.qnx.com

Photon has never been very C++ friendly. Which is unfortunate because is
essentially very object oriented itself.

Nonetheless, (and who the hell made up that word?), you can call C++
methods
from Photon callbacks.

The first problem is that Photon won’t use a ‘this’ pointer for you. So,
the first step is to write static method cover functions into your class
for
any class methods that you want to call.

I.E.

class myclass
{
public:
void fn_X();
static void fn_X_cover( myclass * mcPtr );
};

static void myclass::fn_X_cover( myclass * mcPtr )
{
mcPtr->fn_X(); // this line fakes a this pointer
};

This way your photon code can call myclass::fn_X_cover( ) and pass in a
pointer to the object to be treated as this and your cover function will
do
the call to the real C++ method with a real this.

The second gimmick is that when you tell photon the name of your callback
functions you need to make sure that they will be in a C++ module so that
all of the appropriate name mangling will happen and the linker can find
everything. You do this by adding a file name to the function name in a
callback in the callback editor.

I.E.
Instead of entering a callback function in the callback editor in PhAB as:
“my_callback()”, enter it as “my_callback()@my_callback.cc”. The ‘@’
tells
PhAB that your giving it the exact name of the file that has the function
and the .cc extension tells it that this is a C++ file.

Important Notes:
Make sure that you tell PhAB that your app is a C++ app before you
generate
it the first time (by specifying at least one callback with “@*.cc”)
otherwise there will me many assumption that PhAB will make that are inval
id
that you will have to hand fix.

Also, I’ve found that .cc works better than .cpp or .C file extensions. I
realize that this should be a matter of personal taste but the .cpp & .C
extensions have both exhibited problems at some point in a project life
cycle.

Good luck.

“Jordi Garcia” <> jgbusquets@yahoo.com> > wrote in message
news:abc7lu$8c9$> 1@inn.qnx.com> …
Hi!!

I’m very new to Photon & QNX, so be patient… > :slight_smile:> )

I’ve done my first steps in photon, and I have designed the interface of
my
application (in fact, just a window and a pair of buttons inside).

In the other hand I have 4 classes written in C++ (developed under unix)
that implement a genetic algorithm.

The big point now is that I want to use this classes in my project. For
example, I would like to call the algorithm when I press one of the
buttons
in my window.

Is this integration possible?? What steps do I have to follow?? Do I
have
to
modify a ‘makefile’ or similar?? And the most important… will my c++
code
compile under photon??

Thanks all.

Jordi Garcia.

\

Well, it is well worth the effort.

“Jordi Garcia” <jgbusquets@yahoo.com> wrote in message
news:aberar$725$1@inn.qnx.com

Thank you very much for the information. After reading your answer I think
it will not be as easy to do as I thought…

Jordi Garcia.


Bill Caroselli (Q-TPS) <> QTPS@EarthLink.net> > escribió en el mensaje de
noticias abcbm1$as4$> 1@inn.qnx.com> …
Photon has never been very C++ friendly. Which is unfortunate because
is
essentially very object oriented itself.

Nonetheless, (and who the hell made up that word?), you can call C++
methods
from Photon callbacks.

The first problem is that Photon won’t use a ‘this’ pointer for you.
So,
the first step is to write static method cover functions into your class
for
any class methods that you want to call.

I.E.

class myclass
{
public:
void fn_X();
static void fn_X_cover( myclass * mcPtr );
};

static void myclass::fn_X_cover( myclass * mcPtr )
{
mcPtr->fn_X(); // this line fakes a this pointer
};

This way your photon code can call myclass::fn_X_cover( ) and pass in a
pointer to the object to be treated as this and your cover function will
do
the call to the real C++ method with a real this.

The second gimmick is that when you tell photon the name of your
callback
functions you need to make sure that they will be in a C++ module so
that
all of the appropriate name mangling will happen and the linker can find
everything. You do this by adding a file name to the function name in a
callback in the callback editor.

I.E.
Instead of entering a callback function in the callback editor in PhAB
as:
“my_callback()”, enter it as “my_callback()@my_callback.cc”. The ‘@’
tells
PhAB that your giving it the exact name of the file that has the
function
and the .cc extension tells it that this is a C++ file.

Important Notes:
Make sure that you tell PhAB that your app is a C++ app before you
generate
it the first time (by specifying at least one callback with “@*.cc”)
otherwise there will me many assumption that PhAB will make that are
inval
id
that you will have to hand fix.

Also, I’ve found that .cc works better than .cpp or .C file extensions.
I
realize that this should be a matter of personal taste but the .cpp & .C
extensions have both exhibited problems at some point in a project life
cycle.

Good luck.

“Jordi Garcia” <> jgbusquets@yahoo.com> > wrote in message
news:abc7lu$8c9$> 1@inn.qnx.com> …
Hi!!

I’m very new to Photon & QNX, so be patient… > :slight_smile:> )

I’ve done my first steps in photon, and I have designed the interface
of
my
application (in fact, just a window and a pair of buttons inside).

In the other hand I have 4 classes written in C++ (developed under
unix)
that implement a genetic algorithm.

The big point now is that I want to use this classes in my project.
For
example, I would like to call the algorithm when I press one of the
buttons
in my window.

Is this integration possible?? What steps do I have to follow?? Do I
have
to
modify a ‘makefile’ or similar?? And the most important… will my c++
code
compile under photon??

Thanks all.

Jordi Garcia.



\

hi all ?
I read the title “Integration photon project and C++ classes” below.
so I try doing this way. but have a few question for this way.

If static method cover functions is written, photon callback function must
create objects
to call static method cover function ,whenever phton callback function is
called.

I.E

photonCallback (Ptwidet_t *widget, ApInfo_t *apinfo, PtCallbackInfo *cbinfo)
{
// create object
Cmyclass myclass;

// call static method cover functions
myclass.fn_X_cover(&myclass);
}

class Cmyclass
{
public:
void fn_x(){
// cleate other objects
// or other functions
}
static void fn_X_cover(Cmyclass *mcPtr);
};

void fn_X_cover(Cmyclass *mcPtr)
{
mcPtr->fn_x();
}

  1. I wish to create myclass object outside callback funtion. before calling
    photonCallback function. how to do ?
    I can’t create myclass object in admain.cc becouse that admain.cc must
    be generated by PhAB tool.


    thank you



    “Bill Caroselli (Q-TPS)” <QTPS@EarthLink.net> wrote in message
    news:abcbm1$as4$1@inn.qnx.com

Photon has never been very C++ friendly. Which is unfortunate because is
essentially very object oriented itself.

Nonetheless, (and who the hell made up that word?), you can call C++
methods
from Photon callbacks.

The first problem is that Photon won’t use a ‘this’ pointer for you. So,
the first step is to write static method cover functions into your class
for
any class methods that you want to call.

I.E.

class myclass
{
public:
void fn_X();
static void fn_X_cover( myclass * mcPtr );
};

static void myclass::fn_X_cover( myclass * mcPtr )
{
mcPtr->fn_X(); // this line fakes a this pointer
};

This way your photon code can call myclass::fn_X_cover( ) and pass in a
pointer to the object to be treated as this and your cover function will
do
the call to the real C++ method with a real this.

The second gimmick is that when you tell photon the name of your callback
functions you need to make sure that they will be in a C++ module so that
all of the appropriate name mangling will happen and the linker can find
everything. You do this by adding a file name to the function name in a
callback in the callback editor.

I.E.
Instead of entering a callback function in the callback editor in PhAB as:
“my_callback()”, enter it as “my_callback()@my_callback.cc”. The ‘@’
tells
PhAB that your giving it the exact name of the file that has the function
and the .cc extension tells it that this is a C++ file.

Important Notes:
Make sure that you tell PhAB that your app is a C++ app before you
generate
it the first time (by specifying at least one callback with “@*.cc”)
otherwise there will me many assumption that PhAB will make that are
invalid
that you will have to hand fix.

Also, I’ve found that .cc works better than .cpp or .C file extensions. I
realize that this should be a matter of personal taste but the .cpp & .C
extensions have both exhibited problems at some point in a project life
cycle.

Good luck.

“Jordi Garcia” <> jgbusquets@yahoo.com> > wrote in message
news:abc7lu$8c9$> 1@inn.qnx.com> …
Hi!!

I’m very new to Photon & QNX, so be patient… > :slight_smile:> )

I’ve done my first steps in photon, and I have designed the interface of
my
application (in fact, just a window and a pair of buttons inside).

In the other hand I have 4 classes written in C++ (developed under unix)
that implement a genetic algorithm.

The big point now is that I want to use this classes in my project. For
example, I would like to call the algorithm when I press one of the
buttons
in my window.

Is this integration possible?? What steps do I have to follow?? Do I
have
to
modify a ‘makefile’ or similar?? And the most important… will my c++
code
compile under photon??

Thanks all.

Jordi Garcia.

\