# HG changeset patch # User sl # Date 1394995821 -3600 # Node ID d9a866996670f197dcec8cf278a636e77847f0fb # Parent 523a7dc3469f73879743f718055c6b4b7f83c225 Improved event framework. Init now properly reporting notification. diff -r 523a7dc3469f -r d9a866996670 Event.cpp --- a/Event.cpp Sun Mar 16 09:11:39 2014 +0100 +++ b/Event.cpp Sun Mar 16 19:50:21 2014 +0100 @@ -27,3 +27,17 @@ WaitForSingleObject(m_hEvent, INFINITE); } //------------------------------------------------------------------------------ + + +// +// +// + +LRESULT WindowEvent::Execute(UINT aMsg) + { + //Typically only execute if the given message is for us + if (aMsg==iMsg) + { + return DoExecute(); + } + } \ No newline at end of file diff -r 523a7dc3469f -r d9a866996670 Event.h --- a/Event.h Sun Mar 16 09:11:39 2014 +0100 +++ b/Event.h Sun Mar 16 19:50:21 2014 +0100 @@ -22,6 +22,24 @@ private: HANDLE m_hEvent; }; + + +/** +*/ +class WindowEvent: public Event +{ +public: + WindowEvent(HWND aWnd, UINT aMsg):Event(),iWnd(aWnd),iMsg(aMsg){} + + BOOL Post(){return PostMessage(iWnd, iMsg, (WPARAM)this, (LPARAM)NULL);} + virtual LRESULT Execute(UINT aMsg); + virtual LRESULT DoExecute() = 0; + +protected: + HWND iWnd; + UINT iMsg; +}; + //------------------------------------------------------------------------------ #endif //------------------------------------------------------------------------------ diff -r 523a7dc3469f -r d9a866996670 IdwThread.cpp --- a/IdwThread.cpp Sun Mar 16 09:11:39 2014 +0100 +++ b/IdwThread.cpp Sun Mar 16 19:50:21 2014 +0100 @@ -24,12 +24,24 @@ #define WM_IDW_SETLCDPROGRESS (WM_USER + 18) #define WM_IDW_INTERRUPT (WM_USER + 100) //------------------------------------------------------------------------------ -struct IdwImonInitResult -{ - DSPResult result; - DSPNInitResult initResult; - DSPType dspType; -}; + +/** +*/ +class IdwImonInitRequest : public WindowEvent + { +public: + IdwImonInitRequest(HWND aWnd, UINT aMsg): WindowEvent(aWnd,aMsg) {} + //from WindowEvent + virtual LRESULT DoExecute(); + void HandleImonNotifications(WPARAM wParam, LPARAM lParam); +public: + DSPNotifyCode iNotification; + DSPResult iResult; + DSPNInitResult iInitResult; + DSPType iDspType; + static const UINT KMsgIdImonNotification = WM_IDW_IMON; + }; + struct IdwSetVfdText { DSPResult result; @@ -97,17 +109,17 @@ if (!WaitForWindow()) return DSP_E_FAIL; - IdwImonInitResult result; - Event finished; - PostMessage(m_hWnd, WM_IDW_INIT, (WPARAM)&result, (LPARAM)&finished); - finished.Await(); + IdwImonInitRequest request(m_hWnd, WM_IDW_INIT); + request.Post(); + request.Await(); if (pInitResult != NULL) { - pInitResult->initResult = result.initResult; - pInitResult->dspType = result.dspType; + pInitResult->iInitResult = request.iInitResult; + pInitResult->iDspType = request.iDspType; + pInitResult->iNotification = request.iNotification; } - return result.result; + return request.iResult; } //------------------------------------------------------------------------------ DSPResult IdwThread::Uninit() @@ -442,12 +454,9 @@ return true; } //------------------------------------------------------------------------------ -LRESULT CALLBACK IdwThread::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, - LPARAM lParam) -{ - static bool initing = false; - static IdwImonInitResult* pInitResult = NULL; - static Event* pInitFinished = NULL; +LRESULT CALLBACK IdwThread::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + static IdwImonInitRequest* initRequest = NULL; DSPResult* pResult; Event* pFinished; @@ -461,29 +470,26 @@ PostQuitMessage(0); return 0; - case WM_IDW_IMON: - if (initing) - { - initing = false; - pInitResult->initResult = (DSPNInitResult)wParam; - pInitResult->dspType = (DSPType)lParam; - pInitFinished->Signal(); - } - return 0; + //Notifications from iMON Display API + case IdwImonInitRequest::KMsgIdImonNotification: + if (initRequest) + { + initRequest->HandleImonNotifications(wParam,lParam); + initRequest=NULL; + } + return 0; case WM_IDW_INIT: - initing = true; - pInitResult = (IdwImonInitResult*)wParam; - pInitFinished = (Event*)lParam; - pInitResult->result = IMON_Display_Init(hwnd, WM_IDW_IMON); - if (pInitResult->result != DSP_SUCCEEDED) - { - initing = false; - pInitResult->initResult = DSPN_ERR_UNKNOWN; - pInitResult->dspType = DSPN_DSP_NONE; - pInitFinished->Signal(); - } - return 0; + { + initRequest = (IdwImonInitRequest*)wParam; + LRESULT res=initRequest->Execute(uMsg); + if (res==1) + { + //Request has been completed + initRequest=NULL; + } + return 0; + } case WM_IDW_UNINIT: pResult = (DSPResult*)wParam; @@ -742,4 +748,55 @@ return L'#'; } } -//------------------------------------------------------------------------------ + +/** +Handle iMON notifications +*/ +void IdwImonInitRequest::HandleImonNotifications(WPARAM wParam, LPARAM lParam) + { + iNotification=(DSPNotifyCode)wParam; + iDspType=DSPN_DSP_NONE; + iResult= DSP_SUCCEEDED; + + switch (iNotification) + { + case DSPNM_PLUGIN_SUCCEED: + case DSPNM_IMON_RESTARTED: + case DSPNM_HW_CONNECTED: + //lParam is display type + iDspType = (DSPType)lParam; + break; + case DSPNM_PLUGIN_FAILED: + case DSPNM_HW_DISCONNECTED: + case DSPNM_IMON_CLOSED: + //lParam is error + iInitResult = (DSPNInitResult)lParam; + break; + case DSPNM_LCD_TEXT_SCROLL_DONE: + //That should not happen, report an error + iResult = DSP_E_FAIL; + break; + } + + //Complete our request + Signal(); + } + + +/** +Run our display initialization. +*/ +LRESULT IdwImonInitRequest::DoExecute() + { + iResult = IMON_Display_Init(iWnd, KMsgIdImonNotification); + if (iResult != DSP_SUCCEEDED) + { + iNotification = DSPNM_PLUGIN_FAILED; + iInitResult = DSPN_ERR_UNKNOWN; + iDspType = DSPN_DSP_NONE; + Signal(); + return 1; + } + + return 0; + } diff -r 523a7dc3469f -r d9a866996670 IdwThread.h --- a/IdwThread.h Sun Mar 16 09:11:39 2014 +0100 +++ b/IdwThread.h Sun Mar 16 19:50:21 2014 +0100 @@ -12,51 +12,49 @@ class IdwThread : public Thread { public: - IdwThread(HINSTANCE hInstance); - virtual ~IdwThread(); + IdwThread(HINSTANCE hInstance); + virtual ~IdwThread(); private: - IdwThread(const IdwThread& other) {} - IdwThread& operator=(const IdwThread& other) { return *this; } + IdwThread(const IdwThread& other) {} + IdwThread& operator=(const IdwThread& other) { return *this; } public: - virtual void Interrupt(); - DSPResult Init(IDW_INITRESULT* pInitResult); - DSPResult Uninit(); - DSPResult IsInited(); - DSPResult IsPluginModeEnabled(); - DSPResult SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2); - DSPResult SetVfdEqData(PDSPEQDATA pEqData); - DSPResult SetLcdText(LPCWSTR lpszText); - DSPResult SetLcdEqData(PDSPEQDATA pEqDataL, PDSPEQDATA pEqDataR); - DSPResult SetLcdAllIcons(BOOL bOn); - DSPResult SetLcdOrangeIcon(BYTE btIconData1, BYTE btIconData2); - DSPResult SetLcdMediaTypeIcon(BYTE btIconData); - DSPResult SetLcdSpeakerIcon(BYTE btIconData1, BYTE btIconData2); - DSPResult SetLcdVideoCodecIcon(BYTE btIconData); - DSPResult SetLcdAudioCodecIcon(BYTE btIconData); - DSPResult SetLcdAspectRatioIcon(BYTE btIconData); - DSPResult SetLcdEtcIcon(BYTE btIconData); - DSPResult SetLcdProgress(int nCurPos, int nTotal); + virtual void Interrupt(); + DSPResult Init(IDW_INITRESULT* pInitResult); + DSPResult Uninit(); + DSPResult IsInited(); + DSPResult IsPluginModeEnabled(); + DSPResult SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2); + DSPResult SetVfdEqData(PDSPEQDATA pEqData); + DSPResult SetLcdText(LPCWSTR lpszText); + DSPResult SetLcdEqData(PDSPEQDATA pEqDataL, PDSPEQDATA pEqDataR); + DSPResult SetLcdAllIcons(BOOL bOn); + DSPResult SetLcdOrangeIcon(BYTE btIconData1, BYTE btIconData2); + DSPResult SetLcdMediaTypeIcon(BYTE btIconData); + DSPResult SetLcdSpeakerIcon(BYTE btIconData1, BYTE btIconData2); + DSPResult SetLcdVideoCodecIcon(BYTE btIconData); + DSPResult SetLcdAudioCodecIcon(BYTE btIconData); + DSPResult SetLcdAspectRatioIcon(BYTE btIconData); + DSPResult SetLcdEtcIcon(BYTE btIconData); + DSPResult SetLcdProgress(int nCurPos, int nTotal); protected: - virtual void Run(); + virtual void Run(); + +private: + bool RegisterClass(); + bool CreateMessageWindow(); + void AllowImonMessages(); + bool WaitForWindow(); + static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + static void MapChars(LPWSTR lpszTarget, LPCWSTR lpszSource, int nMaxLength); + static wchar_t MapChar(wchar_t ch); private: - bool RegisterClass(); - bool CreateMessageWindow(); - void AllowImonMessages(); - bool WaitForWindow(); - static LRESULT CALLBACK WndProc( - HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); - static void MapChars( - LPWSTR lpszTarget, LPCWSTR lpszSource, int nMaxLength); - static wchar_t MapChar(wchar_t ch); - -private: - HINSTANCE m_hInstance; - HWND m_hWnd; - Event m_eventWindowCreationDone; + HINSTANCE m_hInstance; + HWND m_hWnd; + Event m_eventWindowCreationDone; }; //------------------------------------------------------------------------------ #endif diff -r 523a7dc3469f -r d9a866996670 iMONDisplayWrapper.h --- a/iMONDisplayWrapper.h Sun Mar 16 09:11:39 2014 +0100 +++ b/iMONDisplayWrapper.h Sun Mar 16 19:50:21 2014 +0100 @@ -12,10 +12,11 @@ #endif //------------------------------------------------------------------------------ typedef struct _IDW_INITRESULT -{ - DSPNInitResult initResult; - DSPType dspType; -} IDW_INITRESULT; + { + DSPNotifyCode iNotification; + DSPNInitResult iInitResult; + DSPType iDspType; + } IDW_INITRESULT; //------------------------------------------------------------------------------ #ifdef __cplusplus extern "C"