1 /*
2  * Copyright (c) 2024 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 #include <atomic>
17 #include "WebSocketServer.h"
18 #include "MockGlobalResult.h"
19 
20 lws* WebSocketServer::webSocket = nullptr;
21 std::atomic<bool> WebSocketServer::interrupted = false;
22 WebSocketServer::WebSocketState WebSocketServer::webSocketWritable = WebSocketState::INIT;
23 uint8_t* WebSocketServer::firstImageBuffer = nullptr;
24 uint64_t WebSocketServer::firstImagebufferSize = 0;
25 
WebSocketServer()26 WebSocketServer::WebSocketServer() : serverThread(nullptr), serverPort(0) {}
27 
~WebSocketServer()28 WebSocketServer::~WebSocketServer() {}
29 
GetInstance()30 WebSocketServer& WebSocketServer::GetInstance()
31 {
32     static WebSocketServer server;
33     return server;
34 }
35 
SetServerPort(int port)36 void WebSocketServer::SetServerPort(int port)
37 {
38     serverPort = port;
39 }
40 
ProtocolCallback(struct lws* wsi, enum lws_callback_reasons reason, void* user, void* in, size_t len)41 int WebSocketServer::ProtocolCallback(struct lws* wsi,
42                                       enum lws_callback_reasons reason,
43                                       void* user,
44                                       void* in,
45                                       size_t len)
46 {
47     return 0;
48 }
49 
SignalHandler(int sig)50 void WebSocketServer::SignalHandler(int sig)
51 {
52     interrupted = true;
53 }
54 
StartWebsocketListening()55 void WebSocketServer::StartWebsocketListening() {}
56 
Run()57 void WebSocketServer::Run()
58 {
59     g_run = true;
60 }
61 
WriteData(unsigned char* data, size_t length)62 size_t WebSocketServer::WriteData(unsigned char* data, size_t length)
63 {
64     g_writeData = true;
65     return length;
66 }