SPAOP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Address.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 #ifndef ADDRESS_H_INCLUDED
21 #define ADDRESS_H_INCLUDED
22 
23 #include <iostream>
24 #include <mutex>
25 #include <stdint.h>
26 #include "lo/lo.h"
27 #include "ServerThread.h"
28 #include "Message.h"
29 
30 namespace lowrappers {
31 
35 class Address
36 {
37 public:
38 
50  Address(const std::string &host, const std::string &port,
51  int proto=LO_UDP);
52 
62  Address(lo_address addr, bool isOwner = true);
63 
67  virtual ~Address();
68 
75  Address(const Address& other);
76 
91  bool setAddress(const std::string &newHost, const std::string &newPort);
92 
97  int getTtl() const;
98 
104  void setTtl(uint8_t ttl);
105 
112  std::string getIface() const;
113 
119  void setIfaceByIp(const std::string& ip);
120 
126  std::string url() const;
127 
132  std::string hostname() const;
133 
138  std::string port() const;
139 
149  int send(const std::string &path, const std::string types, ...) const;
150 
158  int send(const std::string &path, const Message& msg) const;
159 
167  int send(const std::string &path, const lo_message msg) const;
168 
181  int sendVAList(const std::string &path, const std::string &types, va_list args) const;
182 
194  int sendFrom(const ServerThread &from, const std::string &path,
195  const std::string types, ...) const;
196 
206  int sendFrom(const ServerThread &from, const std::string &path,
207  const Message& msg) const;
208 
218  int sendFrom(const ServerThread &from, const std::string &path,
219  const lo_message msg) const;
220 
234  int sendVAListFrom(const ServerThread &from, const std::string &path,
235  const std::string &types, va_list args) const;
236 
237 private:
238  Address &operator= (Address& other); // assignment not allowed
239 
240  lo_address addr_;
241  mutable std::mutex mutex_;
242  bool isOwner_;
243 };
244 
245 }
246 #endif /* defined(ADDRESS_H_INCLUDED) */
A wrapper of Liblo's lo_message.
Definition: Message.h:33
std::string getIface() const
Returns the name of the network interface that will be used for sending to this address.
Definition: Address.cpp:92
std::string url() const
An URL describing this address.
Definition: Address.cpp:104
virtual ~Address()
Destructor.
Definition: Address.cpp:42
int sendVAList(const std::string &path, const std::string &types, va_list args) const
Sends a OSC formatted message to this address.
Definition: Address.cpp:145
int getTtl() const
Returns the time-to-live value for this Address.
Definition: Address.cpp:80
std::string hostname() const
The hostname of this adress.
Definition: Address.cpp:113
int sendFrom(const ServerThread &from, const std::string &path, const std::string types,...) const
Sends a OSC formatted message to this address, from the same socket as the specified server...
Definition: Address.cpp:176
int send(const std::string &path, const std::string types,...) const
Sends a OSC formatted message to this address.
Definition: Address.cpp:133
A wrapper for Liblo's lo_address.
Definition: Address.h:35
void setTtl(uint8_t ttl)
Sets the time-to-live value for this Address.
Definition: Address.cpp:86
bool setAddress(const std::string &newHost, const std::string &newPort)
Updates this Address to send to a new destination.
Definition: Address.cpp:58
void setIfaceByIp(const std::string &ip)
Sets the network interface to use for sending to this address.
Definition: Address.cpp:98
Address(const std::string &host, const std::string &port, int proto=LO_UDP)
Constructor.
Definition: Address.cpp:24
A server thread with Liblo-style callback capabilities.
Definition: ServerThread.h:52
int sendVAListFrom(const ServerThread &from, const std::string &path, const std::string &types, va_list args) const
Sends a OSC formatted message to this address, from the same socket that a specified ServerThread is ...
Definition: Address.cpp:201
std::string port() const
The port/service name of this adress.
Definition: Address.cpp:123