@@ -28,6 +28,21 @@ class observer_impl_base
2828 explicit observer_impl_base (
2929 observer_configuration&& conf, alsa_raw_observer_configuration&& apiconf)
3030 : configuration{std::move (conf), std::move (apiconf)}
31+ {
32+ }
33+
34+ ~observer_impl_base ()
35+ {
36+ #if LIBREMIDI_HAS_UDEV
37+ m_termination_event.notify ();
38+
39+ if (m_thread.joinable ())
40+ m_thread.join ();
41+ #endif
42+ }
43+
44+ // Must be called for child classes due to virtual function calls
45+ void finish_init ()
3146 {
3247 if (!configuration.has_callbacks ())
3348 return ;
@@ -48,16 +63,6 @@ class observer_impl_base
4863#endif
4964 }
5065
51- ~observer_impl_base ()
52- {
53- #if LIBREMIDI_HAS_UDEV
54- m_termination_event.notify ();
55-
56- if (m_thread.joinable ())
57- m_thread.join ();
58- #endif
59- }
60-
6166 std::vector<libremidi::input_port> get_input_ports () const noexcept override
6267 {
6368 std::vector<libremidi::input_port> ret;
@@ -84,7 +89,6 @@ class observer_impl_base
8489 return ret;
8590 }
8691
87- private:
8892#if LIBREMIDI_HAS_UDEV
8993 void run ()
9094 {
@@ -98,6 +102,12 @@ class observer_impl_base
98102 return ;
99103 }
100104
105+ // Check eventfd to see if we need to exit
106+ if (m_fds[1 ].revents & POLLIN)
107+ {
108+ break ;
109+ }
110+
101111 // Check udev
102112 if (m_fds[0 ].revents & POLLIN)
103113 {
@@ -122,12 +132,6 @@ class observer_impl_base
122132 m_fds[0 ].revents = 0 ;
123133 }
124134
125- // Check eventfd
126- if (m_fds[1 ].revents & POLLIN)
127- {
128- break ;
129- }
130-
131135 // Check timer
132136 if (m_fds[2 ].revents & POLLIN)
133137 {
@@ -146,26 +150,35 @@ class observer_impl_base
146150 -> std::conditional_t<Input, input_port, output_port>
147151 {
148152#if LIBREMIDI_HAS_UDEV
149- auto [container, device, type] = get_udev_soundcard_info (m_udev, p.card );
153+ auto [container, device, type, manufacturer, product, serial]
154+ = get_udev_soundcard_info (m_udev, p.card );
150155#else
151156 container_identifier container{};
152157 device_identifier device{};
153- libremidi::port_information::port_type type{};
158+ libremidi::transport_type type{};
159+ std::string manufacturer;
160+ std::string product;
161+ std::string serial;
154162#endif
155163 std::string display_name = p.subdevice_name ;
156164 if (display_name.empty ())
157165 display_name = p.device_name ;
158166 if (display_name.empty ())
159167 display_name = p.card_name ;
168+ if (display_name.empty ())
169+ display_name = product;
160170 if (display_name.empty ())
161171 display_name = " unknown" ;
162172
163173 return {
164- {.client = 0 ,
174+ {.api = get_current_api (),
175+ .client = 0 ,
165176 .container = container,
166177 .device = device,
167178 .port = raw_to_port_handle ({p.card , p.dev , p.sub }),
168- .manufacturer = p.card_name ,
179+ .manufacturer = manufacturer,
180+ .product = product,
181+ .serial = serial,
169182 .device_name = p.device_name ,
170183 .port_name = p.subdevice_name ,
171184 .display_name = std::move (display_name),
@@ -247,7 +260,12 @@ namespace libremidi::alsa_raw
247260{
248261struct observer_impl : observer_impl_base<alsa_raw::midi1_enumerator>
249262{
250- using alsa_raw::observer_impl_base<midi1_enumerator>::observer_impl_base;
263+ observer_impl (observer_configuration&& conf, alsa_raw_observer_configuration&& apiconf)
264+ : observer_impl_base<alsa_raw::midi1_enumerator>{std::move (conf), std::move (apiconf)}
265+ {
266+ finish_init ();
267+ }
268+
251269 libremidi::API get_current_api () const noexcept override { return libremidi::API::ALSA_RAW; }
252270};
253271}
0 commit comments