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
20lws* WebSocketServer::webSocket = nullptr;
21std::atomic<bool> WebSocketServer::interrupted = false;
22WebSocketServer::WebSocketState WebSocketServer::webSocketWritable = WebSocketState::INIT;
23uint8_t* WebSocketServer::firstImageBuffer = nullptr;
24uint64_t WebSocketServer::firstImagebufferSize = 0;
25
26WebSocketServer::WebSocketServer() : serverThread(nullptr), serverPort(0) {}
27
28WebSocketServer::~WebSocketServer() {}
29
30WebSocketServer& WebSocketServer::GetInstance()
31{
32    static WebSocketServer server;
33    return server;
34}
35
36void WebSocketServer::SetServerPort(int port)
37{
38    serverPort = port;
39}
40
41int 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
50void WebSocketServer::SignalHandler(int sig)
51{
52    interrupted = true;
53}
54
55void WebSocketServer::StartWebsocketListening() {}
56
57void WebSocketServer::Run()
58{
59    g_run = true;
60}
61
62size_t WebSocketServer::WriteData(unsigned char* data, size_t length)
63{
64    g_writeData = true;
65    return length;
66}