File indexing completed on 2024-04-28 16:59:41
0001 /* 0002 Copyright (C) 2013 Andreas Hartmetz <ahartmetz@gmail.com> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LGPL. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 0019 Alternatively, this file is available under the Mozilla Public License 0020 Version 1.1. You may obtain a copy of the License at 0021 http://www.mozilla.org/MPL/ 0022 */ 0023 0024 #ifndef CONNECTADDRESS_H 0025 #define CONNECTADDRESS_H 0026 0027 #include "export.h" 0028 0029 #include <string> 0030 0031 // I think we don't need to bother with subclasses, which will add boilerplate 0032 // while on the other hand all-in-one isn't particularly easy to misuse. 0033 0034 class DFERRY_EXPORT ConnectAddress 0035 { 0036 public: 0037 enum class StandardBus : unsigned char 0038 { 0039 System, 0040 Session 0041 }; 0042 0043 enum class Type : unsigned char 0044 { 0045 None = 0, 0046 UnixPath, 0047 UnixDir, 0048 RuntimeDir, 0049 TmpDir, 0050 AbstractUnixPath, 0051 Tcp = 6, 0052 Tcp4, 0053 Tcp6 0054 }; 0055 0056 enum class Role : unsigned char 0057 { 0058 None = 0, 0059 BusClient, 0060 // BusServer, // = 2, not implemented 0061 PeerClient = 3, 0062 PeerServer 0063 }; 0064 0065 ConnectAddress(); 0066 // Intentionally not explicit; this constructor discovers the bus address (mostly ;) according to spec 0067 ConnectAddress(StandardBus bus); 0068 ConnectAddress(const ConnectAddress &other); 0069 ConnectAddress &operator=(const ConnectAddress &other); 0070 ~ConnectAddress(); 0071 0072 bool operator==(const ConnectAddress &other) const; 0073 bool operator!=(const ConnectAddress &other) const { return !(*this == other); } 0074 0075 void setType(Type type); 0076 Type type() const; 0077 0078 void setRole(Role role); 0079 Role role() const; 0080 0081 void setPath(const std::string &path); 0082 std::string path() const; // only for Unix domain sockets 0083 0084 void setHostname(const std::string &path); 0085 std::string hostname() const; // Only for IP sockets. Only an IP address string ("192.168.0.10") is 0086 // supported, hostname ("myhost.local") support might be added later. 0087 // As an exception, hostname "localhost" or empty string will be 0088 // understood as the loopback address. 0089 0090 void setPort(int port); 0091 int port() const; // only for TcpSocket 0092 0093 void setGuid(const std::string &guid); 0094 std::string guid() const; 0095 0096 // the dbus standard format strings don't contain information about role and bus type, so the setter 0097 // will not touch these and the getter will lose that information. 0098 bool setAddressFromString(const std::string &addr); 0099 std::string toString() const; 0100 0101 bool isServerOnly() const; 0102 0103 // TODO comparison operators 0104 0105 private: 0106 class Private; 0107 Private *d; 0108 }; 0109 0110 #endif // CONNECTADDRESS_H