1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef LOCAL_SOCKET_OPTIONS_H
17 #define LOCAL_SOCKET_OPTIONS_H
18 
19 #include <string>
20 
21 #include "extra_options_base.h"
22 
23 namespace OHOS::NetStack::Socket {
24 class LocalSocketRemoteInfo {
25 public:
LocalSocketRemoteInfo()26     LocalSocketRemoteInfo() {}
~LocalSocketRemoteInfo()27     virtual ~LocalSocketRemoteInfo() {}
28 
SetAddress(const std::string & address)29     void SetAddress(const std::string &address)
30     {
31         address_ = address;
32     }
SetSize(uint32_t size)33     void SetSize(uint32_t size)
34     {
35         size_ = size;
36     }
GetAddress()37     [[nodiscard]] const std::string &GetAddress() const
38     {
39         return address_;
40     }
GetSize()41     [[nodiscard]] uint32_t GetSize() const
42     {
43         return size_;
44     }
45 
46 private:
47     std::string address_;
48     uint32_t size_ = 0;
49 };
50 
51 class LocalSocketOptions {
52 public:
LocalSocketOptions()53     LocalSocketOptions() {}
~LocalSocketOptions()54     ~LocalSocketOptions() {}
55     void SetBuffer(const std::string &buffer);
56     void SetBuffer(void *data, size_t size);
SetEncoding(const std::string & encoding)57     void SetEncoding(const std::string &encoding)
58     {
59         encoding_ = encoding;
60     }
61     [[nodiscard]] const std::string &GetBufferRef() const;
62 
63 private:
64     std::string buffer_;
65     std::string encoding_;
66 };
67 
68 class LocalExtraOptions : public ExtraOptionsBase {
69 public:
AlreadySetRecvBufSize()70     bool AlreadySetRecvBufSize() const
71     {
72         return recvBufSizeFlag_;
73     }
AlreadySetSendBufSize()74     bool AlreadySetSendBufSize() const
75     {
76         return sendBufSizeFlag_;
77     }
AlreadySetTimeout()78     bool AlreadySetTimeout() const
79     {
80         return timeoutFlag_;
81     }
SetRecvBufSizeFlag(bool flag)82     void SetRecvBufSizeFlag(bool flag)
83     {
84         recvBufSizeFlag_ = flag;
85     }
SetSendBufSizeFlag(bool flag)86     void SetSendBufSizeFlag(bool flag)
87     {
88         sendBufSizeFlag_ = flag;
89     }
SetTimeoutFlag(bool flag)90     void SetTimeoutFlag(bool flag)
91     {
92         timeoutFlag_ = flag;
93     }
94 
95 private:
96     bool recvBufSizeFlag_ = false;
97     bool sendBufSizeFlag_ = false;
98     bool timeoutFlag_ = false;
99 };
100 } // namespace OHOS::NetStack::Socket
101 
102 #endif