Threading and messages


#1

I have a class which does downloading in a separated thread. For example:

[code]class FileManager:public Thread, public MessageListener
{
public:
void* result;
FileManager(void);
virtual void handleMessage (const Message& message);
void run();
};

void FileManager::run()
{
downloadBigFile();
StatusMessage* msg= new StatusMessage(SuccessStat);
postMessage( msg);
}[/code]

and a UI component, which runs thread to download a file:

class SomeComponent: public Component, public MessageListener { void runLoading(); virtual void handleMessage (const Message& message); }
What I want is to receive a message from FileManager inside handleMessage
How should I bind FileManager and SomeComponent to be able to handle messages? Something related to MessageManager ?

Thanks

//corrected code


#2

It sounds like you want to pass arbitrary messages from one thread to another?


#3

yes
Here is my message class:

class StatusMessage: public Message { int m_status; public: StatusMessage(int stat); ~StatusMessage(void); int status(){return m_status;} };
And I want to notify Main UI thread that donwloading is completed and to do something like


#4

So make the thread post a message to the thing you want to notify… (?)


#5

That is my question. How to post it exactly to my component?


#6

That is my question. How to post it exactly to my component?[/quote]

With MessageListener::postMessage() !


#7

I do it like

but cannot receive it in


#8

Then you’re posting it to the wrong place.


#9

I post it in the thread I want to receive a message from.
I’ve found this thread http://www.rawmaterialsoftware.com/viewtopic.php?f=2&t=2869
It appears that MessageListener cannot listen to messages from another thread.


#10

[quote=“acid”]I do it like
CODE: SELECT ALL
postMessage( msg);

but cannot receive it in
CODE: SELECT ALL
SomeComponent::handleMessage[/quote]

you need to do

SomeComponent->postMessage(msg)

#11

It appears that i need to pass pointer to the component to the 2nd thread and then it works.
Thank you.