SPAOP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ServerThread.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Martin Hansen
3  *
4  * This file is part of SPAOP (Spatial Audio Object Positioner).
5  *
6  * SPAOP is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * SPAOP is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with SPAOP. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 
21 #ifndef SERVERTHREAD_H_INCLUDED
22 #define SERVERTHREAD_H_INCLUDED
23 
24 #include <iostream>
25 #include "lo/lo.h"
26 #include "Thread.h"
27 
28 #define SEVER_THREAD_RCV_INTERVAL 10
37 namespace lowrappers {
38 
50 class ServerThread : public thread::Thread
51 {
55  friend class Address;
56 public:
57 
62  class Listener
63  {
64  public:
65  virtual ~Listener(){}
66 
83  virtual int callback(const char *path, const char *types,
84  lo_arg **argv, int argc, lo_message msg) = 0;
85  };
86 
94  ServerThread(lo_err_handler err_h);
95 
104  ServerThread(const std::string &port, lo_err_handler err_h);
105 
116  ServerThread(const std::string& group, const std::string &port, lo_err_handler err_h);
117 
130  ServerThread(const std::string& group, const std::string &port,
131  const std::string& ifaceIp, lo_err_handler err_h);
132 
134  virtual ~ServerThread();
135 
141  bool isValid() const;
142 
148  std::string url() const;
149 
155  int port() const;
156 
176  bool addMethod(const char *path, const char *typespec,
177  lo_method_handler h, void *user_data);
178 
198  bool addListener(const char *path, const char *typespec,
199  Listener* listener);
200 
208  void delMethod(const char *path, const char *typespec);
209 
210 private:
211  ServerThread(const ServerThread& other); // copying not allowed
212  ServerThread &operator= (const ServerThread other); // assignment not allowed
213 
218  static int genericCallback(const char *path, const char *types, lo_arg **argv,
219  int argc, lo_message msg, void *user_data);
220 
221  void run(); // inherited from thread::Thread
222 
223  lo_server server;
224 };
225 
226 }
227 
228 #endif // SERVERTHREAD_H_INCLUDED
virtual void run()=0
This is the method that will be executed by the thread.
A listener interface for listeners to be called by the ServerThread when incoming OSC messages are re...
Definition: ServerThread.h:64
A server thread with Liblo-style callback capabilities.
Definition: ServerThread.h:52
A wrapper for the std::thread wrapping it into a Java-style thread object.
Definition: Thread.h:39