keyboard: split class
authorMax Kellermann <max@musicpd.org>
Tue, 9 Apr 2019 20:47:16 +0000 (22:47 +0200)
committerMax Kellermann <max@musicpd.org>
Tue, 9 Apr 2019 20:47:16 +0000 (22:47 +0200)
meson.build
src/AsyncUserInput.cxx [moved from src/keyboard.cxx with 86% similarity]
src/AsyncUserInput.hxx [new file with mode: 0644]
src/Instance.cxx
src/Instance.hxx
src/UserInput.cxx [new file with mode: 0644]
src/UserInput.hxx [moved from src/keyboard.hxx with 74% similarity]
src/screen_find.cxx

index 2e6defc..594445d 100644 (file)
@@ -311,7 +311,8 @@ ncmpc = executable('ncmpc',
   'src/Command.cxx',
   'src/Bindings.cxx',
   'src/GlobalBindings.cxx',
-  'src/keyboard.cxx',
+  'src/UserInput.cxx',
+  'src/AsyncUserInput.cxx',
   'src/KeyName.cxx',
   'src/Match.cxx',
   'src/ncu.cxx',
similarity index 86%
rename from src/keyboard.cxx
rename to src/AsyncUserInput.cxx
index 0325cac..5ba0367 100644 (file)
@@ -1,5 +1,5 @@
 /* ncmpc (Ncurses MPD Client)
- * (c) 2004-2018 The Music Player Daemon Project
+ * (c) 2004-2019 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
  *
  * This program is free software; you can redistribute it and/or modify
@@ -18,7 +18,7 @@
  */
 
 #include "config.h"
-#include "keyboard.hxx"
+#include "AsyncUserInput.hxx"
 #include "Command.hxx"
 #include "Bindings.hxx"
 #include "GlobalBindings.hxx"
@@ -40,7 +40,7 @@ translate_key(int key)
 }
 
 void
-UserInput::OnReadable(const boost::system::error_code &error)
+AsyncUserInput::OnReadable(const boost::system::error_code &error)
 {
        if (error) {
                get_io_context().stop();
@@ -88,14 +88,9 @@ UserInput::OnReadable(const boost::system::error_code &error)
        AsyncWait();
 }
 
-UserInput::UserInput(boost::asio::io_service &io_service, WINDOW &_w)
-       :d(io_service),
-#if BOOST_VERSION >= 107000
-        io_context(io_service),
-#endif
-        w(_w)
+AsyncUserInput::AsyncUserInput(boost::asio::io_service &io_service, WINDOW &_w)
+       :UserInput(io_service), w(_w)
 {
-       d.assign(STDIN_FILENO);
        AsyncWait();
 }
 
diff --git a/src/AsyncUserInput.hxx b/src/AsyncUserInput.hxx
new file mode 100644 (file)
index 0000000..c1ec646
--- /dev/null
@@ -0,0 +1,45 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2019 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef ASYNC_USER_INPUT_HXX
+#define ASYNC_USER_INPUT_HXX
+
+#include "UserInput.hxx"
+
+#include <curses.h>
+
+class AsyncUserInput : public UserInput {
+       WINDOW &w;
+
+public:
+       AsyncUserInput(boost::asio::io_service &io_service, WINDOW &_w);
+
+private:
+       void AsyncWait() {
+               UserInput::AsyncWait(std::bind(&AsyncUserInput::OnReadable, this,
+                                              std::placeholders::_1));
+       }
+
+       void OnReadable(const boost::system::error_code &error);
+};
+
+void
+keyboard_unread(boost::asio::io_service &io_service, int key);
+
+#endif
index 2232b89..d9740e9 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "Instance.hxx"
 #include "Options.hxx"
-#include "keyboard.hxx"
 #include "xterm_title.hxx"
 
 Instance::Instance()
index 31ce627..6a62c1e 100644 (file)
@@ -21,7 +21,7 @@
 #define NCMPC_INSTANCE_HXX
 
 #include "config.h"
-#include "keyboard.hxx"
+#include "AsyncUserInput.hxx"
 #include "mpdclient.hxx"
 #include "DelayedSeek.hxx"
 #include "screen.hxx"
@@ -70,7 +70,7 @@ class Instance {
        LircInput lirc_input;
 #endif
 
-       UserInput user_input;
+       AsyncUserInput user_input;
 
 public:
        Instance();
diff --git a/src/UserInput.cxx b/src/UserInput.cxx
new file mode 100644 (file)
index 0000000..40055e3
--- /dev/null
@@ -0,0 +1,31 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2019 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "UserInput.hxx"
+
+#include <unistd.h>
+
+UserInput::UserInput(boost::asio::io_service &io_service)
+       :d(io_service)
+#if BOOST_VERSION >= 107000
+       , io_context(io_service)
+#endif
+{
+       d.assign(STDIN_FILENO);
+}
similarity index 74%
rename from src/keyboard.hxx
rename to src/UserInput.hxx
index 20b32af..6489be0 100644 (file)
@@ -1,5 +1,5 @@
 /* ncmpc (Ncurses MPD Client)
- * (c) 2004-2018 The Music Player Daemon Project
+ * (c) 2004-2019 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
  *
  * This program is free software; you can redistribute it and/or modify
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifndef KEYBOARD_H
-#define KEYBOARD_H
+#ifndef USER_INPUT_HXX
+#define USER_INPUT_HXX
 
 #include "AsioServiceFwd.hxx"
 
 #include <boost/asio/posix/stream_descriptor.hpp>
 
-#include <curses.h>
-
 class UserInput {
        boost::asio::posix::stream_descriptor d;
 
@@ -33,10 +31,8 @@ class UserInput {
        boost::asio::io_context &io_context;
 #endif
 
-       WINDOW &w;
-
 public:
-       UserInput(boost::asio::io_service &io_service, WINDOW &_w);
+       explicit UserInput(boost::asio::io_service &io_service);
 
        auto &get_io_context() noexcept {
 #if BOOST_VERSION >= 107000
@@ -46,17 +42,11 @@ public:
 #endif
        }
 
-private:
-       void AsyncWait() {
+       template<typename F>
+       void AsyncWait(F &&f) noexcept {
                d.async_read_some(boost::asio::null_buffers(),
-                                 std::bind(&UserInput::OnReadable, this,
-                                           std::placeholders::_1));
+                                 std::forward<F>(f));
        }
-
-       void OnReadable(const boost::system::error_code &error);
 };
 
-void
-keyboard_unread(boost::asio::io_service &io_service, int key);
-
 #endif
index a17d0c5..4f8b739 100644 (file)
@@ -22,7 +22,7 @@
 #include "screen_status.hxx"
 #include "screen.hxx"
 #include "ListWindow.hxx"
-#include "keyboard.hxx"
+#include "AsyncUserInput.hxx"
 #include "i18n.h"
 #include "Options.hxx"
 #include "util/LocaleString.hxx"