This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Dynamic function call


Hi,

I have a problem when I am calling a dynamically attached object. The idéa
of my code is that all the object that is created within a thread attaches
it self to a dispatcher. This is done so that they can receive messages that
are sent to that thread. Every object attaches it self in a list that means
that when a message is sent to that position in the list then every attached
object receives that message.

Doesn't the linker support this kind of dynamic calls?

However, i want this to be very generic and don't want any object to be
"hardcoded" in the dispatcher. Can anyone tell me why my code doesn't work?

-----clip from the attachfunction in dispatcher-----

void CDispatcher::Attach(CCommon* pMsgHandler, Receiver_t RecObj)
{
 AttachedObjects[RecObj] = pMsgHandler;
}
----endclip------

All object within a thread calles the Attach function and a pointer to
itself is sent as a parameter
-----clip from the caller of dispatcher-----
Dispatcher.Attach(this, USERS);
----endclip------

Here comes all the different ways that i have tried so far. I want to be
able to use the first one but is doesn't work. The array AttachedObjects
declared as a CBase* AttachedObjects[N] so it will contain of a lot of
pointers to all the attached objects. None of the three alternatives below
works!! The only thing that works is when i hardcode the object name in the
function (see clip below)

Any hints?

Regards, Daniel

----clip------- Call one of the attached objects-------
Alt 1
AttachedObjects[(msgRaw->Receiver)]->EventHandler(msgRaw);

Alt 2
 CUsers &test= Users;
 test.EventHandler(msgRaw);

Alt 3
 CUsers *test;
test = &Users
 test->EventHandler(msgRaw);
----endclip------



----clip-----This works!!
 if(msgRaw->Receiver == USERS) Users.EventHandler(msgRaw);
 if(msgRaw->Receiver == CAR) Car.EventHandler(msgRaw);
 if(msgRaw->Receiver == NODEMAN) NodeManager.EventHandler(msgRaw);
----clip-----

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]