OpenCPN Partial API docs
win_usb_watch.cpp
1 /***************************************************************************
2  * Copyright (C) 2024 Alec Leamas *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18  **************************************************************************/
19 
22 #include <windows.h>
23 #include <Dbt.h>
24 
25 #include <wx/frame.h>
26 #include <wx/log.h>
27 #include <wx/window.h>
28 
29 #include "model/gui.h"
30 #include "model/sys_events.h"
31 #include "model/win_usb_watch.h"
32 
33 
34 class UsbListenFrame : public wxFrame {
35 public:
36  UsbListenFrame() : wxFrame(GetTopWindow(), wxID_ANY, "") {}
37 
38  virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam,
39  WXLPARAM lParam) {
40  if (nMsg == WM_DEVICECHANGE) {
41  wxLogDebug("WM_DEVICECHANGE %x %x", wParam, lParam);
42  if (wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE) {
43  SystemEvents::GetInstance().evt_dev_change.Notify();
44  }
45  }
46  return wxFrame::MSWWindowProc(nMsg, wParam, lParam);
47  }
48 };
49 
50 void WinUsbWatchDaemon::Start() {
51  if (m_frame) return;
52  m_frame = new UsbListenFrame();
53  m_frame->Hide();
54 }
55 
56 
57 void WinUsbWatchDaemon::Stop() {
58  if (!m_frame) return;
59  delete m_frame;
60  m_frame = 0;
61 }
const void Notify()
Notify all listeners, no data supplied.
EventVar evt_dev_change
Notified when a new or removed device is detected, usually an USB hotplug event:
Definition: sys_events.h:44
wxWindow * GetTopWindow()
Return the top level window a k a gFrame.
Definition: gui.cpp:24
Hooks int gui available in model.
Windows specific hardware events interface.