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 NET_WEBSOCKET_BASE_CONTEXT_H 17 #define NET_WEBSOCKET_BASE_CONTEXT_H 18 19 #include <string> 20 21 #include "ffi_structs.h" 22 23 namespace OHOS::NetStack::NetWebSocket { 24 class CJWebsocketProxy; 25 26 class WebSocketBaseContext { 27 public: 28 WebSocketBaseContext() = delete; 29 30 WebSocketBaseContext(CJWebsocketProxy* websocketProxy); 31 32 virtual ~WebSocketBaseContext(); 33 34 CJWebsocketProxy* GetWebsocketProxy(); 35 36 void SetWebsocketProxy(CJWebsocketProxy* websocketProxy); 37 38 void SetParseOK(bool parseOK); 39 40 [[nodiscard]] bool IsParseOK() const; 41 42 void SetExecOK(bool requestOK); 43 44 [[nodiscard]] bool IsExecOK() const; 45 46 [[nodiscard]] virtual int32_t GetErrorCode() const; 47 48 void SetErrorCode(int32_t errorCode); 49 50 [[nodiscard]] virtual std::string GetErrorMessage() const; 51 52 void SetError(int32_t errorCode, const std::string &errorMessage); 53 54 void SetPermissionDenied(bool deny); 55 56 bool IsPermissionDenied() const; 57 58 protected: 59 CJWebsocketProxy* websocketProxy_; 60 61 private: 62 int32_t errorCode_; 63 64 bool parseOK_ = false; 65 66 bool requestOK_ = false; 67 68 bool permissionDenied_ = false; 69 70 std::string errorMessage_; 71 }; 72 } 73 #endif