Improved event framework.
Init now properly reporting notification.
1.1 --- a/Event.cpp Sun Mar 16 09:11:39 2014 +0100
1.2 +++ b/Event.cpp Sun Mar 16 19:50:21 2014 +0100
1.3 @@ -27,3 +27,17 @@
1.4 WaitForSingleObject(m_hEvent, INFINITE);
1.5 }
1.6 //------------------------------------------------------------------------------
1.7 +
1.8 +
1.9 +//
1.10 +//
1.11 +//
1.12 +
1.13 +LRESULT WindowEvent::Execute(UINT aMsg)
1.14 + {
1.15 + //Typically only execute if the given message is for us
1.16 + if (aMsg==iMsg)
1.17 + {
1.18 + return DoExecute();
1.19 + }
1.20 + }
1.21 \ No newline at end of file
2.1 --- a/Event.h Sun Mar 16 09:11:39 2014 +0100
2.2 +++ b/Event.h Sun Mar 16 19:50:21 2014 +0100
2.3 @@ -22,6 +22,24 @@
2.4 private:
2.5 HANDLE m_hEvent;
2.6 };
2.7 +
2.8 +
2.9 +/**
2.10 +*/
2.11 +class WindowEvent: public Event
2.12 +{
2.13 +public:
2.14 + WindowEvent(HWND aWnd, UINT aMsg):Event(),iWnd(aWnd),iMsg(aMsg){}
2.15 +
2.16 + BOOL Post(){return PostMessage(iWnd, iMsg, (WPARAM)this, (LPARAM)NULL);}
2.17 + virtual LRESULT Execute(UINT aMsg);
2.18 + virtual LRESULT DoExecute() = 0;
2.19 +
2.20 +protected:
2.21 + HWND iWnd;
2.22 + UINT iMsg;
2.23 +};
2.24 +
2.25 //------------------------------------------------------------------------------
2.26 #endif
2.27 //------------------------------------------------------------------------------
3.1 --- a/IdwThread.cpp Sun Mar 16 09:11:39 2014 +0100
3.2 +++ b/IdwThread.cpp Sun Mar 16 19:50:21 2014 +0100
3.3 @@ -24,12 +24,24 @@
3.4 #define WM_IDW_SETLCDPROGRESS (WM_USER + 18)
3.5 #define WM_IDW_INTERRUPT (WM_USER + 100)
3.6 //------------------------------------------------------------------------------
3.7 -struct IdwImonInitResult
3.8 -{
3.9 - DSPResult result;
3.10 - DSPNInitResult initResult;
3.11 - DSPType dspType;
3.12 -};
3.13 +
3.14 +/**
3.15 +*/
3.16 +class IdwImonInitRequest : public WindowEvent
3.17 + {
3.18 +public:
3.19 + IdwImonInitRequest(HWND aWnd, UINT aMsg): WindowEvent(aWnd,aMsg) {}
3.20 + //from WindowEvent
3.21 + virtual LRESULT DoExecute();
3.22 + void HandleImonNotifications(WPARAM wParam, LPARAM lParam);
3.23 +public:
3.24 + DSPNotifyCode iNotification;
3.25 + DSPResult iResult;
3.26 + DSPNInitResult iInitResult;
3.27 + DSPType iDspType;
3.28 + static const UINT KMsgIdImonNotification = WM_IDW_IMON;
3.29 + };
3.30 +
3.31 struct IdwSetVfdText
3.32 {
3.33 DSPResult result;
3.34 @@ -97,17 +109,17 @@
3.35 if (!WaitForWindow())
3.36 return DSP_E_FAIL;
3.37
3.38 - IdwImonInitResult result;
3.39 - Event finished;
3.40 - PostMessage(m_hWnd, WM_IDW_INIT, (WPARAM)&result, (LPARAM)&finished);
3.41 - finished.Await();
3.42 + IdwImonInitRequest request(m_hWnd, WM_IDW_INIT);
3.43 + request.Post();
3.44 + request.Await();
3.45 if (pInitResult != NULL)
3.46 {
3.47 - pInitResult->initResult = result.initResult;
3.48 - pInitResult->dspType = result.dspType;
3.49 + pInitResult->iInitResult = request.iInitResult;
3.50 + pInitResult->iDspType = request.iDspType;
3.51 + pInitResult->iNotification = request.iNotification;
3.52 }
3.53
3.54 - return result.result;
3.55 + return request.iResult;
3.56 }
3.57 //------------------------------------------------------------------------------
3.58 DSPResult IdwThread::Uninit()
3.59 @@ -442,12 +454,9 @@
3.60 return true;
3.61 }
3.62 //------------------------------------------------------------------------------
3.63 -LRESULT CALLBACK IdwThread::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
3.64 - LPARAM lParam)
3.65 -{
3.66 - static bool initing = false;
3.67 - static IdwImonInitResult* pInitResult = NULL;
3.68 - static Event* pInitFinished = NULL;
3.69 +LRESULT CALLBACK IdwThread::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3.70 +{
3.71 + static IdwImonInitRequest* initRequest = NULL;
3.72
3.73 DSPResult* pResult;
3.74 Event* pFinished;
3.75 @@ -461,29 +470,26 @@
3.76 PostQuitMessage(0);
3.77 return 0;
3.78
3.79 - case WM_IDW_IMON:
3.80 - if (initing)
3.81 - {
3.82 - initing = false;
3.83 - pInitResult->initResult = (DSPNInitResult)wParam;
3.84 - pInitResult->dspType = (DSPType)lParam;
3.85 - pInitFinished->Signal();
3.86 - }
3.87 - return 0;
3.88 + //Notifications from iMON Display API
3.89 + case IdwImonInitRequest::KMsgIdImonNotification:
3.90 + if (initRequest)
3.91 + {
3.92 + initRequest->HandleImonNotifications(wParam,lParam);
3.93 + initRequest=NULL;
3.94 + }
3.95 + return 0;
3.96
3.97 case WM_IDW_INIT:
3.98 - initing = true;
3.99 - pInitResult = (IdwImonInitResult*)wParam;
3.100 - pInitFinished = (Event*)lParam;
3.101 - pInitResult->result = IMON_Display_Init(hwnd, WM_IDW_IMON);
3.102 - if (pInitResult->result != DSP_SUCCEEDED)
3.103 - {
3.104 - initing = false;
3.105 - pInitResult->initResult = DSPN_ERR_UNKNOWN;
3.106 - pInitResult->dspType = DSPN_DSP_NONE;
3.107 - pInitFinished->Signal();
3.108 - }
3.109 - return 0;
3.110 + {
3.111 + initRequest = (IdwImonInitRequest*)wParam;
3.112 + LRESULT res=initRequest->Execute(uMsg);
3.113 + if (res==1)
3.114 + {
3.115 + //Request has been completed
3.116 + initRequest=NULL;
3.117 + }
3.118 + return 0;
3.119 + }
3.120
3.121 case WM_IDW_UNINIT:
3.122 pResult = (DSPResult*)wParam;
3.123 @@ -742,4 +748,55 @@
3.124 return L'#';
3.125 }
3.126 }
3.127 -//------------------------------------------------------------------------------
3.128 +
3.129 +/**
3.130 +Handle iMON notifications
3.131 +*/
3.132 +void IdwImonInitRequest::HandleImonNotifications(WPARAM wParam, LPARAM lParam)
3.133 + {
3.134 + iNotification=(DSPNotifyCode)wParam;
3.135 + iDspType=DSPN_DSP_NONE;
3.136 + iResult= DSP_SUCCEEDED;
3.137 +
3.138 + switch (iNotification)
3.139 + {
3.140 + case DSPNM_PLUGIN_SUCCEED:
3.141 + case DSPNM_IMON_RESTARTED:
3.142 + case DSPNM_HW_CONNECTED:
3.143 + //lParam is display type
3.144 + iDspType = (DSPType)lParam;
3.145 + break;
3.146 + case DSPNM_PLUGIN_FAILED:
3.147 + case DSPNM_HW_DISCONNECTED:
3.148 + case DSPNM_IMON_CLOSED:
3.149 + //lParam is error
3.150 + iInitResult = (DSPNInitResult)lParam;
3.151 + break;
3.152 + case DSPNM_LCD_TEXT_SCROLL_DONE:
3.153 + //That should not happen, report an error
3.154 + iResult = DSP_E_FAIL;
3.155 + break;
3.156 + }
3.157 +
3.158 + //Complete our request
3.159 + Signal();
3.160 + }
3.161 +
3.162 +
3.163 +/**
3.164 +Run our display initialization.
3.165 +*/
3.166 +LRESULT IdwImonInitRequest::DoExecute()
3.167 + {
3.168 + iResult = IMON_Display_Init(iWnd, KMsgIdImonNotification);
3.169 + if (iResult != DSP_SUCCEEDED)
3.170 + {
3.171 + iNotification = DSPNM_PLUGIN_FAILED;
3.172 + iInitResult = DSPN_ERR_UNKNOWN;
3.173 + iDspType = DSPN_DSP_NONE;
3.174 + Signal();
3.175 + return 1;
3.176 + }
3.177 +
3.178 + return 0;
3.179 + }
4.1 --- a/IdwThread.h Sun Mar 16 09:11:39 2014 +0100
4.2 +++ b/IdwThread.h Sun Mar 16 19:50:21 2014 +0100
4.3 @@ -12,51 +12,49 @@
4.4 class IdwThread : public Thread
4.5 {
4.6 public:
4.7 - IdwThread(HINSTANCE hInstance);
4.8 - virtual ~IdwThread();
4.9 + IdwThread(HINSTANCE hInstance);
4.10 + virtual ~IdwThread();
4.11
4.12 private:
4.13 - IdwThread(const IdwThread& other) {}
4.14 - IdwThread& operator=(const IdwThread& other) { return *this; }
4.15 + IdwThread(const IdwThread& other) {}
4.16 + IdwThread& operator=(const IdwThread& other) { return *this; }
4.17
4.18 public:
4.19 - virtual void Interrupt();
4.20 - DSPResult Init(IDW_INITRESULT* pInitResult);
4.21 - DSPResult Uninit();
4.22 - DSPResult IsInited();
4.23 - DSPResult IsPluginModeEnabled();
4.24 - DSPResult SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2);
4.25 - DSPResult SetVfdEqData(PDSPEQDATA pEqData);
4.26 - DSPResult SetLcdText(LPCWSTR lpszText);
4.27 - DSPResult SetLcdEqData(PDSPEQDATA pEqDataL, PDSPEQDATA pEqDataR);
4.28 - DSPResult SetLcdAllIcons(BOOL bOn);
4.29 - DSPResult SetLcdOrangeIcon(BYTE btIconData1, BYTE btIconData2);
4.30 - DSPResult SetLcdMediaTypeIcon(BYTE btIconData);
4.31 - DSPResult SetLcdSpeakerIcon(BYTE btIconData1, BYTE btIconData2);
4.32 - DSPResult SetLcdVideoCodecIcon(BYTE btIconData);
4.33 - DSPResult SetLcdAudioCodecIcon(BYTE btIconData);
4.34 - DSPResult SetLcdAspectRatioIcon(BYTE btIconData);
4.35 - DSPResult SetLcdEtcIcon(BYTE btIconData);
4.36 - DSPResult SetLcdProgress(int nCurPos, int nTotal);
4.37 + virtual void Interrupt();
4.38 + DSPResult Init(IDW_INITRESULT* pInitResult);
4.39 + DSPResult Uninit();
4.40 + DSPResult IsInited();
4.41 + DSPResult IsPluginModeEnabled();
4.42 + DSPResult SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2);
4.43 + DSPResult SetVfdEqData(PDSPEQDATA pEqData);
4.44 + DSPResult SetLcdText(LPCWSTR lpszText);
4.45 + DSPResult SetLcdEqData(PDSPEQDATA pEqDataL, PDSPEQDATA pEqDataR);
4.46 + DSPResult SetLcdAllIcons(BOOL bOn);
4.47 + DSPResult SetLcdOrangeIcon(BYTE btIconData1, BYTE btIconData2);
4.48 + DSPResult SetLcdMediaTypeIcon(BYTE btIconData);
4.49 + DSPResult SetLcdSpeakerIcon(BYTE btIconData1, BYTE btIconData2);
4.50 + DSPResult SetLcdVideoCodecIcon(BYTE btIconData);
4.51 + DSPResult SetLcdAudioCodecIcon(BYTE btIconData);
4.52 + DSPResult SetLcdAspectRatioIcon(BYTE btIconData);
4.53 + DSPResult SetLcdEtcIcon(BYTE btIconData);
4.54 + DSPResult SetLcdProgress(int nCurPos, int nTotal);
4.55
4.56 protected:
4.57 - virtual void Run();
4.58 + virtual void Run();
4.59 +
4.60 +private:
4.61 + bool RegisterClass();
4.62 + bool CreateMessageWindow();
4.63 + void AllowImonMessages();
4.64 + bool WaitForWindow();
4.65 + static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
4.66 + static void MapChars(LPWSTR lpszTarget, LPCWSTR lpszSource, int nMaxLength);
4.67 + static wchar_t MapChar(wchar_t ch);
4.68
4.69 private:
4.70 - bool RegisterClass();
4.71 - bool CreateMessageWindow();
4.72 - void AllowImonMessages();
4.73 - bool WaitForWindow();
4.74 - static LRESULT CALLBACK WndProc(
4.75 - HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
4.76 - static void MapChars(
4.77 - LPWSTR lpszTarget, LPCWSTR lpszSource, int nMaxLength);
4.78 - static wchar_t MapChar(wchar_t ch);
4.79 -
4.80 -private:
4.81 - HINSTANCE m_hInstance;
4.82 - HWND m_hWnd;
4.83 - Event m_eventWindowCreationDone;
4.84 + HINSTANCE m_hInstance;
4.85 + HWND m_hWnd;
4.86 + Event m_eventWindowCreationDone;
4.87 };
4.88 //------------------------------------------------------------------------------
4.89 #endif
5.1 --- a/iMONDisplayWrapper.h Sun Mar 16 09:11:39 2014 +0100
5.2 +++ b/iMONDisplayWrapper.h Sun Mar 16 19:50:21 2014 +0100
5.3 @@ -12,10 +12,11 @@
5.4 #endif
5.5 //------------------------------------------------------------------------------
5.6 typedef struct _IDW_INITRESULT
5.7 -{
5.8 - DSPNInitResult initResult;
5.9 - DSPType dspType;
5.10 -} IDW_INITRESULT;
5.11 + {
5.12 + DSPNotifyCode iNotification;
5.13 + DSPNInitResult iInitResult;
5.14 + DSPType iDspType;
5.15 + } IDW_INITRESULT;
5.16 //------------------------------------------------------------------------------
5.17 #ifdef __cplusplus
5.18 extern "C"