Adding support for status request.
1.1 --- a/IdwApi.cpp Sun Mar 16 19:50:21 2014 +0100
1.2 +++ b/IdwApi.cpp Mon Mar 17 12:29:19 2014 +0100
1.3 @@ -1,6 +1,7 @@
1.4 //------------------------------------------------------------------------------
1.5 #include "IdwApi.h"
1.6 #include <windows.h>
1.7 +
1.8 //------------------------------------------------------------------------------
1.9 IdwApi::IdwApi(HINSTANCE hInstance)
1.10 : m_hInstance(hInstance)
1.11 @@ -50,7 +51,7 @@
1.12 return ret;
1.13 }
1.14 //------------------------------------------------------------------------------
1.15 -DSPResult IdwApi::IsInited()
1.16 +DSPResult IdwApi::IsInitialized()
1.17 {
1.18 m_mutex.Request();
1.19 if (m_nInitCount == 0)
1.20 @@ -75,6 +76,25 @@
1.21 m_mutex.Release();
1.22 return ret;
1.23 }
1.24 +
1.25 +/**
1.26 +Fetch our current status.
1.27 +It's actually just the last notification from iMON.
1.28 +*/
1.29 +DSPResult IdwApi::GetStatus(IDW_STATUS* aStatus)
1.30 + {
1.31 + m_mutex.Request();
1.32 + if (m_nInitCount == 0)
1.33 + {
1.34 + m_mutex.Release();
1.35 + return DSP_E_NOT_INITED;
1.36 + }
1.37 +
1.38 + DSPResult ret = m_pIdwThread->GetStatus(aStatus);
1.39 + m_mutex.Release();
1.40 + return ret;
1.41 + }
1.42 +
1.43 //------------------------------------------------------------------------------
1.44 DSPResult IdwApi::SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2)
1.45 {
2.1 --- a/IdwApi.h Sun Mar 16 19:50:21 2014 +0100
2.2 +++ b/IdwApi.h Mon Mar 17 12:29:19 2014 +0100
2.3 @@ -7,7 +7,12 @@
2.4 #include "iMONDisplayDefines.h"
2.5 #include "iMONDisplayWrapper.h"
2.6 #include "IdwThread.h"
2.7 -//------------------------------------------------------------------------------
2.8 +
2.9 +/**
2.10 +Provide access to iMON Display API.
2.11 +We have one instance of this object per process attaching our DLL.
2.12 +It basically synchronize and forward API calls to our Window through our thread object.
2.13 +*/
2.14 class IdwApi
2.15 {
2.16 public:
2.17 @@ -17,8 +22,9 @@
2.18 public:
2.19 DSPResult Init(IDW_INITRESULT* pInitResult);
2.20 DSPResult Uninit();
2.21 - DSPResult IsInited();
2.22 + DSPResult IsInitialized();
2.23 DSPResult IsPluginModeEnabled();
2.24 + DSPResult GetStatus(IDW_STATUS* aStatus);
2.25 DSPResult SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2);
2.26 DSPResult SetVfdEqData(PDSPEQDATA pEqData);
2.27 DSPResult SetLcdText(LPCWSTR lpszText);
2.28 @@ -39,7 +45,7 @@
2.29
2.30 private:
2.31 HINSTANCE m_hInstance;
2.32 - Mutex m_mutex;
2.33 + Mutex m_mutex; ///Used to guarantee we only have one request running at a time.
2.34 int m_nInitCount;
2.35 IdwThread* m_pIdwThread;
2.36 };
3.1 --- a/IdwThread.cpp Sun Mar 16 19:50:21 2014 +0100
3.2 +++ b/IdwThread.cpp Mon Mar 17 12:29:19 2014 +0100
3.3 @@ -22,10 +22,12 @@
3.4 #define WM_IDW_SETLCDASPECTRATIO (WM_USER + 16)
3.5 #define WM_IDW_SETLCDETCICON (WM_USER + 17)
3.6 #define WM_IDW_SETLCDPROGRESS (WM_USER + 18)
3.7 +#define WM_IDW_STATUS (WM_USER + 19)
3.8 #define WM_IDW_INTERRUPT (WM_USER + 100)
3.9 //------------------------------------------------------------------------------
3.10
3.11 /**
3.12 +iMON Display initialization request.
3.13 */
3.14 class IdwImonInitRequest : public WindowEvent
3.15 {
3.16 @@ -42,6 +44,22 @@
3.17 static const UINT KMsgIdImonNotification = WM_IDW_IMON;
3.18 };
3.19
3.20 +
3.21 +/**
3.22 +iMON Display status request.
3.23 +Retrieve the latest iMON notification code.
3.24 +*/
3.25 +class IdwImonStatusRequest : public WindowEvent
3.26 + {
3.27 +public:
3.28 + IdwImonStatusRequest(HWND aWnd, UINT aMsg): WindowEvent(aWnd,aMsg) {}
3.29 + //from WindowEvent
3.30 + virtual LRESULT DoExecute();
3.31 +public:
3.32 + DSPResult iResult;
3.33 + DSPNotifyCode iNotification;
3.34 + };
3.35 +
3.36 struct IdwSetVfdText
3.37 {
3.38 DSPResult result;
3.39 @@ -103,7 +121,11 @@
3.40 return;
3.41 PostMessage(m_hWnd, WM_IDW_INTERRUPT, 0, 0);
3.42 }
3.43 -//------------------------------------------------------------------------------
3.44 +
3.45 +/**
3.46 +Issue iMON initialization request.
3.47 +@param [in, out] Contains our request results on return.
3.48 +*/
3.49 DSPResult IdwThread::Init(IDW_INITRESULT* pInitResult)
3.50 {
3.51 if (!WaitForWindow())
3.52 @@ -147,6 +169,29 @@
3.53
3.54 return result;
3.55 }
3.56 +
3.57 +/**
3.58 +Issue iMON initialization request.
3.59 +@param [in, out] Contains our request results on return.
3.60 +*/
3.61 +DSPResult IdwThread::GetStatus(IDW_STATUS* aStatus)
3.62 + {
3.63 + if (!WaitForWindow())
3.64 + {
3.65 + return DSP_E_FAIL;
3.66 + }
3.67 +
3.68 + IdwImonStatusRequest request(m_hWnd, WM_IDW_STATUS);
3.69 + request.Post();
3.70 + request.Await();
3.71 + if (aStatus != NULL)
3.72 + {
3.73 + aStatus->iNotification = request.iNotification;
3.74 + }
3.75 +
3.76 + return request.iResult;
3.77 + }
3.78 +
3.79 //------------------------------------------------------------------------------
3.80 DSPResult IdwThread::IsPluginModeEnabled()
3.81 {
3.82 @@ -457,7 +502,7 @@
3.83 LRESULT CALLBACK IdwThread::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3.84 {
3.85 static IdwImonInitRequest* initRequest = NULL;
3.86 -
3.87 + static DSPNotifyCode notification = DSPNM_PLUGIN_FAILED;
3.88 DSPResult* pResult;
3.89 Event* pFinished;
3.90
3.91 @@ -472,6 +517,7 @@
3.92
3.93 //Notifications from iMON Display API
3.94 case IdwImonInitRequest::KMsgIdImonNotification:
3.95 + notification=(DSPNotifyCode)wParam; //Keep track of our current status
3.96 if (initRequest)
3.97 {
3.98 initRequest->HandleImonNotifications(wParam,lParam);
3.99 @@ -512,6 +558,15 @@
3.100 pFinished->Signal();
3.101 return 0;
3.102
3.103 + case WM_IDW_STATUS:
3.104 + {
3.105 + IdwImonStatusRequest* request = (IdwImonStatusRequest*)wParam;
3.106 + request->iNotification = notification; //Get our notification code
3.107 + request->iResult = DSP_SUCCEEDED;
3.108 + LRESULT res=request->Execute(uMsg);
3.109 + return 0;
3.110 + }
3.111 +
3.112 case WM_IDW_SETVFDTEXT:
3.113 {
3.114 IdwSetVfdText* pSetVfdText = (IdwSetVfdText*)wParam;
3.115 @@ -800,3 +855,12 @@
3.116
3.117 return 0;
3.118 }
3.119 +
3.120 +
3.121 +/**
3.122 +*/
3.123 +LRESULT IdwImonStatusRequest::DoExecute()
3.124 + {
3.125 + Signal();
3.126 + return 0;
3.127 + }
3.128 \ No newline at end of file
4.1 --- a/IdwThread.h Sun Mar 16 19:50:21 2014 +0100
4.2 +++ b/IdwThread.h Mon Mar 17 12:29:19 2014 +0100
4.3 @@ -8,7 +8,15 @@
4.4 #include "Mutex.h"
4.5 #include "iMONDisplayDefines.h"
4.6 #include "iMONDisplayWrapper.h"
4.7 -//------------------------------------------------------------------------------
4.8 +
4.9 +
4.10 +/**
4.11 +iMON Display Wrapper thread.
4.12 +Create a window and implement its event loop.
4.13 +This window will be used to process iMON display messages.
4.14 +Implement iMON Display API by send messages to our window.
4.15 +Actual iMON Display API call call are made from the window procedure.
4.16 +*/
4.17 class IdwThread : public Thread
4.18 {
4.19 public:
4.20 @@ -25,6 +33,7 @@
4.21 DSPResult Uninit();
4.22 DSPResult IsInited();
4.23 DSPResult IsPluginModeEnabled();
4.24 + DSPResult GetStatus(IDW_STATUS* aStatus);
4.25 DSPResult SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2);
4.26 DSPResult SetVfdEqData(PDSPEQDATA pEqData);
4.27 DSPResult SetLcdText(LPCWSTR lpszText);
4.28 @@ -38,7 +47,7 @@
4.29 DSPResult SetLcdAspectRatioIcon(BYTE btIconData);
4.30 DSPResult SetLcdEtcIcon(BYTE btIconData);
4.31 DSPResult SetLcdProgress(int nCurPos, int nTotal);
4.32 -
4.33 +
4.34 protected:
4.35 virtual void Run();
4.36
5.1 --- a/iMONDisplayWrapper.cpp Sun Mar 16 19:50:21 2014 +0100
5.2 +++ b/iMONDisplayWrapper.cpp Mon Mar 17 12:29:19 2014 +0100
5.3 @@ -6,18 +6,22 @@
5.4 IdwApi* pIdwApi = NULL;
5.5 //------------------------------------------------------------------------------
5.6 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
5.7 -{
5.8 - switch (fdwReason)
5.9 - {
5.10 - case DLL_PROCESS_ATTACH:
5.11 - pIdwApi = new IdwApi(hinstDLL);
5.12 - break;
5.13 - case DLL_PROCESS_DETACH:
5.14 - delete pIdwApi;
5.15 - break;
5.16 - }
5.17 - return TRUE;
5.18 -}
5.19 + {
5.20 + switch (fdwReason)
5.21 + {
5.22 + case DLL_PROCESS_ATTACH:
5.23 + if (pIdwApi==NULL) //Defensive
5.24 + {
5.25 + pIdwApi = new IdwApi(hinstDLL);
5.26 + }
5.27 + break;
5.28 + case DLL_PROCESS_DETACH:
5.29 + delete pIdwApi;
5.30 + pIdwApi=NULL;
5.31 + break;
5.32 + }
5.33 + return TRUE;
5.34 + }
5.35 //------------------------------------------------------------------------------
5.36 DSPResult IDW_Init(IDW_INITRESULT* pInitResult)
5.37 {
5.38 @@ -29,15 +33,23 @@
5.39 return pIdwApi->Uninit();
5.40 }
5.41 //------------------------------------------------------------------------------
5.42 -DSPResult IDW_IsInited()
5.43 +DSPResult IDW_IsInitialized()
5.44 {
5.45 - return pIdwApi->IsInited();
5.46 + return pIdwApi->IsInitialized();
5.47 }
5.48 //------------------------------------------------------------------------------
5.49 DSPResult IDW_IsPluginModeEnabled()
5.50 {
5.51 return pIdwApi->IsPluginModeEnabled();
5.52 }
5.53 +
5.54 +/**
5.55 +*/
5.56 +DSPResult IDW_GetStatus(IDW_STATUS* aStatus)
5.57 + {
5.58 + return pIdwApi->GetStatus(aStatus);
5.59 + }
5.60 +
5.61 //------------------------------------------------------------------------------
5.62 DSPResult IDW_SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2)
5.63 {
6.1 --- a/iMONDisplayWrapper.h Sun Mar 16 19:50:21 2014 +0100
6.2 +++ b/iMONDisplayWrapper.h Mon Mar 17 12:29:19 2014 +0100
6.3 @@ -17,6 +17,13 @@
6.4 DSPNInitResult iInitResult;
6.5 DSPType iDspType;
6.6 } IDW_INITRESULT;
6.7 +
6.8 +//------------------------------------------------------------------------------
6.9 +typedef struct _IDW_STATUS
6.10 + {
6.11 + DSPNotifyCode iNotification;
6.12 + } IDW_STATUS;
6.13 +
6.14 //------------------------------------------------------------------------------
6.15 #ifdef __cplusplus
6.16 extern "C"
6.17 @@ -25,8 +32,9 @@
6.18 //------------------------------------------------------------------------------
6.19 IMONDSPWRAPPER DSPResult IDW_Init(IDW_INITRESULT* pInitResult);
6.20 IMONDSPWRAPPER DSPResult IDW_Uninit();
6.21 -IMONDSPWRAPPER DSPResult IDW_IsInited();
6.22 +IMONDSPWRAPPER DSPResult IDW_IsInitialized();
6.23 IMONDSPWRAPPER DSPResult IDW_IsPluginModeEnabled();
6.24 +IMONDSPWRAPPER DSPResult IDW_GetStatus(IDW_STATUS* aStatus);
6.25 IMONDSPWRAPPER DSPResult IDW_SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2);
6.26 IMONDSPWRAPPER DSPResult IDW_SetVfdEqData(PDSPEQDATA pEqData);
6.27 IMONDSPWRAPPER DSPResult IDW_SetLcdText(LPCWSTR lpszLine1);