/src/logging-log4cxx/src/main/cpp/socket.cpp
Line | Count | Source |
1 | | /* |
2 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
3 | | * contributor license agreements. See the NOTICE file distributed with |
4 | | * this work for additional information regarding copyright ownership. |
5 | | * The ASF licenses this file to You under the Apache License, Version 2.0 |
6 | | * (the "License"); you may not use this file except in compliance with |
7 | | * the License. You may obtain a copy of the License at |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | */ |
17 | | #include <log4cxx/helpers/socket.h> |
18 | | #include <log4cxx/private/socket_priv.h> |
19 | | #include <log4cxx/private/aprsocket.h> |
20 | | #include <log4cxx/helpers/loader.h> |
21 | | #include <log4cxx/helpers/loglog.h> |
22 | | |
23 | | using namespace LOG4CXX_NS; |
24 | | using namespace LOG4CXX_NS::helpers; |
25 | | |
26 | | IMPLEMENT_LOG4CXX_OBJECT(Socket) |
27 | | |
28 | | Socket::Socket(std::unique_ptr<Socket::SocketPrivate> priv) : |
29 | 0 | m_priv(std::move(priv)){ |
30 | |
|
31 | 0 | } |
32 | | |
33 | | Socket::~Socket() |
34 | 0 | { |
35 | 0 | } |
36 | | |
37 | | InetAddressPtr Socket::getInetAddress() const |
38 | 0 | { |
39 | 0 | return m_priv->address; |
40 | 0 | } |
41 | | |
42 | | int Socket::getPort() const |
43 | 0 | { |
44 | 0 | return m_priv->port; |
45 | 0 | } |
46 | | |
47 | | void Socket::setAttributes(const InetAddressPtr& newAddress, int newPort) |
48 | 0 | { |
49 | 0 | m_priv->address = newAddress; |
50 | 0 | m_priv->port = newPort; |
51 | 0 | } |
52 | | |
53 | | #if LOG4CXX_ABI_VERSION <= 15 |
54 | 0 | SocketUniquePtr Socket::create(InetAddressPtr& address, int port){ |
55 | 0 | return std::make_unique<APRSocket>(address, port); |
56 | 0 | } |
57 | | #endif |
58 | | |
59 | | SocketUniquePtr Socket::create(LOG4CXX_16_CONST InetAddressPtr& address, int port, const LogString& concreteClassName) |
60 | 0 | { |
61 | | #if 15 < LOG4CXX_ABI_VERSION |
62 | | if (!concreteClassName.empty()) |
63 | | { |
64 | | if (LogLog::isDebugEnabled()) |
65 | | { |
66 | | LogLog::debug(LOG4CXX_STR("Desired ") + Socket::getStaticClass().getName() |
67 | | + LOG4CXX_STR(" sub-class: [") + concreteClassName + LOG4CXX_STR("]")); |
68 | | } |
69 | | auto& classObj = Loader::loadClass(concreteClassName); |
70 | | auto newObject = classObj.newInstance(); |
71 | | auto pSocket = dynamic_cast<Socket*>(newObject); |
72 | | if (!pSocket) |
73 | | { |
74 | | LogLog::error(concreteClassName + LOG4CXX_STR(" is not a ") + Socket::getStaticClass().getName() + LOG4CXX_STR(" sub-class")); |
75 | | delete newObject; |
76 | | } |
77 | | else |
78 | | { |
79 | | auto result = std::unique_ptr<Socket>(pSocket); |
80 | | pSocket->setAttributes(address, port); |
81 | | pSocket->open(); |
82 | | return result; |
83 | | } |
84 | | } |
85 | | #endif |
86 | 0 | return std::make_unique<APRSocket>(address, port); |
87 | 0 | } |
88 | | |