diff --git a/core/LocDualContext.cpp b/core/LocDualContext.cpp index 86c3613a..fa4c4d60 100644 --- a/core/LocDualContext.cpp +++ b/core/LocDualContext.cpp @@ -74,6 +74,8 @@ const MsgTask* LocDualContext::getMsgTask(MsgTask::tAssociate tAssociate, { if (NULL == mMsgTask) { mMsgTask = new MsgTask(tAssociate, name); + } else if (tAssociate) { + mMsgTask->associate(tAssociate); } return mMsgTask; } diff --git a/core/MsgTask.cpp b/core/MsgTask.cpp index 37813394..4db992d9 100644 --- a/core/MsgTask.cpp +++ b/core/MsgTask.cpp @@ -69,6 +69,21 @@ MsgTask::~MsgTask() { msg_q_unblock((void*)mQ); } +void MsgTask::associate(tAssociate tAssociator) const { + struct LocAssociateMsg : public LocMsg { + tAssociate mAssociator; + inline LocAssociateMsg(tAssociate associator) : + LocMsg(), mAssociator(associator) {} + inline virtual void proc() const { + if (mAssociator) { + LOC_LOGD("MsgTask::associate"); + mAssociator(); + } + } + }; + sendMsg(new LocAssociateMsg(tAssociator)); +} + void MsgTask::createPThread(const char* threadName) { pthread_attr_t attr; pthread_attr_init(&attr); diff --git a/core/MsgTask.h b/core/MsgTask.h index d09de731..d50bb31a 100644 --- a/core/MsgTask.h +++ b/core/MsgTask.h @@ -52,6 +52,7 @@ public: MsgTask(tAssociate tAssociator, const char* threadName); ~MsgTask(); void sendMsg(const LocMsg* msg) const; + void associate(tAssociate tAssociator) const; private: const void* mQ;