• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 COMMUNICATIONNETSTACK_SERVER_START_CONTEXT_H
17 #define COMMUNICATIONNETSTACK_SERVER_START_CONTEXT_H
18 
19 #include <string>
20 
21 #include "base_context.h"
22 #include "libwebsockets.h"
23 #include "nocopyable.h"
24 
25 namespace OHOS::NetStack::Websocket {
26 class ServerStartContext final : public BaseContext {
27 public:
28     DISALLOW_COPY_AND_MOVE(ServerStartContext);
29 
30     ServerStartContext() = delete;
31 
32     ServerStartContext(napi_env env, const std::shared_ptr<EventManager> &sharedManager);
33 
34     ~ServerStartContext() override;
35 
36     void ParseParams(napi_value *params, size_t paramsCount) override;
37 
38     void SetServerIP(std::string &ip);
39 
40     [[nodiscard]] std::string GetServerIP() const;
41 
42     void SetServerPort(uint32_t &serverPort);
43 
44     [[nodiscard]] uint32_t GetServerPort() const;
45 
46     void SetServerCert(std::string &certPath, std::string &keyPath);
47 
48     void GetServerCert(std::string &certPath, std::string &keyPath) const;
49 
50     void SetMaxConcurrentClientsNumber(uint32_t &clientsNumber);
51 
52     [[nodiscard]] uint32_t GetMaxConcurrentClientsNumber() const;
53 
54     void SetServerProtocol(std::string &protocol);
55 
56     [[nodiscard]] std::string GetServerProtocol() const;
57 
58     void SetMaxConnectionsForOneClient(uint32_t &count);
59 
60     [[nodiscard]] uint32_t GetMaxConnectionsForOneClient() const;
61 
62     [[nodiscard]] int32_t GetErrorCode() const override;
63 
64     [[nodiscard]] std::string GetErrorMessage() const override;
65 
66     std::string serverIp_;
67 
68     uint32_t serverPort_ = 0;
69 
70     std::string certPath_;
71 
72     std::string keyPath_;
73 
74     uint32_t maxClientsNumber_ = 0;
75 
76     std::string websocketServerProtocol_;
77 
78     uint32_t maxCountForOneClient_ = 0;
79 
80 private:
81     bool CheckParamsType(napi_value *params, size_t paramsCount);
82 
83     void ParseCallback(napi_value const *params, size_t paramsCount);
84 
85     bool ParseRequiredParams(napi_env env, napi_value params);
86 
87     void ParseOptionalParams(napi_env env, napi_value params);
88 
89     void ParseServerCert(napi_env env, napi_value params);
90 };
91 } // namespace OHOS::NetStack::Websocket
92 #endif /* COMMUNICATIONNETSTACK_SERVER_START_CONTEXT_H */