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 #include <vector> 21 22 #include <json/json.h> 23 24 #include "host/frontend/gcastv2/https/include/https/WebSocketHandler.h" 25 #include "host/frontend/gcastv2/signaling_server/device_registry.h" 26 #include "host/frontend/gcastv2/signaling_server/server_config.h" 27 #include "host/frontend/gcastv2/signaling_server/signal_handler.h" 28 29 namespace cuttlefish { 30 31 class ClientHandler; 32 33 class DeviceHandler 34 : public SignalHandler, 35 public std::enable_shared_from_this<DeviceHandler> { 36 public: 37 DeviceHandler(DeviceRegistry* registry, const ServerConfig& server_config); 38 ~DeviceHandler() override; 39 device_info()40 Json::Value device_info() const { return device_info_; } 41 42 size_t RegisterClient(std::shared_ptr<ClientHandler> client_handler); 43 void SendClientMessage(size_t client_id, const Json::Value& message); 44 protected: 45 int handleMessage(const std::string& type, 46 const Json::Value& message) override; 47 48 private: 49 int HandleRegistrationRequest(const Json::Value& message); 50 int HandleForward(const Json::Value& message); 51 52 std::string device_id_; 53 Json::Value device_info_; 54 std::vector<std::weak_ptr<ClientHandler>> clients_; 55 }; 56 } // namespace cuttlefish 57