1 //
2 // Copyright (C) 2020 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #pragma once
17 
18 #include <memory>
19 #include <string>
20 
21 #include <json/json.h>
22 
23 #include "host/frontend/gcastv2/https/include/https/WebSocketHandler.h"
24 #include "host/frontend/gcastv2/signaling_server/device_registry.h"
25 #include "host/frontend/gcastv2/signaling_server/server_config.h"
26 
27 namespace cuttlefish {
28 
29 class SignalHandler : public WebSocketHandler {
30  protected:
31   SignalHandler(DeviceRegistry* registry, const ServerConfig& server_config);
32 
33   bool IsBinaryMessage(uint8_t header_byte);
34 
35   int handleMessage(uint8_t header_byte, const uint8_t* msg,
36                     size_t len) override;
37   virtual int handleMessage(const std::string& message_type,
38                             const Json::Value& message) = 0;
39   void SendServerConfig();
40 
41   void LogAndReplyError(const std::string& message);
42   void Reply(const Json::Value& json);
43 
44   DeviceRegistry* registry_;
45   const ServerConfig& server_config_;
46 };
47 }  // namespace cuttlefish
48