OpenCPN Partial API docs
Loading...
Searching...
No Matches
win_usb_watch.cpp
Go to the documentation of this file.
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
25#include <windows.h>
26#include <Dbt.h>
27
28#include <wx/frame.h>
29#include <wx/log.h>
30#include <wx/window.h>
31
32#include "model/gui.h"
33#include "model/sys_events.h"
34#include "model/win_usb_watch.h"
35
36class UsbListenFrame : public wxFrame {
37public:
38 UsbListenFrame() : wxFrame(GetTopWindow(), wxID_ANY, "") {}
39
40 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam,
41 WXLPARAM lParam) {
42 if (nMsg == WM_DEVICECHANGE) {
43 wxLogDebug("WM_DEVICECHANGE %x %x", wParam, lParam);
44 if (wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE) {
45 SystemEvents::GetInstance().evt_dev_change.Notify();
46 }
47 }
48 return wxFrame::MSWWindowProc(nMsg, wParam, lParam);
49 }
50};
51
52void WinUsbWatchDaemon::Start() {
53 if (m_frame) return;
54 m_frame = new UsbListenFrame();
55 m_frame->Hide();
56}
57
58void WinUsbWatchDaemon::Stop() {
59 if (!m_frame) return;
60 delete m_frame;
61 m_frame = 0;
62}
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:46
wxWindow * GetTopWindow()
Return the top level window a k a gFrame.
Definition gui.cpp:29
Hooks into gui available in model.
Suspend/resume and new devices events exchange point.
Windows specific hardware events interface.