Added a ApplicationThread::InMainThread to check if you're currently in the applications thread.

This commit is contained in:
Daniel Önnerby 2008-04-27 23:17:56 +00:00
parent 76b52a99b7
commit 23edf06444
4 changed files with 24 additions and 12 deletions

View File

@ -107,13 +107,12 @@ void TransportController::OnVolumeSliderChange()
}
void TransportController::OnTrackChange(musik::core::TrackPtr track){
win32cpp::ApplicationThread::Call1(this,&TransportController::OnTrackChangeAppThread,track);
}
void TransportController::OnTrackChangeAppThread(musik::core::TrackPtr track){
/* musik::core::TrackPtr track = musik::core::PlaybackQueue::Instance().CurrentTrack();
this->transportView.titleLabel. // HMM.. Can't find how to set the labels
*/
if(!win32cpp::ApplicationThread::InMainThread()){
win32cpp::ApplicationThread::Call1(this,&TransportController::OnTrackChange,track);
return;
}
// this->transportView.titleLabel. // HMM.. Can't find how to set the labels
}

View File

@ -66,7 +66,6 @@ protected: void OnNextPressed();
protected: void OnPreviousPressed();
protected: void OnVolumeSliderChange();
protected: void OnTrackChange(musik::core::TrackPtr track);
protected: void OnTrackChangeAppThread(musik::core::TrackPtr track);
};
//////////////////////////////////////////////////////////////////////////////

View File

@ -46,12 +46,23 @@ using namespace win32cpp;
ApplicationThread::ApplicationThread(void)
: helperWindow(NULL)
{
this->applicationThreadId = GetCurrentThreadId();
}
ApplicationThread::~ApplicationThread(void){
delete this->helperWindow;
}
bool ApplicationThread::InMainThread(){
ApplicationThread *thread=Application::Instance().thread;
if(thread){
DWORD theThread = GetCurrentThreadId();
return thread->applicationThreadId==theThread;
}
return false;
}
void ApplicationThread::AddCall(CallClassBase *callClass){
this->calls.push_back(CallClassPtr(callClass));
this->NotifyMainThread();

View File

@ -56,12 +56,15 @@ class ApplicationThread{
ApplicationThread(void);
void MainThreadCallback();
void NotifyMainThread();
void Initialize();
DWORD applicationThreadId;
boost::mutex mutex;
public:
~ApplicationThread(void);
void Initialize();
static bool InMainThread();
//////////////////////////////////////////////////////////////////////////////
private:
@ -120,7 +123,7 @@ class ApplicationThread{
public:
sigslot::signal1<Arg1Type> signal;
Arg1Type arg1mem;
CallClass1(DestinationType* destinationObject,void (DestinationType::*memberMethod)(Arg1Type),Arg1Type arg1) : arg1mem(arg1){
CallClass1(DestinationType* destinationObject,void (DestinationType::*memberMethod)(Arg1Type),Arg1Type &arg1) : arg1mem(arg1){
this->signal.connect(destinationObject,memberMethod);
};
@ -131,7 +134,7 @@ class ApplicationThread{
public:
template<class DestinationType,class Arg1Type>
static void Call1(DestinationType* destinationObject,void (DestinationType::*memberMethod)(Arg1Type),Arg1Type arg1){
static void Call1(DestinationType* destinationObject,void (DestinationType::*memberMethod)(Arg1Type),Arg1Type &arg1){
win32cpp::Application::Instance().thread->AddCall(new CallClass1<DestinationType,Arg1Type>(destinationObject,memberMethod,arg1));
};