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, see <https://www.gnu.org/licenses/ *
16 **************************************************************************/
17
23
24#include <winsock2.h>
25#include <windows.h>
26#include <Dbt.h>
27
28#include <wx/app.h>
29#include <wx/frame.h>
30#include <wx/log.h>
31#include <wx/window.h>
32
33#include "model/sys_events.h"
34#include "model/win_usb_watch.h"
35
36class UsbListenFrame : public wxFrame {
37public:
38 UsbListenFrame() : wxFrame(wxTheApp->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 wxFrame* frame = m_frame.get();
60 m_frame = nullptr;
61 delete frame;
62}
Suspend/resume and new devices events exchange point.
Windows specific hardware events interface.