blob: af4011dd85c8474cb89e27035a3172a6c6d974e0 [file] [log] [blame]
Mike Yubab3daa2018-10-19 22:11:43 +08001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _DNS_DNSTLSSOCKETFACTORY_H
18#define _DNS_DNSTLSSOCKETFACTORY_H
19
20#include <memory>
21
22#include "DnsTlsSocket.h"
23#include "IDnsTlsSocketFactory.h"
24
25namespace android {
26namespace net {
27
28class IDnsTlsSocketObserver;
29class DnsTlsSessionCache;
30struct DnsTlsServer;
31
32// Trivial RAII factory for DnsTlsSocket. This is owned by DnsTlsDispatcher.
33class DnsTlsSocketFactory : public IDnsTlsSocketFactory {
Bernie Innocentiec4219b2019-01-30 11:16:36 +090034 public:
Mike Yubab3daa2018-10-19 22:11:43 +080035 std::unique_ptr<IDnsTlsSocket> createDnsTlsSocket(const DnsTlsServer& server, unsigned mark,
Bernie Innocentiec4219b2019-01-30 11:16:36 +090036 IDnsTlsSocketObserver* _Nonnull observer,
37 DnsTlsSessionCache* _Nonnull cache) override {
Mike Yubab3daa2018-10-19 22:11:43 +080038 auto socket = std::make_unique<DnsTlsSocket>(server, mark, observer, cache);
39 if (!socket->initialize()) {
40 return nullptr;
41 }
42 return std::move(socket);
43 }
44};
45
46} // end of namespace net
47} // end of namespace android
48
49#endif // _DNS_DNSTLSSOCKETFACTORY_H