IdwThread.cpp
author sl
Mon, 17 Mar 2014 12:38:39 +0100
changeset 3 d5f6b2119a13
parent 2 558712318e1b
permissions -rw-r--r--
Fixing init result issue.
sl@0
     1
//------------------------------------------------------------------------------
sl@0
     2
#include "IdwThread.h"
sl@0
     3
#include "iMONDisplayAPI.h"
sl@0
     4
//------------------------------------------------------------------------------
sl@0
     5
#define CLASSNAME TEXT("IDW_IMON_COM_WNDCLASS")
sl@0
     6
//------------------------------------------------------------------------------
sl@0
     7
#define WM_IDW_IMON                (WM_USER + 1)
sl@0
     8
#define WM_IDW_INIT                (WM_USER + 2)
sl@0
     9
#define WM_IDW_UNINIT              (WM_USER + 3)
sl@0
    10
#define WM_IDW_ISINITED            (WM_USER + 4)
sl@0
    11
#define WM_IDW_ISPLUGINMODEENABLED (WM_USER + 5)
sl@0
    12
#define WM_IDW_SETVFDTEXT          (WM_USER + 6)
sl@0
    13
#define WM_IDW_SETVFDEQ            (WM_USER + 7)
sl@0
    14
#define WM_IDW_SETLCDTEXT          (WM_USER + 8)
sl@0
    15
#define WM_IDW_SETLCDEQ            (WM_USER + 9)
sl@0
    16
#define WM_IDW_SETLCDALLICONS      (WM_USER + 10)
sl@0
    17
#define WM_IDW_SETLCDORANGEICON    (WM_USER + 11)
sl@0
    18
#define WM_IDW_SETLCDMEDIATYPEICON (WM_USER + 12)
sl@0
    19
#define WM_IDW_SETLCDSPEAKERICON   (WM_USER + 13)
sl@0
    20
#define WM_IDW_SETLCDVIDEOCODEC    (WM_USER + 14)
sl@0
    21
#define WM_IDW_SETLCDAUDIOCODEC    (WM_USER + 15)
sl@0
    22
#define WM_IDW_SETLCDASPECTRATIO   (WM_USER + 16)
sl@0
    23
#define WM_IDW_SETLCDETCICON       (WM_USER + 17)
sl@0
    24
#define WM_IDW_SETLCDPROGRESS      (WM_USER + 18)
sl@2
    25
#define WM_IDW_STATUS			   (WM_USER + 19)
sl@0
    26
#define WM_IDW_INTERRUPT           (WM_USER + 100)
sl@0
    27
//------------------------------------------------------------------------------
sl@1
    28
sl@1
    29
/**
sl@2
    30
iMON Display initialization request.
sl@1
    31
*/
sl@1
    32
class IdwImonInitRequest : public WindowEvent
sl@1
    33
	{
sl@1
    34
public:
sl@1
    35
	IdwImonInitRequest(HWND aWnd, UINT aMsg): WindowEvent(aWnd,aMsg) {} 
sl@1
    36
	//from WindowEvent
sl@1
    37
	virtual LRESULT DoExecute();
sl@1
    38
	void HandleImonNotifications(WPARAM wParam, LPARAM lParam);
sl@1
    39
public:
sl@1
    40
	DSPNotifyCode iNotification;
sl@1
    41
	DSPResult iResult;
sl@1
    42
	DSPNInitResult iInitResult;
sl@1
    43
	DSPType iDspType;
sl@1
    44
	static const UINT KMsgIdImonNotification = WM_IDW_IMON;
sl@1
    45
	};
sl@1
    46
sl@2
    47
sl@2
    48
/**
sl@2
    49
iMON Display status request.
sl@2
    50
Retrieve the latest iMON notification code.
sl@2
    51
*/
sl@2
    52
class IdwImonStatusRequest : public WindowEvent
sl@2
    53
	{
sl@2
    54
public:
sl@2
    55
	IdwImonStatusRequest(HWND aWnd, UINT aMsg): WindowEvent(aWnd,aMsg) {} 
sl@2
    56
	//from WindowEvent
sl@2
    57
	virtual LRESULT DoExecute();
sl@2
    58
public:
sl@2
    59
	DSPResult iResult;
sl@2
    60
	DSPNotifyCode iNotification;
sl@2
    61
	};
sl@2
    62
sl@0
    63
struct IdwSetVfdText
sl@0
    64
{
sl@0
    65
  DSPResult result;
sl@0
    66
  LPCWSTR pszLine1;
sl@0
    67
  LPCWSTR pszLine2;
sl@0
    68
};
sl@0
    69
struct IdwSetVfdEq
sl@0
    70
{
sl@0
    71
  DSPResult result;
sl@0
    72
  PDSPEQDATA pEqData;
sl@0
    73
};
sl@0
    74
struct IdwSetLcdText
sl@0
    75
{
sl@0
    76
  DSPResult result;
sl@0
    77
  LPCWSTR pszLine1;
sl@0
    78
};
sl@0
    79
struct IdwSetLcdEq
sl@0
    80
{
sl@0
    81
  DSPResult result;
sl@0
    82
  PDSPEQDATA pEqDataL;
sl@0
    83
  PDSPEQDATA pEqDataR;
sl@0
    84
};
sl@0
    85
struct IdwSetLcdAllIcons
sl@0
    86
{
sl@0
    87
  DSPResult result;
sl@0
    88
  BOOL bOn;
sl@0
    89
};
sl@0
    90
struct IdwSetLcdIcons
sl@0
    91
{
sl@0
    92
  DSPResult result;
sl@0
    93
  BYTE btIconData;
sl@0
    94
};
sl@0
    95
struct IdwSetLcdIcons2
sl@0
    96
{
sl@0
    97
  DSPResult result;
sl@0
    98
  BYTE btIconData1;
sl@0
    99
  BYTE btIconData2;
sl@0
   100
};
sl@0
   101
struct IdwSetLcdProgress
sl@0
   102
{
sl@0
   103
  DSPResult result;
sl@0
   104
  int nCurPos;
sl@0
   105
	int nTotal;
sl@0
   106
};
sl@0
   107
//------------------------------------------------------------------------------
sl@0
   108
IdwThread::IdwThread(HINSTANCE hInstance)
sl@0
   109
: m_hInstance(hInstance)
sl@0
   110
, m_hWnd(NULL)
sl@0
   111
{
sl@0
   112
}
sl@0
   113
//------------------------------------------------------------------------------
sl@0
   114
IdwThread::~IdwThread()
sl@0
   115
{
sl@0
   116
}
sl@0
   117
//------------------------------------------------------------------------------
sl@0
   118
void IdwThread::Interrupt()
sl@0
   119
{
sl@0
   120
  if (!WaitForWindow())
sl@0
   121
    return;
sl@0
   122
  PostMessage(m_hWnd, WM_IDW_INTERRUPT, 0, 0);
sl@0
   123
}
sl@2
   124
sl@2
   125
/**
sl@2
   126
Issue iMON initialization request.
sl@2
   127
@param [in, out] Contains our request results on return.
sl@2
   128
*/
sl@0
   129
DSPResult IdwThread::Init(IDW_INITRESULT* pInitResult)
sl@0
   130
{
sl@0
   131
  if (!WaitForWindow())
sl@0
   132
    return DSP_E_FAIL;
sl@0
   133
sl@1
   134
  IdwImonInitRequest request(m_hWnd, WM_IDW_INIT);
sl@1
   135
  request.Post();
sl@1
   136
  request.Await();
sl@0
   137
  if (pInitResult != NULL)
sl@0
   138
  {
sl@1
   139
    pInitResult->iInitResult = request.iInitResult;
sl@1
   140
    pInitResult->iDspType = request.iDspType;
sl@1
   141
	pInitResult->iNotification = request.iNotification;
sl@0
   142
  }
sl@0
   143
sl@1
   144
  return request.iResult;
sl@0
   145
}
sl@0
   146
//------------------------------------------------------------------------------
sl@0
   147
DSPResult IdwThread::Uninit()
sl@0
   148
{
sl@0
   149
  if (!WaitForWindow())
sl@0
   150
    return DSP_E_FAIL;
sl@0
   151
sl@0
   152
  DSPResult result;  
sl@0
   153
  Event finished;
sl@0
   154
  PostMessage(m_hWnd, WM_IDW_UNINIT, (WPARAM)&result, (LPARAM)&finished);
sl@0
   155
  finished.Await();
sl@0
   156
sl@0
   157
  return result;
sl@0
   158
}
sl@0
   159
//------------------------------------------------------------------------------
sl@3
   160
DSPResult IdwThread::IsInitialized()
sl@0
   161
{
sl@0
   162
  if (!WaitForWindow())
sl@0
   163
    return DSP_E_FAIL;
sl@0
   164
sl@0
   165
  DSPResult result;  
sl@0
   166
  Event finished;
sl@0
   167
  PostMessage(m_hWnd, WM_IDW_ISINITED, (WPARAM)&result, (LPARAM)&finished);
sl@0
   168
  finished.Await();
sl@0
   169
sl@0
   170
  return result;
sl@0
   171
}
sl@2
   172
sl@2
   173
/**
sl@2
   174
Issue iMON initialization request.
sl@2
   175
@param [in, out] Contains our request results on return.
sl@2
   176
*/
sl@2
   177
DSPResult IdwThread::GetStatus(IDW_STATUS* aStatus)
sl@2
   178
	{
sl@2
   179
	if (!WaitForWindow())
sl@2
   180
		{
sl@2
   181
		return DSP_E_FAIL;
sl@2
   182
		}
sl@2
   183
sl@2
   184
	IdwImonStatusRequest request(m_hWnd, WM_IDW_STATUS);
sl@2
   185
	request.Post();
sl@2
   186
	request.Await();
sl@2
   187
	if (aStatus != NULL)
sl@2
   188
		{
sl@2
   189
		aStatus->iNotification = request.iNotification;
sl@2
   190
		}
sl@2
   191
sl@2
   192
	return request.iResult;
sl@2
   193
	}
sl@2
   194
sl@0
   195
//------------------------------------------------------------------------------
sl@0
   196
DSPResult IdwThread::IsPluginModeEnabled()
sl@0
   197
{
sl@0
   198
  if (!WaitForWindow())
sl@0
   199
    return DSP_E_FAIL;
sl@0
   200
sl@0
   201
  DSPResult result;  
sl@0
   202
  Event finished;
sl@0
   203
  PostMessage(m_hWnd, WM_IDW_ISPLUGINMODEENABLED, (WPARAM)&result,
sl@0
   204
              (LPARAM)&finished);
sl@0
   205
  finished.Await();
sl@0
   206
sl@0
   207
  return result;
sl@0
   208
}
sl@0
   209
//------------------------------------------------------------------------------
sl@0
   210
DSPResult IdwThread::SetVfdText(LPCWSTR lpszLine1, LPCWSTR lpszLine2)
sl@0
   211
{
sl@0
   212
  if (!WaitForWindow())
sl@0
   213
    return DSP_E_FAIL;
sl@0
   214
sl@0
   215
  IdwSetVfdText text;
sl@0
   216
  text.pszLine1 = lpszLine1;
sl@0
   217
  text.pszLine2 = lpszLine2;
sl@0
   218
  Event finished;
sl@0
   219
  PostMessage(m_hWnd, WM_IDW_SETVFDTEXT, (WPARAM)&text, (LPARAM)&finished);
sl@0
   220
  finished.Await();
sl@0
   221
sl@0
   222
  return text.result;
sl@0
   223
}
sl@0
   224
//------------------------------------------------------------------------------
sl@0
   225
DSPResult IdwThread::SetVfdEqData(PDSPEQDATA pEqData)
sl@0
   226
{
sl@0
   227
  if (!WaitForWindow())
sl@0
   228
    return DSP_E_FAIL;
sl@0
   229
sl@0
   230
  IdwSetVfdEq eq;
sl@0
   231
  eq.pEqData = pEqData;
sl@0
   232
  Event finished;
sl@0
   233
  PostMessage(m_hWnd, WM_IDW_SETVFDEQ, (WPARAM)&eq, (LPARAM)&finished);
sl@0
   234
  finished.Await();
sl@0
   235
sl@0
   236
  return eq.result;
sl@0
   237
}
sl@0
   238
//------------------------------------------------------------------------------
sl@0
   239
DSPResult IdwThread::SetLcdText(LPCWSTR lpszLine1)
sl@0
   240
{
sl@0
   241
  if (!WaitForWindow())
sl@0
   242
    return DSP_E_FAIL;
sl@0
   243
sl@0
   244
  IdwSetLcdText text;
sl@0
   245
  text.pszLine1 = lpszLine1;
sl@0
   246
  Event finished;
sl@0
   247
  PostMessage(m_hWnd, WM_IDW_SETLCDTEXT, (WPARAM)&text, (LPARAM)&finished);
sl@0
   248
  finished.Await();
sl@0
   249
sl@0
   250
  return text.result;
sl@0
   251
}
sl@0
   252
//------------------------------------------------------------------------------
sl@0
   253
DSPResult IdwThread::SetLcdEqData(PDSPEQDATA pEqDataL, PDSPEQDATA pEqDataR)
sl@0
   254
{
sl@0
   255
  if (!WaitForWindow())
sl@0
   256
    return DSP_E_FAIL;
sl@0
   257
sl@0
   258
  IdwSetLcdEq eq;
sl@0
   259
  eq.pEqDataL = pEqDataL;
sl@0
   260
  eq.pEqDataR = pEqDataR;
sl@0
   261
  Event finished;
sl@0
   262
  PostMessage(m_hWnd, WM_IDW_SETLCDEQ, (WPARAM)&eq, (LPARAM)&finished);
sl@0
   263
  finished.Await();
sl@0
   264
sl@0
   265
  return eq.result;
sl@0
   266
}
sl@0
   267
//------------------------------------------------------------------------------
sl@0
   268
DSPResult IdwThread::SetLcdAllIcons(BOOL bOn)
sl@0
   269
{
sl@0
   270
  if (!WaitForWindow())
sl@0
   271
    return DSP_E_FAIL;
sl@0
   272
sl@0
   273
  IdwSetLcdAllIcons allIcons;
sl@0
   274
  allIcons.bOn = bOn;
sl@0
   275
  Event finished;
sl@0
   276
  PostMessage(m_hWnd, WM_IDW_SETLCDALLICONS, 
sl@0
   277
		(WPARAM)&allIcons, (LPARAM)&finished);
sl@0
   278
  finished.Await();
sl@0
   279
sl@0
   280
  return allIcons.result;
sl@0
   281
}
sl@0
   282
//------------------------------------------------------------------------------
sl@0
   283
DSPResult IdwThread::SetLcdOrangeIcon(BYTE btIconData1, BYTE btIconData2)
sl@0
   284
{
sl@0
   285
  if (!WaitForWindow())
sl@0
   286
    return DSP_E_FAIL;
sl@0
   287
sl@0
   288
  IdwSetLcdIcons2 iconData;
sl@0
   289
  iconData.btIconData1 = btIconData1;
sl@0
   290
  iconData.btIconData2 = btIconData2;
sl@0
   291
  Event finished;
sl@0
   292
  PostMessage(m_hWnd, WM_IDW_SETLCDORANGEICON, 
sl@0
   293
		(WPARAM)&iconData, (LPARAM)&finished);
sl@0
   294
  finished.Await();
sl@0
   295
sl@0
   296
  return iconData.result;
sl@0
   297
}
sl@0
   298
//------------------------------------------------------------------------------
sl@0
   299
DSPResult IdwThread::SetLcdMediaTypeIcon(BYTE btIconData)
sl@0
   300
{
sl@0
   301
  if (!WaitForWindow())
sl@0
   302
    return DSP_E_FAIL;
sl@0
   303
sl@0
   304
  IdwSetLcdIcons iconData;
sl@0
   305
  iconData.btIconData = btIconData;
sl@0
   306
  Event finished;
sl@0
   307
  PostMessage(m_hWnd, WM_IDW_SETLCDMEDIATYPEICON, 
sl@0
   308
		(WPARAM)&iconData, (LPARAM)&finished);
sl@0
   309
  finished.Await();
sl@0
   310
sl@0
   311
  return iconData.result;
sl@0
   312
}
sl@0
   313
//------------------------------------------------------------------------------
sl@0
   314
DSPResult IdwThread::SetLcdSpeakerIcon(BYTE btIconData1, BYTE btIconData2)
sl@0
   315
{
sl@0
   316
  if (!WaitForWindow())
sl@0
   317
    return DSP_E_FAIL;
sl@0
   318
sl@0
   319
  IdwSetLcdIcons2 iconData;
sl@0
   320
  iconData.btIconData1 = btIconData1;
sl@0
   321
  iconData.btIconData2 = btIconData2;
sl@0
   322
  Event finished;
sl@0
   323
  PostMessage(m_hWnd, WM_IDW_SETLCDSPEAKERICON, 
sl@0
   324
		(WPARAM)&iconData, (LPARAM)&finished);
sl@0
   325
  finished.Await();
sl@0
   326
sl@0
   327
  return iconData.result;
sl@0
   328
}
sl@0
   329
//------------------------------------------------------------------------------
sl@0
   330
DSPResult IdwThread::SetLcdVideoCodecIcon(BYTE btIconData)
sl@0
   331
{
sl@0
   332
  if (!WaitForWindow())
sl@0
   333
    return DSP_E_FAIL;
sl@0
   334
sl@0
   335
  IdwSetLcdIcons iconData;
sl@0
   336
  iconData.btIconData = btIconData;
sl@0
   337
  Event finished;
sl@0
   338
  PostMessage(m_hWnd, WM_IDW_SETLCDVIDEOCODEC, 
sl@0
   339
		(WPARAM)&iconData, (LPARAM)&finished);
sl@0
   340
  finished.Await();
sl@0
   341
sl@0
   342
  return iconData.result;
sl@0
   343
}
sl@0
   344
//------------------------------------------------------------------------------
sl@0
   345
DSPResult IdwThread::SetLcdAudioCodecIcon(BYTE btIconData)
sl@0
   346
{
sl@0
   347
  if (!WaitForWindow())
sl@0
   348
    return DSP_E_FAIL;
sl@0
   349
sl@0
   350
  IdwSetLcdIcons iconData;
sl@0
   351
  iconData.btIconData = btIconData;
sl@0
   352
  Event finished;
sl@0
   353
  PostMessage(m_hWnd, WM_IDW_SETLCDAUDIOCODEC, 
sl@0
   354
		(WPARAM)&iconData, (LPARAM)&finished);
sl@0
   355
  finished.Await();
sl@0
   356
sl@0
   357
  return iconData.result;
sl@0
   358
}
sl@0
   359
//------------------------------------------------------------------------------
sl@0
   360
DSPResult IdwThread::SetLcdAspectRatioIcon(BYTE btIconData)
sl@0
   361
{
sl@0
   362
  if (!WaitForWindow())
sl@0
   363
    return DSP_E_FAIL;
sl@0
   364
sl@0
   365
  IdwSetLcdIcons iconData;
sl@0
   366
  iconData.btIconData = btIconData;
sl@0
   367
  Event finished;
sl@0
   368
  PostMessage(m_hWnd, WM_IDW_SETLCDASPECTRATIO, 
sl@0
   369
		(WPARAM)&iconData, (LPARAM)&finished);
sl@0
   370
  finished.Await();
sl@0
   371
sl@0
   372
  return iconData.result;
sl@0
   373
}
sl@0
   374
//------------------------------------------------------------------------------
sl@0
   375
DSPResult IdwThread::SetLcdEtcIcon(BYTE btIconData)
sl@0
   376
{
sl@0
   377
  if (!WaitForWindow())
sl@0
   378
    return DSP_E_FAIL;
sl@0
   379
sl@0
   380
  IdwSetLcdIcons iconData;
sl@0
   381
  iconData.btIconData = btIconData;
sl@0
   382
  Event finished;
sl@0
   383
  PostMessage(m_hWnd, WM_IDW_SETLCDETCICON, 
sl@0
   384
		(WPARAM)&iconData, (LPARAM)&finished);
sl@0
   385
  finished.Await();
sl@0
   386
sl@0
   387
  return iconData.result;
sl@0
   388
}
sl@0
   389
//------------------------------------------------------------------------------
sl@0
   390
DSPResult IdwThread::SetLcdProgress(int nCurPos, int nTotal)
sl@0
   391
{
sl@0
   392
  if (!WaitForWindow())
sl@0
   393
    return DSP_E_FAIL;
sl@0
   394
sl@0
   395
  IdwSetLcdProgress progressData;
sl@0
   396
  progressData.nCurPos = nCurPos;
sl@0
   397
	progressData.nTotal = nTotal;
sl@0
   398
  Event finished;
sl@0
   399
  PostMessage(m_hWnd, WM_IDW_SETLCDPROGRESS, 
sl@0
   400
		(WPARAM)&progressData, (LPARAM)&finished);
sl@0
   401
  finished.Await();
sl@0
   402
sl@0
   403
  return progressData.result;
sl@0
   404
}
sl@0
   405
//------------------------------------------------------------------------------
sl@0
   406
void IdwThread::Run()
sl@0
   407
{
sl@0
   408
  if (!RegisterClass())
sl@0
   409
  {
sl@0
   410
    m_eventWindowCreationDone.Signal();
sl@0
   411
    return;
sl@0
   412
  }
sl@0
   413
  if (!CreateMessageWindow())
sl@0
   414
  {
sl@0
   415
    m_eventWindowCreationDone.Signal();
sl@0
   416
    return;
sl@0
   417
  }
sl@0
   418
  AllowImonMessages();
sl@0
   419
sl@0
   420
  m_eventWindowCreationDone.Signal();
sl@0
   421
sl@0
   422
  MSG msg;
sl@0
   423
  BOOL fGotMessage;
sl@0
   424
  while ((fGotMessage = GetMessage(&msg, (HWND) NULL, 0, 0)) != 0
sl@0
   425
       && fGotMessage != -1) 
sl@0
   426
  { 
sl@0
   427
    TranslateMessage(&msg); 
sl@0
   428
    DispatchMessage(&msg); 
sl@0
   429
  } 
sl@0
   430
}
sl@0
   431
//------------------------------------------------------------------------------
sl@0
   432
bool IdwThread::RegisterClass()
sl@0
   433
{
sl@0
   434
  WNDCLASSEX wc;
sl@0
   435
  if (GetClassInfoEx(m_hInstance, CLASSNAME, &wc))
sl@0
   436
  {
sl@0
   437
    return true;
sl@0
   438
  }
sl@0
   439
sl@0
   440
  wc.cbSize = sizeof(wc);
sl@0
   441
  wc.style = CS_HREDRAW | CS_VREDRAW;
sl@0
   442
  wc.lpfnWndProc = IdwThread::WndProc;
sl@0
   443
  wc.cbClsExtra = 0;
sl@0
   444
  wc.cbWndExtra = 0;
sl@0
   445
  wc.hInstance = m_hInstance;
sl@0
   446
  wc.hIcon = NULL;
sl@0
   447
  wc.hCursor = NULL;
sl@0
   448
  wc.hbrBackground = NULL;
sl@0
   449
  wc.lpszMenuName =  NULL;
sl@0
   450
  wc.lpszClassName = CLASSNAME;
sl@0
   451
  wc.hIconSm = NULL;
sl@0
   452
  if (::RegisterClassEx(&wc))
sl@0
   453
  {
sl@0
   454
    return true;
sl@0
   455
  }
sl@0
   456
  return false;
sl@0
   457
}
sl@0
   458
//------------------------------------------------------------------------------
sl@0
   459
bool IdwThread::CreateMessageWindow()
sl@0
   460
{
sl@0
   461
  m_hWnd = CreateWindow( 
sl@0
   462
    CLASSNAME,
sl@0
   463
    TEXT("MP iMON MessageWindow"),
sl@0
   464
    0,
sl@0
   465
    0, 0, 0, 0,
sl@0
   466
    HWND_MESSAGE,
sl@0
   467
    NULL,
sl@0
   468
    m_hInstance,
sl@0
   469
    NULL);
sl@0
   470
 
sl@0
   471
  if (!m_hWnd) 
sl@0
   472
    return false;
sl@0
   473
  return true; 
sl@0
   474
}
sl@0
   475
//------------------------------------------------------------------------------
sl@0
   476
void IdwThread::AllowImonMessages()
sl@0
   477
{
sl@0
   478
  // Determine OS
sl@0
   479
  OSVERSIONINFO version;
sl@0
   480
  version.dwOSVersionInfoSize = sizeof(version);
sl@0
   481
  GetVersionEx(&version);
sl@0
   482
  if (version.dwMajorVersion < 6)
sl@0
   483
  {
sl@0
   484
    return;
sl@0
   485
  }
sl@0
   486
sl@0
   487
  // Determine and allow iMON message number
sl@0
   488
  UINT iMonMsg =
sl@0
   489
    RegisterWindowMessage(
sl@0
   490
    TEXT("iMonMessage-431F1DC6-F31A-4AC6-A1FA-A4BB9C44FF10"));
sl@0
   491
  ChangeWindowMessageFilter(iMonMsg, MSGFLT_ADD);  
sl@0
   492
}
sl@0
   493
//------------------------------------------------------------------------------
sl@0
   494
bool IdwThread::WaitForWindow()
sl@0
   495
{
sl@0
   496
  m_eventWindowCreationDone.Await();
sl@0
   497
  if (m_hWnd == NULL)
sl@0
   498
    return false;
sl@0
   499
  return true;
sl@0
   500
}
sl@0
   501
//------------------------------------------------------------------------------
sl@1
   502
LRESULT CALLBACK IdwThread::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
sl@1
   503
{  
sl@1
   504
  static IdwImonInitRequest* initRequest = NULL;
sl@2
   505
  static DSPNotifyCode notification = DSPNM_PLUGIN_FAILED;
sl@0
   506
  DSPResult* pResult;
sl@0
   507
  Event* pFinished;
sl@0
   508
sl@0
   509
  switch (uMsg) 
sl@0
   510
  { 
sl@0
   511
    case WM_CREATE: 
sl@0
   512
      return 0; 
sl@0
   513
 
sl@0
   514
    case WM_DESTROY:
sl@0
   515
      PostQuitMessage(0);
sl@0
   516
      return 0;
sl@0
   517
sl@1
   518
	//Notifications from iMON Display API
sl@1
   519
	case IdwImonInitRequest::KMsgIdImonNotification:
sl@2
   520
		notification=(DSPNotifyCode)wParam; //Keep track of our current status
sl@1
   521
		if (initRequest)
sl@1
   522
			{
sl@1
   523
			initRequest->HandleImonNotifications(wParam,lParam);
sl@1
   524
			initRequest=NULL;
sl@1
   525
			}
sl@1
   526
		return 0;
sl@0
   527
sl@0
   528
    case WM_IDW_INIT:
sl@1
   529
		{
sl@1
   530
		initRequest = (IdwImonInitRequest*)wParam;
sl@1
   531
		LRESULT res=initRequest->Execute(uMsg);
sl@1
   532
		if (res==1)
sl@1
   533
			{
sl@1
   534
			//Request has been completed
sl@1
   535
			initRequest=NULL;
sl@1
   536
			}
sl@1
   537
		return 0;
sl@1
   538
		}
sl@0
   539
sl@0
   540
    case WM_IDW_UNINIT:
sl@0
   541
      pResult = (DSPResult*)wParam;
sl@0
   542
      pFinished = (Event*)lParam;
sl@0
   543
      *pResult = IMON_Display_Uninit();
sl@0
   544
      pFinished->Signal();
sl@0
   545
      return 0;
sl@0
   546
sl@0
   547
    case WM_IDW_ISINITED:
sl@0
   548
      pResult = (DSPResult*)wParam;
sl@0
   549
      pFinished = (Event*)lParam;
sl@0
   550
      *pResult = IMON_Display_IsInited();
sl@0
   551
      pFinished->Signal();
sl@0
   552
      return 0;
sl@0
   553
sl@0
   554
    case WM_IDW_ISPLUGINMODEENABLED:
sl@0
   555
      pResult = (DSPResult*)wParam;
sl@0
   556
      pFinished = (Event*)lParam;
sl@0
   557
      *pResult = IMON_Display_IsPluginModeEnabled();
sl@0
   558
      pFinished->Signal();
sl@0
   559
      return 0;
sl@0
   560
sl@2
   561
    case WM_IDW_STATUS:
sl@2
   562
		{
sl@2
   563
		IdwImonStatusRequest* request = (IdwImonStatusRequest*)wParam;
sl@2
   564
		request->iNotification = notification; //Get our notification code
sl@2
   565
		request->iResult = DSP_SUCCEEDED;
sl@2
   566
		LRESULT res=request->Execute(uMsg);
sl@2
   567
		return 0;
sl@2
   568
		}
sl@2
   569
sl@0
   570
    case WM_IDW_SETVFDTEXT:
sl@0
   571
			{
sl@0
   572
				IdwSetVfdText* pSetVfdText = (IdwSetVfdText*)wParam;			
sl@0
   573
				WCHAR szLine1[20];
sl@0
   574
				WCHAR szLine2[20];
sl@0
   575
				pFinished = (Event*)lParam;
sl@0
   576
				MapChars(szLine1, pSetVfdText->pszLine1, 16);
sl@0
   577
				MapChars(szLine2, pSetVfdText->pszLine2, 16);
sl@0
   578
				pSetVfdText->result = IMON_Display_SetVfdText(szLine1, szLine2);
sl@0
   579
				pFinished->Signal();
sl@0
   580
				return 0;
sl@0
   581
			}
sl@0
   582
sl@0
   583
    case WM_IDW_SETVFDEQ:
sl@0
   584
			{
sl@0
   585
				IdwSetVfdEq* pSetVfdEq = (IdwSetVfdEq*)wParam;
sl@0
   586
				pFinished = (Event*)lParam;
sl@0
   587
				pSetVfdEq->result = IMON_Display_SetVfdEqData(pSetVfdEq->pEqData);
sl@0
   588
				pFinished->Signal();
sl@0
   589
				return 0;
sl@0
   590
			}
sl@0
   591
sl@0
   592
    case WM_IDW_SETLCDTEXT:
sl@0
   593
			{
sl@0
   594
				IdwSetLcdText* pSetLcdText = (IdwSetLcdText*)wParam;
sl@0
   595
				pFinished = (Event*)lParam;
sl@0
   596
				pSetLcdText->result = IMON_Display_SetLcdText(pSetLcdText->pszLine1);
sl@0
   597
				pFinished->Signal();
sl@0
   598
				return 0;
sl@0
   599
			}
sl@0
   600
sl@0
   601
    case WM_IDW_SETLCDEQ:
sl@0
   602
			{
sl@0
   603
				IdwSetLcdEq* pSetLcdEq = (IdwSetLcdEq*)wParam;
sl@0
   604
				pFinished = (Event*)lParam;
sl@0
   605
				pSetLcdEq->result = 
sl@0
   606
					IMON_Display_SetLcdEqData(pSetLcdEq->pEqDataL, pSetLcdEq->pEqDataR);
sl@0
   607
				pFinished->Signal();
sl@0
   608
				return 0;
sl@0
   609
			}
sl@0
   610
sl@0
   611
		case WM_IDW_SETLCDALLICONS:
sl@0
   612
			{
sl@0
   613
				IdwSetLcdAllIcons* pSetLcdAllIcons = (IdwSetLcdAllIcons*)wParam;
sl@0
   614
				pFinished = (Event*)lParam;
sl@0
   615
				pSetLcdAllIcons->result = 
sl@0
   616
					IMON_Display_SetLcdAllIcons(pSetLcdAllIcons->bOn);
sl@0
   617
				pFinished->Signal();
sl@0
   618
				return 0;
sl@0
   619
			}
sl@0
   620
sl@0
   621
		case WM_IDW_SETLCDORANGEICON:
sl@0
   622
			{
sl@0
   623
				IdwSetLcdIcons2* pSetLcdIcons2 = (IdwSetLcdIcons2*)wParam;
sl@0
   624
				pFinished = (Event*)lParam;
sl@0
   625
				pSetLcdIcons2->result = IMON_Display_SetLcdOrangeIcon(
sl@0
   626
					pSetLcdIcons2->btIconData1, pSetLcdIcons2->btIconData2);
sl@0
   627
				pFinished->Signal();
sl@0
   628
				return 0;
sl@0
   629
			}
sl@0
   630
sl@0
   631
	  case WM_IDW_SETLCDMEDIATYPEICON:
sl@0
   632
			{
sl@0
   633
				IdwSetLcdIcons* pSetLcdIcons = (IdwSetLcdIcons*)wParam;
sl@0
   634
				pFinished = (Event*)lParam;
sl@0
   635
				pSetLcdIcons->result = 
sl@0
   636
					IMON_Display_SetLcdMediaTypeIcon(pSetLcdIcons->btIconData);
sl@0
   637
				pFinished->Signal();
sl@0
   638
				return 0;
sl@0
   639
			}
sl@0
   640
sl@0
   641
		case WM_IDW_SETLCDSPEAKERICON:
sl@0
   642
			{
sl@0
   643
				IdwSetLcdIcons2* pSetLcdIcons2 = (IdwSetLcdIcons2*)wParam;
sl@0
   644
				pFinished = (Event*)lParam;
sl@0
   645
				pSetLcdIcons2->result = IMON_Display_SetLcdSpeakerIcon(
sl@0
   646
					pSetLcdIcons2->btIconData1, pSetLcdIcons2->btIconData2);
sl@0
   647
				pFinished->Signal();
sl@0
   648
				return 0;
sl@0
   649
			}
sl@0
   650
sl@0
   651
	  case WM_IDW_SETLCDVIDEOCODEC:
sl@0
   652
			{
sl@0
   653
				IdwSetLcdIcons* pSetLcdIcons = (IdwSetLcdIcons*)wParam;
sl@0
   654
				pFinished = (Event*)lParam;
sl@0
   655
				pSetLcdIcons->result = 
sl@0
   656
					IMON_Display_SetLcdVideoCodecIcon(pSetLcdIcons->btIconData);
sl@0
   657
				pFinished->Signal();
sl@0
   658
				return 0;
sl@0
   659
			}
sl@0
   660
sl@0
   661
		case WM_IDW_SETLCDAUDIOCODEC:
sl@0
   662
			{
sl@0
   663
				IdwSetLcdIcons* pSetLcdIcons = (IdwSetLcdIcons*)wParam;
sl@0
   664
				pFinished = (Event*)lParam;
sl@0
   665
				pSetLcdIcons->result = 
sl@0
   666
					IMON_Display_SetLcdAudioCodecIcon(pSetLcdIcons->btIconData);
sl@0
   667
				pFinished->Signal();
sl@0
   668
				return 0;
sl@0
   669
			}
sl@0
   670
sl@0
   671
		case WM_IDW_SETLCDASPECTRATIO:
sl@0
   672
			{
sl@0
   673
				IdwSetLcdIcons* pSetLcdIcons = (IdwSetLcdIcons*)wParam;
sl@0
   674
				pFinished = (Event*)lParam;
sl@0
   675
				pSetLcdIcons->result = 
sl@0
   676
					IMON_Display_SetLcdAspectRatioIcon(pSetLcdIcons->btIconData);
sl@0
   677
				pFinished->Signal();
sl@0
   678
				return 0;
sl@0
   679
			}
sl@0
   680
sl@0
   681
		case WM_IDW_SETLCDETCICON:
sl@0
   682
			{
sl@0
   683
				IdwSetLcdIcons* pSetLcdIcons = (IdwSetLcdIcons*)wParam;
sl@0
   684
				pFinished = (Event*)lParam;
sl@0
   685
				pSetLcdIcons->result = 
sl@0
   686
					IMON_Display_SetLcdEtcIcon(pSetLcdIcons->btIconData);
sl@0
   687
				pFinished->Signal();
sl@0
   688
				return 0;
sl@0
   689
			}
sl@0
   690
sl@0
   691
		case WM_IDW_SETLCDPROGRESS:
sl@0
   692
			{
sl@0
   693
				IdwSetLcdProgress* pSetLcdProgress = (IdwSetLcdProgress*)wParam;
sl@0
   694
				pFinished = (Event*)lParam;
sl@0
   695
				pSetLcdProgress->result = IMON_Display_SetLcdProgress(
sl@0
   696
					pSetLcdProgress->nCurPos, pSetLcdProgress->nTotal);
sl@0
   697
				pFinished->Signal();
sl@0
   698
				return 0;
sl@0
   699
			}
sl@0
   700
sl@0
   701
    case WM_IDW_INTERRUPT:
sl@0
   702
      DestroyWindow(hwnd);
sl@0
   703
      return 0;
sl@0
   704
	}
sl@0
   705
  return DefWindowProc(hwnd, uMsg, wParam, lParam);
sl@0
   706
}
sl@0
   707
//------------------------------------------------------------------------------
sl@0
   708
void IdwThread::MapChars(LPWSTR lpszTarget, LPCWSTR lpszSource,
sl@0
   709
                         int nMaxLength)
sl@0
   710
{
sl@0
   711
  int len = (int)wcslen(lpszSource);
sl@0
   712
  if ((nMaxLength > 0) && (len > nMaxLength))
sl@0
   713
    len = nMaxLength;
sl@0
   714
  lpszTarget[len] = 0;
sl@0
   715
  for (int i = 0; i < len; ++i)
sl@0
   716
  {
sl@0
   717
    wchar_t ch = lpszSource[i];
sl@0
   718
    lpszTarget[i] = MapChar(ch);
sl@0
   719
  }
sl@0
   720
}
sl@0
   721
//------------------------------------------------------------------------------
sl@0
   722
#define IN_RANGE(ch, s, e) ((ch >= s) && (ch <= e))
sl@0
   723
#define IS(ch, c) (ch == c)
sl@0
   724
wchar_t IdwThread::MapChar(wchar_t ch)
sl@0
   725
{
sl@0
   726
  if (IN_RANGE(ch, 0x0020, 0x005B)
sl@0
   727
   || IN_RANGE(ch, 0x005D, 0x007D)
sl@0
   728
   || IS(ch, 0x0401)
sl@0
   729
   || IS(ch, 0x0404)
sl@0
   730
   || IN_RANGE(ch, 0x0406, 0x0407)
sl@0
   731
   || IN_RANGE(ch, 0x0410, 0x044F)
sl@0
   732
   || IS(ch, 0x0451)
sl@0
   733
   || IS(ch, 0x0454)
sl@0
   734
   || IN_RANGE(ch, 0x0456, 0x0457)
sl@0
   735
   || IN_RANGE(ch, 0x0490, 0x0491))
sl@0
   736
    return ch;
sl@0
   737
sl@0
   738
  switch (ch)
sl@0
   739
  {
sl@0
   740
  case 0x5C:
sl@0
   741
    return 0x8C;
sl@0
   742
  case 0x7E:
sl@0
   743
    return 0x8E;
sl@0
   744
  case 0x7F:
sl@0
   745
    return 0x20;
sl@0
   746
  case 0xA2:
sl@0
   747
    return 0xEC;
sl@0
   748
  case 0xA3:
sl@0
   749
    return 0x92;
sl@0
   750
  case 0xA5:
sl@0
   751
    return 0x5C;
sl@0
   752
  case 0xA6:
sl@0
   753
    return 0x98;
sl@0
   754
  case 0xA7:
sl@0
   755
    return 0x8F;
sl@0
   756
  case 0xB0:
sl@0
   757
    return 0xDF;
sl@0
   758
  case 0xB5:
sl@0
   759
    return 0xE4;
sl@0
   760
  case 0xC2:
sl@0
   761
    return 0x82;
sl@0
   762
  case 0xC4:
sl@0
   763
    return 0x80;
sl@0
   764
  case 0xC5:
sl@0
   765
    return 0x81;
sl@0
   766
  case 0xC6:
sl@0
   767
    return 0x90;
sl@0
   768
  case 0xC7:
sl@0
   769
    return 0x99;
sl@0
   770
  case 0xD1:
sl@0
   771
    return 0xEE;
sl@0
   772
  case 0xD6:
sl@0
   773
    return 0x86;
sl@0
   774
  case 0xD8:
sl@0
   775
    return 0x88;
sl@0
   776
  case 0xDC:
sl@0
   777
    return 0x8A;
sl@0
   778
  case 0xDE:
sl@0
   779
    return 0xF0;
sl@0
   780
  case 0xDF:
sl@0
   781
    return 0xE2;
sl@0
   782
  case 0xE1:
sl@0
   783
    return 0x83;
sl@0
   784
  case 0xE4:
sl@0
   785
    return 0xE1;
sl@0
   786
  case 0xE5:
sl@0
   787
    return 0x84;
sl@0
   788
  case 0xE7:
sl@0
   789
    return 0x99;
sl@0
   790
  case 0xF1:
sl@0
   791
    return 0xD1;
sl@0
   792
  case 0xF6:
sl@0
   793
    return 0x87;
sl@0
   794
  case 0xF7:
sl@0
   795
    return 0xFD;
sl@0
   796
  case 0xF8:
sl@0
   797
    return 0x89;
sl@0
   798
  case 0xFC:
sl@0
   799
    return 0x8B;
sl@0
   800
  case 0xFE:
sl@0
   801
    return 0xF0;
sl@0
   802
  default:
sl@0
   803
    return L'#';
sl@0
   804
  }
sl@0
   805
}
sl@1
   806
sl@1
   807
/**
sl@1
   808
Handle iMON notifications
sl@1
   809
*/
sl@1
   810
void IdwImonInitRequest::HandleImonNotifications(WPARAM wParam, LPARAM lParam)
sl@1
   811
	{
sl@1
   812
	iNotification=(DSPNotifyCode)wParam;
sl@1
   813
	iDspType=DSPN_DSP_NONE;
sl@1
   814
	iResult= DSP_SUCCEEDED;
sl@1
   815
sl@1
   816
	switch (iNotification)
sl@1
   817
		{
sl@1
   818
	case DSPNM_PLUGIN_SUCCEED:
sl@1
   819
	case DSPNM_IMON_RESTARTED:
sl@1
   820
	case DSPNM_HW_CONNECTED:
sl@1
   821
		//lParam is display type
sl@1
   822
		iDspType = (DSPType)lParam;
sl@3
   823
		iInitResult = DSPN_SUCCEEDED;
sl@1
   824
		break;
sl@1
   825
	case DSPNM_PLUGIN_FAILED:
sl@1
   826
	case DSPNM_HW_DISCONNECTED:
sl@1
   827
	case DSPNM_IMON_CLOSED:
sl@1
   828
		//lParam is error
sl@1
   829
		iInitResult = (DSPNInitResult)lParam;
sl@1
   830
		break;
sl@1
   831
	case DSPNM_LCD_TEXT_SCROLL_DONE:
sl@1
   832
		//That should not happen, report an error
sl@1
   833
		iResult = DSP_E_FAIL;
sl@1
   834
		break;
sl@1
   835
		}
sl@1
   836
	
sl@1
   837
	//Complete our request
sl@1
   838
	Signal();
sl@1
   839
	}
sl@1
   840
sl@1
   841
sl@1
   842
/**
sl@1
   843
Run our display initialization.
sl@1
   844
*/
sl@1
   845
LRESULT IdwImonInitRequest::DoExecute()
sl@1
   846
	{
sl@1
   847
	iResult = IMON_Display_Init(iWnd, KMsgIdImonNotification);
sl@1
   848
    if (iResult != DSP_SUCCEEDED)
sl@1
   849
		{
sl@1
   850
		iNotification = DSPNM_PLUGIN_FAILED;
sl@1
   851
        iInitResult = DSPN_ERR_UNKNOWN;
sl@1
   852
        iDspType = DSPN_DSP_NONE;
sl@1
   853
        Signal();
sl@1
   854
		return 1;
sl@1
   855
		}
sl@1
   856
sl@1
   857
	return 0;
sl@1
   858
	}
sl@2
   859
sl@2
   860
sl@2
   861
/**
sl@2
   862
*/
sl@2
   863
LRESULT IdwImonStatusRequest::DoExecute()
sl@2
   864
	{
sl@2
   865
	Signal();
sl@2
   866
	return 0;
sl@2
   867
	}