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 #include "host/frontend/gcastv2/signaling_server/signal_handler.h" 27 28 namespace cuttlefish { 29 class DeviceHandler; 30 class ClientHandler : public SignalHandler, 31 public std::enable_shared_from_this<ClientHandler> { 32 public: 33 ClientHandler(DeviceRegistry* registry, const ServerConfig& server_config); 34 void SendDeviceMessage(const Json::Value& message); 35 protected: 36 int handleMessage(const std::string& type, 37 const Json::Value& message) override; 38 39 private: 40 int handleConnectionRequest(const Json::Value& message); 41 int handleForward(const Json::Value& message); 42 43 std::weak_ptr<DeviceHandler> device_handler_; 44 // The device handler assigns this to each client to be able to differentiate 45 // them. 46 size_t client_id_; 47 }; 48 } // namespace cuttlefish 49