summaryrefslogtreecommitdiff
path: root/libs/surfaces/websockets/ardour_websockets.cc
diff options
context:
space:
mode:
authorLuciano Iam <lucianito@gmail.com>2020-02-20 13:12:36 +0100
committerRobin Gareus <robin@gareus.org>2020-02-22 23:10:24 +0100
commit8db9755d1e075f22275286e94b37af311c6d489f (patch)
treed72749d8cdc77914303c34c6aa6f5a28e620ddb8 /libs/surfaces/websockets/ardour_websockets.cc
parent44165309299960e35d4efa2194b2c2db63c2c1b2 (diff)
Add websockets surface module
Diffstat (limited to 'libs/surfaces/websockets/ardour_websockets.cc')
-rw-r--r--libs/surfaces/websockets/ardour_websockets.cc132
1 files changed, 132 insertions, 0 deletions
diff --git a/libs/surfaces/websockets/ardour_websockets.cc b/libs/surfaces/websockets/ardour_websockets.cc
new file mode 100644
index 0000000000..0dd3bea4c2
--- /dev/null
+++ b/libs/surfaces/websockets/ardour_websockets.cc
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2009-2014 David Robillard <d@drobilla.net>
+ * Copyright (C) 2009-2017 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2012-2016 Tim Mayberry <mojofunk@gmail.com>
+ * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2015-2016 Ben Loftis <ben@harrisonconsoles.com>
+ * Copyright (C) 2015-2018 John Emmas <john@creativepost.co.uk>
+ * Copyright (C) 2015 Johannes Mueller <github@johannes-mueller.org>
+ * Copyright (C) 2016-2018 Len Ovens <len@ovenwerks.net>
+ * Copyright (C) 2020 Luciano Iam <lucianito@gmail.com>
+ *
+ * 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 "ardour/session.h"
+
+#include "ardour_websockets.h"
+
+using namespace ARDOUR;
+using namespace ArdourSurface;
+
+#include "pbd/abstract_ui.cc" // instantiate template
+
+ArdourWebsockets::ArdourWebsockets (Session& s)
+ : ControlProtocol (s, X_(SURFACE_NAME))
+ , AbstractUI<ArdourWebsocketsUIRequest> (name ())
+ , _strips (*this)
+ , _globals (*this)
+ , _feedback (*this)
+ , _server (*this)
+ , _dispatcher (*this)
+{
+ _components = { &_strips, &_globals, &_server, &_feedback, &_dispatcher };
+}
+
+ArdourWebsockets::~ArdourWebsockets ()
+{
+ stop();
+}
+
+void*
+ArdourWebsockets::request_factory (uint32_t num_requests)
+{
+ /* AbstractUI<T>::request_buffer_factory() is a template method only
+ instantiated in this source module. To provide something visible for
+ use in the interface/descriptor, we have this static method that is
+ template-free.
+ */
+ return request_buffer_factory (num_requests);
+}
+
+int
+ArdourWebsockets::set_active (bool yn)
+{
+ if (yn != active ()) {
+ if (yn) {
+ if (start ()) {
+ return -1;
+ }
+ } else {
+ if (stop ()) {
+ return -1;
+ }
+ }
+ }
+
+ return ControlProtocol::set_active (yn);
+}
+
+void
+ArdourWebsockets::thread_init ()
+{
+ pthread_set_name (event_loop_name ().c_str ());
+ PBD::notify_event_loops_about_thread_creation (pthread_self (), event_loop_name (), 2048);
+ SessionEvent::create_per_thread_pool (event_loop_name (), 128);
+}
+
+void
+ArdourWebsockets::do_request (ArdourWebsocketsUIRequest* req)
+{
+ if (req->type == CallSlot) {
+ call_slot (MISSING_INVALIDATOR, req->the_slot);
+ } else if (req->type == Quit) {
+ stop ();
+ }
+}
+
+int
+ArdourWebsockets::start ()
+{
+ // startup the event loop thread
+ BaseUI::run ();
+
+ for (std::vector<SurfaceComponent *>::iterator it = _components.begin ();
+ it != _components.end (); ++it) {
+ int rc = (*it)->start ();
+ if (rc != 0) {
+ return -1;
+ }
+ }
+
+ PBD::info << "ArdourWebsockets: started" << endmsg;
+
+ return 0;
+}
+
+int
+ArdourWebsockets::stop () {
+ for (std::vector<SurfaceComponent *>::iterator it = _components.begin ();
+ it != _components.end (); ++it) {
+ (*it)->stop ();
+ }
+
+ BaseUI::quit ();
+
+ PBD::info << "ArdourWebsockets: stopped" << endmsg;
+
+ return 0;
+}