Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

347 lines
10 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. drivers.cpp
  7. Tapi drivers config dialog
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "drivers.h"
  12. #include "tapidb.h"
  13. #include "server.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CDriverSetup dialog
  21. CDriverSetup::CDriverSetup(ITFSNode * pServerNode, ITapiInfo * pTapiInfo, CWnd* pParent /*=NULL*/)
  22. : CBaseDialog(CDriverSetup::IDD, pParent)
  23. {
  24. //{{AFX_DATA_INIT(CDriverSetup)
  25. // NOTE: the ClassWizard will add member initialization here
  26. //}}AFX_DATA_INIT
  27. m_spServerNode.Set(pServerNode);
  28. m_spTapiInfo.Set(pTapiInfo);
  29. m_fDriverAdded = FALSE;
  30. }
  31. void CDriverSetup::DoDataExchange(CDataExchange* pDX)
  32. {
  33. CBaseDialog::DoDataExchange(pDX);
  34. //{{AFX_DATA_MAP(CDriverSetup)
  35. // NOTE: the ClassWizard will add DDX and DDV calls here
  36. //}}AFX_DATA_MAP
  37. }
  38. BEGIN_MESSAGE_MAP(CDriverSetup, CBaseDialog)
  39. //{{AFX_MSG_MAP(CDriverSetup)
  40. ON_BN_CLICKED(IDC_BUTTON_ADD_DRIVER, OnButtonAdd)
  41. ON_BN_CLICKED(IDC_BUTTON_EDIT_DRIVER, OnButtonEdit)
  42. ON_BN_CLICKED(IDC_BUTTON_REMOVE_DRIVER, OnButtonRemove)
  43. ON_LBN_DBLCLK(IDC_LIST_DRIVERS, OnDblclkListDrivers)
  44. ON_LBN_SELCHANGE(IDC_LIST_DRIVERS, OnSelchangeListDrivers)
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CDriverSetup message handlers
  49. BOOL CDriverSetup::OnInitDialog()
  50. {
  51. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  52. CBaseDialog::OnInitDialog();
  53. CTapiProvider tapiProvider;
  54. int i, nIndex;
  55. // fill in the listbox with the providers that are installed.
  56. for (i = 0; i < m_spTapiInfo->GetProviderCount(); i++)
  57. {
  58. // add this provider to the listbox.
  59. m_spTapiInfo->GetProviderInfo(&tapiProvider, i);
  60. nIndex = ((CListBox *) GetDlgItem(IDC_LIST_DRIVERS))->AddString(tapiProvider.m_strName);
  61. ((CListBox *) GetDlgItem(IDC_LIST_DRIVERS))->SetItemData(nIndex, tapiProvider.m_dwProviderID);
  62. }
  63. ((CListBox *) GetDlgItem(IDC_LIST_DRIVERS))->SetCurSel(0);
  64. EnableButtons();
  65. return TRUE; // return TRUE unless you set the focus to a control
  66. // EXCEPTION: OCX Property Pages should return FALSE
  67. }
  68. void CDriverSetup::OnButtonAdd()
  69. {
  70. CAddDriver dlgAddDriver(m_spTapiInfo);
  71. if (dlgAddDriver.DoModal() == IDOK)
  72. {
  73. CTapiServer * pServer = GETHANDLER(CTapiServer, m_spServerNode);
  74. // add to listbox
  75. int nIndex = ((CListBox *) GetDlgItem(IDC_LIST_DRIVERS))->AddString(dlgAddDriver.m_tapiProvider.m_strName);
  76. ((CListBox *) GetDlgItem(IDC_LIST_DRIVERS))->SetItemData(nIndex, dlgAddDriver.m_tapiProvider.m_dwProviderID);
  77. // add to MMC UI
  78. pServer->AddProvider(m_spServerNode, &dlgAddDriver.m_tapiProvider);
  79. m_fDriverAdded = TRUE;
  80. }
  81. EnableButtons();
  82. }
  83. void CDriverSetup::OnButtonEdit()
  84. {
  85. HRESULT hr = hrOK;
  86. int nCurSel;
  87. DWORD dwProviderID;
  88. nCurSel = ((CListBox *) GetDlgItem(IDC_LIST_DRIVERS))->GetCurSel();
  89. dwProviderID = (DWORD) ((CListBox *) GetDlgItem(IDC_LIST_DRIVERS))->GetItemData(nCurSel);
  90. hr = m_spTapiInfo->ConfigureProvider(dwProviderID, GetSafeHwnd());
  91. if (FAILED(hr))
  92. {
  93. ::TapiMessageBox(WIN32_FROM_HRESULT(hr));
  94. }
  95. }
  96. void CDriverSetup::OnButtonRemove()
  97. {
  98. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  99. HRESULT hr = hrOK;
  100. int nCurSel, nCount;
  101. DWORD dwProviderID;
  102. CString strMessage;
  103. CTapiProvider tapiProvider;
  104. CTapiServer * pServer = GETHANDLER(CTapiServer, m_spServerNode);
  105. nCurSel = ((CListBox *) GetDlgItem(IDC_LIST_DRIVERS))->GetCurSel();
  106. dwProviderID = (DWORD) ((CListBox *) GetDlgItem(IDC_LIST_DRIVERS))->GetItemData(nCurSel);
  107. m_spTapiInfo->GetProviderInfo(&tapiProvider, dwProviderID);
  108. AfxFormatString2(strMessage, IDS_WARN_PROVIDER_DELETE, tapiProvider.m_strName, pServer->GetName());
  109. if (AfxMessageBox(strMessage, MB_YESNO) == IDYES)
  110. {
  111. Assert(m_spTapiInfo);
  112. BEGIN_WAIT_CURSOR;
  113. hr = m_spTapiInfo->RemoveProvider(dwProviderID, GetSafeHwnd());
  114. if (FAILED(hr))
  115. {
  116. ::TapiMessageBox(WIN32_FROM_HRESULT(hr));
  117. }
  118. else
  119. {
  120. // remove from the list box
  121. ((CListBox *) GetDlgItem(IDC_LIST_DRIVERS))->DeleteString(nCurSel);
  122. // now remove from the MMC UI
  123. pServer->RemoveProvider(m_spServerNode, dwProviderID);
  124. // update the list of installed providers
  125. m_spTapiInfo->EnumProviders();
  126. }
  127. END_WAIT_CURSOR;
  128. }
  129. // select another item in the listbox
  130. nCount = ((CListBox *) GetDlgItem(IDC_LIST_DRIVERS))->GetCount();
  131. ((CListBox *) GetDlgItem(IDC_LIST_DRIVERS))->SetCurSel((nCurSel == nCount) ? nCount - 1 : nCurSel);
  132. EnableButtons();
  133. }
  134. void CDriverSetup::OnDblclkListDrivers()
  135. {
  136. OnButtonEdit();
  137. }
  138. void CDriverSetup::OnCancel()
  139. {
  140. // TODO: Add extra cleanup here
  141. CBaseDialog::OnCancel();
  142. }
  143. void CDriverSetup::OnSelchangeListDrivers()
  144. {
  145. EnableButtons();
  146. }
  147. void CDriverSetup::EnableButtons()
  148. {
  149. int nIndex = ((CListBox *) GetDlgItem(IDC_LIST_DRIVERS))->GetCurSel();
  150. if (nIndex != LB_ERR)
  151. {
  152. DWORD dwProviderID = (DWORD) ((CListBox *) GetDlgItem(IDC_LIST_DRIVERS))->GetItemData(nIndex);
  153. CTapiProvider tapiProvider;
  154. m_spTapiInfo->GetProviderInfo(&tapiProvider, dwProviderID);
  155. // enable the appropriate buttons
  156. GetDlgItem(IDC_BUTTON_REMOVE_DRIVER)->EnableWindow(tapiProvider.m_dwFlags & AVAILABLEPROVIDER_REMOVABLE);
  157. GetDlgItem(IDC_BUTTON_EDIT_DRIVER)->EnableWindow(tapiProvider.m_dwFlags & AVAILABLEPROVIDER_CONFIGURABLE);
  158. }
  159. else
  160. {
  161. GetDlgItem(IDC_BUTTON_REMOVE_DRIVER)->EnableWindow(FALSE);
  162. GetDlgItem(IDC_BUTTON_EDIT_DRIVER)->EnableWindow(FALSE);
  163. }
  164. }
  165. /////////////////////////////////////////////////////////////////////////////
  166. // CAddDriver dialog
  167. CAddDriver::CAddDriver(ITapiInfo * pTapiInfo, CWnd* pParent /*=NULL*/)
  168. : CBaseDialog(CAddDriver::IDD, pParent)
  169. {
  170. //{{AFX_DATA_INIT(CAddDriver)
  171. // NOTE: the ClassWizard will add member initialization here
  172. //}}AFX_DATA_INIT
  173. m_spTapiInfo.Set(pTapiInfo);
  174. }
  175. void CAddDriver::DoDataExchange(CDataExchange* pDX)
  176. {
  177. CBaseDialog::DoDataExchange(pDX);
  178. //{{AFX_DATA_MAP(CAddDriver)
  179. // NOTE: the ClassWizard will add DDX and DDV calls here
  180. //}}AFX_DATA_MAP
  181. }
  182. BEGIN_MESSAGE_MAP(CAddDriver, CBaseDialog)
  183. //{{AFX_MSG_MAP(CAddDriver)
  184. ON_BN_CLICKED(IDC_BUTTON_ADD_NEW_DRIVER, OnButtonAdd)
  185. ON_LBN_DBLCLK(IDC_LIST_NEW_DRIVERS, OnDblclkListNewDrivers)
  186. //}}AFX_MSG_MAP
  187. END_MESSAGE_MAP()
  188. /////////////////////////////////////////////////////////////////////////////
  189. // CAddDriver message handlers
  190. BOOL CAddDriver::OnInitDialog()
  191. {
  192. CBaseDialog::OnInitDialog();
  193. CTapiProvider tapiProvider;
  194. int i, j, nIndex;
  195. m_spTapiInfo->EnumAvailableProviders();
  196. for (i = 0; i < m_spTapiInfo->GetAvailableProviderCount(); i++)
  197. {
  198. // add this provider to the listbox.
  199. m_spTapiInfo->GetAvailableProviderInfo(&tapiProvider, i);
  200. if (tapiProvider.m_dwFlags & AVAILABLEPROVIDER_INSTALLABLE)
  201. {
  202. BOOL bInstalled = FALSE;
  203. /* some TAPI providers can be installed mutliple times, so just add to the list
  204. and let the server return an error if it fails.
  205. for (j = 0; j < m_spTapiInfo->GetProviderCount(); j++)
  206. {
  207. CTapiProvider tapiProviderInstalled;
  208. m_spTapiInfo->GetProviderInfo(&tapiProviderInstalled, j);
  209. if (tapiProviderInstalled.m_strFilename.CompareNoCase(tapiProvider.m_strFilename) == 0)
  210. {
  211. // this provider is already installed... don't add
  212. bInstalled = TRUE;
  213. break;
  214. }
  215. }
  216. */
  217. if (!bInstalled)
  218. {
  219. // this provider isn't installed yet... make it available to the user
  220. nIndex = ((CListBox *) GetDlgItem(IDC_LIST_NEW_DRIVERS))->AddString(tapiProvider.m_strName);
  221. ((CListBox *) GetDlgItem(IDC_LIST_NEW_DRIVERS))->SetItemData(nIndex, i);
  222. }
  223. }
  224. }
  225. ((CListBox *) GetDlgItem(IDC_LIST_NEW_DRIVERS))->SetCurSel(0);
  226. EnableButtons();
  227. return TRUE; // return TRUE unless you set the focus to a control
  228. // EXCEPTION: OCX Property Pages should return FALSE
  229. }
  230. void CAddDriver::OnButtonAdd()
  231. {
  232. int nCurSel, nIndex;
  233. HRESULT hr = hrOK;
  234. // get the info on the currently selected provider
  235. nCurSel = ((CListBox *) GetDlgItem(IDC_LIST_NEW_DRIVERS))->GetCurSel();
  236. nIndex = (int) ((CListBox *) GetDlgItem(IDC_LIST_NEW_DRIVERS))->GetItemData(nCurSel);
  237. m_spTapiInfo->GetAvailableProviderInfo(&m_tapiProvider, nIndex);
  238. BEGIN_WAIT_CURSOR;
  239. // try to add the provider to the server
  240. hr = m_spTapiInfo->AddProvider(m_tapiProvider.m_strFilename, &m_tapiProvider.m_dwProviderID, GetSafeHwnd());
  241. if (FAILED(hr))
  242. {
  243. ::TapiMessageBox(WIN32_FROM_HRESULT(hr));
  244. }
  245. else
  246. {
  247. // success... we're done here
  248. // update our installed provider list
  249. hr = m_spTapiInfo->EnumProviders();
  250. EndDialog(IDOK);
  251. }
  252. END_WAIT_CURSOR;
  253. }
  254. void CAddDriver::OnDblclkListNewDrivers()
  255. {
  256. OnButtonAdd();
  257. }
  258. void CAddDriver::EnableButtons()
  259. {
  260. int nCount = ((CListBox *) GetDlgItem(IDC_LIST_NEW_DRIVERS))->GetCount();
  261. GetDlgItem(IDC_BUTTON_ADD_NEW_DRIVER)->EnableWindow(nCount > 0);
  262. }