# HG changeset patch # User sl # Date 1395055759 -3600 # Node ID 558712318e1b49684cd456793b623f0e3b37ee46 # Parent d9a866996670f197dcec8cf278a636e77847f0fb Adding support for status request. diff -r d9a866996670 -r 558712318e1b IdwApi.cpp --- a/IdwApi.cpp Sun Mar 16 19:50:21 2014 +0100 +++ b/IdwApi.cpp Mon Mar 17 12:29:19 2014 +0100 @@ -1,6 +1,7 @@ //------------------------------------------------------------------------------ #include "IdwApi.h" #include + //------------------------------------------------------------------------------ IdwApi::IdwApi(HINSTANCE hInstance) : m_hInstance(hInstance) @@ -50,7 +51,7 @@ return ret; } //------------------------------------------------------------------------------ -DSPResult IdwApi::IsInited() +DSPResult IdwApi::IsInitialized() { m_mutex.Request(); if (m_nInitCount == 0) @@ -75,6 +76,25 @@ m_mutex.Release(); return ret; } + +/** +Fetch our current status. +It's actually just the last notification from iMON. +*/ +DSPResult IdwApi::GetStatus(IDW_STATUS* aStatus) + { + m_mutex.Request(); + if (m_nInitCount == 0) + { + m_mutex.Release(); + return DSP_E_NOT_INITED; + } + + DSPResult ret = m_pIdwThread->GetStatus(aStatus); + m_mutex.Release(); + return ret; + } + //------------------------------------------------------------------------------ DSPResult IdwApi::SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2) { diff -r d9a866996670 -r 558712318e1b IdwApi.h --- a/IdwApi.h Sun Mar 16 19:50:21 2014 +0100 +++ b/IdwApi.h Mon Mar 17 12:29:19 2014 +0100 @@ -7,7 +7,12 @@ #include "iMONDisplayDefines.h" #include "iMONDisplayWrapper.h" #include "IdwThread.h" -//------------------------------------------------------------------------------ + +/** +Provide access to iMON Display API. +We have one instance of this object per process attaching our DLL. +It basically synchronize and forward API calls to our Window through our thread object. +*/ class IdwApi { public: @@ -17,8 +22,9 @@ public: DSPResult Init(IDW_INITRESULT* pInitResult); DSPResult Uninit(); - DSPResult IsInited(); + DSPResult IsInitialized(); DSPResult IsPluginModeEnabled(); + DSPResult GetStatus(IDW_STATUS* aStatus); DSPResult SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2); DSPResult SetVfdEqData(PDSPEQDATA pEqData); DSPResult SetLcdText(LPCWSTR lpszText); @@ -39,7 +45,7 @@ private: HINSTANCE m_hInstance; - Mutex m_mutex; + Mutex m_mutex; ///Used to guarantee we only have one request running at a time. int m_nInitCount; IdwThread* m_pIdwThread; }; diff -r d9a866996670 -r 558712318e1b IdwThread.cpp --- a/IdwThread.cpp Sun Mar 16 19:50:21 2014 +0100 +++ b/IdwThread.cpp Mon Mar 17 12:29:19 2014 +0100 @@ -22,10 +22,12 @@ #define WM_IDW_SETLCDASPECTRATIO (WM_USER + 16) #define WM_IDW_SETLCDETCICON (WM_USER + 17) #define WM_IDW_SETLCDPROGRESS (WM_USER + 18) +#define WM_IDW_STATUS (WM_USER + 19) #define WM_IDW_INTERRUPT (WM_USER + 100) //------------------------------------------------------------------------------ /** +iMON Display initialization request. */ class IdwImonInitRequest : public WindowEvent { @@ -42,6 +44,22 @@ static const UINT KMsgIdImonNotification = WM_IDW_IMON; }; + +/** +iMON Display status request. +Retrieve the latest iMON notification code. +*/ +class IdwImonStatusRequest : public WindowEvent + { +public: + IdwImonStatusRequest(HWND aWnd, UINT aMsg): WindowEvent(aWnd,aMsg) {} + //from WindowEvent + virtual LRESULT DoExecute(); +public: + DSPResult iResult; + DSPNotifyCode iNotification; + }; + struct IdwSetVfdText { DSPResult result; @@ -103,7 +121,11 @@ return; PostMessage(m_hWnd, WM_IDW_INTERRUPT, 0, 0); } -//------------------------------------------------------------------------------ + +/** +Issue iMON initialization request. +@param [in, out] Contains our request results on return. +*/ DSPResult IdwThread::Init(IDW_INITRESULT* pInitResult) { if (!WaitForWindow()) @@ -147,6 +169,29 @@ return result; } + +/** +Issue iMON initialization request. +@param [in, out] Contains our request results on return. +*/ +DSPResult IdwThread::GetStatus(IDW_STATUS* aStatus) + { + if (!WaitForWindow()) + { + return DSP_E_FAIL; + } + + IdwImonStatusRequest request(m_hWnd, WM_IDW_STATUS); + request.Post(); + request.Await(); + if (aStatus != NULL) + { + aStatus->iNotification = request.iNotification; + } + + return request.iResult; + } + //------------------------------------------------------------------------------ DSPResult IdwThread::IsPluginModeEnabled() { @@ -457,7 +502,7 @@ LRESULT CALLBACK IdwThread::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static IdwImonInitRequest* initRequest = NULL; - + static DSPNotifyCode notification = DSPNM_PLUGIN_FAILED; DSPResult* pResult; Event* pFinished; @@ -472,6 +517,7 @@ //Notifications from iMON Display API case IdwImonInitRequest::KMsgIdImonNotification: + notification=(DSPNotifyCode)wParam; //Keep track of our current status if (initRequest) { initRequest->HandleImonNotifications(wParam,lParam); @@ -512,6 +558,15 @@ pFinished->Signal(); return 0; + case WM_IDW_STATUS: + { + IdwImonStatusRequest* request = (IdwImonStatusRequest*)wParam; + request->iNotification = notification; //Get our notification code + request->iResult = DSP_SUCCEEDED; + LRESULT res=request->Execute(uMsg); + return 0; + } + case WM_IDW_SETVFDTEXT: { IdwSetVfdText* pSetVfdText = (IdwSetVfdText*)wParam; @@ -800,3 +855,12 @@ return 0; } + + +/** +*/ +LRESULT IdwImonStatusRequest::DoExecute() + { + Signal(); + return 0; + } \ No newline at end of file diff -r d9a866996670 -r 558712318e1b IdwThread.h --- a/IdwThread.h Sun Mar 16 19:50:21 2014 +0100 +++ b/IdwThread.h Mon Mar 17 12:29:19 2014 +0100 @@ -8,7 +8,15 @@ #include "Mutex.h" #include "iMONDisplayDefines.h" #include "iMONDisplayWrapper.h" -//------------------------------------------------------------------------------ + + +/** +iMON Display Wrapper thread. +Create a window and implement its event loop. +This window will be used to process iMON display messages. +Implement iMON Display API by send messages to our window. +Actual iMON Display API call call are made from the window procedure. +*/ class IdwThread : public Thread { public: @@ -25,6 +33,7 @@ DSPResult Uninit(); DSPResult IsInited(); DSPResult IsPluginModeEnabled(); + DSPResult GetStatus(IDW_STATUS* aStatus); DSPResult SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2); DSPResult SetVfdEqData(PDSPEQDATA pEqData); DSPResult SetLcdText(LPCWSTR lpszText); @@ -38,7 +47,7 @@ DSPResult SetLcdAspectRatioIcon(BYTE btIconData); DSPResult SetLcdEtcIcon(BYTE btIconData); DSPResult SetLcdProgress(int nCurPos, int nTotal); - + protected: virtual void Run(); diff -r d9a866996670 -r 558712318e1b iMONDisplayWrapper.cpp --- a/iMONDisplayWrapper.cpp Sun Mar 16 19:50:21 2014 +0100 +++ b/iMONDisplayWrapper.cpp Mon Mar 17 12:29:19 2014 +0100 @@ -6,18 +6,22 @@ IdwApi* pIdwApi = NULL; //------------------------------------------------------------------------------ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) -{ - switch (fdwReason) - { - case DLL_PROCESS_ATTACH: - pIdwApi = new IdwApi(hinstDLL); - break; - case DLL_PROCESS_DETACH: - delete pIdwApi; - break; - } - return TRUE; -} + { + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + if (pIdwApi==NULL) //Defensive + { + pIdwApi = new IdwApi(hinstDLL); + } + break; + case DLL_PROCESS_DETACH: + delete pIdwApi; + pIdwApi=NULL; + break; + } + return TRUE; + } //------------------------------------------------------------------------------ DSPResult IDW_Init(IDW_INITRESULT* pInitResult) { @@ -29,15 +33,23 @@ return pIdwApi->Uninit(); } //------------------------------------------------------------------------------ -DSPResult IDW_IsInited() +DSPResult IDW_IsInitialized() { - return pIdwApi->IsInited(); + return pIdwApi->IsInitialized(); } //------------------------------------------------------------------------------ DSPResult IDW_IsPluginModeEnabled() { return pIdwApi->IsPluginModeEnabled(); } + +/** +*/ +DSPResult IDW_GetStatus(IDW_STATUS* aStatus) + { + return pIdwApi->GetStatus(aStatus); + } + //------------------------------------------------------------------------------ DSPResult IDW_SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2) { diff -r d9a866996670 -r 558712318e1b iMONDisplayWrapper.h --- a/iMONDisplayWrapper.h Sun Mar 16 19:50:21 2014 +0100 +++ b/iMONDisplayWrapper.h Mon Mar 17 12:29:19 2014 +0100 @@ -17,6 +17,13 @@ DSPNInitResult iInitResult; DSPType iDspType; } IDW_INITRESULT; + +//------------------------------------------------------------------------------ +typedef struct _IDW_STATUS + { + DSPNotifyCode iNotification; + } IDW_STATUS; + //------------------------------------------------------------------------------ #ifdef __cplusplus extern "C" @@ -25,8 +32,9 @@ //------------------------------------------------------------------------------ IMONDSPWRAPPER DSPResult IDW_Init(IDW_INITRESULT* pInitResult); IMONDSPWRAPPER DSPResult IDW_Uninit(); -IMONDSPWRAPPER DSPResult IDW_IsInited(); +IMONDSPWRAPPER DSPResult IDW_IsInitialized(); IMONDSPWRAPPER DSPResult IDW_IsPluginModeEnabled(); +IMONDSPWRAPPER DSPResult IDW_GetStatus(IDW_STATUS* aStatus); IMONDSPWRAPPER DSPResult IDW_SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2); IMONDSPWRAPPER DSPResult IDW_SetVfdEqData(PDSPEQDATA pEqData); IMONDSPWRAPPER DSPResult IDW_SetLcdText(LPCWSTR lpszLine1);